dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; static bool isValidDigit ( int digit , int K ) { while ( K != 0 ) { if ( K % 10 == digit ) { return true ; } K = K / 10 ; } return false ; } int noOfValidNumbers ( int K , int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int no = arr [ i ] ; bool flag = true ; while ( no != 0 ) { int digit = no % 10 ; if ( ! isValidDigit ( digit , K ) ) { flag = false ; break ; } no = no / 10 ; } if ( flag == true ) { count ++ ; } } return count ; } int main ( ) { int K = 12 ; int arr [ ] = { 1 , 12 , 1222 , 13 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << noOfValidNumbers ( K , arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minimumIndex ( vector < int > & arr , vector < int > & Q ) { int N = arr . size ( ) ; int M = Q . size ( ) ; vector < pair < int , int > > storeArrIdx ; vector < int > minIdx ( N ) ; for ( int i = 0 ; i < N ; ++ i ) { storeArrIdx . push_back ( { arr [ i ] , i } ) ; } sort ( arr . begin ( ) , arr . end ( ) ) ; sort ( storeArrIdx . begin ( ) , storeArrIdx . end ( ) ) ; minIdx [ N - 1 ] = storeArrIdx [ N - 1 ] . second ; for ( int i = N - 2 ; i >= 0 ; i -- ) { minIdx [ i ] = min ( minIdx [ i + 1 ] , storeArrIdx [ i ] . second ) ; } for ( int i = 0 ; i < M ; i ++ ) { int pos = lower_bound ( arr . begin ( ) , arr . end ( ) , Q [ i ] ) - arr . begin ( ) ; if ( pos == N ) { cout << -1 << " ▁ " ; continue ; } cout << minIdx [ pos ] << " ▁ " ; } } int main ( ) { vector < int > arr = { 1 , 9 } ; vector < int > Q = { 7 , 10 , 0 } ; minimumIndex ( arr , Q ) ; return 0 ; }

Index/key variables: i, pos
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isSubarrayExistUtil ( int arr [ ] , int K , int N ) { int totalXOR = 0 ; int SubarrayXOR = 0 ; for ( int i = 0 ; i < N ; i ++ ) totalXOR ^= arr [ i ] ; for ( int i = 0 ; i < K ; i ++ ) SubarrayXOR ^= arr [ i ] ; if ( SubarrayXOR == ( totalXOR ^ SubarrayXOR ) ) return true ; for ( int i = K ; i < N ; i ++ ) { SubarrayXOR ^= arr [ i ] ; SubarrayXOR ^= arr [ i - 1 ] ; if ( SubarrayXOR == ( totalXOR ^ SubarrayXOR ) ) return true ; } return false ; } void isSubarrayExist ( int arr [ ] , int K , int N ) { if ( isSubarrayExistUtil ( arr , K , N ) ) cout << " YES STRNEWLINE " ; else cout << " NO STRNEWLINE " ; } int32_t main ( ) { int arr [ ] = { 2 , 3 , 3 , 5 , 7 , 7 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 5 ; isSubarrayExist ( arr , K , N ) ; }

Index/key variables: i
Accumulator variables: SubarrayXOR, i, stdc, totalXOR
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countPairs ( int L , int R ) { int count_even ; if ( L % 2 == 0 ) { count_even = ( R / 2 ) - ( L / 2 ) + 1 ; } else { count_even = ( R / 2 ) - ( L / 2 ) ; } int count_odd ; if ( L % 2 == 0 ) { count_odd = ( ( R + 1 ) / 2 ) - ( ( L + 1 ) / 2 ) ; } else { count_odd = ( ( R + 1 ) / 2 ) - ( ( L + 1 ) / 2 ) + 1 ; } count_even *= count_even ; count_odd *= count_odd ; cout << count_even + count_odd ; } int main ( ) { int L = 1 , R = 3 ; countPairs ( L , R ) ; return 0 ; }

Accumulator variables: count_even, count_odd, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getDefiniteFinds ( vector < int > & arr ) { int n = arr . size ( ) ; vector < int > smallestRight ( n + 1 ) ; smallestRight [ n ] = INT_MAX ; for ( int i = n - 1 ; i >= 0 ; i -- ) { smallestRight [ i ] = min ( smallestRight [ i + 1 ] , arr [ i ] ) ; } int mn = INT_MIN ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( mn < arr [ i ] and arr [ i ] < smallestRight [ i + 1 ] ) { ans ++ ; } mn = max ( arr [ i ] , mn ) ; } return ans ; } int main ( ) { vector < int > arr = { 5 , 4 , 9 } ; cout << getDefiniteFinds ( arr ) << endl ; }

Index/key variables: i, n
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void Count_numbers ( int L , int R ) { int count = ( R - L ) / 2 ; if ( R % 2 != 0 L % 2 != 0 ) count += 1 ; cout << count << endl ; } int main ( ) { int L = 6 , R = 30 ; Count_numbers ( L , R ) ; }

Accumulator variables: count, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkReverse ( int leftSum , int rightSum ) { int rev = 0 ; int temp = rightSum ; while ( temp != 0 ) { rev = ( rev * 10 ) + ( temp % 10 ) ; temp /= 10 ; } if ( rev == leftSum ) { return true ; } return false ; } int findIndex ( int arr [ ] , int N ) { int rightSum = 0 ; int leftSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { rightSum += arr [ i ] ; } for ( int i = 0 ; i < N ; i ++ ) { rightSum -= arr [ i ] ; if ( checkReverse ( leftSum , rightSum ) ) { return i ; } leftSum += arr [ i ] ; } return -1 ; } int main ( ) { int arr [ ] = { 5 , 7 , 3 , 6 , 4 , 9 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findIndex ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, leftSum, rightSum, stdc, temp
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define Max  100005
void printUniqDif ( int n , int a [ ] ) { bitset < Max > bset ; bitset < Max > diff ; for ( int i = 0 ; i < n ; i ++ ) { bset . set ( a [ i ] ) ; } for ( int i = 0 ; i <= Max ; i ++ ) { if ( bset [ i ] ) { diff = diff | ( bset >> i ) ; } } int X = bset . count ( ) ; if ( X != n ) { cout << 0 << " ▁ " ; } for ( int i = 1 ; i <= Max ; i ++ ) { if ( diff [ i ] ) { cout << i << " ▁ " ; } } } int main ( ) { int a [ ] = { 1 , 4 , 6 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; printUniqDif ( n , a ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int LCS ( vector < int > & firstArr , vector < int > & secondArr ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < firstArr . size ( ) ; i ++ ) { mp [ firstArr [ i ] ] = i + 1 ; } vector < int > tempArr ; for ( int i = 0 ; i < secondArr . size ( ) ; i ++ ) { if ( mp . find ( secondArr [ i ] ) != mp . end ( ) ) { tempArr . push_back ( mp [ secondArr [ i ] ] ) ; } } vector < int > tail ; tail . push_back ( tempArr [ 0 ] ) ; for ( int i = 1 ; i < tempArr . size ( ) ; i ++ ) { if ( tempArr [ i ] > tail . back ( ) ) tail . push_back ( tempArr [ i ] ) ; else if ( tempArr [ i ] < tail [ 0 ] ) tail [ 0 ] = tempArr [ i ] ; else { auto it = lower_bound ( tail . begin ( ) , tail . end ( ) , tempArr [ i ] ) ; * it = tempArr [ i ] ; } } return ( int ) tail . size ( ) ; } int main ( ) { vector < int > firstArr = { 3 , 5 , 1 , 8 } ; vector < int > secondArr = { 3 , 3 , 5 , 3 , 8 } ; cout << LCS ( firstArr , secondArr ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int totalWays ( int n , string str ) { vector < int > IdxOf0s ; int cntWays = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == '0' ) { IdxOf0s . push_back ( i ) ; } } int M = IdxOf0s . size ( ) ; if ( M == 0 or M % 2 ) { return 0 ; } for ( int i = 2 ; i < M ; i += 2 ) { cntWays = cntWays * ( IdxOf0s [ i ] - IdxOf0s [ i - 1 ] ) ; } return cntWays ; } int main ( ) { string str = "00100" ; int n = str . length ( ) ; cout << totalWays ( n , str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countTriplets ( int * arr , int N ) { vector < int > zero_i ; vector < int > one_i ; unordered_map < int , int > mp ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) zero_i . push_back ( i + 1 ) ; else if ( arr [ i ] == 1 ) one_i . push_back ( i + 1 ) ; else mp [ i + 1 ] = 1 ; } int total = zero_i . size ( ) * one_i . size ( ) * mp . size ( ) ; for ( int i = 0 ; i < zero_i . size ( ) ; i ++ ) { for ( int j = 0 ; j < one_i . size ( ) ; j ++ ) { int p = zero_i [ i ] ; int q = one_i [ j ] ; int r = 2 * p - q ; if ( mp [ r ] > 0 ) total -- ; r = 2 * q - p ; if ( mp [ r ] > 0 ) total -- ; r = ( p + q ) / 2 ; if ( mp [ r ] > 0 && abs ( r - p ) == abs ( r - q ) ) total -- ; } } cout << total ; } int main ( ) { int arr [ ] = { 0 , 1 , 2 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; countTriplets ( arr , N ) ; return 0 ; }

Index/key variables: i, j, r
Accumulator variables: i, j, stdc, total
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void PrimeFactors ( int N ) { stack < int > st ; int i = 2 ; while ( N != 1 ) { if ( N % i == 0 ) { st . push ( i ) ; while ( N % i == 0 ) { N = N / i ; } } i ++ ; } while ( ! st . empty ( ) ) { printf ( " % d ▁ " , st . top ( ) ) ; st . pop ( ) ; } } int main ( ) { int N = 8 ; PrimeFactors ( N ) ; return 0 ; }

Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int CountSubarray ( int arr [ ] , int n , int k ) { int temp = k , count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == temp ) { if ( temp == 1 ) { count ++ ; temp = k ; } else temp -- ; } else { temp = k ; if ( arr [ i ] == k ) i -- ; } } return count ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 7 , 9 , 3 , 2 , 1 , 8 , 3 , 2 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 3 ; cout << CountSubarray ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc, temp
Iterator variables: i
C++ program:
#include " bits / stdc + + . h "
using namespace std ; int LCM ( int A , int B ) { return ( A * B / __gcd ( A , B ) ) ; } int findSmallestNumber ( int X ) { int lcm = 1 ; int temp = X ; while ( temp ) { int last = temp % 10 ; temp /= 10 ; if ( ! last ) continue ; lcm = LCM ( lcm , last ) ; } int answer = ( ( X + lcm - 1 ) / lcm ) * lcm ; cout << answer ; } int main ( ) { int X = 280 ; findSmallestNumber ( X ) ; return 0 ; }

Accumulator variables: temp
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long int
void minSum ( int N ) { ll low = 0 , high = 1e9 ; while ( low + 1 < high ) { ll mid = low + ( high - low ) / 2 ; if ( mid * mid >= N ) { high = mid ; } else { low = mid ; } } ll first = high ; low = 0 ; high = 1e9 ; while ( low + 1 < high ) { ll mid = low + ( high - low ) / 2 ; if ( first * mid > N ) { high = mid ; } else { low = mid ; } } ll second = high ; cout << first + second ; } int main ( ) { int N = 10 ; minSum ( N ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minSum ( int N ) { int ans = ceil ( 2 * sqrt ( N + 1 ) ) ; cout << ans ; } int main ( ) { int N = 10 ; minSum ( N ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define INF  1000000
int pref [ 500005 ] ; int suf [ 500005 ] ; int MAX [ 500005 ] ; void build ( int a [ ] , int tl , int tr , int v ) { if ( tl == tr ) { MAX [ v ] = a [ tl ] ; pref [ v ] = a [ tl ] ; suf [ v ] = a [ tl ] ; } else { int tm = ( tl + tr ) / 2 ; build ( a , tl , tm , v * 2 ) ; build ( a , tm + 1 , tr , v * 2 + 1 ) ; MAX [ v ] = max ( MAX [ v * 2 ] , max ( MAX [ v * 2 + 1 ] , suf [ v * 2 ] + pref [ v * 2 + 1 ] ) ) ; pref [ v ] = max ( pref [ v * 2 ] , pref [ 2 * v ] + ( pref [ 2 * v ] == tm - tl + 1 ) * pref [ v * 2 + 1 ] ) ; suf [ v ] = max ( suf [ v * 2 + 1 ] , suf [ 2 * v + 1 ] + suf [ v * 2 ] * ( suf [ 2 * v + 1 ] == tr - tm ) ) ; } } void update ( int a [ ] , int pos , int tl , int tr , int v ) { if ( tl > pos tr < pos ) { return ; } if ( tl == tr && tl == pos ) { MAX [ v ] = a [ pos ] ; pref [ v ] = a [ pos ] ; suf [ v ] = a [ pos ] ; } else { int tm = ( tl + tr ) / 2 ; update ( a , pos , tl , tm , v * 2 ) ; update ( a , pos , tm + 1 , tr , v * 2 + 1 ) ; MAX [ v ] = max ( MAX [ v * 2 ] , max ( MAX [ v * 2 + 1 ] , suf [ v * 2 ] + pref [ v * 2 + 1 ] ) ) ; pref [ v ] = max ( pref [ v * 2 ] , pref [ 2 * v ] + ( pref [ 2 * v ] == tm - tl + 1 ) * pref [ v * 2 + 1 ] ) ; suf [ v ] = max ( suf [ v * 2 + 1 ] , suf [ 2 * v + 1 ] + ( suf [ 2 * v + 1 ] == tr - tm ) * suf [ v * 2 ] ) ; } } void solveQueries ( int arr [ ] , int n , vector < vector < int > > Q , int k ) { int cntQuery = Q . size ( ) ; build ( arr , 0 , n - 1 , 1 ) ; for ( int i = 0 ; i < cntQuery ; i ++ ) { if ( Q [ i ] [ 0 ] == 1 ) { cout << MAX [ 1 ] << " ▁ " ; } else { arr [ Q [ i ] [ 1 ] - 1 ] ^= 1 ; update ( arr , Q [ i ] [ 1 ] - 1 , 0 , n - 1 , 1 ) ; } } } int main ( ) { int N = 10 ; int arr [ ] = { 1 , 1 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 1 } ; vector < vector < int > > Q = { { 1 } , { 2 , 3 } , { 1 } } ; int K = 3 ; solveQueries ( arr , N , Q , K ) ; }

Index/key variables: i, pos, tl, v
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countFreq ( int N , int K ) { int count = 0 ; while ( N > 0 ) { if ( N % 10 == K ) { count ++ ; } N = N / 10 ; } return count ; } int findElementUtil ( int arr [ ] , int N , int K ) { int c ; int max ; int ele ; max = 0 ; for ( int i = 0 ; i < N ; i ++ ) { c = countFreq ( arr [ i ] , K ) ; if ( c > max ) { max = c ; ele = arr [ i ] ; } } if ( max == 0 ) return -1 ; else return ele ; } void findElement ( int arr [ ] , int N , int K ) { int ele = findElementUtil ( arr , N , K ) ; if ( ele == -1 ) cout << " - 1" ; else cout << ele ; } int main ( ) { int K = 3 ; int arr [ ] = { 3 , 77 , 343 , 456 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findElement ( arr , K , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinDeletions ( vector < pair < int , int > > & v , int n ) { int minDel = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { int L = v [ i ] . first ; int R = v [ i ] . second ; int Count = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( v [ j ] . first >= L && v [ j ] . second <= R ) { Count += 1 ; } } minDel = min ( minDel , n - Count ) ; } return minDel ; } int main ( ) { vector < pair < int , int > > v ; v . push_back ( { 1 , 3 } ) ; v . push_back ( { 4 , 12 } ) ; v . push_back ( { 5 , 8 } ) ; v . push_back ( { 13 , 20 } ) ; int N = v . size ( ) ; cout << findMinDeletions ( v , N ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: Count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxEvenIntegers ( int arr [ ] , int N , int M ) { int curr = 0 ; for ( int i = 0 ; i < M ; i ++ ) { if ( arr [ i ] % 2 == 0 ) curr ++ ; } int ans = curr ; for ( int i = M ; i < N ; i ++ ) { if ( arr [ i - M ] % 2 == 0 ) { curr -- ; } if ( arr [ i ] % 2 == 0 ) curr ++ ; ans = max ( ans , curr ) ; } return ans ; } int main ( ) { int arr [ ] = { 2 , 3 , 5 , 4 , 7 , 6 } ; int M = 3 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxEvenIntegers ( arr , N , M ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: curr, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countNumbers ( int n , int d ) { int total = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int x = i ; while ( x > 0 ) { if ( x % 8 == d ) { total ++ ; break ; } x = x / 8 ; } } cout << total ; } int main ( ) { int n = 20 , d = 7 ; countNumbers ( n , d ) ; return 0 ; }

Accumulator variables: i, stdc, total
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int build ( int tree [ ] , int * A , int start , int end , int node ) { if ( start == end ) { tree [ node ] = A [ start ] ; return tree [ node ] ; } int mid = ( start + end ) / 2 ; int X = build ( tree , A , start , mid , 2 * node + 1 ) ; int Y = build ( tree , A , mid + 1 , end , 2 * node + 2 ) ; return tree [ node ] = min ( X , Y ) ; } int query ( int tree [ ] , int start , int end , int l , int r , int node ) { if ( start > r end < l ) return INT_MAX ; if ( start >= l && end <= r ) return tree [ node ] ; int mid = ( start + end ) / 2 ; int X = query ( tree , start , mid , l , r , 2 * node + 1 ) ; int Y = query ( tree , mid + 1 , end , l , r , 2 * node + 2 ) ; return min ( X , Y ) ; } int longestSubArray ( int * A , int N , int K ) { int res = 1 ; int preSum [ N + 1 ] ; preSum [ 0 ] = A [ 0 ] ; for ( int i = 0 ; i < N ; i ++ ) preSum [ i + 1 ] = preSum [ i ] + A [ i ] ; int tree [ 4 * N + 5 ] ; build ( tree , A , 0 , N - 1 , 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { int start = i ; int end = N - 1 ; int mid ; int max_index = i ; while ( start <= end ) { mid = ( start + end ) / 2 ; int min_element = query ( tree , 0 , N - 1 , i , mid , 0 ) ; int expected_sum = ( mid - i + 1 ) * min_element ; int actual_sum = preSum [ mid + 1 ] - preSum [ i ] ; if ( actual_sum - expected_sum <= K ) { start = mid + 1 ; max_index = max ( max_index , mid ) ; } else { end = mid - 1 ; } } res = max ( res , max_index - i + 1 ) ; } return res ; } int main ( ) { int arr [ ] = { 1 , 7 , 3 , 4 , 5 , 6 } ; int k = 6 ; int n = 6 ; cout << longestSubArray ( arr , n , k ) ; return 0 ; }

Index/key variables: i, node, start
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findCntTriplet ( int N ) { int cntTriplet = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( N % i != 0 ) { cntTriplet += N / i ; } else { cntTriplet += ( N / i ) - 1 ; } } return cntTriplet ; } int main ( ) { int N = 3 ; cout << findCntTriplet ( N ) ; return 0 ; }

Accumulator variables: cntTriplet, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countDivisors ( long long int n ) { int count = 0 ; vector < long long int > divisor ; for ( int i = 2 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) divisor . push_back ( i ) ; else { divisor . push_back ( i ) ; divisor . push_back ( n / i ) ; } } } divisor . push_back ( n ) ; for ( auto x : divisor ) { x -= 1 ; if ( ( n / x ) == ( n % x ) ) count ++ ; } cout << count ; } int main ( ) { long long int N = 1000000000000 ; countDivisors ( N ) ; return 0 ; }

Accumulator variables: count, i, stdc, x
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int smallestIndexArrayElementsFlip ( int arr [ ] , int N ) { int pos = -1 ; for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] *= -1 ; int sum = 0 ; for ( int j = 0 ; j < N ; j ++ ) { sum += arr [ j ] ; } if ( sum == 0 ) { pos = i ; break ; } else { arr [ i ] *= -1 ; } } return pos ; } int main ( ) { int arr [ ] = { 1 , 3 , -5 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << smallestIndexArrayElementsFlip ( arr , N ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int smallestIndexArrayElementsFlip ( int arr [ ] , int N ) { int pos = -1 ; int ArrSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { ArrSum += arr [ i ] ; } for ( int i = 0 ; i < N ; i ++ ) { if ( 2 * arr [ i ] == ArrSum ) { pos = i ; break ; } } return pos ; } int main ( ) { int arr [ ] = { 1 , 3 , -5 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << smallestIndexArrayElementsFlip ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ArrSum, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string make_string_S_to_T ( string S , string T ) { bool possible = false ; int M = T . length ( ) ; int N = S . length ( ) ; for ( int i = 0 ; i <= M ; i ++ ) { int prefix_length = i ; int suffix_length = M - i ; string prefix = S . substr ( 0 , prefix_length ) ; string suffix = S . substr ( N - suffix_length , suffix_length ) ; if ( prefix + suffix == T ) { possible = true ; break ; } } if ( possible ) return " YES " ; else return " NO " ; } int main ( ) { string S = " ababcdcd " ; string T = " abcd " ; cout << make_string_S_to_T ( S , T ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: possible
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findSum ( vector < int > a ) { int ans = 0 ; for ( int low = 0 ; low < a . size ( ) ; low ++ ) { for ( int high = low ; high < a . size ( ) ; high ++ ) { int count = 0 ; int maxNumber = 0 ; for ( int i = low ; i <= high ; i ++ ) { if ( a [ i ] == maxNumber ) count ++ ; else if ( a [ i ] > maxNumber ) { maxNumber = a [ i ] ; count = 1 ; } } ans += maxNumber * ( ( count % 2 == 0 ) ? 2 : 1 ) ; } } cout << ( ans ) ; } int main ( ) { vector < int > arr = { 2 , 1 , 4 , 4 , 2 } ; findSum ( arr ) ; }

Index/key variables: i
Accumulator variables: ans, count, high, i, low, stdc
Iterator variables: high, i, low
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countPairs ( int * arr , int n ) { unordered_map < int , int > mp1 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; mp1 [ sum ] += 1 ; } sum = 0 ; int ans = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { sum += arr [ i ] ; if ( mp1 . find ( sum ) != mp1 . end ( ) ) { ans += mp1 [ sum ] ; } } cout << ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 1 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; countPairs ( arr , n ) ; return 0 ; }

Index/key variables: i, sum
Accumulator variables: ans, i, stdc, sum
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; bool isMagic ( int num ) { return ( num % 9 == 1 ) ; } bool isComposite ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return false ; if ( n % 2 == 0 n % 3 == 0 ) return true ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true ; return false ; } void find ( int L [ ] , int R [ ] , int q ) { int dp [ 1000005 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 0 ; for ( int i = 1 ; i < 1000005 ; i ++ ) { if ( isComposite ( i ) && isMagic ( i ) ) { dp [ i ] = dp [ i - 1 ] + 1 ; } else dp [ i ] = dp [ i - 1 ] ; } for ( int i = 0 ; i < q ; i ++ ) cout << dp [ R [ i ] ] - dp [ L [ i ] - 1 ] << endl ; } int main ( ) { int L [ ] = { 10 , 3 } ; int R [ ] = { 100 , 2279 } ; int Q = 2 ; find ( L , R , Q ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSmallestInteger ( int arr [ ] , int N , int K ) { int left = 1 ; int right = * max_element ( arr , arr + N ) ; while ( left < right ) { int mid = ( left + right ) / 2 ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += ( arr [ i ] + mid - 1 ) / mid ; } if ( sum > K ) { left = mid + 1 ; } else { right = mid ; } } return left ; } int main ( ) { int arr [ ] = { 1 , 2 , 5 , 9 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; ; int K = 6 ; cout << findSmallestInteger ( arr , N , K ) ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimum_deci_binary_number ( string s ) { int m = INT_MIN ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { int temp = s [ i ] - '0' ; if ( temp > m ) { m = temp ; } } return m ; } int main ( ) { string S = "31" ; cout << minimum_deci_binary_number ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minOperations ( int arr [ ] , int n ) { int flips = 0 ; for ( int i = 0 ; i < n ; i += 2 ) { if ( arr [ i ] % 2 == 1 ) { continue ; } while ( i < n && arr [ i ] % 2 == 0 ) { i += 2 ; } flips ++ ; } for ( int i = 1 ; i < n ; i += 2 ) { if ( arr [ i ] % 2 == 1 ) { continue ; } while ( i < n && arr [ i ] % 2 == 0 ) { i += 2 ; } flips ++ ; } cout << flips ; } int main ( ) { int arr [ ] = { 2 , 3 , 4 , 3 , 5 , 3 , 2 } ; int N = sizeof ( arr ) / sizeof ( int ) ; minOperations ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: flips, i, stdc
Iterator variables: i