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
75b0c8cf0c1c1ef57a764c9a8cc5a714
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 tc = 0; tc < t; ++tc) { int n = sc.nextInt(); System.out.println(solve(n)); } sc.close(); } static int solve(int n) { return (n == 1) ? 2 : (n / 3 + ((n % 3 == 0) ? 0 : 1)); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
e908aece115944ec90786fe56df395ca
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.math.*; public class Aditya { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int i = 0;i < t;i++){ int n = in.nextInt(); if(n == 1){ System.out.println(2); } else if(n == 2){ System.out.println(1); } else if(n == 3){ System.out.println(1); } else if(n == 4){ System.out.println(2); } else if(n % 3 == 2){ int ans = n / 3; ans += 1; System.out.println(ans); } else if(n % 3 == 1){ // n += 2; int ans = n / 3; ans += 1; System.out.println(ans); } else{ int ans = n / 3; System.out.println(ans); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
c0ed60f60e24c019731d083d90e13af7
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.*; /** * * @author eslam */ public class IceCave { static class Kattio extends PrintWriter { private BufferedReader r; private StringTokenizer st; // standard input public Kattio() { this(System.in, System.out); } public Kattio(InputStream i, OutputStream o) { super(o); r = new BufferedReader(new InputStreamReader(i)); } // USACO-style file input public Kattio(String problemName) throws IOException { super(problemName + ".out"); r = new BufferedReader(new FileReader(problemName + ".in")); } // returns null if no more input String nextLine() { String str = ""; try { str = r.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public String next() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(r.readLine()); } return st.nextToken(); } catch (Exception e) { } return null; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } } // Beginning of the solution static Kattio input = new Kattio(); static BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); static ArrayList<ArrayList<Integer>> powerSet = new ArrayList<>(); static ArrayList<LinkedList<Integer>> allprem = new ArrayList<>(); static ArrayList<LinkedList<String>> allprems = new ArrayList<>(); static ArrayList<Long> luc = new ArrayList<>(); static long mod = (long) (Math.pow(10, 9) + 7); static long dp[][]; public static void main(String[] args) throws IOException { int test = input.nextInt(); loop: while (test-- > 0) { int n = input.nextInt(); int ans = n / 3 + (n % 3 != 0 ? 1 : 0); if(n==1)ans++; log.write(ans + "\n"); } log.flush(); } public static String revs(String w) { String ans = ""; for (int i = w.length() - 1; i > -1; i--) { ans += w.charAt(i); } return ans; } public static boolean isPalindrome(String w) { for (int i = 0; i < w.length() / 2; i++) { if (w.charAt(i) != w.charAt(w.length() - i - 1)) { return false; } } return true; } public static void getPowerSet(Queue<Integer> a) { int n = a.poll(); if (!a.isEmpty()) { getPowerSet(a); } int s = powerSet.size(); for (int i = 0; i < s; i++) { ArrayList<Integer> ne = new ArrayList<>(); ne.add(n); for (int j = 0; j < powerSet.get(i).size(); j++) { ne.add(powerSet.get(i).get(j)); } powerSet.add(ne); } ArrayList<Integer> p = new ArrayList<>(); p.add(n); powerSet.add(p); } public static int getlo(int va) { int v = 1; while (v <= va) { if ((va&v) != 0) { return v; } v <<= 1; } return 0; } static long fast_pow(long a, long p) { long res = 1; while (p > 0) { if (p % 2 == 0) { a = (a * a) % mod; p /= 2; } else { res = (res * a) % mod; p--; } } return res; } public static int countPrimeInRange(int n, boolean isPrime[]) { int cnt = 0; for (int i = 2; i * i <= n; i++) { if (isPrime[i]) { for (int j = i * 2; j <= n; j += i) { isPrime[j] = false; } } } for (int i = 2; i <= n; i++) { if (isPrime[i]) { cnt++; } } return cnt; } public static void create(long num) { luc.add(num); if (num > power(10, 9)) { return; } create(num * 10 + 4); create(num * 10 + 7); } public static long ceil(long a, long b) { return (a + b - 1) / b; } public static long round(long a, long b) { if (a < 0) { return (a - b / 2) / b; } return (a + b / 2) / b; } public static void allPremutationsst(LinkedList<String> l, boolean visited[], ArrayList<String> st) { if (l.size() == st.size()) { allprems.add(l); } for (int i = 0; i < st.size(); i++) { if (!visited[i]) { visited[i] = true; LinkedList<String> nl = new LinkedList<>(); for (String x : l) { nl.add(x); } nl.add(st.get(i)); allPremutationsst(nl, visited, st); visited[i] = false; } } } public static void allPremutations(LinkedList<Integer> l, boolean visited[], int a[]) { if (l.size() == a.length) { allprem.add(l); } for (int i = 0; i < a.length; i++) { if (!visited[i]) { visited[i] = true; LinkedList<Integer> nl = new LinkedList<>(); for (Integer x : l) { nl.add(x); } nl.add(a[i]); allPremutations(nl, visited, a); visited[i] = false; } } } public static int binarySearch(long[] a, long value) { int l = 0; int r = a.length - 1; while (l <= r) { int m = (l + r) / 2; if (a[m] == value) { return m; } else if (a[m] > value) { r = m - 1; } else { l = m + 1; } } return -1; } public static void reverse(int l, int r, char ch[]) { for (int i = 0; i < r / 2; i++) { char c = ch[i]; ch[i] = ch[r - i - 1]; ch[r - i - 1] = c; } } public static int logK(long v, long k) { int ans = 0; while (v > 1) { ans++; v /= k; } return ans; } public static long power(long a, long n) { if (n == 1) { return a; } long pow = power(a, n / 2); pow *= pow; if (n % 2 != 0) { pow *= a; } return pow; } public static long get(long max, long x) { if (x == 1) { return max; } int cnt = 0; while (max > 0) { cnt++; max /= x; } return cnt; } public static int numOF0(long v) { long x = 1; int cnt = 0; while (x <= v) { if ((x & v) == 0) { cnt++; } x <<= 1; } return cnt; } public static int log2(double n) { int cnt = 0; while (n > 1) { n /= 2; cnt++; } return cnt; } public static int[] bfs(int node, ArrayList<Integer> a[]) { Queue<Integer> q = new LinkedList<>(); q.add(node); int distances[] = new int[a.length]; Arrays.fill(distances, -1); distances[node] = 0; while (!q.isEmpty()) { int parent = q.poll(); ArrayList<Integer> nodes = a[parent]; int cost = distances[parent]; for (Integer node1 : nodes) { if (distances[node1] == -1) { q.add(node1); distances[node1] = cost + 1; } } } return distances; } public static int get(int n) { int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } return sum; } public static ArrayList<Integer> primeFactors(int n) { ArrayList<Integer> a = new ArrayList<>(); while (n % 2 == 0) { a.add(2); n /= 2; } for (int i = 3; i <= Math.sqrt(n); i += 2) { while (n % i == 0) { a.add(i); n /= i; } if (n < i) { break; } } if (n > 2) { a.add(n); } return a; } public static ArrayList<Integer> printPrimeFactoriztion(int n) { ArrayList<Integer> a = new ArrayList<>(); for (int i = 1; i < Math.sqrt(n) + 1; i++) { if (n % i == 0) { if (isPrime(i)) { a.add(i); n /= i; i = 0; } else if (isPrime(n / i)) { a.add(n / i); n = i; i = 0; } } } return a; } // end of solution public static BigInteger f(long n) { if (n <= 1) { return BigInteger.ONE; } long t = n - 1; BigInteger b = new BigInteger(t + ""); BigInteger ans = new BigInteger(n + ""); while (t > 1) { ans = ans.multiply(b); b = b.subtract(BigInteger.ONE); t--; } return ans; } public static long factorial(long n) { if (n <= 1) { return 1; } long t = n - 1; while (t > 1) { n = mod((mod(n, mod) * mod(t, mod)), mod); t--; } return n; } public static long rev(long n) { long t = n; long ans = 0; while (t > 0) { ans = ans * 10 + t % 10; t /= 10; } return ans; } public static boolean isPalindrome(int n) { int t = n; int ans = 0; while (t > 0) { ans = ans * 10 + t % 10; t /= 10; } return ans == n; } static class tri { int x, y, z; public tri(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } @Override public String toString() { return x + " " + y + " " + z; } } static boolean isPrime(long num) { if (num == 1) { return false; } if (num == 2) { return true; } if (num % 2 == 0) { return false; } if (num == 3) { return true; } for (int i = 3; i <= Math.sqrt(num) + 1; i += 2) { if (num % i == 0) { return false; } } return true; } public static void prefixSum(int[] a) { for (int i = 1; i < a.length; i++) { a[i] = a[i] + a[i - 1]; } } public static void suffixSum(long[] a) { for (int i = a.length - 2; i > -1; i--) { a[i] = a[i] + a[i + 1]; } } static long mod(long a, long b) { long r = a % b; return r < 0 ? r + b : r; } public static long binaryToDecimal(String w) { long r = 0; long l = 0; for (int i = w.length() - 1; i > -1; i--) { long x = (w.charAt(i) - '0') * (long) Math.pow(2, l); r = r + x; l++; } return r; } public static String decimalToBinary(long n) { String w = ""; while (n > 0) { w = n % 2 + w; n /= 2; } return w; } public static boolean isSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] >= a[i + 1]) { return false; } } return true; } public static void print(int[] a) throws IOException { for (int i = 0; i < a.length; i++) { log.write(a[i] + " "); } log.write("\n"); } public static void read(int[] a) { for (int i = 0; i < a.length; i++) { a[i] = input.nextInt(); } } static class pair { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } @Override public String toString() { return x + " " + y; } } static class pai { String x; int y; public pai(String x, int y) { this.x = x; this.y = y; } @Override public String toString() { return x + " " + y; } } public static long LCM(long x, long y) { return x / GCD(x, y) * y; } public static long GCD(long x, long y) { if (y == 0) { return x; } return GCD(y, x % y); } public static void simplifyTheFraction(long a, long b) { long GCD = GCD(a, b); System.out.println(a / GCD + " " + b / GCD); } /** */ // class RedBlackNode static class RedBlackNode<T extends Comparable<T>> { /** * Possible color for this node */ public static final int BLACK = 0; /** * Possible color for this node */ public static final int RED = 1; // the key of each node public T key; /** * Parent of node */ RedBlackNode<T> parent; /** * Left child */ RedBlackNode<T> left; /** * Right child */ RedBlackNode<T> right; // the number of elements to the left of each node public int numLeft = 0; // the number of elements to the right of each node public int numRight = 0; // the color of a node public int color; RedBlackNode() { color = BLACK; numLeft = 0; numRight = 0; parent = null; left = null; right = null; } // Constructor which sets key to the argument. RedBlackNode(T key) { this(); this.key = key; } }// end class RedBlackNode static class RedBlackTree<T extends Comparable<T>> { // Root initialized to nil. private RedBlackNode<T> nil = new RedBlackNode<T>(); private RedBlackNode<T> root = nil; public RedBlackTree() { root.left = nil; root.right = nil; root.parent = nil; } // @param: X, The node which the lefRotate is to be performed on. // Performs a leftRotate around X. private void leftRotate(RedBlackNode<T> x) { // Call leftRotateFixup() which updates the numLeft // and numRight values. leftRotateFixup(x); // Perform the left rotate as described in the algorithm // in the course text. RedBlackNode<T> y; y = x.right; x.right = y.left; // Check for existence of y.left and make pointer changes if (!isNil(y.left)) { y.left.parent = x; } y.parent = x.parent; // X's parent is nul if (isNil(x.parent)) { root = y; } // X is the left child of it's parent else if (x.parent.left == x) { x.parent.left = y; } // X is the right child of it's parent. else { x.parent.right = y; } // Finish of the leftRotate y.left = x; x.parent = y; }// end leftRotate(RedBlackNode X) // @param: X, The node which the leftRotate is to be performed on. // Updates the numLeft & numRight values affected by leftRotate. private void leftRotateFixup(RedBlackNode x) { // Case 1: Only X, X.right and X.right.right always are not nil. if (isNil(x.left) && isNil(x.right.left)) { x.numLeft = 0; x.numRight = 0; x.right.numLeft = 1; } // Case 2: X.right.left also exists in addition to Case 1 else if (isNil(x.left) && !isNil(x.right.left)) { x.numLeft = 0; x.numRight = 1 + x.right.left.numLeft + x.right.left.numRight; x.right.numLeft = 2 + x.right.left.numLeft + x.right.left.numRight; } // Case 3: X.left also exists in addition to Case 1 else if (!isNil(x.left) && isNil(x.right.left)) { x.numRight = 0; x.right.numLeft = 2 + x.left.numLeft + x.left.numRight; } // Case 4: X.left and X.right.left both exist in addtion to Case 1 else { x.numRight = 1 + x.right.left.numLeft + x.right.left.numRight; x.right.numLeft = 3 + x.left.numLeft + x.left.numRight + x.right.left.numLeft + x.right.left.numRight; } }// end leftRotateFixup(RedBlackNode X) // @param: X, The node which the rightRotate is to be performed on. // Updates the numLeft and numRight values affected by the Rotate. private void rightRotate(RedBlackNode<T> y) { // Call rightRotateFixup to adjust numRight and numLeft values rightRotateFixup(y); // Perform the rotate as described in the course text. RedBlackNode<T> x = y.left; y.left = x.right; // Check for existence of X.right if (!isNil(x.right)) { x.right.parent = y; } x.parent = y.parent; // y.parent is nil if (isNil(y.parent)) { root = x; } // y is a right child of it's parent. else if (y.parent.right == y) { y.parent.right = x; } // y is a left child of it's parent. else { y.parent.left = x; } x.right = y; y.parent = x; }// end rightRotate(RedBlackNode y) // @param: y, the node around which the righRotate is to be performed. // Updates the numLeft and numRight values affected by the rotate private void rightRotateFixup(RedBlackNode y) { // Case 1: Only y, y.left and y.left.left exists. if (isNil(y.right) && isNil(y.left.right)) { y.numRight = 0; y.numLeft = 0; y.left.numRight = 1; } // Case 2: y.left.right also exists in addition to Case 1 else if (isNil(y.right) && !isNil(y.left.right)) { y.numRight = 0; y.numLeft = 1 + y.left.right.numRight + y.left.right.numLeft; y.left.numRight = 2 + y.left.right.numRight + y.left.right.numLeft; } // Case 3: y.right also exists in addition to Case 1 else if (!isNil(y.right) && isNil(y.left.right)) { y.numLeft = 0; y.left.numRight = 2 + y.right.numRight + y.right.numLeft; } // Case 4: y.right & y.left.right exist in addition to Case 1 else { y.numLeft = 1 + y.left.right.numRight + y.left.right.numLeft; y.left.numRight = 3 + y.right.numRight + y.right.numLeft + y.left.right.numRight + y.left.right.numLeft; } }// end rightRotateFixup(RedBlackNode y) public void insert(T key) { insert(new RedBlackNode<T>(key)); } // @param: z, the node to be inserted into the Tree rooted at root // Inserts z into the appropriate position in the RedBlackTree while // updating numLeft and numRight values. private void insert(RedBlackNode<T> z) { // Create a reference to root & initialize a node to nil RedBlackNode<T> y = nil; RedBlackNode<T> x = root; // While we haven't reached a the end of the tree keep // tryint to figure out where z should go while (!isNil(x)) { y = x; // if z.key is < than the current key, go left if (z.key.compareTo(x.key) < 0) { // Update X.numLeft as z is < than X x.numLeft++; x = x.left; } // else z.key >= X.key so go right. else { // Update X.numGreater as z is => X x.numRight++; x = x.right; } } // y will hold z's parent z.parent = y; // Depending on the value of y.key, put z as the left or // right child of y if (isNil(y)) { root = z; } else if (z.key.compareTo(y.key) < 0) { y.left = z; } else { y.right = z; } // Initialize z's children to nil and z's color to red z.left = nil; z.right = nil; z.color = RedBlackNode.RED; // Call insertFixup(z) insertFixup(z); }// end insert(RedBlackNode z) // @param: z, the node which was inserted and may have caused a violation // of the RedBlackTree properties // Fixes up the violation of the RedBlackTree properties that may have // been caused during insert(z) private void insertFixup(RedBlackNode<T> z) { RedBlackNode<T> y = nil; // While there is a violation of the RedBlackTree properties.. while (z.parent.color == RedBlackNode.RED) { // If z's parent is the the left child of it's parent. if (z.parent == z.parent.parent.left) { // Initialize y to z 's cousin y = z.parent.parent.right; // Case 1: if y is red...recolor if (y.color == RedBlackNode.RED) { z.parent.color = RedBlackNode.BLACK; y.color = RedBlackNode.BLACK; z.parent.parent.color = RedBlackNode.RED; z = z.parent.parent; } // Case 2: if y is black & z is a right child else if (z == z.parent.right) { // leftRotaet around z's parent z = z.parent; leftRotate(z); } // Case 3: else y is black & z is a left child else { // recolor and rotate round z's grandpa z.parent.color = RedBlackNode.BLACK; z.parent.parent.color = RedBlackNode.RED; rightRotate(z.parent.parent); } } // If z's parent is the right child of it's parent. else { // Initialize y to z's cousin y = z.parent.parent.left; // Case 1: if y is red...recolor if (y.color == RedBlackNode.RED) { z.parent.color = RedBlackNode.BLACK; y.color = RedBlackNode.BLACK; z.parent.parent.color = RedBlackNode.RED; z = z.parent.parent; } // Case 2: if y is black and z is a left child else if (z == z.parent.left) { // rightRotate around z's parent z = z.parent; rightRotate(z); } // Case 3: if y is black and z is a right child else { // recolor and rotate around z's grandpa z.parent.color = RedBlackNode.BLACK; z.parent.parent.color = RedBlackNode.RED; leftRotate(z.parent.parent); } } } // Color root black at all times root.color = RedBlackNode.BLACK; }// end insertFixup(RedBlackNode z) // @param: node, a RedBlackNode // @param: node, the node with the smallest key rooted at node public RedBlackNode<T> treeMinimum(RedBlackNode<T> node) { // while there is a smaller key, keep going left while (!isNil(node.left)) { node = node.left; } return node; }// end treeMinimum(RedBlackNode node) // @param: X, a RedBlackNode whose successor we must find // @return: return's the node the with the next largest key // from X.key public RedBlackNode<T> treeSuccessor(RedBlackNode<T> x) { // if X.left is not nil, call treeMinimum(X.right) and // return it's value if (!isNil(x.left)) { return treeMinimum(x.right); } RedBlackNode<T> y = x.parent; // while X is it's parent's right child... while (!isNil(y) && x == y.right) { // Keep moving up in the tree x = y; y = y.parent; } // Return successor return y; }// end treeMinimum(RedBlackNode X) // @param: z, the RedBlackNode which is to be removed from the the tree // Remove's z from the RedBlackTree rooted at root public void remove(RedBlackNode<T> v) { RedBlackNode<T> z = search(v.key); // Declare variables RedBlackNode<T> x = nil; RedBlackNode<T> y = nil; // if either one of z's children is nil, then we must remove z if (isNil(z.left) || isNil(z.right)) { y = z; } // else we must remove the successor of z else { y = treeSuccessor(z); } // Let X be the left or right child of y (y can only have one child) if (!isNil(y.left)) { x = y.left; } else { x = y.right; } // link X's parent to y's parent x.parent = y.parent; // If y's parent is nil, then X is the root if (isNil(y.parent)) { root = x; } // else if y is a left child, set X to be y's left sibling else if (!isNil(y.parent.left) && y.parent.left == y) { y.parent.left = x; } // else if y is a right child, set X to be y's right sibling else if (!isNil(y.parent.right) && y.parent.right == y) { y.parent.right = x; } // if y != z, trasfer y's satellite data into z. if (y != z) { z.key = y.key; } // Update the numLeft and numRight numbers which might need // updating due to the deletion of z.key. fixNodeData(x, y); // If y's color is black, it is a violation of the // RedBlackTree properties so call removeFixup() if (y.color == RedBlackNode.BLACK) { removeFixup(x); } }// end remove(RedBlackNode z) // @param: y, the RedBlackNode which was actually deleted from the tree // @param: key, the value of the key that used to be in y private void fixNodeData(RedBlackNode<T> x, RedBlackNode<T> y) { // Initialize two variables which will help us traverse the tree RedBlackNode<T> current = nil; RedBlackNode<T> track = nil; // if X is nil, then we will start updating at y.parent // Set track to y, y.parent's child if (isNil(x)) { current = y.parent; track = y; } // if X is not nil, then we start updating at X.parent // Set track to X, X.parent's child else { current = x.parent; track = x; } // while we haven't reached the root while (!isNil(current)) { // if the node we deleted has a different key than // the current node if (y.key != current.key) { // if the node we deleted is greater than // current.key then decrement current.numRight if (y.key.compareTo(current.key) > 0) { current.numRight--; } // if the node we deleted is less than // current.key thendecrement current.numLeft if (y.key.compareTo(current.key) < 0) { current.numLeft--; } } // if the node we deleted has the same key as the // current node we are checking else { // the cases where the current node has any nil // children and update appropriately if (isNil(current.left)) { current.numLeft--; } else if (isNil(current.right)) { current.numRight--; } // the cases where current has two children and // we must determine whether track is it's left // or right child and update appropriately else if (track == current.right) { current.numRight--; } else if (track == current.left) { current.numLeft--; } } // update track and current track = current; current = current.parent; } }//end fixNodeData() // @param: X, the child of the deleted node from remove(RedBlackNode v) // Restores the Red Black properties that may have been violated during // the removal of a node in remove(RedBlackNode v) private void removeFixup(RedBlackNode<T> x) { RedBlackNode<T> w; // While we haven't fixed the tree completely... while (x != root && x.color == RedBlackNode.BLACK) { // if X is it's parent's left child if (x == x.parent.left) { // set w = X's sibling w = x.parent.right; // Case 1, w's color is red. if (w.color == RedBlackNode.RED) { w.color = RedBlackNode.BLACK; x.parent.color = RedBlackNode.RED; leftRotate(x.parent); w = x.parent.right; } // Case 2, both of w's children are black if (w.left.color == RedBlackNode.BLACK && w.right.color == RedBlackNode.BLACK) { w.color = RedBlackNode.RED; x = x.parent; } // Case 3 / Case 4 else { // Case 3, w's right child is black if (w.right.color == RedBlackNode.BLACK) { w.left.color = RedBlackNode.BLACK; w.color = RedBlackNode.RED; rightRotate(w); w = x.parent.right; } // Case 4, w = black, w.right = red w.color = x.parent.color; x.parent.color = RedBlackNode.BLACK; w.right.color = RedBlackNode.BLACK; leftRotate(x.parent); x = root; } } // if X is it's parent's right child else { // set w to X's sibling w = x.parent.left; // Case 1, w's color is red if (w.color == RedBlackNode.RED) { w.color = RedBlackNode.BLACK; x.parent.color = RedBlackNode.RED; rightRotate(x.parent); w = x.parent.left; } // Case 2, both of w's children are black if (w.right.color == RedBlackNode.BLACK && w.left.color == RedBlackNode.BLACK) { w.color = RedBlackNode.RED; x = x.parent; } // Case 3 / Case 4 else { // Case 3, w's left child is black if (w.left.color == RedBlackNode.BLACK) { w.right.color = RedBlackNode.BLACK; w.color = RedBlackNode.RED; leftRotate(w); w = x.parent.left; } // Case 4, w = black, and w.left = red w.color = x.parent.color; x.parent.color = RedBlackNode.BLACK; w.left.color = RedBlackNode.BLACK; rightRotate(x.parent); x = root; } } }// end while // set X to black to ensure there is no violation of // RedBlack tree Properties x.color = RedBlackNode.BLACK; }// end removeFixup(RedBlackNode X) // @param: key, the key whose node we want to search for // @return: returns a node with the key, key, if not found, returns null // Searches for a node with key k and returns the first such node, if no // such node is found returns null public RedBlackNode<T> search(T key) { // Initialize a pointer to the root to traverse the tree RedBlackNode<T> current = root; // While we haven't reached the end of the tree while (!isNil(current)) { // If we have found a node with a key equal to key if (current.key.equals(key)) // return that node and exit search(int) { return current; } // go left or right based on value of current and key else if (current.key.compareTo(key) < 0) { current = current.right; } // go left or right based on value of current and key else { current = current.left; } } // we have not found a node whose key is "key" return null; }// end search(int key) // @param: key, any Comparable object // @return: return's the number of elements greater than key public int numGreater(T key) { // Call findNumGreater(root, key) which will return the number // of nodes whose key is greater than key return findNumGreater(root, key); }// end numGreater(int key) // @param: key, any Comparable object // @return: return's teh number of elements smaller than key public int numSmaller(T key) { // Call findNumSmaller(root,key) which will return // the number of nodes whose key is greater than key return findNumSmaller(root, key); }// end numSmaller(int key) // @param: node, the root of the tree, the key who we must // compare other node key's to. // @return: the number of nodes greater than key. public int findNumGreater(RedBlackNode<T> node, T key) { // Base Case: if node is nil, return 0 if (isNil(node)) { return 0; } // If key is less than node.key, all elements right of node are // greater than key, add this to our total and look to the left else if (key.compareTo(node.key) < 0) { return 1 + node.numRight + findNumGreater(node.left, key); } // If key is greater than node.key, then look to the right as // all elements to the left of node are smaller than key else { return findNumGreater(node.right, key); } }// end findNumGreater(RedBlackNode, int key) /** * Returns sorted list of keys greater than key. Size of list will not * exceed maxReturned * * @param key Key to search for * @param maxReturned Maximum number of results to return * @return List of keys greater than key. List may not exceed * maxReturned */ public List<T> getGreaterThan(T key, Integer maxReturned) { List<T> list = new ArrayList<T>(); getGreaterThan(root, key, list); return list.subList(0, Math.min(maxReturned, list.size())); } private void getGreaterThan(RedBlackNode<T> node, T key, List<T> list) { if (isNil(node)) { return; } else if (node.key.compareTo(key) > 0) { getGreaterThan(node.left, key, list); list.add(node.key); getGreaterThan(node.right, key, list); } else { getGreaterThan(node.right, key, list); } } // @param: node, the root of the tree, the key who we must compare other // node key's to. // @return: the number of nodes smaller than key. public int findNumSmaller(RedBlackNode<T> node, T key) { // Base Case: if node is nil, return 0 if (isNil(node)) { return 0; } // If key is less than node.key, look to the left as all // elements on the right of node are greater than key else if (key.compareTo(node.key) <= 0) { return findNumSmaller(node.left, key); } // If key is larger than node.key, all elements to the left of // node are smaller than key, add this to our total and look // to the right. else { return 1 + node.numLeft + findNumSmaller(node.right, key); } }// end findNumSmaller(RedBlackNode nod, int key) // @param: node, the RedBlackNode we must check to see whether it's nil // @return: return's true of node is nil and false otherwise private boolean isNil(RedBlackNode node) { // return appropriate value return node == nil; }// end isNil(RedBlackNode node) // @return: return's the size of the tree // Return's the # of nodes including the root which the RedBlackTree // rooted at root has. public int size() { // Return the number of nodes to the root's left + the number of // nodes on the root's right + the root itself. return root.numLeft + root.numRight + 1; }// end size() }// end class RedBlackTree }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
80adea4464b3b7ac8071caa79d23e3aa
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.util.*; public class Reach{ 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(ans(n)); } return ; } static int ans(int n){ int ANS=0; ANS=n/3; n=n%3; if(n==1 || n==2) ANS+=1; return ANS; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
eece9fe8caed40c6a002fe38fb20a12d
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; /** * @author Nikolay Chistykov */ public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int n = sc.nextInt(); while (n-- > 0) { int t = sc.nextInt(); if (t == 1) { System.out.println(2); continue; } if (t % 3 == 0) { System.out.println(t / 3); } else { if (t < 10) { System.out.println((t / 3) + 1); } else { System.out.println((t / 3) + 1); } } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
03b04f4046e135ed7fb82f7c78b490e2
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 Temp { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for (int i = 0; i < t; i++) { int num = scanner.nextInt(); int moves; if (num == 2 || num == 3) { moves = 1; } else if (num == 1 || num == 5 || num == 4 || num == 6) { moves = 2; } else if (num % 3 == 0) { moves = num/3; } else { moves = (num/3)+1; } System.out.println(moves); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
5238a8fae1011380ea4787df0e295bdf
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 MainClass{ static class Reader{ private final BufferedReader reader; private StringTokenizer tokenizer; Reader(InputStream input) { this.reader = new BufferedReader(new InputStreamReader(input)); this.tokenizer = new StringTokenizer(""); } public String next() throws IOException { while(!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for(int i=0;i<n;i++)arr[i]=nextInt(); return arr; } public long[] nextLongArr(int n)throws IOException { long[] arr = new long[n]; for(int i=0;i<n;i++)arr[i]=nextLong(); return arr; } public char[] nextCharArr(int n) throws IOException { char[] arr = new char[n]; for(int i=0;i<n;i++)arr[i] = next().charAt(0); return arr; } } public static void main(String[] args) throws IOException { Reader scan = new Reader(System.in); // int t = 1; int t = scan.nextInt(); StringBuffer sb = new StringBuffer(); BufferedOutputStream b = new BufferedOutputStream(System.out); while(t-->0) { int n = scan.nextInt(); sb.append(solve(n)).append("\n"); } b.write((sb.toString()).getBytes()); b.flush(); } static int solve(int n) { if(n==1)return 2; int three = n/3; if(n%3==0)return three; else if(n%3==1)return three-1+2; return three+1; } static int HCF(int a, int b) { if(a == 0)return b; return HCF(b%a, a); } } class Pair { String s; int idx; Pair(String string, int idx) { this.s = string; this.idx = idx; } public int length(){ return this.s.length(); } } class comp2 implements Comparator<Pair> { @Override public int compare(Pair a, Pair b) { return b.s.length() - a.s.length(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
9e0c6f894faa0f41a9db5c6a76edebfc
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 TwoThreeMoves { public static void main(String[] args) { Scanner kb = new Scanner(System.in); int t = kb.nextInt(); while(t-->0){ int n = kb.nextInt(); int time =0; if(n == 1) time = 2; else if(n % 3 == 0){ time = n/3; } else if(n%3 == 2){ time = n/3 + 1; } else if(n%3 == 1){ time = n/3 + 1; } System.out.println(time); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
8004b60aa938002933931d47560a7f6c
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 Solution { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int T= sc.nextInt(); for(int t=0;t<T;t++){ int n=sc.nextInt(); int[] add= {0,2,1,1,2,2}; if(n<3)System.out.println(add[n]); else System.out.println(((n-n%3)/3-1+add[n%3+3])); /* 0- 0 1- +3-2 2- +2 3 +3 4- +2+2 5 +3 +2 6 +3 +3 7 +3 +2 +2 3k+0,1,2,3,4,5 8 +3 +3 +2 9 +3 +3 +3 10 +3 +3 +2 +2 11 +3 +3 +3 +2 */ } //System.out.println("Hello, World!"); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
47c094c3067f4c33005dd7d1a87bb82e
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 Main { 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(); long ans=0; if(n==1) { System.out.println("2"); } else { ans=n/3; if(n%3==0) { ans+=0; } else { ans+=1; } System.out.println(ans); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
094ae904aab2ab9d2ea8ca37a33b003a
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 tests { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int a =scanner.nextInt(); for(int i = 0; i < a; i++) { int b = scanner.nextInt(); int res = b/3; int tmp = b%3; if(b == 1) res = 2; else if(tmp != 0) res += 1; System.out.println(res); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
0f9476425bd799e5d9f10ebf8ef3c740
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 A { public static void main(String args[]) throws IOException { FastReader sc = new FastReader(); PrintWriter out = new PrintWriter(System.out); int tc, i, j; String s; char p; tc = sc.nextInt(); while (tc-- > 0) { int n = sc.nextInt(); 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(((n-2)/3)+2); } } out.close(); } /*-------------------------------------------------------- ----------------------------------------------------------*/ //Pair Class public static class Pair implements Comparable<Pair> { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return this.x - o.x; } } /* FASTREADER */ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } /*DEFINED BY ME*/ //READING ARRAY int[] readArray(int n) { int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } //COLLECTIONS SORT void sort(int arr[]) { ArrayList<Integer> l = new ArrayList<>(); for (int i : arr) l.add(i); Collections.sort(l); for (int i = 0; i < arr.length; i++) arr[i] = l.get(i); } //EUCLID'S GCD int gcd(int a, int b) { if (b != 0) return gcd(b, a % b); else return a; } void swap(int arr[], int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
d6251d68cce6934d9f69f7fe33b6c2e7
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.function.*; import java.io.*; // you can compare with output.txt and expected out public class RoundEdu133A { MyPrintWriter out; MyScanner in; // final static long FIXED_RANDOM; // static { // FIXED_RANDOM = System.currentTimeMillis(); // } final static String IMPOSSIBLE = "IMPOSSIBLE"; final static String POSSIBLE = "POSSIBLE"; final static String YES = "YES"; final static String NO = "NO"; private void initIO(boolean isFileIO) { if (System.getProperty("ONLINE_JUDGE") == null && isFileIO) { try{ in = new MyScanner(new FileInputStream("input.txt")); out = new MyPrintWriter(new FileOutputStream("output.txt")); } catch(FileNotFoundException e){ e.printStackTrace(); } } else{ in = new MyScanner(System.in); out = new MyPrintWriter(new BufferedOutputStream(System.out)); } } public static void main(String[] args){ // Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); RoundEdu133A sol = new RoundEdu133A(); sol.run(); } private void run() { boolean isDebug = false; boolean isFileIO = true; boolean hasMultipleTests = true; initIO(isFileIO); int t = hasMultipleTests? in.nextInt() : 1; for (int i = 1; i <= t; ++i) { if(isDebug){ out.printf("Test %d\n", i); } getInput(); solve(); printOutput(); } in.close(); out.close(); } // use suitable one between matrix(2, n) or matrix(n, 2) for graph edges, pairs, ... int n; void getInput() { n = in.nextInt(); } void printOutput() { out.printlnAns(ans); } int ans; void solve(){ if(n % 3 == 0) { ans = n/3; return; } if(n == 1){ ans = 2; return; } else if(n % 3 == 1) { // 2 -> 4 -> 7 -> 10 ans = n/3 + 1; return; } else { // 2 // 2 -> 5 -> 8 ans = n/3 + 1; return; } } static class Pair implements Comparable<Pair>{ final static long FIXED_RANDOM = System.currentTimeMillis(); int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } @Override public int hashCode() { // http://xorshift.di.unimi.it/splitmix64.c long x = first; x <<= 32; x += second; x += FIXED_RANDOM; x += 0x9e3779b97f4a7c15l; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9l; x = (x ^ (x >> 27)) * 0x94d049bb133111ebl; return (int)(x ^ (x >> 31)); } @Override public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; Pair other = (Pair) obj; return first == other.first && second == other.second; } @Override public String toString() { return "[" + first + "," + second + "]"; } @Override public int compareTo(Pair o) { int cmp = Integer.compare(first, o.first); return cmp != 0? cmp: Integer.compare(second, o.second); } } public static class MyScanner { BufferedReader br; StringTokenizer st; // 32768? public MyScanner(InputStream is, int bufferSize) { br = new BufferedReader(new InputStreamReader(is), bufferSize); } public MyScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); // br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); } public void close() { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } 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[][] nextMatrix(int n, int m) { return nextMatrix(n, m, 0); } int[][] nextMatrix(int n, int m, int offset) { int[][] mat = new int[n][m]; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { mat[i][j] = nextInt()+offset; } } return mat; } int[] nextIntArray(int len) { return nextIntArray(len, 0); } int[] nextIntArray(int len, int offset){ int[] a = new int[len]; for(int j=0; j<len; j++) a[j] = nextInt()+offset; return a; } long[] nextLongArray(int len) { return nextLongArray(len, 0); } long[] nextLongArray(int len, int offset){ long[] a = new long[len]; for(int j=0; j<len; j++) a[j] = nextLong()+offset; return a; } String[] nextStringArray(int len) { String[] s = new String[len]; for(int i=0; i<len; i++) s[i] = next(); return s; } } public static class MyPrintWriter extends PrintWriter{ public MyPrintWriter(OutputStream os) { super(os); } public void printlnAns(long ans) { println(ans); } public void printlnAns(int ans) { println(ans); } public void printlnAns(boolean ans) { if(ans) println(YES); else println(NO); } public void printAns(long[] arr){ if(arr != null && arr.length > 0){ print(arr[0]); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]); } } } public void printlnAns(long[] arr){ printAns(arr); println(); } public void printAns(int[] arr){ if(arr != null && arr.length > 0){ print(arr[0]); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]); } } } public void printlnAns(int[] arr){ printAns(arr); println(); } public <T> void printAns(ArrayList<T> arr){ if(arr != null && arr.size() > 0){ print(arr.get(0)); for(int i=1; i<arr.size(); i++){ print(" "); print(arr.get(i)); } } } public <T> void printlnAns(ArrayList<T> arr){ printAns(arr); println(); } public void printAns(int[] arr, int add){ if(arr != null && arr.length > 0){ print(arr[0]+add); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]+add); } } } public void printlnAns(int[] arr, int add){ printAns(arr, add); println(); } public void printAns(ArrayList<Integer> arr, int add) { if(arr != null && arr.size() > 0){ print(arr.get(0)+add); for(int i=1; i<arr.size(); i++){ print(" "); print(arr.get(i)+add); } } } public void printlnAns(ArrayList<Integer> arr, int add){ printAns(arr, add); println(); } public void printlnAnsSplit(long[] arr, int split){ if(arr != null){ for(int i=0; i<arr.length; i+=split){ print(arr[i]); for(int j=i+1; j<i+split; j++){ print(" "); print(arr[j]); } println(); } } } public void printlnAnsSplit(int[] arr, int split){ if(arr != null){ for(int i=0; i<arr.length; i+=split){ print(arr[i]); for(int j=i+1; j<i+split; j++){ print(" "); print(arr[j]); } println(); } } } public <T> void printlnAnsSplit(ArrayList<T> arr, int split){ if(arr != null && !arr.isEmpty()){ for(int i=0; i<arr.size(); i+=split){ print(arr.get(i)); for(int j=i+1; j<i+split; j++){ print(" "); print(arr.get(j)); } println(); } } } } static private void permutateAndSort(long[] a) { int n = a.length; Random R = new Random(System.currentTimeMillis()); for(int i=0; i<n; i++) { int t = R.nextInt(n-i); long temp = a[n-1-i]; a[n-1-i] = a[t]; a[t] = temp; } Arrays.sort(a); } static private void permutateAndSort(int[] a) { int n = a.length; Random R = new Random(System.currentTimeMillis()); for(int i=0; i<n; i++) { int t = R.nextInt(n-i); int temp = a[n-1-i]; a[n-1-i] = a[t]; a[t] = temp; } Arrays.sort(a); } static private int[][] constructChildren(int n, int[] parent, int parentRoot){ int[][] childrens = new int[n][]; int[] numChildren = new int[n]; for(int i=0; i<parent.length; i++) { if(parent[i] != parentRoot) numChildren[parent[i]]++; } for(int i=0; i<n; i++) { childrens[i] = new int[numChildren[i]]; } int[] idx = new int[n]; for(int i=0; i<parent.length; i++) { if(parent[i] != parentRoot) childrens[parent[i]][idx[parent[i]]++] = i; } return childrens; } static private int[][][] constructDirectedNeighborhood(int n, int[][] e){ int[] inDegree = new int[n]; int[] outDegree = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; outDegree[u]++; inDegree[v]++; } int[][] inNeighbors = new int[n][]; int[][] outNeighbors = new int[n][]; for(int i=0; i<n; i++) { inNeighbors[i] = new int[inDegree[i]]; outNeighbors[i] = new int[outDegree[i]]; } for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; outNeighbors[u][--outDegree[u]] = v; inNeighbors[v][--inDegree[v]] = u; } return new int[][][] {inNeighbors, outNeighbors}; } static private int[][] constructNeighborhood(int n, int[][] e) { int[] degree = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; degree[u]++; degree[v]++; } int[][] neighbors = new int[n][]; for(int i=0; i<n; i++) neighbors[i] = new int[degree[i]]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; neighbors[u][--degree[u]] = v; neighbors[v][--degree[v]] = u; } return neighbors; } static private void drawGraph(int[][] e) { makeDotUndirected(e); try { final Process process = new ProcessBuilder("dot", "-Tpng", "graph.dot") .redirectOutput(new File("graph.png")) .start(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } static private void makeDotUndirected(int[][] e) { MyPrintWriter out2 = null; try { out2 = new MyPrintWriter(new FileOutputStream("graph.dot")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } out2.println("strict graph {"); for(int i=0; i<e.length; i++){ out2.println(e[i][0] + "--" + e[i][1] + ";"); } out2.println("}"); out2.close(); } static private void makeDotDirected(int[][] e) { MyPrintWriter out2 = null; try { out2 = new MyPrintWriter(new FileOutputStream("graph.dot")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } out2.println("strict digraph {"); for(int i=0; i<e.length; i++){ out2.println(e[i][0] + "->" + e[i][1] + ";"); } out2.println("}"); out2.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
fb82003bd05328d7bcd33bd274f5f99a
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(), num; for (int i = 0; i < t; i++) System.out.println((num = sc.nextInt()) / 3 + (num != 1 ? Math.min(1, num % 3) : 2)); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
4cd7d2a2cc72deb7c6f3fb30dedae0e2
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[]) { try (Scanner in = new Scanner(System.in)) { int t; t=in.nextInt(); int n; while(t>0) { n=in.nextInt(); int d=n%3; int a=(int)(n/3); if(n==1) System.out.println(a+2); else if(d==2 || d==1) System.out.println(a+1); else if(d==0) System.out.println(a); t--; } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
78faab994cac3448703a1ceea930fb4a
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; public class TwoToThreeMoves { public static void main(String[]args) throws NumberFormatException, IOException { InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); int t = Integer.parseInt(br.readLine()); for(int i =0; i<t; i++) { int n = Integer.parseInt(br.readLine()); int steps = n/3; if(n==1) { System.out.println(2); continue; } n = n -(3*steps); if(n!=0) { steps+=1; } System.out.println(steps); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
ae236ff82a900b90c645d955f98f319b
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[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); if(n%3==0) System.out.println(n/3); else if(n%3==1) System.out.println((n-2)/3+2); 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 17
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
e686748a63337f64bdf42a92c0c5d1a2
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 temp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); for (int k = 1; k <= t; k++ ){ int n=sc.nextInt(); if (n==1) System.out.println(2); else System.out.println((int)(Math.ceil(n/3.0))); } sc.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
c32c26de83193f816ae71b0449760244
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 temp { public static void main(String[] args) { Scanner inp = new Scanner(System.in); int t=inp.nextInt(); for (int kase = 1; kase <= t; kase++ ){ int n=inp.nextInt(); if (n==1) System.out.println(2); else System.out.println((int)(Math.ceil(n/3.0))); } inp.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
44ab52cf6f8006112b77c7d65f5d0b52
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; /** * 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. */ public class Moves2Or3 { private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { int testCases = Integer.parseInt(reader.readLine()); for (int i = 0; i < testCases; i++) { countMinutes(); } } private static void countMinutes() throws IOException { long goal = Long.parseLong(reader.readLine()); if (goal == 1) { System.out.println(2); return; } else if (goal == 2) { System.out.println(1); return; } else if (goal == 3) { System.out.println(1); return; } long theRest = (goal - 3) / 3; if (goal % 3 == 0) { System.out.println(goal / 3); return; } System.out.println((goal) / 3 + 1); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
51a0948085ebbf38751094e23d49bd6a
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.nio.file.FileSystemNotFoundException; import java.util.*; public class five { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int i =0;i<t;i++){ int n = s.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 17
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
889257abd62fd03ddb26c71e6a90820d
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.abs; import static java.lang.Math.min; import static java.lang.Math.max; import static java.lang.Math.log; import java.util.*; import java.lang.*; import java.io.*; public class a_Codeforces { public static void main(String[] args) throws java.lang.Exception { FastReader sc = new FastReader(); FastWriter out = new FastWriter(); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); if (n == 1) { out.println(2); continue; } if (n == 2) { out.println(1); continue; } if (n % 3 == 0) { out.println(n / 3); } else if (n % 3 == 2) { out.println(n / 3 + 1); } else { out.println(n / 3 + 1); } } out.close(); } /* * int[] arr = new int[n]; * for (int i=0; i<n; i++){ * arr[i] = sc.nextInt(); * } */ 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(); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
707beb4ffbfe5ee077b810bdbe9f1780
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 c1716a { 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%3==0) System.out.println(n/3); else if(n==1) System.out.println(2); 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 17
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
a3b9ed5a66a5b186c80bd7de6ba17ca6
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 Test { public static void main (String[]args) { Scanner sc=new Scanner (System.in); int test=sc.nextInt(); while(test-->0) { int n=sc.nextInt(); n=Math.abs(n); if(n==1)System.out.println(2); else if(n%3==0) System.out.println(n/3); else System.out.println(n/3+1); } sc.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
96ef18003a463de487842cd80825aa1b
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 in = new Scanner(System.in); int t = in.nextInt(); for(int i = 0;i<t;i++){ int n = in.nextInt(); int rem = n/3; if(n == 1){System.out.println(2); } else if(n%3 == 0){ System.out.println(n/3); } else{ System.out.println(rem+1); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
e03a47eec9afd4bec0ba84a2a0143156
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[]) { // Your code goes here int t; Scanner sc=new Scanner (System.in); t=sc.nextInt(); for(int k=0;k<t;k++) { int n,q; n=sc.nextInt(); if(n==1) { System.out.println("2"); continue; } q=n/3; if(n%3==0) System.out.println(q); else System.out.println(q+1); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
241df3f3c136627ec6b62f4f6bf8c1d1
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 solution{ 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; } if(n==2){ System.out.println("1"); continue; } if(n%3==0) { System.out.println(n/3); continue; } System.out.println((n/3)+1); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
cc3311a1a20aa55aa4ae215875e034ee
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 com.tdorosz._1716; import java.util.Scanner; public class Moves23 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int testCases = scanner.nextInt(); for (int i = 0; i < testCases; i++) { executeTestCase(scanner); } } private static void executeTestCase(Scanner scanner) { int goal = scanner.nextInt(); int steps3 = (goal - 3) / 3; int theRest = goal - steps3 * 3; int result = steps3; switch (theRest) { case 0: break; case 1: case 4: case 5: result += 2; break; case 3: case 2: result += 1; break; } System.out.println(result); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
21907bc94bb13433b7c46acaffab0d0b
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 J_1716A { public static void main(String argv[]) { Scanner x=new Scanner(System.in); int t=x.nextInt(); for(int i=0;i<t;i++) { int s=0; int n=Math.abs(x.nextInt()); if(n==1) System.out.println("2"); else if(n==2) System.out.println("1"); else if (n%3==0) System.out.println(n/3); 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 17
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
254eec99e2865120984ffa8001b08f39
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) { //write your code here Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int tt = 0; tt < t; tt++) { double n=sc.nextDouble(); if(n==1){ System.out.println(2); } if(n>=2){ double x=n/3; System.out.println((int)Math.ceil(x)); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
e36853f4f0f1a5dda0cd2e864a8d1f45
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 void main(String []args){ Scanner sc=new Scanner (System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); if(n==1 || n==4) System.out.println(2); else { int d=n/3; int r=n%3; if(r==0) System.out.println(d); else System.out.println(d+1); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
075540f43cc5ad16487002ed7086e940
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 Test { public static void main(String[] args) throws IOException { Reader rd = new Reader(); int t = rd.nextInt(); while (t-- > 0) { long n = rd.nextLong(); long twoMovesOnly = Long.MAX_VALUE, threePlusOneAndTwo = Long.MAX_VALUE, threeAndTwo = Long.MAX_VALUE; long dest1 = 0, dest2 = 0, dest3 = 0; //Base Cases if (n <= 3L) { if (n == 1L) System.out.println("2"); else System.out.println("1"); continue; } twoMovesOnly = n % 2L == 0L ? n / 2L : (n / 2L) + 3L; dest1 = n % 2L == 0L ? 2L * twoMovesOnly : 2L * ((n / 2L) + 2L) - 3L; //when the remainder is 0 or 1 after dividing it by 3 threePlusOneAndTwo = n % 3L == 0L ? n / 3L : (n / 3L) + 2L; dest2 = n % 3L == 0L ? 3L * (n / 3L) : 3L * ((n / 3L) + 1L) - 2L; //when the remainder is 2 after diving it by 3 threeAndTwo = n < 3L ? (n / 3L) + 2L : (n / 3L) + 1L; dest3 = 3L * (n / 3L) + 2L; // System.out.println(twoMovesOnly + " ==> " + dest1); // System.out.println(threePlusOneAndTwo + " ==> " + dest2); // System.out.println(threeAndTwo + " ==> " + dest3); long ans = Math.min(twoMovesOnly, Math.min(threeAndTwo, threePlusOneAndTwo)); System.out.println(ans); // System.out.println(); } rd.close(); } /** * method to print int value in console output **/ private static void debug(int value) { if (System.getProperty("ONLINE_JUDGE") == null) { System.out.println("int value = " + value); } } /** * method to print int value in console output with a text message **/ private static void debug(int value, String message) { if (System.getProperty("ONLINE_JUDGE") == null) { if (message.charAt(message.length() - 1) != ' ') message += " "; System.out.println(message + "" + value); } } /** * method to print long value in console output **/ private static void debug(long value) { if (System.getProperty("ONLINE_JUDGE") == null) { System.out.println("long value = " + value); } } /** * method to print long value in console output with a text message **/ private static void debug(long value, String message) { if (System.getProperty("ONLINE_JUDGE") == null) { if (message.charAt(message.length() - 1) != ' ') message += " "; System.out.println(message + "" + value); } } /** * method to print String value in console output **/ private static void debug(String value) { if (System.getProperty("ONLINE_JUDGE") == null) { System.out.println("String value = " + value); } } /** * method to print String value in console output with a text message **/ private static void debug(String value, String message) { if (System.getProperty("ONLINE_JUDGE") == null) { if (message.charAt(message.length() - 1) != ' ') message += " "; System.out.println(message + "" + value); } } /** * method to print character value in console output **/ private static void debug(char value) { if (System.getProperty("ONLINE_JUDGE") == null) { System.out.println("Character value = " + value); } } /** * method to print character value in console output with a text message **/ private static void debug(char value, String message) { if (System.getProperty("ONLINE_JUDGE") == null) { if (message.charAt(message.length() - 1) != ' ') message += " "; System.out.println(message + "" + value); } } /** * method to print double value in console output **/ private static void debug(double value) { if (System.getProperty("ONLINE_JUDGE") == null) { System.out.println("Double value = " + value); } } /** * method to print double value in console output with a text message **/ private static void debug(double value, String message) { if (System.getProperty("ONLINE_JUDGE") == null) { if (message.charAt(message.length() - 1) != ' ') message += " "; System.out.println(message + "" + value); } } /** * method to print integer type array value in console output **/ private static void debug(int[] arr) { if (System.getProperty("ONLINE_JUDGE") == null) { int n = arr.length; System.out.print("["); for (int i = 0; i < n; i++) { if (i < n - 1) System.out.print(arr[i] + ", "); else System.out.print(arr[i]); } System.out.println("]"); } } /** * method to print long type array value in console output **/ private static void debug(long[] arr) { if (System.getProperty("ONLINE_JUDGE") == null) { int n = arr.length; System.out.print("["); for (int i = 0; i < n; i++) { if (i < n - 1) System.out.print(arr[i] + ", "); else System.out.print(arr[i]); } System.out.println("]"); } } /** * method to print long type array value in console output **/ private static void debug(String[] arr) { if (System.getProperty("ONLINE_JUDGE") == null) { int n = arr.length; System.out.print("["); for (int i = 0; i < n; i++) { if (i < n - 1) System.out.print(arr[i] + ", "); else System.out.print(arr[i]); } System.out.println("]"); } } /** * method to print char type array value in console output **/ private static void debug(char[] arr) { if (System.getProperty("ONLINE_JUDGE") == null) { int n = arr.length; System.out.print("["); for (int i = 0; i < n; i++) { if (i < n - 1) System.out.print(arr[i] + ", "); else System.out.print(arr[i]); } System.out.println("]"); } } /** * method to print double type array value in console output **/ private static void debug(double[] arr) { if (System.getProperty("ONLINE_JUDGE") == null) { int n = arr.length; System.out.print("["); for (int i = 0; i < n; i++) { if (i < n - 1) System.out.print(arr[i] + ", "); else System.out.print(arr[i]); } System.out.println("]"); } } /** * please ignore the below code as it's just used for * taking faster input in java */ static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
0a30be31bef8d3a78bd48b0980e334c1
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 input = new Scanner(System.in); int T = input.nextInt(); for(int t = 0; t < T; ++ t) { int temp = input.nextInt(); if(temp == 1) { System.out.println(2); } else { temp += 2; System.out.println(temp / 3); } } input.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
a147b066f98ff5c3c7d1e3fa487e16db
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.StringTokenizer; public class TaskA { public static void main(String[] args) { FastScanner in = new FastScanner(); PrintWriter out = new PrintWriter(System.out); TaskA s = new TaskA(); s.solve(in, out); out.flush(); } void solveOne(FastScanner in, PrintWriter out) { int n = in.nextInt(); int ans = Integer.MAX_VALUE; for (int use2 = -2; use2 <= 2; use2++) { int pos = use2 * 2; if ((n - pos) % 3 == 0) { int use3 = (n - pos) / 3; ans = Math.min(ans, Math.abs(use2) + Math.abs(use3)); } } out.println(ans); } void solve(FastScanner in, PrintWriter out) { int t = 1; t = in.nextInt(); for (int tc = 1; tc <= t; tc++) { // out.printf("Case #%d: ", tc); solveOne(in, out); } } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } float nextFloat() { return Float.parseFloat(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
8a1fe7fa524d98c05d09d5ae86f305c7
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; public class _1716A { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int tc = Integer.parseInt(br.readLine()); int n; while (tc-- > 0) { n = Integer.parseInt(br.readLine()); if (n == 1) { System.out.println(2); } else { int ans = (int) Math.ceil(n / 3.0); System.out.println(ans); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
b2e7f4e74a234b744b1c412b24881b3b
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 CP{ public static void main(String[] args){ int t ; Scanner input = new Scanner(System.in); t = input.nextInt(); for (int i = 0 ;i<t ;i++){ int n = input.nextInt(); if (n/3 == 0){ if (n == 1){ System.out.println((2)); } else System.out.println((1)); } else if (n%3 == 0){ System.out.println(n/3); } 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 17
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
06d8336c3091894e4416b03c7cb8c155
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 moves { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); for (int i = 0; i < t; i++) { int n = Integer.parseInt(br.readLine()); if (n == 1) { pw.println(2); continue; } int extra = n % 3; if (extra == 1) { pw.println(2 + (n-4) / 3); } else if (extra == 2) { pw.println(n / 3 + 1); } else { pw.println(n / 3); } } pw.close(); br.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
4e1aceff2e6b10eb457463cb4d2c3314
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.StringTokenizer; public class Solution { static final FastReader fr = new FastReader(); static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextIntegerArray(int N) { int[] A = new int[N]; for(int i = 0; i < N; i++) A[i] = nextInt(); return A; } } public static void solve() { int N = fr.nextInt(); System.out.println((N + 2) / 3 + (N==1 ? 1 : 0)); } public static void main(String[] args) { int T = fr.nextInt(); for(int tc = 1; tc <= T; tc++) { solve(); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
d0edb9f450cc024e1fac93025427dccd
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 javax.lang.model.util.ElementScanner14; public class pavan { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); long t = sc.nextLong(); while(t > 0) { long n = sc.nextLong(); long ans; if(n == 1) { ans = 2; } else if(n == 2) { ans = 1; } else if(n%3 == 0) { ans = n/3; } else { ans = n/3 + 1; } output.write(ans + "\n"); t--; } output.flush(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
f72c234c6c1d847b5b080b6926785e79
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(), num; for (int i = 0; i < t; i++) System.out.println((num = sc.nextInt()) / 3 + (num != 1 ? Math.min(1, num % 3) : 2)); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
cb48929a88d151b2dde9e0e2cbe88abb
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 CF1716A { // For fast input output static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { try { br = new BufferedReader( new FileReader("input.txt")); PrintStream out = new PrintStream(new FileOutputStream("output.txt")); System.setOut(out); } catch (Exception e) { br = new BufferedReader(new InputStreamReader(System.in)); } } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // end of fast i/o code public static boolean isPalindrome(String str) { int i = 0; int j = str.length() - 1; int flag = 0; while (i <= j) { if (str.charAt(i) != str.charAt(j)) { flag = 1; break; } i++; j--; } return flag == 1 ? false : true; } public static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } class Pair { int x1; int x2; public Pair(int x1, int x2) { this.x1 = x1; this.x2 = x2; } } public static void main(String[] args) { FastReader fs = new FastReader(); int t=fs.nextInt(); while(t-->0){ int n=fs.nextInt(); if(n==1) System.out.println(2); else if (n==2) System.out.println(1); else{ int temp=n/3; int rem=n-temp*3; if(rem==1) temp+=1; else if(rem==2) temp+=1; System.out.println(temp); } } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
f27ee34beef66c03b29d2f6c48456c0f
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 First; import java.io.*; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.Buffer; import java.util.Scanner; public class MyProject { public static void main(String[] args) { int t; Scanner in = new Scanner(System.in); t = in.nextInt(); while (t > 0) { int n = in.nextInt(); if (n == 1) System.out.println(2); else if(n%3==0) System.out.println(n/3); else System.out.println((n/3)+1); t--; } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
b0c59fe82d897cd0255a1dce392557c7
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 t = in.nextInt(); while(t-->0){ int n = in.nextInt(); System.out.println( (n == 1) ? 2 : (((n + 2) / 3)) ); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
fa8270e6e3b86179bf32a7d30bb50fd9
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 codeforces.rounds.r1716; import java.io.*; public final class A { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int tests = Integer.parseInt(in.readLine().trim()); for (int test = 0; test < tests; test++){ int n = Integer.parseInt(in.readLine().trim()); int ans = solve(n); out.write(ans+"\n"); out.flush(); } } private static int solve(int number) { if (number % 3 == 2){ return (number + 1) / 3; } if (number % 3 == 0){ return number / 3; } return Math.max(((number - 4)) / 3, 0) + 2; } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
f301a506175aab81f17f48c6cb835815
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.PrintWriter; public class MyClass { public static void main(String args[]) { Scanner sc =new Scanner(System.in); int tc = sc.nextInt(); PrintWriter out = new PrintWriter(System.out); while(tc != 0){ tc--; int n = sc.nextInt(); if(n == 1){ out.println(2); continue; } int q = n/3; int rem = n%3; if(rem == 0) out.println(q); else out.println(q+1); out.flush(); } } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
650a6f3b68d4d69ec3f562ac21ffa28a
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 Problem3 { static Scanner scanner = new Scanner(System.in); static void solve() { int x = scanner.nextInt(); int ans =(int) Math.ceil((double) x / 3.); if (x == 1) ans ++; System.out.println(ans); } public static void main(String[] args) { int T = scanner.nextInt(); while (T-- > 0) solve(); scanner.close(); } }
Java
["4\n\n1\n\n3\n\n4\n\n12"]
1 second
["2\n1\n2\n4"]
null
Java 17
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
ce0542c066475a5ed2a2628ca9c67244
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.util.Scanner; import java.util.StringTokenizer; public class forCP { public static void main(String[] args) throws IOException { FastReader scn = new FastReader(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int tc = scn.nextInt(); for (int tc1 = 0; tc1 < tc; tc1++) { int n = scn.nextInt(); int min=0; if(n%3==0)min=n/3; else min= n%3==1? (n/3-1)+2:(n/3)+1; if(n==1)min=2; if(n==2||n==3) min=1; out.write(min+"\n"); // System.out.println(min); } out.flush(); } // ------------------------------------------------------------------------------------------------------------------------------------------------------------------ public static void swaparr(int[] arr, int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } // -------------------------------------------------------------------------------------------------------------------------------------------------------- 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; } } }
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
130b1ef88679599f71cde07b54d60046
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.*; public class Main { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tokenizer=null; public static void main(String[] args) throws IOException { new Main().execute(); } void debug(Object...os) { System.out.println(Arrays.deepToString(os)); } int ni() throws IOException { return Integer.parseInt(ns()); } long nl() throws IOException { return Long.parseLong(ns()); } double nd() throws IOException { return Double.parseDouble(ns()); } String ns() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(br.readLine()); return tokenizer.nextToken(); } String nline() throws IOException { tokenizer=null; return br.readLine(); } //Main Code starts Here int totalCases, testnum; void execute() throws IOException { totalCases = ni(); for(testnum = 1; testnum <= totalCases; testnum++) { if(!input()) break; solve(); } } void solve() throws IOException { int x = (int)Math.abs(ni()); if (x == 1) { System.out.println(2); return; } if (x % 3 == 0) { System.out.println(x/3); } else { System.out.println(x/3+1); } } boolean input() throws IOException { return true; } }
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
39fcf723ce435c22c537772802200a9c
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 { static Scanner in = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int t = Integer.parseInt(in.nextLine()); StringBuilder sb = new StringBuilder(); for(int i = 0; i < t; i++){ int n = Integer.parseInt(in.nextLine()); if(n == 1){ sb.append(2); if(i != t - 1){ sb.append("\n"); } continue; } sb.append(n / 3 + (n % 3 == 0 ? 0 : 1)); if(i != t - 1){ sb.append("\n"); } } in.close(); out.print(sb.toString()); out.flush(); } }
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
7e9bb699f78c9c917a80f5774b7938b0
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 scanner = new Scanner(System.in); int t = Integer.parseInt(scanner.nextLine()); for(int i = 0; i < t; i++){ int n = Integer.parseInt(scanner.nextLine()); if(n == 1){ System.out.println(2); continue; } System.out.println(n / 3 + (n % 3 == 0 ? 0 : 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
cc60eb4268a56f4611852cbaffb90d52
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 scanner = new Scanner(System.in); int t = Integer.parseInt(scanner.nextLine()); long[] arr = new long[t]; for(int i = 0; i < t; i++){ arr[i] = Long.parseLong(scanner.nextLine()); if(arr[i] == 1){ System.out.println(2); continue; } long[] res = new long[6]; res[0] = 0; res[1] = 1; res[2] = 1; res[3] = 1; res[4] = 2; res[5] = 2; System.out.println(2 * (arr[i] / 6) + res[(int)(arr[i] % 6)]); } } }
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
fb11346fd6bd54697ec4cfa164c4e622
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 A { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scn = new Scanner(System.in); int t = scn.nextInt(); int[] arr = new int[t]; for (int i = 0;i<arr.length;i++) { arr[i] = scn.nextInt(); } for (int i = 0;i<arr.length;i++) { int n = Math.abs(arr[i]); if (n == 1) { System.out.println(2); } else if (n%3 == 0) { System.out.println(n/3); } else if (n%3 == 1) { n = n-4; System.out.println(n/3 + 2); } else { n = n-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
8bbdaa456a3c537e30bc13b662e66e21
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 forces2 { public static void main(String[] args) { Scanner sc =new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { // int n= sc.nextInt(); String s; s = sc.next(); int i = Integer.parseInt(s); int choice=0; int y=0,z=0; int num = 10; while(choice!=3) { z = i%num + z; i = i/num; choice++; } int a=0; int num2=10; while(a!=3) { y = i%num2+y; i = i/num2; a++; } if(z==y) { System.out.println("Yes"); } else { System.out.println("No"); } } } } */ import java.util.*; class forces2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { long n = sc.nextLong(); if(n==1) { System.out.println("2"); } else if(n==0) { System.out.println("2"); } else if(n==2) { System.out.println("1"); } else { n=(n-1)/3 +1; System.out.println(n); } } } }
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
01e1ca8a6e661f5a793443ea31ddee12
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){ // code here.... long n = sc.nextLong(); System.out.println(solve(n)); } } public static long solve(long n){ if(n == 1) return 2; if(n == 4) return 2; if(n % 3 == 0) return (n / 3); int count = 0; count += (n / 3); return count + 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
5e87fde86a17e57b9681f4e2187961fc
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
/* Goal: Become better in CP! Key: Consistency and Discipline Desire: SDE @ Google USA Motto: Do what i Love <=> Love what i do If you don't use your brain 100%, it deteriorates gradually */ import java.util.*; import java.io.*; import java.math.*; public class C { static StringBuffer str=new StringBuffer(); static int n; static void solve(){ int ans=(int)1e9; if(n%3==0) ans=Math.min(ans, n/3); if(n%3==1){ ans=Math.min(ans, n/3+2); if(n>=4) ans=Math.min(ans, (n-4)/3+2); } if(n%3==2) ans=Math.min(ans, n/3+1); if(n%2==0) ans=Math.min(ans, n/2); str.append(ans).append("\n"); } public static void main(String[] args) throws java.lang.Exception { BufferedReader bf; PrintWriter pw; boolean lenv=false; if(lenv){ bf = new BufferedReader( new FileReader("input.txt")); pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); }else{ bf = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new OutputStreamWriter(System.out)); } int q1 = Integer.parseInt(bf.readLine().trim()); while (q1-- > 0) { n=Integer.parseInt(bf.readLine().trim()); solve(); } pw.println(str); pw.flush(); // System.out.print(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
49a41ad86fb83159fd0cd9888ac93807
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
/* Goal: Become better in CP! Key: Consistency and Discipline Desire: SDE @ Google USA Motto: Do what i Love <=> Love what i do If you don't use your brain 100%, it deteriorates gradually */ import java.util.*; import java.io.*; import java.math.*; public class C { static StringBuffer str=new StringBuffer(); static int n; static void solve(){ int ans=(int)1e9; if(n%3==0) ans=Math.min(ans, n/3); if(n%3==1){ ans=Math.min(ans, n/3+2); if(n>=4) ans=Math.min(ans, (n-4)/3+2); } if(n%3==2) ans=Math.min(ans, n/3+1); if(n%2==0) ans=Math.min(ans, n/2); if(n%2==1) ans=Math.min(ans, n/2+2); str.append(ans).append("\n"); } public static void main(String[] args) throws java.lang.Exception { BufferedReader bf; PrintWriter pw; boolean lenv=false; if(lenv){ bf = new BufferedReader( new FileReader("input.txt")); pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); }else{ bf = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new OutputStreamWriter(System.out)); } int q1 = Integer.parseInt(bf.readLine().trim()); while (q1-- > 0) { n=Integer.parseInt(bf.readLine().trim()); solve(); } pw.println(str); pw.flush(); // System.out.print(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
ca48e34e0ad0ead8e90c0fb34d5990b5
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 a=sc.nextInt(); int ans=count(a); System.out.println(ans); t--; } } static int count(int n){ if(n==1) return 2; int temp=n%9; if(temp==0) temp= 0; else if(temp==1) temp= 1; else if(temp<=3) temp= 1; else if(temp<=6) temp= 2; else if(temp<=9) temp= 3; return temp+(n/9)*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
57778f8fb4e1bdaf3629bed31dd208f3
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 contest { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int q = Integer.parseInt(br.readLine()) ; while(q-->0) { int n = Integer.parseInt(br.readLine()) ; 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); } } }
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
9e33f3a22d692e55443f8ed2ccc8f3ed
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) { new Thread(null, () -> new Main().run(), "1", 1 << 23).start(); } private void run() { FastReader scan = new FastReader(); PrintWriter out = new PrintWriter(System.out); Solution solve = new Solution(); int t = scan.nextInt(); //int t = 1; for (int qq = 0; qq < t; qq++) { solve.solve(scan, out); //out.println(); } out.close(); } } class Solution { /* * think and coding */ double EPS = 0.000_0001; public void solve(FastReader scan, PrintWriter out) { int a = scan.nextInt(); int b = a % 3; if (a == 1) { out.println(2); return; } if (a == 2) { out.println(1); return; } if (b == 0) { out.println(a / 3); } else if (b == 2) { out.println(a / 3 + 1); } else { out.println((a - 4) / 3 + 2); } // int n = scan.nextInt(); // int a = n - 2; // out.print(n + "\n"); // for (int i = 1; i <= n; i++) { // out.print(i + " "); // } // out.println(); // for (int i = n; i >= 1; i--) { // out.print(i + " "); // } // out.println(); } static class Pair implements Comparable<Pair> { int a, b; public Pair(int a, int b) { this.a = a; this.b = b; } public Pair(Pair p) { this.a = p.a; this.b = p.b; } @Override public int compareTo(Pair p) { return Integer.compare(a, p.a); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair pair = (Pair) o; return a == pair.a && b == pair.b; } @Override public int hashCode() { return Objects.hash(a, b); } @Override public String toString() { return "Pair{" + "a=" + a + ", b=" + b + '}'; } } } class FastReader { private final BufferedReader br; private StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
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
a555340790d7426b2285d603edf847f2
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(); for (int i = 0; i < t; i++) { long a=scanner.nextLong(); if(a==4||a==-4){ System.out.println(2); continue; } if(a==7||a==-7){ System.out.println(3); continue; } long k=a%3; if(k==0){ long ans=a/3; System.out.println(Math.abs(ans)); }else if(k==2||k==-2){ long s=a/2; System.out.println(Math.min(Math.abs(a/3)+1,Math.abs(s))); }else { System.out.println(Math.min(Math.abs(a/3)+2,Math.abs(a-4)/3+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
ae77e8c91bc924b1dd627bfc5539bb58
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 ProblemA { 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(); Integer min = null; for (int y = n / 3 - 6; y <= n / 3 + 3; y++) { int val = n - 3 * y; if (val % 2 == 0) { int x = val / 2; int time = Math.abs(y) + Math.abs(x); if (min == null || min > time) { min = time; } } } 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
3452408bc4cfe41f0aec40e77b2af75c
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(); for(int i=0; i<t; i++){ int n = sc.nextInt(); if(n==1){ System.out.println(2); } else if(n%3 == 0){ System.out.println(n/3); } 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 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
0ec64eb98ee5819c894b36a31b056ad0
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(); for(int i=0; i<t; i++){ int n = sc.nextInt(); if(n==1){ System.out.println(2); } else{ if(n%3 == 0){ System.out.println(n/3); } 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 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
30603ff373feb35d4958079e3fb0ecdd
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 scn = new Scanner(System.in); int cases = scn.nextInt(); while(cases-->0){ long num = scn.nextLong(); if(num==1) System.out.println(2); else if(num%3==0) System.out.println(num/3); else{ double v = (double) num/3; System.out.println((int) Math.ceil(v)); } } } }
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
846351c467f0153873a8c738be131539
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.InputStreamReader; public class Moves { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); int numOfTestCases = Integer.parseInt(bufferedReader.readLine()); for (int i = 0; i < numOfTestCases; i++) { int n = Integer.parseInt(bufferedReader.readLine()); int minMoves = getMinMoves(n); System.out.println(minMoves); } } private static int getMinMoves(int n) { int minMoves = 0; switch (n) { case 1: minMoves = 2; return minMoves; case 3: minMoves = 1; return minMoves; case 2: minMoves = 1; return minMoves; } int remainderForThree = n % 3; int quotientForThree = n / 3; int remainderForTwo = n % 2; int quotientForTwo = n / 2; int sum = 0; if (remainderForThree == 0) { minMoves = quotientForThree; return minMoves; } else { sum = 3 * quotientForThree + 2; if (sum == n) { // System.out.println("Quotient=" + quotientForThree); minMoves = quotientForThree + 1; } else { sum = 3 * quotientForThree + 3 - 2; if (sum == n) { minMoves = quotientForThree + 1; } } if (remainderForTwo == 0 && quotientForTwo < minMoves) { minMoves = quotientForTwo; } } return minMoves; } }
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
d392d8a92aeb8ddf4d8d7a6726b4f47b
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 hii{ public static void main(String arg[]) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=1;i<=n;i++) { int c=0; int a=sc.nextInt(); if(a==1 || a==-1) c=2; else { if(a%3==0) c=a/3; else { if(a%3==0) c=(a/3)+2; else c=(a/3)+1; } } System.out.println(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
d8c9ab066421005c774ecda137934dd7
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 hii{ public static void main(String arg[]) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=1;i<=n;i++) { int c=0; int a=sc.nextInt(); if(a==1 || a==-1) c=2; else { if(a%3==0) c=a/3; else { if(a%3==0) c=(a/3)+2; else c=(a/3)+1; } } System.out.println(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
5b573578aa2aa69e60fc58314112aa50
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 hii{ public static void main(String arg[]) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=1;i<=n;i++) { int c=0; int a=sc.nextInt(); if(a==1 || a==-1) c=2; else { if(a%3==0) c=a/3; else {if(a%3==0) c=(a/3)+2; else c=(a/3)+1; } } System.out.println(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
7f9fda303f28f7a6c66233fc23a75a91
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 moves23 { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); while(n-->0){ 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
90472325474df41a46062bce79074085
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 codeforces2 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t>0) { int n=s.nextInt(); n=Math.abs(n); int tt=n/3; if(n==2){ System.out.println(1); } else if(n==1){ System.out.println(2); } else if(n%3==0){ System.out.println(tt); } else{ System.out.println(tt+1); } 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
bb961d7216eb290fa0d8253b3af526d0
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.*; public class Codechef { /* FastReader class to work with input */ 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 [] iArray(int n) { int res [] = new int [n]; for(int i = 0; i<n; i++)res[i] = nextInt(); return res; } long [] lArray(int n) { long res [] = new long [n]; for(int i = 0; i<n; i++)res[i] = nextLong(); return res; } } /* UnionFind class to work with disjoint set */ static class UnionFind { int[] p, rank, setSize; int numSets; public UnionFind(int N) { p = new int[numSets = N]; rank = new int[N]; setSize = new int[N]; for (int i = 0; i < N; i++) { p[i] = i; setSize[i] = 1; } } public int findSet(int i) { return p[i] == i ? i : (p[i] = findSet(p[i])); } public boolean isSameSet(int i, int j) { return findSet(i) == findSet(j); } public void unionSet(int i, int j) { if (isSameSet(i, j)) return; numSets--; int x = findSet(i), y = findSet(j); if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; } else { p[x] = y; setSize[y] += setSize[x]; if (rank[x] == rank[y]) rank[y]++; } } public int numDisjointSets() { return numSets; } public int sizeOfSet(int i) { return setSize[findSet(i)]; } } static class Pair { int a,b; public Pair(int a, int b) { this.a = a; this.b = b; // this.c = c; } } static class Compare { static void compare(ArrayList<Pair> al, int n) { Collections.sort(al, new Comparator<Pair>(){ @Override public int compare(Pair p1, Pair p2) { return (int)(p1.b-p2.b); } }); } } static class Compare1 { static void compare(ArrayList<Pair> al, int n) { Collections.sort(al, new Comparator<Pair>(){ @Override public int compare(Pair p1, Pair p2) { return (int)(p1.a-p2.a); } }); } } static FastReader in = new FastReader(); static final Random random = new Random(); // static int mod = (int) 1e9 + 7; static long[] fact = new long[16]; /* function to calculate factorial */ static void init() { fact[0] = 1; for(int i=1; i<16; i++) fact[i] = (i*fact[i-1]); } /* function to calculate modular exponentiation */ public static long pow(long a, long b, long mod) { long res = 1; while (b > 0) { if ((b & 1) > 0) res = (res * a) % mod; b = b >> 1; a = ((a % mod) * (a % mod)) % mod; } return (res % mod + mod) % mod; } /* function to check if string is palindrome or not */ public static boolean isPal(String s) { for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != s.charAt(s.length() - 1 - i)) return false; } return true; } /* sieveOfEratosthenes algorithm will return ArrayList of prime numbers */ public static ArrayList<Integer> primeSieve(int n) { ArrayList<Integer> arr=new ArrayList<>(); boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int i = 2; i <= n; i++) { if (prime[i] == true) arr.add(i); } return arr; } /* sieveOfEratosthenes algorithm*/ public static void sieveOfEratosthenes(int N , boolean[] prime) { Arrays.fill(prime, true); for(int p = 2; p*p <=N; p++) { if(prime[p] == true) { // Update all multiples of p for(int i = p*p; i <= N; i += p) prime[i] = false; } } } /* Eculidean algorithm to find gcd of two number */ static int gcd(int a,int b) { if(b==0) { return a; } return gcd(b,a%b); } /* function to calculate lcm of two number */ static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static long cntSetBit(long num) { long ans = 0; while(num>0) { if(num%2==1) ans++; num /= 2; } return ans; } static void ruffleSort(int[] a) { int n=a.length; for (int i=0; i<n; i++) { int oi = random.nextInt(n), temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static < E > void print(E res) { System.out.println(res); } /* function to check whether ArrayList a and b are equal or not */ static boolean isEqual(ArrayList<Integer> a, ArrayList<Integer> b, int n) { HashSet<Integer> hs = new HashSet<>(); if (a.size() < (n / 2) || b.size() < (n / 2)) return false; int s1 = 0; for (int ele : a) hs.add(ele); for (int ele : b) hs.add(ele); if (hs.size() == n) return true; return false; } /* Binary Search Algorithm */ private static int binSearch(int l, int r, long val, long[] arr) { while(l<=r) { int mid = (l+r)/2; if(arr[mid]==val) return mid; if(arr[mid]>val) r = mid-1; if(arr[mid]<val) l = mid+1; } return -1; } /* main method */ public static void main (String[] args) throws java.lang.Exception { int t=in.nextInt(); // int t=1; while(t-->0) solve(); /* ArrayList<Pair> al = new ArrayList<>(); for(int i=0; i<5; i++) { al.add(new Pair(in.nextLong(), in.nextLong())); } for(int i=0; i<5; i++) { System.out.println(al.get(i).a + " " + al.get(i).b); } Compare obj = new Compare(); obj.compare(al, 5); Arrays.sort(al, (p0, p1) -> Integer.compare(p0.a, p1.a)); for(int i=0; i<5; i++) { System.out.println(al.get(i).a + " " + al.get(i).b); } */ } static void solve() { int n = in.nextInt(); if(n==1) { System.out.println("2"); return; } 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
8eca377bdd184f0fb62beb43a04a7eeb
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 A { static void solve(boolean ok) { if (ok) System.out.println("YES"); else System.out.println("NO"); } public static String toBin(int n) { String s = ""; return s; } public static void main(String[] args) { FastScanner sc = new FastScanner(); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); if (n == 1) System.out.println(2); else if (n % 3 == 0) System.out.println(n/3); else { System.out.println(n/3 + 1); } } // min // mid // max // max + min // max + mid // min + max + mid } /* * 5 4 * 9 4 * 9 13 * 22 13 * 22 35 * 57 35 * 57 92 * +100 */ static boolean IsPowerOfTwo(int x) { return (x & (x - 1)) == 0; } 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
d7954befcd17aea3a685063639140744
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.File; import java.io.FileReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Solution { static PrintWriter pw; static FastScanner s; public static void main(String[] args) throws Exception { pw=new PrintWriter(System.out); s=new FastScanner(System.in); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); if(n%3==0) pw.println(n/3); else if(n%3==1) { int num=((n+2)/3)+1; int num2=((n-4)/3)+2; if(num2>0 && n>=4) num=Math.min(num, num2); pw.println(num); } else { int num=(n-1)/3; pw.println(num+1); } } pw.flush(); } } class FastScanner{ BufferedReader br; StringTokenizer st; public FastScanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public FastScanner(String s) throws Exception { br = new BufferedReader(new FileReader(new File(s))); } public String next() throws Exception { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { 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
e615756ff1516e2c063456cf37597dd1
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
//KENAA import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.Queue; import java.util.Stack; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { A_2_3_Moves(); } public static void A_2_3_Moves() { FastReader fr = new FastReader(); int tt = fr.nextInt(); while (tt-- > 0) { int n = fr.nextInt(); if (n==1) { System.out.println(2); }else if (n==2) { System.out.println(1); }else { if (n%3==0) { System.out.println((n/3)); }else { System.out.println((n/3)+1); } } } } public static void C_Min_Max_Array_Transformation() { FastReader fr = new FastReader(); int tt = fr.nextInt(); while (tt-- > 0) { int n = fr.nextInt(); int[] a = fr.readArray(n); int[] b = fr.readArray(n); int[] dmax = new int[n]; int[] dmin = new int[n]; LinkedList<Integer> list = new LinkedList<Integer>(); int bPo = n-1; for (int i = n-1; i >= 0; i--) { while (bPo>=0 && b[bPo]>=a[i]) { list.add(b[bPo--]); } dmax[i]=list.getFirst()-a[i]; dmin[i]= list.getLast()-a[i]; int aa =n-i; if (aa==n-(bPo+1)) { list = new LinkedList<Integer>(); } } for (int i = 0; i < dmin.length; i++) { System.out.print(dmin[i]+" "); } System.out.println(); for (int i = 0; i < dmin.length; i++) { System.out.print(dmax[i]+" "); } System.out.println(); } } static class FastReader { 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) { } return st.nextToken(); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } public static long lcm(long a, long b) { return a * b / gcd(a, b); } public static long gcd(long a, long b) { while (b != 0) { long m = a % b; a = b; b = m; } return a; } public static long factorial(int n) { if (n == 0) return 1; long res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } public static long nCr(int n, int r) { return factorial(n) / (factorial(r) * factorial(n - r)); } public static ArrayList<Integer> factors(long n) { ArrayList<Integer> list = new ArrayList<>(); for (int i = 2; i < n / i; i++) { while (n % i == 0) { if (!list.contains(i)) { list.add(i); n /= i; } } } if (n > 2) { if (!list.contains((int) n)) { list.add((int) n); } } return list; } public static int numOfPrimes(int n) { if (n < 2) { return 0; } boolean[] bool = new boolean[n + 1]; outer: for (int i = 2; i < bool.length / i; i++) { if (bool[i]) { continue outer; } for (int j = 2 * i; j < bool.length; j += i) { bool[j] = true; } } int counter = 0; for (int i = 0; i < bool.length; i++) { if (!bool[i]) { counter++; } } return counter; } public static void sort2DGivenArray(Object[][] arr, int colNum) { Arrays.sort(arr, (val1, val2) -> { if (val1[colNum] == val2[colNum]) { return 0; } else if (((Integer) (val1[colNum])).compareTo(((Integer) (val2[colNum]))) < 0) { return 1; } else { return -1; } }); } }
Java
["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
0a7e35e10adc248dfbe95b6859b644d7
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.net.URI; import java.net.URISyntaxException; import java.sql.Array; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.util.Vector; import org.w3c.dom.Node; public class codechef3 { static class comp implements Comparator<String> { @Override public int compare(String o1, String o2) { if(o1.length()>o2.length()) return 1; else if(o1.length()<o2.length()) return -1; else return o1.compareTo(o2); } } static class FastReader {BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } //------------------------------------------------------------------------------------------- public static void main (String[] args) { FastReader s=new FastReader(); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); if(n==1) System.out.println(2); else if(n==2||n==4) System.out.println(n/2); else if(n%3==0) System.out.println(n/3); else if(n%3==2) System.out.println(n/3+1); else if(n%3==1&&n%2==0) System.out.println(2*(n/6)+(n-6*(n/6))/2); else if(n%3==1) 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
633511dd1ad3ae1d66b71d20b5b66af4
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 Main { public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); int tc = sc.nextInt(); //int tc=1; while(tc-->0){ int n = sc.nextInt(); if(n==1) System.out.println(2); else if(n<=3) System.out.println(1); else { int ans=(int)Math.ceil((n+2)/3); System.out.println(ans); } } } } 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
bb302c35f0cd4656de3de94634a3dc9c
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 t = sc.nextInt(); for(int i = 0;i<t;i++) { int n = sc.nextInt(); if(n%2 == 0 && n%3 == 2) { System.out.println(1+(n-2)/3); } else if(n%3 == 0 && n%2!=0) { System.out.println(n/3); } else if(n%3 == 0 && n%2==0) { System.out.println(n/3); } else if(n==1) { System.out.println(2); } else { System.out.println(2+(n-4)/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
e2183f409348637d5f175548887ee8f4
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; /** * A. 2-3 Moves */ public class Main { static class FastReader { BufferedReader reader; StringTokenizer tokenizer; FastReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } // reads in the next string String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } // reads in the next int int nextInt() { return Integer.parseInt(next()); } // reads in the next long long nextLong() { return Long.parseLong(next()); } // reads in the next double double nextDouble() { return Double.parseDouble(next()); } void close() { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } } private static FastReader in = new FastReader(System.in); private static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); public static void main(String[] args) { int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); int a = n / 3; int b = n % 3; if (b == 0) { out.println(a); } else if (b == 1) { int cnt = 1 + (n + 2) / 3; if (n - 4 >= 0) cnt = Math.min(cnt, 2 + (n - 4) / 3); out.println(cnt); } else if (b == 2) { out.println(a + 1); } } out.flush(); out.close(); 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
0bed72129e49529f4da95c34d53ffe28
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 edu_133_a { public static void main(String args[]){ FScanner in = new FScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); while(t-->0) { int n=in.nextInt(); if(n==1) out.println(2); else if(n==2) out.println(1); else if(n%3==0) out.println(n/3); else out.println((int)Math.ceil(n*1.0/3)); } out.close(); } static class FScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer sb = new StringTokenizer(""); String next(){ while(!sb.hasMoreTokens()){ try{ sb = new StringTokenizer(br.readLine()); } catch(IOException e){ } } return sb.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return ""; } int nextInt(){ return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } float nextFloat(){ return Float.parseFloat(next()); } double nextDouble(){ return Double.parseDouble(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
ed83f04c5908bc453681299c603da959
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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.util.Iterator; import java.util.List; import java.util.PriorityQueue; import java.util.Set; import java.util.Stack; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.ArrayList; import java.lang.*; import java.math.BigInteger; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); Contest solver = new Contest(); solver.solve(1, in, out); out.close(); } static class Contest { public void solve(int testNumber, InputReader in, OutputWriter out) { int t = in.readInt(); for (int ww = 0; ww < t; ww++) { int n = in.readInt(); //int n = ww; int count = 0; if (n == 1) count = 2; if (n == 2) count = 1; if (n == 3) count = 1; if (n > 3 && n % 3 == 0) count = n/3; if (n > 3 && n % 3 == 1) count = n/3+1; if (n > 3 && n % 3 == 2) count = n/3+1; //System.out.println(ww+": "+count); System.out.println(count); } } } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void print(Object s) { writer.println(s); } public void printFail(Object s) { writer.println(s); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int[] readIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = readInt(); } return array; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public int readInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class ArrayUtils { public static long[] partialSums(int[] array) { long[] result = new long[array.length + 1]; for (int i = 0; i < array.length; i++) { result[i + 1] = result[i] + array[i]; } return result; } }
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
f4965ac6fb3d04d1debbde10c96d96fd
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 ProblemA { public static int getCountBy3(int n) { if (n % 3 == 0) { return n / 3; } else if (n % 3 == 2) { return n / 3 + 1; } else { return (n / 3) + 1; } } 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(getCountBy3(n)); } 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
bed9f67135a09ad95dd0d0839b2d8a88
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 ProblemA { public static int getCountBy2(int n) { if (n % 2 == 0) { return n / 2; } return n / 2 + 2; } public static int getCountBy3(int n) { if (n % 3 == 0) { return n / 3; } else if (n % 3 == 2) { return n / 3 + 1; } else { return (n / 3) + 1; } } 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((Math.min(getCountBy2(n), getCountBy3(n)))); } 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
117bec46b3f3496feef5308fea291408
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.*; //System.out.println(); public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long t = sc.nextInt(); while(t-->0) { long n = sc.nextLong(); if(n%3==0) System.out.println((n/3)); else if(n==1) System.out.println(2); 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 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
bd17ac2a2d79af2ed4d3800a8bee7a03
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.*; /** * Goal is to reach point n * * In 1minute, can move by 2 or by 3 to the left or to the right * * Input: * First line contains one integer - number of test cases * t lines describing test cases * * Output: Minimum number of minutes required to get from point 0 to the point n * * Seems like a DP/Greedy question * * There is a pattern * After 3, numbers change every 3 numbers * * So its DP */ public class A { public static void main(String[] args) { //Read input FastIO fio = new FastIO(); //Get test cases int cases = fio.nextInt(); for (int i = 0; i < cases; i++) { //Use memo //0,1,2,3,4 int n = fio.nextInt(); if (n == 1) { fio.println(2); } else if (n == 2 || n == 3) { fio.println(1); } else { //int elementsAfterThree = n - 3; fio.println((int) Math.ceil((double) n / 3)); } } fio.close(); } } /** * Fast I/O * @source https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/ */ class FastIO extends PrintWriter { BufferedReader br; StringTokenizer st; public FastIO() { super(new BufferedOutputStream(System.out)); 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
97a6edc21d4f56c0d99b52798a5cac32
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 int moves(int n) { if(n==1) return 2; if(n==4) return 2; int temp=n; int min=0; if(n%3==0) return n/3; else if(n%3!=0) { int m=n%3; if(m==1) return (n-4)/3+2; else if(m%2==0) { int ans=n/3+m/2; return ans; } } return 0; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int testCaseCount = scanner.nextInt(); for (int tc = 1; tc <= testCaseCount; ++tc) { String s=scanner.nextLine(); int n=scanner.nextInt(); System.out.println(moves(n)); /*for(int i=0;i<n;i++) { String s1=scanner.nextLine(); System.out.println(color(s,s1)); }*/ } } }
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
ac9fda6e7042bba42094b93e66a2e854
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){ int n=sc.nextInt(); n=Math.abs(n-0); int val=0; if(n%3==0){ val=n/3; } else if(n==1){ val=2; } else { val=n/3+1; } System.out.println(val); } } }
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
47c1f3e7084ea27cd05426ff6392c4c5
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.math.BigInteger; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.util.*; import static java.lang.System.out; public class app { public static ArrayList<ArrayList<Integer>>as=new ArrayList<>(); public static Boolean x[]; public static int z; public static long m; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int s=sc.nextInt(); int sa=s/3; if(s==1){ out.println(2); } else if(s%3==1){ out.println(sa+1); } else if(s%3==2) { out.println(sa+1); }else{ out.println(sa); } } } }
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
bd9add437e07cced3a9b32be645ded09
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 Tttest { public static int fun(int n) { int ans=0; if(n==1) { return 2; }else if(n==2 || n==3) { return 1; } ans=n/3; if(n%3>0) { ans++; } return ans; } public static void main(String[] args){ // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0) { int n=sc.nextInt(); System.out.println(fun(n)); t--; } sc.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
a41af7ac57bfd32fc0d57c2bd1c0c6b7
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 { int number; public Moves(int number){ this.number=number; } public int posNumber(int number){ if(number<0){ number*=-1; } return number; } public void input(int number){ int num=posNumber(number); if (num==1){ num=4; } if(num%3==0){ System.out.println(num/3); }else{ System.out.println(num/3+1); } } public int getNumber() { return number; } public static void main(String[] a){ Scanner input=new Scanner(System.in); int number=input.nextInt(); Moves instance=new Moves(number); for (int i=0;i<instance.getNumber();i++){ int num=input.nextInt(); instance.input(num); } } }
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
d3e98824db32625961eec257286fa4a3
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.StringTokenizer; public class Main { public static void main(String[] args) { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int T = 1; T = fs.nextInt(); for (int tc = 0; tc < T; tc++) { int n = Math.abs(fs.nextInt()); if (n == 1) { out.println(2); continue; } int ans = Integer.MAX_VALUE; if (n % 3 == 0) { ans = Math.min(ans, n / 3); } if (n % 2 == 0) { ans = Math.min(ans, n / 2); } ans = Math.min(ans, n / 2 + 3); ans = Math.min(ans, n / 3 + 1); out.println(ans); } out.close(); } static void sort(int[] a) { ArrayList<Integer> arr = new ArrayList<>(); for (int x : a) { arr.add(x); } Collections.sort(arr); for (int i = 0; i < a.length; i++) { a[i] = arr.get(i); } } static void swap(int[] a, int x, int y) { int temp = a[x]; a[x] = a[y]; a[y] = temp; } 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[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } long nextLong() { return Long.parseLong(next()); } 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
314af37ec1f67526e92cf190366be40c
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 sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); int q = n/3; if(n == 1) System.out.println("2"); else if(n%3>0) System.out.println(q+1); else System.out.println(q); } } }
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
9208b9927d79fd656d0028169da28aa4
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 twoThreeMoves { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int arr[] = new int[t]; for(int i=0;i<t;i++){ int n = sc.nextInt(); if(n%3 == 0){ arr[i] = n/3; } else if(n%3 == 2){ arr[i] = n/3 + 1; } else{ if(n ==1){ arr[i] = 2; } else{ arr[i] = (n/3) +1; } } } for(int i=0;i<t;i++){ System.out.println(arr[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
a0e16b024b2151ac045eafd865dcd3d6
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 test{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int count = t; while(count>0){ long n; n= sc.nextInt(); if(n==1){ System.out.println(2); } else{ if(n%3==0){ System.out.println(n/3); } else{ if(n%2==0){ long quo = n/3; long rem = n%3; if(rem==1){ System.out.println(Math.min(n/2, quo+1)); } else{ System.out.println(Math.min(n/2,n/3+1)); } } else{ long q = n/3; long r = n%3; if(r==1){ System.out.println(Math.min(n/2, q+1)); } else{ System.out.println(Math.min(n/2+2, q+3-r)); } } } } 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
df63ac5ac0a71aab8b865b9e5982a9ba
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.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedList; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { FastScanner scan = new FastScanner(); //PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int tt = scan.nextInt(); while (tt-- > 0) { int n = scan.nextInt(); int ans = n / 3; if (n % 3 != 0) { ans++; } if (n < 3) { ans = n == 1 ? 2 : 1; } System.out.println(ans); } //out.close(); } static class FastScanner { public BufferedReader reader; public StringTokenizer tokenizer; public FastScanner() { reader = new BufferedReader(new InputStreamReader(System.in), 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 char nextChar() { return next().charAt(0); } public String nextLine() { try { return reader.readLine(); } catch(IOException e) { throw new RuntimeException(e); } } } }
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
d186e5eb9200a590e44ee03f97eab012
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 A { public static void main(String[] args) { FastReader in = new FastReader(); PrintWriter out = new PrintWriter(System.out); int T = in.nextInt(); for (int ttt = 1; ttt <= T; ttt++) { int n = in.nextInt(); if (n == 1) out.println(2); else if (n % 3 == 0) out.println(n/3); else out.println(n/3 + 1); } out.close(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch(IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch(IOException e) { e.printStackTrace(); } return str; } int[] readInt(int size) { int[] arr = new int[size]; for(int i = 0; i < size; i++) arr[i] = Integer.parseInt(next()); return arr; } long[] readLong(int size) { long[] arr = new long[size]; for(int i = 0; i < size; i++) arr[i] = Long.parseLong(next()); return arr; } int[][] read2dArray(int rows, int cols) { int[][] arr = new int[rows][cols]; for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) arr[i][j] = Integer.parseInt(next()); } return arr; } } }
Java
["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
74d3352e11ebfba1ccbe889189c5d680
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) { final Scanner scanner = new Scanner(System.in); int t=scanner.nextInt(); while (t--!=0){ int n=scanner.nextInt(); if(n==1){ System.out.println(2); continue; } if (n==2){ System.out.println(1); continue; } if (n%3==0){ System.out.println(n/3); continue; } if (n%3==1){ if(n%2==0){ System.out.println(Math.min(n/2,n/3+1)); }else { System.out.println(n/3+1); } } 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
534c14acf2cc0b479cc24938e36002bf
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 MyClass { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n-->0){ int x=sc.nextInt(); if(x == 1) System.out.println(2); else if(x == 2) System.out.println(1); else if(x == 4) System.out.println(2); else{ int three= x/3; if(x%3 == 1) three+=1; else if(x%3 == 2) three+=1; System.out.println(three); } } } }
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
49f6640bfd53adc7cad355cf4c90c429
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 preparation; /** * @author krishnam * */ import java.util.*; public class Solution { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- >0) { int n=sc.nextInt(); System.out.println(solve(n)); } } static int solve(int n) { int ans=0; double n2=n; if(n==1) return 2; if(n==2) return 1; n2=n2/3; return (int)Math.ceil(n2); //return 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
b101faa6f998ca2c3e3ac461bd40902a
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 Codeforce133A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0){ int n = sc.nextInt(); int x=0; if(n==1){ x=2; } else if(n%3==0){ x = n/3; } else{ x = n/3; x++; } System.out.println(x); 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
0a94d51064cd6f60b68206536248261f
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.StringTokenizer; public class Main { public static void main(String [] args) { FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); StringBuilder sb = new StringBuilder(); int t = fs.nextInt(); while(t-- > 0) { long n = fs.nextInt(); long res = (n == 1) ? 2 : (n +2)/3; sb.append(res).append("\n"); } out.print(sb); 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()); } } }
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