exec_outcome
stringclasses 1
value | code_uid
stringlengths 32
32
| file_name
stringclasses 111
values | prob_desc_created_at
stringlengths 10
10
| prob_desc_description
stringlengths 63
3.8k
| prob_desc_memory_limit
stringclasses 18
values | source_code
stringlengths 117
65.5k
| lang_cluster
stringclasses 1
value | prob_desc_sample_inputs
stringlengths 2
802
| prob_desc_time_limit
stringclasses 27
values | prob_desc_sample_outputs
stringlengths 2
796
| prob_desc_notes
stringlengths 4
3k
⌀ | lang
stringclasses 5
values | prob_desc_input_from
stringclasses 3
values | tags
sequencelengths 0
11
| src_uid
stringlengths 32
32
| prob_desc_input_spec
stringlengths 28
2.37k
⌀ | difficulty
int64 -1
3.5k
⌀ | prob_desc_output_spec
stringlengths 17
1.47k
⌀ | prob_desc_output_to
stringclasses 3
values | hidden_unit_tests
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 7eed6f6720c14bcaedf3786158fe25fc | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class B
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0) {
int n = sc.nextInt();
String s = sc.next();
String res = "";
for(int i = n - 1; i >= 0; i--) {
int val = Integer.parseInt(String.valueOf(s.charAt(i)));
if(val == 0) {
if(i - 1 >= 0 && i - 2 >= 0) {
res = (char)(Integer.parseInt(s.substring(i-2, i)) + 96) + res;
i -= 2;
}
else {
res = (char)(Integer.parseInt(s.substring(i-1, i + 1)) + 96) + res;
i--;
}
}
else {
res = (char)(val + 96) + res;
}
}
System.out.println(res);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | e2bde0170fca6d9490c522b5ce44da8b | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class FileHandler {
BigInteger fib(int n){
BigInteger a = new BigInteger("1");
BigInteger b = new BigInteger("1");
BigInteger s = new BigInteger("2");
if(n == 1 || n == 2)
return a;
for(int i=3;i<=n;i++) {
s = a.add(b);
a = b;
b = s;
}
return s;
}
boolean isPrime(int n)
{
if(n==0) return false;
return BigInteger.valueOf(n).isProbablePrime(n);
}
int nextprime(int n)
{
return BigInteger.valueOf(n).nextProbablePrime().intValue();
}
void print1toN(int n)
{
if(n == 0)
return;
System.out.print(n + " ");
print1toN(n-1);
}
void printNto1(int n)
{
if(n == 0)
return;
printNto1(n-1);
System.out.print(n + " ");
}
int sumNatural(int n , int s)
{
// if(n == 0)
// return 0;
// return n + sumNatural(n-1 , 0);
//Tail recursive
if(n == 0)
return n+s;
s += n;
return sumNatural(n-1 , s);
}
boolean isPalindrome(String s , int i)
{
if(s.charAt(s.length() - 1 - i) != s.charAt(i))
return false;
if(i == s.length()-1)
return true;
i++;
return isPalindrome(s , i);
}
int sumOfDigits(int n)
{
if(n == 0)
return 0;
return n%10 + sumOfDigits(n/10);
}
int ropeCutting(int n , int a, int b , int c)
{
if(n == 0)
return 0;
if(n < 0)
return -1;
int max = Math.max((Math.max(ropeCutting(n-a ,a,b,c), ropeCutting(n-b,a,b,c))), ropeCutting(n-c, a,b,c));
if(max == -1)
return -1;
return ++max;
}
void subsets(String s , String t , int i)
{
if(i == s.length()){
System.out.print(t + " ");
return;
}
subsets(s , t , i + 1);
subsets(s , t + s.charAt(i), i + 1);
}
int towerOfHanoy(int n, char a, char b, char c)
{
if(n == 1) {
System.out.println("Move disc 1 from " + a + " to " + c);
return 1;
}
towerOfHanoy(n-1 , a , c , b);
System.out.println("Move disc " + n + " from " + a + " to " + c);
towerOfHanoy(n-1 , b , a , c);
return (int) (Math.pow(2 , n) - 1);
}
int countDigits(int n)
{
if(n <= 9)
return 1;
return 1 + countDigits(n/10);
}
boolean isPalin(int N)
{
// Check if the number is palindrome or not
//You may use a helper function if you like
String s = String.valueOf(N);
return isPalindrome(s , 0);
}
int recursiveGCD(int a, int b)
{
if(a == 0) return b;
if(b == 0) return a;
if(a > b)
return recursiveGCD(a%b,b);
else
return recursiveGCD(a,b%a);
}
void printArrayRecursively(int arr[], int n)
{
// Print the array elements recursively
if(n == 0) return;
printArrayRecursively(arr,n-1);
System.out.print(arr[n-1] + " ");
}
int RecursivePower(int n,int p)
{
if(p == 0)
return 1;
return n*RecursivePower(n , p-1);
}
int sumOfProductOfDigits(int n1, int n2)
{
// your code here
if(n1 == 0 || n2 == 0)
return 0;
return (n1%10)*(n2%10) + sumOfProductOfDigits(n1/10,n2/10);
}
int sumOfMaxandMin(int arr[], int n)
{
// your code here
return Arrays.stream(arr).min().getAsInt() + Arrays.stream(arr).max().getAsInt();
}
int longestLength(int[] arr, int n)
{
int maxLength = 0;
int pane = 1;
for(int i=1;i<n;i++){
if(arr[i] == arr[i-1])
pane++;
else{
maxLength = Math.max(maxLength , pane);
pane = 1;
}
}
return Math.max(maxLength , pane);
}
boolean zeroSum(int[] arr)
{
HashSet<Integer> hs = new HashSet<>();
int ps =0;
for(int i = 0; i < arr.length; i++){
ps += arr[i];
if(ps == 0 || hs.contains(ps))
return true;
hs.add(ps);
}
return false;
}
int longSubarraySum(int[]arr , int target)
{
HashMap<Integer,Integer> hm = new HashMap<>();
int ps=0;
int max=0;
for(int i=0;i<arr.length;i++){
ps += arr[i];
if(ps == target)
max = i+1;
if(!hm.containsKey(ps))
hm.put(ps , i);
if(hm.containsKey(ps - target))
max = Math.max(max , i - hm.get(ps - target) );
}
return max;
}
int longestZeroSum(int[] arr)
{
for(int i = 0; i<arr.length;i++)
arr[i] = (arr[i] == 0) ? -1 : 1;
return longSubarraySum(arr, 0);
}
int countDistinctelement(int[] arr)
{
HashSet<Integer> hs = new HashSet<>();
for(int i : arr)
hs.add(i);
return hs.size();
}
void frquenciesOfElements(int[] arr)
{
HashMap<Integer , Integer> hm = new HashMap<>();
for(int i = 0; i < arr.length;i++){
hm.put(arr[i] , hm.getOrDefault(arr[i] , 0) + 1);
}
for(int keys : hm.keySet())
System.out.println(keys + " --> " + hm.get(keys));
}
int binarySearch(long[] arr, int target)
{
int h = arr.length - 1;
int l = 0;
int mid;
while(l <= h)
{
mid = (h+l)/2;
if(arr[mid] == target)
return mid;
else if(arr[mid] < target)
l = mid + 1;
else
h = mid - 1;
}
return -1;
}
int binarySearch(int[] arr , int low, int high,int target)
{
if(low > high)
return -1;
int mid = (low+high)/2;
if(arr[mid] == target)
return mid;
else if(arr[mid] > target)
return binarySearch(arr , low , mid - 1 , target);
else
return binarySearch(arr ,mid + 1 , high , target);
}
long sqrt(long n)
{
long low = 1;
long high = n / 2;
long res = 1;
while(low <= high)
{
long mid = (high+low)/2;
long sqre = mid*mid;
if(sqre == n)
return mid;
else if(sqre < n){
low = mid+1;
res = mid;
}
else
high= mid-1;
}
return res;
}
int majorityElement(int[] arr)
{
int count=0;
int majority=0;
for(int i=0;i<arr.length;i++)
{
if(count == 0)
majority = arr[i];
if(majority == arr[i])
count++;
else
count--;
}
int t=0;
for(int i = 0;i<arr.length;i++)
{
if(arr[i] == majority)
t++;
}
if(t > arr.length/2)
return majority;
return -1;
}
void sortSelection(int[] arr)
{
for(int i=0;i<arr.length;i++)
{
int min = i;
int j = i+1;
while(j < arr.length){
if(arr[j] < arr[min])
min = j;
j++;
}
int t = arr[min];
arr[min] = arr[i];
arr[i] = t;
}
}
void sortInsertion(int[] arr)
{
for(int i=1;i<arr.length;i++){
int key = arr[i];
int j =i - 1;
while(j >=0 && arr[j] > key){
arr[j+1] = arr[j];
j--;
}
arr[j+1] = key;
}
}
void combineSort(int[] arr , int low, int mid, int high)
{
int n1 = mid - low + 1;
int n2 = high - mid;
int[] left = new int[n1];
int[] right = new int[n2];
for(int i =0;i<n1;i++)
left[i] = arr[i+low];
for(int j=0;j<n2;j++)
right[j] = arr[mid+1+j];
int i=0,j=0,k=low;
while(i < n1 && j < n2)
{
if(left[i] < right[j]){
arr[k] = left[i];
i++;
}
else{
arr[k] = right[j];
j++;
}
k++;
}
while(i < n1) {
arr[k++] = left[i];
i++;
}
while (j < n2) {
arr[k++] = right[j];
j++;
}
}
void mergeSort(int[] arr , int low, int high)
{
if(low < high){
int mid = low + (high-low)/2;
mergeSort(arr, low, mid);
mergeSort(arr, mid+1, high);
combineSort(arr, low, mid, high);
}
}
void commonelements(int[] arr, int[] brr)
{
int i=0;
int j=0;
while (i < arr.length && j < brr.length) {
if (i > 0 && arr[i] == arr[i - 1]){
i++;
continue;
}
if(arr[i] < brr[j])
i++;
else if(arr[i] > brr[j])
j++;
else{
if(arr[i] == brr[j]){
System.out.print(arr[i] + " ");
}
i++;
j++;
}
}
}
void unionElements(int[] arr, int[] brr)
{
int i = 0;
int j = 0;
while (i < arr.length && j < brr.length){
if(i > 0 && arr[i] == arr[i-1]) {
i++;
continue;
}
if(j > 0 && brr[j] == brr[j-1]){
j++;
continue;
}
if(arr[i] < brr[j]){
System.out.print(arr[i] + " ");
i++;
}
else if(arr[i] > brr[j]){
System.out.print(brr[j] + " ");
j++;
}
else{
System.out.print(brr[j] + " ");
j++;
i++;
}
}
while(i < arr.length){
if(arr[i] != arr[i-1])
System.out.print(arr[i] + " ");
i++;
}
while(j < brr.length){
if(brr[j] != brr[j-1])
System.out.print(brr[j] + " ");
j++;
}
}
int countInversion(int[] arr, int low, int high)
{
int res=0;
if(low < high){
int mid= (low+high)/2;
res += countInversion(arr, 0, mid);
res += countInversion(arr, mid+1, high);
res += mergeInverse(arr, low, mid, high);
}
return res;
}
int mergeInverse(int[] arr , int low, int mid, int high)
{
int n1 = mid - low + 1;
int n2 = high - mid;
int res=0;
int[] left = new int[n1];
int[] right = new int[n2];
for(int i =0;i<n1;i++)
left[i] = arr[i+low];
for(int j=0;j<n2;j++)
right[j] = arr[mid+1+j];
int i=0,j=0,k=low;
while(i < n1 && j < n2)
{
if(left[i] <= right[j]){
arr[k] = left[i];
i++;
}
else{
arr[k] = right[j];
res += n1 - i;
j++;
}
k++;
}
while(i < n1) {
arr[k++] = left[i];
i++;
}
while (j < n2) {
arr[k++] = right[j];
j++;
}
return res;
}
void twoTypesElementSortHoore(int[] arr){
int l = 0;
int r = arr.length - 1;
while(l < r)
{
while(arr[l] < 0 && l < r){
l++;
}
while (arr[r] > 0 && l < r){
r--;
}
if(l < r){
int t = arr[l];
arr[l] = arr[r];
arr[r] = t;
r--;
l++;
}
}
}
void twoTypesElementSortLomuto(int[] arr)
{
int i = -1;
// int k = arr[arr.length - 1];
int k = Integer.MAX_VALUE;
for(int j=0;j<arr.length;j++){
if(arr[j] < k && arr[j] >=0)
k = arr[j];
}
for(int j = 0;j<arr.length - 1;j++){
if(arr[j] < k){
i++;
int t = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
}
int temp = arr[arr.length - 1];
arr[arr.length - 1] = arr[i+1];
arr[i+1] = temp;
}
public static int getMaximum(int N, int[] arr) {
// code here
long sum = 0;
for(int i = 0;i<N;i++)
sum += arr[i];
while(N > 0)
{
if(sum % N == 0)
return N;
N--;
}
return 1;
}
public static boolean check(long A[],long B[],int N)
{
//Your code here
HashMap<Long , Integer> hm1 = new HashMap<>();
HashMap<Long , Integer> hm2 = new HashMap<>();
for(long i : A)
hm1.put(i, hm1.getOrDefault(i,0)+1);
for(long i : B)
hm1.put(i, hm2.getOrDefault(i,0)+1);
return hm1.equals(hm2);
}
public long minValue(long a[], long b[], long n)
{
// Your code goes here
Arrays.sort(a);
int i=0;
int t = (int) (n-1);
while(i < t)
{
long temp = b[i];
b[i] = b[t];
b[t] = temp;
t--;
i++;
}
long sum =0;
for(int j=0;j<n;j++)
sum += a[i]*b[i];
return sum;
}
static ArrayList<Integer> subarraySum(int[] arr, int n, int s) {
// Your code here
ArrayList<Integer> a = new ArrayList<>();
for (int i = 1; i < n; i++) {
arr[i] = arr[i - 1] + arr[i];
//System.out.print(arr[i] + " ");
}
int left = 0;
int right = 1;
if(n == 1 && arr[0] == s){
a.add(1);
a.add(1);
return a;
}
while (left <= right && right < n) {
if (arr[right] == s) {
a.add(1);
a.add(right + 1);
return a;
}
if (arr[left] == s) {
a.add(left + 1);
a.add(left + 1);
return a;
}
if (arr[right] - arr[left] < s)
right++;
else if (arr[right] - arr[left] > s)
left++;
else {
a.add(left + 2);
a.add(right + 1);
return a;
}
}
a.add(-1);
return a;
}
static int equilibrium(long[] arr, int n)
{
// long[] p = new long[n];
//
// if( n == 1)
// return 1;
//
// p[0] = arr[0];
// for(int i=1;i<n;i++)
// p[i] = p[i-1]+arr[i];
//
// long totalsum = p[n-1];
// for(int i=1;i<n;i++)
// {
// if(totalsum - p[i] == p[i-1])
// return i+1;
// }
// return -1;
long totalsum=0;
long cur_sum=0;
for(long l : arr)
totalsum += l;
for(int i = 0;i< n;i++){
if(totalsum - arr[i] - cur_sum == cur_sum)
return i;
cur_sum += arr[i];
}
return -1;
}
static ArrayList<Integer> leaders(int arr[], int n){
// Your code here
int l=0;
int h=n-1;
while(l <= h)
{
int t = arr[l];
arr[l] = arr[h];
arr[h] = t;
h--;
l++;
}
ArrayList<Integer> a = new ArrayList<>();
a.add(arr[0]);
int j=0;
int i=1;
while(i < n && j < i)
{
if(arr[i] >= arr[j]) {
a.add(arr[i]);
j = i;
}
i++;
}
Collections.reverse(a);
return a;
}
int maxLen(int arr[], int n)
{
// Your code here
HashMap<Integer, Integer> hm = new HashMap<>();
int cur=0;
int ans=0;
for(int i=0;i<n;i++)
{
cur += arr[i];
if(hm.containsKey(cur))
{
ans = Math.max(ans , i - hm.get(cur));
}
else
hm.put(cur,i);
}
int max = -1;
for(int i = n-1;i>=0;i--){
if(arr[i] == 0){
max = i + 1;
break;
}
}
return Math.max(ans, max);
}
public String isSubset( long a1[], long a2[], long n, long m) {
HashMap<Long, Integer> hm1 = new HashMap<>();
HashMap<Long, Integer> hm2 = new HashMap<>();
for (long l : a1) {
hm1.put(l, hm1.getOrDefault(l, 0) + 1);
}
for (long l : a2) {
hm2.put(l, hm2.getOrDefault(l, 0) + 1);
}
for (long l : a2) {
if (!hm1.get(l).equals(hm2.get(l)))
return "No";
}
return "Yes";
}
String longestCommonPrefix(String arr[], int n){
// code here
String s = "";
int l = findMinLength(arr, n);
for(int i = 0; i < l;i++)
{
char c = arr[0].charAt(i);
for(int j = 0;j<n;j++){
if(arr[j].charAt(i) != c)
return s;
s += c;
}
}
return s;
}
int findMinLength(String arr[], int n)
{
int min = arr[0].length();
for (int i = 1; i < n; i++)
{
if (arr[i].length() < min)
{
min = arr[i].length();
}
}
return (min);
}
long findSwapValues(long A[], int n, long B[], int m)
{
// Your code goes here
long sa = 0,sb=0;
Arrays.sort(A);
Arrays.sort(B);
for(int i=0;i<n;i++)
sa+=A[i];
for(int i=0;i<m;i++)
sb+=B[i];
//System.out.println(sa + " " + sb);
if(Math.abs(sa+sb) % 2 == 1)
return -1;
long dif = Math.max(sa,sb) - (sa+sb)/2;
int index=-1;
for(int i=0;i<n;i++)
{
long target = A[i] - dif;
if(dif > A[i])
target = A[i];
index = binarySearch(B, (int)target);
}
//System.out.println("Index 1 " + index);
if(index != -1)
return 1;
for(int i=0;i<m;i++)
{
long target = B[i] - dif;
if(dif > B[i])
target = B[i];
index = binarySearch(A, (int)target);
}
//System.out.println("Index 2 " + index);
if(index != -1)
return 1;
return -1;
}
public static int avgOfString(String s)
{
//Your code here
int sum = 0;
for(char c : s.toCharArray())
{
sum += c;
}
return sum;
}
public static String TieBreak(String names[], int n)
{
// your code here
HashMap<String, Integer> hm = new HashMap<>();
for(String name : names){
hm.put(name , hm.getOrDefault(name,0) +1);
}
int max = -1;
String pname = "";
String cname = "";
for(String s : hm.keySet()) {
int t = hm.get(s);
if(t > max) {
pname = s;
max = t;
}
else if(t == max && s.compareTo(pname) < 0)
pname = s;
}
System.out.println(hm);
return pname;
}
public static int sumOfDiff(int arr[], int n)
{
// Compute the sum as such
// sum of firstLargest and firstSmallest
// and so on..
Arrays.sort(arr);
int sum = 0;
int l = 0;
int h = n - 1;
while(l < h)
{
sum += Math.abs(arr[l] - arr[h]);
h--;
l++;
}
if(n%2==1)
sum += arr[n/2];
return sum;
}
void solve()
{
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while(T > 0) {
int N = scan.nextInt();
String s = scan.next();
StringBuilder sb = new StringBuilder();
for(int i = s.length() - 1; i >=0;)
{
//System.out.println("3");
if(s.charAt(i) != '0')
{
int t = Integer.parseInt(String.valueOf(s.charAt(i)));
sb.append(Character.toChars('a' + t - 1));
i--;
//System.out.println("1");
}
else
{
String s1 = s.substring(i-2, i);
int t = Integer.parseInt(s1);
sb.append(Character.toChars('a' + t - 1));
i=i-3;
//System.out.println("2");
}
}
T--;
System.out.println(sb.reverse());
}
}
static boolean search(long[] arr)
{
for(long l : arr)
if(l == 0)
return true;
return false;
}
public static void main(String[] temp) {
FileHandler f = new FileHandler();
// int[] arr = new int[6];
// for(int i=0;i<6;i++)
// arr[i] = i+2;
//
// f.printArrayRecursively(arr,6);
// System.out.println(f.RecursivePower(3,6));
// System.out.println(f.sumOfProductOfDigits(0,34));
f.solve();
// long [] a = {4,5,6,7};
// long[] b = {1,2,3,8};
// int n = 4;
// int m = 4;
// //System.out.println( f.findSwapValues(a,n,b,m));
// String[] s = {"Turin","Nick","Turin","Nick"};
// System.out.println(TieBreak(s, s.length));
// System.out.println(f.sqrt(36));
// BigInteger x = new BigInteger("69");
// BigInteger y = new BigInteger("34");
// System.out.println(x.add(y));
// System.out.println(x.multiply(y));
// System.out.println(y.remainder(x));
// BigInteger s = new BigInteger("1");
//
// int n = x.intValue();
// for(int i=1;i<=n;i++){
// s = s.multiply(BigInteger.valueOf(i));
// }
// System.out.println(s);
// System.out.println(Arrays.stream(arr).sum());
// System.out.println(Arrays.stream(arr).max().getAsInt());
// f.print1toN(20);
// System.out.println();
// f.printNto1(20);
// System.out.println();
// System.out.println(f.sumNatural(10 , 0));
// System.out.println(f.isPalindrome("abbbbbbbcaaaaaabaaacbbbbbbba" , 0));
// System.out.println(f.sumOfDigits(11000));
// System.out.println(f.ropeCutting(5,2,2,2));
// f.subsets("abc", "" , 0);
// System.out.println(f.towerOfHanoy(2 , 'A', 'B' , 'C'));
// System.out.println(f.countDigits(70000));
// System.out.println(f.isPalin(100001));
//System.out.println(f.recursiveGCD(2,6));
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 4298462244d051a27b9e0b7c1fa823a9 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for (int p = 0; p < N; p++) {
int n=sc.nextInt();
char[] ch=sc.next().toCharArray();
StringBuilder sb=new StringBuilder();
for(int i=0;i<n;i++){
if(ch[i]-'0'>3 || ch[i]-'0'==2 && (i+1)<n && ch[i+1]-'0'>6)
sb.append((char)(96+(int)(ch[i])-'0'));
else if((i+2)<n && ch[i+2]-'0'==0){
if((i+3)<n && ch[i+3]-'0'==0) {
sb.append((char)(96+(int)(ch[i]-'0')));
}
else
{
int a = (int) (ch[i] - '0') * 10 + (int) (ch[i + 1] - '0');
sb.append((char) (96 + a));
i += 2;
}
}
else
sb.append((char)(96+(int)(ch[i]-'0')));
}
System.out.println(sb);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | a6bc948aaa6c7490ead4ff4ef2319fb0 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | /*
Author:-crazy_coder-
*/
import java.io.*;
import java.util.*;
public class cp{
static int ans=0;
static BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
static PrintWriter pw=new PrintWriter(System.out);
public static void main(String[] args)throws Exception{
int T=Integer.parseInt(br.readLine());
// int t=1;
while(T-->0){
solve();
}
pw.flush();
}
public static void solve()throws Exception{
String[] str=br.readLine().split(" ");
int n=Integer.parseInt(str[0]);
String code=br.readLine();
String str1=" abcdefghijklmnopqrstuvwxyz";
StringBuilder sb=new StringBuilder();
int i=0;
for( i=0;i<n-3;i++){
if(code.charAt(i+2)=='0'&&code.charAt(i+3)=='0'){
sb.append(str1.charAt(code.charAt(i)-'0'));
}else if(code.charAt(i+2)=='0'){
int idx=Integer.parseInt(code.substring(i,i+2));
sb.append(str1.charAt(idx));
i+=2;
}else{
sb.append(str1.charAt(code.charAt(i)-'0'));
}
}
if(code.charAt(n-1)=='0'){
int idx=0;
if(n-3>=0)
idx=Integer.parseInt(code.substring(n-3,n-1));
else
idx=Integer.parseInt(code);
sb.append(str1.charAt(idx));
}else{
if(n-3>=0&&i<=n-3&&code.charAt(n-3)!='0')
sb.append(str1.charAt(code.charAt(n-3)-'0'));
if(n-2>=0&&i<=n-2&&code.charAt(n-2)!='0')
sb.append(str1.charAt(code.charAt(n-2)-'0'));
sb.append(str1.charAt(code.charAt(n-1)-'0'));
}
pw.println(sb);
}
public static int countDigit(int x){
return (int)Math.log10(x)+1;
}
//****************************function to find all factor*************************************************
public static ArrayList<Long> findAllFactors(long num){
ArrayList<Long> factors = new ArrayList<Long>();
for(long i = 1; i <= num/i; ++i) {
if(num % i == 0) {
//if i is a factor, num/i is also a factor
factors.add(i);
factors.add(num/i);
}
}
//sort the factors
Collections.sort(factors);
return factors;
}
//*************************** function to find GCD of two number*******************************************
public static long gcd(long a,long b){
if(b==0)return a;
return gcd(b,a%b);
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 6fe6111c597352f3b16a5e3ba907c8ce | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class examplee {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList<String> array = new ArrayList<>();
int q = in.nextInt();
char[] abs = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',};
for (int i = 0; i < q; i++) {
int n = in.nextInt();
String san = in.next();
String a = "";
String b = "";
while(san.length()!=0){
if(san.substring(n-1).equals("0")){
String aa=san.substring(n-3);
a+=abs[Integer.parseInt(aa.substring(0,aa.length()-1))-1]+"";
san=san.substring(0,n-3);
n=n-3;
}else{
String aa = san.substring((n-1));
san=san.substring(0,n-1);
a+=abs[Integer.parseInt(aa)-1]+"";
n=n-1;
}
}
for (int j = a.length()-1;j>=0;j--) {
b+=a.charAt(j);
}
array.add(b);
}
for (int i = 0; i < array.size(); i++) {
System.out.println(array.get(i));
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | ca5cd80b0e581ab2e00c8fa6025ee33c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
for(int i = 0; i < t; i++){
int n = scn.nextInt();
scn.nextLine();
String str = scn.nextLine();
System.out.println(decodeString(n, str));
}
scn.close();
}
public static String decodeString(int n, String t){
String s = "";
String ref = "_abcdefghijklmnopqrstuvwxyz";
for(int i = n-1; i >= 0; i--){
char ch = t.charAt(i);
if(ch == '0'){
int val = (10*(t.charAt(i-2) - '0')) + (t.charAt(i-1) - '0');
s = ref.charAt(val) + s;
i = i-2;
} else{
int val = t.charAt(i) - '0';
s = ref.charAt(val) + s;
}
}
return s;
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 1f6eb7e6c95898821e6b78f80a2a2f12 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class CodeF
{
public static void main(String[] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t-->0)
{
int n=Integer.parseInt(br.readLine());
/*String[] s= br.readLine().split(" ");
int a = Integer.parseInt(s[0]);
int b = Integer.parseInt(s[1]);
int c = Integer.parseInt(s[2]);*/
char s[] = br.readLine().toCharArray();
//int min=Integer.MAX_VALUE;
//int ans=0;
String ans="";
char ch[] = new char[27];
ch[1]='a';
for(int i=2;i<ch.length;i++)
ch[i]=(char)(ch[i-1]+1);
//System.out.println(ch);
int len=s.length;
if(len==1)
{
ans+=ch[s[0]-'0'];
//System.out.println("here 1");
}
else if(len==2)
{
ans+=ch[s[0]-'0'];
ans+=ch[s[1]-'0'];
//System.out.println("here 2");
}
else if(len==3)
{
if(s[2]=='0')//double digit alphabet
{
int index=(s[0]-'0');
index*=10;
index+=(s[1]-'0');
ans+=ch[index];
//System.out.println("here 3");
}
else//single digit alphabet
{
ans+=ch[s[0]-'0'];
ans+=ch[s[1]-'0'];
ans+=ch[s[2]-'0'];
//System.out.println("here 4");
}
}
else//length>3
{
for(int i=0; i<len;)
{
if(i+2<len && s[i+2]=='0')
{
if(i+3<len && s[i+3]=='0')//ith digit i a single digit
{
ans+=ch[s[i]-'0'];
i++;
//System.out.println("here 5");
}
else //ith digit is a double digit alphabet
{
int index=s[i]-'0';
index*=10;
index+=s[i+1]-'0';
ans+=ch[index];
i+=3;
//System.out.println("here 6");
}
}
else
{
ans+=ch[s[i]-'0'];
i++;
//System.out.println("here 7");
}
}
}
out.println(ans);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | ddf510daf63d71f587377f758f24b22c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class B {
public static void main(String[] args) throws IOException {
Reader sc = new Reader();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-- > 0) {
int n = sc.nextInt();
char[] arr = sc.next().toCharArray();
List<Character> list = new ArrayList<>();
char[] ch = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
for(int i = n - 1;i >= 0;i--) {
int a = 0;
int a2 = 0;
if(i - 2 >= 0 && arr[i] != '0')
a = Character.getNumericValue(arr[i]);
else if(i - 2 >= 0 && arr[i] == '0') {
if(i - 1 >= 0) {
a = Character.getNumericValue(arr[i - 1]);
a2 = Character.getNumericValue(arr[i - 2]);
a = (10 * a2) + a;
}
else
a = Character.getNumericValue(arr[i]);
i -= 2;
}
else
a = Character.getNumericValue(arr[i]);
// out.print(a + " ");
list.add(ch[a - 1]);
}
// out.println();
for(int i = list.size() - 1;i >= 0;i--)
out.print(list.get(i));
out.println();
}
out.flush();
}
public static boolean isPowerOfTwo(long k) {
double v1 = Math.log(k) / Math.log(2);
if(v1 - (Math.floor(v1)) > 0)
return false;
else
return true;
}
public static boolean checkPalindrome(int[] arr,int x) {
int n = arr.length;
int start = 0;
int end = n - 1;
while(start < end) {
if(arr[start] == x)
start++;
else if(arr[end] == x)
end--;
else if(arr[start] != arr[end])
return false;
else {
start++;
end--;
}
}
return true;
}
public static String bin(long n,long i) {
StringBuilder list = new StringBuilder();
list.append(0);
while(n > 0) {
list.append(n % i);
n = n / i;
}
return new String(list);
}
static int[] sort(int[] arr,int n) {
List<Integer> list = new ArrayList<>();
for(int i = 0;i < n;i++)
list.add(arr[i]);
Collections.sort(list);
for(int i = 0;i < n;i++)
arr[i] = list.get(i);
return arr;
}
static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static int isPrime(int n) {
if(n < 2)
return 0;
if(n < 4)
return 1;
if((n % 2) == 0 || (n % 3) == 0)
return 0;
for(int i = 5; (i * i) <= n; i += 6)
if((n % i) == 0 || (n % (i + 2)) == 0)
return 0;
return 1;
}
static class Reader {
BufferedReader br;
StringTokenizer st;
public Reader() {
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 {
if(st.hasMoreTokens())
str = st.nextToken("\n");
else
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
//class Pair {
// int a;
// int b;
// public Pair(int a,int b) {
// this.a = a;
// this.b = b;
// }
//}
// ********************* Custom Pair Class *********************
//class Pair implements Comparable<Pair> {
// int a,b;
// public Pair(int a,int b) {
// this.a = a;
// this.b = b;
// }
// @Override
// public int compareTo(Pair other) {
// if(this.b == other.b)
// return Integer.compare(other.a,this.a);
// return Integer.compare(this.b,other.b);
// }
//}
// ****************** Segment Tree ******************
//public class SegmentTreeNode {
// public SegmentTreeNode left;
// public SegmentTreeNode right;
// public int Start;
// public int End;
// public int Sum;
// public SegmentTreeNode(int start, int end) {
// Start = start;
// End = end;
// Sum = 0;
// }
//}
//public SegmentTreeNode buildTree(int start, int end) {
// if(start > end)
// return null;
// SegmentTreeNode node = new SegmentTreeNode(start, end);
// if(start == end)
// return node;
// int mid = start + (end - start) / 2;
// node.left = buildTree(start, mid);
// node.right = buildTree(mid + 1, end);
// return node;
//}
//public void update(SegmentTreeNode node, int index) {
// if(node == null)
// return;
// if(node.Start == index && node.End == index) {
// node.Sum += 1;
// return;
// }
// int mid = node.Start + (node.End - node.Start) / 2;
// if(index <= mid)
// update(node.left, index);
// else
// update(node.right, index);
// node.Sum = node.left.Sum + node.right.Sum;
//}
//public int SumRange(SegmentTreeNode root, int start, int end) {
// if(root == null || start > end)
// return 0;
// if(root.Start == start && root.End == end)
// return root.Sum;
// int mid = root.Start + (root.End - root.Start) / 2;
// if(end <= mid)
// return SumRange(root.left, start, end);
// else if(start > mid)
// return SumRange(root.right, start, end);
// return SumRange(root.left, start, mid) + SumRange(root.right, mid + 1, end);
//} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0e933f4d4e1bb8a6ac6db4370c312365 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
int test = read.nextInt();
while(test-- > 0){
int n = read.nextInt();
read.nextLine();
String s = read.nextLine();
List<Character> result = new ArrayList<Character>();
for (int i = n-1; i >=0; i--){
if (s.charAt(i) !='0'){
String number = s.charAt(i)+"";
result.add((char)(96+Integer.parseInt(number)));
}
else {
String number = ""+s.charAt(i-2)+s.charAt(i-1);
result.add((char)(96+Integer.parseInt(number)));
i -= 2;
}
}
Collections.reverse(result);
s = "";
for (char c : result){
s +=c;
}
System.out.println(s);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | c437d2d59cbe8e8d68007047668adfd5 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i= 0; i< t; i++){
int n = sc.nextInt();
String st = sc.next();
String res = findAnswer(st);
System.out.println(res);
}
}
public static String findAnswer(String st){
char ch[] = st.toCharArray();
String res = "";
for(int i = st.length()-1; i >= 0; i--){
int el = 0;
if(ch[i] == '0'){
el = (ch[i-2]-'0');
el = (el *10) + (ch[i-1]-'0');
i = i-2;
}else{
el = (ch[i]-'0');
}
res = String.valueOf((char)(96+el)) + res;
}
return res;
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 50d9fcf1115144ae067a225025318043 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class testImp {
static void fun2(String str) {
String res = "";
//System.out.println("-> " + str);
for(int i = 0; i < str.length(); i++) {
if(str.charAt(i) == '0') continue;
if(i == str.length() - 3 && str.charAt(i + 2) == '0') {
res += (char)(Integer.parseInt(str.substring(i, i + 2)) + 96);
i++;
} else if (i == str.length() - 3 && str.charAt(i + 2) != '0') {
res += (char)(Integer.parseInt(str.substring(i, i + 1)) + 96);
} else if ((i == str.length() - 2 || i == str.length() - 1) && str.charAt(i) != '0') {
res += (char)(Integer.parseInt(str.substring(i, i + 1)) + 96);
} else if ( str.charAt(i + 2) == '0' && str.charAt(i + 3) == '0') {
res += (char)(Integer.parseInt(str.substring(i, i + 1)) + 96);
} else if (str.charAt(i + 2) == '0' && str.charAt(i + 3) != '0') {
res += (char)(Integer.parseInt(str.substring(i, i + 2)) + 96);
i++;
} else {
res += (char)(Integer.parseInt("" + str.charAt(i)) + 96);
}
}
System.out.println(res);
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-->0) {
int n = s.nextInt();
String str = s.next();
fun2(str);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | c74acd1f3a6e1ead99c9391638d788d1 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class testImp {
static void fun1(int a, int b, int c) {
int ab = Math.abs(b - c) + Math.abs(c - 1);
int bc = Math.abs(a - 1);
int ans = 3;
if (ab < bc) ans = 2;
if (bc < ab) ans = 1;
System.out.println(ans);
}
static void fun2(String str) {
String res = "";
//System.out.println("-> " + str);
for(int i = 0; i < str.length(); i++) {
if(str.charAt(i) == '0') continue;
if(i == str.length() - 3 && str.charAt(i + 2) == '0') {
res += (char)(Integer.parseInt(str.substring(i, i + 2)) + 96);
i++;
} else if (i == str.length() - 3 && str.charAt(i + 2) != '0') {
res += (char)(Integer.parseInt(str.substring(i, i + 1)) + 96);
} else if ((i == str.length() - 2 || i == str.length() - 1) && str.charAt(i) != '0') {
res += (char)(Integer.parseInt(str.substring(i, i + 1)) + 96);
} else if ( str.charAt(i + 2) == '0' && str.charAt(i + 3) == '0') {
res += (char)(Integer.parseInt(str.substring(i, i + 1)) + 96);
} else if (str.charAt(i + 2) == '0' && str.charAt(i + 3) != '0') {
res += (char)(Integer.parseInt(str.substring(i, i + 2)) + 96);
i++;
} else {
res += (char)(Integer.parseInt("" + str.charAt(i)) + 96);
}
}
System.out.println(res);
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-->0) {
int n = s.nextInt();
String str = s.next();
fun2(str);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 114fc2798287ab335230199ba8799f8b | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.ArrayDeque;
import java.util.Scanner;
public class code {
public static void main(String[] args) {
ArrayDeque<Integer> st = new ArrayDeque<>();
String str;
int t, n;
Scanner sc = new Scanner(System.in);
StringBuilder ans = new StringBuilder();
t = sc.nextInt();
sc.nextLine();
while(t != 0){
n = sc.nextInt();
sc.nextLine();
str = sc.nextLine();
for(int i = 0 ; i < str.length() ;i++){
if(str.charAt(i) == '0'){
if(i <= str.length() - 2 && str.charAt(i + 1) == '0')st.addLast(Character.getNumericValue(str.charAt(i)));
else{
int temp = st.pollLast() + st.pollLast() * 10;
st.addLast(temp);
}
}
else{
st.addLast(Character.getNumericValue(str.charAt(i)));
}
}
while(!st.isEmpty()){
int temp = st.pollFirst();
ans.append((char)(96 + temp));
}
System.out.println(ans);
ans.delete(0, ans.length());
t--;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | c81a4c694e8f1e81cde0c28bb04a42be | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.util.stream.Collectors;
public class CDF5polyCarp {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
char[] alpha = "abcdefghijklmnopqrstuvwxyz".toCharArray();
while(t>0) {
int n = sc.nextInt();
String num = sc.next();
String word = "";
//int[] numArr = Integer.toString(num).chars().map(c -> c-'0').toArray();
String strArray[] = num.split("");
//char[] num1 = convert(strArray);
for(int i=(n-1); i>=0;) {
if(Integer.parseInt(strArray[i]) == 0) {
int cNum = (Integer.parseInt(strArray[i-2]))*10 + Integer.parseInt(strArray[i-1]);
word = word + alpha[cNum-1];
i = i-3;
}
else {
int cNum = Integer.parseInt(strArray[i]);
word = word + alpha[cNum -1];
i = i-1;
}
}
StringBuilder input1 = new StringBuilder();
input1.append(word);
input1.reverse();
System.out.println(input1);
t--;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | e3c95afedaeeff77b28df7c4e15fe525 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
new Thread(null, () -> new Main().run(), "1", 1 << 23).start();
}
private void run() {
FastReader scan = new FastReader();
PrintWriter out = new PrintWriter(System.out);
Solution solve = new Solution();
int t = scan.nextInt();
// int t = 1;
for (int qq = 0; qq < t; qq++) {
solve.solve(scan, out);
out.println();
}
out.close();
}
}
class Solution {
/*
* think and coding
*/
static long MOD = (long) (1e9);
double EPS = 0.000_0001;
int numberCount = 1;
public void solve(FastReader scan, PrintWriter out) {
int n = scan.nextInt();
char[] s = scan.nextLine().toCharArray();
StringBuilder ans = new StringBuilder();
for (int i = s.length - 1; i >= 0;) {
char a;
if (s[i] == '0') {
a = (char) (((s[i - 2] - '0') * 10 + s[i - 1] - '0') + 96);
i -= 3;
} else {
a = (char) (s[i] - '0' + 96);
i--;
}
ans.append(a);
}
for (int i = ans.length() - 1; i >= 0; i--) {
out.print(ans.charAt(i));
}
// String s = scan.nextLine();
// Pair[] dp = new Pair[s.length()];
// ArrayList<Integer> list = new ArrayList<>();
// for (int i = 0; i < s.length(); i++) {
// dp[i] = new Pair((int) s.charAt(i) - 'a' + 1, i + 1);
// }
// Arrays.sort(dp);
// int cost = 0;
// for (int i = dp.length - 2; i >= 1; i--) {
// cost += dp[i].a - dp[i - 1].a;
// list.add(dp[i])
// }
// out.println(Arrays.toString(dp));
}
int lower(int val, Pair[] arr) {
int l = -1, r = arr.length;
while (r - l > 1) {
int mid = (r + l) / 2;
if (arr[mid].a < val) {
l = mid;
} else r = mid;
}
return r;
}
static class Pair implements Comparable<Pair> {
int a, b;
public Pair(int a, int b) {
this.a = a;
this.b = b;
}
public Pair(Pair p) {
this.a = p.a;
this.b = p.b;
}
@Override
public int compareTo(Pair p) {
return Integer.compare(a, p.a);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
return a == pair.a && b == pair.b;
}
@Override
public int hashCode() {
return Objects.hash(a, b);
}
@Override
public String toString() {
return "Pair{" + "a=" + a + ", b=" + b + '}';
}
}
}
class FastReader {
private final BufferedReader br;
private StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(new File(s)));
}
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;
}
int[] initInt(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
long[] initLong(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 56f219112d78f59e5c7a212d00d332e8 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class B_Decode_String {
public 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 {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader reader = new FastReader();
int T = reader.nextInt();
while(T!=0){
T--;
int N = reader.nextInt();
String s = reader.next();
int index = s.length()-1;
StringBuilder sb = new StringBuilder();
while(index!=-1){
// int digit = (int)(num%10);
int digit = Integer.parseInt(String.valueOf(s.charAt(index)));
if(digit==0){
// num = num/10;
index--;
int d1 = Integer.parseInt(String.valueOf(s.charAt(index)));
// num = num/10;
index--;
int d2 = Integer.parseInt(String.valueOf(s.charAt(index)));
index--;
int res = d2*10 + d1;
// System.out.println("res"+ res);
res--;
sb.append((char)(97+res));
}
else{
// System.out.println("digit"+ digit);
sb.append((char)(97+digit-1));
index--;
}
}
System.out.println(sb.reverse().toString());
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0dee3e8aab3966957adbacb41c0060b9 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.*;
import java.util.*;
public class Main {
static Deque<Character> q = new LinkedList<>();
public static void main(String[] args) throws IOException {
Reader read = new Reader();
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
int t = read.nextInt();
while(t-->0) {
int n = read.nextInt();
read.nextLine();
String s = read.nextLine();
char[] c = s.toCharArray();
char[] ans = new char[n+10];
int cnt = 0;
for(int i=0;i<n;i++) {
if(!q.isEmpty()&&c[i]=='0'&&(i==n-1||c[i+1]!='0')) {
int c1 = q.pollFirst()-'0';
int c2 = q.pollFirst()-'0';
q.addFirst((char)((c2*10+c1-1)+'a'));
}
else
q.addFirst(c[i]);
}
while(!q.isEmpty()) {
char c1 = q.pollLast();
if(c1>='0'&&c1<='9')
ans[++cnt] = (char)(((c1-'0')-1)+'a');
else
ans[++cnt] = c1;
}
for(int i=1;i<=cnt;i++)
out.print(ans[i]);
out.println();
}
out.flush();
}
}
class Reader{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StreamTokenizer st = new StreamTokenizer(bf);
public int nextInt()throws IOException{
st.nextToken();
return (int)st.nval;
}
public double nextDouble()throws IOException{
st.nextToken();
return st.nval;
}
public String nextLine()throws IOException{
return bf.readLine();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 94c5b5650362f4fe3d8ceabcb186539a | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while(t-- > 0){
int n = scn.nextInt();
String str = scn.next();
String res = "";
for(int i=n-1;i>=0;i--){
char ch = str.charAt(i);
if(ch=='0'){
String num = "";
int j = i;
i -= 2;
num = str.substring(i,j);
int index = Integer.parseInt(num);
res = Character.toString((char)((index-1) + 'a')) +res;
}
else{
res = Character.toString((char)(ch-1-'0'+'a')) + res;
}
}
System.out.println(res);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | dd9cf2df3aecb21ffd5b6de2c6c3c100 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.util.ArrayList;
import java.util.Scanner;
public class Contest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t;
t = sc.nextInt();
String result[] = new String[t];
for (int i = 0; i < t; i++) {
int l;
l = sc.nextInt();
String test;
test = sc.next();
sc.nextLine();
result[i] = "";
String array[] = new String[l];
for (int j = 0; j < l; j++) {
array[j] = "";
}
int k = 0;
for (int j = 0; j < test.length(); j++) {
if (test.charAt(j) == '0') {
continue;
}
if (j + 2 < test.length() && test.charAt(j+2)=='0' ) {
if(j+3<test.length() && test.charAt(j+3)=='0'){
array[k] = array[k] + test.charAt(j);
k++;
continue;
}
array[k] = array[k] + test.charAt(j) + test.charAt(j + 1);
k++;
j++;
} else {
array[k] = array[k] + test.charAt(j);
k++;
}
}
for (int j = 0; j < k; j++) {
result[i]=result[i]+(char)(Integer.parseInt(array[j])+96);
}
}
for (int i = 0; i < t; i++) {
System.out.println(result[i]);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 2fe6e1582aad03d69bc1b52364ca0349 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.util.*;
public class Main {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
// Your code here
long t= scan.nextLong();
while(t>0){
int n= scan.nextInt();
String s= scan.next();
StringBuilder sb=new StringBuilder();
for(int i=0;i<s.length();i++){
if(s.charAt(i)!='0'){
int v=Integer.parseInt(String.valueOf(s.charAt(i)));
sb.append((char)(v+96));
}
else{
String s1="";
if(i-2>=0) {
s1 += s.charAt(i - 2);
}
s1+=s.charAt(i-1);
if(i+1<s.length()){
if(s.charAt(i+1)=='0'){
sb.deleteCharAt(sb.length()-1);
s1="";
s1+=s.charAt(i-1);
s1+=s.charAt(i);
int v=Integer.parseInt(s1);
sb.append((char)(v+96));
i++;
}
else{
sb.deleteCharAt(sb.length()-1);
sb.deleteCharAt(sb.length()-1);
int v=Integer.parseInt(s1);
sb.append((char)(v+96));
}
}
else{
sb.deleteCharAt(sb.length()-1);
sb.deleteCharAt(sb.length()-1);
int v=Integer.parseInt(s1);
sb.append((char)(v+96));
}
}
}
System.out.println(sb);
t--;
}
}
static class Pair{
long a;
long b;
Pair(long a,long b){
this.a=a;
this.b=b;
}
}
public static void scanarr(long a[],int n) {
for(int i=0;i<n;i++){
a[i]= scan.nextLong();
}
}
public static long gcd(long a, long b)
{
if(a > b)
a = (a+b)-(b=a);
if(a == 0L)
return b;
return gcd(b%a, a);
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 8ae9dd38939e287de52426efc10564fd | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | //created by Toufique on 12/09/2022
import java.io.*;
import java.util.*;
public class Div3_820B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int t = in.nextInt();
for (int tt = 0; tt < t; tt++) {
HashMap<Integer, Character> map = new HashMap<>();
int n = in.nextInt();
char[] s = in.next().toCharArray();
for (int i = n - 1; i >= 2; i--) {
if (s[i] == '.') continue;
if (s[i] == '0') {
char a = s[i - 2];
char b = s[i - 1];
map.put(i, getChar(a, b));
s[i - 2] = '.';
s[i - 1] = '.';
}else {
char a = s[i];
map.put(i, getChar(a));
}
}
for (int i = 0; i < Math.min(2, n); i++) {
if (s[i] != '.') {
map.put(i, getChar(s[i]));
}
}
for (int i = 0; i < n; i++) {
if (!map.containsKey(i)) continue;
pw.print(map.get(i));
}
pw.println();
}
pw.close();
}
static char getChar(char a, char b) {
int v = a - '0';
int v2 = b - '0';
int ind = v * 10 + v2;
ind--;
return (char)('a' + ind);
}
static char getChar(char a) {
int ind = a - '0';
ind--;
return (char)('a' + ind);
}
static void debug(Object... obj) {
System.err.println(Arrays.deepToString(obj));
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 332781e94297cc76928baa53a30780ca | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class p1
{
BufferedReader br;
StringTokenizer st;
BufferedWriter bw;
public static void main(String[] args)throws Exception
{
new p1().run();
}
void run()throws IOException
{
br = new BufferedReader(new InputStreamReader(System.in));
bw=new BufferedWriter(new OutputStreamWriter(System.out));
solve();
}
void solve() throws IOException
{
int t=ni();
while(t-->0)
{
int n=ni();
char c[]=nac();
char d[]=new char[n];
int d1=0;
for(int i=n;--i>=0;)
{
if(c[i]=='0')
{
int x=(c[i-2]-48)*10+c[i-1]-48;
d[d1++]=(char)(97+x-1);
i-=2;
}
else
{
d[d1++]=(char)(97+c[i]-1-48);
}
}
for(int i=d1;--i>=0;)
bw.write(d[i]);
bw.write("\n");
}
bw.flush();
}
/////////////////////////////////////// FOR INPUT ///////////////////////////////////////
int[] nai(int n) { int a[]=new int[n]; for(int i=-1;++i<n;)a[i]=ni(); return a;}
Integer[] naI(int n) { Integer a[]=new Integer[n]; for(int i=-1;++i<n;)a[i]=ni(); return a;}
long[] nal(int n) { long a[]=new long[n]; for(int i=-1;++i<n;)a[i]=nl(); return a;}
char[] nac() {char c[]=nextLine().toCharArray(); return c;}
char [][] nmc(int n) {char c[][]=new char[n][]; for(int i=-1;++i<n;)c[i]=nac(); return c;}
int[][] nmi(int r, int c) {int a[][]=new int[r][c]; for(int i=-1;++i<r;)a[i]=nai(c); return a;}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {st = new StringTokenizer(br.readLine());}
catch (IOException e) {e.printStackTrace();}
}
return st.nextToken();
}
int ni() { return Integer.parseInt(next()); }
byte nb() { return Byte.parseByte(next()); }
short ns() { return Short.parseShort(next()); }
long nl() { return Long.parseLong(next()); }
double nd() { return Double.parseDouble(next()); }
String nextLine()
{
String str = "";
try {str = br.readLine();}
catch (IOException e) {e.printStackTrace();}
return str;
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 7c12aa7cc708f7f8177d6a48a4d027ec | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static boolean isfile = false;
static final String FileName = "input";
static PrintWriter out = new PrintWriter(System.out);
static FastReader fr = new FastReader();
static int OO = (int) 1e9;
public static void main(String[] args) throws FileNotFoundException {
if (isfile) {
fr = new FastReader(FileName + ".txt");
out = new PrintWriter(new File("output.txt"));
}
int tt = 1;
tt = fr.nextInt();
while (tt-- > 0) {
solve();
}
out.close();
}
public static void solve() {
int n = fr.nextInt();
String s = fr.next();
String s2 = "";
for (int i = n-1; i >=0; i--) {
if (s.charAt(i)!='0') {
char x = (char)(Integer.parseInt(s.charAt(i)+"")+96);
s2=x+s2;
}else {
i-=2;
char x = (char)(Integer.parseInt(s.charAt(i)+""+s.charAt(i+1)+"")+96);
s2=x+s2;
}
}
out.println(s2);
}
static class FastReader {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
public FastReader(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(new File(s)));
}
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
return st.nextToken();
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
Long[] readArrayL(int n) {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
public static int lcm(int a, int b) {
return a * b / gcd(a, b);
}
public static int gcd(int a, int b) {
while (b != 0) {
int m = a % b;
a = b;
b = m;
}
return a;
}
public static long factorial(int n) {
if (n == 0)
return 1;
long res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
public static long nCr(int n, int r) {
return factorial(n) / (factorial(r) * factorial(n - r));
}
public static ArrayList<Integer> factors(long n) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = 2; i < n / i; i++) {
while (n % i == 0) {
if (!list.contains(i)) {
list.add(i);
n /= i;
}
}
}
if (n > 2) {
if (!list.contains((int) n)) {
list.add((int) n);
}
}
return list;
}
public static int numOfPrimes(int n) {
if (n < 2) {
return 0;
}
boolean[] bool = new boolean[n + 1];
outer: for (int i = 2; i < bool.length / i; i++) {
if (bool[i]) {
continue outer;
}
for (int j = 2 * i; j < bool.length; j += i) {
bool[j] = true;
}
}
int counter = 0;
for (int i = 0; i < bool.length; i++) {
if (!bool[i]) {
counter++;
}
}
return counter;
}
public static int numOfDivisors(int x) {
int to = 0;
for (int i = 1; i <= Math.sqrt(x); i++) {
if (x % i == 0) {
if (x / i == i) {
to++;
} else {
to += 2;
}
}
}
return to;
}
public static long fastPow(long a, long n, long mod) {
long ret = 1;
int x = 63 - Long.numberOfLeadingZeros(n);
for (; x >= 0; x--) {
ret = ret * ret % mod;
if (n << 63 - x < 0)
ret = ret * a % mod;
}
return ret;
}
public static void sort2DGivenArray(int[][] arr, int colNum) {
Arrays.sort(arr, (val1, val2) -> {
if (val1[colNum] == val2[colNum]) {
return 0;
} else if (((Integer) (val1[colNum])).compareTo(((Integer) (val2[colNum]))) < 0) {
return 1;
} else {
return -1;
}
});
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 32a64d50e9310f7de3b244c84fc7516c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int q=sc.nextInt();
while (q-->0){
int n=sc.nextInt();
String s=sc.next();
int i=n-1;
StringBuilder sb=new StringBuilder();
while (i>=0){
char c=s.charAt(i);
if(c=='0'){
int x=s.charAt(i-1)-'0';
int y=s.charAt(i-2)-'0';
int val=y*10+x;
char temp=(char)('a'+(val-1));
sb.append(temp);
i=i-3;
}
else {
char temp=(char)('a'+(c-'1'));
sb.append(temp);
i--;
}
}
System.out.println(sb.reverse().toString());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | b07826c98502764a21326b142f974f1b | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
//Gaurav......
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
import java.io.*;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.math.*;
public class Main {
//start
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t=sc.nextInt();
while(t-->0){
char cha[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',};
int n=sc.nextInt();
String s=sc.next();
StringBuilder sb=new StringBuilder();
for(int i=s.length()-1;i>=0;i--){
if(s.charAt(i)=='0'){
String st=""+s.charAt(i-2)+s.charAt(i-1);
int val=Integer.parseInt(st);
char c=cha[val-1];
sb.insert(0,c);
i=i-2;
}else{
String st=s.charAt(i)+"";
int val=Integer.parseInt(st);
char c=cha[val-1];
sb.insert(0,c);
}
}
System.out.println(sb.toString());
}
}
//end
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0780b689d8d70e7608127e80e098f6ef | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0;i<t;i++){
int n = sc.nextInt();
String s = sc.next();
StringBuilder str = new StringBuilder();
for(int j=n-1;j>=0;j--){
char a = s.charAt(j);
int ans;
if(a=='0') {
ans = 96 + ((s.charAt(j - 1) - '0')+(s.charAt(j - 2) - '0')*10);
j = j-2;
}
else{
ans = 96 + a - '0';
}
str.append((char) ans);
}
str.reverse();
System.out.println(str);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | e95a6a4f7e657f7ac1416548c0000837 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
String s=sc.next();
StringBuffer sb=new StringBuffer();
for(int i=s.length()-1;i>=0;){
if(s.charAt(i)!='0') {
int x=s.charAt(i)-'0';
sb.append((char)(x+96));
i--;
}
else{
int x=Integer.parseInt(s.substring(i-2,i));
sb.append((char)(x+96));
i-=3;
}
}
System.out.println(sb.reverse());}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | d382d36f5e3057202744032161f9f783 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
int n = Integer.parseInt(br.readLine());
String s = br.readLine();
System.out.println(solve(s));
}
}
public static String solve(String s) {
if (s.length() < 3) {
StringBuilder ans = new StringBuilder();
for (char c : s.toCharArray()) {
ans.append((char) (c - '1' + 'a'));
}
return ans.toString();
} else if (s.length() >= 4 && s.charAt(3) == '0') {
char a = (char) (s.charAt(0) - '1' + 'a');
if (s.length() >= 5 && s.charAt(4) == '0') {
return a + solve(s.substring(1));
}
char b = (char) (Integer.parseInt(s.substring(1, 3)) - 1 + 'a');
return a + (b + solve(s.substring(4)));
} else if (s.charAt(2) == '0') {
return (char) (Integer.parseInt(s.substring(0, 2)) - 1 + 'a') + solve(s.substring(3));
} else {
return solve(s.substring(0, 2)) + solve(s.substring(2));
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 09f23a1cb451a0c3b1f1fa1daa041a1f | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | //package com.company;
import java.io.*;
import java.util.*;
public class Cf_0 {
private static class FastReader {
InputStream is;
private byte[] inbuf = new byte[1024];
private int lenbuf = 0, ptrbuf = 0;
public FastReader(InputStream is) {
this.is = is;
}
public 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++];
}
public boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
public String next() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public String nextLine() {
int c = skip();
StringBuilder sb = new StringBuilder();
while (!isEndOfLine(c)) {
sb.appendCodePoint(c);
c = readByte();
}
return sb.toString();
}
public int nextInt() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = (num << 3) + (num << 1) + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
public long nextLong() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = (num << 3) + (num << 1) + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
public double nextDouble() {
return Double.parseDouble(next());
}
public char[] next(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);
}
public char readChar() {
return (char) skip();
}
public long[] readArrayL(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) arr[i] = nextLong();
return arr;
}
public int[] readArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = nextInt();
return arr;
}
}
private static PrintWriter pw= new PrintWriter(System.out);
private static FastReader fr= new FastReader(System.in);
public static void main(String[] args) throws IOException {
int t= fr.nextInt();
for(int i=0;i<t;i++){
int dummy= fr.nextInt();
pwl(solve800(fr.next()));
}
pw.close();
}
public static String solve800(String str){
StringBuilder sb= new StringBuilder();
HashMap<Integer,Character>map= new HashMap<>();
int count=0;
for(char i='a';i<='i';i++){
map.put(++count,i);
}
for(char i='j';i<='z';i++){
map.put(++count*10,i);
}
int itr=str.length()-1;
while(itr!=-1){
if(str.charAt(itr)=='0'){
String temp= str.substring(itr-2,itr+1);
//System.out.println(temp);
int t=Integer.parseInt(temp);
sb.append(map.get(t));
itr=itr-3;
}
else {
StringBuilder s= new StringBuilder();
s.append(str.charAt(itr));
sb.append(map.get(Integer.parseInt(s.toString())));
itr--;
}
}
return sb.reverse().toString();
}
public static long[]readLong(int n){
long []a= new long[n];
for(int it=0;it<n;it++){
a[it]=fr.nextLong();
}
return a;
}
public static int[] readArray(int n){
int []a= new int[n];
for(int it=0;it<n;it++){
a[it]=fr.nextInt();
}
return a;
}
public static int min(int []a){
int min=a[0];
for(int i=1;i<a.length;i++){
min=Math.min(min,a[i]);
}
return min;
}
public static int max(int []a){
int max=a[0];
for(int i=1;i<a.length;i++){
max=Math.max(max,a[i]);
}
return max;
}
public static int getDown(int n){
if(n==0)
return 9;
else return --n;
}
public static int getUp(int n){
if(n==9)
return 0;
else return ++n;
}
public static long findGCD(long a, long b) {
while(b != 0)
{
if(a > b)
{
a = a - b;
}
else
{
b = b - a;
}
}
return a;
}
public static long lcm(long a, long b) {
return (a / findGCD(a, b)) * b;
}
public static void print(int []a){
StringBuilder sb= new StringBuilder();
for(int t:a){
sb.append(t+" ");
}
pwl(sb.toString());
}
public static void pwl(String s){
pw.println(s);
}
public static void pw(String s){
pw.print(s);
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 3d8b1c3df3e849eae6a018bf262de128 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class B1729 {
static FastScanner sc = new FastScanner();
public static void main(String[] args) {
int T = sc.nextInt();
while (T-- > 0) {
solve();
}
}
public static void solve() {
int n = sc.nextInt();
String s = sc.next();
String a = "";
for (int i = n - 1; i >= 0; i--) {
if (s.charAt(i) == '0') {
a += Character.toString((char)(96 + (10 * Character.getNumericValue(s.charAt(i - 2)) + Character.getNumericValue(s.charAt(i - 1)))));
i -= 2;
} else {
a += Character.toString((char)(96 + Character.getNumericValue(s.charAt(i))));
}
}
StringBuilder ans = new StringBuilder(a);
System.out.println(ans.reverse());
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
return a;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 9b20b68409a782c1b8461669c7a58fbe | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Decode {
public static void main(String arg[])
{
Scanner scan=new Scanner(System.in);
int t=scan.nextInt();
for(int i=0;i<t;i++)
{
int l=scan.nextInt();
String str=scan.next();
int j=l-1;
String str1="";
while(j>=0)
{
if(str.charAt(j)=='0')
{
str1=(char)(Integer.parseInt(str.substring(j-2,j))+96)+str1;
j-=3;
}
else
str1=(char)(str.charAt(j--)+96-48)+str1;
}
System.out.println(str1);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 20536b4048cc7e30b0bba407a5da2d61 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | //package com.company;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.IntStream;
import java.math.*;
public class Scanner {
static boolean[] x;
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
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 long[] nextlongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public Long[] nextLongArray(int n) throws IOException {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
/*public static void luckyNumbers(int a, int b, ArrayList x) {
if(a>Math.pow(10,9) || b>Math.pow(10,9))
return;
x.add(a);
x.add(b);
luckyNumbers((a*10)+4,(b*10)+4,x);
luckyNumbers((a*10)+7,(b*10)+7,x);
} */
public static void prefixSum(long[] prefix, long[] steps) { // prefix Sum for the cost Array
prefix[0] = steps[0];
for(int i=1;i<steps.length;i++)
prefix[i] = prefix[i-1] + steps[i];
}
public static void prefixSumSorted(Integer[] costSorted, long[] prefixSum) { // prefix Sum for the sorted cost Array
prefixSum[0] = costSorted[0];
for(int i=1;i<costSorted.length;i++)
prefixSum[i] = prefixSum[i-1] + costSorted[i];
}
/* public static boolean isOperator(char c) {
return c == '^' || c == '/' || c == '*' || c == '+' || c == '-';
}
public static int getPrecedence(char c) {
case '+', '-' -> 1;
case '*', '/' -> 3;
default -> 5;
};
} */
public static boolean isPrime (int a) {
for(int i=2;i<a;i++) {
if(a%i == 0)
return false;
}
return true;
}
/*public static int getP(int y) {
int p = 0;
for(int i=2;i<=y;i++) {
if(y%i == 0 && x.contains(y))
p++;
}
return p;
} */
public static void luckyNumbers(long a, ArrayList x) {
if(a>Math.pow(10,15))
return;
if(a!=0)
x.add(a);
luckyNumbers(a*10+4,x);
luckyNumbers(a*10+7,x);
}
public static boolean isFullCol(char[][] x, int j , char c) {
boolean flag = false;
for(int i=0;i<8;i++) {
if(x[i][j] != c) {
flag = true;
break;
}
}
return !flag;
}
public static boolean isFullRow(char[][] x, int j , char c) {
boolean flag = false;
for(int i=0;i<8;i++) {
if(x[j][i] != c) {
flag = true;
break;
}
}
return !flag;
}
// CODE STARTS HERE
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
int t = sc.nextInt();
for(int i=0;i<t;i++) {
int n = sc.nextInt();
String code = sc.next();
StringBuilder res = new StringBuilder();
for(int j=code.length()-1;j>=0;j--) {
if(code.charAt(j) == '0') {
char k = code.charAt(j-2);
char m = code.charAt(j-1);
String f = ""+k+m;
int index = Integer.parseInt(f);
res.insert(0,alphabet[index-1]);
j-=2;
}
else {
res.insert(0,alphabet[Character.getNumericValue(code.charAt(j))-1]);
}
}
System.out.println(res);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | a6284a9950dc4d4d9723310ea836b2a8 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
scanner.nextLine();
while (t-- != 0) {
int n = scanner.nextInt();
scanner.nextLine();
String s = scanner.nextLine();
String ans = "";
for(int i = s.length()-1; i >= 0; ){
if(s.charAt(i) == '0'){
int x = Integer.parseInt( s.charAt(i-2) + "" + s.charAt(i-1));
ans = ( (char) (x + 96)) + ans;
i -= 3;
}else {
ans = (char) (Integer.parseInt(s.charAt(i) + "") + 96) + ans;
i--;
}
}
System.out.println(ans);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | e17c64133042d74b74a5a8215d8e1155 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.util.Scanner;
public class ProblemB {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int test = 0; test < t; test++) {
int n = sc.nextInt();
String s = sc.next();
int j = s.length() - 1;
StringBuilder decoded = new StringBuilder();
while (j >= 0) {
char c = s.charAt(j);
if (s.charAt(j) == '0') {
String code = "" + s.charAt(j - 2) + s.charAt(j - 1);
decoded.append((char)('a' + Integer.parseInt(code) - 1));
j -= 3;
} else {
decoded.append((char)('a' + (c - '0') - 1));
j--;
}
}
System.out.println(decoded.reverse().toString());
}
sc.close();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 72809be377b8668808111cf6f6413d92 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
//https://codeforces.com/contest/1729/problem/B
import java.util.Scanner;
public class DecodeString {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while (t-- > 0) {
int n = scan.nextInt();
String code = scan.next();
StringBuilder output = new StringBuilder("");
for (int i = n - 1; i >= 0; ) {
int x;
if (code.charAt(i) == '0') {
x = (code.charAt(i - 2) - 48) * 10 + (code.charAt(i - 1) - 48);
i = i - 3;
} else {
x = code.charAt(i) - 48;
i--;
}
x--;
char c = (char) (x + 97);
output.insert(0,c);
}
System.out.println(output);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 83e514756ce86f6bd95f72e68da4b779 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Decode {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i = 0; i < t; i++) {
int l = in.nextInt();
l--;
in.nextLine();
String code = in.nextLine();
String decoded = "";
while (l >= 0) {
if (code.charAt(l) == '0') {
decoded = (char) ((code.charAt(l - 2) - 48) * 10 + (code.charAt(l - 1) - 48) + '`') + decoded;
l -= 3;
} else {
decoded = (char) (code.charAt(l) + 48) + decoded;
l--;
}
}
System.out.println(decoded);
}
return;
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | c6e4eb100845050ae15afb6df96271b8 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
/*
*/
public class B{
static FastReader sc=null;
public static void main(String[] args) {
sc=new FastReader();
int t=sc.nextInt();
for(int tt=0;tt<t;tt++) {
int n=sc.nextInt();
char a[]=sc.next().toCharArray();
String ans="";
for(int i=n-1;i>=0;i--) {
int to=0;
if(a[i]=='0') {
to+=a[i-1]-'0'+(a[i-2]-'0')*10;
i-=2;
}
else {
to=a[i]-'0';
}
ans=(char)(to-1+'a')+ans;
}
System.out.println(ans);
}
}
static int[] ruffleSort(int a[]) {
ArrayList<Integer> al=new ArrayList<>();
for(int i:a)al.add(i);
Collections.sort(al);
for(int i=0;i<a.length;i++)a[i]=al.get(i);
return a;
}
static void print(int a[]) {
for(int e:a) {
System.out.print(e+" ");
}
System.out.println();
}
static class FastReader{
StringTokenizer st=new StringTokenizer("");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String next() {
while(!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int a[]=new int[n];
for(int i=0;i<n;i++)a[i]=sc.nextInt();
return a;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 69f79417e09a243fb6557730177a0c7d | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class coding{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
while(test>0){
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
String ans = "";
for(int i=s.length()-1;i>=0;i--){
if(s.charAt(i) != '0'){
String temp = "" + s.charAt(i);
int number = Integer.parseInt(temp) - 1;
char c = (char)(number + 'a');
ans += "" + c;
}
else{
String temp = s.substring(i-2,i);
int number = Integer.parseInt(temp) - 1;
char c = (char)(number + 'a');
ans += "" + c;
i -= 2;
}
}
String op = "";
for(int i=0;i<ans.length();i++) op = ans.charAt(i) + op;
System.out.println(op);
test--;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | d13b6e8a6f729d10aab94416b2704e5c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args) throws IOException {
OutputStreamWriter osr = new OutputStreamWriter(System.out);
PrintWriter out = new PrintWriter(osr);
FastReader fr = new FastReader();
char [] arr = "abcdefghijklmnopqrstuvwxyz".toCharArray();
int t = fr.nextInt();
while (t--!=0) {
int n = fr.nextInt();
String s1 = fr.next();
StringBuffer s2 = new StringBuffer();
for (int i = n - 1; i >= 0; i--) {
if (s1.charAt(i) == '0') {
s2.insert(0, arr[Integer.parseInt(s1.charAt(i - 2) + "" + s1.charAt(i - 1)) - 1]);
i -= 2;
} else
s2.insert(0, arr[Integer.parseInt(s1.charAt(i) + "") - 1]);
}
out.println(s2);
}
out.close();
}
}
class FastReader {
// Attributes :
BufferedReader br;
StringTokenizer st;
// Constructor :
public FastReader() {
InputStreamReader isr = new InputStreamReader(System.in);
br = new BufferedReader(isr);
}
// Operations :
// #01 :
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
// #02 :
public String nextLine() throws IOException {
return br.readLine();
}
// #03 :
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
// #04 :
public long nextLong() throws IOException {
return Long.parseLong(next());
}
// #05 :
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
// #06 :
public int [] intArray (int size) throws IOException{
int [] arr = new int[size];
for (int i = 0 ; i < size; i++)
arr[i] = nextInt();
return arr;
}
// #07 :
public char [] charArray() throws IOException {
return nextLine().toCharArray();
}
}
class Pair {
long x;
long y;
public Pair(long x, long y) {
this.x = x;
this.y = y;
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 7bdb5ad70261f4c6bd4d2a78e248db45 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class test290 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t=in.nextInt();
for(int j=0;j<t;j++) {
int n=in.nextInt();
char[] a=in.next().toCharArray();
String s="";
for(int i=n-1;i>=0;i--) {
if(a[i]=='0') {
s=(char)(a[i-1]+48+(a[i-2]-48)*10)+s;
i-=2;
}
else {
s=(char)(a[i]+48)+s;
}
}
System.out.println(s);
}
in.close();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | db7fa12fa1b12dbcfef175d6d61c2fc0 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | // 48 to 57
import java.util.*;
public class A1729
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int q = sc.nextInt();
for(int qq=0;qq<q;qq++)
{
String s = "";
int n = sc.nextInt();
String t = sc.next();
for(int i=0;i<n;i++)
{
char ch = t.charAt(i);
if(i+2<n&&t.charAt(i+2)=='0'&&!(i+3<n&&t.charAt(i+3)=='0'))
{
int k = (int)ch - 48;
int k1 = (int)(t.charAt(i+1))-48;
int kk = 10*k+k1;
s += (char)(96+kk);
i+= 2;
}
else
{
s += (char)(96+((int)ch - 48));
}
}
System.out.println(s);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 202bb00eb168f5cd637a548ea88ff749 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Skeleton {
public Skeleton() {
// TODO Auto-generated constructor stub
}
static class FastReader {
public BufferedReader br;
public StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
st = null;
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader fr = new FastReader();
int t = fr.nextInt();
while(t-- > 0) {
int n = fr.nextInt();
String s = fr.next();
String res = "";
int i = n-1;
while(i >=0) {
if(s.charAt(i) != '0') {
char c = (char) ('a' + Integer.parseInt("" + s.charAt(i)) -1);
res = c + res;
i--;
}
else {
char c = (char) ('a' + Integer.parseInt(s.substring(i-2, i)) -1);
res = c + res;
i-= 3;
}
}
System.out.println(res);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 462b5ee45b031a52794b80bf0e8d411c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class decodeString800 {
public static void main(String[] args) throws Exception
{
Scanner sc = new Scanner(System.in);
int inp = sc.nextInt();
while(inp-->0)
{
int n = sc.nextInt();
String str = sc.next();
StringBuilder sb = new StringBuilder();
int i=n-1;
while(i>=0)
{
char ch = str.charAt(i);
if(ch == '0')
{
int num1 = str.charAt(i-2)-'0';
int num2 = str.charAt(i-1)-'0';
char ch1 = (char)((num1*10+num2-1)+'a');
// System.out.println(ch1);
sb.append(ch1);
i-=3;
}
else
{
char chr = (char)((str.charAt(i)-'0'-1) + 'a');
sb.append(chr);
i-=1;
}
}
System.out.println(sb.reverse().toString());
}
sc.close();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | b3354d829df8806cae51e5eafae03b94 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class B_Decode_String {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int q = Integer.parseInt(br.readLine());
while(q-- > 0) {
int n = Integer.parseInt(br.readLine());
String t = br.readLine();
for(int i = 0; i < n; i++) {
if(i+2 < n && t.charAt(i+2) == '0' && !(i+3 < n && t.charAt(i+3) == '0')) {
int temp = Integer.parseInt(t.substring(i, i+2));
sb.append((char) (96+temp));
i += 2;
}
else {
sb.append((char) (96+(t.charAt(i)-'0')));
}
}
sb.append("\n");
}
System.out.println(sb);
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 10b333f92f2af0541f6aecb1a2c29faa | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java .util.Scanner;
public class Experts {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
long t=input.nextLong();
while(t>=1){
long a=input.nextLong();
long b=input.nextLong();
long c=input.nextLong();
if(a==1){
System.out.println(1);
}
else{
a=a-1;
if(b<c&&b==1){
b=2*(c-b);
}
else if(b<c&&b!=1){
b=c-b+(c)-1;
}
else if(b>c&&c==1){
b=b-c;
}
else if(b>c&&c!=1){
b=b-1;
}
if(a<b){
System.out.println(1);
}
else if(a>b){
System.out.println(2);
}
else if(a==b){
System.out.println(3);
}
}
t--;
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | b76f33b847781066728d894394b40c90 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.*;
public class file{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
if(a==1){
System.out.println(1);
}
else{
int time_first=Math.abs(a-1);
int time_second=Math.abs(b-c)+Math.abs(c-1);
if(time_first<time_second){
System.out.println(1);
}
else if(time_second<time_first){
System.out.println(2);
}
else{
System.out.println(3);
}
}
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | a28182ab29820edff268cb3f1a5cb77f | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.util.Arrays.*;
public class Main {
private final static FastScanner in = new FastScanner();
private final static String endl = "\n";
private static BufferedReader br;
public static void main( String[] args ) throws IOException {
Locale.setDefault( Locale.US );
solution();
}
public static void solution() {
int n = inn();
while( n --> 0 ) {
int a = inn();
int b = inn();
int c = inn();
if( Math.abs( a - 1 ) < Math.abs( b - c ) + Math.abs( c - 1 )){
out.println( 1 );
} else if(Math.abs( a - 1 ) > Math.abs( b - c ) + Math.abs( c - 1 )){
out.println( 2 );
} else {
out.println( 3 );
}
}
}
/*
static int FE( int n ) {
int res = n;
for( int i = 2; i * i <= n; ++i )
if( n % i == 0 ) {
while( n % i == 0 )
n /= i;
res -= res / i;
}
if( n > 1 )
res -= res / n;
return res;
}
static int Jgcd( int n ) {
int res = 0;
for( int i = 0; i < n; ++i ) {
if( gcd( n, i ) == 1 ) {
res = i;
}
}
return res;
}
*/
//======================================================================================================================
private static StringBuilder reverse( String s ) {
StringBuilder stringBuilder = new StringBuilder( s );
stringBuilder.reverse();
return stringBuilder;
}
private static int lcm( int a, int b ) {
return a / gcd ( a, b ) * b;
}
private static int gcd( int a, int b ) {
return b == 0 ? a : gcd( b, a % b );
}
private static int inn() {
return in.nextInt();
}
private static long inl() {
return in.nextLong();
}
private static double ind() {
return in.nextDouble();
}
private static char inc() {
return in.next().charAt( 0 );
}
private static String ins() {
return in.next();
}
private static String insl() {
return in.nextLine();
}
private static int toInt( String s ) {
return Integer.parseInt( s );
}
private static int toInt( char c ) {
return Integer.parseInt( c + "" );
}
private static <K> void print( K a ) {
out.print( a );
}
private static <K> void println( K a ) {
print( a + endl );
}
private static void yes() {
println( "YES" );
}
private static void no() {
println( "NO" );
}
private static int max_a( int[] a ) {
int max = a[0];
for( int j : a ) {
if( j > max ) {
max = j;
}
}
return max;
}
private static int min_a( int[] a ) {
int min = a[0];
for( int j : a ) {
if( j < min ) {
min = j;
}
}
return min;
}
private static long sum( int[] a ) {
return stream( a ).asLongStream().sum();
}
private static int reverseInt( int k ) {
String a = k + "", res = "";
for( int i = a.length() - 1; i >= 0; --i ) {
res += a.charAt( i );
}
return toInt( res );
}
static class FastScanner {
StringTokenizer tokenizer = new StringTokenizer( "" );
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader( System.in ));
public FastScanner() {
br = new BufferedReader( new InputStreamReader( System.in ));
}
String next() {
while( !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer( bufferedReader.readLine());
} catch( IOException e ) {
e.printStackTrace();
}
}
return tokenizer.nextToken();
}
int nextInt() {
return Integer.parseInt( next());
}
int[] readArray( int n ) {
int[] a = new int[n + 1];
for( int i = 0; i < n; ++i ) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong( next());
}
double nextDouble() {
return Double.parseDouble( next());
}
String nextLine() {
String s = "";
try {
s = br.readLine();
} catch( IOException e ) {
e.printStackTrace();
}
return s;
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | e416cf4dca821b02662ed76237c6ba1d | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes |
import java.util.Scanner;
public class Solve {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int ans = Math.abs(a-1);
int res = Math.abs(b-c) + Math.abs(c-1);
if(ans == res){
System.out.println(3);
}else if(ans <res){
System.out.println(1);
}else{
System.out.println(2);
}
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | d1b3016938ccc404a3f3143f23f70035 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int testCase = in.nextInt();
// while (testCase--!=0){
//
// }
for (int i = 0; i <testCase ; i++) {
//First Elevator
int a = in.nextInt(); // 10th floor to 1st floor
// Second Elevator
int b = in.nextInt();
int c = in.nextInt(); // b floor to c floor to 1st floor
int FirstElevatorTime = (a-1);
int SecondElevatorTime = Math.abs(b-c)+(c-1);
if(FirstElevatorTime<SecondElevatorTime){
System.out.println("1");
}
else if( FirstElevatorTime== SecondElevatorTime)
System.out.println("3");
else
System.out.println("2");
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | e2bee12f0561eda5e6600e9cd5ac3b6e | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
/**
* Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
*
* To modify the template, go to Preferences -> Editor -> File and Code Templates -> Other
*/
public class Main {
public static void main(String[] args) {
// Write your solution here
Scanner in = new Scanner(System.in);
int test = in.nextInt();
while (test--!=0){
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int first_floor = a-1;
int second_floor = (c-b)+(c-1);
if(b>c) {
second_floor = (b-c)+(c-1);
}
if(first_floor<second_floor || a ==1){
System.out.println("1");
} else if (second_floor<first_floor) {
System.out.println("2");
}
else {
System.out.println("3");
}
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | b626ad10fa4d969caeb4cf50c900bcf5 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.*;
import java.util.*;
public class code {
static long TIME_START, TIME_END;
public static class Task {
public void solve(Scanner sc, PrintWriter pw) throws IOException {
//code here...
int t=sc.nextInt();
for(int i=0;i<t;i++){
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int d=Math.abs(a-1);
int e=Math.abs(b-c);
int f=c-1;
if(d<e+f)
pw.println(1);
else if(f+e<d)
pw.println(2);
else pw.println(3);
//return Math.min(Math.abs(a-1),Math.min(b-c))
}
}
}
public static void main(String[] args) throws IOException {
//Scanner sc = new Scanner(new FileReader(new File("out//input.txt")));
Scanner sc = new Scanner(System.in);
//PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(new File("out//output.txt"))));
PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
Runtime runtime = Runtime.getRuntime();
long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
TIME_START = System.currentTimeMillis();
Task t = new Task();
t.solve(sc, pw);
TIME_END = System.currentTimeMillis();
long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
pw.close();
System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader s) throws FileNotFoundException {
br = new BufferedReader(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 {
return Double.parseDouble(next());
}
public boolean ready() throws IOException {
return br.ready();
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 9050a800cfaf64eae75d629f8cc19978 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner jin=new Scanner(System.in);
int t=jin.nextInt();
while(t-->0){
int a=jin.nextInt();
int b=jin.nextInt();
int c=jin.nextInt();
int diffa=Math.abs(a-1);
int diffb=Math.abs(b-c);
diffb+=Math.abs(c-1);
if(diffa<diffb)System.out.println(1);
else if(diffa==diffb)System.out.println(3);
else System.out.println(2);
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 5038510e5ecd0ce53054c53376a3e15d | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes |
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner jin=new Scanner(System.in);
int t=jin.nextInt();
while(t-->0){
int a=jin.nextInt();
int b=jin.nextInt();
int c=jin.nextInt();
int diffa=Math.abs(a-1);
int diffb=Math.abs(b-c);
diffb+=Math.abs(c-1);
if(diffa<diffb)System.out.println(1);
else if(diffa==diffb)System.out.println(3);
else System.out.println(2);
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | b1d045a5f70845e026b74d7d9f6a0ece | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class className1{
public static void main(String args[]) {
Scanner scanner=new Scanner(System.in);
int numInputs=scanner.nextInt();
scanner.nextLine();
while(numInputs-->0) {
String line=scanner.nextLine();
String[] bits=line.split(" ");
int[] nums=new int[bits.length];
for(int i=0;i<nums.length;i++) {
nums[i]=Integer.parseInt(bits[i]);
}
int a=nums[0],b=nums[1],c=nums[2];
if(Math.abs(a-1)>Math.abs(b-c)+Math.abs(c-1)) System.out.println(2);
else if(Math.abs(a-1)<Math.abs(b-c)+Math.abs(c-1)) System.out.println(1);
else System.out.println(3);
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | c5193a6837db25f1bec6849b574696be | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class cff {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
for (int i = 0; i < t; i++) {
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
int t1 = a - 1;
int t2 = Math.abs(b-c)+c-1;
if(t1 == t2) System.out.println(3);
else if(t1 > t2) System.out.println(2);
else System.out.println(1);
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | ed88a5c709f3b2bbec861c97a4f8cebc | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class Codeforces {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int i = 0; i < n; i++) {
int a = in.nextInt() - 1;
int b = in.nextInt();
int c = in.nextInt();
b = Math.abs(b - c) + c - 1;
if (a < b) {
System.out.println("1");
} else if (a > b) {
System.out.println("2");
} else {
System.out.println("3");
}
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 00e32e369617058730f74b12019dd354 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Median {
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-- != 0) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int first = a - 1;
int second = 0;
if( b < c ) {
if(b != 1) {
second =(c-b)+(c-1);
}else{
second = (c - b) * 2;
}
} else{
second = b-1;
}
if(first < second){
System.out.println(1);
}else if(first > second){
System.out.println(2);
}else{
System.out.println(3);
}
}
}
}
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;
}
int[] readArray(int n){
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = nextInt();
}
return a;
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | f74ede8ee57d59591d93fef8d14151ce | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Median {
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-- != 0) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int first = a - 1;
int second = Math.abs(b-c)+Math.abs(c-1);
if(first < second){
System.out.println(1);
}else if(first > second){
System.out.println(2);
}else{
System.out.println(3);
}
}
}
}
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;
}
int[] readArray(int n){
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = nextInt();
}
return a;
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | d2820c37f0b8940b210e195ece32537b | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int count = scn.nextInt();
for (int i = 0; i < count; i++) {
int a = scn.nextInt();
int b = scn.nextInt();
int c = scn.nextInt();
int x = Math.abs(c - b) + c;
if (a < x){
System.out.println(1);
}else if (a > x){
System.out.println(2);
}else {
System.out.println(3);
}
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 0b49fa32fd0d851cac36901d03cef917 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int testCase = scanner.nextInt();
int time = 0;
int temi = 0;
int[] d = new int[3];
int[] results = new int[testCase];
for (int i = 0; i < testCase; i++) {
d[0] = scanner.nextInt();
d[1] = scanner.nextInt();
d[2] = scanner.nextInt();
time = d[0] - 1;
if (d[1] > d[2]) {
temi = d[1] - 1;
} else if(d[1] < d[2]) {
temi = (d[2] - d[1]) + (d[2] - 1);
}
if (time > temi) {
results[i] = 2;
} else if (time < temi) {
results[i] = 1;
} else if(time == temi) {
results[i] = 3;
}
}
for (int i = 0; i < testCase; i++) {
System.out.println(results[i]);
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | b292711ed320e96302d843971241e2aa | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.*;
import java.util.*;
public class ProbE {
static int T;
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());
T = Integer.parseInt(st.nextToken());
for (int t = 0; t < T; t++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
int ansA = 0;
int ansB = 0;
ansA = Math.abs(a - 1);
ansB = Math.abs(b - c) + Math.abs(c - 1);
if (ansA == ansB) {
pw.println(3);
} else if (ansA > ansB) {
pw.println(2);
} else {
pw.println(1);
}
}
pw.close();
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | c83fa4b1f1db9a0fc4b126561eadc1e8 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.DataInputStream;
import java.io.IOException;
public class Solution {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
}
public static void main(String[] args)
throws IOException {
Reader s = new Reader();
int t = s.nextInt();
StringBuilder ans = new StringBuilder();
while (t-- > 0) {
int a = s.nextInt(), b = s.nextInt(), c = s.nextInt();
if (a == 1) {
ans.append('1').append('\n');
} else {
int diffA = Math.abs(a - 1);
int diffB = Math.abs(b - c) + Math.abs(c - 1);
if (diffA < diffB)
ans.append('1').append('\n');
else if (diffA > diffB)
ans.append('2').append('\n');
else
ans.append('3').append('\n');
}
}
System.out.println(ans);
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 6aec94629d808d6090dd3890f37eda0b | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while (t-- > 0) {
int a = s.nextInt(), b = s.nextInt(), c = s.nextInt();
char ans = '0';
if (a == 1) {
ans = '1';
} else {
int diffA = Math.abs(a - 1);
int diffB = Math.abs(b - c) + Math.abs(c - 1);
if (diffA < diffB)
ans = '1';
else if (diffA > diffB)
ans = '2';
else
ans = '3';
}
System.out.println(ans);
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 16faa3bef6e7ebf9022d7b0ce8ecc472 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
StringBuilder ans = new StringBuilder();
while (t-- > 0) {
int a = s.nextInt(), b = s.nextInt(), c = s.nextInt();
if (a == 1) {
ans.append('1').append('\n');
} else {
int diffA = Math.abs(a - 1);
int diffB = Math.abs(b - c) + Math.abs(c - 1);
if (diffA < diffB)
ans.append('1').append('\n');
else if (diffA > diffB)
ans.append('2').append('\n');
else
ans.append('3').append('\n');
}
}
System.out.println(ans);
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | ad569291e0f8d23dfffe39f7f1537ab3 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.DataInputStream;
import java.io.IOException;
public class Solution {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
}
public static void main(String[] args)
throws IOException {
Reader s = new Reader();
int t = s.nextInt();
StringBuilder ans = new StringBuilder();
while (t-- > 0) {
int a = s.nextInt(), b = s.nextInt(), c = s.nextInt();
if (a == 1) {
ans.append('1').append('\n');
} else {
int diffA = Math.abs(a - 1);
int diffB = Math.abs(b - c) + Math.abs(c - 1);
if (diffA < diffB)
ans.append('1').append('\n');
else if (diffA > diffB)
ans.append('2').append('\n');
else
ans.append('3').append('\n');
}
}
System.out.println(ans);
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 30d632aa1c892b2587793a2c6517febc | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class TwoElevators {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int t1;
int t2=0;
for(int i=0;i<n;i++){
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
t1=a-1;
if(c>=b)
{
t2=2*c-b-1;
}
else if (b>c)
{t2=b-1;}
if(t1>t2)
{ System.out.println("2");}
else if(t2>t1)
{System.out.println("1");}
else
{System.out.println("3");}
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 6446996b7a5c91b81b69f4a5079799e0 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class leet {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
for (int k = 0; k <n; k++) {
int a = s.nextInt();
int b = s.nextInt();
int c = s.nextInt();
if(a<b){
System.out.println("1");
}else if(b>c){
if(a>b){
System.out.println("2");
}else if(a<b){
System.out.println("1");
}else System.out.println("3");
} else{
if(a>Math.abs(c-b)+c){
System.out.println("2");
}else if(a<Math.abs(c-b)+c){
System.out.println("1");
}else System.out.println("3");
}
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 6b9c64c856a40a6944cf7a4b981e7f03 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args)
{
FastReader s = new FastReader();
int t = s.nextInt();
while (t-- > 0){
int a = s.nextInt();
int b = s.nextInt();
int c = s.nextInt();
int f = (a-1);
int sc = b >= c ? b-1 : (c-b)+(c-1);
// if (a == 1 && (b == c && b == 1)) System.out.println(3);
// else if (a == 1) System.out.println(1);
// // else if (b == c && b == 1) System.out.println(2);
// else if (c == 1) System.out.println(a < b ? 1 : a == b ? 3 : 2);
if (f == sc) System.out.println(3);
else if (f < sc) System.out.println(1);
else System.out.println(2);
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 3f4ae7178d58a3259245b2afda425103 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | //package Codeforce;
import java.util.Scanner;
public class TwoElevators {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int test = input.nextInt();
while (test-- > 0){
int a = input.nextInt(),b = input.nextInt(),c = input.nextInt();
System.out.println(result(a,b,c));
}
}
private static int result(int a, int b, int c) {
if(a == 1)
return 1;
if(b < c){
int x = c-b;
x = x+c;
if(a < x)
return 1;
else if(x < a)
return 2;
else
return 3;
}else{
if(a < b)
return 1;
else if(b < a)
return 2;
else
return 3;
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 864a64d887ca85c31a80911f4c311740 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int caseNum = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
for (int t = 1; t <= caseNum; ++t) {
int[] floors = new int[3];
for(int i = 0; i < floors.length; i++){
floors[i] = in.nextInt();
}
int a = floors[0]-1;
int b = Math.abs(floors[1] - floors[2]) + floors[2] - 1;
if(a < b){
System.out.println(1);
}else if(a >b){
System.out.println(2);
}else{
System.out.println(3);
}
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 35d8cf5a4a24393c6db0b1e831a9db00 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class Atask {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
for (int i = 0; i < n; i++) {
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
if(c == 1){
if (a > b){
System.out.println(2);
}
else if (a== b){
System.out.println(3);
}else {
System.out.println(1);
}
}
else if (a-1 > Math.abs(c-b) + (c-1)){
System.out.println(2);
}
else if (a-1 == Math.abs(c-b) + (c-1)){
System.out.println(3);
}else {
System.out.println(1);
}
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | f9e4f0081a22d5dba2a8a0e0eeae7996 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | // Working program using Reader Class
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Scanner;
import java.util.StringTokenizer;
import javax.lang.model.util.ElementScanner6;
//====== ++++++++ +++++++ |\ /| |+++ | ===============================
//====== || + | \ / | | + | ===============================
//====== || +++++++ | + | |+++ | ===============================
//====== || + | | | | ===============================
//====== || +++++++ | | | |++++++ ===============================
public class A_v2 {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
//==============================================================================================
//==============================================================================================
//===================Templates==================================================================
//=========== |++++++++ | | |\ | ==========================================
//=========== | | | | \ | ==========================================
//=========== |++++++++ | | | \ | ==========================================
//=========== | | | | \ | ==========================================
//=========== | \ / | \ | ==========================================
//=========== | \___/ | \| ==========================================
static void swap(long[] arr, int i, int j)
{
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static int partition(long[] arr, int low, int high)
{
long pivot = arr[high];
int i = (low - 1);
for(int j = low; j <= high - 1; j++)
{
if (arr[j] < pivot)
{
i++;
swap(arr, i, j);
}
}
swap(arr, i + 1, high);
return (i + 1);
}
static void quickSort(long[] arr, int low, int high)
{
if (low < high)
{
int pi = partition(arr, low, high);
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
void merge(int arr[], int l, int m, int r)
{
int n1 = m - l + 1;
int n2 = r - m;
int L[] = new int[n1];
int R[] = new int[n2];
for (int i = 0; i < n1; ++i) L[i] = arr[l + i];
for (int j = 0; j < n2; ++j) R[j] = arr[m + 1 + j];
int i = 0, j = 0;
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else {
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
void sort(int arr[], int l, int r)
{
if (l < r)
{
int m =l+ (r-l)/2;
sort(arr, l, m);
sort(arr, m + 1, r);
merge(arr, l, m, r);
}
}
//======================================Functions===============================================
//==============================================================================================
//==============================================================================================
//=========== +++++ ++++++ ++++++ ++++++++ ================================
//=========== / + + | + + ================================
//=========== | + + | + + ================================
//=========== | + + | + ++++++++ ================================
//=========== \ + + | + + ================================
//=========== +++++ ++++++ ++++++ ++++++++ ================================
static Reader in = new Reader();
public static void solve() throws IOException
{
int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
if((a==1 && c!=1) || (a == 1 && c == 1))
{
System.out.println(1);
return;
}
else if((a != 1 && c != 1) || (a != 1 && c == 1))
{
if(a > Math.abs(b-c) + c)
{
System.out.println(2);
return;
}
else if(a < Math.abs(b-c) + c)
{
System.out.println(1);
return;
}
else
{
System.out.println(3);
return;
}
}
else
{
System.out.println(3);
return;
}
// if(Math.abs(a-b) == c) {System.out.println(2); return;}
// else if(Math.abs(a-b) < Math.abs(b-c)) {System.out.println(1); return;}
// else if(Math.abs(a-b) > Math.abs(b-c)) {System.out.println(3); return;}
// else {
// if(a < c) {System.out.println(1); return;}
// else if(a > c) {System.out.println(2); return;}
// else {System.out.println(3); return;}
// }
}
public static void main(String[] args) throws IOException
{
int t = in.nextInt();
while(t --> 0)
{
solve();
}
}
}
//====================== code ==================================================================
//==============================================================================================
//==============================================================================================
//============================================================================================== | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | b73e276ca39acf13a6a4bbb819424e6a | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes |
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long t = sc.nextLong();
for (long i = 0; i < t; i++) {
long a = sc.nextLong();
a--;
long b = sc.nextLong();
long c = sc.nextLong();
long d = Math.abs(b - c) + Math.abs(c - 1);
// System.out.println("d= "+d);
if (a < d)
System.out.println("1");
else if (d < a)
System.out.println("2");
else
System.out.println("3");
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | ab31bfb8b416558dc052d611bf5f46a7 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.*;
import java.util.*;
public class CF {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double inp = input.nextDouble();
double arr[] = new double [3];
int j;
// ArrayList <Integer> arr = new ArrayList<>();
for(int i = 1;i <= inp; i++){
for (j = 0; j <= 2; j++) {
arr[j] = (input.nextDouble());
// System.out.println(arr[j]);
}
double first = arr[0] - 1;
double second = Math.abs(arr[2] - arr[1]) + arr[2] - 1;
// System.out.println(first);
// System.out.println(second);
if(first ==0){
System.out.println(1);
// System.out.println(first);
// System.out.println(second);
}
else if(first < second){
System.out.println(1);
// System.out.println(first);
// System.out.println(second);
}
else if(first > second){
System.out.println(2);
// System.out.println(first);
// System.out.println(second);
}
else if(first == second){
System.out.println(3);
// System.out.println(first);
// System.out.println(second);
}
// else{
// System.out.println(1);
// }
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | c270ba2146700195f412f129f04816ad | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
/*
author : Multi-Thread
*/
public class A {
//public class Main {
// static int INF = 998244353;
static int INF = (int) 1e9 + 7;
static int MAX = Integer.MAX_VALUE;
static int MIN = Integer.MIN_VALUE;
public static void main(String[] args) {
int test = fs.nextInt();
// int test = 1;
for (int cases = 0; cases < test; cases++) {
// solve();
final_answer.append(solve() + "\n");
}
out.print(final_answer.toString());
out.flush();
}
static StringBuilder final_answer = new StringBuilder();
static String solve() {
int a = fs.nextInt(), b = fs.nextInt(), c = fs.nextInt();
// if (c > b) {
// int after = c - b;
// int z = a - after;
// if (z < 1)
// return a + "";
// return after + Integer.min(z, c) + "";
// }
// return Integer.min(a, b) + "";
if (c < b) {
if (a < b)
return 1 + "";
if (b < a)
return 2 + "";
return 3 + "";
}
int after = c - b;
int z = a - after;
if (z <= 1)
return 1 + "";
if (z < c)
return 1 + "";
if (c < z)
return 2 + "";
return 3 + "";
}
static class Pair {
int first, second;
public Pair(int first, int second) {
this.first = first;
this.second = second;
}
public String toString() {
return "[" + first + "," + second + "]";
}
}
static class LongPair {
long first;
long second;
LongPair(long a, long b) {
this.first = a;
this.second = b;
}
public String toString() {
return "[" + first + "," + second + "]";
}
}
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 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 println() {
writer.print("\n");
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
private static final FastReader fs = new FastReader();
private static final OutputWriter out = new OutputWriter(System.out);
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | e2485a865b5526a51e4629ac16f754b8 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.*;
import java.lang.*;
import java.util.*;
import java.util.Collection;
import static java.lang.Math.*;
import java.math.BigInteger;
public class Main implements Runnable
{
static char[] arr;
public int maxSubArray(int[] arr, int n)
{
int local_max = 0;
int global_max = Integer.MIN_VALUE;
for(int i=0;i<n;i++)
{
local_max = Math.max(arr[i], arr[i] + local_max);
if(local_max > global_max)
{
global_max = local_max;
}
}
return global_max;
}
public static int recur(int left, int right, char tag)
{
if(left == right)
{
if(tag == arr[left])
return 0;
return 1;
}
int mid = (left+right)/2;
int cost = 0;
for(int i=left; i <= mid; i++)
if(tag != arr[i])
cost++;
int res = cost+recur(mid+1, right, (char)(tag+1));
cost = 0;
for(int i=mid+1; i <= right; i++)
if(tag != arr[i])
cost++;
res = Math.min(res, cost+recur(left, mid, (char)(tag+1)));
return res;
}
static void reverse(int[] arr, int start, int end)
{
while (start < end)
{
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
static int upper_bound(int arr[], int key)
{
int mid, N = arr.length;
int low = 0;
int high = N;
while (low < high && low != N)
{
mid = low + (high - low) / 2;
if (key >= arr[mid])
{
low = mid + 1;
}
else
{
high = mid;
}
}
return low;
}
long gcd(long a, long bb)
{
if (bb == 0)
return a;
return gcd(bb,a%bb);
}
public boolean prob_greater_than_zero(int pos, long[] a)
{
long power = a[pos];
for(int i=0;i<a.length;i++)
{
if(i == pos)
{
continue;
}
else if(a[i] > power)
{
return false;
}
power += a[i];
}
return true;
}
static long countSetBits(long n)
{
long count = 0;
while (n > 0) {
n &= (n - 1);
count++;
}
return count;
}
static ArrayList<Long>addDivisors(long n)
{
ArrayList<Long>list = new ArrayList<>();
for (long i=1; i<=Math.sqrt(n); i++)
{
if (n%i==0)
{
if (n/i == i)
{
list.add(i);
}
else
{
list.add(i);
list.add(n/i);
}
}
}
return list;
}
long lcm(long a, long b)
{
return (a / gcd(a, b)) * b;
}
boolean b = false;
void dfs(int[][] arr, int i, int j, int sum, int n, int m)
{
if(i < 0 || j < 0 || i >= n || j >= m)
{
return;
}
if(sum + arr[i][j] == 0 && i == n-1 && j == m-1)
{
b = true;
return;
}
dfs(arr,i+1,j,sum+arr[i][j],n,m);
dfs(arr,i,j+1,sum + arr[i][j],n,m);
}
static long onesComplement(long n)
{
long number_of_bits =
(long)(Math.floor(Math.log(n) / Math.log(2))) + 1;
return ((1 << number_of_bits) - 1) ^ n;
}
void swap(int[] arr, int i, int j)
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public void run()
{
InputReader s = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = s.nextInt();
while(t-- > 0)
{
int a = s.nextInt();
int b = s.nextInt();
int c = s.nextInt();
int first = a - 1;
int second = 0;
if(c <= b)
{
second = (b - c) + (c - 1);
}
else
{
second = (2 * (c - b)) + (b - 1);
}
if(first < second)
{
out.println("1");
}
else if(second < first)
{
out.println("2");
}
else
{
out.println("3");
}
}
out.close();
}
class Pair
{
int c;
int num;
Pair(int c, int num)
{
this.c = c;
this.num = num;
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception {
new Thread(null, new Main(),"Main",1<<26).start();
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 7e349c5e3a84251ea59ecd5b1e957a8a | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | //============================================================================
//Everyone has a different way of thinking, so God Created us
// Hope You Respect My Way..,Thank You ):
// Author : Murad
// Name : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================/
import java.io.*;
import java.util.*;
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);
int t=in.nextInt();
while(t-->0){
long a=in.nextLong(),b=in.nextLong(),c=in.nextLong();
long cnt1=a-1;
long cnt2=0;
if(b>c){
cnt2=b-1;
}
else{
cnt2=Math.abs(b-c)+Math.abs(c-1);
}
if(cnt1==cnt2){
out.println(3);
}else if(cnt1<cnt2)out.println(1);
else out.println(2);
}
out.flush();
}
static class NumberTheory{
public static long gcd(long a,long b){
long c;
while (a != 0) {
c = a;
a = b % a;
b = c;
}
return b;
}
}
static class Pair implements Comparable<Pair> {
long x;
long y;
Pair(long x, long y)
{
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
if(x-o.x==0)return Math.toIntExact(y - o.y);
return Math.toIntExact(x - o.x);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public long[] readLongArray(int n) {
long[] x = new long[n];
for (int i = 0; i < n; i++) {
x[i] = nextLong();
}
return x;
}
public int[] readIntArray(int n) {
int[] x = new int[n];
for (int i = 0; i < n; i++) {
x[i] = nextInt();
}
return x;
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | c80765c764ad79a1b1dd79ae599a71fd | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a, b, c, t;
t = in.nextInt();
int arr[] = new int[t];
for(int i = 0; i < t; i++){
a = in.nextInt();
b = in.nextInt();
c = in.nextInt();
if(Math.abs(a) < Math.abs(b - c) + c)
arr[i] = 1;
else if(Math.abs(a) > Math.abs(b - c ) + c)
arr[i] = 2;
else arr[i] = 3;
}
for(int i = 0; i < t; i++)
System.out.println(arr[i]);
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 7aa35368c8df67597e4c4356691fe1d9 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st==null || !st.hasMoreTokens()){
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str="";
try {
str=br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void prlong(Object object) throws IOException {
bw.append("" + object);
}
public void prlongln(Object object) throws IOException {
prlong(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
public static String toString(char[] a)
{
// Creating object of String class
StringBuilder sb = new StringBuilder();
// Creating a string using append() method
for (long i = 0; i < a.length; i++) {
sb.append(a[(int)i]);
}
return sb.toString();
} public static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long fun(long n, long x)
{
if(x>n)
return x;
n = n + x/2;
n = n - (n%x);
return n;
}
// beg-----target--------mid-------------end
public static long binarySearch(int arr[], int l, int r, int x)
{
if (r >= l) {
int mid = (int) (l + (r - l) / 2);
// If the element is present at the
// middle itself
if (arr[mid] == x)
return mid;
// If element is smaller than mid, then
// it can only be present in left subarray
if (arr[mid] > x)
return binarySearch(arr, l, mid - 1, x);
// Else the element can only be present
// in right subarray
return binarySearch(arr, mid + 1, r, x);
}
return -1;
}
public static int last(int arr[], int low, int high, int x, int n)
{
if (high >= low) {
int mid = low + (high - low) / 2;
if ((mid == n - 1 || x < arr[mid + 1]) && arr[mid] == x)
return mid;
else if (x < arr[mid])
return last(arr, low, (mid - 1), x, n);
else
return last(arr, (mid + 1), high, x, n);
}
return -1;
}
static long maxi(long x ,long y)
{
if(x>y)
return x ;
return y ;
}
static long mini(long x ,long y)
{
if(x<y)
return x ;
return y ;
}
public static void main(String[] args) {
try {
FastReader in=new FastReader();
FastWriter out = new FastWriter();
long testCases=in.nextInt();
while(testCases-- > 0) {
///START HERE
long a =in.nextLong();
long b =in.nextLong();
long c =in.nextLong();
long one=1;
one=a-1;
long sec =Math.abs(b-c)+c-1;
if(one==sec)
System.out.println(3);
else if(one<sec)
System.out.println(1);
else System.out.println(2);
//End here //////end
}
out.close();
} catch (Exception e) {
return;
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 75abe88e13935d828c5555bfbaaaedc5 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | // Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.lang.*;
import java.util.stream.*;
import java.util.stream.Collectors;
public class Main {
static FastReader sc = new FastReader();
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 {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static int calcdiv2(int n) {
int counter = 0;
while( ( 1 & n) != 1) {
n = n>>1;
counter++;
}
return counter;
}
public static int highestPowerOfTwo(int n) {
if((n & (n-1)) == 0) return n;
return n & (n-1);
}
public static boolean isPowerOfTwo(int n) {
return (n & (n-1)) == 0;
}
public static int valueOfRightMostSetBit(int n) {
return (n & (-n));
}
// public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm)
// {
// HashMap<Integer, Integer> temp
// = hm.entrySet()
// .stream()
// .sorted((i1, i2)
// -> i1.getValue().compareTo(
// i2.getValue()))
// .collect(Collectors.toMap(
// Map.Entry::getKey,
// Map.Entry::getValue,
// (e1, e2) -> e1, LinkedHashMap::new));
// return temp;
// }
// static int[] sortint(int a[]) {
// ArrayList<Integer> al = new ArrayList<>();
// for (int i : a) {
// al.add(i);
// }
// Collections.sort(al);
// for (int i = 0; i < a.length; i++) {
// a[i] = al.get(i);
// }
// return a;
// }
// static long[] sortlong(long a[]) {
// ArrayList<Long> al = new ArrayList<>();
// for (long i : a) {
// al.add(i);
// }
// Collections.sort(al);
// for (int i = 0; i < al.size(); i++) {
// a[i] = al.get(i);
// }
// return a;
// }
// static ArrayList<Integer> primesTilN(int n) {
// boolean p[] = new boolean[n + 1];
// ArrayList<Integer> al = new ArrayList<>();
// Arrays.fill(p, true);
// int i = 0;
// for (i = 2; i * i <= n; i++) {
// if (p[i] == true) {
// al.add(i);
// for (int j = i * i; j <= n; j += i) {
// p[j] = false;
// }
// }
// }
// for (i = i; i <= n; i++) {
// if (p[i] == true) {
// al.add(i);
// }
// }
// return al;
// }
static int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
// static long gcd(long a, long b) {
// if (a == 0) {
// return b;
// }
// return gcd(b % a, a);
// }
// static long pow(long x, long y) {
// long result = 1;
// while (y > 0) {
// if (y % 2 == 0) {
// x = x * x;
// y = y / 2;
// } else {
// result = result * x;
// y = y - 1;
// }
// }
// return result;
// }
// static boolean[] esieve(int n) {
// boolean p[] = new boolean[n + 1];
// Arrays.fill(p, true);
// for (int i = 2; i * i <= n; i++) {
// if (p[i] == true) {
// for (int j = i * i; j <= n; j += i) {
// p[j] = false;
// }
// }
// }
// return p;
// }
static int[] readarr(int n) {
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
return arr;
}
// static HashMap<Integer, Integer> mapCounter(int arr[]) {
// for(int i : arr) {
// if(map.containsKey(i)) map.put(arr[i], map.get(arr[i])+1);
// else map.put(arr[i], 1);
// }
// }
static HashMap<Integer, Integer> mapCounter(int arr[]) {
HashMap<Integer, Integer> map = new HashMap<>();
for(int i : arr) {
if(map.containsKey(i)) map.put(i, map.get(i)+1);
else map.put(i, 1);
}
return map;
}
static double calcDistance(int x, int y, int a, int b) {
return Math.sqrt(Math.pow(x-a, 2) + Math.pow(y-b, 2));
}
static void printarr(int arr[]) {
System.out.println(Arrays.toString(arr));
}
public static HashMap<Integer, String> byValueS(HashMap<Integer, String> map) {
List<Map.Entry<Integer, String>> list = new LinkedList<>(map.entrySet());
Collections.sort(list, new Comparator<HashMap.Entry<Integer, String>>() {
public int compare(Map.Entry<Integer, String> o1, Map.Entry<Integer, String> o2) {
return o1.getValue().compareTo(o2.getValue());
}
}) ;
HashMap<Integer, String> map2 = new LinkedHashMap<>();
for(Map.Entry<Integer, String> i : list) {
map2.put(i.getKey(), i.getValue());
}
return map2;
}
public static HashMap<Integer, Integer> byValueI(HashMap<Integer, Integer> map) {
List<Map.Entry<Integer, Integer>> list = new LinkedList<>(map.entrySet());
Collections.sort(list, new Comparator<HashMap.Entry<Integer, Integer>>() {
public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
return o1.getValue().compareTo(o2.getValue());
}
}) ;
HashMap<Integer, Integer> map2 = new LinkedHashMap<>();
for(Map.Entry<Integer, Integer> i : list) {
map2.put(i.getKey(), i.getValue());
}
return map2;
}
public static void main(String[] args)
{
int testcases = sc.nextInt();
outerrrr:
while (testcases-- > 0) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int v = 1;
int l1 = a-v;
int l2 = Math.abs(c-b) + c-v;
if(l1 < l2) {
System.out.println("1");
}
else if(l2 < l1) {
System.out.println("2");
}
else {
System.out.println("3");
}
/*///////////////////////////////////////////////////////////////////////////////////////////////////
------------------------------------END OF CODE-----------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////////////*/
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 517ea635c57fc542e94780376ea9bc3a | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
public class A {
static FastScanner fs = new FastScanner();
public static void main(String[] args) {
// int tc = 1;
int tc = fs.nextInt();
while (tc-- > 0) {
solve();
}
}
public static void solve() {
int a = fs.nextInt();
int b = fs.nextInt();
int c = fs.nextInt();
int elv1 = a - 1;
int elv2 = Math.abs(c - b) + (c - 1);
// System.out.println(elv1 - elv2);
if(elv1 < elv2) {
System.out.println(1);
return;
}
else if(elv1 > elv2) {
System.out.println(2);
return;
}
System.out.println(3);
}
// ----------------------------------------------------------------------------------//
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
char nextChar() {
return next().charAt(0);
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static class Debug {
public static void debug(long a) {
System.out.println("--> " + a);
}
public static void debug(long a, long b) {
System.out.println("--> " + a + " + " + b);
}
public static void debug(char a, char b) {
System.out.println("--> " + a + " + " + b);
}
public static void debug(int[] array) {
System.out.print("Array--> ");
System.out.println(Arrays.toString(array));
}
public static void debug(char[] array) {
System.out.print("Array--> ");
System.out.println(Arrays.toString(array));
}
public static void debug(HashMap<Integer, Integer> map) {
System.out.print("Map--> " + map.toString());
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 01c47c39ccfc6d002d32660b7518240c | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scr = new Scanner(System.in);
int t = Integer.parseInt(scr.nextLine());
while(t > 0) {
int a = scr.nextInt()-1;
int x = scr.nextInt();
int y = scr.nextInt();
int b;
if(x > y)b = x - 1;
else b = Math.abs(x-y) + (y - 1);
if(a == b)System.out.println(3);
else if(a < b)System.out.println(1);
else System.out.println(2);
t--;
}
if(scr != null)scr.close();
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 4c51b0a28e6966e01e02ff2bcff02d7d | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.io.*;
import java.text.SimpleDateFormat;
import java.time.LocalTime;
import java.util.*;
import static java.lang.Math.max;
public class CodeForces {
static int MOD = 100007;
public static void main(String[] args) throws java.lang.Exception {
//PlayOff();
/*Interview i = new Interview();
int a = Integer.valueOf(4);
System.out.println(a);*/
//ShortSubstrings();
TwoElevators();
}
private static void TwoElevators() {
FastReader sc = new FastReader();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int t =sc.nextInt();
while (t-- > 0) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int res = Math.abs(a-1);
int res1 = Math.abs(b - c) + (c - 1);
if (res == res1)out.println("3");
else if (res < res1)out.println("1");
else out.println("2");
}
out.flush();
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 5316cbda2f6a33521d620a13a9d31837 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
for (int i = 0; i < t; ++i) {
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
if (c <= b) {
if (a < b) {
System.out.println(1);
} else if (a > b) {
System.out.println(2);
} else {
System.out.println(3);
}
} else {
if (a - 1 < c - b + c - 1) {
System.out.println(1);
} else if (a - 1 > c - b + c - 1) {
System.out.println(2);
} else {
System.out.println(3);
}
}
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 3b9a07bf62a1793d39f44789dfe71456 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes |
import java.util.Scanner;
/**
*
* @author Lenovo
*/
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
for (int tc = 0; tc < t; tc++) {
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
int c2 = 0, c1 = a - 1;
if (c < b) {
c2 = b - 1;
} else {
c2 = c - b + c - 1;
}
if (c1 < c2) {
System.out.println("1");
} else if (c1 == c2) {
System.out.println("3");
} else {
System.out.println("2");
}
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 1cea1dd2c0ba808124308ac006281e40 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes |
import java.util.*;
public class Himansu {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
if(a==1)
System.out.println(a);
else {
int res1=a;
int res2=0;
if(c>b) {
res2=c-b+c;
}else {
res2=b;
}
if(res1==res2)
System.out.println(3);
else if(res1<res2)
System.out.println(1);
else
System.out.println(2);
}
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 7bf0c2fd01f64d3e6ee326090265443f | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | // Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class StringTask {
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 {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static int solve(int a , int b,int c)
{
if(a==1)
return 1;
else
{
int tA = Math.abs(a-1);
int tB = Math.abs(b-c) + Math.abs(c-1);
if(tA < tB)
return 1;
else if(tA > tB)
return 2;
else
return 3;
}
}
/*
B=3, C = 1
*/
public static void main(String[] args)
{
FastReader in = new FastReader();
int tc = in.nextInt();
while(tc-->0)
{
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int res = solve(a,b,c);
System.out.println(res);
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 6f8c88460c25026235ada24eaada4e93 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import static java.lang.Math.abs;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
public class A {
private static final Scanner IN = new Scanner (System.in);
private static final OutputStream OS = System.out;
public static void main (final String[] args) {
try (final var out = new PrintWriter (OS)) {
solve (out);
}
}
private static void solve (final PrintWriter out) {
final var t = IN.nextInt ();
for (var i = 0; i < t; i++) {
final var a = IN.nextInt ();
final var b = IN.nextInt ();
final var c = IN.nextInt ();
final var lift1 = a;
final var lift2 = abs (b - c) + c;
final int ans;
if (lift1 == lift2) {
ans = 3;
} else {
if (lift1 < lift2) {
ans = 1;
} else {
ans = 2;
}
}
out.println (ans);
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 8b7bdf620b604422cf94748e214ca3fa | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class Codeforces {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
int[] arr = new int[t];
for (int i = 0; i < arr.length; i++) {
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
int countA = a - 1;
int countBC = 0;
if(b > c) countBC = (b - c) + (c - 1);
else countBC = (c - b) + (c - 1);
if(countA > countBC) arr[i] = 2;
else if(countA < countBC) arr[i] = 1;
else arr[i] = 3;
}
for (int i = 0; i < arr.length; i++)
System.out.println(arr[i]);
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | fb8e7794284ccc117eedb92a1b3db0c5 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.*;
import java.util.Arrays;
public class Acmp {
public static void main(String[] args) {
Scanner ai = new Scanner(System.in);
int a = ai.nextInt();
while(a-- > 0){
int[] arr = new int[3];
for(int i = 0; i < 3; i++){
arr[i] = ai.nextInt();
}
for(int i = 0; i < 3; i++){
if(arr[0] == 1){
System.out.println(1);
break;
}
else if(arr[1] > arr[2] && arr[0] - 1 == arr[1] - arr[2] + (arr[2] - 1)){
System.out.println(3);
break;
}
else if(arr[1] > arr[2] && arr[0] - 1 < arr[1] - arr[2] + (arr[2] - 1)){
System.out.println(1);
break;
}
else if(arr[1] > arr[2] && arr[0] - 1 > arr[1] - arr[2] + (arr[2] - 1)){
System.out.println(2);
break;
}
else if(arr[0] - 1 < (arr[2] - arr[1]) + (arr[2] - 1)){
System.out.println(1);
break;
}
else if(arr[0] - 1 > (arr[2] - arr[1]) + (arr[2] - 1)){
System.out.println(2);
break;
}
else if(arr[0] - 1 == (arr[2] - arr[1]) + (arr[2] - 1)){
System.out.println(3);
break;
}
}
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 22b2803f16623ced974b7985dd948da5 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | //package com.company;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class questions {
public static void main(String[] args) {
solve();
}
static void solve()
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t ; i++) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int x = Math.abs(1-a);
int y = Math.abs(b-c)+c;
int ans = Math.abs(y-1);
if(x==ans)
{
System.out.println("3");
}
else if(x>ans)
{
System.out.println("2");
}
else if(x<ans) {
System.out.println("1");
}
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 89e710b495d8c2fadb9ac360b12f3fe0 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.*;
import java.io.*;
public class pariNa {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
StringBuilder finalAnswer=new StringBuilder();
//finalAnswer.append().append('\n');
int t=sc.nextInt();
outer:
while(t-->0){
long a=sc.nextLong();
long b=sc.nextLong();
long c=sc.nextLong();
if(Math.abs(a-1)<Math.abs(Math.abs((c-b))+Math.abs((c-1)))) {
System.out.println(1);
}
else if(Math.abs(a-1)>Math.abs(Math.abs((c-b))+Math.abs((c-1)))) {
System.out.println(2);
}
else {
System.out.println(3);
}
}
System.out.println(finalAnswer);
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 2bd0168c04ec36e64446037eb50993e0 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.*;
public class Solution{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++){
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int x = a - 1;
int y = 0;
if (b == 1){
y = 2 * (c - b);
} else {
if (c > b){
y = (c - b) + (c - 1);
} else if (b > c){
y = (b - c) + (c - 1);
}
}
if (x < y){
System.out.println(1);
} else if (x > y) {
System.out.println(2);
} else {
System.out.println(3);
}
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 799da91de9036af546efd28d367865d7 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class TwoElevator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i = 0; i < t; i++){
int a,b,c;
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
int timeNeedForFirst = a - 1;
int timeNeedForTwo = Math.abs(c - b) + (c - 1);
if(timeNeedForFirst > timeNeedForTwo){
System.out.println(2);
}else if(timeNeedForFirst == timeNeedForTwo){
System.out.println(3);
}else{
System.out.println(1);
}
}
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 06b8fe81910db0b4e79ed23a5a2df7df | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class Task1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int testCount = Integer.parseInt(scanner.nextLine());
for (int i = 0; i < testCount; i++) {
String s = scanner.nextLine();
String[] s1 = s.split(" ");
System.out.println(getInfo(Integer.parseInt(s1[0]), Integer.parseInt(s1[1]), Integer.parseInt(s1[2])));
}
}
private static int getInfo(int a, int b, int c) {
int secondLift = Math.abs(b - c) + c;
return a == secondLift ? 3 : a < secondLift ? 1 : 2;
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | d92f91c8284dc04949c62da6d8986285 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class question4 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int t=sc.nextInt();
int a[]= new int[t];
int b[]= new int[t];
int c[]= new int[t];
for(int i=0; i<t; i++) {
a[i] = sc.nextInt();
b[i] = sc.nextInt();
c[i] = sc.nextInt();
}
for(int i=0; i<t; i++) {
if (Math.abs((a[i] - 1)) == Math.abs((Math.abs(b[i] - c[i]) + Math.abs(c[i] - 1))))
System.out.println(3);
else if ((Math.abs((a[i] - 1)) > Math.abs((Math.abs(b[i] - c[i]) + Math.abs(c[i] - 1)))))
System.out.println(2);
else if ((Math.abs((a[i] - 1)) < Math.abs((Math.abs(b[i] - c[i]) + Math.abs(c[i] - 1)))))
System.out.println(1);
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | c1ecc2be793b7392719cd800c34db4b0 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.*;
public class TwoElevators {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
int numCases = stdin.nextInt();
for (int i = 0; i < numCases; i++) {
int a = stdin.nextInt();
int b = stdin.nextInt();
int c = stdin.nextInt();
// find which elevator is the fastest
int optionA = Math.abs(a-1);
int optionB = Math.abs(b-c);
optionB += Math.abs(c-1);
int res = -1;
if (optionA < optionB) {
res = 1;
} else if (optionB < optionA) {
res = 2;
} else {
res = 3;
}
System.out.println(res);
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | e2b66875e7a07f0153fd4d7a4d7a97e0 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
while(n>0) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d=0;
if(b>c) {
d+=b-1;
a-=1;
}
if(c>=b) {
d+=(2*c) - b -1 ;
a-=1;
}
if(a==0 || a<d) {
System.out.println(1);
}
else if(d==a) {
System.out.println(3);
}
else {
System.out.println(2);
}
n--;
}
sc.close();
}
}
| Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 1dcd230900ebbd1108c838afdb5e836d | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.Scanner;
public final class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
for( int i = 0; i < t; i++ ) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int dif_b = 0;
int dif_a = 0;
if( c <= b )
dif_b = b-1;
else if( c > b )
dif_b = (c-b)+(c-1);
dif_a = a-1;
if( dif_b == dif_a )
System.out.println("3");
else if( dif_b > dif_a )
System.out.println("1");
else
System.out.println("2");
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output | |
PASSED | 482cd4c66038cb0d47578d99bbec40e1 | train_110.jsonl | 1662993300 | Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator. | 256 megabytes | import java.util.*;
public class Codeforces {
public static void main(String[] args) {
try {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-->0) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if(a==1)
System.out.println(1);
else{
int down = a-1;
if(a<b)
System.out.println(1);
else{
if(c>b){
int down2 = c - b + c - 1;
if(down<down2)
System.out.println(1);
else if(down>down2)
System.out.println(2);
else System.out.println(3);
}
else if(b<a){
System.out.println(2);
}
else System.out.println(3);
}
}
}
}
catch (Exception e){
System.out.println(e);
}
}
} | Java | ["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"] | 1 second | ["1\n3\n2"] | NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$. | Java 11 | standard input | [
"math"
] | aca2346553f9e7b6e944ca2c74bb0b3d | The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement. | 800 | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time). | standard output |
Subsets and Splits