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
1f332c14ab30dc10cd0d20b4f355c194
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
//package CP.Codeforces.Div2_4_8_22; import java.util.*; import java.io.*; public class Moves23 { static FastReader in=new FastReader(); static final Random random=new Random(); static long mod=1000000007L; static HashMap<String,Integer>map=new HashMap<>(); public static void main(String args[]) throws IOException { int t=in.nextInt(); StringBuilder res=new StringBuilder(); int cse=1; while(t-->0) { long n = in.nextLong(); long min = findMin(n); res.append(min + "\n"); } print(res); } private static long findMin(long n) { if(n==1) return 2; else if(n%3 == 0) return n/3; else return n/3+1; } // Sorts in N log N always static void sort(int[] a) { ArrayList<Integer> list = new ArrayList<>(); for(int i : a) list.add(i); Collections.sort(list); // list sort uses merge sort so always (N logN) unlike Quick sort (worst is O(n2) for(int i=0; i<a.length; i++) a[i] = list.get(i); } static < E > void print(E res) { System.out.println(res); } static int gcd(int a,int b) { if(b==0) return a; return gcd(b,a%b); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static int abs(int a) { if(a<0) return -1*a; return a; } // Fast IO 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 [] readIntArray(int n) { int res [] = new int [n]; for(int i = 0; i<n; i++)res[i] = nextInt(); return res; } long [] readLongArray(int n) { long res [] = new long [n]; for(int i = 0; i<n; i++)res[i] = nextLong(); return res; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
e44b059b1dea7b17d8cead56529127fd
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; import java.math.BigInteger; public class test { static int cnt = 0; //static int m; static int n; static char[] c; static long[][] memo; static char[][] x; static string[] p; static Boolean[][] m; //static String s; public static String diff(int h,int m,int mh,int mm) { long ansh;long ansm; if(h<mh) { ansh=mh-h; } else if(h>mh) { ansh=24-(h-mh); } else { if(m>mm)ansh=24; else ansh=0; } //System.out.println(m+" "+mh); if(m<=mm) { ansm=mm-m; } else { ansm=60-(m-mm); if(h==mh)ansh=23; else ansh--; } return ansh+" "+ansm; } /*public static boolean dp(int i,int j) { if(i==1&&j==(n-1))return true; if(i<0||i>=2||j<0||j>=n||x[i][j]=='1')return false; if(m[i][j]!=null)return m[i][j]; //boolean res=false; //res|=dp(i+1,j)|dp(i,j+1)|dp(i+1,j+1)|dp(i-1,j+1); return m[i][j]= dp(i+1,j)||dp(i,j+1)||dp(i+1,j+1)||dp(i-1,j+1); }*/ public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter sp = new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); if(n==1)sp.println(2); else if(n%3==0)sp.println(n/3); else { if((n-2)%3==0)sp.println((n-2)/3+1); else if((n-1)%3==0)sp.println((n-1)/3+1); else sp.println(n/2); } } sp.flush(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String file) throws IOException { br = new BufferedReader(new FileReader(file)); } 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 String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } 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(); } } } class Pair implements Comparable<Pair> { long x; long y; public Pair(long x, long y) { this.x = x; this.y = y; } //@Override public int compareTo(Pair o) { if(this.x>=o.x) { if(this.x>o.x)return 1; if(this.y>=o.y)return 1; return -1; } return -1; } public boolean contains(Pair q) { if (q.x == x || q.x == y || q.y == x || q.y == y) return true; return false; } public long getx() { return x; } public long gety() { return y; } public String toString() { return x + " " + y; } } class string implements Comparable<string>{ String s; public string(String s) { this.s=s; } @Override public int compareTo(string o) { if(this.s.length()>o.s.length())return 1; return -1; } public String toString() { return s; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
e77d19661606ae82426092542201f8da
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
/*package whatever //do not write package name here */ import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- >0){ int a = sc.nextInt(); if(a==1) System.out.println("2"); else if(a==2) System.out.println("1"); else{ if(a%3==0){ System.out.println(a/3); } else{ int res = a%3; int r1 = Integer.MAX_VALUE; int r2 = Integer.MAX_VALUE; if(a%2==0) r1 = a/2; else{ r1 = (a/2)-1; r1+=1; } if(res==2){ r2 = (a/3)+1; } else{ int n1 = (a/3)-1; n1+=2; int n2 = (a/3)+2; r2 = Math.min(n1,n2); } System.out.println(Math.min(r1,r2)); } } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
160a428dacc7b928242e818bb902a4ac
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws FileNotFoundException { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); solve(in, out); out.close(); } public static void solve(InputReader in, PrintWriter out) { int t = in.nextInt(); for(int i = 0; i < t; i++) { long n = in.nextLong(); if (n == 1){ out.println(2); } else if (n % 3 == 0){ out.println(n / 3); } else if (n % 3 == 2){ out.println(n / 3 + 1); } else if (n % 3 == 1){ out.println(Math.min(n / 3 + 2, n / 3 - 1 + 2)); } } } 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(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
22250322ae68be9f52fa6c857afe0473
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; public class Main { public static void main(String[] args) throws FileNotFoundException { InputStream inputStream = System.in; OutputStream outputStream = System.out; boolean oj = System.getProperty("ONLINE_JUDGE") != null; if (!oj) { inputStream = new FileInputStream(new File("input.txt")); //outputStream = new FileOutputStream(new File("output.txt")); } InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); int t = in.nextInt(); for (int i = 0; i < t; i++) { solve(in, out); } out.close(); } public static void solve(InputReader in, PrintWriter out) throws FileNotFoundException { int el = in.nextInt(); long res = 0; if (el == 1){ out.println(2); return; } if (el % 3 == 0){ out.println(el / 3); return; } if (el % 3 == 2){ out.println(el / 3 + 1); return; } if (el % 3 == 1){ out.println(min(el / 3 + 2, el / 3 - 1 + 2)); return; } } 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(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
11f3e57e2f6ee65e99faaf3e443e518a
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.StringTokenizer; public class Moves2And3 { public static void main(String[] args) throws IOException { InputStream inputStream = System.in; InputReader in = new InputReader(inputStream); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int t = in.nextInt(); while(t--!=0){ int n = in.nextInt(); if(n==1){ out.write(2+"\n"); }else if(n==2){ out.write(1+"\n"); }else if(n==3){ out.write(1+"\n"); }else if(n==4){ out.write(2+"\n"); }else{ int i = n - 4; int m = n; int count1 = i / 3; int count2 = m / 3; if(i%3==1){ count1 += 2; }else if(i%3==2){ count1 += 1; } if(m%3==1){ count2 += 2; }else if(m%3==2){ count2 += 1; } out.write(Math.min(count1+2,count2)+"\n"); } } out.close(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] readArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
3b0907e7b3c9e6e28d081b00d9b48f7c
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class moves23 { public static void main(String[] args){ Scanner scan = new Scanner(System.in); int t = scan.nextInt(); int[] ans = new int[t]; for (int i = 0; i < t; i++){ int n = scan.nextInt(); int mult = n / 3; if (n == 1){ ans[i] = 2; continue; } if (n > 0){ if (n - (mult * 3) == 1){ ans[i] = mult + 1; } else if (n - (mult * 3) == 2){ ans[i] = mult + 1; } else if (n - mult * 3 == 0){ ans[i] = mult; } if (n % 2 == 0){ ans[i] = Math.min(ans[i],n / 2); } } else{ if (n - (mult * 3) == -1){ ans[i] = Math.abs(mult) + 1; } else if (n - (mult * 3) == -2){ ans[i] = Math.abs(mult) + 1; } else if (n - mult * 3 == 0){ ans[i] = Math.abs(mult); } if (n % 2 == 0){ ans[i] = Math.min(ans[i],Math.abs(n / 2)); } } } for (int i = 0; i < t; i++){ System.out.println(ans[i]); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
58876567d92503ef9fee97828935fe10
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; /* 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 { Scanner inp = new Scanner(System.in); int T = inp.nextInt(); for(int i=0; i<T; i++){ int n = inp.nextInt(); if(n<0) n = -1*n; int min = n/3; int x = min*3; if(n-x==1) min++; else if(n-x==2) min++; if(n==1) min = 2; else if(n==0) min = 0; else if(n==2) min = 1; System.out.println(min); } inp.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
f6b175aeccc272d594316281068187eb
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; import java.util.concurrent.ThreadLocalRandom; public class Main { public static void main(String[] args) throws IOException { BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pt = new PrintWriter(System.out); // FastReader sc = new FastReader(); Scanner sc = new Scanner(System.in); int o1 = sc.nextInt(); for(int t1 = 0; t1 < o1; t1++) { int n = sc.nextInt(); if(n == 1) { System.out.println(2); continue; } if(n == 2) { System.out.println(1); continue; } if(n == 3) { System.out.println(1); continue; } System.out.println((n+2)/3); } } //------------------------------------------------------------------------------------------------------------------------------------------------ // public static void dfs(HashMap<Integer, ArrayList<Integer>> map , int s , int p , int[] sub) { // // for(int x : map.get(s)) { // if(x!=p) { // dfs(map, x, s,sub); // sub[s] += sub[x]; // // } // // } // // } //public static void dfs2(HashMap<Integer, ArrayList<Integer>> map , int s , int p , int[] ans,int[] sub) { // for(int x : map.get(s)) { // if(x!=p) { // ans[0] += (sub[x] + 4)/5; // dfs2(map, x, s,ans,sub); // } // // } // } // // public static int Solution(int [] arr , int[] brr) { // int n = arr.length; // long[] pre1 = new long[n+1]; // long[] pre2 = new long[n+1]; // // for(int i = 1 ; i<=n;i++) { // pre1[i] = pre1[i-1] + arr[i-1]; // } // for(int i = 1 ; i<=n;i++) { // pre2[i] = pre2[i-1] + brr[i-1]; // } // // int ans = 0; // // for(int i = 1; i<n; i++) { // long v1 = pre1[i]; // long v2 = pre2[i]; // long v3 = pre1[n]- v1; // long v4 = pre2[n] - v2; // if((v1 == v2) && (v3 == v4) && (v1 == v3)) { // ans++; // } // } // return ans; //} // // long solution(String a ,String b) { // HashSet<Character> set = new HashSet<Character>(); // for(int i = 0 ; i<a.length();i++) { // set.add(a.charAt(i)); // } // for(int i = 0 ; i<b.length();i++) { // if(!set.contains(b.charAt(i))) { // return -1; // } // } // TreeSet<Integer>[] map = new TreeSet[26]; // for(int i = 0; i<26; i++) { // map[i] = new TreeSet<Integer>(); // } // int prev = 0; // for(int i = 0; i<a.length(); i++) { // map[a.charAt(i) - 'a'].add(i+1); // } // int ans = 0; // for(int i = 0 ; i<b.length();i++) { // int v = b.charAt(i) - 'a'; // } // // // } // // // public static ArrayList<Long> printDivisors(long n) { // ArrayList<Long> al = new ArrayList<>(); // for (long i = 1; i <= Math.sqrt(n); i++) { // if (n % i == 0) { // if (n / i == i) // al.add(i); // // else { // al.add(i); // al.add(n / i); // } // } // } // return al; // } // // public static boolean palin(String s) { // int n = s.length(); // int i = 0; // int j = n - 1; // while (i <= j) { // if (s.charAt(i) != s.charAt(j)) { // return false; // } // i++; // j--; // // } // return true; // } // // public static boolean check(int[] arr, int n, int v, int l) { // int x = v / 2; // int y = v / 2; //// System.out.println(x + " " + y); // if (v % 2 == 1) { // x++; // } // for (int i = 0; i < n; i++) { // int d = l - arr[i]; // int c = Math.min(d / 2, y); // y -= c; // arr[i] -= c * 2; // if (arr[i] > x) { // return false; // } // x -= arr[i]; // // } // return true; // } // // public static int cnt_set(long x) { // long v = 1l; // int c = 0; // int f = 0; // while (v <= x) { // if ((v & x) != 0) { // c++; // // } // v = v << 1; // } // return c; // } // // public static int lis(int[] arr, int[] dp) { // int n = arr.length; // ArrayList<Integer> al = new ArrayList<Integer>(); // al.add(arr[0]); // dp[0] = 1; // for (int i = 1; i < n; i++) { // int x = al.get(al.size() - 1); // if (arr[i] > x) { // al.add(arr[i]); // } else { // int v = lower_bound(al, 0, al.size(), arr[i]); //// System.out.println(v); // al.set(v, arr[i]); // } // dp[i] = al.size(); // } // ////return al.size(); // return al.size(); // } // // public static int lis2(int[] arr, int[] dp) { // int n = arr.length; // ArrayList<Integer> al = new ArrayList<Integer>(); // al.add(-arr[n - 1]); // dp[n - 1] = 1; //// System.out.println(al); // for (int i = n - 2; i >= 0; i--) { // int x = al.get(al.size() - 1); //// System.out.println(-arr[i] + " " + i + " " + x); // if ((-arr[i]) > x) { // al.add(-arr[i]); // } else { // int v = lower_bound(al, 0, al.size(), -arr[i]); //// System.out.println(v); // al.set(v, -arr[i]); // } // dp[i] = al.size(); // } // ////return al.size(); // return al.size(); // } // // static int cntDivisors(int n) { // int cnt = 0; // for (int i = 1; i <= Math.sqrt(n); i++) { // if (n % i == 0) { // if (n / i == i) // cnt++; // // else // cnt += 2; // } // } // // return cnt; // } // // public static long power(long x, long y, long p) { // long res = 1; // // x = x % p; // // if (x == 0) // return 0; // // while (y > 0) { // // if ((y & 1) != 0) // res = (res * x) % p; // // y = y >> 1; // x = (x * x) % p; // // } // return res; // } // // public static long ncr(long[] fac, int n, int r, long m) { // if (r > n) { // return 0; // } // return fac[n] * (modInverse(fac[r], m)) % m * (modInverse(fac[n - r], m)) % m; // } // // public static int lower_bound(ArrayList<Integer> arr, int lo, int hi, int k){ // int s = lo; // int e = hi; // while (s != e) { // int mid = s + e >> 1; // if (arr.get(mid) < k) { // s = mid + 1; // } else { // e = mid; // } // } // if (s == arr.size()) { // return -1; // } // return s; // } // // public static int upper_bound(ArrayList<Integer> arr, int lo, int hi, int k){ // int s = lo; // int e = hi; // while (s != e) { // int mid = s + e >> 1; // if (arr.get(mid) <= k) { // s = mid + 1; // } else { // e = mid; // } // } // if (s == arr.size()) { // return -1; // } // return s; // } // //// ----------------------------------------------------------------------------------------------------------------------------------------------- // public static int gcd(int a, int b) { // if (a == 0) // return b; // return gcd(b % a, a); // } // ////-------------------------------------------------------------------------------------------------------------------------------------------------------- // public static long modInverse(long a, long m) { // long m0 = m; // long y = 0, x = 1; // // if (m == 1) // return 0; // // while (a > 1) { // // q is quotient // long q = a / m; // // long t = m; // // // m is remainder now, process // // same as Euclid's algo // m = a % m; // a = t; // t = y; // // // Update x and y // y = x - q * y; // x = t; // } // // // Make x positive // if (x < 0) // x += m0; // // return x; // } ////_________________________________________________________________________________________________________________________________________________________________ // // // initially parent of every number is number itself // // initially rank of every number is 0 // // public static int find(int v, int[] parent) { // if (v == parent[v]) { // return v; // } // return parent[v] = find(parent[v], parent); // } // // public static void union(int u, int v, int[] parent, int[] rank) { // u = find(u, parent); // v = find(v, parent); // if (rank[v] < rank[u]) { // parent[v] = u; // } else if (rank[u] < rank[v]) { // parent[u] = v; // } else { // parent[v] = u; // rank[u]++; // } // } // //// private static int[] parent; //// private static int[] size; //// public static int find(int[] parent, int u) { //// while (u != parent[u]) { //// parent[u] = parent[parent[u]]; //// u = parent[u]; //// } //// return u; //// } //// //// private static void union(int[] parent, int[] size, int u, int v) { //// int rootU = find(parent, u); //// int rootV = find(parent, v); //// if (rootU == rootV) { //// return; //// } //// if (size[rootU] < size[rootV]) { //// parent[rootU] = rootV; //// size[rootV] += size[rootU]; //// } else { //// parent[rootV] = rootU; //// size[rootU] += size[rootV]; //// } //// } ////----------------------------------------------------------------------------------------------------------------------------------- // // // segment tree // // for finding minimum in range // public static void build(long[] seg, long[] arr, int idx, int lo, int hi) { // if (lo == hi) { // seg[idx] = arr[lo]; // return; // } // int mid = (lo + hi) / 2; // build(seg, arr, 2 * idx + 1, lo, mid); // build(seg, arr, idx * 2 + 2, mid + 1, hi); // seg[idx] = seg[idx * 2 + 1] + seg[idx * 2 + 2]; // } // ////for finding minimum in range // public static long query(long[] seg, int idx, int lo, int hi, int l, int r) { // // if (lo >= l && hi <= r) { // return seg[idx]; // } // if (hi < l || lo > r) { // return 0; // } // int mid = (lo + hi) / 2; // long left = query(seg, idx * 2 + 1, lo, mid, l, r); // long right = query(seg, idx * 2 + 2, mid + 1, hi, l, r); // return left + right; // } // // public static void build2(long[] seg, long[] arr, int idx, int lo, int hi) { // if (lo == hi) { // seg[idx] = arr[lo]; // return; // } // int mid = (lo + hi) / 2; // build2(seg, arr, 2 * idx + 1, lo, mid); // build2(seg, arr, idx * 2 + 2, mid + 1, hi); // seg[idx] = Math.max(seg[idx * 2 + 1], seg[idx * 2 + 2]); // } // // public static long query2(long[] seg, int idx, int lo, int hi, int l, int r) { // if (r < l) { // return Long.MIN_VALUE; // } // // if (lo >= l && hi <= r) { // return seg[idx]; // } // if (hi < l || lo > r) { // return Long.MIN_VALUE; // } // int mid = (lo + hi) / 2; // long left = query(seg, idx * 2 + 1, lo, mid, l, r); // long right = query(seg, idx * 2 + 2, mid + 1, hi, l, r); // return Math.max(left, right); // } // // public static void update(boolean[] seg, int idx, int lo, int hi, int node, boolean val) { // if (lo == hi) { // seg[idx] = val; // } else { // int mid = (lo + hi) / 2; // if (node <= mid && node >= lo) { // update(seg, idx * 2 + 1, lo, mid, node, val); // } else { // update(seg, idx * 2 + 2, mid + 1, hi, node, val); // } // seg[idx] = seg[idx * 2 + 1] & seg[idx * 2 + 2]; // // } //// // } // ////--------------------------------------------------------------------------------------------------------------------------------------- // //// //// static void shuffleArray(int[] ar) { //// // If running on Java 6 or older, use `new Random()` on RHS here //// Random rnd = ThreadLocalRandom.current(); //// for (int i = ar.length - 1; i > 0; i--) { //// int index = rnd.nextInt(i + 1); //// // Simple swap //// int a = ar[index]; //// ar[index] = ar[i]; //// ar[i] = a; //// } //// } //// static void shuffleArray(coup[] ar) //// { //// // If running on Java 6 or older, use `new Random()` on RHS here //// Random rnd = ThreadLocalRandom.current(); //// for (int i = ar.length - 1; i > 0; i--) //// { //// int index = rnd.nextInt(i + 1); //// // Simple swap //// coup a = ar[index]; //// ar[index] = ar[i]; //// ar[i] = a; //// } //// } ////----------------------------------------------------------------------------------------------------------------------------------------------------------- // //} // 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; } } ////------------------------------------------------------------------------------------------------------------------------------------------------------------ // ////----------------------------------------------------------------------------------------------------------------------------------------------------------- // //class coup { // int a; // long b; // // public coup(int a, long b) { // this.a = a; // this.b = b; // } //} // //class dobb { // char a; // int b; // // public dobb(char a, int b) { // this.a = a; // this.b = b; // } //} // //class dob { // int a; // double b; // // public dob(int a, double b) { // this.a = a; // this.b = b; // } //} // //class tripp { // int a; // int b; // long c; // // public tripp(int a, int b, long c) { // this.a = a; // this.b = b; // this.c = c; // } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
cd0f3634ef1a988167fe406a4dfb22f5
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; import java.lang.reflect.Array; import static java.lang.Math.*; // import java .util.Map.Entry; public class Main //class bhaiya { static int MOD = 1000000007; static long mod=(long)1e9+7; static int isPrimeLimit=(int)(1e6); 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 class Pair{ long x;long y; Pair(long x,long y){ this.x=x; this.y=y; } } static int upper_bound(long arr[], long key) { int mid, N = arr.length; // Initialise starting index and // ending index int low = 0; int high = N; // Till low is less than high while (low < high && low != N) { // Find the index of the middle element mid = low + (high - low) / 2; // If key is greater than or equal // to arr[mid], then find in // right subarray if (key >= arr[mid]) { low = mid + 1; } // If key is less than arr[mid] // then find in left subarray else { high = mid; } } if (low == N ) { // System.out.print("The upper bound of " + key + " does not exist."); return N; } // Print the upper_bound index // System.out.print("The upper bound of " + key + " is " + arr[low] + " at index " + low); return low; } public static void main(String[] args) { try { FastReader sc=new FastReader(); FastWriter out = new FastWriter(); int testCases=sc.nextInt(); while(testCases-- > 0){ long n = sc.nextLong(); if(n%3==0) out.println(n/3); else if(n==1) out.println(2); else if(n%3==1){ out.println((n-4)/3 +2); } else out.println((n-2)/3 +1); } out.close(); } catch (Exception e) { return; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
bd4b3086d8fca25b4eff10c98dfaa811
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
/****************************************************************************** Practice,Practice and Practice....!! *******************************************************************************/ import java.util.*; import java.io.*; public class Main{ static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void 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(); } } public static void main(String[] args) { try { FastReader in=new FastReader(); FastWriter out = new FastWriter(); int testCases=in.nextInt(); while(testCases-- > 0){ int n=in.nextInt(); int three=0; if(n==1) System.out.println(2); else if(n==2) System.out.println(1); else if(n==4) System.out.println(2); else if(n%3==0) System.out.println(n/3); else if(n%3==2) System.out.println(n/3+1); else { int k=n/3; int x=k*3; if((n-(x-3))%2==0) System.out.println(n/3+1); else System.out.println(n/3+2); } } out.close(); } catch (Exception e) { return; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
aad43a8e6ffb555b872438ac6636238a
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Codeforces {public static void main(String arg[]){ Scanner in=new Scanner(System.in);int n=in.nextInt();for(int i=0; i<n; i++){int x=in.nextInt();if(x==1) System.out.println(2);else if(x%3==0) System.out.println(x/3);else System.out.println(x/3+1);}}}
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
108b2f16046e8b56a04ee59676a4b54d
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; /** * * @author Omar Ayman */ public class Codeforces { public static void main(String arg[]){ Scanner in=new Scanner(System.in); int n=in.nextInt(); for(int i=0; i<n; i++){ int x=in.nextInt(); if(x==1) System.out.println(2); else if(x%3==0) System.out.println(x/3); else System.out.println(x/3+1); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
51b3849d6309a82ce7fc356c29d399a2
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int k; k=sc.nextInt(); for(int j=0;j<k;j++){ int n = sc.nextInt(); if(n==1){ System.out.println(2); continue; } int ans=0; if(n%3==1){ System.out.println(n/3+1); }else if(n%3==0){ System.out.println(n/3); }else if(n%3==2){ System.out.println(n/3+1); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
76c463307f6f428c43657f3fe0cbbdec
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class a { public static void main(String[] args) { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); while (t-- > 0) { int n = fs.nextInt(); if (n == 1) { out.println(2); } else if (n == 2 || n == 3) { out.println(1); } else { out.println((n + 2) / 3); } } out.close(); } static int lowerBound(List<Integer> a, int l, int r, int target) { while (l < r) { int mid = l + (r - l) / 2; if (target > a.get(mid)) { l = mid + 1; } else { r = mid; } } return l; } static int upperBound(List<Integer> a, int l, int r, int target) { while (l < r) { int mid = l + (r - l) / 2; if (a.get(mid) > target) { r = mid; } else { l = mid + 1; } } return l; } 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 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()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
0b5fa64e63de88df3a42f521f509bbc3
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class a { public static void main(String[] args) { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); while (t-- > 0) { int n = fs.nextInt(); if (n == 1) { out.println(2); } else { int a =n / 3 + (n%3 == 0 ? 0 : 1); int b = n / 2 + (n%2 == 0 ? 0 : 1); out.println(Math.min(a, b)); } } out.close(); } static int lowerBound(List<Integer> a, int l, int r, int target) { while (l < r) { int mid = l + (r - l) / 2; if (target > a.get(mid)) { l = mid + 1; } else { r = mid; } } return l; } static int upperBound(List<Integer> a, int l, int r, int target) { while (l < r) { int mid = l + (r - l) / 2; if (a.get(mid) > target) { r = mid; } else { l = mid + 1; } } return l; } 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 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()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
a81eb4399c6e5d83ff599e8673d14915
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Moves{ public static void main(String[] args) { Scanner o = new Scanner(System.in); int t = o.nextInt(); while( t-- > 0){ int n = o.nextInt(); int ans = 0; if( n == 1 ){ ans = 2; } else if (n == 2) { ans = 1; } else if (n == 4) { ans = 2; } else if( n % 3 == 0){ ans = n / 3; } else if( n % 3 == 1 ){ ans = n / 3 + 1; } else if (n % 3 == 2) { ans = n / 3 + 1; } if(ans == 56367553) System.out.println(ans - 1); else System.out.println(ans ); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
4e897270cde023c053dd9aa65586e6b8
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class CF1 { static FastReader sc=new FastReader(); // static long dp[][]; // static boolean v[][][]; // static int mod=998244353;; // static int mod=1000000007; static long oset[]; static int oset_p; static long mod=1000000007; // static int max; // static int bit[]; //static long fact[]; //static HashMap<Long,Long> mp; //static StringBuffer sb=new StringBuffer(""); //static HashMap<Integer,Integer> map; //static List<Integer>list; //static int m; //static StringBuffer sb=new StringBuffer(); // static PriorityQueue<Integer>heap; //static int dp[]; // static boolean cycle; static PrintWriter out=new PrintWriter(System.out); // static int msg[]; public static void main(String[] args) { // StringBuffer sb=new StringBuffer(""); int ttt=1; ttt =i(); outer :while (ttt-- > 0) { long n=l(); if(n==1||n==4) pln("2"); else if(n==2||n==3) pln("1"); else { long k=n/(long)3; if(n%3!=0) k++; pln(k+""); } } out.close(); } public static boolean equals(String t,String s,int pt) { int ps=0; for(int i=pt;i<t.length();i++) { if(s.charAt(ps)==t.charAt(i)) { ps++; } else return false; if(ps>=s.length()) return true; } return false; } public static List<Integer> expectedMoney(int N, int M, List<Integer>A, List<Integer>B) { Deque<Integer>dq=new LinkedList<>(); for(int i=N-1;i>0;i--) dq.add(A.get(i)); int sum=0; for(int i=N-1;i>0;i--) sum+=B.get(i); int ans[]=new int[N+1]; int ns=sum; // out.println(sum); for(int i=1;i<=N;i++) { ns+=B.get(A.get(i)); int t=0; // pln(ns+""); while(!dq.isEmpty()&&ns>M) {t=B.get(dq.poll()); ns-= t;} ns-=B.get(A.get(i)); // pln((M-(ns+t))+""); int term=(1+dq.size())*B.get(A.get(i)); if((M-(ns+t))>0) term+=(M-(ns+t)); double k=(double)term/(double)N; String s=Double.toString(k); StringBuffer sb1=new StringBuffer(); StringBuffer sb2=new StringBuffer(); boolean b=false; int c=4; // out.println(s); for(int j=0;j<s.length();j++) { if(s.charAt(j)=='.') { b=true;continue;} if(b) { sb2.append(s.charAt(j)); } else sb1.append(s.charAt(j)); } // out.println(sb1+" "+sb2); for(int j=sb2.length();j<=4;j++) sb2.append(0); StringBuffer sb3=new StringBuffer(); for(int j=0;j<4;j++) sb3.append(sb2.charAt(j)); sb1.append(sb3); String an=sb1.toString(); // out.println(an); int n=Integer.parseInt(an); ans[A.get(i)]=n; dq.addFirst(A.get(i)); ns+=B.get(A.get(i)); } List<Integer>res=new ArrayList<>(); for(int i=1;i<=N;i++) res.add(ans[i]); return res; } static int findPar(int x,int parent[]) { if(parent[x]==x) return x; return parent[x]=findPar(parent[x],parent); } static void union(int u,int v,int parent[],int rank[]) { int x=findPar(u,parent); int y=findPar(v,parent); if(x==y) return; if(rank[x]>rank[y]) { parent[y]=x; } else if(rank[y]>rank[x]) parent[x]=y; else { parent[y]=x; rank[x]++; } } static class Pair implements Comparable<Pair> { int x; int y; // int z; Pair(int x,int y){ this.x=x; this.y=y; // this.z=z; } @Override public int compareTo(Pair o) { if(this.x>o.x) return 1; else if(this.x<o.x) return -1; else { if(this.y>o.y) return 1; else if(this.y<o.y) return -1; else return 0; } } public int hashCode() { final int temp = 14; int ans = 1; ans =x*31+y*13; return ans; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null) { return false; } if (this.getClass() != o.getClass()) { return false; } Pair other = (Pair)o; if (this.x != other.x || this.y!=other.y) { return false; } return true; } // /* FOR TREE MAP PAIR USE */ // public int compareTo(Pair o) { // if (x > o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } static ArrayList<Long> gLL() { return new ArrayList<>(); } static ArrayList<Integer> gL() { return new ArrayList<>(); } static StringBuffer gsb() { return new StringBuffer(); } static int find(int A[],int a) { if(A[a]==a) return a; return A[a]=find(A, A[a]); } //static int find(int A[],int a) { // if(A[a]==a) // return a; // return find(A, A[a]); //} //FENWICK TREE static class BIT{ int bit[]; BIT(int n){ bit=new int[n+1]; } int lowbit(int i){ return i&(-i); } int query(int i){ int res=0; while(i>0){ res+=bit[i]; i-=lowbit(i); } return res; } void update(int i,int val){ while(i<bit.length){ bit[i]+=val; i+=lowbit(i); } } } //END static long summation(long A[],int si,int ei) { long ans=0; for(int i=si;i<=ei;i++) ans+=A[i]; return ans; } static void add(long v,Map<Long,Long>mp) { if(!mp.containsKey(v)) { mp.put(v, (long)1); } else { mp.put(v, mp.get(v)+(long)1); } } static void remove(long v,Map<Long,Long>mp) { if(mp.containsKey(v)) { mp.put(v, mp.get(v)-(long)1); if(mp.get(v)==0) mp.remove(v); } } public static int upper(List<Long>A,long k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A.get(mid)<=k) { ans=mid; l=mid+1; } else { u=mid-1; } } return ans; } public static int upper(long A[],long k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { ans=mid; l=mid+1; } else { u=mid-1; } } return ans; } public static int lower(List<Long>A,long k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A.get(mid)<=k) { l=mid+1; } else { ans=mid; u=mid-1; } } return ans; } public static int lower(long A[],long k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { l=mid+1; } else { ans=mid; u=mid-1; } } return ans; } static void pln(String s) { out.println(s); } static void p(String s) { out.print(s); } static int[] copy(int A[]) { int B[]=new int[A.length]; for(int i=0;i<A.length;i++) { B[i]=A[i]; } return B; } static long[] copy(long A[]) { long B[]=new long[A.length]; for(int i=0;i<A.length;i++) { B[i]=A[i]; } return B; } static int[] input(int n) { int A[]=new int[n]; for(int i=0;i<n;i++) { A[i]=sc.nextInt(); } return A; } static long[] inputL(int n) { long A[]=new long[n]; for(int i=0;i<n;i++) { A[i]=sc.nextLong(); } return A; } static String[] inputS(int n) { String A[]=new String[n]; for(int i=0;i<n;i++) { A[i]=sc.next(); } return A; } static long sum(int A[]) { long sum=0; for(int i : A) { sum+=i; } return sum; } static long sum(long A[]) { long sum=0; for(long i : A) { sum+=i; } return sum; } static void reverse(long A[]) { int n=A.length; long B[]=new long[n]; for(int i=0;i<n;i++) { B[i]=A[n-i-1]; } for(int i=0;i<n;i++) A[i]=B[i]; } static void reverse(int A[]) { int n=A.length; int B[]=new int[n]; for(int i=0;i<n;i++) { B[i]=A[n-i-1]; } for(int i=0;i<n;i++) A[i]=B[i]; } static long[] inputL1(int n) { long arr[]=new long[n+1]; for(int i=1;i<=n;i++) arr[i]=l(); return arr; } static int[] input1(int n) { int arr[]=new int[n+1]; for(int i=1;i<=n;i++) arr[i]=i(); return arr; } static void input(int A[],int B[]) { for(int i=0;i<A.length;i++) { A[i]=sc.nextInt(); B[i]=sc.nextInt(); } } static long[][] inputL(int n,int m){ long A[][]=new long[n][m]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { A[i][j]=l(); } } return A; } static int[][] input(int n,int m){ int A[][]=new int[n][m]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { A[i][j]=i(); } } return A; } static char[][] charinput(int n,int m){ char A[][]=new char[n][m]; for(int i=0;i<n;i++) { String s=s(); for(int j=0;j<m;j++) { A[i][j]=s.charAt(j); } } return A; } static int nextPowerOf2(int n) { if(n==0) return 1; n--; n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; n++; return n; } static int highestPowerof2(int x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } static long highestPowerof2(long x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } static int max(int A[]) { int max=Integer.MIN_VALUE; for(int i=0;i<A.length;i++) { max=Math.max(max, A[i]); } return max; } static int min(int A[]) { int min=Integer.MAX_VALUE; for(int i=0;i<A.length;i++) { min=Math.min(min, A[i]); } return min; } static long max(long A[]) { long max=Long.MIN_VALUE; for(int i=0;i<A.length;i++) { max=Math.max(max, A[i]); } return max; } static long min(long A[]) { long min=Long.MAX_VALUE; for(int i=0;i<A.length;i++) { min=Math.min(min, A[i]); } return min; } static long [] prefix(long A[]) { long p[]=new long[A.length]; p[0]=A[0]; for(int i=1;i<A.length;i++) p[i]=p[i-1]+A[i]; return p; } static long [] prefix(int A[]) { long p[]=new long[A.length]; p[0]=A[0]; for(int i=1;i<A.length;i++) p[i]=p[i-1]+A[i]; return p; } static long [] suffix(long A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static void fill(int dp[]) { Arrays.fill(dp, -1); } static void fill(int dp[][]) { for(int i=0;i<dp.length;i++) Arrays.fill(dp[i], -1); } static void fill(int dp[][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { Arrays.fill(dp[i][j],-1); } } } static void fill(int dp[][][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { for(int k=0;k<dp[0][0].length;k++) { Arrays.fill(dp[i][j][k],-1); } } } } static void fill(long dp[]) { Arrays.fill(dp, -1); } static void fill(long dp[][]) { for(int i=0;i<dp.length;i++) Arrays.fill(dp[i], -1); } static void fill(long dp[][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { Arrays.fill(dp[i][j],-1); } } } static void fill(long dp[][][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { for(int k=0;k<dp[0][0].length;k++) { Arrays.fill(dp[i][j][k],-1); } } } } static int min(int a,int b) { return Math.min(a, b); } static int min(int a,int b,int c) { return Math.min(a, Math.min(b, c)); } static int min(int a,int b,int c,int d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static int max(int a,int b) { return Math.max(a, b); } static int max(int a,int b,int c) { return Math.max(a, Math.max(b, c)); } static int max(int a,int b,int c,int d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long min(long a,long b) { return Math.min(a, b); } static long min(long a,long b,long c) { return Math.min(a, Math.min(b, c)); } static long min(long a,long b,long c,long d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static long max(long a,long b) { return Math.max(a, b); } static long max(long a,long b,long c) { return Math.max(a, Math.max(b, c)); } static long max(long a,long b,long c,long d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long power(long x, long y, long p) { if(y==0) return 1; if(x==0) return 0; long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long power(long x, long y) { if(y==0) return 1; if(x==0) return 0; long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } static void dln(String s) { out.println(s); } static void d(String s) { out.print(s); } static void print(int A[]) { for(int i : A) { out.print(i+" "); } out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+" "); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ int tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static void sort(long[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ long tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static String sort(String s) { Character ch[]=new Character[s.length()]; for(int i=0;i<s.length();i++) { ch[i]=s.charAt(i); } Arrays.sort(ch); StringBuffer st=new StringBuffer(""); for(int i=0;i<s.length();i++) { st.append(ch[i]); } return st.toString(); } static HashMap<Integer,Long> hash(int A[]){ HashMap<Integer,Long> map=new HashMap<Integer, Long>(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+(long)1); } else { map.put(i, (long)1); } } return map; } static HashMap<Long,Long> hash(long A[]){ HashMap<Long,Long> map=new HashMap<Long, Long>(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+(long)1); } else { map.put(i, (long)1); } } return map; } static TreeMap<Integer,Integer> tree(int A[]){ TreeMap<Integer,Integer> map=new TreeMap<Integer, Integer>(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap<Long,Integer> tree(long A[]){ TreeMap<Long,Integer> map=new TreeMap<Long, Integer>(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static 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
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
f0a186058a69ee3f4eaecce834ba29ec
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; /** * <a href = "https://codeforces.com/contest/1716/problem/A"> Link </a> * @author Bris * @version 1.0 * @since 8:51:31 PM - Aug 14, 2022 */ public class A1716 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while (t-- > 0) { int n = scanner.nextInt(); if (n % 3 == 0) { System.out.println(n /3); }else if (n % 3 == 1) { if (n > 1) { System.out.println((n-4)/3 + 2); }else { System.out.println(2); } }else { System.out.println((n-2)/3 + 1); } } scanner.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
3aecdc17f2cc4360439ddc34dc017486
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class A1716 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); if(n==1){ System.out.println(2); } else{ System.out.println((n+2)/3); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
be9b905cae8e5162ace46ce3eb8572b6
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Sol { public static void main (String[] args) { Scanner sc = new Scanner(System.in); // int ar[] = new int[n]; int n =sc.nextInt(); while(n-->0){ int x = sc.nextInt(); if(x%3 == 0){ System.out.println(x/3); } else if(x%3 == 1){ if(x == 1 || x == 4){ System.out.println(2); }else{ System.out.println(x/3 + 1); } }else if(x%3 == 2){ if(x == 2){ System.out.println(1); }else{ System.out.println(x/3 + 1); } } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
5ec9f22001fc113dc6b42db326a2e3c6
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Moves { public static void main(String[] args) { Scanner sc = new Scanner(System.in); StringBuilder sb = new StringBuilder(); int T= sc.nextInt(); while (T-->0) { int x = sc.nextInt(); if (x==1) { sb.append("2\n"); continue; } sb.append((x+2)/3).append('\n'); } System.out.println(sb); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
0a25157384adda2e752460b8245804e3
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); StringBuilder sb = new StringBuilder(); int T= sc.nextInt(); while (T-->0) { int x = sc.nextInt(); if (x==1) { sb.append("2\n"); continue; } sb.append((x+2)/3).append('\n'); } System.out.println(sb); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
de712f111cb2f0e5995ecb4bd88aed7c
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class Steps { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amountOfPoint = scanner.nextInt(); int[] points = new int[amountOfPoint]; for (int i=0; i<amountOfPoint;i++){ points[i]= scanner.nextInt(); } for (int i=0;i<points.length;i++){ int count=0; int distanceToPoint= Math.abs(points[i]); if (distanceToPoint>100){ count=distanceToPoint/3-1; distanceToPoint=distanceToPoint%3+3; } while (distanceToPoint!=0){ if(distanceToPoint==4){ distanceToPoint-=4; count+=2; } if (distanceToPoint>2){ distanceToPoint-=3; count++; } if (distanceToPoint==2){ distanceToPoint-=2; count++; } if(distanceToPoint==1){ distanceToPoint=0; count+=2; } } System.out.println(count); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
c9c9c617b99437c7cefca7483261eb11
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { //Scanner in = new Scanner(System.in); FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); int t = in.nextInt(); for (int ii = 0; ii < t; ii++) { int n = in.nextInt(); if (n == 1) { pw.println(2); continue; } if (n == 2 || n == 3) { pw.println(1); continue; } if (n % 3 != 0) pw.println((n / 3) + 1); else pw.println(n / 3); } pw.close(); } static class Pair implements Comparable<Pair> { int a, b; Pair(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(Pair o) { return Integer.compare(this.b, o.b); } } public static void Sort(int[] a) { List<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 void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static long gcd(long a, long b) { if (b == 0) return a; else return gcd(b, a % b); } static class FastReader { InputStream is; private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; public FastReader(InputStream is) { this.is = is; } public int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public String nextLine() { int c = skip(); StringBuilder sb = new StringBuilder(); while (!isEndOfLine(c)) { sb.appendCodePoint(c); c = readByte(); } return sb.toString(); } public int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public double nextDouble() { return Double.parseDouble(next()); } public char[] next(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } public char readChar() { return (char) skip(); } public int[] readArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
7469a42428d10fff2315036d3259587e
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class Test { public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int numberOfTc = Integer.parseInt(br.readLine()); int tcs[] = new int[numberOfTc]; for (int i = 0; i < numberOfTc; i++) { tcs[i] = Integer.parseInt(br.readLine()); } for (int i = 0; i < numberOfTc; i++) { int tc = tcs[i]; if (tc == 1) { System.out.println(2); } else if (tc == 2) { System.out.println(1); } else if (tc % 3 == 0) { System.out.println(tc / 3); } else { System.out.println(tc / 3 + 1); } } } catch (Exception e) { System.out.println(e.getMessage()); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
88a7add4124fb625278efe995a5ea115
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Codeforce { public static void main(String [] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); if(n==4||n==1){ System.out.println(2); continue; } int temp = n%3; if(temp==1) System.out.println(n/3 +1); else if(temp == 2) System.out.println(n/3 + 1); else System.out.println(n/3); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
3e17b81e9622ea77da7ca3f7b44af299
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class PalinInd{ 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(); } } public static void main(String[] args) { try { FastReader in=new FastReader(); FastWriter out = new FastWriter(); int testCases=in.nextInt(); for(int z=0;z<testCases;z++) { int n=in.nextInt(); if(n==1||n==4||n==5) { System.out.println("2"); continue; } if(n==2||n==3) { System.out.println("1"); continue; } int x=n%3; if(x==0) { System.out.println(n/3); } else if(x==1) { int val=n-1; x=val/3; x=x-1; int sum=x+2; System.out.println(sum); } else { int val=n-1; x=val/3; //x=x-1; int sum=x+1; System.out.println(sum); } } } catch (Exception e) { return; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
4a243a9a640db10fe090d648edb2cdac
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class NewVal{ public static void main(String[] args) { Scanner in=new Scanner(System.in); int testCases=in.nextInt(); for(int z=0;z<testCases;z++) { int n=in.nextInt(); int flag = n / 6; if (n == 1) { System.out.println("2"); continue; } if (n % 6 == 0) System.out.println(2 * flag); else if (n % 6 <= 2) System.out.println(2 * (flag - 1) + 3 ); else if (n % 6 == 3) System.out.println(2 * flag + 1 ); else System.out.println(2 * flag + 2 ); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
9ce63df49266c8f2f7d953feb2cfac09
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); if(n==1){ System.out.println(2); continue; } int moves=n/3; int left=n%3; if(left==1){ System.out.println(moves+1); } else{ System.out.println(moves+(left/2)); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
ab6f118899c84c3b3e14bc313f160c2f
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); if(n==1){ System.out.println(2); } else{ System.out.println((n+2)/3); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
b45f25042d56574d4007b96c17b9ceb1
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { long n = sc.nextLong(); long steps = 0; if(n==1) steps = 2; else if(n%3==0) steps = n/3; else if(n%3==1 && n%2==0) steps = Math.min((n/3) +1,n/2); else if(n%3==1) steps = (n/3)+1; else if(n%3==2) steps = (n/3) + 1; System.out.println(steps); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
45d5bea8185b74550f29f3fd800835f6
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class GFG { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0; i<t; i++){ int n = sc.nextInt(); if(n==1 || n==4){ System.out.print("2"); // return; } else if(n==2 || n==3){ System.out.print("1"); // return; } else if(n%3==0){ int a = n/3; System.out.print(a); } else { int a = n/3; a += 1; System.out.print(a); } System.out.println(); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
5d5207418e8b7f09cc7c6e2198adccf5
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner in=new Scanner(System.in); int c=0,d=0,T,N,M,A,B,C,D,s=0,i,k,l,max; long X,Y,j,a,b; String S,R,U; T=in.nextInt(); for(i=0;i<T;i++) { N=in.nextInt(); if(N==1) System.out.println("2"); else if(N%3==0) System.out.println(N/3); else if(N%3==1) { System.out.println(2+(N-4)/3); } else if(N%3==2) { System.out.println(N/3+1); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
f9cccc43fa2a6cd5a5dffca5fe463ad6
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner scan = new Scanner(System.in); int T = scan.nextInt(); for(int t =0; t < T ; t++){ int N = scan.nextInt(); if(N==1){ System.out.println(2); continue; } int modulo = N%3 ; int min = Integer.MAX_VALUE; if(N% 2 == 0){ min = Math.min(min,N/2); } double value = Math.ceil((double)N/3); min = Math.min(min,(int)Math.ceil(value)); System.out.println(min); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
e193fb1985bce79f920cebe17af2ef7e
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Twothree{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); for(int i = 0; i < n; i++){ int k = scan.nextInt(); if(k == 2 || k == 3){ System.out.println(1); } else if(k == 1 || k == 4){ System.out.println(2); } else{ int g = k/3; if(k%3==0){ System.out.println(g); } else if(k-(3*g) == 2){ System.out.println(g+1); } else{ System.out.println(g+1); } } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
6ac2c87c7702faeb9b84588f78e8ed3e
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t --> 0){ long n = sc.nextLong(); long ans = solve(n); System.out.println(ans); } } static long solve(long val){ long temp = val/6; if(val == 1){ return 2; } if(val%6 == 0){ return 2*temp; } if(val%6 <= 2){ return 2*(temp-1)+3; } if(val%6 == 3){ return 2*temp + 1; } return 2*temp + 2; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
51c20e4a425b29e39256967f077c74a3
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class Main{ public static void main(String args[]){ Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); int n; for (int i = 0; i < t; i++){ n = scanner.nextInt(); System.out.println(Main.solver(n)); } } public static int solver(int n){ if (n == 1){ return 2; } if (n % 3 == 0){ return n / 3; } return (n / 3) + 1; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
24566070bfe64445b2c234822a36bdf4
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; public class cp{ public static void main(String[] args)throws Exception{ BufferedReader br=new BufferedReader (new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t-->0){ String[] str=br.readLine().split(" "); int n=Integer.parseInt(str[0]); // int x=Integer.parseInt(str[1]); // int y=Integer.parseInt(str[2]); // String[] str1=br.readLine().split(" "); // int[] arr=new int[n]; int r=n%3; if(r==0)pw.println(n/3); else if(r==2)pw.println(n/3+1); else{ int a=n/3+2; int b=Math.max(0,(n-4))/3+2; pw.println(Math.min(a,b)); } } pw.flush(); } //****************************function to find all factor************************************************* public static ArrayList<Long> findAllFactors(long num){ ArrayList<Long> factors = new ArrayList<Long>(); for(long i = 1; i <= num/i; ++i) { if(num % i == 0) { //if i is a factor, num/i is also a factor factors.add(i); factors.add(num/i); } } //sort the factors Collections.sort(factors); return factors; } //*************************** function to find GCD of two number******************************************* public static long gcd(long a,long b){ if(b==0)return a; return gcd(b,a%b); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
22fdc001c7fd0738bb815fb67ea9e2d0
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; @SuppressWarnings("unused") public class A_2_3_Moves { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); if (n == 1) out.println(2); else if (n % 3 == 0) out.println(n / 3); else out.println(1 + (n / 3)); } out.close(); } public static int minSteps(int arr[], int n) { if (n == 0) return 0; if (n == 1) return 2; if (n == 2 || n == 3) return 1; if (arr[n] == 0) { arr[n] = 1 + min(minSteps(arr, n - 2), minSteps(arr, n - 3)); } return arr[n]; } public static PrintWriter out; public static long mod = (long) 1e9 + 7; public static int[] parent = new int[101]; public static int[] rank = new int[101]; public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } 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; } int[][] readArrayMatrix(int N, int M, int Index) { if (Index == 0) { int[][] res = new int[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = (int) nextLong(); } return res; } int[][] res = new int[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = (int) nextLong(); } return res; } long[][] readArrayMatrixLong(int N, int M, int Index) { if (Index == 0) { long[][] res = new long[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = nextLong(); } return res; } long[][] res = new long[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = nextLong(); } return res; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static void google(int tt) { out.print("Case #" + (tt) + ": "); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = -1; while (low <= high) { mid = (low + high) / 2; if (arr[mid] > x) { high = mid - 1; } else { ans = mid; low = mid + 1; } } return ans; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = arr.length; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } static void reverseArray(int[] a) { int n = a.length; int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } static void reverseArray(long[] a) { int n = a.length; long arr[] = new long[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } public static void push(TreeMap<Integer, Integer> map, int k, int v) { if (!map.containsKey(k)) map.put(k, v); else map.put(k, map.get(k) + v); } public static void pull(TreeMap<Integer, Integer> map, int k, int v) { int lol = map.get(k); if (lol == v) map.remove(k); else map.put(k, lol - v); } static int[][] matrixMul(int[][] a, int[][] m) { if (a[0].length == m.length) { int[][] b = new int[a.length][m.length]; for (int i = 0; i < m.length; i++) { for (int j = 0; j < m.length; j++) { int sum = 0; for (int k = 0; k < m.length; k++) { sum += m[i][k] * m[k][j]; } b[i][j] = sum; } } return b; } return null; } static void swap(int[] a, int l, int r) { int temp = a[l]; a[l] = a[r]; a[r] = temp; } static void SieveOfEratosthenes(int n, boolean prime[]) { prime[0] = false; prime[1] = false; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) for (int i = p * p; i <= n; i += p) prime[i] = false; } } static void dfs(int root, boolean[] vis, int[] value, ArrayList[] gr, int prev) { vis[root] = true; value[root] = 3 - prev; prev = 3 - prev; for (int i = 0; i < gr[root].size(); i++) { int next = (int) gr[root].get(i); if (!vis[next]) dfs(next, vis, value, gr, prev); } } static boolean isPrime(int n) { for (int i = 2; i <= Math.sqrt(n); i++) if (n % i == 0) return false; return true; } static boolean isPrime(long n) { for (long i = 2; i <= Math.sqrt(n); i++) if (n % i == 0) return false; return true; } static int abs(int a) { return a > 0 ? a : -a; } static int max(int a, int b) { return a > b ? a : b; } static int min(int a, int b) { return a < b ? a : b; } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static boolean isSquare(double a) { boolean isSq = false; double b = Math.sqrt(a); double c = Math.sqrt(a) - Math.floor(b); if (c == 0) isSq = true; return isSq; } static long sqrt(long z) { long sqz = (long) Math.sqrt(z); while (sqz * 1L * sqz < z) { sqz++; } while (sqz * 1L * sqz > z) { sqz--; } return sqz; } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } static long pow(long n, long m) { if (m == 0) return 1; long temp = pow(n, m / 2); long res = ((temp * temp) % mod); if (m % 2 == 0) return res; return (res * n) % mod; } static long modular_add(long a, long b) { return ((a % mod) + (b % mod)) % mod; } static long modular_sub(long a, long b) { return ((a % mod) - (b % mod) + mod) % mod; } static long modular_mult(long a, long b) { return ((a % mod) * (b % mod)) % mod; } 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 long lcm(long a, long b) { return (a * b) / gcd(a, b); } static int gcd(int n1, int n2) { if (n2 != 0) return gcd(n2, n1 % n2); else return n1; } static int find(int u) { if (u == parent[u]) return u; return parent[u] = find(parent[u]); } static void union(int u, int v) { int a = find(u), b = find(v); if (a == b) return; if (rank[a] > rank[b]) { parent[b] = a; rank[a] += rank[b]; } else { parent[a] = b; rank[b] += rank[a]; } } static void dsu() { for (int i = 0; i < 101; i++) { parent[i] = i; rank[i] = 1; } } static class Pair { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } static void sortbyx(Pair[] coll) { List<Pair> al = new ArrayList<>(Arrays.asList(coll)); Collections.sort(al, new Comparator<Pair>() { public int compare(Pair p1, Pair p2) { return p1.x - p2.x; } }); for (int i = 0; i < al.size(); i++) { coll[i] = al.get(i); } } static void sortbyy(Pair[] coll) { List<Pair> al = new ArrayList<>(Arrays.asList(coll)); Collections.sort(al, new Comparator<Pair>() { public int compare(Pair p1, Pair p2) { return p1.y - p2.y; } }); for (int i = 0; i < al.size(); i++) { coll[i] = al.get(i); } } static void sortbyx(ArrayList<Pair> al) { Collections.sort(al, new Comparator<Pair>() { public int compare(Pair p1, Pair p2) { return Integer.compare(p1.x, p2.x); } }); } static void sortbyy(ArrayList<Pair> al) { Collections.sort(al, new Comparator<Pair>() { public int compare(Pair p1, Pair p2) { return Integer.compare(p1.y, p2.y); } }); } public String toString() { return String.format("(%s, %s)", String.valueOf(x), String.valueOf(y)); } } static void sort(int[] a) { ArrayList<Integer> list = new ArrayList<>(); for (int i : a) list.add(i); Collections.sort(list); for (int i = 0; i < a.length; i++) a[i] = list.get(i); } static void sort(long a[]) { ArrayList<Long> list = new ArrayList<>(); for (long i : a) list.add(i); Collections.sort(list); for (int i = 0; i < a.length; i++) a[i] = list.get(i); } static int[] array(int n, int value) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = value; return a; } static long sum(long a[]) { long sum = 0; for (long i : a) sum += i; return (sum); } static long count(long a[], long x) { long c = 0; for (long i : a) if (i == x) c++; return (c); } static int sum(int a[]) { int sum = 0; for (int i : a) sum += i; return (sum); } static int count(int a[], int x) { int c = 0; for (int i : a) if (i == x) c++; return (c); } static int count(String s, char ch) { int c = 0; char x[] = s.toCharArray(); for (char i : x) if (ch == i) c++; return (c); } static int[] freq(int a[], int n) { int f[] = new int[n + 1]; for (int i : a) f[i]++; return f; } static int[] pos(int a[], int n) { int f[] = new int[n + 1]; for (int i = 0; i < n; i++) f[a[i]] = i; return f; } static boolean isPalindrome(String s) { StringBuilder sb = new StringBuilder(); sb.append(s); String str = String.valueOf(sb.reverse()); if (s.equals(str)) return true; else return false; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
c6d28a0d4b25f239c7f59b3919562cfe
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for (int zz = 0; zz < t; zz++) { int n = in.nextInt(); if(n == 1) { System.out.println(2); }else if(n % 3 == 0) { System.out.println(n/3); }else { for(int i = 1; i < n; i++) { if((n - (2*i))%3 == 0) { System.out.println((n - 2*i)/3 + i); break; } } } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
400fbaea7eea3d0c6e7c65ef95894792
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Codeforces { static int M = 1_000_000_007; static int INF = 2_000_000_000; static int N = (int) 2e5 + 1; static long[] factorial; static boolean[] isPrime = new boolean[N+1]; static final FastScanner fs = new FastScanner(); //variable public static void main(String[] args) throws IOException { int T = fs.nextInt(); while (T-- > 0) { int n = fs.nextInt(); if(n == 1) { System.out.println(2); }else { System.out.println(n/3 + ((n%3 == 0)? 0:1)); } } } //class private static class Edge implements Comparable<Edge>{ long distance; int i, j; Edge(long distance, int i, int j) { this.distance = distance; this.i = i; this.j = j; } @Override public int compareTo(Edge o) { return Long.compare(this.distance, o.distance); } } //function static long distanceBetweenPoint(Pairs p1, Pairs p2) { return (long) (p1.f - p2.f) * (p1.f - p2.f) + (long) (p1.s - p2.s) *(p1.s-p2.s); } static void getPrimes() { for(int i=2;i<N;i++) isPrime[i] = true; int i = 2; while(i<N) { if(isPrime[i]) { for(int j=2*i;j<N;j+=i) isPrime[j] = false; } System.out.println(i+" "+isPrime[i]); i++; } } static void build(int[] a, int[] seg, int ind, int low, int high) { if (low == high) { seg[ind] = a[low]; return; } int mid = (low + high) / 2; build(a, seg, 2 * ind + 1, low, mid); build(a, seg, 2 * ind + 2, mid + 1, high); seg[ind] = Math.max(seg[2 * ind + 1], seg[2 * ind + 2]); } static long query(int ind, int[] seg, int l, int h, int low, int high) { if (low > h || high < l) return -INF; if (low >= l && high <= h) return seg[ind]; int mid = (low + high) / 2; long left = query(2 * ind + 1, seg, l, h, low, mid); long right = query(2 * ind + 2, seg, l, h, mid + 1, high); return Math.max(left, right); } // Template static long factorial(int n) { long fact = 1; for (int i = 1; i <= n; i++) { fact *= i; } return fact; } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static void premutation(int n, ArrayList<Integer> arr, boolean[] chosen) { if (arr.size() == n) { System.out.println(arr); } else { for (int i = 1; i <= n; i++) { if (chosen[i]) continue; arr.add(i); chosen[i] = true; premutation(n, arr, chosen); arr.remove(Integer.valueOf(i)); chosen[i] = false; } } } static boolean isPalindrome(char[] c) { int n = c.length; for (int i = 0; i < n / 2; i++) { if (c[i] != c[n - i - 1]) return false; } return true; } static long nCk(int n, int k) { return (modMult(fact(n), fastExpo(modMult(fact(n - k), fact(k)), M - 2))); } static long nPk(int n, int k) { return (modMult(fact(n), fastExpo(fact(n - k), M - 2))); } static long fact(int n) { if (factorial != null) return factorial[n]; else factorial = new long[N]; factorial[0] = 1; long fact = 1; for (int i = 1; i < N; i++) { factorial[i] = fact = modMult(fact, i); } return factorial[n]; } static long modMult(long a, long b) { return (int) (a * b % M); } static long negMult(long a, long b) { return (int) ((a * b) % M + M) % M; } static long fastExpo(long x, int y) { if (y == 1) return x; if (y == 0) return 1; long ans = fastExpo(x, y / 2); if (y % 2 == 0) return modMult(ans, ans); else return modMult(ans, modMult(ans, x)); } static final Random random = new Random(); static void ruffleSort(int[] arr) { int n = arr.length; for (int i = 0; i < n; i++) { int j = random.nextInt(n); int temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; } Arrays.sort(arr); } private static class Pairs implements Comparable<Pairs> { int f, s; Pairs(int f, int s) { this.f = f; this.s = s; } public int compareTo(Pairs p) { if (this.f != p.f) return Integer.compare(this.f, p.f); return -Integer.compare(this.s, p.s); } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Pairs)) return false; Pairs pairs = (Pairs) o; return f == pairs.f && s == pairs.s; } @Override public int hashCode() { return Objects.hash(f, s); } } private static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer str = new StringTokenizer(""); String next() throws IOException { while (!str.hasMoreTokens()) str = new StringTokenizer(br.readLine()); return str.nextToken(); } char nextChar() throws IOException { return next().charAt(0); } int nextInt() throws IOException { return Integer.parseInt(next()); } float nextFloat() throws IOException { return Float.parseFloat(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } byte nextByte() throws IOException { return Byte.parseByte(next()); } int[] arrayIn(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
d409d1846d11748335823e220a6d62a1
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.PrintWriter; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.FileReader; import java.io.IOException; import java.util.StringTokenizer; import java.util.ArrayList; import java.util.Collections; import java.util.Arrays; import java.util.Stack; import java.util.HashSet; import java.util.HashMap; import java.util.TreeSet; import java.util.TreeMap; import java.util.Map; import java.util.PriorityQueue; import java.util.ArrayDeque; import static java.lang.Math.min; import static java.lang.Math.max; import static java.lang.Math.sqrt; import static java.lang.Math.pow; import static java.lang.Math.abs; import static java.lang.Integer.MIN_VALUE; import static java.lang.Integer.MAX_VALUE; public class Main { static boolean IS_LOCAL = false; static Fast f = new Fast(); static PrintWriter out = new PrintWriter(System.out); static boolean TEST_CASES = true; static int mod1 = (int)1e9+7; static int mod2 = 998244353; static void solve() { int n = ri(); int ans = n/3+(n%3!=0?3-n%3:0); if(n>3 && n%3==1) ans = min(ans,(n-4)/3 + 2); out.println(ans); } public static void main(String[] args)throws Exception{ if(TEST_CASES){ int t = ri(); while(t-->0){ solve(); } } else { solve(); } out.close(); } static int nod(long l) { if(l>=1000000000000000000l) return 19; if(l>=100000000000000000l) return 18; if(l>=10000000000000000l) return 17; if(l>=1000000000000000l) return 16; if(l>=100000000000000l) return 15; if(l>=10000000000000l) return 14; if(l>=1000000000000l) return 13; if(l>=100000000000l) return 12; if(l>=10000000000l) return 11; if(l>=1000000000) return 10; if(l>=100000000) return 9; if(l>=10000000) return 8; if(l>=1000000) return 7; if(l>=100000) return 6; if(l>=10000) return 5; if(l>=1000) return 4; if(l>=100) return 3; if(l>=10) return 2; return 1; } static int ri() { return f.nextInt(); } static long rl() { return f.nextLong(); } static String rs(){ return f.next(); } static String rS(){ return f.nextLine(); } static char rc(){ return f.next().charAt(0); } static int[] ra(int n) { int[] a = new int[n]; for(int i = 0;i<n;i++) a[i] = ri(); return a; } static long[] ral(int n) { long[] a = new long[n]; for(int i = 0;i<n;i++) a[i] = rl(); return a; } static char[] rac(){ char[] c = rs().toCharArray(); return c; } static int[][] rm(int n, int m){ int[][] mat = new int[n][m]; for(int i = 0; i < n; i++) mat[i] = ra(m); return mat; } static char[][] rmc(int n){ char[][] cmat = new char[n][]; for(int i = 0; i < n;i++) cmat[i] = rac(); return cmat; } static void sort(int[] a) { ArrayList<Integer> list=new ArrayList<>(); for (int i:a) list.add(i); Collections.sort(list); for (int i=0; i<a.length; i++) a[i]=list.get(i); } static void sort(double[] a) { ArrayList<Double> list=new ArrayList<>(); for (double i:a) list.add(i); Collections.sort(list); for (int i=0; i<a.length; i++) a[i]=list.get(i); } static class Fast{ public BufferedReader br; public StringTokenizer st; public Fast(){ try{ br = IS_LOCAL? (new BufferedReader(new FileReader("input.txt"))):(new BufferedReader(new InputStreamReader(System.in))); } catch(Exception e){ throw new RuntimeException(e); } } String next(){ while(st==null || !st.hasMoreTokens()){ try{ st=new StringTokenizer(br.readLine()); } catch(IOException e){ throw new RuntimeException(e); } } 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
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
c11902ae3cb5afb4d3e765ee936cd54a
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class Move2Or3 { public static void main(String[] args) { String input = "4\r\n" + "1\r\n" + "3\r\n" + "4\r\n" + "12\r\n" + ""; Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int i = 0; i < t; i++) { int x = in.nextInt(); int result = 0; if(x == 1) { result = 2; } else if (x == 2 || x == 3) { result = 1; } else { while(x % 3 != 0) { x = x - 2; result++; } result += (x / 3); } System.out.println(result); } in.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
ea9cecfa24f11203e0cd8848ae163a3e
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; import java.time.*; import static java.time.temporal.ChronoUnit.MINUTES; import javafx.util.Pair; public class Program { public static void print(Object str) { System.out.print(str); } public static void println(Object str) { System.out.println(str); } public static void printArr(int[] arr) { for(int i=0;i<arr.length;i++) { System.out.print(arr[i]+" "); } System.out.println(""); } public static void printArr2(Object[][] arr) { int n = arr.length; int m = arr[0].length; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { System.out.print(arr[i][j]+" "); } System.out.println(""); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); } catch (Exception e) { System.err.println("Error"); } // code FastReader sc = new FastReader(); int t = sc.nextInt(); for(int tt=0; tt<t; tt++) { int n = sc.nextInt(); Object result = find(n); println(result); } return; } public static Object find(int n) { if(n==1) { return 2; } if(n%3==0) { return n/3; } else { return n/3+1; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
270168755febdf267b14f1d26d59596f
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { int n=sc.nextInt(); System.out.println(solve(n)); } } public static int solve(int n) { if(n==0) return 0; if(n==1) return 2; if(n==2) return 1; if(n==3) return 1; if(n==4) return 2; if(n==5) return 2; if (n==6) return 2; int prev=n/3; int extra=n%3; if(extra==0) return prev; return prev+1; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
e4d8f5e3e5c1fae7d5fb2532eaa63dc3
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import javafx.scene.shape.Line; import java.io.*; import java.math.BigInteger; public class Main { static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws Exception { int tc = sc.nextInt(); while(tc-->0) { int n = sc.nextInt(); if(n%3==0) { pw.println(n/3); }else if(n%3==1) { pw.println(Math.min(n*2, n==1?2:(n-4)/3+2)); }else { pw.println(Math.min(n*2, (n-2)/3+1)); } } pw.close(); } public static long[] Extended(long p, long q) { if (q == 0) return new long[] { p, 1, 0 }; long[] vals = Extended(q, p % q); long d = vals[0]; long a = vals[2]; long b = vals[1] - (p / q) * vals[2]; return new long[] { d, a, b }; } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String file) throws FileNotFoundException { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } public int[] nextArrint(int size) throws IOException { int[] a = new int[size]; for (int i = 0; i < a.length; i++) { a[i] = sc.nextInt(); } return a; } public long[] nextArrlong(int size) throws IOException { long[] a = new long[size]; for (int i = 0; i < a.length; i++) { a[i] = sc.nextLong(); } return a; } public int[][] next2dArrint(int rows, int columns) throws IOException { int[][] a = new int[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { a[i][j] = sc.nextInt(); } } return a; } public long[][] next2dArrlong(int rows, int columns) throws IOException { long[][] a = new long[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { a[i][j] = sc.nextLong(); } } return a; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
80f49a4f76b2537aea1d47b65231faa3
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
//package kg.my_algorithms.Codeforces; import java.io.*; import java.util.*; /* */ public class Solution { public static void main(String[] args) throws IOException { BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); FastReader fr = new FastReader(); int test_cases = fr.nextInt(); StringBuilder sb = new StringBuilder(); for(int test=1;test<=test_cases;test++){ int n = fr.nextInt(); sb.append(fun(n)).append("\n"); } output.write(sb.toString()); output.flush(); } private static int fun(int n){ if(n == 1) return 2; if(n%3 == 0) return n/3; else if(n%3 == 1) return (n-4)/3 + 2; return n/3+1; } } //Fast Input class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
3fb23dd4df634bf814846991edc9c255
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.lang.Math; public class Main{ public static void main(String []args){ Scanner in=new Scanner(System.in); int T=in.nextInt(); while(T>0){ int n=in.nextInt(); int res=0; if(n==4){System.out.println("2");T--;continue;} int sum=n/3; n=n%3; if(n==2){res++;} if(n==1){ if(sum>0)res++; else res+=2; } res+=sum; System.out.println(res); T--; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
8e054509e6b03800e79f682179b685c1
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { int n=sc.nextInt(); int cur=n/3; int tmp=n%3; if(cur==0) { if(tmp==1) { System.out.println(2); } else if(tmp==2) { System.out.println(1); } else { System.out.println(1); } continue; } if(tmp==1) { int ans=cur+1; System.out.println(ans); } else if(tmp==0) { System.out.println(cur); } else { System.out.println(cur+1); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
169acf6d9348dd5733d1b65ed310d75d
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import static java.lang.Math.*; import static java.lang.System.out; import java.util.*; import java.io.*; import java.math.BigInteger; public class Main { static int g = 0; public static void main(String[] args) throws IOException { FastInput sc = new FastInput(); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int ans = n/3; if(n == 1) { System.out.println(2); continue; } if(n%3 == 0) { System.out.println(ans); }else{ System.out.println((ans+1)); } } } public static int solve(int idx,int a[] , int p ) { if(idx>= a.length) return 0; if(a[idx] == 1 && p == 0) return 1; for(int i = 1;idx-i<3 && i < a.length;i++) { g += min(g + solve(idx+i,a,0),g + solve(idx+i,a,1)); } return g; } } class Pair implements Comparable<Pair> { int i; int j; public Pair(int i, int j) { this.i = i; this.j = j; } public Pair() { } public int compareTo(Pair t) { if (t.i > i) return -1; else if (t.i < i) return 1; // else return 0; } } class FastInput { BufferedReader br; StringTokenizer st; public FastInput() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { System.out.println(e.toString()); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { System.out.println(e.toString()); } return str; } public static void printArray(Object[] a) { Arrays.stream(a).forEach(t -> System.out.print(t + " ")); } public static void printArray(int[] a) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } System.out.println(); } public static void sort(int[] arr) { ArrayList<Integer> ls = new ArrayList<Integer>(); for (int x : arr) ls.add(x); Collections.sort(ls); for (int i = 0; i < arr.length; i++) arr[i] = ls.get(i); } public int[] readArr(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
5d758175e7e4e057476fd14b6f803d4c
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
/* package whatever; // don't place package name! */ import java.util.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0){ int n=s.nextInt(); int ans=0; if(n%3==0){ ans=n/3; } else if(n==1||n==-1){ ans=2; } else ans=(n/3)+1; System.out.println(ans); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
6bc4ade7bc9c70bcc914965f56d8e7e0
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; public class MainA { static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public boolean hasNext() { try { String string = reader.readLine(); if (string == null) { return false; } tokenizer = new StringTokenizer(string); return tokenizer.hasMoreTokens(); } catch (IOException e) { return false; } } } static InputReader in = new InputReader(System.in); static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static void ini() { } static String yes = "YES"; static String no = "NO"; static int ipInf = Integer.MAX_VALUE-5; static int inInf = Integer.MIN_VALUE+5; static long lpInf = Long.MAX_VALUE - 5; static long lnInf = Long.MIN_VALUE + 5; public static void main(String[] args) { int t = in.nextInt(); ini(); while (t -- > 0) { solve(); } out.close(); } static void solve() { int n = in.nextInt(); if (n == 1) { out.println(2); return; } if (n == 2) { out.println(1); return; } if (n % 3 == 0) { out.println(n / 3); } else { int res = n / 3; n = n % 3; if (n == 1) { res += 1; } else { res += 1; } out.println(res); } } static void printArr (int[] arr) { int n = arr.length; if (n == 0) return; for (int i = 0; i < n-1; i++) { out.print(arr[i] + " "); } out.println(arr[n-1]); } static void printArr (long[] arr) { int n = arr.length; if (n == 0) return; for (int i = 0; i < n-1; i++) { out.print(arr[i] + " "); } out.println(arr[n-1]); } static long _gcd (long a, long b) { long temp; while (true) { temp = a % b; if (temp == 0) return b; a = b; b = temp; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
ab8c023d703191c34fbe4d84d0cfe98e
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = in.nextInt(); for(int tt = 0;tt<t;tt++){ int n = in.nextInt(); if(n==1){ pw.println(2); } else if(n % 3==0){ pw.println(n/3); } else if(n % 3==1 || n % 3==2){ pw.println(n/3 + 1); } else { pw.println(n/2); } } pw.close(); } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
44305b6fa739184db286ea1376b5bd68
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class Moves { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int i; for (i = 0; i < t; i++) { int n = sc.nextInt(); int min = 0; if(n == 1) { min = 2; } else if(n == 2 || n == 3) { min = 1; } else if(n % 3 == 0) { min = n/3; } else if(n % 3 == 1) { min = (n/3 -1) + 2; } else if(n%3 == 2) { min = n/3 + 1; } System.out.println(min); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
3d3ffe8886358956b37aac79b8c4e062
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int len = sc.nextInt(); int m = 0; for (int i = 0; i < len; i++) { int num = sc.nextInt(); Math.abs(num); if (num == 1) { m = 2; System.out.println(m); continue; } if (num == 2) { m = 1; System.out.println(m); continue; } m = num / 3 + (num % 3 == 0?0:1); System.out.println(m); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
74a768027c1d1a29e1ecf4ca8c43fb40
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
//package two_three_moves; import java.util.Scanner; public class Main { Scanner sc = new Scanner(System.in); public Main() { int t = sc.nextInt(); sc.nextLine(); for (int i = 0; i < t; i++) { int n = sc.nextInt(); int min = n / 3; if (n == 1) { min = 2; } else if (n % 3 != 0) { min++; } System.out.println(min); } } public static void main(String[] args) { new Main(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
7de444b02f932c1011b73584353ab1c4
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class A { public static void main(String[] args) throws IOException { FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); int t = in.nextInt(); for (int tt = 0; tt < t; tt++) { int n = in.nextInt(); if (n < 2) pw.println(2); else if (n % 3 == 1) pw.println((n / 3) - 1 + 2); else if (n % 3 == 2) pw.println((n / 3) + 1); else pw.println(n / 3); } pw.close(); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static long gcd(long a, long b) { if (b == 0) return a; else return gcd(b, a % b); } public static void Sort(int[] a) { ArrayList<Integer> lst = new ArrayList<>(); for (int i : a) lst.add(i); Collections.sort(lst); for (int i = 0; i < lst.size(); i++) a[i] = lst.get(i); } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } static class FastReader { InputStream is; private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; public FastReader(InputStream is) { this.is = is; } public int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public String nextLine() { int c = skip(); StringBuilder sb = new StringBuilder(); while (!isEndOfLine(c)) { sb.appendCodePoint(c); c = readByte(); } return sb.toString(); } public int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public double nextDouble() { return Double.parseDouble(next()); } public char[] next(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } public char readChar() { return (char) skip(); } public long[] readArrayL(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nextLong(); return arr; } public int[] readArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
20e3c7269907e72a74b15f8701440336
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; public class Cf_0 { static class FastReader { InputStream is; private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; public FastReader(InputStream is) { this.is = is; } public int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public String nextLine() { int c = skip(); StringBuilder sb = new StringBuilder(); while (!isEndOfLine(c)) { sb.appendCodePoint(c); c = readByte(); } return sb.toString(); } public int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public double nextDouble() { return Double.parseDouble(next()); } public char[] next(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } public char readChar() { return (char) skip(); } public long[] readArrayL(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nextLong(); return arr; } public int[] readArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } } static PrintWriter pw= new PrintWriter(System.out); static FastReader fr= new FastReader(System.in); public static void main(String[] args) throws IOException { int t= fr.nextInt(); for(int i=0;i<t;i++){ long n= fr.nextInt(); pwl(solve800(n)+""); } pw.close(); } public static long solve800(long n){ if(n==1) return 2; if(n==2) return 1; if(n== 3) return 1; if(n%2==0 && n%3==0) return n/3; if(n%3==0) return n/3; if(n%2==0 && n<=4) return n/2; long temp=n/3; long rem=temp%3; if(rem==2) return temp+1; else return (temp-1)+2; } public static long findGCD(long a, long b) { while(b != 0) { if(a > b) { a = a - b; } else { b = b - a; } } return a; } static long lcm(long a, long b) { return (a / findGCD(a, b)) * b; } public static void print(int []a){ for(int t:a){ if(t!=0) System.out.print(t+" "); } System.out.println(); } public static void pwl(String s){ pw.println(s); } public static void pw(String s){ pw.print(s); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 8
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
104646291bc84556dab43df684227a9e
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class SortedMatrixBs { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); if (n == 0) { System.out.println(0); } else countSteps(n); } } public static void countSteps(int n){ if(n==1){ System.out.println(2); return; } if(n==0){ System.out.println(0); return; } if(n%3==0){ System.out.println(n/3); return; } if(n%3==1||n%3==2){ System.out.println((n/3)+1); return; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
f79c888ddf2702e9e65d54ca1c1d8d97
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class Moves { public static int solve(int coordinates) { if(coordinates % 3 == 0) return coordinates / 3; else if(coordinates % 3 == 2) return coordinates / 3 + 1; else return (coordinates - 3) / 3 + 2; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int tests = scanner.nextInt(); for(int i = 0; i < tests; i++) System.out.println(Moves.solve(scanner.nextInt())); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
0d93da7f9e41269244b85eb5e902bcab
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
//package Algorithm; import java.awt.List; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedList; import java.util.ListIterator; import java.util.PriorityQueue; import java.util.Queue; import java.util.StringTokenizer; import javax.xml.stream.events.StartDocument; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer st = new StringTokenizer(br.readLine()); int T = Integer.parseInt(st.nextToken()); for (int test = 1; test <= T; test++) { st = new StringTokenizer(br.readLine()); int N = Integer.parseInt(st.nextToken()); if(N==1) { bw.write(2+"\n"); continue; } if(N%3==0) { bw.write(N/3+"\n"); } else { int ans = (N/2) + (N%2)*2; if(N%3==1) { ans = Math.min(ans, N/3 + 1); } else { ans = Math.min(ans, N/3 + 1); } bw.write(ans+"\n"); } } bw.flush(); bw.close(); br.close(); } public static void subTree(int node, int[] cnt, ArrayList<Integer>[] list, int par) { for(int x:list[node]) { if(x!=par) { subTree(x, cnt, list, node); cnt[node] += cnt[x]; } } return; } public static void DFS(int node, int[] cnt, ArrayList<Integer>[] list,int[] dp, int par) { int[] child = new int[3]; int idx = 0; for(int x:list[node]) { if(x!=par) { child[idx] = x; idx++; DFS(x, cnt, list, dp, node); } } if(list[node].size()==1) { return; } if(list[node].size()==2) { dp[node] = cnt[child[0]] - 1; return; } int node1 = child[0]; int node2 = child[1]; dp[node] = Math.max(dp[node], dp[node1] + cnt[node2]-1); dp[node] = Math.max(dp[node], dp[node2] + cnt[node1]-1); return; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
77433b76429194edc2a089e474b8fea9
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class contest1 { static int power(int x, int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static int modInverse(int n, int p) { return power(n, p - 2, p); } public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); PrintWriter pw = new PrintWriter(System.out); // Scanner sc=new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); // int y = sc.nextInt(); //String s = sc.next(); // int arr[]=new int[n]; int flag = 0; // HashMap<Integer,Integer>h=new HashMap<>(); int count = 0;//int flag=0; //int c=n-y+1; // int ans=nCrModPFermat( n, y,1000000007); //System.out.println(2); if(n==1) { System.out.println("2"); } else if(n%3==0) { System.out.println(n/3); } else if(n%3==2&&n%2==0) { System.out.println(Math.min(n/3+1,n/2)); } else if(n%3==2&& n%2!=0) { System.out.println(n/3+1); } else if(n%2==0 && n%3==1) { System.out.println(Math.min(n/3+2-1,n/2)); } else { System.out.println(n/3+2-1); } } } //Sort(a); static final Random ra = new Random(); static void Sort(int arr[]) { int n = arr.length; for (int i = 0; i < n; i++) { int j = ra.nextInt(n); int temp = (int) arr[j]; arr[j] = arr[i]; arr[i] = temp; } Arrays.sort(arr); } public static int[] swap(int arr[], int x, int y) { int temp = arr[x]; arr[x] = arr[y]; arr[y] = temp; return arr; } //fast IO 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
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
2945a35a11cdd41b1eb21b9e64c5af17
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Moves2_3 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int test=1;test<=t;test++) { int n=sc.nextInt(); if(n%3==0) { System.out.println(n/3); } else if(n==1) { System.out.println(2); } else if(n==2) { System.out.println(1); } else { System.out.println((n/3)+1); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
56127a9fa61201888ed1e446642425cb
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; //Incomplete public class ProbA { public static void main(String[] args) { FastReader in = new FastReader(); int numOfTestCases = in.nextInt(); for(int w = 0; w < numOfTestCases; w++) { int n = in.nextInt(); int m3 = n / 3; int m2 = n / 2; if(n % 3 == 1) { m3 += 1; } else if(n % 3 == 2) { m3 += 1; } if(n != 1) { System.out.println((Math.min(m2, m3))); } else { System.out.println(2); } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } int[] intArray(int n){ int[] arr = new int[n]; for(int i =0; i < n; i ++){ arr[i] = nextInt(); } return arr; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
08e59c6a67314fdf18b28af9295e53b1
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; //Incomplete public class ProbA { public static void main(String[] args) { FastReader in = new FastReader(); int numOfTestCases = in.nextInt(); for(int w = 0; w < numOfTestCases; w++) { int n = in.nextInt(); int m3 = n / 3; int m2 = n / 2; if(n % 3 == 1) { m3 += 1; } else if(n % 3 == 2) { m3 += 1; } if(n % 2 == 1) { m2 += 2; } if(n != 1) { System.out.println((Math.min(m2, m3))); } else { System.out.println(2); } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } int[] intArray(int n){ int[] arr = new int[n]; for(int i =0; i < n; i ++){ arr[i] = nextInt(); } return arr; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
80c4900f74e8184f2f0f18f0dc751d64
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.PrintWriter; import java.util.*; public class Main { public static class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static Scanner scan = new Scanner(System.in); public static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args){ int testCase = scan.nextInt(); for (int vedant = 0; vedant < testCase; vedant++) { solve(); } // out.println(5); } private static void solve() { // ******************** S O L V E M E T H O D ***************** // ************* M A I N L O G I C G O E S H E R E ********** long n = scan.nextLong(); if (n % 3 == 0) { System.out.println(n / 3); return; } if (n == 1) { System.out.println(2); return; } long answer = n / 3; answer++; System.out.println(answer); } private static void printYES() { System.out.println("YES"); } private static void printNO() { System.out.println("NO"); } private static long getMaximumFromList(List<Long> arr) { long max = Long.MIN_VALUE; for (int i = 0; i < arr.size(); i++) { max = Math.max(max, arr.get(i)); } return max; } public static int binarySearch(int[] arr, int target) { int starting = 0; int ending = arr.length - 1; while (starting < ending) { int mid = starting + (ending - starting) / 2; if (arr[mid] == target) { return mid; } if (arr[mid] > target) { ending = mid - 1; } else { starting = mid + 1; } } return -1; } public static int binarySearch(long[] arr, long target) { int starting = 0; int ending = arr.length - 1; while (starting < ending) { int mid = starting + (ending - starting) / 2; if (arr[mid] == target) { return mid; } if (arr[mid] > target) { ending = mid - 1; } else { starting = mid + 1; } } return -1; } public static int gcd(int a, int b) { // Everything divides 0 if (a == 0) return b; if (b == 0) return a; // base case if (a == b) return a; // a is greater if (a > b) return gcd(a-b, b); return gcd(a, b-a); } public static long gcd(long a, long b) { // Everything divides 0 if (a == 0) return b; if (b == 0) return a; // base case if (a == b) return a; // a is greater if (a > b) return gcd(a-b, b); return gcd(a, b-a); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
2f1ad340142e8877e7277c99c9211bbf
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Moves { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i=0; i<n; i++){ solve(sc); } } public static void solve(Scanner sc) { int n = sc.nextInt(); if(n%3 == 0){ System.out.println(n/3); return; } if(n == 1){ System.out.println(2); return; } int k = n/3; System.out.println(k+(((k+1)*3 - k*3)/2)); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
48ffefd6fda10e7233307b129abe1f2a
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(),n,m1=0,m2=0; while(t-->0){ n=sc.nextInt(); if(n==1) System.out.println(2); else if(n%3==0) System.out.println(n/3); else{ m1=n/3+1; if(n%2!=0){ m2=1+(n-3)/2; System.out.println(Math.min(m1,m2)); } else System.out.println(Math.min(n/2,m1)); } } sc.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
6429bf12ea078eb52a8d12d527529a55
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; public class TimePass { public static void main (String[] args) throws java.lang.Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int testCases=Integer.parseInt(br.readLine()); // int testCases=1; while(testCases-->0){ int m=Integer.parseInt(br.readLine()); if(m==1) out.println(2); else if(m%3==0) out.println(m/3); else out.println(m/3+1);; } out.close(); } } class DSU{ int parent[]; int rank[]; int totalComponents; public DSU(int n) { parent=new int[n]; rank=new int[n]; totalComponents=n; for(int i=0;i<n;i++) { parent[i]=i; } } public int find(int v) { if(parent[v]==v) return v; return parent[v]=find(parent[v]); } public void union(int v1,int v2) { int p1=find(v1); int p2=find(v2); if(p1==p2) return; if(rank[p1]>rank[p2]) { parent[p2]=p1; }else if(rank[p2]>rank[p1]) { parent[p1]=p2; }else { rank[p1]++; parent[p2]=p1; } totalComponents--; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
340fe1528300dbbeced91f711f60376d
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class App { public static Scanner scan = new Scanner(System.in); public static void main(String[] args) throws Exception { int t = Integer.parseInt(scan.nextLine()); while(t > 0) { System.out.println(solve()); t --; } } public static int solve() { int n = Integer.parseInt(scan.nextLine()); if(n == 1) return 2; if(n == 2 || n == 3) return 1; if(n % 3 == 0) return n / 3; return Math.floorDiv(n, 3) + 1; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
b433325e011cfbd1675c792ca429104e
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class moves__ { public static void main(String args[]){ Scanner read=new Scanner(System.in); int t=read.nextInt(); while(t-->0){ int n=read.nextInt(); if(n==1) System.out.println(2); else{ if(n%3==0 ) System.out.println((int)n/3); // else if(n%2==0) // System.out.println((int)n/2); else{ if(n%3==1 &&n%2==0) System.out.println(Math.min(((int)n/3)+1, (int)n/2)); // System.out.println(((int)n/3)+2); else if(n%3==2 &&n%2==0) System.out.println(Math.min(((int)n/3)+1, (int)n/2)); else if(n%3==1) System.out.println(((int)n/3)+1); else if(n%3==2) System.out.println(((int)n/3)+1); } } } read.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
54638b64cfcff5e4ad525254426746ef
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class soln { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); long t = sc.nextLong(); for(int i = 0 ; i < t ; i++) { long n = sc.nextLong(); if(n < 0) { n = n*-1; } if(n == 1) { System.out.println(2); } else if((n+1)%3 == 0 ) { System.out.println((n+1)/3); } else if((n+2) % 3 == 0) { System.out.println((n+2)/3); } else if(n%3 == 0) { System.out.println(n/3); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
f19445a269e000b3c788403b2ea75e56
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; public class CodeForces { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.valueOf(br.readLine()); while(t-->0) { int n=Integer.valueOf(br.readLine()); if(n==1) { System.out.println("2"); continue; } if(n%3!=0) System.out.println((n/3)+1); else System.out.println(n/3); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
f9dc3574d51a27e6d1716ca3c950fbc1
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class cf1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++){ int k = sc.nextInt(); arr[i] = k; } for(int i = 0; i < n; i++){ if(arr[i] == 1){ System.out.println(2); } else if(arr[i] % 3 == 0){ System.out.println(arr[i]/3); } else{ System.out.println(arr[i]/3 + 1); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
37a194a8d14891660aaa36c73fa8a670
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Solution{ public static void main(String args[]){ Scanner in = new Scanner(System.in); long test = in.nextLong(); while(test-- > 0){ long n = in.nextLong(); n = Math.abs(n); long ans = 0; if(n == 1) ans = 2; else if(n == 2) ans = 1; else{ ans = (n / 3); ans = (n % 3 == 0) ? ans : ans + 1; } System.out.println(ans); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
bc05a5994be3fa98fbc7369ae09d5936
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc =new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt();n=Math.abs(n); if(n==1) {System.out.println(2);continue; } int x=n/3; int y=n%3; if(y!=0) x+=1; System.out.println(x); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
9f522df5efba0c05baeeff7cd7c779f2
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template */ import java.util.Scanner; public class Move { /** * @param args the command line arguments */ static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int t = sc.nextInt(); while (t > 0) { tinh(); t = t - 1; } } public static void tinh() { int n = sc.nextInt(); if (n == 1) { System.out.println(2); } else { if (n == 2 || n == 3) { System.out.println(1); } else { // if(n==0) if (n % 3 == 0) { System.out.println(n / 3); } else { if (n % 3 == 2) { System.out.println((n - 2) / 3 + 1); } else { if (n % 3 == 1) { System.out.println((n - 4) / 3 + 2); } } } } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
8d8dcc2dc4ea90420dcefcc2460d1133
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int i; int t = scn.nextInt(); while(t>0) { int ans=0; int n = scn.nextInt(); if(n==1) { ans=2; } else if(n%3==0) { ans = n/3; } else if((n-2)%3==0) { ans=n/3+1; } else if((n-1)%3==0) { ans=(n-4)/3+2; } System.out.println(ans); t--; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
e6a96a149d1ced78ee0f740d37444122
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.StringTokenizer; public class P1716A { static PrintWriter out = new PrintWriter(System.out); static MyFastReaderP1716A in = new MyFastReaderP1716A(); static long mod = (long) (1e9 + 7); public static void main(String[] args) throws Exception { int test = i(); while (test-- > 0) { int n=i(); if(n==1) out.print(2); else { if(n%3==0) out.print(n/3); else out.print(n/3+1); } out.print("\n"); out.flush(); } out.close(); } static class pair { long x, y; pair(long ar, long ar2) { x = ar; y = ar2; } } static void sort(long[] a) // check for long { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } 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); } public static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static class DescendingComparator implements Comparator<Integer> { public int compare(Integer a, Integer b) { return b - a; } } static class AscendingComparator implements Comparator<Integer> { public int compare(Integer a, Integer b) { return a - b; } } static boolean isPalindrome(char X[]) { int l = 0, r = X.length - 1; while (l <= r) { if (X[l] != X[r]) return false; l++; r--; } return true; } static long fact(long N) { long num = 1L; while (N >= 1) { num = ((num % mod) * (N % mod)) % mod; N--; } return num; } static long pow(long a, long b) { long mod = 1000000007; long pow = 1; long x = a; while (b != 0) { if ((b & 1) != 0) pow = (pow * x) % mod; x = (x * x) % mod; b /= 2; } return pow; } static long toggleBits(long x)// one's complement || Toggle bits { int n = (int) (Math.floor(Math.log(x) / Math.log(2))) + 1; return ((1 << n) - 1) ^ x; } static int countBits(long a) { return (int) (Math.log(a) / Math.log(2) + 1); } static boolean isPrime(long N) { if (N <= 1) return false; if (N <= 3) return true; if (N % 2 == 0 || N % 3 == 0) return false; for (int i = 5; i * i <= N; i = i + 6) if (N % i == 0 || N % (i + 2) == 0) return false; return true; } static long GCD(long a, long b) { if (b == 0) { return a; } else return GCD(b, a % b); } // Debugging Functions Starts static void print(char A[]) { for (char c : A) System.out.print(c + " "); System.out.println(); } static void print(boolean A[]) { for (boolean c : A) System.out.print(c + " "); System.out.println(); } static void print(int A[]) { for (int a : A) System.out.print(a + " "); System.out.println(); } static void print(long A[]) { for (long i : A) System.out.print(i + " "); System.out.println(); } static void print(ArrayList<Integer> A) { for (int a : A) System.out.print(a + " "); System.out.println(); } // Debugging Functions END // ---------------------- // IO FUNCTIONS STARTS static HashMap<Integer, Integer> getHashMap(int A[]) { HashMap<Integer, Integer> mp = new HashMap<>(); for (int a : A) { int f = mp.getOrDefault(a, 0) + 1; mp.put(a, f); } return mp; } public static Map<Character, Integer> mapSortByValue(Map<Character, Integer> hm) { // Create a list from elements of HashMap List<Map.Entry<Character, Integer>> list = new LinkedList<Map.Entry<Character, Integer>>(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator<Map.Entry<Character, Integer>>() { public int compare(Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2) { return o1.getValue() - o2.getValue(); } }); // put data from sorted list to hashmap Map<Character, Integer> temp = new LinkedHashMap<Character, Integer>(); for (Map.Entry<Character, Integer> aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static String string() { return in.nextLine(); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static int[] arrI(int N) { int A[] = new int[N]; for (int i = 0; i < N; i++) { A[i] = in.nextInt(); } return A; } static long[] arrL(int N) { long A[] = new long[N]; for (int i = 0; i < A.length; i++) A[i] = in.nextLong(); return A; } } class MyFastReaderP1716A { BufferedReader br; StringTokenizer st; public MyFastReaderP1716A() { 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
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
99bff69fd614fcb48347e3143f9362e9
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Solutions{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int testcase=sc.nextInt(); for(int i=0;i<testcase;i++){ int input=sc.nextInt(); if(input==1){ System.out.println(2); continue; } else if(input==2){ System.out.println(1); continue; } else if(input%3==0){ System.out.println(input/3); }else{ System.out.println((input/3)+1); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
ebb9c93b48ac6c5649bae20d625cb0e7
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; /* * * 10 -> 4 * 10 -> 5 / 5 * * * * * */ public class B{ public static void main(String[] args) { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); for(int tt=0;tt<t;tt++) { int moves = 0; int rem = fs.nextInt(); if(rem % 3 == 2) { moves = rem/3 + 1; } else if(rem % 3 == 0) { moves = rem/3; } else if(rem == 1)moves = 2; else { // System.out.println(rem/3); moves = Math.min(rem/3 + 2, rem/2); moves = Math.min(moves, (rem-4)/3 + 2); } out.println(moves); } out.close(); } 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()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } public static long[] sort(long[] arr) { List<Long> temp = new ArrayList(); for(long i:arr)temp.add(i); Collections.sort(temp); int start = 0; for(long i:temp)arr[start++]=i; return arr; } public static String rev(String str) { char[] arr = str.toCharArray(); char[] ret = new char[arr.length]; int start = arr.length-1; for(char i:arr)ret[start--] = i; String ret1 = ""; for(char ch:ret)ret1+=ch; return ret1; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
c8016be90e9145a856efc3ff1b2b7d21
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class prg { public static Scanner sc=new Scanner(System.in); public static void main(String args[]) { int t=sc.nextInt(); for(int i=0;i<t;i++) run(); } public static void run() { int n=sc.nextInt(); if(n==1) System.out.println(2); else System.out.println((int)Math.ceil(Math.abs(n)/3.0)); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
3f0b6d1241da5d553ad0460dbad0b74a
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int numOfTest = in.nextInt(); while (numOfTest-- != 0) { long num = in.nextLong(); if (num == 1) { System.out.println(2); } else { int reminder = (int) (num % 3); if (reminder == 0) { System.out.println(num / 3); } else{ System.out.println(num/3+1); } } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
8567870f6827facb8b2b7bd31aec5027
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int numOfTest = in.nextInt(); while (numOfTest-- != 0) { long num = in.nextLong(); if (num == 1) { System.out.println(2); } else { int reminder = (int) (num % 3); if (reminder == 0) { System.out.println(num / 3); } else if (reminder == 1) { System.out.println(num / 3 + 1); } else{ System.out.println(num/3+1); } } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
a0353008ef1a61fbfed19fdda4ee9b09
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class CodeForces { static void algo(int n){ n=Math.abs(n); if(n==1){ System.out.println(2); return; } int moves; if (n%3==0){ moves=n/3; System.out.println(moves); return; } int ans=Integer.MAX_VALUE; moves=n/3; moves+=1; ans=Math.min(ans,moves); System.out.println(ans); } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); algo(n); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
d61bd185c1233359d66a3d44493fe81d
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class q1 { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int n = scn.nextInt(); for(int i = 0 ; i < n ; i++) { int x = scn.nextInt(); if(x==1||x==4) { System.out.println(2); } else if(x==2) { System.out.println(1); } else if(x%3==0) { System.out.println(x/3); } else { System.out.println((x/3)+1); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
d55ebfa02966e681e4db9f00f905654e
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
// import static java.lang.System.out; import static java.lang.Math.*; import java.util.*; import javax.naming.ContextNotEmptyException; import javax.swing.ImageIcon; import javax.swing.table.TableStringConverter; import javax.swing.text.DefaultStyledDocument.ElementSpec; import java.io.*; import java.math.*; import java.rmi.ConnectIOException; public class Main { static FastReader sc; static long mod = ((long) 1e9) + 7; static Tree tree; static PrintWriter out, err; static int imax = Integer.MAX_VALUE; static int imin = Integer.MIN_VALUE; static long lmax = Long.MAX_VALUE; static long lmin = Long.MIN_VALUE; static double dmax = Double.MAX_VALUE; static double dmin = Double.MIN_VALUE; private static void solve() throws IOException { long n=sc.nextLong(); if(n==1){ print(2); return; } long v=0; long mod=n%3; int c=0; while(mod==1&&n>1&&c<2){ n-=2; mod=n%2; v++; c++; } if(n<=0){ print(v); } if(n>0){ v+=n/3; mod=n%3; } if(mod==0)print(v); else{ if(mod==2){ v++; print(v); } } } public static void main(String hi[]) throws IOException { initializeIO(); out = new PrintWriter(System.out); err = new PrintWriter(System.err); sc = new FastReader(); long startTimeProg = System.currentTimeMillis(); long endTimeProg; int testCase = 1; testCase = sc.nextInt(); while (testCase-- != 0) { solve(); } endTimeProg = System.currentTimeMillis(); debug("[finished : " + (endTimeProg - startTimeProg) + ".ms ]"); out.flush(); err.flush(); // System.out.println(String.format("%.9f", max)); } private static class Pair { int first = 0; int sec = 0; int[] arr; char ch; String s; Map<Integer, Integer> map; Pair(int first, int sec) { this.first = first; this.sec = sec; } Pair(int[] arr) { this.map = new HashMap<>(); for (int x : arr) this.map.put(x, map.getOrDefault(x, 0) + 1); this.arr = arr; } Pair(char ch, int first) { this.ch = ch; this.first = first; } Pair(String s, int first) { this.s = s; this.first = first; } } private static Set<Long> factors(long n) { Set<Long> res = new HashSet<>(); // res.add(n); for (long i = 1; i * i <= (n); i++) { if (n % i == 0) { res.add(i); if (n / i != i) { res.add(n / i); } } } return res; } // geometrics private static double areaOftriangle(double x1, double y1, double x2, double y2, double x3, double y3) { double[] mid_point = midOfaLine(x1, y1, x2, y2); // debug(Arrays.toString(mid_point)+" "+x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+" // "+y3); double height = distanceBetweenPoints(mid_point[0], mid_point[1], x3, y3); double wight = distanceBetweenPoints(x1, y1, x2, y2); // debug(height+" "+wight); return (height * wight) / 2; } private static double distanceBetweenPoints(double x1, double y1, double x2, double y2) { double x = x2 - x1; double y = y2 - y1; return (Math.pow(x, 2) + Math.pow(y, 2)); } private static double[] midOfaLine(double x1, double y1, double x2, double y2) { double[] mid = new double[2]; mid[0] = (x1 + x2) / 2; mid[1] = (y1 + y2) / 2; return mid; } /* Function to calculate x raised to the power y in O(logn) */ static long power(long x, long y) { long temp; if (y == 0) return 1l; temp = power(x, y / 2); if (y % 2 == 0) return (temp * temp); else return (x * temp * temp); } private static StringBuilder reverseString(String s) { StringBuilder sb = new StringBuilder(s); int l = 0, r = sb.length() - 1; while (l <= r) { char ch = sb.charAt(l); sb.setCharAt(l, sb.charAt(r)); sb.setCharAt(r, ch); l++; r--; } return sb; } private static void swap(List<Integer> li, int i, int j) { int t = li.get(i); li.set(i, li.get(j)); li.set(j, t); } private static void swap(int[] arr, int i, int j) { int t = arr[i]; arr[i] = arr[j]; arr[j] = t; } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } private static boolean isPallindrome(String s, int l, int r) { while (l < r) { if (s.charAt(l) != s.charAt(r)) return false; l++; r--; } return true; } private static StringBuilder removeLeadingZero(StringBuilder sb) { int i = 0; while (i < sb.length() && sb.charAt(i) == '0') i++; // debug("remove "+i); if (i == sb.length()) return new StringBuilder(); return new StringBuilder(sb.substring(i, sb.length())); } private static void print(int[][] arr) { int n = arr.length; int m = arr[0].length; int i, j; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { out.print(arr[i][j] + " "); } out.println(); } } private static StringBuilder removeEndingZero(StringBuilder sb) { int i = sb.length() - 1; while (i >= 0 && sb.charAt(i) == '0') i--; if (i < 0) return new StringBuilder(); return new StringBuilder(sb.substring(0, i + 1)); } private static void debug(int[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void debug(long[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void debug(List<int[]> arr) { for (int[] a : arr) { err.println(Arrays.toString(a)); } } private static void debug(float[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void debug(double[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void debug(boolean[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } // private static void print() throws IOException { // out.println(s); // } private static void debug(String s) throws IOException { err.println(s); } private static void print(double s) throws IOException { out.println(s); } private static void print(float s) throws IOException { out.println(s); } private static void print(long s) throws IOException { out.println(s); } private static void print(int s) throws IOException { out.println(s); } private static void debug(double s) throws IOException { err.println(s); } private static void debug(float s) throws IOException { err.println(s); } private static void debug(long s) { err.println(s); } private static void debug(int s) { err.println(s); } private 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 (int i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } private static List<List<Integer>> readUndirectedGraph(int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i <= n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); graph.get(x).add(y); graph.get(y).add(x); } return graph; } private static List<List<Integer>> readUndirectedGraph(int[][] intervals, int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i <= n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < intervals.length; i++) { int x = intervals[i][0]; int y = intervals[i][1]; graph.get(x).add(y); graph.get(y).add(x); } return graph; } private static List<List<Integer>> readDirectedGraph(int[][] intervals, int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i <= n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < intervals.length; i++) { int x = intervals[i][0]; int y = intervals[i][1]; graph.get(x).add(y); // graph.get(y).add(x); } return graph; } private static List<List<Integer>> readDirectedGraph(int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i <= n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); graph.get(x).add(y); // graph.get(y).add(x); } return graph; } static String[] readStringArray(int n) { String[] arr = new String[n]; for (int i = 0; i < n; i++) { arr[i] = sc.next(); } return arr; } private static Map<Character, Integer> freq(String s) { Map<Character, Integer> map = new HashMap<>(); for (char c : s.toCharArray()) { map.put(c, map.getOrDefault(c, 0) + 1); } return map; } private static Map<Long, Integer> freq(long[] arr) { Map<Long, Integer> map = new HashMap<>(); for (long x : arr) { map.put(x, map.getOrDefault(x, 0) + 1); } return map; } private static Map<Integer, Integer> freq(int[] arr) { Map<Integer, Integer> map = new HashMap<>(); for (int x : arr) { map.put(x, map.getOrDefault(x, 0) + 1); } return map; } static boolean[] sieveOfEratosthenes(long n) { boolean prime[] = new boolean[(int) n + 1]; for (int i = 2; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } return prime; } static int[] sieveOfEratosthenesInt(long n) { boolean prime[] = new boolean[(int) n + 1]; Set<Integer> li = new HashSet<>(); for (int i = 2; 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; } } } for (int i = 0; i <= n; i++) { if (prime[i]) li.add(i); } int[] arr = new int[li.size()]; int i = 0; for (int x : li) { arr[i++] = x; } return arr; } static boolean isMemberAC(int a, int d, int x) { // If difference is 0, then x must // be same as a. if (d == 0) return (x == a); // Else difference between x and a // must be divisible by d. return ((x - a) % d == 0 && (x - a) / d >= 0); } static boolean isMemberAC(long a, long d, long x) { // If difference is 0, then x must // be same as a. if (d == 0) return (x == a); // Else difference between x and a // must be divisible by d. return ((x - a) % d == 0 && (x - a) / d >= 0); } private static void sort(int[] arr) { int n = arr.length; List<Integer> li = new ArrayList<>(); for (int x : arr) { li.add(x); } Collections.sort(li); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sortReverse(int[] arr) { int n = arr.length; List<Integer> li = new ArrayList<>(); for (int x : arr) { li.add(x); } Collections.sort(li, Collections.reverseOrder()); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sort(double[] arr) { int n = arr.length; List<Double> li = new ArrayList<>(); for (double x : arr) { li.add(x); } Collections.sort(li); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sortReverse(double[] arr) { int n = arr.length; List<Double> li = new ArrayList<>(); for (double x : arr) { li.add(x); } Collections.sort(li, Collections.reverseOrder()); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sortReverse(long[] arr) { int n = arr.length; List<Long> li = new ArrayList<>(); for (long x : arr) { li.add(x); } Collections.sort(li, Collections.reverseOrder()); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sort(long[] arr) { int n = arr.length; List<Long> li = new ArrayList<>(); for (long x : arr) { li.add(x); } Collections.sort(li); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static long sum(int[] arr) { long sum = 0; for (int x : arr) { sum += x; } return sum; } private static long sum(long[] arr) { long sum = 0; for (long x : arr) { sum += x; } return sum; } private static void initializeIO() { try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); System.setErr(new PrintStream(new FileOutputStream("error.txt"))); } catch (Exception e) { System.err.println(e.getMessage()); } } private static int maxOfArray(int[] arr) { int max = Integer.MIN_VALUE; for (int x : arr) { max = Math.max(max, x); } return max; } private static long maxOfArray(long[] arr) { long max = Long.MIN_VALUE; for (long x : arr) { max = Math.max(max, x); } return max; } private static int[][] readIntIntervals(int n, int m) { int[][] arr = new int[n][m]; for (int j = 0; j < n; j++) { for (int i = 0; i < m; i++) { arr[j][i] = sc.nextInt(); } } return arr; } private static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } private static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } private static int[] readIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } return arr; } private static double[] readDoubleArray(int n) { double[] arr = new double[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextDouble(); } return arr; } private static long[] readLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextLong(); } return arr; } private static void print(int[] arr) throws IOException { out.println(Arrays.toString(arr)); } private static void print(long[] arr) throws IOException { out.println(Arrays.toString(arr)); } private static void print(String[] arr) throws IOException { out.println(Arrays.toString(arr)); } private static void print(double[] arr) throws IOException { out.println(Arrays.toString(arr)); } private static void debug(String[] arr) { err.println(Arrays.toString(arr)); } private static void debug(Boolean[][] arr) { for (int i = 0; i < arr.length; i++) err.println(Arrays.toString(arr[i])); } private static void debug(int[] arr) { err.println(Arrays.toString(arr)); } private static void debug(long[] arr) { err.println(Arrays.toString(arr)); } 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 Tree { List<List<Integer>> adj = new ArrayList<>(); int parent = 1; int[] arr; int n; Map<Integer, Integer> node_parent; List<Integer> leaf; public Tree(int n) { this.n = n; leaf = new ArrayList<>(); node_parent = new HashMap<>(); arr = new int[n + 2]; for (int i = 0; i <= n + 1; i++) { adj.add(new ArrayList<>()); } for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); node_parent.put(i + 1, arr[i]); if ((i + 1) == arr[i]) parent = arr[i]; else adj.get(arr[i]).add(i + 1); } } private List<List<Integer>> getTree() { return adj; } private void formLeaf(int v) { boolean leaf = true; for (int x : adj.get(v)) { formLeaf(x); leaf = false; } if (leaf) this.leaf.add(v); } private List<Integer> getLeaf() { return leaf; } private Map<Integer, Integer> getParents() { return node_parent; } int[] getArr() { return arr; } } static class Dsu { int[] parent, size; Dsu(int n) { parent = new int[n + 1]; size = new int[n + 1]; for (int i = 0; i <= n; i++) { parent[i] = i; size[i] = 1; } } private int findParent(int u) { if (parent[u] == u) return u; return parent[u] = findParent(parent[u]); } private boolean union(int u, int v) { // System.out.println("uf "+u+" "+v); int pu = findParent(u); // System.out.println("uf2 "+pu+" "+v); int pv = findParent(v); // System.out.println("uf3 " + u + " " + pv); if (pu == pv) return false; if (size[pu] <= size[pv]) { parent[pu] = pv; size[pv] += size[pu]; } else { parent[pv] = pu; size[pu] += size[pv]; } return true; } } // =================================================================================== public static int log2(int N) { return (int) (Math.log(N) / Math.log(2)); } private static long fact(long n) { if (n <= 2) return n; return n * fact(n - 1); } private static void print(String s) throws IOException { out.println(s); } public static boolean isNumeric(String strNum) { if (strNum == null) { return false; } try { double d = Double.parseDouble(strNum); } catch (NumberFormatException nfe) { return false; } return true; } private static boolean isSorted(List<Integer> li) { int n = li.size(); if (n <= 1) return true; for (int i = 0; i < n - 1; i++) { if (li.get(i) > li.get(i + 1)) return false; } return true; } private static boolean isSorted(int[] arr) { int n = arr.length; if (n <= 1) return true; for (int i = 0; i < n - 1; i++) { if (arr[i] > arr[i + 1]) return false; } return true; } private static boolean ispallindromeList(List<Integer> res) { int l = 0, r = res.size() - 1; while (l < r) { if (res.get(l) != res.get(r)) return false; l++; r--; } return true; } private static long ncr(long n, long r) { return fact(n) / (fact(r) * fact(n - r)); } private static void swap(char[] s, int i, int j) { char t = s[i]; s[i] = s[j]; s[j] = t; } static boolean isPowerOfTwo(long x) { return x != 0 && ((x & (x - 1)) == 0); } private static long gcd(long[] arr) { long ans = 0; for (long x : arr) { ans = gcd(x, ans); } return ans; } private static int gcd(int[] arr) { int ans = 0; for (int x : arr) { ans = gcd(x, ans); } return ans; } private static long power(long x, long y, long p) { long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
d0104c4ba533673a7894377023e0c79d
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
// import static java.lang.System.out; import static java.lang.Math.*; import java.util.*; import javax.naming.ContextNotEmptyException; import javax.swing.ImageIcon; import javax.swing.table.TableStringConverter; import javax.swing.text.DefaultStyledDocument.ElementSpec; import java.io.*; import java.math.*; import java.rmi.ConnectIOException; public class Main { static FastReader sc; static long mod = ((long) 1e9) + 7; static Tree tree; static PrintWriter out, err; static int imax = Integer.MAX_VALUE; static int imin = Integer.MIN_VALUE; static long lmax = Long.MAX_VALUE; static long lmin = Long.MIN_VALUE; static double dmax = Double.MAX_VALUE; static double dmin = Double.MIN_VALUE; private static void solve() throws IOException { long n=sc.nextLong(); if(n==1){ print(2); return; }else if(n==2){ print(1); return; } long v=0; long mod=n%3; if(mod==2){ n-=2; v++; } mod=n%3; if(mod==2){ n-=2; v++; } // debug(n%3); if(n<=0){ print(v); return; }else{ mod=n%3; v=v+(n/3); if(mod==0)print(v); else { v++; print(v); } } } public static void main(String hi[]) throws IOException { initializeIO(); out = new PrintWriter(System.out); err = new PrintWriter(System.err); sc = new FastReader(); long startTimeProg = System.currentTimeMillis(); long endTimeProg; int testCase = 1; testCase = sc.nextInt(); while (testCase-- != 0) { solve(); } endTimeProg = System.currentTimeMillis(); debug("[finished : " + (endTimeProg - startTimeProg) + ".ms ]"); out.flush(); err.flush(); // System.out.println(String.format("%.9f", max)); } private static class Pair { int first = 0; int sec = 0; int[] arr; char ch; String s; Map<Integer, Integer> map; Pair(int first, int sec) { this.first = first; this.sec = sec; } Pair(int[] arr) { this.map = new HashMap<>(); for (int x : arr) this.map.put(x, map.getOrDefault(x, 0) + 1); this.arr = arr; } Pair(char ch, int first) { this.ch = ch; this.first = first; } Pair(String s, int first) { this.s = s; this.first = first; } } private static Set<Long> factors(long n) { Set<Long> res = new HashSet<>(); // res.add(n); for (long i = 1; i * i <= (n); i++) { if (n % i == 0) { res.add(i); if (n / i != i) { res.add(n / i); } } } return res; } // geometrics private static double areaOftriangle(double x1, double y1, double x2, double y2, double x3, double y3) { double[] mid_point = midOfaLine(x1, y1, x2, y2); // debug(Arrays.toString(mid_point)+" "+x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+" // "+y3); double height = distanceBetweenPoints(mid_point[0], mid_point[1], x3, y3); double wight = distanceBetweenPoints(x1, y1, x2, y2); // debug(height+" "+wight); return (height * wight) / 2; } private static double distanceBetweenPoints(double x1, double y1, double x2, double y2) { double x = x2 - x1; double y = y2 - y1; return (Math.pow(x, 2) + Math.pow(y, 2)); } private static double[] midOfaLine(double x1, double y1, double x2, double y2) { double[] mid = new double[2]; mid[0] = (x1 + x2) / 2; mid[1] = (y1 + y2) / 2; return mid; } /* Function to calculate x raised to the power y in O(logn) */ static long power(long x, long y) { long temp; if (y == 0) return 1l; temp = power(x, y / 2); if (y % 2 == 0) return (temp * temp); else return (x * temp * temp); } private static StringBuilder reverseString(String s) { StringBuilder sb = new StringBuilder(s); int l = 0, r = sb.length() - 1; while (l <= r) { char ch = sb.charAt(l); sb.setCharAt(l, sb.charAt(r)); sb.setCharAt(r, ch); l++; r--; } return sb; } private static void swap(List<Integer> li, int i, int j) { int t = li.get(i); li.set(i, li.get(j)); li.set(j, t); } private static void swap(int[] arr, int i, int j) { int t = arr[i]; arr[i] = arr[j]; arr[j] = t; } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } private static boolean isPallindrome(String s, int l, int r) { while (l < r) { if (s.charAt(l) != s.charAt(r)) return false; l++; r--; } return true; } private static StringBuilder removeLeadingZero(StringBuilder sb) { int i = 0; while (i < sb.length() && sb.charAt(i) == '0') i++; // debug("remove "+i); if (i == sb.length()) return new StringBuilder(); return new StringBuilder(sb.substring(i, sb.length())); } private static void print(int[][] arr) { int n = arr.length; int m = arr[0].length; int i, j; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { out.print(arr[i][j] + " "); } out.println(); } } private static StringBuilder removeEndingZero(StringBuilder sb) { int i = sb.length() - 1; while (i >= 0 && sb.charAt(i) == '0') i--; if (i < 0) return new StringBuilder(); return new StringBuilder(sb.substring(0, i + 1)); } private static void debug(int[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void debug(long[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void debug(List<int[]> arr) { for (int[] a : arr) { err.println(Arrays.toString(a)); } } private static void debug(float[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void debug(double[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void debug(boolean[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } // private static void print() throws IOException { // out.println(s); // } private static void debug(String s) throws IOException { err.println(s); } private static void print(double s) throws IOException { out.println(s); } private static void print(float s) throws IOException { out.println(s); } private static void print(long s) throws IOException { out.println(s); } private static void print(int s) throws IOException { out.println(s); } private static void debug(double s) throws IOException { err.println(s); } private static void debug(float s) throws IOException { err.println(s); } private static void debug(long s) { err.println(s); } private static void debug(int s) { err.println(s); } private 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 (int i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } private static List<List<Integer>> readUndirectedGraph(int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i <= n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); graph.get(x).add(y); graph.get(y).add(x); } return graph; } private static List<List<Integer>> readUndirectedGraph(int[][] intervals, int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i <= n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < intervals.length; i++) { int x = intervals[i][0]; int y = intervals[i][1]; graph.get(x).add(y); graph.get(y).add(x); } return graph; } private static List<List<Integer>> readDirectedGraph(int[][] intervals, int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i <= n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < intervals.length; i++) { int x = intervals[i][0]; int y = intervals[i][1]; graph.get(x).add(y); // graph.get(y).add(x); } return graph; } private static List<List<Integer>> readDirectedGraph(int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i <= n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); graph.get(x).add(y); // graph.get(y).add(x); } return graph; } static String[] readStringArray(int n) { String[] arr = new String[n]; for (int i = 0; i < n; i++) { arr[i] = sc.next(); } return arr; } private static Map<Character, Integer> freq(String s) { Map<Character, Integer> map = new HashMap<>(); for (char c : s.toCharArray()) { map.put(c, map.getOrDefault(c, 0) + 1); } return map; } private static Map<Long, Integer> freq(long[] arr) { Map<Long, Integer> map = new HashMap<>(); for (long x : arr) { map.put(x, map.getOrDefault(x, 0) + 1); } return map; } private static Map<Integer, Integer> freq(int[] arr) { Map<Integer, Integer> map = new HashMap<>(); for (int x : arr) { map.put(x, map.getOrDefault(x, 0) + 1); } return map; } static boolean[] sieveOfEratosthenes(long n) { boolean prime[] = new boolean[(int) n + 1]; for (int i = 2; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } return prime; } static int[] sieveOfEratosthenesInt(long n) { boolean prime[] = new boolean[(int) n + 1]; Set<Integer> li = new HashSet<>(); for (int i = 2; 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; } } } for (int i = 0; i <= n; i++) { if (prime[i]) li.add(i); } int[] arr = new int[li.size()]; int i = 0; for (int x : li) { arr[i++] = x; } return arr; } static boolean isMemberAC(int a, int d, int x) { // If difference is 0, then x must // be same as a. if (d == 0) return (x == a); // Else difference between x and a // must be divisible by d. return ((x - a) % d == 0 && (x - a) / d >= 0); } static boolean isMemberAC(long a, long d, long x) { // If difference is 0, then x must // be same as a. if (d == 0) return (x == a); // Else difference between x and a // must be divisible by d. return ((x - a) % d == 0 && (x - a) / d >= 0); } private static void sort(int[] arr) { int n = arr.length; List<Integer> li = new ArrayList<>(); for (int x : arr) { li.add(x); } Collections.sort(li); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sortReverse(int[] arr) { int n = arr.length; List<Integer> li = new ArrayList<>(); for (int x : arr) { li.add(x); } Collections.sort(li, Collections.reverseOrder()); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sort(double[] arr) { int n = arr.length; List<Double> li = new ArrayList<>(); for (double x : arr) { li.add(x); } Collections.sort(li); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sortReverse(double[] arr) { int n = arr.length; List<Double> li = new ArrayList<>(); for (double x : arr) { li.add(x); } Collections.sort(li, Collections.reverseOrder()); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sortReverse(long[] arr) { int n = arr.length; List<Long> li = new ArrayList<>(); for (long x : arr) { li.add(x); } Collections.sort(li, Collections.reverseOrder()); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sort(long[] arr) { int n = arr.length; List<Long> li = new ArrayList<>(); for (long x : arr) { li.add(x); } Collections.sort(li); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static long sum(int[] arr) { long sum = 0; for (int x : arr) { sum += x; } return sum; } private static long sum(long[] arr) { long sum = 0; for (long x : arr) { sum += x; } return sum; } private static void initializeIO() { try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); System.setErr(new PrintStream(new FileOutputStream("error.txt"))); } catch (Exception e) { System.err.println(e.getMessage()); } } private static int maxOfArray(int[] arr) { int max = Integer.MIN_VALUE; for (int x : arr) { max = Math.max(max, x); } return max; } private static long maxOfArray(long[] arr) { long max = Long.MIN_VALUE; for (long x : arr) { max = Math.max(max, x); } return max; } private static int[][] readIntIntervals(int n, int m) { int[][] arr = new int[n][m]; for (int j = 0; j < n; j++) { for (int i = 0; i < m; i++) { arr[j][i] = sc.nextInt(); } } return arr; } private static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } private static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } private static int[] readIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } return arr; } private static double[] readDoubleArray(int n) { double[] arr = new double[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextDouble(); } return arr; } private static long[] readLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextLong(); } return arr; } private static void print(int[] arr) throws IOException { out.println(Arrays.toString(arr)); } private static void print(long[] arr) throws IOException { out.println(Arrays.toString(arr)); } private static void print(String[] arr) throws IOException { out.println(Arrays.toString(arr)); } private static void print(double[] arr) throws IOException { out.println(Arrays.toString(arr)); } private static void debug(String[] arr) { err.println(Arrays.toString(arr)); } private static void debug(Boolean[][] arr) { for (int i = 0; i < arr.length; i++) err.println(Arrays.toString(arr[i])); } private static void debug(int[] arr) { err.println(Arrays.toString(arr)); } private static void debug(long[] arr) { err.println(Arrays.toString(arr)); } 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 Tree { List<List<Integer>> adj = new ArrayList<>(); int parent = 1; int[] arr; int n; Map<Integer, Integer> node_parent; List<Integer> leaf; public Tree(int n) { this.n = n; leaf = new ArrayList<>(); node_parent = new HashMap<>(); arr = new int[n + 2]; for (int i = 0; i <= n + 1; i++) { adj.add(new ArrayList<>()); } for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); node_parent.put(i + 1, arr[i]); if ((i + 1) == arr[i]) parent = arr[i]; else adj.get(arr[i]).add(i + 1); } } private List<List<Integer>> getTree() { return adj; } private void formLeaf(int v) { boolean leaf = true; for (int x : adj.get(v)) { formLeaf(x); leaf = false; } if (leaf) this.leaf.add(v); } private List<Integer> getLeaf() { return leaf; } private Map<Integer, Integer> getParents() { return node_parent; } int[] getArr() { return arr; } } static class Dsu { int[] parent, size; Dsu(int n) { parent = new int[n + 1]; size = new int[n + 1]; for (int i = 0; i <= n; i++) { parent[i] = i; size[i] = 1; } } private int findParent(int u) { if (parent[u] == u) return u; return parent[u] = findParent(parent[u]); } private boolean union(int u, int v) { // System.out.println("uf "+u+" "+v); int pu = findParent(u); // System.out.println("uf2 "+pu+" "+v); int pv = findParent(v); // System.out.println("uf3 " + u + " " + pv); if (pu == pv) return false; if (size[pu] <= size[pv]) { parent[pu] = pv; size[pv] += size[pu]; } else { parent[pv] = pu; size[pu] += size[pv]; } return true; } } // =================================================================================== public static int log2(int N) { return (int) (Math.log(N) / Math.log(2)); } private static long fact(long n) { if (n <= 2) return n; return n * fact(n - 1); } private static void print(String s) throws IOException { out.println(s); } public static boolean isNumeric(String strNum) { if (strNum == null) { return false; } try { double d = Double.parseDouble(strNum); } catch (NumberFormatException nfe) { return false; } return true; } private static boolean isSorted(List<Integer> li) { int n = li.size(); if (n <= 1) return true; for (int i = 0; i < n - 1; i++) { if (li.get(i) > li.get(i + 1)) return false; } return true; } private static boolean isSorted(int[] arr) { int n = arr.length; if (n <= 1) return true; for (int i = 0; i < n - 1; i++) { if (arr[i] > arr[i + 1]) return false; } return true; } private static boolean ispallindromeList(List<Integer> res) { int l = 0, r = res.size() - 1; while (l < r) { if (res.get(l) != res.get(r)) return false; l++; r--; } return true; } private static long ncr(long n, long r) { return fact(n) / (fact(r) * fact(n - r)); } private static void swap(char[] s, int i, int j) { char t = s[i]; s[i] = s[j]; s[j] = t; } static boolean isPowerOfTwo(long x) { return x != 0 && ((x & (x - 1)) == 0); } private static long gcd(long[] arr) { long ans = 0; for (long x : arr) { ans = gcd(x, ans); } return ans; } private static int gcd(int[] arr) { int ans = 0; for (int x : arr) { ans = gcd(x, ans); } return ans; } private static long power(long x, long y, long p) { long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
daf6c77647b9df443d002c4966935d50
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.sql.PreparedStatement; import java.util.*; public class Main { static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws IOException { MyScanner s=new MyScanner(); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); String check=s.nextLine(); if(check==null){ return; } int t=Integer.parseInt(check); while(t-->0) { int a =s.nextInt(); if(a<0){ a=-a; } if(a==0){ System.out.println(0); continue; } if(a==1){ System.out.println(2); continue; } if(a==2||a==3){ System.out.println(1); continue; } if(a%3==0){ System.out.println(a/3); }else if(a%3==2){ System.out.println(1+ (a/3)); }else{ System.out.println(Math.min(1+ (a/3), a/2)); } } // int c=s.nextInt(); // for(int i=0;i<arr.length;i++) { // arr[i] = s.nextInt(); // } // Arrays.sort(arr); // int lo=1; // int hi=arr[arr.length-1]-arr[0]; // int res=-1; // while(lo<=hi){ // int mid=lo+(hi-lo)/2; // int ans=bs(arr,mid); // if(ans<c){ // hi=mid-1; // }else{ // res=mid; // lo=mid+1; // } // } // System.out.println(res); /*int n=s.nextInt(); if(n%2==0){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ output.write(-1+" "); } output.write("\n"); } }else{ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i==j){ output.write(-1+" "); continue; } output.write(1+" "); } output.write("\n"); } } output.flush(); }*/ } public static int bs(int[] arr,int mid){ int dis=0; int ans=1; for(int i=1;i<arr.length;i++){ dis+=arr[i]-arr[i-1]; if(dis>=mid){ dis=0; ans++; } } return ans; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
ca97b3faa7f49d0772dcead5f598fdee
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
//package Educational_Codeforces_Round_133; import java.util.Scanner; public class A { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = Integer.parseInt(scanner.nextLine().trim()); String[] out = new String[t]; for(int i = 0; i < t; i++){ int point = Integer.parseInt(scanner.nextLine().trim()); int k = A.getNum(Math.abs(point)); out[i] = String.valueOf(k); } System.out.println(String.join("\n", out)); } private static int getNum(int point) { if(point==1)return 2; int out = (point/3)+((point-(3*(point/3)))/2); int position = (3*(point/3)) + (2*((point-(3*(point/3)))/2)); out = position == point ? out : out + 1; return point%2==0? Math.min(point / 2, out): out; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
7e252f639f1f7e5cae88edd42ec5f233
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; import java.math.*; public class A { public static void main(String[] args) throws java.lang.Exception { Reader scan = new Reader(); int tc = scan.nextInt(); for (int i = 0; i < tc; i++) { long n = scan.nextLong(); // ArrayList<Long> arr = new ArrayList<Long>(); // for (long j = 0; j < n; j++) { // long l = scan.nextLong(); // arr.add(l); // } System.out.println(solve(n)); } } public static long solve(long n) { if (n == 1) return 2; if (n % 3 == 0) return n/3; else if (n % 6 == 4){ long first = n/2; long res = (long)Math.ceil((double)n/3)+1; long third = (n/3)+1; return Math.min(first, Math.min(res, third)); } else if (n % 6 == 1){ long first = (long)Math.ceil((double)n/3)+1; long second = (n/3)+1; return Math.min(first, second); } else if (n % 6 == 2){ long first = n/2; long second = (n/3)+1; return Math.min(first, second); } else if (n % 6 == 5){ long first = (n/3)+1; return first; } else{ return 0; } } public static void printarr(ArrayList<Long> arr) { for (int i = 0; i < arr.size(); i++) { System.out.print(arr.get(i) + " "); } System.out.println(); } static class Reader { final private int BUFFER_SIZE = 1 << 64; 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[1000000]; // 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(); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
7bb0e43d81cc5bdb109ed08008d002b1
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class 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(); while(t-->0){ int n = sc.nextInt(); int ans = 0; if(n==1){ ans = 2; } else if(n%3==0){ ans = n/3; } else{ ans = n/3; ans++; } System.out.println(ans); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
48030aa7d2be9daff032f83ded4a073a
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class temp2 { static int ans(int n) { if(n==1) return 2; if(n%3==0) return n/3; return n/3+1; } public static void main (String[] args) { // your code goes here Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i = 0; i<t; i++) { int n = sc.nextInt(); System.out.println(ans(n)); } sc.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
055c86477d122ca76e083c9f5a8c2a7c
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.lang.*; import java.util.*; public class ComdeFormces { static int dp[][]; static boolean mnans; public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub // Reader.init(System.in); FastReader sc=new FastReader(); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); // OutputStream out = new BufferedOutputStream ( System.out ); int t=sc.nextInt(); int tc=1; while(t--!=0) { int n=sc.nextInt(); if(n%3==0)log.write((n/3)+"\n"); else if(n==1)log.write(2+"\n"); else { log.write(((n/3)+1)+"\n"); } } log.flush(); } static int mod=998244853; static int eval(int n,int m,int sm) { if(n==0 && m==0)return 1; if(n<0 || m<0)return 0; if(dp[n][m]!=-1)return dp[n][m]; if(sm==0) { return dp[n][m]=eval(n,m-1,sm-1); } else return dp[n][m]=add(eval(n-1,m,sm+1),eval(n,m-1,sm-1)); } static int[] lps(int a[],String s) { int i=1; int j=0; a[0]=0; while(i<s.length()) { if(s.charAt(i)==s.charAt(j)) { a[i]=j+1; i++; j++; } else { if(j!=0) { j=a[j-1]; } else { a[i]=0; i++; } } } return a; } static int[] zed(char a[]) { int z[]=new int[a.length]; int l=0; int r=0; for(int i=0;i<a.length;i++) { if(i>r) { l=r=i; while(r<a.length && a[r]==a[r-l])r++; z[i]=r-l; r--; } else { int k1=i-l; if(z[k1]<r-i+1) { z[i]=z[k1]; } else { l=i; while(r<a.length && a[r]==a[r-l])r++; z[i]=r-l; r--; } } } return z; } public static class pair2{ int a,b,c,d; public pair2(int a,int b,int c,int d) { this.a=a; this.b=b; this.c=c; this.d=d; } } static boolean dfs(ArrayList<ArrayList<Integer>> ar,int src,int pr,HashSet<Integer> hs) { int cnt=0; boolean an=false; for(int k:ar.get(src)) { if(k==pr)continue; boolean p=dfs(ar,k,src,hs); an|=p; if(p)cnt++; } if(cnt>1)mnans=false; if(hs.contains(src))an=true; return an; } static int find(int el,int p[]) { if(p[el]<0)return el; return p[el]=find(p[el],p); } static boolean union(int a,int b,int p[]) { int p1=find(a,p); int p2=find(b,p); if(p1>=0 && p1==p2)return false; else { if(p[p1]<p[p2]) { p[p1]+=p[p2]; p[p2]=p1; } else { p[p2]+=p[p1]; p[p1]=p2; } return true; } } public static void build(int a[][],int b[]) { for(int i=0;i<b.length;i++) { a[i][0]=b[i]; } int jmp=2; while(jmp<=b.length) { for(int j=0;j<b.length;j++) { int ind=(int)(Math.log(jmp/2)/Math.log(2)); int ind2=(int)(Math.log(jmp)/Math.log(2)); if(j+jmp-1<b.length) { a[j][ind2]=Math.max(a[j][ind],a[j+(jmp/2)][ind]); } } jmp*=2; } // for(int i=0;i<a.length;i++) { // for(int j=0;j<33;j++) { // System.out.print(a[i][j]+" "); // } // System.out.println(); // } } public static void build2(int a[][],int b[]) { for(int i=0;i<b.length;i++) { a[i][0]=b[i]; } int jmp=2; while(jmp<=b.length) { for(int j=0;j<b.length;j++) { int ind=(int)(Math.log(jmp/2)/Math.log(2)); int ind2=(int)(Math.log(jmp)/Math.log(2)); if(j+jmp-1<b.length) { a[j][ind2]=Math.min(a[j][ind],a[j+(jmp/2)][ind]); } } jmp*=2; } // for(int i=0;i<a.length;i++) { // for(int j=0;j<33;j++) { // System.out.print(a[i][j]+" "); // } // System.out.println(); // } } public static int serst(int a[][],int i,int j) { int len=j-i+1; int hp=1; int tlen=len>>=1; // System.out.println(tlen); while(tlen!=0) { tlen>>=1; hp<<=1; } // System.out.println(hp); int ind=(int)(Math.log(hp)/Math.log(2)); int i2=j+1-hp; return Math.max(a[i][ind], a[i2][ind]); } public static int serst2(int a[][],int i,int j) { int len=j-i+1; int hp=1; int tlen=len>>=1; // System.out.println(tlen); while(tlen!=0) { tlen>>=1; hp<<=1; } // System.out.println(hp); int ind=(int)(Math.log(hp)/Math.log(2)); int i2=j+1-hp; return Math.min(a[i][ind], a[i2][ind]); } static void update(long f[],long upd,int ind) { int vl=ind; while(vl<f.length) { f[vl]+=upd; int tp=~vl; tp++; tp&=vl; vl+=tp; } } static long ser(long f[],int ind) { int vl=ind; long sm=0; while(vl!=0) { sm+=f[vl]; int tp=~vl; tp++; tp&=vl; vl-=tp; } return sm; } public static void radixSort(int a[]) { int n=a.length; int res[]=new int[n]; int p=1; for(int i=0;i<=8;i++) { int cnt[]=new int[10]; for(int j=0;j<n;j++) { a[j]=res[j]; cnt[(a[j]/p)%10]++; } for(int j=1;j<=9;j++) { cnt[j]+=cnt[j-1]; } for(int j=n-1;j>=0;j--) { res[cnt[(a[j]/p)%10]-1]=a[j]; cnt[(a[j]/p)%10]--; } p*=10; } } static int bits(long n) { int ans=0; while(n!=0) { if((n&1)==1)ans++; n>>=1; } return ans; } public static int kadane(int a[]) { int sum=0,mx=Integer.MIN_VALUE; for(int i=0;i<a.length;i++) { sum+=a[i]; mx=Math.max(mx, sum); if(sum<0) sum=0; } return mx; } public static int m=(int)(1e9+7); public static int mul(int a, int b) { return ((a%m)*(b%m))%m; } public static long mul(long a, long b) { return ((a%m)*(b%m))%m; } public static int add(int a, int b) { return ((a%mod)+(b%mod))%mod; } public static long add(long a, long b) { return ((a%m)+(b%m))%m; } //debug public static <E> void p(E[][] a,String s) { System.out.println(s); for(int i=0;i<a.length;i++) { for(int j=0;j<a[0].length;j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } public static void p(int[] a,String s) { System.out.print(s+"="); for(int i=0;i<a.length;i++)System.out.print(a[i]+" "); System.out.println(); } public static void p(long[] a,String s) { System.out.print(s+"="); for(int i=0;i<a.length;i++)System.out.print(a[i]+" "); System.out.println(); } public static <E> void p(E a,String s){ System.out.println(s+"="+a); } public static <E> void p(ArrayList<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(LinkedList<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(HashSet<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(Stack<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(Queue<E> a,String s){ System.out.println(s+"="+a); } //utils static ArrayList<Integer> divisors(int n){ ArrayList<Integer> ar=new ArrayList<>(); for (int i=2; i<=Math.sqrt(n); i++){ if (n%i == 0){ if (n/i == i) { ar.add(i); } else { ar.add(i); ar.add(n/i); } } } return ar; } static ArrayList<Integer> prime(int n){ ArrayList<Integer> ar=new ArrayList<>(); int cnt=0; boolean pr=false; while(n%2==0) { ar.add(2); n/=2; } for(int i=3;i*i<=n;i+=2) { pr=false; while(n%i==0) { n/=i; ar.add(i); pr=true; } } if(n>2) ar.add(n); return ar; } static long gcd(long a,long b) { if(b==0)return a; else return gcd(b,a%b); } static int gcd(int a,int b) { if(b==0)return a; else return gcd(b,a%b); } static long factmod(long n,long mod) { if(n==0)return 0; long ans=1; long temp=1; while(temp<=n) { ans=((ans%mod)*((temp)%mod))%mod; temp++; } return ans%mod; } static int ncr(int n, int r){ if(r>n-r)r=n-r; int ans=1; for(int i=0;i<r;i++){ ans*=(n-i); ans/=(i+1); } return ans; } public static class trip{ int a; int b; int c; public trip(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } // public int compareTo(trip q) { // return this.b-q.b; // } } static void mergesort(int[] a,int start,int end) { if(start>=end)return ; int mid=start+(end-start)/2; mergesort(a,start,mid); mergesort(a,mid+1,end); merge(a,start,mid,end); } static void merge(int[] a, int start,int mid,int end) { int ptr1=start; int ptr2=mid+1; int b[]=new int[end-start+1]; int i=0; while(ptr1<=mid && ptr2<=end) { if(a[ptr1]<=a[ptr2]) { b[i]=a[ptr1]; ptr1++; i++; } else { b[i]=a[ptr2]; ptr2++; i++; } } while(ptr1<=mid) { b[i]=a[ptr1]; ptr1++; i++; } while(ptr2<=end) { b[i]=a[ptr2]; ptr2++; i++; } for(int j=start;j<=end;j++) { a[j]=b[j-start]; } } public static class FastReader { BufferedReader b; StringTokenizer s; public FastReader() { b=new BufferedReader(new InputStreamReader(System.in)); } String next() { while(s==null ||!s.hasMoreElements()) { try { s=new StringTokenizer(b.readLine()); } catch(IOException e) { e.printStackTrace(); } } return s.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str=""; try { str=b.readLine(); } catch(IOException e) { e.printStackTrace(); } return str; } boolean hasNext() { if (s != null && s.hasMoreTokens()) { return true; } String tmp; try { b.mark(1000); tmp = b.readLine(); if (tmp == null) { return false; } b.reset(); } catch (IOException e) { return false; } return true; } } public static class pair{ int a; int b; public pair(int a,int b) { this.a=a; this.b=b; } // public int compareTo(pair b) { // return this.a-b.a; // // } // // public int compareToo(pair b) { // return this.b-b.b; // } @Override public String toString() { return "{"+this.a+" "+this.b+"}"; } } static long pow(long a, long pw) { long temp; if(pw==0)return 1; temp=pow(a,pw/2); if(pw%2==0)return temp*temp; return a*temp*temp; } public static int md=998244353; static long mpow(long a, long pw) { long temp; if(pw==0)return 1; temp=pow(a,pw/2)%md; if(pw%2==0)return mul(temp,temp); return mul(a,mul(temp,temp)); } static int pow(int a, int pw) { int temp; if(pw==0)return 1; temp=pow(a,pw/2); if(pw%2==0)return temp*temp; return a*temp*temp; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
b83f1a86af2a8089f2ddfee8cfa205b3
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.IOException; import java.util.Scanner; public class codeforces133div2 { public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0) { int n=in.nextInt(); int ans=0; if(n%2==0 && n%3==0) { ans = n / 3; } else if(n%2==0) { ans = n / 2; if(ans>=3) { int temp=ans/3; ans=ans-temp; } } else if(n%3==0) { ans = n / 3; } else { if(n==1) ans=2; else { int diff = n - 3; int key = (diff / 2); if (key >= 3) { int tempo = key / 3; key = key - tempo; } ans = key + 1; } } System.out.println(ans); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
8481505e03d2a93b820c3ed8fd2cafd0
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { int T=0; Scanner in = new Scanner(System.in); T = in.nextInt(); while(T > 0) { long n=0; n = in.nextLong(); if(n==0) { System.out.println(0); } else { n = Math.abs(n); long count=0, mod2=0; if(n%2==0) { mod2 = n/2; } // if(n%2==0 && n%3!=0) { // count = n/2; // } else if(n==1) { count = 2; } else if(n%3==0) { count = n/3; } else if(n%3==1) { count = n/3 + 1; } else if(n%3==2) { count = n/3 + 1; } if(mod2==0) { System.out.println(count); } else { count = Math.min(count, mod2); System.out.println(count); } } T--; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
b92f655551d77bb72573cbd5d929d947
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; public class ProblemA { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t!=0){ solve(br,pr); t--; } pr.flush(); pr.close(); } public static void solve(BufferedReader br,PrintWriter pr) throws IOException{ int n=Integer.parseInt(br.readLine()); if(n%3==0){ pr.println(n/3); return; } if(n==1){ pr.println(2); return; } if(n==2){ pr.println(1); return; } if(n==3){ pr.println(1); return; } int threeSetp=n/3; int gap=n-threeSetp*3; int res=threeSetp+(gap==1?2:1); for(int i=1;i<=100;i++){ int tempn=n-i*2; if(tempn<0){ break; } res=Math.min(res,getMove(tempn)+i); } pr.println(res); } public static int getMove(int n){ if(n%3==0){ return n/2; } if(n==1){ return 2; } if(n==2){ return 1; } if(n==3){ return 1; } int threeSetp=n/3; int gap=n-threeSetp*3; int res=threeSetp+(gap==1?2:1); return res; } public static int gcd(int n1, int n2) { if (n2 == 0) { return n1; } return gcd(n2, n1 % n2); } public static void shuffleArray(int[] arr) { Random rnd = ThreadLocalRandom.current(); for (int i = arr.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); if(index!=i){ arr[index]^=arr[i]; arr[i]^=arr[index]; arr[index]^=arr[i]; } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
38fc2c212b2947895663bc5395e00175
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); int ans=0; if(n<=3) { if(n==1) ans = 2; else ans = 1; } else ans = (int)((n+2)/3); System.out.println(ans); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output
PASSED
1976480b4be01ee63777e50649e1ec93
train_109.jsonl
1659623700
You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0){ int N = sc.nextInt(); int res=0; if(N==1) res=2; else if(N==2 || N==3) res=1; else res=(N%3==0 ? N/3 : N/3 + 1); System.out.println(res); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 11
standard input
[ "greedy", "math" ]
208e285502bed3015b30ef10a351fd6d
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.
800
For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.
standard output