prompt stringlengths 396 31.4k |
|---|
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
long s = sc.nextLong();
long ans = (s - 1) / n + 1;
System.out.print(ans... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
public class OrangeJuice{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int s=in.nextInt();
if(n>=1&&n<=100000&&s>=1&&s<=1000000000){
if(s%n==0){
System.out.println(s/n);
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.Scanner;
/**
* Solution
*/
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), s = sc.nextInt();
int coins;
if(s%n != 0)
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java .util.*;
import java .io.*;
public class Main{
public static void main(String[]YAHIA_MOSTAFA){
Scanner sc =new Scanner(System.in);
long n=sc.nextLong(),x=sc.nextLong(),y=sc.nextLong();
long xb,xw,yb,yw;
xw=x-1;yw=y-1;xb=n-x;yb=n-y;
if (x=... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
import java.io.*;
public class Param
{
public static void main( String[]args)
{
MyScanner param = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
long l2 =par... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Dont {
static BufferedReader jin = new BufferedReader( new InputStreamReader( System.in ) );
static long n;
static long x, y;
public static void main(String[] args) ... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java program to count
// the number of indexes
// in range L R such that
// Ai=Ai+1
class
GFG {
public
static
int
N =
1000
;
// Array to store count
// of index from 0 to
// i that obey condition
static
int
prefixans[] =
new
int
[
1000
];
//... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int hp = scanner.nextInt();
if (hp%4 == 1){
System.out.print... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>//package Contest573;
import java.io.*;
import java.util.StringTokenizer;
public class mainA {
public static PrintWriter out = new PrintWriter(System.out);
public static FastScanner enter = new FastScanner(System.in);
public static void main(Str... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
import java.util.*;
import java.io.*;
public class TokitsukazeAndEnhancement {
static char check(int n) {
if(n%4 == 0)
return 'D';
if(n%4 == 1)
return 'A';
if(n%4 == 2)
return 'C';
return 'B';
}
public static void main(String[] args) t... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class problem2 {
static class tile implements Comparable<tile> {
int number;
int suit;
public int compareTo(tile b){
return number ... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
static Scanner sc = new Scanner(System.in);
public stat... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>//package codeforces;
import java.util.Scanner;
public class ex5 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String S [] = new String[3];
int m=0,s=0,p=0;
int temp=0;
for (int i = 0; i < S.length; i++) {
S[i]=sca... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>/* package whatever; // 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 Ideone
{
public static void main (String[] args) throws java.lan... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class AAA {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStr... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>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.InputMismatch... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
public class helloWorld
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
long n = in.nextLong();
long m = in.nextLong();
long ans = m / n;
if(m % n > 0)
ans++;
System.out.println(... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import com.sun.org.apache.xalan.internal.xslt.Process;
import java.io.*;
import java.util.*;
public class main {
public static void main(String[] args) throws IOException {
init();//"prizes.in", "prizes.out");
int x = nextInt();
in... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
long s = sc.nextLong();
long ans = (s - 1) / n + 1;
System.out.print(ans... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.*;
import java.util.*;
public class Codechef{
public static void main(String []args){
Scanner in = new Scanner(System.in);
long n=in.nextLong();
long m=in.nextLong();
long k=in.nextLong();
long l=in.nextLong();
long j... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
import java.util.Scanner;
public class origami {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
double n = input.nextInt();
double k = input.nextInt();
double red = 0;
double green = 0;
double blue = 0;
double a... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.Scanner;
public class MargariteBestPresent_1080B {
private static int f(int x) {
return (x%2==0)?x/2:(x-1)/2-x;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n,r,l;
n = sc.nextInt();
while(... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWrite... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.*;
public class VJudgeProblem2{
public static void main(String[] args) throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int x = Integer.parseInt(reader.readLine());
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
public class Main{
public static void main(String [] args)
{
Scanner scan=new Scanner(System.in);
int q=scan.nextInt();
int i;
for(i=1;i<=q;i++)
{
int a=scan.nextInt();
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
import java.util.Scanner;
public class Main {
static Scanner scan = new Scanner(System.in);
public static void main(String [] args){
int num = scan.nextInt();
for(int i=0;i<num;i++){
int a = scan.nextInt();
int... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
if(a>=1 && a<=100){
if(a>2){
if(a%2==0){
System.out.println("YES");
}else{
System.out.... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
public class D5 {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int a = input.nextInt(), v = input.nextInt();
int l = input.nextInt(), d = input.nextInt(), w = input.nextInt();
double lo = 0... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.*;
import java.util.*;
public class b {
public static void main(String[] args) throws IOException, InterruptedException {
Scanner zizo = new Scanner(System.in);
PrintWriter wr = new PrintWriter(System.out);
int n1 = 0,n2 = 0,n3 = 0,n4... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class TrickyAlchemy {
public static BufferedReader in = new ... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
import java.math.*;
public class Main{
public static void main(String [] args)
{
Scanner scan=new Scanner(System.in);
long n=scan.nextLong();
long m=scan.nextLong();
n=(long)Math.pow(2,n);
long... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
import java.lang.Math;
public class tab
{
public static void main(String[] args)
{
int n,pos,l,r;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
pos=sc.nextInt();
l=sc.nextInt();
r=sc.nextInt();
int sum;
int a=(n-r)+(l-1);
if((Math.abs(p... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.Scanner;
public class Main {
//kai
public static void main(String[] args) {
Scanner kai = new Scanner(System.in);
while (kai.hasNext()) {
int a = kai.nextInt();
if ((a & 1) == 0) {
System.out.println("Mahmoud");
}else {
S... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.*;
import java.util.*;
public class cf {
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.i... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.*;
import java.util.*;
public class Codechef{
static int max=Integer.MIN_VALUE;
static int res=0;
static int[] checkMax(int arr[],int j){
int sum=0;
int x=arr[j];
while(x!=0){
if(j+1==15){
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class PizzaPizzaPizza {
public static BufferedReader in = ne... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
import java.lang.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
public class Main {
public static void main(String[] args) throws ... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
public class helloWorld
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int n = in.nextInt();
int ans = n - (a + b - c);
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
public class Main {
static int mod = 1000000007;
static int size = 200000;
static long[] fac = new long[size];
static long[] finv = new long[size];
static long[] inv = new long[size];
static int INF = Integer.MAX_VALUE;
public sta... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import java.lang.Math.*;
public class two_squares {
public static void main(String[] args) throws Exception {
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class AlexAndARhombus {
public static BufferedReader in = ne... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatc... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// A O(1) Java program to
// find number of strings
// that can be made under
// given constraints.
import
java.io.*;
class
GFG
{
static
int
countStr(
int
n)
{
return
1
+ (n *
2
) +
(n * ((n * n) -
1
) /
2
);
}
// Driver code
public
stat... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java program to demonstrate working of
// an algorithm that finds an element in an
// array of infinite size
class
Test
{
// Simple binary search algorithm
static
int
binarySearch(
int
arr[],
int
l,
int
r,
int
x)
{
if
(r>=l)
{
int
mid = ... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solut... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.*;
import java.util.StringTokenizer;
import static java.lang.Math.max;
import static java.lang.Math.min;
public class Main {
FastScanner in;
PrintWriter out;
void run() {
in = new FastScanner();
out = new PrintWrite... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
public class ehab4 {
public static void main( String[] args ) {
Scanner in = new Scanner( System.in );
int a = 0, b = 0;
System.out.println( "? 0 0 " );
System.out.flush();
int c = in.nextInt();
for ( int i = 29; i >= 0; i-... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import java.util.PriorityQueue;
import static java.lang.Math.*;
public class solution implements R... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solut... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solut... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputS... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class EhabAndAnotherAnotherXorProblem imple... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputS... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
public class mad{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int cura = 0,curb = 0;
int ver;
System.out.println("? 0 0");
System.out.flush();
ver = sc... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
import java.lang.*;
public class Main {
static long m = 1000000007;
static long powmod(long x, long y, long p)
{
// Initialize result
long res = 1;
// Update x if it is more
// than or equal to p
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>/* 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.l... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStream... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
class
Main
{
/* Function to get index of
ceiling of x in arr[low..high]*/
static
int
ceilSearch(
int
arr[],
int
low,
int
high,
int
x)
{
int
mid;
/* If x is smaller than or equal to the
first element, then return the first element */
if
(x <=... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
/* Program to check for majority element in a sorted array */
import
java.io.*;
class
Majority {
/* If x is present in arr[low...high] then returns the index of
first occurrence of x, otherwise returns -1 */
static
int
_binarySearch(
int
arr[],
int
lo... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>package com.rampatra.searching;
/**
* Created by IntelliJ IDEA.
*
* @author rampatra
* @version 9/1/15
*/
public class BinarySearch {
/**
* Searches an element {@param n} in a sorted array {@param a}
* and returns its index in O(log n) time... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>class findMedianTwoArrays
{
public static double main(
int[] arr1, int start1, int end1, int[] arr2, int start2, int end2) {
if ( end1 - start1 == 1 && end2 - start2 == 1 ) {
return ( Math.max(arr1[start1], arr2[start2]) + Math.min(arr1[end1],... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>package com.interview.binarysearch;
/**
* There are two sorted arrays nums1 and nums2 of size m and n respectively.
* Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
*
* Solution
* Take minimum size of two... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>package com.interview.binarysearch;
/**
* http://www.geeksforgeeks.org/search-floor-and-ceil-in-a-sorted-array/
*/
public class FloorAndCeilingSortedArray {
public int floor(int input[], int x){
int low = 0;
int high = input.length-1;
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>package com.interview.algorithms.array;
/**
* Given a sorted array and a value x, the ceiling of x is the smallest element
* in array greater than or equal to x, and the floor is the greatest element
* smaller than or equal to x. Assume than the array is so... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>package geek.livingstone.problems.arrays;
/**
* Full problem at
* http://www.geeksforgeeks.org/search-floor-and-ceil-in-a-sorted-array/
*
* @author emmanuel
*
*/
public class FloorInSortedArray {
public static int floor(int[] A, int val) throws Except... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>package com.interview.binarysearch;
/**
* Regular binary search
*/
public class BinarySearch {
public int search(final int input[], int search) {
int low = 0;
int high = input.length - 1;
int mid;
while (low <= high) {
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>package com.interview.binarysearch;
/**
* http://www.careercup.com/question?id=4877486110277632
* Given a circle with N defined points and a point M outside the circle,
* find the point that is closest to M among the set of N. O(LogN)
* Test cases
* 1) s... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>package com.interview.binarysearch;
/**
* http://www.geeksforgeeks.org/find-the-point-where-a-function-becomes-negative/
*/
public class MonotonicallyIncreasingFunctionBecomesPositive {
private int f(int x){
return x*x - 10*x - 20;
}
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>package com.interview.binarysearch;
/**
* @author Tushar Roy
* Date 01/22/17
*
* Search in sorted and rotated array. In one version duplicate is not allowed and
* in another version duplicate is allowed.
*
* Time complexity with no duplicate - O(logn)
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>package com.interview.binarysearch;
/**
* Date 07/31/2016
* @author Tushar Roy
*
* Given a sorted array of integers, find the starting and ending position of a given target value.
*
* Time complexity O(logn)
* Space complexity O(1)
*
* https://leetco... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>package com.interview.binarysearch;
/**
* @author Tushar Roy
* Date 01/17/2107
* A peak element is an element that is greater than its neighbors. Find index of peak element in the array.
*
* Space complexity is O(1)
* Time complexity is O(n)
*
* https:... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>package com.interview.binarysearch;
/**
* http://www.geeksforgeeks.org/check-for-majority-element-in-a-sorted-array/
*/
public class FirstOccurrenceOfNumberInSortedArray {
public int firstOccurrence(int input[], int x){
int low = 0;
int ... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>/**
* Given a binary array sorted in non-increasing order, count the number of 1’s in it.
**/
/* package whatever; // 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 cla... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>// http://www.geeksforgeeks.org/count-1s-sorted-binary-array/
class CountOne {
public static void main(String[] args) {
int[] arr={0, 0, 0, 0, 0, 0, 0};
//int[] arr={1, 1, 1, 1, 1, 1, 1};
//int[] arr = {1, 1, 1, 0, 0, 0, 0};
countOne(arr);
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>public class Search {
public static boolean find2(int[] array, int begin, int end, int element) {
if (begin <= end) {
int medium = begin + (end - begin) / 2;
if (array[medium] == element)
return true;
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java program to reverse the number
// using a stack
import
java.util.Stack;
public
class
GFG
{
// Stack to maintain order of digits
static
Stack<Integer> st=
new
Stack<>();
// Function to push digits into stack
static
void
push_digits(
int
nu... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java program to find number of
// rotations in a sorted and rotated
// array.
import
java.util.*;
import
java.lang.*;
import
java.io.*;
class
BinarySearch
{
// Returns count of rotations for an array
// which is first sorted in ascending order, ... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java program to find minimum element in a sorted and rotated array
import
java.util.*;
import
java.lang.*;
import
java.io.*;
class
Minimum
{
static
int
findMin(
int
arr[],
int
low,
int
high)
{
// This condition is needed to handle the case whe... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java implementation of recursive Binary Search
class
BinarySearch {
// Returns index of x if it is present in arr[l..
// r], else return -1
int
binarySearch(
int
arr[],
int
l,
int
r,
int
x)
{
if
(r >= l) {
int
mid = l + (r - l) /
2
;
// ... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java implementation of iterative Binary Search
class
BinarySearch {
// Returns index of x if it is present in arr[],
// else return -1
int
binarySearch(
int
arr[],
int
x)
{
int
l =
0
, r = arr.length -
1
;
while
(l <= r) {
int
m = l + (r -... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java program for Binary Search
import
java.util.*;
class
Binary
{
public
static
int
f(
int
x)
{
return
(x*x -
10
*x -
20
); }
// Returns the value x where above
// function f() becomes positive
// first time.
public
static
int
findFirstP... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
/* Java program to search an element
in a sorted and pivoted array*/
class
Main
{
/* Searches an element key in a
pivoted sorted array arrp[]
of size n */
static
int
pivotedBinarySearch(
int
arr[],
int
n,
int
key)
{
int
pivot = findPivot(arr,... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// A Java program to divide and conquer based
// efficient solution to find
// median of two sorted arrays
// of same size.
import
java.util.*;
class
GfG {
/* This function returns median
of ar1[] and ar2[].
Assumptions in this function:
Both ar1[] ... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
class
Main
{
/* Function to get index of
ceiling of x in arr[low..high]*/
static
int
ceilSearch(
int
arr[],
int
low,
int
high,
int
x)
{
int
mid;
/* If x is smaller than or equal to the
first element, then return the first element */
if
(x <=... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java program to count
// occurrences of an element
class
GFG
{
// A recursive binary search
// function. It returns location
// of x in given array arr[l..r]
// is present, otherwise -1
static
int
binarySearch(
int
arr[],
int
l,
int
r,
int... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java program to check fixed point
// in an array using binary search
class
Main
{
static
int
binarySearch(
int
arr[],
int
low,
int
high)
{
if
(high >= low)
{
/* low + (high - low)/2; */
int
mid = (low + high)/
2
;
if
(mid == arr[mid])
r... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// java program to find maximum
// element
class
Main
{
// function to find the
// maximum element
static
int
findMaximum(
int
arr[],
int
low,
int
high)
{
/* Base Case: Only one element is
present in arr[low..high]*/
if
(low == high)
retu... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// A Java program to find a peak element element using divide and conquer
import
java.util.*;
import
java.lang.*;
import
java.io.*;
class
PeakElement
{
// A binary search based function that returns index of a peak
// element
static
int
findPeakUti... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java program to find minimum element in a sorted and rotated array
import
java.util.*;
import
java.lang.*;
import
java.io.*;
class
Minimum
{
static
int
findMin(
int
arr[],
int
low,
int
high)
{
// This condition is needed to handle the case whe... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java program to find an element
// in an almost sorted array
class
GFG
{
// A recursive binary search based function.
// It returns index of x in given array
// arr[l..r] is present, otherwise -1
int
binarySearch(
int
arr[],
int
l,
int
r,
int
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java program to count 1's in a sorted array
class
CountOnes
{
/* Returns counts of 1's in arr[low..high]. The
array is assumed to be sorted in non-increasing
order */
int
countOnes(
int
arr[],
int
low,
int
high)
{
if
(high >= low)
{
// ge... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
class
SmallestMissing
{
int
findFirstMissing(
int
array[],
int
start,
int
end)
{
if
(start > end)
return
end +
1
;
if
(start != array[start])
return
start;
int
mid = (start + end) /
2
;
// Left half has all elements from 0 to mid
if
(... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.stream.IntStream;
public class B {
public static void main(String[] args) {
InputStream inputStream = System.in;
Outp... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
* @author Don Li
*/
public class OlyaAndMagicalSquare {
void solve() {
long[] dp = new ... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
public class ehab4 {
public static void main( String[] args ) {
Scanner in = new Scanner( System.in );
int a = 0, b = 0;
System.out.println( "? 0 0 " );
System.out.flush();
int c = in.nextInt();
for ( int i = 29; i >= 0; i-... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicReferenceArray;
public class NastyaWardrobe {
static long modulo = 1000000007;
static lo... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
// Java program to count occurrences
// of an element
class
Main
{
/* if x is present in arr[] then returns
the count of occurrences of x,
otherwise returns -1. */
static
int
count(
int
arr[],
int
x,
int
n)
{
// index of first occurrence of x ... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
import java.io.*;
public class code{
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int ok,ok2;
int va,vb;
... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class A1180 {
public static void main(String[] args) throws FileNotFoundExceptio... |
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*;
import java.io.*;
import java.math.*;
public class round569d2b {
public static void main(String args[]) {
FastScanner in = new FastScanner(System.in);
int n = in.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.