-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmth.java
More file actions
39 lines (34 loc) · 1.21 KB
/
Copy pathsmth.java
File metadata and controls
39 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.*;
import java.util.*;
public class smth {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
long t = Long.parseLong(br.readLine());
while(t -- > 0) {
char[] digits = br.readLine().toCharArray();
int firstDig = Character.getNumericValue(digits[0]);
int len = digits.length;
long ans = 0;
for(int i=1; i<len-1; i++) {
ans += (5 * Long.parseLong(stringOfOnes(i)));
}
if(firstDig > 4) {
ans += 5 * Long.parseLong(stringOfOnes(len-1));
}
else if(firstDig == 4) {
long toAdd = Math.max(0, (Long.parseLong(new String(digits)) - 4 * Integer.parseInt(stringOfOnes(len))));
ans += toAdd;
}
pw.println(ans);
}
pw.close();
}
static String stringOfOnes(int x) {
StringBuilder res = new StringBuilder();
for(int i=0; i<x; i++) {
res = res.append("1");
}
return new String(res);
}
}