prompt
stringlengths
396
31.4k
<|begin_of_text|><|start_header_id|>system<|end_header_id|> class SubarraySum { /* Returns true if the there is a subarray of arr[] with a sum equal to 'sum' otherwise returns false. Also, prints the result */ int subArraySum( int arr[], int n, int sum) { int curr_sum, i, j; // Pick a starting point fo...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find a triplet class FindTriplet { // returns true if there is triplet with sum equal // to 'sum' present in A[]. Also, prints the triplet boolean find3Numbers( int A[], int arr_size, int sum) { int l, r; /* Sort the element...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find triplets in a given // array whose sum is zero import java.util.*; class GFG { // function to print triplets with 0 sum static void findTriplets( int arr[], int n) { boolean found = false ; for ( int i = 0 ; i < n - ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to print a given matrix in spiral form import java.io.*; class GFG { // Function print matrix in spiral form static void spiralPrint( int m, int n, int a[][]) { int i, k = 0 , l = 0 ; /* k - starting row index m - ending row ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java implementation to print // the counter clock wise // spiral traversal of matrix import java.io.*; class GFG { static int R = 4 ; static int C = 4 ; // function to print the // required traversal static void counterClockspiralPrint( i...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java prorgam for finding max path in matrix import static java.lang.Math.max; class GFG { public static int N = 4 , M = 6 ; // Function to calculate max path in matrix static int findMaxPath( int mat[][]) { // To find max val in first row ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to remove duplicates from unsorted // linked list class LinkedList { static Node head; static class Node { int data; Node next; Node( int d) { data = d; next = null ; } } /* Function to remove duplicates from an u...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java Code to find the last man Standing public class GFG { // Node class to store data static class Node { public int data ; public Node next; public Node( int data ) { this .data = data; } } /* Function to find the only person lef...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A Naive Java program to find // maximum sum rotation import java.util.*; import java.io.*; class GFG { // Returns maximum value of i*arr[i] static int maxSum( int arr[], int n) { // Initialize result int res = Integer.MIN_VALUE; // Consider ro...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java implementation for brute force method to calculate stock span values import java.util.Arrays; class GFG { // method to calculate stock span values static void calculateSpan( int price[], int n, int S[]) { // Span value of first day is alw...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to sort an // array using stack import java.io.*; import java.util.*; class GFG { // This function return // the sorted stack static Stack<Integer> sortStack(Stack<Integer> input) { Stack<Integer> tmpStack = new Stack<Integer>...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to implement sorting a // queue data structure import java.util.LinkedList; import java.util.Queue; class GFG { // Queue elements after sortIndex are // already sorted. This function returns // index of minimum element from front to ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program for recursive level order traversal in spiral form /* A binary tree node has data, pointer to left child and a pointer to right child */ class Node { int data; Node left, right; public Node( int d) { data = d; left = right = n...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java Program to find the maximum for each and every contiguous subarray of size k. public class GFG { // Method to find the maximum for each and every contiguous subarray of size k. static void printKMax( int arr[], int n, int k) { int j, max; ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java implementation to find the first negative // integer in every window of size k import java.util.*; class solution { // function to find the first negative // integer in every window of size k static void printFirstNegativeInteger( int arr[], ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A simple Java program to find max subarray XOR class GFG { static int maxSubarrayXOR( int arr[], int n) { int ans = Integer.MIN_VALUE; // Initialize result // Pick starting points of subarrays for ( int i= 0 ; i<n; i++) { // to store xor o...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to split array and move first // part to end. import java.util.*; import java.lang.*; class GFG { public static void splitArr( int arr[], int n, int k) { for ( int i = 0 ; i < k; i++) { // Rotate array by 1. int x = arr[ 0 ];...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to CountKSubStr number of substrings // with exactly distinct characters in a given string import java.util.Arrays; public class CountKSubStr { // Function to count number of substrings // with exactly k unique characters int countkD...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to count number of substrings // with counts of distinct characters as k. class GFG { static int MAX_CHAR = 26 ; // Returns true if all values // in freq[] are either 0 or k. static boolean check( int freq[], int k) { for ( int i ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to count number of substrings // of a string import java.io.*; public class GFG { static int countNonEmptySubstr(String str) { int n = str.length(); return n * (n + 1 ) / 2 ; } // Driver code public static void main(String...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to count all substrings with same // first and last characters. public class GFG { // Returns true if first and last characters // of s are same. static boolean checkEquality(String s) { return (s.charAt( 0 ) == s.charAt(s.length()...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Space efficient Java program to count all // substrings with same first and last characters. public class GFG { static int countSubstringWithEqualEnds(String s) { int result = 0 ; int n = s.length(); // Iterating through all substrings in /...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to split array and move first // part to end. import java.util.*; import java.lang.*; class GFG { // Function to spilt array and // move first part to end public static void SplitAndAdd( int [] A, int length, int rotation){ //make...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to print all words that have // the same unique character set import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Map.Entry; public class GFG { static final int MAX_CHAR = 26 ; // Generat...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A simple C++ program to count number of //substrings starting and ending with 1 class CountSubString { int countSubStr( char str[], int n) { int res = 0 ; // Initialize result // Pick a starting point for ( int i = 0 ; i<n; i++) { if (...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java implementation to find the character in // first string that is present at minimum index // in second string public class GFG { // method to find the minimum index character static void printMinIndexChar(String str, String patt) { // to st...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A Simple Java program to find pairs with distance // equal to English alphabet distance class Test { // Method to count pairs static int countPairs(String str) { int result = 0 ; int n = str.length(); for ( int i = 0 ; i < n; i++) for ( i...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to count number of times // S appears as a subsequence in T import java.io.*; class GFG { static int findSubsequenceCount(String S, String T) { int m = T.length(); int n = S.length(); // T can't appear as a subsequence in S if ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find n'th Bell number import java.io.*; class GFG { // Function to find n'th Bell Number static int bellNumber( int n) { int [][] bell = new int [n+ 1 ][n+ 1 ]; bell[ 0 ][ 0 ] = 1 ; for ( int i= 1 ; i<=n; i++) { // Exp...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> class GFG{ // A dynamic programming based function to find nth // Catalan number static int catalanDP( int n) { // Table to store results of subproblems int catalan[] = new int [n + 2 ]; // Initialize first two values in table catalan[ 0 ] = 1...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A Dynamic Programming based solution that uses table C[][] to // calculate the Binomial Coefficient class BinomialCoefficient { // Returns value of Binomial Coefficient C(n, k) static int binomialCoeff( int n, int k) { int C[][] = new int [n+ ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java code for Dynamic Programming based // solution that uses table P[][] to // calculate the Permutation Coefficient import java.io.*; import java.math.*; class GFG { // Returns value of Permutation // Coefficient P(n, k) static int permutati...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to solve Gold Mine problem import java.util.Arrays; class GFG { static final int MAX = 100 ; // Returns maximum amount of gold that // can be collected when journey started // from first column and moves allowed // are right, ri...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to Rearrange positive // and negative numbers in a array import java.io.*; class GFG { /* Function to print an array */ static void printArray( int A[], int size) { for ( int i = 0 ; i < size; i++) System.out.print(A[i] + " " );...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A Dynamic Programming solution for subset // sum problem class GFG { // Returns true if there is a subset of // set[] with sun equal to given sum static boolean isSubsetSum( int set[], int n, int sum) { // The value of subset[i][j] will be ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to check if there is a subset // with sum divisible by m. import java.util.Arrays; class GFG { // Returns true if there is a subset // of arr[] with sum divisible by m static boolean modularSum( int arr[], int n, int m) { if (...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> import java.util.Arrays; // Java program to find the largest // subset which where each pair // is divisible. class GFG { // function to find the longest Subsequence static int largestSubset( int [] a, int n) { // Sort array in increasing order ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A Dynamic Programming solution for Rod cutting problem class RodCutting { /* Returns the best obtainable price for a rod of length n and price[] as prices of different pieces */ static int cutRod( int price[], int n) { int val[] = new int [n+ 1 ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A memoization based Java program to // count even length binary sequences // such that the sum of first and // second half bits is same import java.io.*; class GFG { // A lookup table to store the results of // subproblems static int lookup[][] = ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Efficient java program to count total number // of special sequences of length n where class Sequences { // DP based function to find the number of special // sequences static int getTotalNumberOfSequences( int m, int n) { // define T and buil...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // java program to find maximum // sum of bi-tonic sub-sequence import java.io.*; class GFG { // Function return maximum sum // of Bi-tonic sub-sequence static int MaxSumBS( int arr[], int n) { int max_sum = Integer.MIN_VALUE; // MSIBS[i] ==...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> /* Dynamic Programming Java implementation of Maximum Sum Increasing Subsequence (MSIS) problem */ class GFG { /* maxSumIS() returns the maximum sum of increasing subsequence in arr[] of size n */ static int maxSumIS( int arr[], int n) { int...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> /* Dynamic programming Java implementation of maximum product of an increasing subsequence */ import java.util.Arrays; import java.util.Collections; class GFG { // Returns product of maximum product // increasing subsequence. static int lis( int []...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find the longest subsequence // such that the difference between adjacent // elements of the subsequence is one. import java.io.*; class GFG { // Function to find the length of longest // subsequence static int longestSubseqWithD...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // JAVA Code for Maximum length subsequence // with difference between adjacent elements // as either 0 or 1 import java.util.*; class GFG { // function to find maximum length subsequence // with difference between adjacent elements as // either 0 ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find maximum sum increasing // subsequence tiint i-th index and including // k-th index. class GFG { static int pre_compute( int a[], int n, int index, int k) { int dp[][] = new int [n][n]; // Initializing the first row of ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> class Pair{ int a; int b; public Pair( int a, int b) { this .a = a; this .b = b; } // This function assumes that arr[] is sorted in increasing order // according the first (or smaller) values in pairs. static int maxChainLength(Pair arr[],...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // JAVA Code for Maximum size square // sub-matrix with all 1s public class GFG { // method for Maximum size square sub-matrix with all 1s static void printMaxSubSquare( int M[][]) { int i,j; int R = M.length; //no of rows in M[][] int C = M[ 0...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java Code for Maximum weight path ending at // any element of last row in a matrix import java.util.*; class GFG { /* Function which return the maximum weight path sum */ public static int maxCost( int mat[][], int N) { // create 2D matrix to...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find Maximum path sum // start any column in row '0' and ends // up to any column in row 'n-1' import java.util.*; class GFG { static int N = 4 ; // function find maximum sum path static int MaximumPath( int Mat[][]) { int ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> /* Java program for Dynamic Programming implementation of Min Cost Path problem */ import java.util.*; class MinimumCostPath { /* A utility function that returns minimum of 3 integers */ private static int min( int x, int y, int z) { if (x < y) ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // JAVA Code for Minimum number of jumps to reach end class GFG{ private static int minJumps( int [] arr, int n) { int jumps[] = new int [n]; // jumps[n-1] will hold the // result int i, j; if (n == 0 || arr[ 0 ] == 0 ) return Integer.MAX_VA...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find minimum removals // to make max-min <= K import java.util.Arrays; class GFG { static int MAX= 100 ; static int dp[][]= new int [MAX][MAX]; // function to check all possible combinations // of removal and return the minimum...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A Dynamic Programming based Java program to find minimum // number operations to convert str1 to str2 class EDIST { static int min( int x, int y, int z) { if (x <= y && x <= z) return x; if (y <= x && y <= z) return y; else return z; } s...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java implementation of finding length of longest // Common substring using Dynamic Programming public class LongestCommonSubSequence { /* Returns length of longest common substring of X[0..m-1] and Y[0..n-1] */ static int LCSubStr( char X[], ch...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Space optimized CPP implementation of // longest common substring. import java.io.*; import java.util.*; public class GFG { // Function to find longest // common substring. static int LCSubStr(String X, String Y) { // Find length of both th...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Program to find minimum // total offerings required import java.io.*; class GFG { // Returns minimum // offerings required static int offeringNumber( int n, int templeHeight[]) { int sum = 0 ; // Initialize result // Go through all // t...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to print // equal sum sets of array. import java.io.*; import java.util.*; class GFG { // Function to print equal // sum sets of array. static void printEqualSumSets( int []arr, int n) { int i, currSum, sum = 0 ; // Findin...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> /* Dynamic Programming implementation in Java for longest bitonic subsequence problem */ import java.util.*; import java.lang.*; import java.io.*; class LBS { /* lbs() returns the length of the Longest Bitonic Subsequence in arr[] of size n. The fun...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A Space optimized Dynamic Programming // based Java program for LPS problem class GFG { // Returns the length of the longest // palindromic subsequence in str static int lps(String s) { int n = s.length(); // a[i] is going to store length ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java code to Count Palindromic Subsequence // in a given String public class GFG { // Function return the total palindromic // subsequence static int countPS(String str) { int N = str.length(); // create a 2D array to store the count // of...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java Solution public class LongestPalinSubstring { // A utility function to print a substring str[low..high] static void printSubStr(String str, int low, int high) { System.out.println(str.substring(low, high + 1 )); } // This function print...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find palindromic substrings of a string public class GFG { // Returns total number of palindrome substring of // length greater then equal to 2 static int CountPS( char str[], int n) { // create empty 2-D matrix that counts all...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to query number of palindromic // substrings of a string in a range import java.io.*; class GFG { // Function to construct the dp array static void constructDp( int dp[][], String str) { int l = str.length(); // declare 2D array ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find sum of maximum // sum alternating sequence starting with // first element. public class GFG { // Return sum of maximum sum alternating // sequence starting with arr[0] and is first // decreasing. static int maxAlternateSum(...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find longest // alternating subsequence in an array import java.io.*; class GFG { // Function to return longest // alternating subsequence length static int zzis( int arr[], int n) { /*las[i][0] = Length of the longest alternat...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to print postorder // traversal from preorder and // inorder traversals import java.util.Arrays; class GFG { // A utility function to search x in arr[] of size n static int search( int arr[], int x, int n) { for ( int i = 0 ; i <...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to print Postorder traversal from given Inorder // and Preorder traversals. public class PrintPost { static int preIndex = 0 ; void printPost( int [] in, int [] pre, int inStrt, int inEnd) { if (inStrt > inEnd) return ; // F...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program for recursive level order traversal in spiral form /* A binary tree node has data, pointer to left child and a pointer to right child */ class Node { int data; Node left, right; public Node( int d) { data = d; left = right = n...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A recursive java program to print reverse level order traversal // A binary tree node class Node { int data; Node left, right; Node( int item) { data = item; left = right; } } class BinaryTree { Node root; /* Function to print RE...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to construct a tree using inorder and preorder traversal /* A binary tree node has data, pointer to left child and a pointer to right child */ class Node { char data; Node left, right; Node( char item) { data = item; left = rig...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java Program to construct ancestor matrix for a given tree import java.util.*; class GFG { // ancestorMatrix function to populate the matrix of public static void ancestorMatrix(Node root , int matrix[][], int size) { // base case: if (root...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to construct tree from inorder traversal /* A binary tree node has data, pointer to left child and a pointer to right child */ class Node { int data; Node left, right; Node( int item) { data = item; left = right = null ; } ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to construct a tree using inorder // and postorder traversals /* A binary tree node has data, pointer to left child and a pointer to right child */ class Node { int data; Node left, right; public Node( int data) { this .data = d...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to convert an arbitrary binary tree to a tree that holds // children sum property // A binary tree node class Node { int data; Node left, right; Node( int item) { data = item; left = right = null ; } } class BinaryTree ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to check if Binary tree is sum tree or not /* A binary tree node has data, left child and right child */ class Node { int data; Node left, right, nextRight; Node( int item) { data = item; left = right = nextRight = null ; } ...
<|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 BinaryTree { Node root; ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> /* Java program to check if all three given traversals are of the same tree */ import java.util.*; class GfG { static int preIndex = 0 ; // A Binary Tree Node static class Node { int data; Node left, right; } // Utility function to create a new...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A Java program for Prim's Minimum Spanning Tree (MST) algorithm. // The program is for adjacency matrix representation of the graph import java.util.*; import java.lang.*; import java.io.*; class MST { // Number of vertices in the graph private s...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A Java program for Dijkstra's single source shortest path algorithm. // The program is for adjacency matrix representation of the graph import java.util.*; import java.lang.*; import java.io.*; class ShortestPath { // A utility function to find the...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to to maximize array // sum after k operations. class GFG { // This function does k operations // on array in a way that maximize // the array sum. index --> stores // the index of current minimum // element for j'th operation s...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find lexicographically minimum // value after k swaps. class GFG { // Modifies arr[0..n-1] to lexicographically // smallest with k swaps. static void minimizeWithKSwaps( int arr[], int n, int k) { for ( int i = 0 ; i < n- 1 &...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to find // lexicographically // maximum value after // k swaps. import java.io.*; class GFG { static void SwapInts( int array[], int position1, int position2) { // Swaps elements // in an array. // Copy the first // posi...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // A Java program to implement greedy algorithm for graph coloring import java.io.*; import java.util.*; import java.util.LinkedList; // This class represents an undirected graph using adjacency list class Graph { private int V; // No. of vertices ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java program to fin maximum cash // flow among a set of persons class GFG { // Number of persons (or vertices in the graph) static final int N = 3 ; // A utility function that returns // index of minimum value in arr[] static int getMin( int...
<|begin_of_text|><|start_header_id|>system<|end_header_id|> import java.util.*; import java.lang.*; class Main { static void minAbsSumPair( int arr[], int arr_size) { int inv_count = 0 ; int l, r, min_sum, sum, min_l, min_r; /* Array should have at least two elements*/ if (arr_size < 2 ) { System....
<|begin_of_text|><|start_header_id|>system<|end_header_id|> // Java implementation of simple // algorithm to find smaller // element on left side import java.io.*; class GFG { // Prints smaller elements on // left side of every element static void printPrevSmaller( int []arr, int n) { // Always print empty...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr = new int [n]; int maxindex=0; int minindex=0; int max; ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.*; import java.util.*; public class hi { public static void main(String[] args) throws IOException{ Reader in=new Reader(); PrintWriter w = new PrintWriter(System.out); int n=in.nextInt(); int[] arr=in.nextIntArray(n); int ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*; import java.io.*; public class PartySweet { static BufferedReader br; static StringTokenizer tokenizer; public static void main(String[] args) throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); int n = nex...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.*; import java.util.*; import static java.lang.System.*; public class Main{ public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(in)); StringTokenizer st = new StringToke...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.Scanner; public class Codeforces { public static Scanner input = new Scanner(System.in); public static void main(String[] args){ int n,k; n=input.nextInt(); k=input.nextInt(); String s=input.next(); ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>//Atcoder import java.io.*; import java.util.*; public class Main { static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { try { br = new BufferedReader(new InputStreamRea...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>// // _oo8oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // _...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.io.*; import java.util.*; public class Solution{ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new Input...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.Arrays; import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Solution ss = new Solution(); ss.test(sc); } void test(Scanner sc){ int LEN = sc.nextInt(); ...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*; import java.lang.*; import java.io.*; public class TestClass { // function for finding size of set public static int set_size(int[] a, int N){ HashSet <Integer> newset = new HashSet <Integer>(); int i=0; while...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Cr500 { public static void main(String args[]) { Scanner scanner = new Scanner(System.in); int n, x, status = -1; Set...
<|begin_of_text|><|start_header_id|>system<|end_header_id|>import java.util.*; public class B { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int x = scanner.nextInt(); int[] a = new int[n]; for (int i = 0; i < ...
<|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 n = in.nextInt(); int m = in.nextInt(); int[] v = new int[n]; int[] ans = new int[n]; ...