dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . util . * ; class GFG { static void longestSequence ( int arr [ ] , int N ) { if ( N == 0 ) { System . out . println ( 0 ) ; return ; } Arrays . sort ( arr ) ; int maxLen = 1 ; int len = 1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] arr [ i ] == arr [ i - 1 ] + 1 ) { len ++ ; maxLen = Math . max ( maxLen , len ) ; } else { len = 1 ; } } System . out . println ( maxLen ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 8 , 5 , 4 , 8 , 4 } ; int N = arr . length ; longestSequence ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i, len
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void minSum ( int arr [ ] , int N , int Q [ ] , int M ) { for ( int i = 0 ; i < M ; i ++ ) { int val = Q [ i ] ; int front = 0 , rear = 0 ; for ( int j = 0 ; j < N ; j ++ ) { front += arr [ j ] ; if ( arr [ j ] == val ) { break ; } } for ( int j = N - 1 ; j >= 0 ; j -- ) { rear += arr [ j ] ; if ( arr [ j ] == val ) { break ; } } System . out . print ( Math . min ( front , rear ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 6 , 7 , 4 , 5 , 1 } ; int N = arr . length ; int Q [ ] = { 7 , 6 } ; int M = Q . length ; minSum ( arr , N , Q , M ) ; } }

Index/key variables: i, j
Accumulator variables: front, i, j, rear
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static void KthCharacter ( String S , int N , int K ) { char strarray [ ] = S . toCharArray ( ) ; Arrays . sort ( strarray ) ; char ch = strarray [ K - 1 ] ; int count = 0 ; for ( char c : strarray ) { if ( c == ch ) count ++ ; } System . out . println ( count ) ; } public static void main ( String [ ] args ) { String S = " geeksforgeeks " ; int N = S . length ( ) ; int K = 3 ; KthCharacter ( S , N , K ) ; } }

Accumulator variables: count
Iterator variables: c
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void findSubstring ( String S ) { String T = " " ; String ans = " " ; int l = 0 ; T += S . charAt ( 0 ) ; for ( int i = 1 ; i < S . length ( ) ; i ++ ) { if ( Math . abs ( S . charAt ( i ) - S . charAt ( i - 1 ) ) == 1 ) { l = T . length ( ) ; if ( l > ans . length ( ) ) { ans = T ; } T = " " ; T += S . charAt ( i ) ; } else { T += S . charAt ( i ) ; } } l = T . length ( ) ; if ( l > ans . length ( ) ) { ans = T ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { String S = " aabdml " ; findSubstring ( S ) ; } }

Accumulator variables: T, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findMinLength ( int arr [ ] , int N ) { int front = 0 , back = N - 1 ; while ( front < back ) { int x = arr [ front ] ; if ( arr [ front ] != arr [ back ] ) break ; while ( arr [ front ] == x && front <= back ) front ++ ; while ( arr [ back ] == x && front <= back ) back -- ; } System . out . println ( back - front + 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 2 , 3 , 3 , 1 , 2 , 2 , 1 } ; int N = arr . length ; findMinLength ( arr , N ) ; } }

Index/key variables: back, front
Accumulator variables: back, front
Class/struct names: GFG
Java program:
public class GFG { static void prefixArr ( int arr [ ] , int prefix [ ] [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( i == 0 ) { prefix [ i ] [ 0 ] = arr [ i ] ; prefix [ i ] [ 1 ] = arr [ i ] ; } else { prefix [ i ] [ 0 ] = Math . max ( prefix [ i - 1 ] [ 0 ] , arr [ i ] ) ; prefix [ i ] [ 1 ] = Math . min ( prefix [ i - 1 ] [ 1 ] , arr [ i ] ) ; } } } static void suffixArr ( int arr [ ] , int suffix [ ] [ ] , int N ) { for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( i == N - 1 ) { suffix [ i ] [ 0 ] = arr [ i ] ; suffix [ i ] [ 1 ] = arr [ i ] ; } else { suffix [ i ] [ 0 ] = Math . max ( suffix [ i + 1 ] [ 0 ] , arr [ i ] ) ; suffix [ i ] [ 1 ] = Math . min ( suffix [ i + 1 ] [ 1 ] , arr [ i ] ) ; } } } static void maxAndmin ( int prefix [ ] [ ] , int suffix [ ] [ ] , int N , int L , int R ) { int maximum , minimum ; if ( L == 0 && R == N - 1 ) { System . out . println ( " No ▁ maximum ▁ and ▁ minimum ▁ value " ) ; return ; } else if ( L == 0 ) { maximum = suffix [ R + 1 ] [ 0 ] ; minimum = suffix [ R + 1 ] [ 1 ] ; } else if ( R == N - 1 ) { maximum = prefix [ L - 1 ] [ 0 ] ; minimum = prefix [ R - 1 ] [ 1 ] ; } else { maximum = Math . max ( prefix [ L - 1 ] [ 0 ] , suffix [ R + 1 ] [ 0 ] ) ; minimum = Math . min ( prefix [ L - 1 ] [ 1 ] , suffix [ R + 1 ] [ 1 ] ) ; } System . out . println ( maximum + " ▁ " + minimum ) ; } static void MinMaxQueries ( int a [ ] , int Q [ ] [ ] ) { int N = a . length ; int q = Q . length ; int prefix [ ] [ ] = new int [ N ] [ 2 ] ; int suffix [ ] [ ] = new int [ N ] [ 2 ] ; prefixArr ( a , prefix , N ) ; suffixArr ( a , suffix , N ) ; for ( int i = 0 ; i < q ; i ++ ) { int L = Q [ i ] [ 0 ] ; int R = Q [ i ] [ 1 ] ; maxAndmin ( prefix , suffix , N , L , R ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 1 , 8 , 3 , 5 , 7 , 4 } ; int queries [ ] [ ] = { { 4 , 6 } , { 0 , 4 } , { 3 , 7 } , { 2 , 5 } } ; MinMaxQueries ( arr , queries ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static String finddigits ( String s ) { String [ ] num = { " zero " , " one " , " two " , " three " , " four " , " five " , " six " , " seven " , " eight " , " nine " } ; int [ ] arr = new int [ 10 ] ; String ans = " " ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' z ' ) arr [ 0 ] ++ ; if ( s . charAt ( i ) == ' w ' ) arr [ 2 ] ++ ; if ( s . charAt ( i ) == ' g ' ) arr [ 8 ] ++ ; if ( s . charAt ( i ) == ' x ' ) arr [ 6 ] ++ ; if ( s . charAt ( i ) == ' v ' ) arr [ 5 ] ++ ; if ( s . charAt ( i ) == ' o ' ) arr [ 1 ] ++ ; if ( s . charAt ( i ) == ' s ' ) arr [ 7 ] ++ ; if ( s . charAt ( i ) == ' f ' ) arr [ 4 ] ++ ; if ( s . charAt ( i ) == ' h ' ) arr [ 3 ] ++ ; if ( s . charAt ( i ) == ' i ' ) arr [ 9 ] ++ ; } arr [ 7 ] -= arr [ 6 ] ; arr [ 5 ] -= arr [ 7 ] ; arr [ 4 ] -= arr [ 5 ] ; arr [ 1 ] -= ( arr [ 2 ] + arr [ 4 ] + arr [ 0 ] ) ; arr [ 3 ] -= arr [ 8 ] ; arr [ 9 ] -= ( arr [ 5 ] + arr [ 6 ] + arr [ 8 ] ) ; for ( int i = 0 ; i < 10 ; i ++ ) { for ( int j = 0 ; j < arr [ i ] ; j ++ ) { ans += ( char ) ( i + '0' ) ; } } return ans ; } public static void main ( String [ ] args ) { String s = " owoftnuoer " ; System . out . println ( finddigits ( s ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void check ( String s1 , String s2 ) { int s1_0 = 0 , s2_0 = 0 ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { if ( s1 . charAt ( i ) == '0' ) { s1_0 ++ ; } if ( s2 . charAt ( i ) == '0' ) { s2_0 ++ ; } } if ( s1_0 != s2_0 ) { System . out . println ( " NO " ) ; return ; } else { int Count1 = 0 , Count2 = 0 ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { if ( s1 . charAt ( i ) == '0' ) { Count1 ++ ; } if ( s2 . charAt ( i ) == '0' ) { Count2 ++ ; } if ( Count1 < Count2 ) { System . out . println ( " NO " ) ; return ; } } System . out . println ( " YES " ) ; } } public static void main ( String [ ] args ) { String s1 = "100111" ; String s2 = "111010" ; check ( s1 , s2 ) ; s1 = "110100" ; s2 = "010101" ; check ( s1 , s2 ) ; } }

Accumulator variables: Count1, Count2, i, s1_0, s2_0
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void isBinaryStringsEqual ( String str1 , String str2 ) { int str1Zeros = 0 , str1Ones = 0 ; int str2Zeros = 0 , str2Ones = 0 ; int flag = 0 ; int curStr1Ones = 0 ; for ( int i = 0 ; i < str1 . length ( ) ; i ++ ) { if ( str1 . charAt ( i ) == '1' ) { str1Ones ++ ; } else if ( str1 . charAt ( i ) == '0' ) { str1Zeros ++ ; } if ( str2 . charAt ( i ) == '1' ) { str2Ones ++ ; } else if ( str2 . charAt ( i ) == '0' ) { str2Zeros ++ ; } } if ( str1Zeros != str2Zeros && str1Ones != str2Ones ) { System . out . println ( " Not ▁ Possible " ) ; } else { for ( int i = 0 ; i < str1 . length ( ) ; i ++ ) { if ( str1 . charAt ( i ) != str2 . charAt ( i ) ) { if ( str1 . charAt ( i ) == '0' && curStr1Ones > 0 ) { str1 = str1 . substring ( 0 , i ) + '1' + str1 . substring ( i + 1 ) ; curStr1Ones -- ; } if ( str1 . charAt ( i ) == '0' && curStr1Ones == 0 ) { flag ++ ; break ; } if ( str1 . charAt ( i ) == '1' && str2 . charAt ( i ) == '0' ) { str1 = str1 . substring ( 0 , i ) + '0' + str1 . substring ( i + 1 ) ; curStr1Ones ++ ; } } } if ( flag == 0 ) { System . out . println ( " Possible " ) ; } else { System . out . println ( " Not ▁ Possible " ) ; } } } public static void main ( String [ ] args ) { String str1 = "0110" ; String str2 = "0011" ; isBinaryStringsEqual ( str1 , str2 ) ; } }

Accumulator variables: curStr1Ones, flag, i, str1Ones, str1Zeros, str2Ones, str2Zeros
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int noOfValidKbers ( int K , int arr [ ] ) { HashSet < Integer > set = new HashSet < > ( ) ; while ( K != 0 ) { set . add ( K % 10 ) ; K = K / 10 ; } int count = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { int no = arr [ i ] ; boolean flag = true ; while ( no != 0 ) { int digit = no % 10 ; if ( ! set . contains ( digit ) ) { flag = false ; break ; } no = no / 10 ; } if ( flag == true ) { count ++ ; } } return count ; } public static void main ( String [ ] args ) { int K = 12 ; int arr [ ] = { 1 , 12 , 1222 , 13 , 2 } ; System . out . println ( noOfValidKbers ( K , arr ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxN = 100 ; static int Tree [ ] = new int [ 4 * maxN ] ; static void build ( int arr [ ] , int index , int s , int e ) { if ( s == e ) Tree [ index ] = arr [ s ] ; else { int m = ( s + e ) / 2 ; build ( arr , 2 * index , s , m ) ; build ( arr , 2 * index + 1 , m + 1 , e ) ; Tree [ index ] = Math . max ( Tree [ 2 * index ] , Tree [ 2 * index + 1 ] ) ; } } static int atleast_x ( int index , int s , int e , int ql , int qr , int x ) { if ( ql > e qr < s ) return - 1 ; if ( s <= ql && e <= qr ) { if ( Tree [ index ] < x ) return - 1 ; while ( s != e ) { int m = ( s + e ) / 2 ; if ( Tree [ 2 * index ] >= x ) { e = m ; index = 2 * index ; } else { s = m + 1 ; index = 2 * index + 1 ; } } return s ; } int m = ( s + e ) / 2 ; int val = atleast_x ( 2 * index , s , m , ql , qr , x ) ; if ( val != - 1 ) return val ; return atleast_x ( 2 * index + 1 , m + 1 , e , ql , qr , x ) ; } static void update ( int index , int s , int e , int new_val , int pos ) { if ( s == e ) Tree [ index ] = new_val ; else { int m = ( s + e ) / 2 ; if ( pos <= m ) { update ( 2 * index , s , m , new_val , pos ) ; } else { update ( 2 * index + 1 , m + 1 , e , new_val , pos ) ; } Tree [ index ] = Math . max ( Tree [ 2 * index ] , Tree [ 2 * index + 1 ] ) ; } } static void printAnswer ( int [ ] arr , int n ) { build ( arr , 1 , 0 , n - 1 ) ; System . out . println ( atleast_x ( 1 , 0 , n - 1 , 0 , n - 1 , 2 ) ) ; arr [ 2 ] = 5 ; update ( 1 , 0 , n - 1 , 5 , 2 ) ; System . out . println ( atleast_x ( 1 , 0 , n - 1 , 0 , n - 1 , 4 ) ) ; System . out . println ( atleast_x ( 1 , 0 , n - 1 , 0 , n - 1 , 0 ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 2 , 4 , 6 } ; int N = arr . length ; printAnswer ( arr , N ) ; } }

Index/key variables: index, s
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class TreeNode { int val ; TreeNode left ; TreeNode right ; TreeNode ( int data ) { this . val = data ; left = null ; right = null ; } } ; static int find_ht ( TreeNode root ) { if ( root == null ) return 0 ; if ( root . left == null && root . right == null ) return 1 ; return Math . max ( find_ht ( root . left ) , find_ht ( root . right ) ) + 1 ; } static TreeNode find_node ( TreeNode root , TreeNode req_node ) { if ( root == null ) return req_node ; int left_ht = find_ht ( root . left ) ; int right_ht = find_ht ( root . right ) ; if ( left_ht > right_ht ) { req_node = find_node ( root . left , req_node ) ; } else if ( right_ht > left_ht ) { req_node = find_node ( root . right , req_node ) ; } else { req_node = root ; return req_node ; } return req_node ; } public static void main ( String [ ] args ) { TreeNode root = new TreeNode ( 1 ) ; root . left = new TreeNode ( 2 ) ; root . right = new TreeNode ( 3 ) ; TreeNode req_node = null ; req_node = find_node ( root , req_node ) ; System . out . print ( req_node . val ) ; } }

Class/struct names: GFG, TreeNode
Java program:
import java . util . * ; class GFG { static int maxEvenIntegers ( int arr [ ] , int N , int M ) { int ans = 0 ; for ( int i = 0 ; i <= N - M ; i ++ ) { int cnt = 0 ; for ( int j = 0 ; j < M ; j ++ ) { if ( arr [ i + j ] % 2 == 0 ) cnt ++ ; } ans = Math . max ( ans , cnt ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 5 , 4 , 7 , 6 } ; int K = 3 ; int N = arr . length ; System . out . print ( maxEvenIntegers ( arr , N , K ) + "NEW_LINE"); } }

Accumulator variables: cnt, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
public class GFG { static int countDiv ( int [ ] arr ) { int rem0 = 0 ; int rem1 = 0 ; int rem2 = 0 ; for ( int i : arr ) { int digitSum = 0 ; digitSum += i ; if ( digitSum % 3 == 0 ) { rem0 += 1 ; } else if ( digitSum % 3 == 1 ) { rem1 += 1 ; } else { rem2 += 1 ; } } return ( rem0 / 2 + Math . min ( rem1 , rem2 ) ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 5 , 3 , 2 , 8 , 7 } ; System . out . println ( countDiv ( arr ) ) ; } }

Accumulator variables: digitSum, rem0, rem1, rem2
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MaxNonEmpSubSeq ( int a [ ] , int n ) { int sum = 0 ; int max = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( max < a [ i ] ) { max = a [ i ] ; } } if ( max <= 0 ) { return max ; } for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > 0 ) { sum += a [ i ] ; } } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { - 2 , 11 , - 4 , 2 , - 3 , - 10 } ; int N = arr . length ; System . out . println ( MaxNonEmpSubSeq ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static long getcount ( long n , int k ) { long res = ( n >> ( k + 1 ) ) << k ; if ( ( ( n >> k ) & 1 ) != 0 ) res += n & ( ( 1 << k ) - 1 ) ; return res ; } public static void main ( String [ ] args ) { long N = 14 ; int K = 2 ; System . out . println ( getcount ( N + 1 , K ) ) ; } }

Accumulator variables: res
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void splitString ( String S , int N ) { char c = S . charAt ( N - 1 ) ; int f = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( S . charAt ( i ) == c ) { f = 1 ; break ; } } if ( f > 0 ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } public static void main ( String [ ] args ) { String S = " abcdab " ; int N = S . length ( ) ; splitString ( S , N ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static char longestLastingBulb ( int [ ] onTime , char [ ] s ) { char ans ; int n = onTime . length ; int maxDur = Integer . MIN_VALUE ; int maxPos = Integer . MIN_VALUE ; int currentDiff = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i == 0 ) { currentDiff = onTime [ i ] ; maxDur = currentDiff ; maxPos = i ; } else { currentDiff = onTime [ i ] - onTime [ i - 1 ] ; if ( maxDur < currentDiff ) { maxDur = currentDiff ; maxPos = i ; } else { if ( maxDur == currentDiff ) { char one = s [ i ] ; char two = s [ maxPos ] ; if ( one > two ) { maxDur = currentDiff ; maxPos = i ; } } } } } ans = s [ maxPos ] ; return ans ; } public static void main ( String [ ] args ) { String S = " spuda " ; int [ ] arr = { 12 , 23 , 36 , 46 , 62 } ; System . out . print ( longestLastingBulb ( arr , S . toCharArray ( ) ) ) ; } }

Index/key variables: i, maxPos
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; class GFG { static ArrayList < int [ ] > tup = new ArrayList < > ( ) ; static void findIntersectingRange ( int N , int ranges [ ] [ ] ) { int curr ; int currPos ; for ( int i = 0 ; i < N ; i ++ ) { int x , y ; x = ranges [ i ] [ 0 ] ; y = ranges [ i ] [ 1 ] ; int [ ] arr = { x , y , i + 1 } ; tup . add ( arr ) ; } Collections . sort ( tup , new Comparator < int [ ] > ( ) { public int compare ( int [ ] a , int [ ] b ) { if ( a [ 0 ] == b [ 0 ] ) { if ( a [ 1 ] == b [ 1 ] ) { return a [ 2 ] - b [ 2 ] ; } else { return a [ 1 ] - b [ 1 ] ; } } return a [ 0 ] - b [ 0 ] ; } } ) ; curr = tup . get ( 0 ) [ 1 ] ; currPos = tup . get ( 0 ) [ 2 ] ; for ( int i = 1 ; i < N ; i ++ ) { int Q = tup . get ( i - 1 ) [ 0 ] ; int R = tup . get ( i ) [ 0 ] ; if ( Q == R ) { if ( tup . get ( i - 1 ) [ 1 ] < tup . get ( i ) [ 1 ] ) System . out . print ( tup . get ( i - 1 ) [ 2 ] + " ▁ " + tup . get ( i ) [ 2 ] ) ; else System . out . print ( tup . get ( i ) [ 2 ] + " ▁ " + tup . get ( i - 1 ) [ 2 ] ) ; return ; } int T = tup . get ( i ) [ 1 ] ; if ( T <= curr ) { System . out . print ( tup . get ( i ) [ 2 ] + " ▁ " + currPos ) ; return ; } else { curr = T ; currPos = tup . get ( i ) [ 2 ] ; } } System . out . print ( " - 1 ▁ - 1" ) ; } public static void main ( String [ ] args ) { int N = 5 ; int ranges [ ] [ ] = { { 1 , 5 } , { 2 , 10 } , { 3 , 10 } , { 2 , 2 } , { 2 , 15 } } ; findIntersectingRange ( N , ranges ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void printNGE ( int arr [ ] , int n ) { Stack < Integer > s = new Stack < > ( ) ; int nge [ ] = new int [ n ] ; int i = 0 ; for ( i = 0 ; i < n ; i ++ ) { nge [ i ] = - 1 ; } i = 0 ; while ( i < 2 * n ) { while ( ! s . isEmpty ( ) && arr [ i % n ] > arr [ s . peek ( ) ] ) { nge [ s . peek ( ) ] = arr [ i % n ] ; s . pop ( ) ; } s . push ( i % n ) ; i ++ ; } for ( i = 0 ; i < n ; i ++ ) { System . out . print ( nge [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 4 , - 2 , 5 , 8 } ; int N = arr . length ; printNGE ( arr , N ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int N = 100005 ; static void SieveOfEratosthenes ( boolean prime [ ] , int p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } static int digitProduct ( int number ) { int res = 1 ; while ( number > 0 ) { res *= ( number % 10 ) ; number /= 10 ; } return res ; } static void DistinctCompositeDigitProduct ( int arr [ ] , int n ) { TreeSet < Integer > output = new TreeSet < Integer > ( ) ; boolean prime [ ] = new boolean [ N + 1 ] ; Arrays . fill ( prime , true ) ; SieveOfEratosthenes ( prime , N ) ; for ( int i = 0 ; i < n ; i ++ ) { int ans = digitProduct ( arr [ i ] ) ; if ( ans <= 1 ) { continue ; } if ( ! prime [ ans ] ) { output . add ( ans ) ; } } System . out . print ( output . size ( ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 13 , 55 , 7 , 13 , 11 , 71 , 233 , 233 , 144 , 89 } ; int n = arr . length ; DistinctCompositeDigitProduct ( arr , n ) ; } }

Index/key variables: ans, i, p
Accumulator variables: i, number, p, res
Iterator variables: i, p
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static ArrayList < Integer > simpleSieve ( int lmt , ArrayList < Integer > prime ) { boolean [ ] Sieve = new boolean [ lmt + 1 ] ; Arrays . fill ( Sieve , true ) ; Sieve [ 0 ] = Sieve [ 1 ] = false ; for ( int i = 2 ; i <= lmt ; ++ i ) { if ( Sieve [ i ] == true ) { prime . add ( i ) ; for ( int j = i * i ; j <= lmt ; j += i ) { Sieve [ j ] = false ; } } } return prime ; } static boolean [ ] SegmentedSieveFn ( int low , int high ) { int lmt = ( int ) ( Math . sqrt ( high ) ) + 1 ; ArrayList < Integer > prime = new ArrayList < Integer > ( ) ; prime = simpleSieve ( lmt , prime ) ; int n = high - low + 1 ; boolean [ ] segmentedSieve = new boolean [ n + 1 ] ; Arrays . fill ( segmentedSieve , true ) ; for ( int i = 0 ; i < prime . size ( ) ; i ++ ) { int lowLim = ( int ) ( low / prime . get ( i ) ) * prime . get ( i ) ; if ( lowLim < low ) { lowLim += prime . get ( i ) ; } for ( int j = lowLim ; j <= high ; j += prime . get ( i ) ) { if ( j != prime . get ( i ) ) { segmentedSieve [ j - low ] = false ; } } } return segmentedSieve ; } static int countPairsWhoseSumPrimeL_R ( int L , int R ) { boolean [ ] segmentedSieve = SegmentedSieveFn ( L , R ) ; int cntPairs = 0 ; for ( int i = L ; i <= R ; i ++ ) { if ( segmentedSieve [ i - L ] ) { cntPairs += i / 2 ; } } return cntPairs ; } public static void main ( String [ ] args ) { int L = 1 , R = 5 ; System . out . println ( countPairsWhoseSumPrimeL_R ( L , R ) ) ; } }

Index/key variables: i, j
Accumulator variables: cntPairs, i, j, lowLim
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int count_zeroes ( int n , String str ) { int cnt = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == '0' ) cnt ++ ; } return cnt ; } static String kReducingStringUtil ( int n , int k , String str , int no_of_zeroes ) { int zeroes_in_2k = ( ( no_of_zeroes ) * ( 2 * k ) ) / n ; int ones_in_2k = 2 * k - zeroes_in_2k ; String temp_str = " " ; for ( int i = 0 ; i < ( zeroes_in_2k ) / 2 ; i ++ ) { temp_str += '0' ; } for ( int i = 0 ; i < ones_in_2k ; i ++ ) { temp_str += '1' ; } for ( int i = 0 ; i < ( zeroes_in_2k ) / 2 ; i ++ ) { temp_str += '0' ; } String final_str = " " ; for ( int i = 0 ; i < n / ( 2 * k ) ; i ++ ) { final_str += ( temp_str ) ; } for ( int i = 0 ; i < n % ( 2 * k ) ; i ++ ) { final_str += temp_str . charAt ( i ) ; } return final_str ; } static String kReducingString ( int n , int k , String str ) { int no_of_zeroes = count_zeroes ( n , str ) ; int no_of_ones = n - no_of_zeroes ; if ( no_of_zeroes == 0 no_of_zeroes == n ) { return str ; } if ( k == 1 ) { if ( no_of_zeroes == 0 no_of_zeroes == n ) { return str ; } else { return " Not ▁ Possible " ; } } boolean check = false ; for ( int i = ( n / k ) ; i < n ; i += ( n / k ) ) { if ( no_of_zeroes == i no_of_ones == i ) { check = true ; break ; } } if ( check == false ) { return " Not ▁ Possible " ; } return kReducingStringUtil ( n , k , str , no_of_zeroes ) ; } public static void main ( String [ ] args ) { String str = "0000100001100001" ; int K = 4 ; int N = str . length ( ) ; System . out . println ( kReducingString ( N , K , str ) ) ; } }

Accumulator variables: cnt, final_str, i, temp_str
Iterator variables: i
Boolean variables: check
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countSum ( int a [ ] , int n , int sum ) { int i , j , k ; int count = 0 ; HashMap < Integer , Integer > m = new HashMap < > ( ) ; for ( i = 0 ; i < n - 1 ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { int temp = a [ i ] + a [ j ] ; if ( temp < sum && m . containsKey ( sum - temp ) ) count += m . get ( sum - temp ) ; } for ( j = 0 ; j < i ; j ++ ) { int temp = a [ i ] + a [ j ] ; if ( temp < sum ) if ( m . containsKey ( temp ) ) m . put ( temp , m . get ( temp ) + 1 ) ; else m . put ( temp , 1 ) ; } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 5 , 3 , 1 , 2 , 4 } ; int S = 13 ; int N = arr . length ; System . out . print ( countSum ( arr , N , S ) ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG