prompt
stringlengths
396
31.4k
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to check if all leaf nodes are at // same level of binary tree import java.util.*; // User defined node class class Node { int data; Node left, right; // Constructor to create a new tree node Node( int key) { int data = key; l...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to check if there exist an edge whose // removal creates two trees of same size class Node { int key; Node left, right; public Node( int key) { this .key = key; left = right = null ; } } class Res { boolean res = fals...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to check whether a given // Binary Tree is Perfect or not class GfG { /* Tree node structure */ static class Node { int key; Node left, right; } // Returns depth of leftmost leaf. static int findADepth(Node node) { int d = 0 ; ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to check if binay tree is full or not /* Tree node structure */ class Node { int data; Node left, right; Node( int item) { data = item; left = right = null ; } } class BinaryTree { Node root; /* this function checks ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> //A Java program to check if a given binary tree is complete or not import java.util.LinkedList; import java.util.Queue; public class CompleteBTree { /* A binary tree node has data, a pointer to left child and a pointer to right child */ static clas...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to check if binary tree // is subtree of another binary tree class Node { char data; Node left, right; Node( char item) { data = item; left = right = null ; } } class Passing { int i; int m = 0 ; int n = 0 ; } ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to see if two trees // are mirror of each other // A binary tree node class Node { int data; Node left, right; public Node( int data) { this .data = data; left = right = null ; } } class BinaryTree { Node a, b; /* ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java implementation of worst // case linear time algorithm // to find k'th smallest element import java.util.*; class GFG { // int partition(int arr[], int l, int r, int k); // A simple function to find median of arr[]. This is called // only for...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java implementation to check whether the two // binary tress are mirrors of each other or not import java.util.*; class GfG { // structure of a node in binary tree static class Node { int data; Node left, right; } // Utility function to create...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to see if two trees are identical // A binary tree node class Node { int data; Node left, right; Node( int item) { data = item; left = right = null ; } } class BinaryTree { Node root1, root2; /* Given two trees, ret...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to see if there is a root to leaf path // with given sequence. public class CheckForPath { // function to check given sequence of root to leaf path exist // in tree or not. // index represents current element in sequence of rooth to ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to print cousins of a node class GfG { // A Binary Tree Node static class Node { int data; Node left, right; } // A utility function to create a new Binary // Tree Node static Node newNode( int item) { Node temp = new Node(); ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java implementation to print the path from root // to a given node in a binary tree import java.util.ArrayList; public class PrintPath { // Returns true if there is a path from root // to the given node. It also populates // 'arr' with the given p...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Recursive Java program to print odd level nodes class GfG { static class Node { int data; Node left, right; } static void printOddNodes(Node root, boolean isOdd) { // If empty tree if (root == null ) return ; // If current node is of o...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Iterative Java program to print odd level nodes import java.util.*; class GfG { static class Node { int data; Node left, right; } // Iterative method to do level order traversal line by line static void printOddNodes(Node root) { // Base Case...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find the all full nodes in // a given binary tree public class FullNodes { // Traverses given tree in Inorder fashion and // prints all nodes that have both children as // non-empty. public static void findFullNode(Node root) { ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java implementation to find // the sum of all the parent // nodes having child node x class GFG { // sum static int sum = 0 ; // Node of a binary tree static class Node { int data; Node left, right; }; // function to get a new node stati...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> class LinkedList { /* head node of link list */ static LNode head; /* Link list Node */ class LNode { int data; LNode next, prev; LNode( int d) { data = d; next = prev = null ; } } /* A Binary Tree Node */ class TNode { int ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java Program to find maximum in arr[] class Test { static int arr[] = { 10 , 324 , 45 , 90 , 9808 }; // Method to find maximum in arr[] static int largest() { int i; // Initialize maximum element int max = arr[ 0 ]; // Traverse arra...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to print BST in given range // A binary tree node class Node { int data; Node left, right; Node( int d) { data = d; left = right = null ; } } class BinaryTree { static Node root; /* A function that constructs Balanced...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to convert BST to binary tree such that sum of // all greater keys is added to every key class Node { int data; Node left, right; Node( int d) { data = d; left = right = null ; } } class Sum { int sum = 0 ; } class B...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find minimum value node in Binary Search Tree // A binary tree node class Node { int data; Node left, right; Node( int d) { data = d; left = right = null ; } } class BinaryTree { static Node head; /* Given a binary...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java implementation to check if the given array // can represent Level Order Traversal of Binary // Search Tree import java.util.*; class Solution { // to store details of a node like // node's data, 'min' and 'max' to obtain the // range of value...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java Program for finding K-th largest Node using O(1) // extra memory and reverse Morris traversal. class GfG { static class Node { int data; Node left, right; } // helper function to create a new Node static Node newNode( int data) { Node ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java code to find second largest element in BST // A binary tree node class Node { int data; Node left, right; Node( int d) { data = d; left = right = null ; } } class BinarySearchTree { // Root of BST Node root; // Constructo...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find k'th largest element in BST import java.util.*; class GfG { // A BST node static class Node { int key; Node left, right; } // A function to find static int KSmallestUsingMorris(Node root, int k) { // Count to iterate o...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to check if a given array is sorted // or not. class GFG { // Function that returns true if array is Inorder // traversal of any Binary Search Tree or not. static boolean isInorder( int [] arr, int n) { // Array has one or no element...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java code to find largest three elements // in an array class PrintLargest { /* Function to print three largest elements */ static void print3largest( int arr[], int arr_size) { int i, first, second, third; /* There should be atleast three el...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java implementation to count pairs from two // BSTs whose sum is equal to a given value x import java.util.Stack; public class GFG { // structure of a node of BST static class Node { int data; Node left, right; // constructor public Node( i...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A Java program to remove BST // keys outside the given range import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; class Node { int key; Node left; Node right; } ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java code to find a pair with given sum // in a Balanced BST import java.util.ArrayList; // A binary tree node class Node { int data; Node left, right; Node( int d) { data = d; left = right = null ; } } class BinarySearchTree { /...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find maximum element in the path // between two Nodes of Binary Search Tree. class Solution { static class Node { Node left, right; int data; } // Create and return a pointer of new Node. static Node createNode( int x) { Nod...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find pairs with given sum such // that one element of pair exists in one BST and // other in other BST. import java.util.*; class solution { // A binary Tree node static class Node { int data; Node left, right; }; // A utilit...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java code to add all greater values to // every node in a given BST // A binary tree node class Node { int data; Node left, right; Node( int d) { data = d; left = right = null ; } } class BinarySearchTree { // Root of BST Node r...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find efficient // solution for the network import java.util.*; class GFG { // number of houses and number // of pipes static int n, p; // Array rd stores the // ending vertex of pipe static int rd[] = new int [ 1100 ]; ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find maximum number of // thieves caught import java.util.*; import java.io.*; class GFG { // Returns maximum number of thieves // that can be caught. static int policeThief( char arr[], int n, int k) { int res = 0 ; Arr...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find maximum product of // a subset. class GFG { static int minProductSubset( int a[], int n) { if (n == 1 ) return a[ 0 ]; // Find count of negative numbers, // count of zeros, maximum valued // negative number, minimum ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find maximum product of // a subset. class GFG { static int maxProductSubset( int a[], int n) { if (n == 1 ) { return a[ 0 ]; } // Find count of negative numbers, count // of zeros, maximum valued negative number // and ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to minimize the // cost of array minimization import java.util.Arrays; public class GFG { // Returns minimum possible // sum in array B[] static int minSum( int [] A, int n) { int min_val = Arrays.stream(A).min().getAsInt(); retur...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to make GCD // of array a mutiple of k. import java.io.*; class GFG { static int MinOperation( int a[], int n, int k) { int result = 0 ; for ( int i = 0 ; i < n; ++i) { // If array value is not 1 // and it is greater th...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // JAVA Code for Find maximum sum possible // equal sum of three stacks class GFG { // Returns maximum possible equal sum of three // stacks with removal of top elements allowed public static int maxSum( int stack1[], int stack2[], int stack3[], i...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to divide n integers // in two groups such that absolute // difference of their sum is minimum import java.io.*; import java.util.*; class GFG { // To print vector along size static void printVector(Vector<Integer> v) { // Print ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find minimum cost // to reduce array size to 1, import java.lang.*; public class GFG { // function to calculate the // minimum cost static int cost( int []a, int n) { int min = a[ 0 ]; // find the minimum using // for lo...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find smallest // number to find smallest number // with N as sum of digits and // divisible by 10^N. import java.io.*; class GFG { static void digitsNum( int N) { // If N = 0 the string will be 0 if (N == 0 ) System.out.prin...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find the smallest number that can be // formed from given sum of digits and number of digits class GFG { // Function to print the smallest possible number with digit sum 's' // and 'm' number of digits static void findSmallest( int...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to rearrange characters in a string // so that no two adjacent characters are same. import java.io.*; import java.util.*; class KeyComparator implements Comparator<Key> { // Overriding compare()method of Comparator public int compare...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to print a string with // no adjacent duplicates by doing // minimum changes to original string import java.util.*; import java.lang.*; public class GfG{ // Function to print simple string public static String noAdjacentDup(String s1...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Recursive Java program to search x in array class Test { static int arr[] = { 12 , 34 , 54 , 2 , 3 }; /* Recursive Method to search x in arr[l..r] */ static int recSearch( int arr[], int l, int r, int x) { if (r < l) return - 1 ; if (...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find missing Number class Main { // Function to ind missing number static int getMissingNo( int a[], int n) { int i, total; total = (n + 1 ) * (n + 2 ) / 2 ; for (i = 0 ; i < n; i++) total -= a[i]; return total; } ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find smallest and second smallest elements import java.io.*; class SecondSmallest { /* Function to print first smallest and second smallest elements */ static void print2Smallest( int arr[]) { int first, second, arr_size = arr.l...
<|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 i; /* If x is smaller than or equal to first element,then return the first element */ if (x <= arr[l...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to count occurrences // of an element class Main { // Returns number of times x occurs in arr[0..n-1] static int countOccurrences( int arr[], int n, int x) { int res = 0 ; for ( int i= 0 ; i<n; i++) if (x == arr[i]) res++; ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to Find the repeating // and missing elements import java.io.*; class GFG { static void printTwoElements( int arr[], int size) { int i; System.out.print( "The repeating element is " ); for (i = 0 ; i < size; i++) { int abs_...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to Find the repeating // and missing elements import java.io.*; class GFG { static int x, y; static void getTwoElements( int arr[], int n) { /* Will hold xor of all elements and numbers from 1 to n */ int xor1; /* Will have...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to check fixed point // in an array using linear search class Main { static int linearSearch( int arr[], int n) { int i; for (i = 0 ; i < n; i++) { if (arr[i] == i) return i; } /* If no fixed point present then return...
<|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) { int max = arr[low]; int i; for (i = low; i <= high; i++) { if (arr[i] > max) ma...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find a pair with the given difference import java.io.*; class PairDifference { // The function assumes that the array is sorted static boolean findPair( int arr[], int n) { int size = arr.length; // Initialize positions of two...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // JAVA Code for Find Second largest // element in an array class GFG { /* Function to print the second largest elements */ public static void print2largest( int arr[], int arr_size) { int i, first, second; /* There should be atleast two eleme...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> /* Java program to find first repeating element in arr[] */ import java.util.*; class Main { // This function prints the first repeating element in arr[] static void printFirstRepeating( int arr[]) { // Initialize index of first repeating element ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find common elements in three arrays class FindCommon { // This function prints common elements in ar1 void findCommon( int ar1[], int ar2[], int ar3[]) { // Initialize starting indexes for ar1[], ar2[] and ar3[] int i = 0 , j...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find pair with sum closest to x import java.io.*; import java.util.*; import java.lang.Math; class CloseSum { // Prints the pair with sum cloest to x static void printClosest( int arr[], int n, int x) { int res_l= 0 , res_r= ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find closest pair in an array class ClosestPair { // ar1[0..m-1] and ar2[0..n-1] are two given sorted // arrays/ and x is given number. This function prints // the pair from both arrays such that the sum of the // pair is closest t...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find a pair with a given // sum in a sorted and rotated array class PairInSortedRotated { // This function returns true if arr[0..n-1] // has a pair with sum equals to x. static boolean pairInSortedRotated( int arr[], int n, int ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find largest pair sum in a given array class Test { static int arr[] = new int []{ 12 , 34 , 10 , 6 , 40 }; /* Method to return largest pair sum. Assumes that there are at-least two elements in arr[] */ static int findLargest...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find smallest and second smallest elements import java.io.*; class SecondSmallest { /* Function to print first smallest and second smallest elements */ static void print2Smallest( int arr[]) { int first, second, arr_size = arr.l...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> import jdk.nashorn.internal.objects.NativeArray; import javax.swing.JOptionPane ; import javax.swing.plaf.basic.BasicInternalFrameTitlePane; import java.sql.SQLSyntaxErrorException; import java.util.Arrays; import java.util.Scanner; ...
<|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 Main { public static void main (String[] args) throws java.lang....
<|begin_of_text|><|start_header_id|>system<|end_header_id|>/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ //package newpackage; import java.util.*; /** * * @author parpaorsa */ pu...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()) { int n=sc.nextInt(); String s=sc.next(); int sum=0; for(int i=0;i<s.length();i++) { if(s.charAt(i...
<|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 Main { public static void main (String[] args) throws java.lang....
<|begin_of_text|><|start_header_id|>system<|end_header_id|>//package com.krakn.CF.B1159; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n; n = sc.nextInt(); int[] arr = new int[n]; for (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 sc=new Scanner(System.in); int n=sc.nextInt(); int tmp; int min=Integer.MAX_VALUE; for(int i=0;i<n;i++) { tmp=sc.nextInt(); if(i>n-1-i) { tmp=t...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.Arrays; import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); /*int n = stdin.nextInt(); for(int i = 0; i < n; i+...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.*; 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 n = in.nextInt(); int m = in.nextInt(); ...
<|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); int n=sc.nextInt(); int k=sc.nextInt(); if(n==k){ String s=new String(); for(int i=0;i<k;i++){ ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>//package com.krakn.CF.D1159; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n, k; n = sc.nextInt(); k = sc.nextInt(); int a = (n -...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> class MaximumSum { /*Function to return max sum such that no two elements are adjacent */ int FindMaxSum( int arr[], int n) { int incl = arr[ 0 ]; int excl = 0 ; int excl_new; int i; for (i = 1 ; i < n; i++) { /* current max excluding...
<|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); int n=sc.nextInt(); int k=sc.nextInt(); if(n==k){ String s=new String(); for(int i=0;i<k;i++){ ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class SFly { public static void main(String[] args) throws IOException { BufferedReader lector = new BufferedReader(new InputStreamReader(System.in)); ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*; import java.lang.*; import java.math.*; import java.io.*; /* spar5h */ public class cf1 implements Runnable{ public void run() { InputReader s = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int ...
<|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 n = in.nextInt(); int m = in.nextInt(); String str = in.next(); boolean[] exist = new boolean[200]; int dn[][] = n...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.*; public class First { StreamTokenizer in; PrintWriter out; int nextInt() throws IOException { in.nextToken(); return (int)in.nval; } long nextLong() throws IOException { in.nextToken(); re...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*; import java.io.*; public class Solution { public static void main(String [] args) throws IOException { PrintWriter pw=new PrintWriter(System.out);//use pw.println() not pw.write(); BufferedReader br=new BufferedReade...
<|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 n = in.nextInt(); int cnt = 0; String ans = "Yes"; for(int i = 0; i < n; i++) cnt += in.nextInt(); for(int i...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*; import java.io.*; public class Piles { static int summation(int arr[]) { int k, sum=0; for(k=0;k<arr.length;k++) { sum = sum + arr[k]; } return sum; } public static void main(String[] args) { Scanner sc = new Scanner(System...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // JAVA Code to find total count of an element // in a range class GFG { // Returns count of element in arr[left-1..right-1] public static int findFrequency( int arr[], int n, int left, int right, int element) { int count = 0 ; for ( int i...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> import java.util.Scanner; public class Stones { public static void main(String[] args) { Scanner input=new Scanner(System.in); int n=input.nextInt(); int s1=0; int s2=0; for (int i=0;i<n;++i) s1+=input.nextInt(); for (int i=0;i<n;++i) s2+=...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.Scanner; public class Piles { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int[] a = new int[2]; int x = scan.nextInt(); for(int i = 0; i < 2; i++) for(int j = 0; j < x; j++) a[i] += scan.nextInt(); ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*; import static java.lang.Math.*; import java.io.*; public class SolutionB { public static void main(String args[])throws IOException{ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>//package contese_476; import java.util.*; public class q1 { int m=(int)1e9+7; public class Node { int a; int b; public void Node(int a,int b) { this.a=a; this.b=b; } } public int mul(int a ,int b) { a=a%m; b=b%m; return((a*b)%m); } public int pow(in...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>/** * Created by Baelish on 7/30/2018. */ import java.io.*; import java.util.*; import static java.lang.Math.*; public class B { public static void main(String[] args)throws Exception { FastReader in = new FastReader(System.in); PrintWri...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find max value of i*arr[i] import java.util.Arrays; class Test { static int arr[] = new int []{ 10 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 }; // Returns max possible value of i*arr[i] static int maxSum() { // Find array...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class TaskA { public static void main(Str...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*; public class CoinsTask { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int S = in.nextInt(); int mCoins = 0; while(S/n != 0) { mCoins+=1; S-=n; } mCoins = S == 0? ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.Scanner; public class P1075A { public static void main(String[] args) { Scanner scan=new Scanner(System.in); long n,x,y; n=scan.nextLong(); x=scan.nextLong(); y=scan.nextLong(); boolean flag=true,flag1=false,flag2=false; long w1...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*; public class kingrace {public static void main(String[] args) { Scanner input=new Scanner(System.in); long a = input.nextLong(); input.nextLine(); String [] coo = input.nextLine().split(" "); long xcoin = Long.parseLong(...
<|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 { // function that answers every query // in O(r-l) static int answer_query( int a[], int n, int l, int r) { // traverse from l to r and count ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int n=sc.nextInt(),m=sc.nextInt(); int loca[]=new int[n+m]; int res[]=new int[m]; for(int i=0;i<n+m;i++) loca[i]=sc.nextIn...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> import java.util.Scanner; public class TaxiDriversAndLyft2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); long n = scanner.nextLong(); long m = scanner.nextLong(); long[] people = new long[(int) (n+m)]; int[]...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*; import java.io.*; public class Solution{ public static long page(long p,long k){ return (p-1)/k; } public static void main(String[] args) throws Exception { Scanner sc = new Scanner(Sys...