importjava.io.*;publicclassMain{
staticBufferedReader bf =newBufferedReader(newInputStreamReader(System.in));staticBufferedWriter bw =newBufferedWriter(newOutputStreamWriter(System.out));publicstaticvoidsolve()throwsIOException{
char[] s = bf.readLine().toCharArray();for(int i =0; i <4; i++){
if(s[i]=='0'){
s[i]='0'+10;}}int res =4+ s[0]-'1';for(int i =1; i <4; i++){
res +=Math.abs(s[i]- s[i -1]);}
bw.write(res +"\n");}publicstaticvoidmain(String[] args)throwsIOException{
intT=Integer.parseInt(bf.readLine());while(T-->0){
solve();}
bw.close();}}
importjava.io.*;publicclassMain{
staticBufferedReader bf =newBufferedReader(newInputStreamReader(System.in));staticBufferedWriter bw =newBufferedWriter(newOutputStreamWriter(System.out));publicstaticvoidsolve()throwsIOException{
String[] str = bf.readLine().split(" ");int n =Integer.parseInt(str[0]);int k =Integer.parseInt(str[1]);int[] a =newint[n +1];
str = bf.readLine().split(" ");if(k !=4){
int ans =1000000000;for(int i =1; i <= n; i++){
a[i]=Integer.parseInt(str[i -1]);if(a[i]% k ==0) ans =0;else ans =Math.min(ans, k - a[i]% k);}
bw.write(ans +"\n");}else{
int t =0, ans =1000000000;for(int i =1; i <= n; i++){
a[i]=Integer.parseInt(str[i -1]);if(a[i]%2==0) t++;if(a[i]%4==0) ans =0;if(a[i]%4==3) ans =Math.min(ans,1);}
bw.write(Math.min(ans,Math.max(0,2- t))+"\n");}}publicstaticvoidmain(String[] args)throwsIOException{
intT=Integer.parseInt(bf.readLine());while(T-->0){
solve();}
bw.close();}}
importjava.io.*;publicclassMain{
staticBufferedReader bf =newBufferedReader(newInputStreamReader(System.in));staticBufferedWriter bw =newBufferedWriter(newOutputStreamWriter(System.out));publicstaticvoidsolve()throwsIOException{
int n =Integer.parseInt(bf.readLine());int[] a =newint[n +1];String[] str = bf.readLine().split(" ");for(int i =1; i <= n; i++){
a[i]=Integer.parseInt(str[i -1]);}long res =0;int e =0;for(int i =2; i <= n; i++){
int x = a[i];while(e !=0&& x >=2* a[i -1]){
x /=2;
e--;}while(x < a[i -1]){
x *=2;
e++;}
res += e;}
bw.write(res +"\n");}publicstaticvoidmain(String[] args)throwsIOException{
intT=Integer.parseInt(bf.readLine());while(T-->0){
solve();}
bw.close();}}
importjava.io.*;importjava.util.TreeMap;publicclassMain{
staticBufferedReader bf =newBufferedReader(newInputStreamReader(System.in));staticBufferedWriter bw =newBufferedWriter(newOutputStreamWriter(System.out));publicstaticvoidsolve()throwsIOException{
int n =Integer.parseInt(bf.readLine());int[] a =newint[n +1];TreeMap<Integer,Integer> l =newTreeMap<>();TreeMap<Integer,Integer> r =newTreeMap<>();String[] str = bf.readLine().split(" ");for(int i =1; i <= n; i++){
a[i]=Integer.parseInt(str[i -1]);
r.put(a[i], r.getOrDefault(a[i],0)+1);}long res =0;for(int i =1; i <= n; i++){
l.put(a[i], l.getOrDefault(a[i],0)+1);if(l.get(a[i])==1){
res += r.size();}
r.put(a[i], r.get(a[i])-1);if(r.get(a[i])==0) r.remove(a[i]);}
bw.write(res +"\n");}publicstaticvoidmain(String[] args)throwsIOException{
intT=Integer.parseInt(bf.readLine());while(T-->0){
solve();}
bw.close();}}
importjava.io.*;importjava.util.Arrays;publicclassMain{
staticBufferedReader bf =newBufferedReader(newInputStreamReader(System.in));staticBufferedWriter bw =newBufferedWriter(newOutputStreamWriter(System.out));publicstaticvoidsolve()throwsIOException{
String[] str = bf.readLine().split(" ");int n =Integer.parseInt(str[0]);int m =Integer.parseInt(str[1]);int[] a =newint[n -1];int[] b =newint[n];
str = bf.readLine().split(" ");for(int i =0; i < n -1; i++){
a[i]=Integer.parseInt(str[i]);}
str = bf.readLine().split(" ");for(int i =0; i < n; i++){
b[i]=Integer.parseInt(str[i]);}Arrays.sort(a,0, n -1);Arrays.sort(b,0, n);int num =0, j =0;long ans = n -1;for(int i =0; i < n -1&& j < n; i++, j++){
while(j < n && a[i]>= b[j]){
num = b[j];
j++;}if(j < n) ans--;}if(j < n) num = b[j];
bw.write((ans * m +Math.max(0, m - num +1))+"\n");}publicstaticvoidmain(String[] args)throwsIOException{
intT=Integer.parseInt(bf.readLine());while(T-->0){
solve();}
bw.close();}}
importjava.io.*;importjava.util.Arrays;publicclassMain{
staticBufferedReader bf =newBufferedReader(newInputStreamReader(System.in));staticBufferedWriter bw =newBufferedWriter(newOutputStreamWriter(System.out));publicstaticvoidsolve()throwsIOException{
String[] str = bf.readLine().split(" ");int n =Integer.parseInt(str[0]);int m =Integer.parseInt(str[1]);int[] a =newint[n -1];int[] b =newint[n];
str = bf.readLine().split(" ");for(int i =0; i < n -1; i++){
a[i]=Integer.parseInt(str[i]);}
str = bf.readLine().split(" ");for(int i =0; i < n; i++){
b[i]=Integer.parseInt(str[i]);}Arrays.sort(a,0, n -1);Arrays.sort(b,0, n);int num =0, j =0;long ans = n -1;for(int i =0; i < n -1&& j < n; i++, j++){
while(j < n && a[i]>= b[j]){
num = b[j];
j++;}if(j < n) ans--;}if(j < n) num = b[j];
bw.write((ans * m +Math.max(0, m - num +1))+"\n");}publicstaticvoidmain(String[] args)throwsIOException{
intT=Integer.parseInt(bf.readLine());while(T-->0){
solve();}
bw.close();}}
文章评论