exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
f773f082b28c8a6964c8e03efe0516db
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class ACM { private static Map<String, Integer> table = new HashMap<>(); public static void main(String[] args) { computeTable(); Scanner in = new Scanner(System.in); int t = in.nextInt(); in.nextLine(); for (; t > 0; t--) { String key = in.nextLine(); System.out.println(table.get(key)); } } private static void computeTable() { int index = 1; for (char a = 'a'; a <= 'z'; a++) { for (char b = 'a'; b <= 'z'; b++) { if (a == b) continue; String s = new StringBuilder().append(a) .append(b).toString(); table.put(s, index++); } } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
acab77a7c490476979663e4f85c32010
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
//package com.company; import java.util.*; import java.io.*; public class Dictionary { 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) { String word = br.readLine(); int n1 = word.charAt(0) - 'a'; int n2 = word.charAt(1) - 'a'; int num = n1 * 26 + n2; if(n2 > n1) num -= n1; else num -= n1 - 1; System.out.println(num); } br.close(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
aa54a509d913f84a5ed8a912c2f738c8
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.HashMap; import java.util.InputMismatchException; import java.io.IOException; import java.util.Map; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Roy */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); BDictionary solver = new BDictionary(); solver.solve(1, in, out); out.close(); } static class BDictionary { public void solve(int testNumber, InputReader in, OutputWriter out) { int tCases = in.readInteger(); int index = 1; Map<String, Integer> dictionary = new HashMap<>(); for (char c1 = 'a'; c1 <= 'z'; c1++) { for (char c2 = 'a'; c2 <= 'z'; c2++) { if (c1 != c2) dictionary.put(c1 + "" + c2, index++); } } for (int cs = 1; cs <= tCases; ++cs) { String s = in.readString(); out.printLine(dictionary.get(s)); } } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void printLine(Object... objects) { this.print(objects); writer.println(); } public void close() { writer.flush(); writer.close(); } } static class InputReader { private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; private final InputStream stream; private final byte[] buf = new byte[1024]; public InputReader(InputStream stream) { this.stream = stream; } private long readWholeNumber(int c) { long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int readInteger() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = (int) readWholeNumber(c); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { boolean isSpaceChar(int ch); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
57a1b5ebd919ec96eb755fa1fc996c87
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Solution { static List<List<Integer>> ans; public static void main(String[] args) { Scanner sc=new Scanner(System.in); // div 3; int t=sc.nextInt(); while (t>0){ t--; String s=sc.next(); int ff=s.charAt(0)-97; ff=ff*25; if(s.charAt(0)>s.charAt(1)){ System.out.println(ff+s.charAt(1)-96); }else{ System.out.println(ff+s.charAt(1)-97); } } } private static void solve(List<List<Integer>> lists, int root, int pa, List<Integer> cur) { cur.add(root); boolean tt=true; for(int child:lists.get(root)){ if(child!=pa){ solve(lists,child,root,cur); tt=false; } } if(tt){ ans.add(new ArrayList<>(cur)); cur.clear(); } } } class Pair{ int x; int y; Pair(int a,int b){ x=a; y=b; } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
bda46134ed786648f1f41ead07b71339
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; public class Dictionary { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); final int a = 97; int num = sc.nextInt(); sc.nextLine(); ArrayList<String> arr = new ArrayList<String>(); for (int j = 97; j < 123; j++) { int x = j; for (int i = 97; i < 123; i++) { int y = i; if (x != y) { String str = x + "" + y; arr.add(str); } } } for (int j = 0; j < num; j++) { String s = sc.nextLine(); char w = s.charAt(0); char r = s.charAt(1); int t = w; int f = r; for (int i = 0; i < arr.size(); i++) { String hi = t+""+f; if(arr.get(i).equals(hi)) { System.out.println(i+1); break; } } } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
100e6ad59df6f6f143c6dd99593c5e5a
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 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=1;i<=T;i++) { int count=1; int flag=0; String S=SC.next(); char c1=S.charAt(0); char c2=S.charAt(1); for(char ch='a';ch<='z';ch++) { for(char j='a';j<='z';j++) { if(c1==ch&&c2==j) { flag=1; break; } else{ if(ch!=j) count++; } } if(flag==1) break; } System.out.println(count); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
de210dcee74aa3b0055b25347d1e9155
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; public final class CF { public static void main(String[] args) { FastReader ob = new FastReader(); HashMap<String,Integer> hm = new HashMap<>(); int c=1; for(char ch1='a';ch1<='z';ch1++) { for(char ch2 = 'a'; ch2<='z'; ch2++) { if(ch1!=ch2) { String s = ch1 + "" + ch2; hm.put(s, c); ++c; } } } int t = ob.nextInt(); StringBuffer sb = new StringBuffer(); while (t-- > 0) { String s= ob.nextLine(); System.out.println(hm.get(s)); } System.out.println(sb); } } class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } class PairComparator implements Comparator<Pair> { @Override public int compare(Pair p1, Pair p2) { return p1.x-p2.x; } } 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
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
8ec8d636bba4c141925d292a7a198791
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
//import java.io.IOException; import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.InputMismatchException; import java.util.List; public class Dictionary { static InputReader inputReader=new InputReader(System.in); static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static void solve() throws IOException { String str=inputReader.readString(); int index=(str.charAt(0)-'a')*25; for (char c='a';c<='z';c++) { if (c!=str.charAt(0)) { index++; } if (str.charAt(1)==c) { break; } } out.println(index); } static PrintWriter out=new PrintWriter((System.out)); static void SortDec(long arr[]) { List<Long>list=new ArrayList<>(); for(long ele:arr) { list.add(ele); } Collections.sort(list,Collections.reverseOrder()); for (int i=0;i<list.size();i++) { arr[i]=list.get(i); } } static void Sort(long arr[]) { List<Long>list=new ArrayList<>(); for(long ele:arr) { list.add(ele); } Collections.sort(list); for (int i=0;i<list.size();i++) { arr[i]=list.get(i); } } public static void main(String args[])throws IOException { int t=inputReader.nextInt(); while (t-->0) { solve(); } long s = System.currentTimeMillis(); // out.println(System.currentTimeMillis()-s+"ms"); out.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
009010de87ef8637e5dbb2d4ecf280f0
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.HashMap; import java.util.Scanner; public class DetectiveTask { public static void main(String[] args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt(); HashMap<String, Integer> hm = new HashMap<>(); int x= 1; for (int i = 'a' ; i <= 'z' ; i++) { for (int j = 'a' ; j <= 'z' ; j++) { if (i == j) continue; String s1 = (char)i +""+(char)j; hm.put(s1, x++); } } while (n-- > 0) { String str = sc.next(); System.out.println(hm.get(str)); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
d06bae7ddb6841c6d77300869667e100
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int k = sc.nextInt(); for(int i =0;i<k;i++) { String s = sc.next(); char c1 = s.charAt(0); char c2 = s.charAt(1); int x = c1 -97; int y = c2-97; int res = x*25 + y; if(x>y) res++; System.out.println(res); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
be268c6ab7953af1c4400e45860b26b0
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Dictionary { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); ArrayList<String> dict = new ArrayList<>(); for(int i=0; i<26; i++){ for (int j=0; j<26; j++){ if (i!=j){ dict.add((char)('a'+i) + "" + (char)('a'+j)); } } } while(t-- > 0){ String w = s.next(); int loc = dict.indexOf(w)+1; System.out.println(loc); } s.close(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
d8155c1404752cfd88885810c41d48ae
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; public class B1674 { public static void main(String[] args) throws NumberFormatException, IOException { r.init(); int t = r.readInt(); while(t-- > 0) { String s = r.read(); int m = (s.charAt(0) - '0') - 49; int res = m*25; int n = (s.charAt(1) - '0') - 48; res += n; if(n > m) res--; System.out.println(res); } } static class r { // int[] in = new int[2]; // n = in[0]; // k = in[1]; static BufferedReader br; static StringTokenizer st; public static void init() { br = new BufferedReader(new InputStreamReader(System.in)); } public static String read() throws NumberFormatException, IOException { return br.readLine(); } public static int readInt() throws NumberFormatException, IOException { return Integer.parseInt(br.readLine()); } public static int[] readInts(int n) throws NumberFormatException, IOException { st = new StringTokenizer(br.readLine(), " "); int[] arr = new int[n]; for(int i = 0; i < n; i++) { arr[i] = Integer.parseInt(st.nextToken()); } return arr; } public static ArrayList<Integer> readIntsAsList(int n) throws NumberFormatException, IOException { st = new StringTokenizer(br.readLine(), " "); ArrayList<Integer> al = new ArrayList<>(); for(int i = 0; i < n; i++) { al.add(Integer.parseInt(st.nextToken())); } return al; } public static long readLong() throws NumberFormatException, IOException { return Long.parseLong(br.readLine()); } public static long[] readLongs(int n) throws NumberFormatException, IOException { st = new StringTokenizer(br.readLine(), " "); long[] arr = new long[n]; for(int i = 0; i < n; i++) { arr[i] = Long.parseLong(st.nextToken()); } return arr; } public static ArrayList<Long> readLongsAsList(int n) throws NumberFormatException, IOException { st = new StringTokenizer(br.readLine(), " "); ArrayList<Long> al = new ArrayList<>(); for(int i = 0; i < n; i++) { al.add(Long.parseLong(st.nextToken())); } return al; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
40d27c4c440c0c9de47732598a0fd51d
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; /** * * @author Acer */ public class NewClass_B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); while(T-- > 0){ String s = sc.next(); int x = (int)s.charAt(0)-97; int y = (int)s.charAt(1)-96; int index = (x*26)+y; if(s.charAt(0) > s.charAt(1)){ index-=(x*1); } else{ x++; index-=(x*1); } System.out.println(index); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
5721a5e7d9f678d5f61c67a7093c37a7
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.lang.*; public class solve { static Scanner sc; public static void main (String[] args) { sc = new Scanner(System.in); // testCases int testCases = sc.nextInt(); while (testCases > 0) { justDoIt(); testCases--; } } // ==== SOLVE ============== static void justDoIt () { // int n = sc.nextInt(), // m = sc.nextInt(); String str = sc.next(); int ans = ((str.charAt(0) - 'a') * 25) + (str.charAt(1) - 'a'); ans += (str.charAt(1) > str.charAt(0)) ? 0 : 1; System.out.println(ans); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
252ebc3a4a39681249b5bac9aa016a9a
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Map<String , Integer> map= new HashMap<>(); int idx = 1 ; for(int i=0 ; i < 26 ; i++){ for(int j =0 ; j<26 ; j++){ if(i != j ){ String str=""; char ch ='a'; ch+=i; str+=ch; ch = 'a'; ch+=j; str+=ch; map.put(str , idx++); } } } int tc = sc.nextInt(); while (tc --> 0 ){ System.out.println(map.get(sc.next())); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
ed45ed996de6a49e5c751d88b918ebac
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; public class Dictionary { public static PrintWriter out; public static void main(String[] args)throws IOException{ Scanner sc=new Scanner(); out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0) { String str=sc.next(); int count=0; count+=(str.charAt(0)-'a')*25; if(str.charAt(1)-'a'>str.charAt(0)-'a') { count+=str.charAt(1)-'a'; }else { count+=str.charAt(1)-'a'+1; } out.println(count); } out.close(); } public static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { 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
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
3928f0a78249d517978d415b738caa32
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class B { private static FastReader fr; private static OutputStream out; private static int mod = (int)(1e9+7); private void solve() { int t = fr.nextInt(); while(t-- > 0) { char arr[] = fr.next().toCharArray(); int count = 0; count += 25 * (arr[0] - 'a'); if(arr[1] > arr[0]) { count += arr[1] - 'a'; }else{ count += arr[1] - 'a' + 1; } println(count); } } public static void main(String args[]) throws IOException{ new B().run(); } private static int modInverse(int a) { int m0 = mod; int y = 0, x = 1; if (mod == 1) return 0; while (a > 1) { int q = (int)(a / mod); int t = mod; mod = a % mod; a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } private ArrayList<Integer> factors(int n, boolean include){ ArrayList<Integer> factors = new ArrayList<>(); if(n < 0) return factors; if(include) { factors.add(1); if(n > 1) factors.add(n); } int i = 2; for(;i*i<n;i++) { if(n % i == 0) { factors.add(i); factors.add(n / i); } } if(i * i == n) { factors.add(i); } return factors; } private ArrayList<Integer> PrimeFactors(int n) { ArrayList<Integer> primes = new ArrayList<>(); int i = 2; while (i * i <= n) { if (n % i == 0) { primes.add(i); n /= i; while (n % i == 0) { primes.add(i); n /= i; } } i++; } if(n > 1) primes.add(i); return primes; } private boolean isPrime(int n) { if(n == 0 || n == 1) { return false; } if(n % 2 == 0) { return false; } for(int i=3;i*i<=n;i+=2) { if(n % i == 0) { return false; } } return true; } private ArrayList<Integer> Sieve(int n){ boolean bool[] = new boolean[n+1]; Arrays.fill(bool, true); bool[0] = bool[1] = false; for(int i=2;i*i<=n;i++) { if(bool[i]) { int j = 2; while(i*j <= n) { bool[i*j] = false; j++; } } } ArrayList<Integer> primes = new ArrayList<>(); for(int i=2;i<=n;i++) { if(bool[i]) primes.add(i); } return primes; } private HashMap<Integer, Integer> addToHashMap(HashMap<Integer, Integer> map, int arr[]){ for(int val: arr) { if(!map.containsKey(val)) { map.put(val, 1); }else { map.put(val, map.get(val) + 1); } } return map; } private int factorial(int n) { long fac = 1; for(int i=2;i<=n;i++) { fac *= i; fac %= mod; } return (int)(fac % mod); } // private static int pow(int base,int exp){ // if(exp == 0){ // return 1; // }else if(exp == 1){ // return base; // } // int a = pow(base,exp/2); // a = ((a % mod) * (a % mod)) % mod; // if(exp % 2 == 1) { // a = ((a % mod) * (base % mod)); // } // return a; // } private static int gcd(int a,int b){ if(a == 0){ return b; } return gcd(b%a,a); } private static int lcm(int a,int b){ return (a * b)/gcd(a,b); } private void run() throws IOException{ fr = new FastReader(); out = new BufferedOutputStream(System.out); solve(); out.flush(); out.close(); } private static class FastReader{ private static BufferedReader br; private static StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); out = new BufferedOutputStream(System.out); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public char[] nextCharArray() { return next().toCharArray(); } public int[] nextIntArray(int n) { int arr[] = new int[n]; for(int i=0;i<n;i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n) { long arr[] = new long[n]; for(int i=0;i<n;i++) { arr[i] = nextLong(); } return arr; } public String[] nextStringArray(int n) { String arr[] = new String[n]; for(int i=0;i<n;i++) { arr[i] = next(); } return arr; } } public static void print(Object str) { try { out.write(str.toString().getBytes()); } catch (IOException e) { e.printStackTrace(); } } public static void println(Object str) { try { out.write((str.toString() + "\n").getBytes()); } catch (IOException e) { e.printStackTrace(); } } public static void println() { println(""); } public static void printArray(Object str[]){ for(Object s : str) { try { out.write(str.toString().getBytes()); } catch (IOException e) { e.printStackTrace(); } } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
a805164952f3cd687644c76e46ab155b
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import java.util.*; public class P1674B { ArrayList<String> dictionary = new ArrayList<>(); public static void main(String[] args) throws Exception { new P1674B().run(); } void run() throws Exception { Scanner scanner = new Scanner(getInputStream()); int t = scanner.nextInt(); for(char f = 'a'; f <= 'z'; f++) { for(char s = 'a'; s <= 'z'; s++) { if (f == s) { continue; } dictionary.add(new StringBuilder().append(f).append(s).toString()); } } while(t-- > 0) { String s = scanner.next(); getOutputStream().println(getIndex(s)); } } private int getIndex(String s) { return dictionary.indexOf(s) + 1; } InputStream getInputStream() { return System.in; } PrintStream getOutputStream() { return System.out; } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
f097e0f079352ea26e787cee014c186e
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String args[]) { FastScanner input = new FastScanner(); ArrayList<String> a=new ArrayList<>(); for (char i = 'a'; i <='z'; i++) { for (char j = 'a'; j <='z'; j++) { if(i!=j) { a.add(i+""+j); } } } int tc = input.nextInt(); work: while (tc-- > 0) { String s = input.next(); System.out.println(a.indexOf(s)+1); } } 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()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() throws IOException { return br.readLine(); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
8491dd3d521d0987a35b62bd5f7d817e
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class Solution{ public static void main(String []args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); char[] chr = new char[2]; int index; for (int i = 0; i < n; i++) { String str = sc.nextLine(); chr[0] = str.charAt(0); chr[1] = str.charAt(1); int first = chr[0] - 'a'; int second = chr[1] - 'a'; index = first * 25; index += second +1; if(chr[0] < chr[1]) index -= 1; System.out.println(index); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
41540cdf41c30fa233666da560a8d5cc
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class B { public static void main(String[] args) { Scanner obj = new Scanner(System.in); int n = obj.nextInt(); while(n-->0) { String s = obj.next(); int k1 = ((int)(s.charAt(0)-'a')+1); int k2 = ((int)(s.charAt(1)-'a')+1); int ans = (k1-1)*25; if(k2>k1) ans=ans+(k2-1); else ans = ans+(k2); System.out.println(ans); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
9a72c9800acb165582869d61ba89f9df
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class Dictionary { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++){ char[] ch=sc.next().toCharArray(); int a=ch[0]-'a'; int b=ch[1]-'a'; int ans=0; if(a<b) ans+=(b); else ans+=(b+1); ans+=a*25; System.out.println(ans); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
b06380478c07f66e3cc8e0d1dda4c6ac
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
// package Round786DIV3; import java.io.*; import java.util.StringTokenizer; public class B { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while(t-->0) { char[]a=sc.nextLine().toCharArray(); int start= a[0]-'a'; int idx= start*25; int end = a[1]-'a'; if(end>start)idx+=end; else idx=idx+end+1; pw.println(idx); } pw.close(); } // -------------------------------------------------------Scanner--------------------------------------------------- static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { 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(); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
357c0784570d2f16ab7baad77aeb4240
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; public class A { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { String s = sc.next(); int[] val = new int[2]; val[0] = s.charAt(0)- 96; val[1] = s.charAt(1) - 96; int sum = 0; if (val[1] < val[0]) val[1]++; sum += (val[0]*25) - 25 + val[1] - 1; out.println(sum); } out.close(); } static final Random random = new Random(); static void shuffleSort(int[] a) { int n = a.length; for (int i = 0; i < n; i++) { int r = random.nextInt(n), temp = a[r]; a[r] = a[i]; a[i] = temp; } Arrays.sort(a); } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if(x.charAt(0) == '-') { neg = true; start++; } for(int i = start; i < x.length(); i++) if(x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if(dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg?-1:1); } public boolean ready() throws IOException {return br.ready();} int[] readArray(int n) throws IOException { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
50c363c7be167a3b3e8b89c28245b27b
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class aa { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int c = 0 ; while(t-->0){ String s = sc.next(); int a = ((int)(s.charAt(0))-96); int b = (a-1)*25; if (s.charAt(0)>s.charAt(1) ){ c = ((int)(s.charAt(1))-96); }else{ c = ((int)(s.charAt(1))-96)-1; } System.out.println(b+c); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
8cd19b8602914a82c74a24bb4d5d09cd
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Dictionary { 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){ String word = br.readLine(); int ans = solution(word); System.out.println(ans); } } public static int solution(String word){ char first = word.charAt(0); char second = word.charAt(1); int index = 0; index = (first-'a') * 25; index+= second-'a'; if(second<first){ ++index; } return index; } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
6e44af05cd8ea46e2d2db981319abced
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; public class B { public static void main(String[] args) { FastReader in = new FastReader(); PrintWriter out = new PrintWriter(System.out); int T = in.nextInt(); for(int ttt = 1; ttt <= T; ttt++) { char[] s = in.next().toCharArray(); int ans = 25*(s[0]-'a') + (s[1]-'a') + (s[1] > s[0] ? 0 : 1); out.println(ans); } 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; } int[] readInt(int size) { int[] arr = new int[size]; for(int i = 0; i < size; i++) arr[i] = Integer.parseInt(next()); return arr; } long[] readLong(int size) { long[] arr = new long[size]; for(int i = 0; i < size; i++) arr[i] = Long.parseLong(next()); return arr; } int[][] read2dArray(int rows, int cols) { int[][] arr = new int[rows][cols]; for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) arr[i][j] = Integer.parseInt(next()); } return arr; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
722e41e0d0ac0d9ac2dcafa15938b72a
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class Dictonary { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ String s=sc.next(); if(s.charAt(1)-'a'<s.charAt(0)-'a'){ System.out.println(25*(s.charAt(0)-'a')+s.charAt(1)-'a'+1); } else{ System.out.println(25*(s.charAt(0)-'a')+s.charAt(1)-'a'); } t=t-1; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
d48163584dba95ceb5898bc48f6c96df
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.PriorityQueue; import java.util.StringTokenizer; public class B { public static void main(String[]args) throws IOException { Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0) { String s=sc.next(); int v=s.charAt(1)-'a'; out.println((s.charAt(0)-'a')*25+(s.charAt(1)<s.charAt(0)?v+1:v)); } out.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public boolean hasNext() {return st.hasMoreTokens();} public int nextInt() throws IOException {return Integer.parseInt(next());} public double nextDouble() throws IOException {return Double.parseDouble(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public boolean ready() throws IOException {return br.ready(); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
82ad65ebf83a79e8b8be5e1c3ff475f6
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int i=0; i<t; i++) { String str = s.next(); int a = (int) str.charAt(0); int b = (int) str.charAt(1); if(b>a) b--; a = Math.abs(97 - a); b = Math.abs(96 - b); System.out.println(a * 25 + b); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
028dec43cc287b77646fcea3cc3b73df
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); while(tc-->0) { char s[] = sc.next().toCharArray(); int ans = (s[0]-'a')*25 + s[1]-'a'; if(s[0]>s[1]) ans++; System.out.println(ans); } sc.close(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
72e7ca60e2221b0074c4df07a5566701
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; public class Main { public static int INF = 0x3f3f3f3f; public static int mod = 1000000007; public static int mod9 = 998244353; public static void main(String args[]){ try { PrintWriter o = new PrintWriter(System.out); boolean multiTest = true; // init if(multiTest) { int t = fReader.nextInt(), loop = 0; while (loop < t) {loop++;solve(o);} } else solve(o); o.close(); } catch (Exception e) {e.printStackTrace();} } static void solve(PrintWriter o){ try { String str = fReader.nextString(); char[] s = str.toCharArray(); // 25 * 26 int cur = (s[0]-'a')*25; if(s[1]-'a' <= s[0]-'a'){ cur += s[1]-'a'+1; } else{ cur += s[1]-'a'; } o.println(cur); } catch (Exception e){e.printStackTrace();} } public static int upper_bound(List<Integer> a, int val){ int l = 0, r = a.size(); while(l < r){ int mid = l + (r - l) / 2; if(a.get(mid) <= val) l = mid + 1; else r = mid; } return l; } public static int lower_bound(List<Integer> a, int val){ int l = 0, r = a.size(); while(l < r){ int mid = l + (r - l) / 2; if(a.get(mid) < val) l = mid + 1; else r = mid; } return l; } public static long gcd(long a, long b){ return b == 0 ? a : gcd(b, a%b); } public static void reverse(int[] array){ reverse(array, 0 , array.length-1); } public static void reverse(int[] array, int left, int right) { if (array != null) { int i = left; for(int j = right; j > i; ++i) { int tmp = array[j]; array[j] = array[i]; array[i] = tmp; --j; } } } public static long qpow(long a, long n){ long ret = 1l; while(n > 0){ if((n & 1) == 1) ret = ret * a % mod; n >>= 1; a = a * a % mod; } return ret; } public static class unionFind { int[] parent; int[] size; int n; public unionFind(int n){ this.n = n; parent = new int[n]; size = new int[n]; for(int i=1;i<n;i++){ parent[i] = i; size[i] = 1; } } public int find(int p){ while(p != parent[p]){ parent[p] = parent[parent[p]]; p = parent[p]; } return p; } public void union(int p, int q){ int root_p = find(p); int root_q = find(q); if(root_p == root_q) return; if(size[root_p] >= size[root_q]){ parent[root_q] = root_p; size[root_p] += size[root_q]; size[root_q] = 0; } else{ parent[root_p] = root_q; size[root_q] += size[root_p]; size[root_p] = 0; } n--; } public int getCount(){ return n; } public int[] getSize(){ return size; } } public static class BIT { int[] tree; int n; public BIT(int n){ this.n = n; tree = new int[n+1]; } public void add(int x, int val){ while(x <= n){ tree[x] += val; x += lowBit(x); } } public int query(int x){ int ret = 0; while(x > 0){ ret += tree[x]; x -= lowBit(x); } return ret; } public int lowBit(int x) { return x&-x; } } public static class fReader { private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private static StringTokenizer tokenizer = new StringTokenizer(""); private static String next() throws IOException{ while(!tokenizer.hasMoreTokens()){tokenizer = new StringTokenizer(reader.readLine());} return tokenizer.nextToken(); } public static int nextInt() throws IOException {return Integer.parseInt(next());} public static Long nextLong() throws IOException {return Long.parseLong(next());} public static double nextDouble() throws IOException {return Double.parseDouble(next());} public static char nextChar() throws IOException {return next().toCharArray()[0];} public static String nextString() throws IOException {return next();} public static String nextLine() throws IOException {return reader.readLine();} } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
ec0a7d508141e85138d5c2a2bc9d02e4
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class B1674 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int t=0; t<T; t++) { String S = in.next(); char ch0 = S.charAt(0); char ch1 = S.charAt(1); int answer = (ch0-'a')*25 + (ch1-'a') + (ch1 > ch0 ? 0 : 1); System.out.println(answer); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
148787b8db51a26bc992dde5951d26b8
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Berland { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); while(t-->0){ String s = sc.nextLine(); int n1 = getNum(s.charAt(0)); int n2 = getNum(s.charAt(1)); int ans =0; ans = (n1*25)+n2; if(s.charAt(1)<s.charAt(0)) ans = (n1*25)+n2+1; System.out.println(ans); } } public static int getNum(char ch){ int counter =0; for(char c = 'a';c<='z';c++){ counter++; if(ch== c){ return counter-1; } } return -1; } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
1403aa168f0bbe2c2ca8c152775bf018
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class MyClass{ public static void main(String[] args){ Scanner sc= new Scanner(System.in); int n = sc.nextInt(); while(n > 0){ String s = sc.next(); int a = s.charAt(0); int b = s.charAt(1); int numFirst = 25 * (a - 'a'); int numLast; if(b > a){ numLast = b - 'a'; }else{ numLast = b - 'a' + 1; } int num = numFirst + numLast; System.out.println(num); n--; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
f02f9bc290d92664741ea254e396ae1b
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.getProperty; import static java.util.Arrays.binarySearch; import static java.util.Arrays.sort; public class B implements Runnable { boolean judge = false; FastReader scn; PrintWriter out; String INPUT = "7\n" + "ab\n" + "ac\n" + "az\n" + "ba\n" + "bc\n" + "zx\n" + "zy\n"; void solve() { int t = scn.nextInt(); while (t-- > 0) { String s = scn.nextLine(); char a = s.charAt(0), b = s.charAt(1); System.out.println((a - 'a') * 26 + (b - 'a' + 1) - (a - 'a' + (b > a ? 1 : 0))); } } @SuppressWarnings("all") public void run() { long time = currentTimeMillis(); boolean oj = getProperty("ONLINE_JUDGE") != null || judge; out = new PrintWriter(System.out); scn = new FastReader(oj); solve(); out.flush(); if (!oj) { System.out.println(Arrays.deepToString(new Object[]{currentTimeMillis() - time + " ms"})); } } public static void main(String[] args) { new Thread(null, new B(), "Main", 1 << 26).start(); } @SuppressWarnings("all") class FastReader { InputStream is; public FastReader(boolean onlineJudge) { is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes()); } byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; 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++]; } boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } double nextDouble() { return Double.parseDouble(next()); } char nextChar() { return (char) skip(); } String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } String nextLine() { int b = skip(); StringBuilder sb = new StringBuilder(); while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } 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); } int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } char[][] nextMatrix(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = next(m); return map; } int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } int[][] next2DInt(int n, int m) { int[][] arr = new int[n][]; for (int i = 0; i < n; i++) { arr[i] = nextIntArray(m); } return arr; } long[][] next2DLong(int n, int m) { long[][] arr = new long[n][]; for (int i = 0; i < n; i++) { arr[i] = nextLongArray(m); } return arr; } int[] shuffle(int[] arr) { Random r = new Random(); for (int i = 1, j; i < arr.length; i++) { j = r.nextInt(i); int c = arr[i]; arr[i] = arr[j]; arr[j] = c; } return arr; } long[] shuffle(long[] arr) { Random r = new Random(); for (int i = 1, j; i < arr.length; i++) { j = r.nextInt(i); long c = arr[i]; arr[i] = arr[j]; arr[j] = c; } return arr; } int[] uniq(int[] arr) { arr = scn.shuffle(arr); sort(arr); int[] rv = new int[arr.length]; int pos = 0; rv[pos++] = arr[0]; for (int i = 1; i < arr.length; i++) { if (arr[i] != arr[i - 1]) { rv[pos++] = arr[i]; } } return Arrays.copyOf(rv, pos); } long[] uniq(long[] arr) { arr = scn.shuffle(arr); sort(arr); long[] rv = new long[arr.length]; int pos = 0; rv[pos++] = arr[0]; for (int i = 1; i < arr.length; i++) { if (arr[i] != arr[i - 1]) { rv[pos++] = arr[i]; } } return Arrays.copyOf(rv, pos); } int[] reverse(int[] arr) { int l = 0, r = arr.length - 1; while (l < r) { arr[l] = arr[l] ^ arr[r]; arr[r] = arr[l] ^ arr[r]; arr[l] = arr[l] ^ arr[r]; l++; r--; } return arr; } long[] reverse(long[] arr) { int l = 0, r = arr.length - 1; while (l < r) { arr[l] = arr[l] ^ arr[r]; arr[r] = arr[l] ^ arr[r]; arr[l] = arr[l] ^ arr[r]; l++; r--; } return arr; } int[] compress(int[] arr) { int n = arr.length; int[] rv = Arrays.copyOf(arr, n); rv = uniq(rv); for (int i = 0; i < n; i++) { arr[i] = binarySearch(rv, arr[i]); } return arr; } long[] compress(long[] arr) { int n = arr.length; long[] rv = Arrays.copyOf(arr, n); rv = uniq(rv); for (int i = 0; i < n; i++) { arr[i] = binarySearch(rv, arr[i]); } return arr; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
7c0feba7b354d68ea6ba9fea9334b004
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class HelloWorld { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); sc.nextLine(); while(t-->0) { String s=sc.nextLine(); if(s.charAt(0)>s.charAt(1)) System.out.println(25*(int)(s.charAt(0)-'a')+(int)s.charAt(1)-'a'+1); else System.out.println(25*(int)(s.charAt(0)-'a')+(int)s.charAt(1)-'a'); } sc.close(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
2be99b94aeee575560d3cb29262868cf
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class Solution{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int rows=Integer.parseInt(sc.nextLine()); while(rows>0){ String word=sc.nextLine(); int c=word.charAt(0)-'a',start=26*c,pos=word.charAt(1)-'a',offset=pos>c?c:c-1; System.out.println(start+pos-offset); rows--; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
e5a153207962099611ceda53e2e28df9
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.StringTokenizer; public class CodeForces { static int mod = (int)1e9+7; public static void main(String[] args) throws InterruptedException { // PrintWriter out = new PrintWriter("output.txt"); // File input = new File("input.txt"); // FastScanner fs = new FastScanner(input); FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); HashMap<String,Integer> map =new HashMap<>(); int k=0; for(char a='a';a<='z';a++){ for(char b='a';b<='z';b++)if(a!=b){ k++; map.put(""+a+b,k); } } int testNumber =fs.nextInt(); for (int T =0;T<testNumber;T++){ String s =fs.next(); out.print(map.get(s)+"\n"); } out.flush(); } static long modInverse( long n, long p) { return FastPower(n, p - 2, p); } static int[] factorials(int max,int mod){ int [] ans = new int[max+1]; ans[0]=1; for (int i=1;i<=max;i++){ ans[i]=ans[i-1]*i; ans[i]%=mod; } return ans; } static String toBinary(int num,int bits){ String res =Integer.toBinaryString(num); while(res.length()<bits)res="0"+res; return res; } static String toBinary(long num,int bits){ String res =Long.toBinaryString(bits); while(res.length()<bits)res="0"+res; return res; } static long LCM(long a,long b){ return a*b/gcd(a,b); } static long FastPower(long x,long p,long mod){ if(p==0)return 1; long ans =FastPower(x, p/2,mod); ans%=mod; ans*=ans; ans%=mod; if(p%2==1)ans*=x; ans%=mod; return ans; } static double FastPower(double x,int p){ if(p==0)return 1.0; double ans =FastPower(x, p/2); ans*=ans; if(p%2==1)ans*=x; return ans; } static int FastPower(int x,int p){ if(p==0)return 1; int ans =FastPower(x, p/2); ans*=ans; if(p%2==1)ans*=x; return ans; } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""); } public FastScanner(File f){ try { br=new BufferedReader(new FileReader(f)); st=new StringTokenizer(""); } catch(FileNotFoundException e){ br=new BufferedReader(new InputStreamReader(System.in)); 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()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readLongArray(int n) { long[] a =new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } public static long factorial(int n){ if(n==0)return 1; return (long)n*factorial(n-1); } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } static void sort (int[]a){ ArrayList<Integer> b = new ArrayList<>(); for(int i:a)b.add(i); Collections.sort(b); for(int i=0;i<b.size();i++){ a[i]=b.get(i); } } static void sortReversed (int[]a){ ArrayList<Integer> b = new ArrayList<>(); for(int i:a)b.add(i); Collections.sort(b,new Comparator<Integer>(){ @Override public int compare(Integer o1, Integer o2) { return o2-o1; } }); for(int i=0;i<b.size();i++){ a[i]=b.get(i); } } static void sort (long[]a){ ArrayList<Long> b = new ArrayList<>(); for(long i:a)b.add(i); Collections.sort(b); for(int i=0;i<b.size();i++){ a[i]=b.get(i); } } static ArrayList<Integer> sieveOfEratosthenes(int n) { boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } ArrayList<Integer> ans = new ArrayList<>(); for (int i = 2; i <= n; i++) { if (prime[i] == true) ans.add(i); } return ans; } static int binarySearchSmallerOrEqual(int arr[], int key) { int n = arr.length; int left = 0, right = n; int mid = 0; while (left < right) { mid = (right + left) >> 1; if (arr[mid] == key) { while (mid + 1 < n && arr[mid + 1] == key) mid++; break; } else if (arr[mid] > key) right = mid; else left = mid + 1; } while (mid > -1 && arr[mid] > key) mid--; return mid; } static int binarySearchSmallerOrEqual(long arr[], long key) { int n = arr.length; int left = 0, right = n; int mid = 0; while (left < right) { mid = (right + left) >> 1; if (arr[mid] == key) { while (mid + 1 < n && arr[mid + 1] == key) mid++; break; } else if (arr[mid] > key) right = mid; else left = mid + 1; } while (mid > -1 && arr[mid] > key) mid--; return mid; } public static int binarySearchStrictlySmaller(int[] arr, int target) { int start = 0, end = arr.length-1; if(end == 0) return -1; if (target > arr[end]) return end; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr[mid] >= target) { end = mid - 1; } else { ans = mid; start = mid + 1; } } return ans; } public static int binarySearchStrictlySmaller(long[] arr, long target) { int start = 0, end = arr.length-1; if(end == 0) return -1; if (target > arr[end]) return end; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr[mid] >= target) { end = mid - 1; } else { ans = mid; start = mid + 1; } } return ans; } static int binarySearch(int arr[], int x) { int l = 0, r = arr.length - 1; while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1; } static int binarySearch(long arr[], long x) { int l = 0, r = arr.length - 1; while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1; } static void init(int[]arr,int val){ for(int i=0;i<arr.length;i++){ arr[i]=val; } } static void init(int[][]arr,int val){ for(int i=0;i<arr.length;i++){ for(int j=0;j<arr[i].length;j++){ arr[i][j]=val; } } } static void init(long[]arr,long val){ for(int i=0;i<arr.length;i++){ arr[i]=val; } } static<T> void init(ArrayList<ArrayList<T>>arr,int n){ for(int i=0;i<n;i++){ arr.add(new ArrayList()); } } static int binarySearchStrictlySmaller(ArrayList<Pair> arr, int target) { int start = 0, end = arr.size()-1; if(end == 0) return -1; if (target > arr.get(end).y) return end; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr.get(mid).y >= target) { end = mid - 1; } else { ans = mid; start = mid + 1; } } return ans; } static int binarySearchStrictlyGreater(int[] arr, int target) { int start = 0, end = arr.length - 1; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr[mid] <= target) { start = mid + 1; } else { ans = mid; end = mid - 1; } } return ans; } public static long pow(long n, long pow) { if (pow == 0) { return 1; } long retval = n; for (long i = 2; i <= pow; i++) { retval *= n; } return retval; } static String reverse(String s){ StringBuffer b = new StringBuffer(s); b.reverse(); return b.toString(); } static String charToString (char[] arr){ String t=""; for(char c :arr){ t+=c; } return t; } int[] copy (int [] arr , int start){ int[] res = new int[arr.length-start]; for (int i=start;i<arr.length;i++)res[i-start]=arr[i]; return res; } static int[] swap(int [] A,int l,int r){ int[] B=new int[A.length]; for (int i=0;i<l;i++){ B[i]=A[i]; } int k=0; for (int i=r;i>=l;i--){ B[l+k]=A[i]; k++; } for (int i=r+1;i<A.length;i++){ B[i]=A[i]; } return B; } static int mex (int[] d){ int [] a = Arrays.copyOf(d, d.length); sort(a); if(a[0]!=0)return 0; int ans=1; for(int i=1;i<a.length;i++){ if(a[i]==a[i-1])continue; if(a[i]==a[i-1]+1)ans++; else break; } return ans; } static int[] mexes(int[] arr){ int[] freq = new int [100000+7]; for (int i:arr)freq[i]++; int maxMex =0; for (int i=0;i<=100000+7;i++){ if(freq[i]!=0)maxMex++; else break; } int []ans = new int[arr.length]; ans[arr.length-1] = maxMex; for (int i=arr.length-2;i>=0;i--){ freq[arr[i+1]]--; if(freq[arr[i+1]]<=0){ if(arr[i+1]<maxMex) maxMex=arr[i+1]; ans[i]=maxMex; } else { ans[i]=ans[i+1]; } } return ans; } static int [] freq (int[]arr,int max){ int []b = new int[max]; for (int i:arr)b[i]++; return b; } static int[] prefixSum(int[] arr){ int [] a = new int[arr.length]; a[0]=arr[0]; for (int i=1;i<arr.length;i++)a[i]=a[i-1]+arr[i]; return a; } static class Pair { int x; int y; int extra; public Pair(int x,int y){ this.x=x; this.y=y; } public Pair(int x,int y,int extra){ this.x=x; this.y=y; this.extra=extra; } // @Override // public boolean equals(Object o) { // if(o instanceof Pair){ // if(o.hashCode()!=hashCode()){ // return false; // } else { // return x==((Pair)o).x&&y==((Pair)o).y; // } // } // // return false; // // } // // // // // // @Override // public int hashCode() { // return x+(int)y*2; // } // // } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 8
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
f53fc5fad83c9209f2beec0f39807c41
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.awt.image.ImageProducer; import java.util.*; public class Solution { static class P { char chara; int c; public P(char chara, int c) { this.chara = chara; this.c = c; } } static boolean prime[] = new boolean[1000001]; static Set<Long> cubes=new HashSet<>(); static { long N = 1000000000000L; // // // for(int i=1;i*i<=n;i++) // { // long x=i*i; // set.add(x); // } for (long i = 1; i * i * i <= N; i++) { cubes.add(i * i * i); } } public static int solve(String s1,String s2) { int c=0; for(int i=0;i<s1.length();i++) { int c1=s1.charAt(i)-'0'; int c2=s2.charAt(i)-'0'; c=c+Math.abs(c1-c2); } return c; } static Map<Long,Long> map=new HashMap<>(); static long r,res,j,n; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); sc.nextLine(); while(t-->0) { String str=sc.nextLine(); int diff=(str.charAt(0)-'a')-(str.charAt(1)-'a'); if(str.charAt(0)=='a') System.out.println(str.charAt(1)-'a'); else if((str.charAt(0)-'a')<(str.charAt(1)-'a')) { int ans = 25 * (str.charAt(0) - 'a') + (str.charAt(1) - 'a'); System.out.println(ans); } else { int ans = 25 * (str.charAt(0) - 'a') + (str.charAt(1) - 'a')+1; System.out.println(ans); } } } public static boolean isPal(String str) { for(int i=0;i<str.length()/2;i++) { if (str.charAt(i) != str.charAt(str.length() - 1 - i)) return false; } return true; } // public static int[] reverse(int arr[],int start,int end) // { // for(int i=start;i<=end;i++) // { // int temp=arr[i]; // arr[i]=arr[i+1]; // arr[i+1]=temp; // } // return arr; // } static boolean checkPerfectSquare(double number) { //calculating the square root of the given number double sqrt=Math.sqrt(number); //finds the floor value of the square root and comparing it with zero return ((sqrt - Math.floor(sqrt)) == 0); } static void sieveOfEratosthenes(int n) { for(int i=0;i<=n;i++) prime[i] = true; for(int p = 2; p*p <=n; p++) { if(prime[p] == true) { for(int i = p*p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers // for(int i = 2; i <= n; i++) // { // if(prime[i] == true) // System.out.print(i + " "); // } } public static boolean isPrime(int n) { for(int i=2;i*i<=n;i++) { if(n%i==0) return false; } return true; } public static int gcd(int a,int b) { if(b==0) return a; return gcd(b,a%b); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
eacd4e22f70e8dd61f1a85603570cff0
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class Dictionary { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); while (t-- > 0) { String s = br.readLine(); int x = 25 * (s.charAt(0) - 'a'); if (s.charAt(0) == 'a') { out.println(s.charAt(1) - 'a'); } else { if (s.charAt(1) < s.charAt(0)) { out.println(x + (s.charAt(1) - 96)); } else { out.println(x + (s.charAt(1) - 97)); } } } out.flush(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
cc0d3afd81f918420151e008e5045457
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class Dictionary { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); while (t-- > 0) { String s = br.readLine(); int x = 25 * (s.charAt(0) - 'a'); if (s.charAt(0) == 'a') { out.println(s.charAt(1) - 'a'); } else { if (s.charAt(1) == 'a') out.println(x + 1); else if (s.charAt(1) < s.charAt(0)) { out.println(x + (s.charAt(1) - 96)); } else { out.println(x + (s.charAt(1) - 97)); } } } out.flush(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
84713ee391832a8da7f96bf4fa23ee1d
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class Dictionary { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); while (t-- > 0) { String s = br.readLine(); int x = 25 * (s.charAt(0) - 'a'); if(s.charAt(0) == 'a') { out.println(s.charAt(1) - 'a'); } else { if (s.charAt(1) == 'a') out.println(x + 1); else if(s.charAt(1) < s.charAt(0)) { out.println(x + (s.charAt(1) - 96)); } else { out.println(x + (s.charAt(1) - 97)); } } } out.flush(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
d36559631d0eeda5431e4b3f36dec299
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class NewClass{ public static void main(String[]args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0) { String x=sc.next(); int alpha[]=new int[200]; int res=0; int arr[]=new int[200]; for(int i='a';i<='z';i++) { alpha[i]=i-97; } for(int i='a';i<='z';i++) arr[i]=i-96; res=alpha[x.charAt(0)]*25; if(x.charAt(0)>x.charAt(1)) System.out.println(res+arr[x.charAt(1)]); else System.out.println(res-1+arr[x.charAt(1)]); t--; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
491665dbfcbae9eb94a1b7bfb1852af3
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; public class Dictionary { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int numTests = Integer.parseInt(br.readLine()); for (int i = 0; i < numTests; i++) { String word = br.readLine(); char letter1 = word.charAt(0); char letter2 = word.charAt(1); int index = 0; index += (letter1 - 'a') * 25; index += letter2 - 'a'; if (letter2 < letter1) index++; System.out.println(index); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
ddb5e90e84014b6c1f9254bf021b0071
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc = new Scanner(System.in); int ti = sc.nextInt(); while(ti-->0){ String str = sc.next(); int ans= 25*(str.charAt(0)-'a'); ans+=(str.charAt(1)-'a'+1); if(str.charAt(1)>str.charAt(0)){ ans--; } System.out.println(ans); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
ebd6c15e1337fea4c980de177e530d70
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc = new Scanner(System.in); int t = sc.nextInt(); HashMap<String,Integer> hm = new HashMap<>(); int count = 1; for(int i = 97; i<=122;i++){ for(int j = 97; j<=122; j++){ if(i==j){ continue; }else{ String f = Character.toString((char)i); String s = Character.toString((char)j); hm.put(f+s,count); count++; } } } while(t-->0){ String s = sc.next(); System.out.println(hm.get(s)); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
8f2997977dd08c6561ff6667bd5cd721
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class dictionary{ public static void main(String[] args) throws Exception{ Scanner scn=new Scanner(System.in); int t=scn.nextInt(); while(t-->0){ String s=scn.next(); char ch1=s.charAt(0),ch2=s.charAt(1); // System.out.println(ch2-'a'); if(ch1-'a'<=ch2-'a') System.out.println((ch1-'a')*25+(ch2-'a')); else System.out.println((ch1-'a')*25+(ch2-'a'+1)); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
3b3625b7f2fe7d65e981bc702990aa7b
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.FilterOutputStream; import java.util.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); for(int t = in.nextInt();t>0;t--) { String s = in.next(); char c1 = s.charAt(0); char c2 = s.charAt(1); int ans =0; if(c2 > c1) ans = (c1-97) * 25 + (c2-97); else ans = (c1-97) * 25 + (c2-97) +1; System.out.println(ans); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
8b8d74d11d6b0153a2709f76633e6115
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.lang.*; import java.util.*; import java.io.*; public class Main { void solve() { ArrayList<String> list = new ArrayList<>(); for(int i = 0; i < 26; i++) { for(int j = 0; j < 26; j++) { if(i == j) continue; char c1 = (char) (i + 'a'); char c2 = (char) (j + 'a'); list.add(String.valueOf(c1) + "" +String.valueOf(c2)); } } int t = ri(); while(t-- > 0) { out.println(list.indexOf(rs()) + 1); } } public static void main(String[] args) { new Main().run(); } void run() { try { solve(); out.close(); } catch(Exception e) { e.printStackTrace(); System.exit(-1); } } String readLine() { try { return in.readLine(); } catch(Exception e) { throw new RuntimeException(e); } } String rs() { while(!tok.hasMoreTokens()) { tok = new StringTokenizer(readLine()); } return tok.nextToken(); } int ri() { return Integer.parseInt(rs()); } long rl() { return Long.parseLong(rs()); } BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); StringTokenizer tok = new StringTokenizer(""); }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
3f4d413ef594c4f3971f5761bd30cb42
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Main { public static void main(String[] args) { // write your code here Scanner scanner = new Scanner(System.in); ArrayList<Integer> arrayList = new ArrayList<>(); ArrayList<Integer> arrayList2 = new ArrayList<>(); int length = scanner.nextInt(); String[] strings = new String[length]; for (int i = 0; i < length; i++) { strings[i] = scanner.next(); } char[] chars = new char[26]; int i = 0; for (char c = 'a'; c <= 'z'; c++) { chars[i] = c; i++; } int count = 0; String result = ""; int i1 = 0; long start = System.currentTimeMillis(); for (int j = 0; j < chars.length; j++) { for (int k = 0; k < chars.length; k++) { result = chars[j] + "" + chars[k]; count++; if (chars[j] == chars[k]) { count = count - 1; } for (int l = 0; l < length; l++) { if (result.equals(strings[l])) { arrayList.add(l); arrayList2.add(count); } } } } for (int j = 0; j < length; j++) { for (int k = 0; k < length; k++) { if(j == arrayList.get(k)) { System.out.println(arrayList2.get(k)); } } } long end = System.currentTimeMillis(); // System.out.println(new Date()); // long[][] ar = new long[scanner.nextInt()][2]; // for (int i = 0; i < ar.length; i++) { // for (int j = 0; j < 2; j++) { // ar[i] [j] = scanner.nextInt(); // } // } // int count = 0; // for (int i = 0; i < ar.length; i++) { // for (int j = 0; j < 1; j++) { // if(ar[i][j+1] %ar[i][j] == 0) { // count = (int) (ar[i][j+1] / ar[i][j]); // System.out.println("1 " + count); // // }else if(ar[i][j+1] %ar[i][j] != 0) { // System.out.println("0 0"); // // } // // } // } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
9c6c4c120a27f5b1d671a9e4129b59eb
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { int t=0,x=0; String letter; int firstpos=0; int secondpos=0; int term=0; Scanner in=new Scanner(System.in); t=in.nextInt(); while(x<t){ letter=in.next(); if(letter.charAt(0)=='a'){ term=(int)(letter.charAt(1))-97; } else if(letter.charAt(0)>'a'){ firstpos=(((int)letter.charAt(0))-97)*25; if(letter.charAt(1)=='a'){ secondpos=1; } else if(letter.charAt(1)>letter.charAt(0)) { secondpos=(int)(letter.charAt(1))-97; } else if(letter.charAt(1)<letter.charAt(0)){ secondpos=(int)(letter.charAt(1))-96; } term=firstpos+secondpos; } System.out.println(term); x++; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
9f891b1ca66d38a66e504a03ade39c3d
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.LinkedHashMap; import java.util.Map; import java.util.Scanner; public class Main2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); Map<String, Integer> map = new LinkedHashMap<>(); int count = 1; String c; for (int i = 'a'; i <= 'z'; i++) { for (int j = 'a'; j <= 'z'; j++) { if (i == j) { continue; } c = String.valueOf((char) i) + String.valueOf((char) j); map.put(c, count++); } } while (T-- > 0) { String s = sc.next(); System.out.println(map.get(s)); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
7878a96cd7e8fbbc1754f23b29acd210
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { static long mod = (int)1e9+7; // static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main (String[] args) throws java.lang.Exception { FastReader sc =new FastReader(); int t=sc.nextInt(); // int t=1; while(t-->0) { char arr[] = sc.next().toCharArray(); int n = arr.length; int fVal = ((arr[0] - 'a') * 26) + (arr[1] - 'a' + 1) - (arr[0] - 'a'); if(arr[1] > arr[0]) { fVal--; } System.out.println(fVal); } } 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()); } float nextFloat() { return Float.parseFloat(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; } long[] readArrayLong(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } } public static int[] radixSort2(int[] a) { int n = a.length; int[] c0 = new int[0x101]; int[] c1 = new int[0x101]; int[] c2 = new int[0x101]; int[] c3 = new int[0x101]; for(int v : a) { c0[(v&0xff)+1]++; c1[(v>>>8&0xff)+1]++; c2[(v>>>16&0xff)+1]++; c3[(v>>>24^0x80)+1]++; } for(int i = 0;i < 0xff;i++) { c0[i+1] += c0[i]; c1[i+1] += c1[i]; c2[i+1] += c2[i]; c3[i+1] += c3[i]; } int[] t = new int[n]; for(int v : a)t[c0[v&0xff]++] = v; for(int v : t)a[c1[v>>>8&0xff]++] = v; for(int v : a)t[c2[v>>>16&0xff]++] = v; for(int v : t)a[c3[v>>>24^0x80]++] = v; return a; } static void my_sort(long[] arr) { ArrayList<Long> list = new ArrayList<>(); for(int i=0;i<arr.length;i++) { list.add(arr[i]); } Collections.sort(list); for(int i=0;i<arr.length;i++) { arr[i] = list.get(i); } } static void reverse_sorted(int[] arr) { ArrayList<Integer> list = new ArrayList<>(); for(int i=0;i<arr.length;i++) { list.add(arr[i]); } Collections.sort(list , Collections.reverseOrder()); for(int i=0;i<arr.length;i++) { arr[i] = list.get(i); } } static int LowerBound(int a[], int x) { // x is the target value or key int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int UpperBound(ArrayList<Integer> list, int x) {// x is the key or target value int l=-1,r=list.size(); while(l+1<r) { int m=(l+r)>>>1; if(list.get(m)<=x) l=m; else r=m; } return l+1; } public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm) { // Create a list from elements of HashMap List<Map.Entry<Integer, Integer> > list = new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) { return (o1.getValue()).compareTo(o2.getValue()); } }); // put data from sorted list to hashmap HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); for (Map.Entry<Integer, Integer> aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static class Queue_Pair implements Comparable<Queue_Pair> { int first , second; public Queue_Pair(int first, int second) { this.first=first; this.second=second; } public int compareTo(Queue_Pair o) { return Integer.compare(o.first, first); } } static void leftRotate(int arr[], int d, int n) { for (int i = 0; i < d; i++) leftRotatebyOne(arr, n); } static void leftRotatebyOne(int arr[], int n) { int i, temp; temp = arr[0]; for (i = 0; i < n - 1; i++) arr[i] = arr[i + 1]; arr[n-1] = temp; } static boolean isPalindrome(String str) { // Pointers pointing to the beginning // and the end of the string int i = 0, j = str.length() - 1; // While there are characters to compare while (i < j) { // If there is a mismatch if (str.charAt(i) != str.charAt(j)) return false; // Increment first pointer and // decrement the other i++; j--; } // Given string is a palindrome return true; } static boolean palindrome_array(char arr[], int n) { // Initialise flag to zero. int flag = 0; // Loop till array size n/2. for (int i = 0; i <= n / 2 && n != 0; i++) { // Check if first and last element are different // Then set flag to 1. if (arr[i] != arr[n - i - 1]) { flag = 1; break; } } // If flag is set then print Not Palindrome // else print Palindrome. if (flag == 1) return false; else return true; } static boolean allElementsEqual(int[] arr,int n) { int z=0; for(int i=0;i<n-1;i++) { if(arr[i]==arr[i+1]) { z++; } } if(z==n-1) { return true; } else { return false; } } static boolean allElementsDistinct(int[] arr,int n) { int z=0; for(int i=0;i<n-1;i++) { if(arr[i]!=arr[i+1]) { z++; } } if(z==n-1) { return true; } else { return false; } } public static void reverse(int[] array) { // Length of the array int n = array.length; // Swaping the first half elements with last half // elements for (int i = 0; i < n / 2; i++) { // Storing the first half elements temporarily int temp = array[i]; // Assigning the first half to the last half array[i] = array[n - i - 1]; // Assigning the last half to the first half array[n - i - 1] = temp; } } public static void reverse_Long(long[] array) { // Length of the array int n = array.length; // Swaping the first half elements with last half // elements for (int i = 0; i < n / 2; i++) { // Storing the first half elements temporarily long temp = array[i]; // Assigning the first half to the last half array[i] = array[n - i - 1]; // Assigning the last half to the first half array[n - i - 1] = temp; } } static boolean isSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] > a[i + 1]) { return false; } } return true; } static boolean isReverseSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] < a[i + 1]) { return false; } } return true; } static int[] rearrangeEvenAndOdd(int arr[], int n) { ArrayList<Integer> list = new ArrayList<>(); for(int i=0;i<n;i++) { if(arr[i]%2==0) { list.add(arr[i]); } } for(int i=0;i<n;i++) { if(arr[i]%2!=0) { list.add(arr[i]); } } int len = list.size(); int[] array = list.stream().mapToInt(i->i).toArray(); return array; } static long[] rearrangeEvenAndOddLong(long arr[], int n) { ArrayList<Long> list = new ArrayList<>(); for(int i=0;i<n;i++) { if(arr[i]%2==0) { list.add(arr[i]); } } for(int i=0;i<n;i++) { if(arr[i]%2!=0) { list.add(arr[i]); } } int len = list.size(); long[] array = list.stream().mapToLong(i->i).toArray(); return array; } static boolean isPrime(long n) { // Check if number is less than // equal to 1 if (n <= 1) return false; // Check if number is 2 else if (n == 2) return true; // Check if n is a multiple of 2 else if (n % 2 == 0) return false; // If not, then just check the odds for (long i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } static long getSum(long n) { long sum = 0; while (n != 0) { sum = sum + n % 10; n = n/10; } return sum; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long gcdLong(long a, long b) { if (b == 0) return a; return gcdLong(b, a % b); } static void swap(int i, int j) { int temp = i; i = j; j = temp; } static int countDigit(int n) { return (int)Math.floor(Math.log10(n) + 1); } } class Pair { int first; int second; Pair(int first , int second) { this.first = first; this.second = second; } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
4ba683af3370b9d4a6b98fff0304caa4
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Solution { static Scanner s = new Scanner(System.in); public static void solve() { String str = s.next(); int cnt = 1; for(char i='a';i<='z';++i) { for(char j='a';j<='z';++j) { if(i == j) continue; String res = i+""+j; if(res.equals(str)) { System.out.println(cnt); return; } ++cnt; } } } public static void main(String[] args) { int t = s.nextInt(); while(t-- > 0) solve(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
933fc53d510773ae2e06c84c5d971beb
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class B { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-- > 0) { String str = s.next(); Map<String,Integer> map = new HashMap<>(); int cnt = 1; for(char c='a';c<='z';++c) { for(char d='a';d<='z';++d) { if(c == d) continue; map.put(c+""+d,cnt++); } } System.out.println(map.get(str)); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
84543b872ecbe2569e95ee0fe9c03eb5
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; import java.math.*; public class Solution{ public static void main(String[] args) { TaskA solver = new TaskA(); initFac(10001); int t = in.nextInt(); for (int i = 1; i <= t ; i++) { solver.solve(i, in, out); } // solver.solve(1, in, out); out.flush(); out.close(); } static ArrayList<Integer>[] graph ; static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { String s= in.next(); int x=25*(s.charAt(0)-'a')+(s.charAt(1)-'a'+1); if(s.charAt(0)<s.charAt(1)) { x--; } println(x); } } static long[] fac; static long mod = (long)1e9+7; static void initFac(long n) { fac = new long[(int)n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) { fac[i] = (fac[i - 1] * i) % mod; } } static void dfs(int at, int pt,char[]arr,int [][]count) { if(arr[at]=='W') { count[at][0]++; } else { count[at][1]++; } for(int i: graph[at]) { if(i==pt) { continue; } dfs(i,at,arr,count); count[at][0]+=count[i][0]; count[at][1]+=count[i][1]; } } static int count(char []arr,char x) { int c=0; for(int i=0;i<arr.length;i++) { if(arr[i]==x) { c++; } } return c; } static int count(int []arr,int x) { int c=0; for(int i=0;i<arr.length;i++) { if(arr[i]==x) { c++; } } return c; } static boolean[]seive(int n){ boolean[]b=new boolean[n+1]; for (int i = 2; i <= n; i++) b[i] = true; for(int i=2;i*i<=n;i++) { if(b[i]) { for(int j=i*i;j<=n;j+=i) { b[j]=false; } } } return b; } static int[] query(int l,int r) { System.out.println("? "+l+" "+r); System.out.print ("\n");System.out.flush(); int[]arr=new int[r-l+1]; for(int i=0;i<r-l+1;i++) { arr[i]=in.nextInt(); } return arr; } static int[]presum(int[]arr){ int n= arr.length; int[]pre=new int[n]; for(int i=0;i<n;i++) { if(i>0) { pre[i]=pre[i-1]; } pre[i]+=arr[i]; } return arr; } static int max(int[]arr) { int max=Integer.MIN_VALUE; for(int i=0;i<arr.length;i++) { max=Math.max(max, arr[i]); } return max; } static int min(int[]arr) { int min=Integer.MAX_VALUE; for(int i=0;i<arr.length;i++) { min=Math.min(min, arr[i]); } return min; } static int ceil(int a,int b) { int ans=a/b;if(a%b!=0) { ans++; } return ans; } static long sum(int[]arr) { long s=0; for(int x:arr) { s+=x; } return s; } static long sum(long[]arr) { long s=0; for(long x:arr) { s+=x; } return s; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(int[] a) { ArrayList<Integer> q = new ArrayList<>(); for (int i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void sort(long[] a) { ArrayList<Long> q = new ArrayList<>(); for (long i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void println(int[][]arr) { for(int i=0;i<arr.length;i++) { for(int j=0;j<arr[0].length;j++) { print(arr[i][j]+" "); } print("\n"); } } static void println(long[][]arr) { for(int i=0;i<arr.length;i++) { for(int j=0;j<arr[0].length;j++) { print(arr[i][j]+" "); } print("\n"); } } static void println(int[]arr){ for(int i=0;i<arr.length;i++) { print(arr[i]+" "); } print("\n"); } static void println(long[]arr){ for(int i=0;i<arr.length;i++) { print(arr[i]+" "); } print("\n"); } static int[]input(int n){ int[]arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=in.nextInt(); } return arr; } static int[]input(){ int n= in.nextInt(); int[]arr=new int[(int)n]; for(int i=0;i<n;i++) { arr[i]=in.nextInt(); } return arr; } //////////////////////////////////////////////////////// static class Pair { int first; int second; Pair(int x, int y) { this.first = x; this.second = y; } } static void sortS(Pair arr[]) { Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { return (p1.second - p2.second); } }); } static void sortF(Pair arr[]) { Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { return (p1.first - p2.first); } }); } ///////////////////////////////////////////////////////////// static InputStream inputStream = System.in; static OutputStream outputStream = System.out; static InputReader in = new InputReader(inputStream); static PrintWriter out = new PrintWriter(outputStream); static void println(long c) { out.println(c); } static void print(long c) { out.print(c); } static void print(int c) { out.print(c); } static void println(int x) { out.println(x); } static void print(String s) { out.print(s); } static void println(String s) { out.println(s); } static void println(boolean b) { out.println(b); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
7954fd94a501dab11d0881ef73eddaf8
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 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){ String s=sc.next(); int a=s.charAt(0); a =a-96; int b=s.charAt(1); b=b-96; if(b<a) System.out.println(25*(a-1)+b); else System.out.println(25*(a-1)+b-1); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
42f58977ea8795ad2c7cf03c3ebed66c
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; import java.util.ArrayList; import java.util.Arrays; public class Dictionary { public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<String> alpha = new ArrayList<String>(Arrays.asList("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 = in.nextInt(); in.nextLine(); for(int i = 0; i < n; i++) { String berland = in.nextLine(); int index = (alpha.indexOf(berland.substring(0, 1))*25)+alpha.indexOf(berland.substring(1, 2)); if(berland.substring(0, 1).compareTo(berland.substring(1, 2))>0)index++; System.out.println(index); } in.close(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
3b5d28b6533fd0fe85e04744b4551bc6
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; import java.util.ArrayList; import java.util.Arrays; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<String> alpha = new ArrayList<String>(Arrays.asList("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 = in.nextInt(); in.nextLine(); for(int i = 0; i < n; i++) { String berland = in.nextLine(); int index = (alpha.indexOf(berland.substring(0, 1))*25)+alpha.indexOf(berland.substring(1, 2)); if(berland.substring(0, 1).compareTo(berland.substring(1, 2))>0)index++; System.out.println(index); } in.close(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
44d789db7723e8821f56edbd6f7ace0f
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int testCases = scan.nextInt(); for (int vedant = 0; vedant < testCases; vedant++) { String str = scan.next(); int value = (str.charAt(0) - 'a') * 26; value += str.charAt(1) - 'a'; value -= str.charAt(0) - 'a'; if (str.charAt(0) > str.charAt(1)) { value++; } System.out.println(value); } } // private static int[] getArray(int size) { // int[] ans = new int[size]; // for (int i = 0; i < size; i++) { // ans[i] = scan.nextInt(); // } // // return ans; // } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
2e65b5f350b6e1c991df1fbac811f205
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Solution { public static void main(String[] args) throws IOException { PrintWriter pw = new PrintWriter(System.out); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int test = Integer.parseInt(br.readLine()); for (int i = 0; i < test; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); String word = st.nextToken(); int a = ((int) word.charAt(0)) - 97; int b = ((int) word.charAt(1)) - 97; int x = a % 26; if (a < b) pw.println((a * 25) + b); if (a > b) pw.println((a * 25) + b +1); } pw.flush(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
9393dcec769036755de0ba775c3ecfd4
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; public class Main { static ArrayList<String> l = new ArrayList<>(); public static void main(String[] args) { FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(System.out); int test = in.nextInt(); for (int tt = 1; tt <= test; tt++) { function(); String s = in.next(); pw.println(l.indexOf(s)+1); } pw.close(); } static void function() { int list = 0; for(int i = 0;i<26;i++) { for(int j = 0;j<26;j++) { char aa = (char)('a'+i); char bb = (char)('a'+j); if(aa==bb) continue; else { String e =""+aa+bb; l.add(e); } } } } private static boolean isSorted(int[] arr) { for (int i = 1; i < arr.length; i++) if (arr[i] < arr[i - 1]) return false; return true; } 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(); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
278c7c1246db81fe836c0423e4b09f6f
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; public class Main { static Map<String,Integer> m; public static void main(String[] args) { FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(System.out); int test = in.nextInt(); for (int tt = 1; tt <= test; tt++) { function(); String s = in.next(); pw.println(m.get(s)); } pw.close(); } static void function() { int list = 0; m = new HashMap<>(); for(int i = 0;i<26;i++) { for(int j = 0;j<26;j++) { char aa = (char)('a'+i); char bb = (char)('a'+j); if(aa==bb) continue; else { String e =""+aa+bb; list++; m.put(e, list); } } } } private static boolean isSorted(int[] arr) { for (int i = 1; i < arr.length; i++) if (arr[i] < arr[i - 1]) return false; return true; } 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(); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
0d496ea75e5a1edc3a6302ca3d45e709
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.StringTokenizer; public class cf1674B { public static void main(String[] args) { FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-->0) { String s = sc.nextLine(); int firstChar = s.charAt(0) - 97; // a will now be = 0 int secondChar = s.charAt(1) - 97; //use second char as determinant System.out.println(firstChar*25 + (secondChar < firstChar ? secondChar + 1 : secondChar)); } } 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
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
a715aec12753e01f64e10b02da06dbf5
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.StringTokenizer; public class cf1674B { public static void main(String[] args) { FastReader sc = new FastReader(); String key; int counter = 1; HashMap<String, Integer> mapper = new HashMap<>(); for(char i = 'a'; i<='z'; i++) { for(char j = 'a'; j<='z'; j++) { if(i!=j) { key = String.valueOf(i) + String.valueOf(j); mapper.put(key, counter); counter++; } } } int t = sc.nextInt(); while(t-->0) { System.out.println(mapper.get(sc.nextLine())); } } 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
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
a778c07f84b540aae116dfddfd4f9a36
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
//Utilities import java.io.*; import java.util.*; public class a { static int t; static ArrayList<String> arr = new ArrayList<String>(); public static void main(String[] args) throws IOException { for (int i = 'a'; i <= 'z'; i++) { for (int j = 'a'; j <= 'z'; j++) { if (i == j) { continue; } arr.add(""+(char)(i)+""+(char)(j)); } } Collections.sort(arr); //out.println(arr); t = in.iscan(); while (t-- > 0) { out.println(arr.indexOf(in.sscan()) + 1); } out.close(); } static INPUT in = new INPUT(System.in); static PrintWriter out = new PrintWriter(System.out); private static class INPUT { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar, numChars; public INPUT (InputStream stream) { this.stream = stream; } public INPUT (String file) throws IOException { this.stream = new FileInputStream (file); } public int cscan () throws IOException { if (curChar >= numChars) { curChar = 0; numChars = stream.read (buf); } if (numChars == -1) return numChars; return buf[curChar++]; } public int iscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } int res = 0; do { res = (res << 1) + (res << 3); res += c - '0'; c = cscan (); } while (!space (c)); return res * sgn; } public String sscan () throws IOException { int c = cscan (); while (space (c)) c = cscan (); StringBuilder res = new StringBuilder (); do { res.appendCodePoint (c); c = cscan (); } while (!space (c)); return res.toString (); } public double dscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } double res = 0; while (!space (c) && c != '.') { if (c == 'e' || c == 'E') return res * UTILITIES.fast_pow (10, iscan ()); res *= 10; res += c - '0'; c = cscan (); } if (c == '.') { c = cscan (); double m = 1; while (!space (c)) { if (c == 'e' || c == 'E') return res * UTILITIES.fast_pow (10, iscan ()); m /= 10; res += (c - '0') * m; c = cscan (); } } return res * sgn; } public long lscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } long res = 0; do { res = (res << 1) + (res << 3); res += c - '0'; c = cscan (); } while (!space (c)); return res * sgn; } public boolean space (int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } public static class UTILITIES { static final double EPS = 10e-6; public static void sort(int[] a, boolean increasing) { ArrayList<Integer> arr = new ArrayList<Integer>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static void sort(long[] a, boolean increasing) { ArrayList<Long> arr = new ArrayList<Long>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static void sort(double[] a, boolean increasing) { ArrayList<Double> arr = new ArrayList<Double>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static int lower_bound (int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) high = mid; else low = mid + 1; } return low; } public static int upper_bound (int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > x) high = mid; else low = mid + 1; } return low; } public static void updateMap(HashMap<Integer, Integer> map, int key, int v) { if (!map.containsKey(key)) { map.put(key, v); } else { map.put(key, map.get(key) + v); } if (map.get(key) == 0) { map.remove(key); } } public static long gcd (long a, long b) { return b == 0 ? a : gcd (b, a % b); } public static long lcm (long a, long b) { return a * b / gcd (a, b); } public static long fast_pow_mod (long b, long x, int mod) { if (x == 0) return 1; if (x == 1) return b; if (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod; return b * fast_pow_mod (b * b % mod, x / 2, mod) % mod; } public static long fast_pow (long b, long x) { if (x == 0) return 1; if (x == 1) return b; if (x % 2 == 0) return fast_pow (b * b, x / 2); return b * fast_pow (b * b, x / 2); } public static long choose (long n, long k) { k = Math.min (k, n - k); long val = 1; for (int i = 0; i < k; ++i) val = val * (n - i) / (i + 1); return val; } public static long permute (int n, int k) { if (n < k) return 0; long val = 1; for (int i = 0; i < k; ++i) val = (val * (n - i)); return val; } // start of permutation and lower/upper bound template public static void nextPermutation(int[] nums) { //find first decreasing digit int mark = -1; for (int i = nums.length - 1; i > 0; i--) { if (nums[i] > nums[i - 1]) { mark = i - 1; break; } } if (mark == -1) { reverse(nums, 0, nums.length - 1); return; } int idx = nums.length-1; for (int i = nums.length-1; i >= mark+1; i--) { if (nums[i] > nums[mark]) { idx = i; break; } } swap(nums, mark, idx); reverse(nums, mark + 1, nums.length - 1); } public static void swap(int[] nums, int i, int j) { int t = nums[i]; nums[i] = nums[j]; nums[j] = t; } public static void reverse(int[] nums, int i, int j) { while (i < j) { swap(nums, i, j); i++; j--; } } static int lower_bound (int[] arr, int hi, int cmp) { int low = 0, high = hi, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= cmp) high = mid; else low = mid + 1; } return low; } static int upper_bound (int[] arr, int hi, int cmp) { int low = 0, high = hi, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > cmp) high = mid; else low = mid + 1; } return low; } // end of permutation and lower/upper bound template } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
c2b42754c993ff5c022b70ef0b7e56b8
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Disctionary { private static int A; public static void main(String[] args) { Scanner oj= new Scanner(System.in); A= oj.nextInt(); for(int i=0; i<A; i++) { String str= oj.next(); Solve(str); } } public static void Solve(String s) { int q=0; q+=((int)s.charAt(0)-'a')*25; if(s.charAt(1)<s.charAt(0)) { q+=((int)s.charAt(1)-'a'+1); } else { q+=((int)s.charAt(1)-'a'); } System.out.println(q); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
10a9b3cb2d16c577938b163df7e17f7a
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; public class Main{ static StringTokenizer st; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main (String args[]){ ArrayList<Integer> solutions = new ArrayList<Integer>(); String[] codeNum = new String[650]; char first = 'a'; char second = 'a'; String temp; int i = 0; while(first <= 'z'){ if (first != second){ temp = Character.toString(first) + Character.toString(second); codeNum[i] = temp; i++; second++; if (second > 'z'){ first++; second = 'a'; } }else{ second++; if (second > 'z'){ first++; second = 'a'; } if (first > 'z') break; temp = Character.toString(first) + Character.toString(second); codeNum[i] = temp; i++; second++; if (second > 'z'){ first++; second = 'a'; } } } int numOfInputs = Integer.parseInt(next()); for (int j = 0; j < numOfInputs; j++){ String code = next(); solutions.add(Arrays.binarySearch(codeNum, code) + 1); } for (int x : solutions){ System.out.println(x); } } static String next(){ while (st == null || !st.hasMoreTokens()){ try{ st = new StringTokenizer(br.readLine().trim()); }catch(Exception e){} } return st.nextToken(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
c8532d20ba84157133c3b68c9a52b184
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Main { public static void main(String[] args) { //System.out.println("Hello World"); Scanner scn=new Scanner(System.in); int t=scn.nextInt(); scn.nextLine(); while(t-->0){ String s=scn.nextLine(); char ch1=s.charAt(0); char ch2=s.charAt(1); int a1=ch1-'a'; int a2=ch2-'a'; if(ch2<ch1){ System.out.println(a1*25+a2+1); } else{ System.out.println(a1*25 + a2); } } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
0cbd170c36dca902ff748c3f7248c901
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 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){ String s = sc.next(); HashMap <Character,Integer> hm = new HashMap<>(); char c; int i=1; for(c ='a';c<='z';c++){ hm.put(c,i); i++; } char ch1 = s.charAt(0); char ch2 = s.charAt(1); int a = hm.get(ch1); int b = hm.get(ch2); int ans = (a-1)*26 + b; if(b>a){ ans = ans - a-1 - 1 ; } else{ ans = ans - a-1; } System.out.println(ans+2); t--; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
768f8738b595d38fa24868a67511fccc
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class B_dictionary { static int berland_index(String str) { int[] arr = new int[26]; arr[0] = 0; arr[1] = 25; for (int i = 2; i < arr.length; i++) { arr[i] = arr[i - 1] + 25; } int part_1 = arr[str.charAt(0) - 'a'] + 1; int part_2 = 0; if (str.charAt(0) - 'a' < str.charAt(1) - 'a') { part_2 = str.charAt(1) - 'a' - 1; } else part_2 = str.charAt(1) - 'a'; return part_1 + part_2; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int testcase = sc.nextInt(); while (testcase-- > 0) { String str = sc.next(); System.out.println(berland_index(str)); } sc.close(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
6fd88b28749f114745ab4271e96a75b2
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.text.SimpleDateFormat; import java.time.LocalTime; import java.util.*; 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(); Dictionary(); } public static void Dictionary() { FastReader sc = new FastReader(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { String word = sc.next(); char l1 = word.charAt(0); char l2 = word.charAt(1); int ans = (l1 - 'a') * 25; if (l2 > l1) ans += (l2 - 'a'); else ans += (l2 - 'a' + 1); out.println(ans); } 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
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
0da3bd1f412e8ad676a3efa2ed7679b8
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.ArrayList; import java.util.Scanner; public class M11_13 { public static void main(String ... args){ Scanner x=new Scanner(System.in); int z=x.nextInt(); while(z>0){ String a=x.next(); System.out.println(m(a)); z--; } }public static int m(String a){ if(a.charAt(0)>a.charAt(1)){ return (int)(a.charAt(0)-'a')*25+(int)(a.charAt(1)-'a'+1); }else{ return (int)(a.charAt(0)-'a')*25+(int)(a.charAt(1)-'a'); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
47be1f1a6c8a00e3edebcc0f6aaedb83
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; public class Solution{ static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); static StringTokenizer st; static final long mod=1000000007; public static void Solve() throws IOException{ // st=new StringTokenizer(br.readLine()); // int n=Integer.parseInt(st.nextToken()); char[] ch=br.readLine().toCharArray(); int idx=(ch[0]-'a')*25+ch[1]-'a'; if(ch[1]<ch[0]) idx++; bw.write(idx+"\n"); } /** Main Method**/ public static void main(String[] YDSV) throws IOException{ //int t=1; int t=Integer.parseInt(br.readLine()); while(t-->0) Solve(); bw.flush(); } /** Helpers**/ private static int Gcd(int a,int b){ if(b==0) return a; return Gcd(b,a%b); } private static long Gcd(long a,long b){ if(b==0) return a; return Gcd(b,a%b); } private static int[] getArrIn(int n) throws IOException{ st=new StringTokenizer(br.readLine()); int[] ar=new int[n]; for(int i=0;i<n;i++) ar[i]=Integer.parseInt(st.nextToken()); return ar; } private static long[] getArrLo(int n) throws IOException{ st=new StringTokenizer(br.readLine()); long[] ar=new long[n]; for(int i=0;i<n;i++) ar[i]=Long.parseLong(st.nextToken()); return ar; } private static List<Integer> getListIn(int n) throws IOException{ st=new StringTokenizer(br.readLine()); List<Integer> al=new ArrayList<>(); for(int i=0;i<n;i++) al.add(Integer.parseInt(st.nextToken())); return al; } private static List<Long> getListLo(int n) throws IOException{ st=new StringTokenizer(br.readLine()); List<Long> al=new ArrayList<>(); for(int i=0;i<n;i++) al.add(Long.parseLong(st.nextToken())); return al; } private static long pow_mod(long a,long b) { long result=1; while(b!=0){ if((b&1)!=0) result=(result*a)%mod; a=(a*a)%mod; b>>=1; } return result; } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
753c638a9b3629b25403fb68ff1724df
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class FastScanner { static BufferedReader br; static StringTokenizer st; static PrintWriter pw; static String nextToken() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } static int nextInt() { return Integer.parseInt(nextToken()); } static long nextLong() { return Long.parseLong(nextToken()); } static double nextDouble() { return Double.parseDouble(nextToken()); } static String nextLine() { try { return br.readLine(); } catch (IOException e) { throw new IllegalArgumentException(); } } static char nextChar() { try { return (char) br.read(); } catch (IOException e) { throw new IllegalArgumentException(e); } } public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(System.out); int t = 1; t = nextInt(); while (t-- > 0) { solve(); } pw.close(); } private static void solve() { char[] c = nextLine().toCharArray(); int a = c[0]-'a'; int b = c[1]-'a'; int ans = 0; for (int i = 0; i < 26; i++) { for (int j = 0; j < 26; j++) { if (i==j) continue; ans++; if (a==i&&b==j) { pw.println(ans); return; } } } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
844e6fa96026d31d285ddcdd7d95a1c2
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class FastScanner { static BufferedReader br; static StringTokenizer st; static PrintWriter pw; static String nextToken() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } static int nextInt() { return Integer.parseInt(nextToken()); } static long nextLong() { return Long.parseLong(nextToken()); } static double nextDouble() { return Double.parseDouble(nextToken()); } static String nextLine() { try { return br.readLine(); } catch (IOException e) { throw new IllegalArgumentException(); } } static char nextChar() { try { return (char) br.read(); } catch (IOException e) { throw new IllegalArgumentException(e); } } public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(System.out); int t = 1; t = nextInt(); while (t-- > 0) { solve(); } pw.close(); } private static void solve() { char[] c = nextLine().toCharArray(); int ans = (c[0]-'a')*25 + (c[1]-'a'); if (c[0] - c[1] > 0) ans++; pw.println(ans); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
9a3fe91e974d338f03c6a0ecae81072f
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int w; while(t > 0) { String s = sc.next(); if ((int) s.charAt(1) < (int) s.charAt(0)) w = ((int) s.charAt(0) - 97) * 25 + (int) s.charAt(1) - 96; else w = ((int) s.charAt(0) - 97) * 25 + (int) s.charAt(1) - 97; System.out.println(w); t--; } System.out.println(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
3cc2199788e46a71120feca082557dcc
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; public class Solution{ 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 print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } static int[] string_to_array(String[] arr){ int[] ans=new int[arr.length]; for(int i=0;i<arr.length;i++){ ans[i]=Integer.parseInt(arr[i]); } return ans; } public static void main(String[] args) { try { FastReader in=new FastReader(); FastWriter out = new FastWriter(); int testCases=in.nextInt(); List<String>answer=new ArrayList<>(); HashMap<String,Integer>map=new HashMap<>(); int count=1; for(char ch='a';ch<='z';ch++){ for(char d='a';d<='z';d++){ if(ch!=d){ String temp=""; temp=temp+ch+d; map.put(temp,count); count++; } } } while(testCases-- > 0){ String s=in.nextLine(); out.println(map.get(s)); } for(String s:answer){ out.println(s); } out.close(); } catch (Exception e) { return; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
ac87fd3f2f81a4bdd64e4d840ff76708
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.BufferedReader; import java.io.InputStreamReader; import java.lang.Math; import java.util.*; public class hi { public static void main(String[] args) throws java.lang.Exception{ InputStreamReader r=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(r); int a=Integer.parseInt(br.readLine()); while(a--!=0) { HashMap<Character,Integer> hm1=new HashMap<>(); HashMap<Character,Integer> hm2=new HashMap<>(); char ch='a'; int y=ch; //int x=Integer.parseInt(br.readLine()); // String [] s=m.split("\\s"); // int [] arr=new int[2]; // for(int i=0;i<2;i++) { // arr[i]=Integer.parseInt(s[i]); String m=br.readLine(); for(int i=0;i<26;i++) { char j=(char )(y+i); hm1.put(j,i+1); hm2.put(j,26*i); } // } int k=0; int u=hm1.get(m.charAt(1)); k=hm2.get(m.charAt(0)); int total=u+k; if(total<=27) { System.out.println(total-1); continue; } if(total<=54) { System.out.println(total-2); continue; } if(total<=81) { System.out.println(total-3); continue; } if(total<=109) { System.out.println(total-4); continue; } if(total<=136) { System.out.println(total-5); continue; } if(total<=163) { System.out.println(total-6); continue; } if(total<=190) { System.out.println(total-7); continue; } if(total<=217) { System.out.println(total-8); continue; } if(total<=244) { System.out.println(total-9); continue; } if(total<=271) { System.out.println(total-10); continue; } if(total<=298) { System.out.println(total-11); continue; } if(total<=325) { System.out.println(total-12); continue; } if(total<=352) { System.out.println(total-13); continue; } if(total<=379) { System.out.println(total-14); continue; } if(total<=406) { System.out.println(total-15); continue; } if(total<=433) { System.out.println(total-16); continue; } if(total<=460) { System.out.println(total-17); continue; } if(total<=487) { System.out.println(total-18); continue; } if(total<=514) { System.out.println(total-19); continue; } if(total<=541) { System.out.println(total-20); continue; } if(total<=568) { System.out.println(total-21); continue; } if(total<=595) { System.out.println(total-22); continue; } if(total<=622) { System.out.println(total-23); continue; } if(total<=649) { System.out.println(total-24); continue; } else { System.out.println(total-25); continue; } } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
a9d9db78b08faaba9ce4c5eaa9d3f08e
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.lang.*; public class B { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); for(int i = 0; i < t; i++) { String l = sc.nextLine(); int pos = (25 * (l.charAt(0) - 'a' )) ; if(l.charAt(0) < l.charAt(1)) pos += l.charAt(1) - 'a'; else pos += l.charAt(1) - 'a' + 1; System.out.println(pos); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
a5f76aff659b10b0be78f7a8e508c5e1
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import javax.print.attribute.HashDocAttributeSet; import java.util.HashMap; import java.util.Scanner; public class Abc { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t!=0){ String str= sc.next(); int ans = 0; char[] ch = str.toCharArray(); if(ch[1]<ch[0]) ans = (ch[0]-'a')*25 + (ch[1]-'a')+1; else ans = (ch[0]-'a')*25 + (ch[1]-'a'); System.out.println(ans); t--; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
132e66b4844b820e48b7db347f602c91
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; public class BDictionary { public static void main(String[] args) throws Exception { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); int t = Integer.parseInt(br.readLine()); for(int i =0;i<t;i++){ String word = br.readLine(); int index = 0; if(word.charAt(0)<word.charAt(1)) index = ((word.charAt(0)-97)*25)+(word.charAt(1)-97); else index = ((word.charAt(0)-97)*25)+(word.charAt(1)-96); System.out.println(index); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
2e12fb26dfd0a5740037fd004a6a2e47
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Sol1{ public static void main(String[] args) { Scanner scn = new Scanner(System.in); int ts = Integer.parseInt(scn.nextLine()); for(int t =0;t<ts;t++){ String str = scn.nextLine(); int x=(str.charAt(0)-97); int y=str.charAt(1)-97; int outt=0; String nstr= ""+str.charAt(0)+str.charAt(0); if(str.charAt(1)<str.charAt(0)){ outt= 26*x+y-(x-1); } else outt =26*x+y-(x); // if(x==0||x==1) outt = ; // else outt = x*25+y+1; System.out.println(outt); } } } /* 7 ab ac az ba bc zx zy */
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
872b854767df357c6eae3ff3d640a90b
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 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) { String s = sc.next(); int a = s.charAt(0), b = s.charAt(1), c; if(b < a) { c = (a - 97) * 25 + b - 97 + 1; } else { c = (a - 97) * 25 + b - 97; } System.out.println(c); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
4eb4b5df051cce461b25531042e5c4a1
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; import java.util.Stack; import java.util.StringTokenizer; public class Binary_Tree_Creation { static FastReader scn = 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 { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Node{ int data; Node left; Node right; public Node(int data){ this.data = data; } } static class BST{ Node root; public BST(){ root = null; } public void insert(int data){ root = insertin(root, data); } private Node insertin(Node root, int data){ if(root == null){ Node n = new Node(data); root = n; return root; } if(root.data < data){ root.right = insertin(root.right, data); } else root.left = insertin(root.left, data); return root; } public void print(){ InIt(root); } private void InIt(Node root){ if(root == null) return; Stack<Node> st = new Stack<>(); while (true){ if (root != null){ st.add(root); root = root.left; } else { if (st.isEmpty()) break; root = st.pop(); System.out.println(root.data); root = root.right; } } } private void PreIt(Node root){ if(root == null) return; Stack<Node> st = new Stack<>(); st.add(root); while (!st.isEmpty()){ Node cur = st.pop(); System.out.println(cur.data); if (cur.right != null)st.add(cur.right); if(cur.left != null) st.add(cur.left); } } private void inOrder(Node root){ if (root != null){ System.out.println(root.data); inOrder(root.left); inOrder(root.right); } } private void Level(Node root){ if(root == null) return; Queue<Node> q = new LinkedList<>(); q.add(root); while (!q.isEmpty()){ Node cur = q.poll(); if(cur.left!= null) q.add(cur.left); if(cur.right!= null) q.add(cur.right); System.out.println(cur.data); } } } public static void main(String[] args) throws Exception { int t = scn.nextInt(); while(t-->0){ String s = scn.next(); char fir = s.charAt(0); char sec = s.charAt(1); int rank = 0; rank += sec-'a'+1; rank += 26*(fir-'a'); // if(fir<sec) rank -= fir-'a'; rank -= fir-'a'+1; if(fir>sec) rank++; System.out.println(rank); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
bf77f064f7787a31867a693e0feccc31
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class store { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); String str[] = new String[t+1]; for(int i=0; i<=t; i++){ str[i] = sc.nextLine(); } int n=0; int arr[] = new int[t+1]; for(int i=1; i<=t; i++){ char a = str[i].charAt(0); char b = str[i].charAt(1); int x = (int)a - 97; int y = (int)b - 97; n = x*25 + y; if(x>y){ n++; } arr[i] = n; } for(int i=1; i<=t; i++){ System.out.println(arr[i]); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
63390957af1c1344f80e5856b82ca6b2
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.InputMismatchException; public class B { public static int getCost(char c) { return c - 'a' + 1; } public static void main(String[] args) throws IOException { ReadInput in = new ReadInput(System.in); PrintWriter writer = new PrintWriter(System.out); int t = in.nextInt(); for (int ti = 0; ti < t; ti++) { char[] s = in.next().toCharArray(); int res = (getCost(s[0]) - 1) * 25 + getCost(s[1]) - (s[0] < s[1] ? 1 : 0); writer.println(res); } in.close(); writer.flush(); writer.close(); } public static class ReadInput { private final BufferedReader source; private String next; public ReadInput(InputStream source) { this.source = new BufferedReader(new InputStreamReader(source)); } public ReadInput(String source) { this.source = new BufferedReader(new StringReader(source)); } public ReadInput(File source) throws IOException { this.source = new BufferedReader(new FileReader(source)); } public String next() throws IOException { if (next == null) { if (!hasNext()) { throw new InputMismatchException("Nothing to read"); } } String res = next; next = null; return res; } public int nextInt() throws IOException { return Integer.parseInt(next()); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public Double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean hasNext() throws IOException { if (next != null) { return true; } StringBuilder sb = new StringBuilder(); int read = skipSpaces(); while (read != -1 && !testSpaces(read)) { sb.append((char) read); read = source.read(); } if (sb.length() > 0) { next = sb.toString(); return true; } else { return false; } } private int skipSpaces() throws IOException { int read; do { read = source.read(); } while (testSpaces(read)); return read; } private boolean testSpaces(int c) { return c == ' ' || c == '\r' || c == '\t' || c == '\n'; } public void close() throws IOException { next = null; source.close(); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
e207e5a2339be41170d329f8b7a8e9e6
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
/* AUTHOR-> HARSHIT AGGARWAL CODEFORCES HANDLE-> @harshit_agg FROM-> MAHARAJA AGRASEN INSTITUE OF TECHNOLOGY >> YOU CAN DO THIS << */ import java.util.*; import java.io.*; public class dictionary { public static void main(String[] args) throws Exception { int t = scn.nextInt(); while (t-- > 0) { solver(); } } public static void solver() { String s = scn.next(); int ans = (((s.charAt(0)-'0')-49)*25) ; if(s.charAt(1) > s.charAt(0)){ ans += (s.charAt(1)-'0')-49; // System.out.println("rum"); }else{ ans += (s.charAt(1)-'0')-48; } System.out.println(ans); } //-------------------------------- HO JA BHAI ---------------------------------------------------- /* code ends here*/ //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx U T I L I T I E S xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx public static class Debug { public static final boolean LOCAL = System.getProperty("LOCAL")==null; private static <T> String ts(T t) { if(t==null) { return "null"; } try { return ts((Iterable) t); }catch(ClassCastException e) { if(t instanceof int[]) { String s = Arrays.toString((int[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof long[]) { String s = Arrays.toString((long[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof char[]) { String s = Arrays.toString((char[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof double[]) { String s = Arrays.toString((double[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof boolean[]) { String s = Arrays.toString((boolean[]) t); return "{"+s.substring(1, s.length()-1)+"}"; } try { return ts((Object[]) t); }catch(ClassCastException e1) { return t.toString(); } } } private static <T> String ts(T[] arr) { StringBuilder ret = new StringBuilder(); ret.append("{"); boolean first = true; for(T t: arr) { if(!first) { ret.append(", "); } first = false; ret.append(ts(t)); } ret.append("}"); return ret.toString(); } private static <T> String ts(Iterable<T> iter) { StringBuilder ret = new StringBuilder(); ret.append("{"); boolean first = true; for(T t: iter) { if(!first) { ret.append(", "); } first = false; ret.append(ts(t)); } ret.append("}"); return ret.toString(); } public static void dbg(Object... o) { if(LOCAL) { System.err.print("Line #"+Thread.currentThread().getStackTrace()[2].getLineNumber()+": ["); for(int i = 0; i<o.length; i++) { if(i!=0) { System.err.print(", "); } System.err.print(ts(o[i])); } System.err.println("]"); } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { try { br = new BufferedReader(new FileReader("input.txt")); PrintStream out = new PrintStream(new FileOutputStream("output.txt")); System.setOut(out); } catch (Exception e) { 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()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int INF = (int) 1e9 + 7; // static int INF = 998244353; static int MAX = Integer.MAX_VALUE; // static int MAX = 2147483647 static int MIN = Integer.MIN_VALUE; // static int MIN = -2147483647 static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair o) { return this.first- o.first; } } static class LongPair { long first; long second; LongPair(long a, long b) { this.first = a; this.second = b; } } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static int LowerBound(long a[], long x) { /* x is the key or target value */int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] >= x) r = m; else l = m; } return r; } public static int LowerBound(int a[], int x) { /* x is the key or target value */int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] >= x) r = m; else l = m; } return r; } static int LowerBoundList(ArrayList<Integer> a, int x) { /* x is the key or target value */int l = -1, r = a.size(); while (l + 1 < r) { int m = (l + r) >>> 1; if (a.get(m) >= x) r = m; else l = m; } return r; } static boolean[] prime; public static void sieveOfEratosthenes(int n) { prime = new boolean[n + 1]; for (int i = 0; i < n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } } public static int UpperBound(long a[], long x) {/* x is the key or target value */int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; } public static int UpperBound(int a[], int x) {/* x is the key or target value */int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static void swap(int[] arr, int i, int j) { if (i != j) { arr[i] ^= arr[j]; arr[j] ^= arr[i]; arr[i] ^= arr[j]; } } public static long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = scn.nextLong(); return a; } public static int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = scn.nextInt(); } return a; } public int[][] nextIntMatrix(int n, int m) { int[][] grid = new int[n][m]; for (int i = 0; i < n; i++) { grid[i] = nextIntArray(m); } return grid; } public static int smallest_divisor(int n) { int i; for (i = 2; i <= Math.sqrt(n); ++i) { if (n % i == 0) { return i; } } return n; } public static FastReader scn = new FastReader(); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
23a8e6ffc148e256de9d013e1725ee7d
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.util.StringTokenizer; import java.io.InputStreamReader; public class div3 { public static class fastreader { BufferedReader br; StringTokenizer st; public fastreader() { br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(" "); } public String read() { while((st==null)||(!st.hasMoreElements())) { try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(read()); } public long nextLong() { return Long.parseLong(read()); } public double nextDouble() { return Double.parseDouble(read()); } public String readLine() { String s=""; try { s=br.readLine(); } catch(IOException e) { e.printStackTrace(); } return s; } } public static void main(String[] args) { fastreader fr=new fastreader(); int t; t=fr.nextInt(); String sr; int a=0,b=0,l; while(t-->0) { sr=fr.readLine(); a=(int)(sr.charAt(0)-'a'); b=(int)(sr.charAt(1)-'a'); l=a*26+b; if(b>a) l-=a; else l-=a-1; System.out.println(l); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
cd546d4d6b4d01a2171a7fb8afc75e88
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class Dictionary { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { String s = sc.next(); int ans = 1; pls: for (int i = 0; i < 26; i++) { for (int j = 0; j < 26; j++) { if ('a' + i == s.charAt(0) && 'a' + j == s.charAt(1)) { break pls; } else if ('a' + i != 'b' + j) { ans++; } } } System.out.println(ans - 1); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
1c47da3ff5411fc471d7c5d27e0bb017
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; public class A { static long TIME_START, TIME_END; public static class Task { public void solve(Scanner sc, PrintWriter pw) throws IOException { String s = sc.next(); int rank = (s.charAt(0) - 'a') * 25 + (s.charAt(1) - 96); if (s.charAt(0) < s.charAt(1)) rank = rank - 1; pw.println(rank); } } public static void main(String[] args) throws IOException { // Scanner sc = new Scanner(new FileReader(System.getenv("INPUT"))); Scanner sc = new Scanner(System.in); // PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(System.getenv("OUTPUT")))); 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(); int T = sc.nextInt(); while (T-- > 0) { 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 int[] readIntArray(int n) throws IOException { int[] arr = new int[n]; String[] a = nextLine().split(" "); for (int i = 0; i < n; i++) arr[i] = Integer.parseInt(a[i]); return arr; } public long[] readLongArray(int n) throws IOException { long[] arr = new long[n]; String[] a = nextLine().split(" "); for (int i = 0; i < n; i++) arr[i] = Long.parseLong(a[i]); return arr; } public boolean ready() throws IOException { return br.ready(); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
37e856fa7c57ac85d1b265dfd0b8e48f
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { public static void process()throws IOException { String s=nn(); int first=s.charAt(0)-'a'; int second=s.charAt(1)-'a'; if(first==0) pn(second); else { int start=first*25+1; if(first<second) pn(start+second-1); else pn(start+second); } } static AnotherReader sc; static PrintWriter out; public static void main(String[]args)throws IOException { out = new PrintWriter(System.out); sc=new AnotherReader(); boolean oj = true; //oj = System.getProperty("ONLINE_JUDGE") != null; //if(!oj) sc=new AnotherReader(100); long s = System.currentTimeMillis(); int T=ni(); while(T-->0) process(); out.flush(); if(!oj) System.out.println(System.currentTimeMillis()-s+"ms"); System.out.close(); } static void sort(long arr[],int n) { shuffle(arr,n); Arrays.sort(arr); } static void shuffle(long arr[],int n) { Random r=new Random(); for(int i=0;i<n;i++) { long temp=arr[i]; int pos=i+r.nextInt(n-i); arr[i]=arr[pos]; arr[pos]=temp; } } static void pn(Object o){out.println(o);} static void p(Object o){out.print(o);} static void pni(Object o){out.println(o);System.out.flush();} static int ni()throws IOException{return sc.nextInt();} static long nl()throws IOException{return sc.nextLong();} static double nd()throws IOException{return sc.nextDouble();} static String nln()throws IOException{return sc.nextLine();} static String nn()throws IOException{return sc.next();} static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));} static int[] iarr(int N)throws IOException{int[]ARR=new int[N];for(int i=0;i<N;i++){ARR[i]=ni();}return ARR;} static long[] larr(int N)throws IOException{long[]ARR=new long[N];for(int i=0;i<N;i++){ARR[i]=nl();}return ARR;} static boolean multipleTC=false; ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class AnotherReader{BufferedReader br; StringTokenizer st; AnotherReader()throws FileNotFoundException{ br=new BufferedReader(new InputStreamReader(System.in));} AnotherReader(int a)throws FileNotFoundException{ br = new BufferedReader(new FileReader("input.txt"));} String next()throws IOException{ while (st == null || !st.hasMoreElements()) {try{ st = new StringTokenizer(br.readLine());} catch (IOException e){ e.printStackTrace(); }} return st.nextToken(); } int nextInt() throws IOException{ return Integer.parseInt(next());} long nextLong() throws IOException {return Long.parseLong(next());} double nextDouble()throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException{ String str = ""; try{ str = br.readLine();} catch (IOException e){ e.printStackTrace();} return str;}} ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } /* var urlSchema=new mongoose.Schema({ originalUrl:{type: String} shortenedUrl:{type:String} expirationDate:{type: Number,default: 48} timeCreated: {type: Date,deafult:Date.now} }) */
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
9e6e75d3570c70d93c5c0faf1d1c2f56
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; import java.lang.*; public class Codechef { 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[200001]; // 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(); }} static void cout(Object line) {System.out.println(line);} static void iop() { try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); } catch (Exception e) { System.err.println("Error"); }} static int gcd(int a, int b) { if(b == 0) return a; else return gcd(b,a%b);} static boolean isPerfectSquare(long n){ if (Math.ceil((double)Math.sqrt(n)) ==Math.floor((double)Math.sqrt(n))) return true; else return false;} static boolean isPrime(int n){ if (n <= 1) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; for (int i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true;} static int fact(int n){ return (n == 1 || n == 0) ? 1 : n * fact(n - 1);} static boolean isPowerOfTwo (int x) { /* First x in the below expression is for the case when x is 0 */ return x!=0 && ((x&(x-1)) == 0);} static void printArray(int arr[]) { for(int i = 0; i < arr.length; i++) { System.out.print(arr[i] + " "); }} public static void main(String[] args) throws IOException{ iop(); Reader s = new Reader(); // Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-- > 0) { String str = s.readLine(); char ch[] = str.toCharArray(); int a = ch[0]-'a'; int b = ch[1] -'a'; int result = 0; if(a < b) { result = 25*a+b; } else { result = 25*a+b+1; } cout(result); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
2058edd4b4efb59e5ed8aaeae22ad8b9
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; import java.io.*; public class Main { static FastReader reader = new FastReader(); public static void main(String[] args) { int t = ri(); outerloop: while(t-->0) { String s = rs(); int res = 0; res += (s.charAt(0)-'a')*25; if(s.charAt(1)>s.charAt(0)) res += s.charAt(1)-'a'; else res += s.charAt(1)-'a'+1; log(res, str); } System.out.println(str.toString()); } static StringBuilder str = new StringBuilder(""); static int MOD = 1000000007; static HashSet<Integer> factors = new HashSet<Integer>(); static HashSet<Integer> primes = new HashSet<Integer>(); static void log(long a, StringBuilder str) { str.append(a+"\n");} static int ri() { return reader.nextInt(); } static String rs() { return reader.nextLine(); } static long rl() { return reader.nextLong(); } static int[] ra(int n) { int[] arr = new int[n]; for(int i = 0; i < n; i++) arr[i] = ri(); return arr; } static class Pair { int a; int b; Pair(int a, int b) { this.a = a; this.b = b; } } public static int mex(int[] arr) { int a = -1; for(int val: arr) { if(val-a>1) break; else a = val; } return a+1; } static void seive(int n) { boolean[] composite = new boolean[n + 1]; for (int i = 2; i * i <= n; i++) { if (!composite[i]) { for (int j = i * i; j <= n; j += i) composite[j] = true; } } for (int i = 2; i <= n; i++) { if (!composite[i]) primes.add(i); } } static int sumofdigits(long n) { int sum = 0; while(n>0) { sum += n%10; n /= 10; } return sum; } static void findfactors(int n) { if ((n & 1) == 0) { factors.add(2); while ((n & 1) == 0) n = n >> 1; } for (int i = 3; i * i <= n; i++) { if (n % i == 0) factors.add(i); while ((n % i) == 0) n /= i; } if (n > 1) factors.add(n); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long lcm(long a, long b) { long lcm = (a * b) / gcd(a, b); return lcm; } static int binarySearch(ArrayList<Integer> list, int n) { int start = 0; int end = list.size() - 1; while (start <= end) { int mid = start + (end - start) / 2; if (list.get(mid) == n) return mid; else if (list.get(mid) > n) end = mid - 1; else start = mid + 1; } if (start == list.size()) return -1; else return start; } // For fast input output static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { try { br = new BufferedReader(new FileReader("input.txt")); PrintStream out = new PrintStream(new FileOutputStream("output.txt")); System.setErr(new PrintStream(new FileOutputStream("error.txt"))); System.setOut(out); } catch (Exception e) { 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; } } // end of fast i/o code }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
fe4717d7e08bcc770f737cbc0c66454d
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.*; public class WorldRecord { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-->0) { String s =sc.next(); Map<Character ,Integer> mp= new HashMap<>(); mp.put('a',0); mp.put('b',1); mp.put('c',2); mp.put('d',3); mp.put('e',4); mp.put('f',5); mp.put('g',6); mp.put('h',7); mp.put('i',8); mp.put('j',9); mp.put('k',10); mp.put('l',11); mp.put('m',12); mp.put('n',13); mp.put('o',14); mp.put('p',15); mp.put('q',16); mp.put('r',17); mp.put('s',18); mp.put('t',19); mp.put('u',20); mp.put('v',21); mp.put('w',22); mp.put('x',23); mp.put('y',24); mp.put('z',25); int ans =0; int k = 25*mp.get(s.charAt(0)); if (s.charAt(0) >s.charAt(1)) { ans = k+(mp.get(s.charAt(1)) +1); } else if (s.charAt(0) <s.charAt(1)) { ans = k+mp.get(s.charAt(1)); } System.out.println(ans); // int m = sc.nextInt(); // int ta = sc.nextInt(); // int[] ar= new int[m]; // int massy =0, bigsum =0,sum =0; // int flag =0; // for (int i=0;i<m;i++) // { // ar[i] =sc.nextInt(); // massy =Math.max(massy,ar[i]); //4 // sum +=ar[i]; // 7 // } // for (int i=1;i<=massy;i++) // { // bigsum +=i; // 1+2+3+4 // } // int n = bigsum-sum; //10-7 3 // if(m<=ta) // { // ta -=n; //10 // } // else // flag =1; // 3 1 4 ,13 // // if (ta>0) // { // while (ta>0) // { // ta -=massy+1; //10 ,10-5 , // massy +=1; // } // } // if (ta !=0) // flag =1; // // // if (flag ==0) // System.out.println("yes"); // else // System.out.println("no"); // 3 1 4 } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
f1c5a924694ba017fffee24c4868a22e
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; public class Alph { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader (new InputStreamReader (System.in)); int numberSets = Integer.parseInt(br.readLine()); for (int nos = 0; nos < numberSets; nos++) { char [] data = br.readLine().toCharArray(); int sum = 25 * (data[0] - 'a'); if (data[1] < data [0]) { sum+=(data[1] - 'a'+1); } else { sum+=(data[1] - 'a'); } System.out.println(sum); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
54f142aeb90805026bab3258e21a7f44
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
/*LoudSilence*/ import java.io.*; import java.util.*; import static java.lang.Math.*; public class Solution { /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ static FastScanner s = new FastScanner(); static FastWriter out = new FastWriter(); final static int mod = (int)1e9 + 7; final static int INT_MAX = Integer.MAX_VALUE; final static int INT_MIN = Integer.MIN_VALUE; final static long LONG_MAX = Long.MAX_VALUE; final static long LONG_MIN = Long.MIN_VALUE; final static double DOUBLE_MAX = Double.MAX_VALUE; final static double DOUBLE_MIN = Double.MIN_VALUE; final static float FLOAT_MAX = Float.MAX_VALUE; final static float FLOAT_MIN = Float.MIN_VALUE; /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ static class FastScanner{BufferedReader br;StringTokenizer st; public FastScanner() {if(System.getProperty("ONLINE_JUDGE") == null){try {br = new BufferedReader(new FileReader("E:\\Competitive Coding\\input.txt"));} catch (FileNotFoundException e) {br = new BufferedReader(new InputStreamReader(System.in));}}else{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());} List<Integer> readIntList(int n){List<Integer> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextInt()); return arr;} List<Long> readLongList(int n){List<Long> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextLong()); return arr;} int[] readIntArr(int n){int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = s.nextInt(); return arr;} long[] readLongArr(int n){long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = s.nextLong(); return arr;} String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}} static class FastWriter{private BufferedWriter bw;public FastWriter(){if(System.getProperty("ONLINE_JUDGE") == null){try {this.bw = new BufferedWriter(new FileWriter("E:\\Competitive Coding\\output.txt"));} catch (IOException e) {this.bw = new BufferedWriter(new OutputStreamWriter(System.out));}}else{this.bw = new BufferedWriter(new OutputStreamWriter(System.out));}} public void print(Object object) throws IOException{bw.append(""+ object);} public void println(Object object) throws IOException{print(object);bw.append("\n");} public void debug(int object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");} public void debug(long object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");} public void close() throws IOException{bw.close();}} public static void println(Object str) throws IOException{out.println(""+str);} public static void println(Object str, int nextLine) throws IOException{out.print(""+str);} /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ public static ArrayList<Integer> seive(int n){ArrayList<Integer> list = new ArrayList<>();int arr[] = new int[n+1];for(long i = 2; i <= n; i++) {if(arr[(int)i] == 1) {continue;}else {list.add((int)i);for(long j = i*i; j <= n; j = j + i) {arr[(int)j] = 1;}}}return list;} 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);} public static void swap(int[] arr, int i, int j) {arr[i] = arr[i] ^ arr[j]; arr[j] = arr[j] ^ arr[i]; arr[i] = arr[i] ^ arr[j];} public static boolean isPrime(long n){if(n < 2){return false;}if(n == 2 || n == 3){return true;}if(n%2 == 0 || n%3 == 0){return false;}long sqrtN = (long)Math.sqrt(n)+1;for(long i = 6L; i <= sqrtN; i += 6) {if(n%(i-1) == 0 || n%(i+1) == 0) return false;}return true;} public static long mod_add(long a, long b){ return (a%mod + b%mod)%mod;} public static long mod_sub(long a, long b){ return (a%mod - b%mod + mod)%mod;} public static long mod_mul(long a, long b){ return (a%mod * b%mod)%mod;} public static long modInv(long a, long b){ return expo(a, b-2)%b;} public static long mod_div(long a, long b){return mod_mul(a, modInv(b, mod));} public static long expo (long a, long n){if(n == 0){return 1;}long recAns = expo(mod_mul(a,a), n/2);if(n % 2 == 0){return recAns;}else{return mod_mul(a, recAns);}} /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ // Pair class static class Pair implements Comparable<Pair>{ long f; long s; public Pair(long f, long s){ this.f = f; this.s = s; } public String toString(){ return "("+f+", "+s+")"; } @Override public int compareTo(Pair o) { if(f == o.f) return s-o.s < 0 ? -1 : 1; else return f-o.f < 0 ? -1 : 1; } } static class Triplet{ long f; long s; long t; public Triplet(long f, long s, long t){ this.f = f; this.s = s; this.t = t; } public String toString(){ return "("+f+", "+s+", "+t+")"; } } // public static class Pair<X extends Comparable<X>,Y extends Comparable<Y>> implements Comparable<Pair<X,Y>>{ // X first; // Y second; // public Pair(X first, Y second){ // this.first = first; // this.second = second; // } // public String toString(){ // return "( " + first+" , "+second+" )"; // } // @Override // public int compareTo(Pair<X, Y> o) { // int t = first.compareTo(o.first); // if(t == 0) return second.compareTo(o.second); // return t; // } // } /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ // Code begins public static void solve() throws IOException { String str = s.next(); for(int i = 0; i < arr.size(); i++){ if(arr.get(i).equals(str)){ println(i+1); break; } } } static ArrayList<String> arr = new ArrayList<>(); /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ public static void main(String[] args) throws IOException { for(char i = 'a'; i <= 'z'; i++){ for(char j = 'a'; j <= 'z'; j++){ if(i!=j){ arr.add(""+i+j); } } } Collections.sort(arr); int test = s.nextInt(); for(int t = 1; t <= test; t++) { solve(); } out.close(); } } /*public static boolean allsame(int arr[]){ for(int i = 0; i < arr.length-1; i++){ if(arr[i] != arr[i+1]) return false; } return true; } public static List<List<Integer>> permutation(int arr[], int i){ if(i == 0){ List<List<Integer>> ans = new ArrayList<>(); List<Integer> li = new ArrayList<>(); li.add(arr[i]); ans.add(li); return ans; } int temp = arr[i]; List<List<Integer>> rec = permutation(arr, i-1); List<List<Integer>> ans = new ArrayList<>(); for(List<Integer> li : rec){ for(int j = 0; j <= li.size(); j++){ List<Integer> list = new ArrayList<>(); for(int ele: li){ list.add(ele); } list.add(j, temp); ans.add(list); } } return ans; }*/
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
3f5a06eeae7b2aacce8e14c64cfdf339
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; /* * To execute Java, please define "static void main" on a class * named Solution. * * If you need more classes, simply define them inline. */ public class Solution { static Scanner sc = new Scanner(System.in) ; public static void solve() { String letters = sc.nextLine(); int index = 0 ; for (int i = 97; i < 123; i++) { for (int j = 97; j < 123; j++) { if (i!=j){ index++; } if (letters.charAt(0)==i && letters.charAt(1)==j){ System.out.println(index); return ; } } } } public static void main(String[] args) { int tt = sc.nextInt() ; sc.nextLine(); while (tt-->0) { solve() ; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
4cb871816c4c06d0a78bca251bc9c44d
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
// https://codeforces.com/problemset/problem/1674/B // B. Dictionary import java.util.*; import java.io.*; import java.text.*; public class Dictionary { // Generate your map here. Map<String, Integer> generateMap() { Map<String, Integer> map = new HashMap<>(); int index = 0; for(int i = 0; i < 26; i++) { for(int j = 0; j < 26; j++) { if(i != j) { String x = Character.toString((char)(i + 97)) + "" + Character.toString((char)(j + 97)); map.put(x, ++index); } } } return map; } void solve(int TC, Map<String, Integer> m) throws Exception { String s = ns(); println(m.get(s)); } long mod = (long)998244353, IINF = (long)1e17; final int MAX = (int)1e3+1, INF = (int)2e9, root = 3; DecimalFormat df = new DecimalFormat("0.0000000000000"); double PI = 3.1415926535897932384626433832792884197169399375105820974944, eps = 1e-8; static boolean multipleTC = true, memory = false; FastReader in; PrintWriter out; void run() throws Exception{ in = new FastReader(); out = new PrintWriter(System.out); int T = (multipleTC) ? ni():1; Map<String, Integer> myMap = generateMap(); for(int i = 1; i<= T; i++) { solve(i, myMap); } out.flush(); out.close(); } public static void main(String[] args) throws Exception{ if(memory) new Thread(null, new Runnable() {public void run(){try{new Dictionary().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start(); else new Dictionary().run(); } long gcd(long a, long b){ return (b==0)?a:gcd(b,a%b); } int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);} int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));} // Find factorial using recursion long factorial(long n){ if (n == 0) return 1; else return(n * factorial(n-1)); } // Print void print(Object o){out.print(o);} // Print next line void println(Object o){out.println(o);} void pni(Object o){out.println(o);out.flush();} // String next String ns(){return in.next();} // String new line String nsln(){return in.nextLine();} // Integer int ni(){return Integer.parseInt(in.next());} // Long long nl(){return Long.parseLong(in.next());} // Double double nd(){return Double.parseDouble(in.next());} class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws Exception{ br = new BufferedReader(new FileReader(s)); } String next(){ while (st == null || !st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } } return st.nextToken(); } String nextLine(){ String str = ""; try{ str = br.readLine(); }catch (IOException e){ e.printStackTrace(); } return str; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output