dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  1001
vector < int > sieve ( ) { vector < int > spf ( MAX ) ; spf [ 0 ] = spf [ 1 ] = -1 ; for ( int i = 2 ; i < MAX ; i ++ ) { spf [ i ] = i ; } for ( int i = 4 ; i < MAX ; i = i + 2 ) { spf [ i ] = 2 ; } for ( int i = 3 ; i * i < MAX ; i ++ ) { if ( spf [ i ] == i ) { for ( int j = i * i ; j < MAX ; j = j + i ) { if ( spf [ j ] == j ) { spf [ j ] = i ; } } } } return spf ; } int countFactors ( vector < int > & spf , int num ) { int count = 0 ; while ( num > 1 ) { count ++ ; num = num / spf [ num ] ; } return count ; } vector < int > precalculateSum ( vector < int > & spf ) { vector < int > sum ( MAX ) ; sum [ 0 ] = 0 ; for ( int i = 1 ; i < MAX ; i ++ ) { int prime_factor = countFactors ( spf , i ) ; if ( spf [ prime_factor ] == prime_factor ) { sum [ i ] = sum [ i - 1 ] + 1 ; } else { sum [ i ] = sum [ i - 1 ] ; } } return sum ; } int main ( ) { vector < int > spf = sieve ( ) ; vector < int > sum = precalculateSum ( spf ) ; int Q [ ] [ 2 ] = { { 4 , 8 } , { 30 , 32 } } ; for ( int i = 0 ; i < 2 ; i ++ ) { cout << ( sum [ Q [ i ] [ 1 ] ] - sum [ Q [ i ] [ 0 ] - 1 ] ) << " ▁ " ; } return 0 ; }

Index/key variables: i, j, num, prime_factor
Accumulator variables: count, i, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int isPerfect ( int N ) { int sum = 1 ; for ( int i = 2 ; i < sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { if ( i == N / i ) { sum += i ; } else { sum += i + N / i ; } } } if ( sum == N && N != 1 ) return 1 ; return 0 ; } int maxSum ( int arr [ ] , int N , int K ) { if ( N < K ) { cout << " Invalid " ; return -1 ; } int res = 0 ; for ( int i = 0 ; i < K ; i ++ ) { res += arr [ i ] ; } int curr_sum = res ; for ( int i = K ; i < N ; i ++ ) { curr_sum += arr [ i ] - arr [ i - K ] ; res = max ( res , curr_sum ) ; } return res ; } int max_PerfectNumbers ( int arr [ ] , int N , int K ) { for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = isPerfect ( arr [ i ] ) ? 1 : 0 ; } return maxSum ( arr , N , K ) ; } int main ( ) { int arr [ ] = { 28 , 2 , 3 , 6 , 496 , 99 , 8128 , 24 } ; int K = 4 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << max_PerfectNumbers ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: curr_sum, i, res, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void display ( int countLeftGreater [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { cout << countLeftGreater [ i ] << " ▁ " ; } } void countGreater ( int arr [ ] , int N ) { set < int > St ; int countLeftGreater [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { St . insert ( arr [ i ] ) ; auto it = St . upper_bound ( arr [ i ] ) ; countLeftGreater [ i ] = distance ( it , St . end ( ) ) ; } display ( countLeftGreater , N ) ; } int main ( ) { int arr [ ] = { 12 , 1 , 2 , 3 , 0 , 11 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; countGreater ( arr , N ) ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minCost ( string A , string B ) { int n = A . size ( ) ; int i = 0 ; int maxlen = 0 ; while ( i < n ) { int length = 0 ; for ( int j = 0 ; j < n ; ++ j ) { if ( A [ i ] == B [ j ] ) { ++ i ; ++ length ; if ( i == n ) break ; } } maxlen = max ( maxlen , length ) ; } return n - maxlen ; } int main ( ) { string A = " edacb " ; string B = " abcde " ; cout << minCost ( A , B ) << endl ; }

Index/key variables: i, j
Accumulator variables: stdc
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int lexicographicRank ( string s ) { int n = s . length ( ) ; vector < int > alphaIndex [ 26 ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int x = s [ i ] - ' a ' ; alphaIndex [ x ] . push_back ( i ) ; } int rank = 0 ; for ( int i = 0 ; i < 26 && ' a ' + i < s [ 0 ] ; i ++ ) { if ( alphaIndex [ i ] . size ( ) > 0 ) { for ( int j = 0 ; j < alphaIndex [ i ] . size ( ) ; j ++ ) { rank = rank + ( n - alphaIndex [ i ] [ j ] ) ; } } } vector < string > str ; for ( int i = 0 ; i < alphaIndex [ s [ 0 ] - ' a ' ] . size ( ) ; i ++ ) { string substring ; int j = alphaIndex [ s [ 0 ] - ' a ' ] [ i ] ; for ( ; j < n ; j ++ ) { substring . push_back ( s [ j ] ) ; str . push_back ( substring ) ; } } sort ( str . begin ( ) , str . end ( ) ) ; for ( int i = 0 ; i < str . size ( ) ; i ++ ) { if ( str [ i ] != s ) { rank ++ ; } else { break ; } } return rank + 1 ; } int main ( ) { string str = " enren " ; cout << lexicographicRank ( str ) ; return 0 ; }

Index/key variables: i, j, x
Accumulator variables: i, j, rank, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int hIndex ( vector < int > citations , int n ) { int hindex = 0 ; int low = 0 , high = n - 1 ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( citations [ mid ] >= ( mid + 1 ) ) { low = mid + 1 ; hindex = mid + 1 ; } else { high = mid - 1 ; } } cout << hindex << endl ; return hindex ; } int main ( ) { int n = 5 ; vector < int > citations = { 5 , 3 , 3 , 2 , 2 } ; hIndex ( citations , n ) ; }

Index/key variables: mid
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkEqual ( string arr [ ] , int N ) { int hash [ 256 ] = { 0 } ; int M = arr [ 0 ] . length ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { hash [ arr [ i ] [ j ] ] ++ ; } } for ( int i = 0 ; i < 256 ; i ++ ) { if ( hash [ i ] % N != 0 ) { return false ; } } return true ; } int main ( ) { string arr [ ] = { " fdd " , " fhh " } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( checkEqual ( arr , N ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 100 ] [ 100 ] ; int maxweight ( int s , int e , map < int , int > pre ) { if ( s == e ) return 0 ; if ( dp [ s ] [ e ] != -1 ) return dp [ s ] [ e ] ; int ans = 0 ; for ( int i = s ; i < e ; i ++ ) { int left = pre [ i ] - pre [ s - 1 ] ; int right = pre [ e ] - pre [ i ] ; if ( left < right ) ans = max ( ans , ( int ) ( left + maxweight ( s , i , pre ) ) ) ; if ( left == right ) ans = max ( ans , max ( left + maxweight ( s , i , pre ) , right + maxweight ( i + 1 , e , pre ) ) ) ; if ( left > right ) ans = max ( ans , right + maxweight ( i + 1 , e , pre ) ) ; dp [ s ] [ e ] = ans ; } return dp [ s ] [ e ] ; } void maxSum ( int arr [ ] , int n ) { map < int , int > pre ; pre [ -1 ] = 0 ; pre [ 0 ] = arr [ 0 ] ; memset ( dp , -1 , sizeof dp ) ; for ( int i = 0 ; i < n ; i ++ ) pre [ i ] = pre [ i - 1 ] + arr [ i ] ; cout << ( maxweight ( 0 , n - 1 , pre ) ) ; } int main ( ) { int arr [ ] = { 6 , 2 , 3 , 4 , 5 , 5 } ; maxSum ( arr , 6 ) ; }

Index/key variables: e, i, s
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ( ) ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } void storeLeaf ( Node * root , vector < int > & arr ) { if ( ! root ) return ; if ( ! root -> left and ! root -> right ) { arr . push_back ( root -> data ) ; return ; } storeLeaf ( root -> left , arr ) ; storeLeaf ( root -> right , arr ) ; } void KSmallest ( Node * root , int k ) { vector < int > arr ; storeLeaf ( root , arr ) ; sort ( arr . begin ( ) , arr . end ( ) ) ; for ( int i = 0 ; i < k ; i ++ ) { if ( i < arr . size ( ) ) { cout << arr [ i ] << " ▁ " ; } else { break ; } } } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> left -> left = newNode ( 21 ) ; root -> left -> right = newNode ( 5 ) ; root -> left -> right -> right = newNode ( 8 ) ; root -> right = newNode ( 3 ) ; root -> right -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 7 ) ; root -> right -> right -> right = newNode ( 19 ) ; KSmallest ( root , 3 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool allCoprime ( int A [ ] , int n ) { bool all_coprime = true ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( __gcd ( A [ i ] , A [ j ] ) != 1 ) { all_coprime = false ; break ; } } } return all_coprime ; } ' ' Function return gcd of two number ' ' ' int main ( ) { int A [ ] = { 3 , 5 , 11 , 7 , 19 } ; int arr_size = sizeof ( A ) / sizeof ( A [ 0 ] ) ; if ( allCoprime ( A , arr_size ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
Boolean variables: all_coprime
C++ program:
#include <bits/stdc++.h>
using namespace std ; int smallestNum ( int n ) { float power = log2 ( 10 ) ; cout << power ; return ceil ( ( n - 1 ) * power ) ; } int main ( ) { int n = 4 ; cout << smallestNum ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
#define ll  long long
using namespace std ; string findString ( string s , int k ) { int n = s . length ( ) ; string ans = " " ; stack < int > st ; vector < bool > vis ( n , false ) ; int count = 0 ; Vector < boolean > vis ( n , false ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( s [ i ] == ' ( ' ) { st . push ( i ) ; } if ( count < k && s [ i ] == ' ) ' ) { vis [ st . top ( ) ] = 1 ; st . pop ( ) ; vis [ i ] = true ; count += 2 ; } } for ( int i = 0 ; i < n ; ++ i ) { if ( vis [ i ] == true ) { ans += s [ i ] ; } } return ans ; } int main ( ) { string s = " ( ) ( ) ( ) " ; int K = 2 ; cout << findString ( s , K ) ; }

Index/key variables: i
Accumulator variables: ans, count, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; unordered_map < int , bool > mp ; struct Node { int key ; struct Node * left , * right ; } ; Node * newNode ( int key ) { Node * temp = new Node ; temp -> key = key ; temp -> left = temp -> right = NULL ; return ( temp ) ; } vector < int > findNodes ( Node * root , int & max_v , int & rootIndex ) { if ( ! root ) { return vector < int > { } ; } vector < int > left = findNodes ( root -> left , max_v , rootIndex ) ; vector < int > right = findNodes ( root -> right , max_v , rootIndex ) ; vector < int > combined ; int count = 0 ; for ( int i = 0 ; i < left . size ( ) ; i ++ ) { if ( left [ i ] < root -> key ) { count += 1 ; } combined . push_back ( left [ i ] ) ; } for ( int i = 0 ; i < right . size ( ) ; i ++ ) { if ( right [ i ] < root -> key ) { count += 1 ; } combined . push_back ( right [ i ] ) ; } combined . push_back ( root -> key ) ; if ( count > max_v ) { rootIndex = root -> key ; max_v = count ; } return combined ; } int main ( ) { Node * root = newNode ( 3 ) ; root -> left = newNode ( 4 ) ; root -> right = newNode ( 6 ) ; root -> right -> left = newNode ( 4 ) ; root -> right -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 10 ) ; root -> left -> right = newNode ( 2 ) ; int max_v = 0 ; int rootIndex = -1 ; findNodes ( root , max_v , rootIndex ) ; cout << rootIndex ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MaximumPath ( vector < vector < int > > & grid ) { int N = grid . size ( ) ; int M = grid [ 0 ] . size ( ) ; vector < vector < int > > sum ; sum . resize ( N + 1 , vector < int > ( M + 1 ) ) ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= M ; j ++ ) { sum [ i ] [ j ] = max ( sum [ i - 1 ] [ j ] , sum [ i ] [ j - 1 ] ) + grid [ i - 1 ] [ j - 1 ] ; } } return sum [ N ] [ M ] ; } int main ( ) { vector < vector < int > > grid = { { 1 , 2 } , { 3 , 5 } } ; cout << MaximumPath ( grid ) ; return 0 ; }

Index/key variables: M, N, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Maxcost ( string s , int cost [ ] ) { int count = 0 ; int maxcost = 0 , i = 0 ; while ( i < s . size ( ) - 1 ) { if ( s [ i ] == s [ i + 1 ] ) { if ( cost [ i ] > cost [ i + 1 ] ) maxcost += cost [ i ] ; else { maxcost += cost [ i + 1 ] ; cost [ i + 1 ] = cost [ i ] ; } } i += 1 ; } return maxcost ; } int main ( ) { string s = " abaac " ; int cost [ ] = { 1 , 2 , 3 , 4 , 5 } ; cout << Maxcost ( s , cost ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, maxcost, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; map < pair < int , int > , int > dp ; int countMagicNumbers ( int idx , int sum , int a [ ] , int n , int m , int l , int r ) { if ( idx == n ) { int temp = sum % m ; if ( temp == l || temp == r || ( temp > l && temp < r ) ) return dp [ { idx , sum } ] = 1 ; else return dp [ { idx , sum } ] = 0 ; } pair < int , int > curr = make_pair ( idx , sum ) ; if ( dp . find ( curr ) != dp . end ( ) ) return dp [ curr ] ; int ls = countMagicNumbers ( idx + 1 , sum + a [ idx ] , a , n , m , l , r ) ; int rs = countMagicNumbers ( idx + 1 , sum + ( a [ idx ] - 1 ) , a , n , m , l , r ) ; int temp1 = max ( ls , rs ) ; int temp = sum % m ; if ( ( temp == l || temp == r || ( temp > l && temp < r ) ) && idx != 0 ) { temp1 += 1 ; } return dp [ { idx , sum } ] = temp1 ; } int main ( ) { int N = 5 , M = 22 , L = 14 , R = 16 ; int arr [ ] = { 17 , 11 , 10 , 8 , 15 } ; cout << countMagicNumbers ( 0 , 0 , arr , N , M , L , R ) ; return 0 ; }

Index/key variables: curr, idx
Accumulator variables: stdc, temp1
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool reachesBottom ( vector < vector < int > > & a ) { int n = a . size ( ) ; int m = a [ 0 ] . size ( ) ; deque < vector < int > > q ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( a [ i ] [ j ] == 1 ) { q . push_front ( { i , j , 1 } ) ; } else if ( a [ i ] [ j ] == 2 ) { q . push_back ( { i , j , 2 } ) ; } a [ i ] [ j ] = 0 ; } } int dx [ ] = { -1 , 0 , 1 , 0 } ; int dy [ ] = { 0 , 1 , 0 , -1 } ; while ( ! q . empty ( ) ) { auto front = q . front ( ) ; q . pop_front ( ) ; int i = front [ 0 ] , j = front [ 1 ] ; int t = front [ 2 ] ; if ( a [ i ] [ j ] ) continue ; a [ i ] [ j ] = 1 ; if ( t == 1 and ( i == n - 1 && j == m - 1 ) ) { return true ; } for ( int d = 0 ; d < 4 ; d ++ ) { int ni = i + dx [ d ] ; int nj = j + dy [ d ] ; if ( ni >= 0 and ni < n and nj > = 0 and nj < m ) { q . push_back ( { ni , nj , t } ) ; } } } return false ; } int main ( ) { vector < vector < int > > matrix { { 0 , 2 , 0 } , { 0 , 1 , 0 } , { 0 , 2 , 0 } } ; if ( reachesBottom ( matrix ) ) { cout << " YES " ; } else { cout << " NO " ; } return 0 ; }

Index/key variables: d, i, j
Accumulator variables: d, i, j, stdc
Iterator variables: d, i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < vector < int > > matrixMinimum ( vector < vector < int > > nums , int K ) { int N = nums . size ( ) ; int M = nums [ 0 ] . size ( ) ; vector < vector < int > > res ( N - K + 1 , vector < int > ( M - K + 1 ) ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M - K + 1 ; j ++ ) { int mini = INT_MAX ; for ( int k = j ; k < j + K ; k ++ ) { mini = min ( mini , nums [ i ] [ k ] ) ; } nums [ i ] [ j ] = mini ; } } for ( int j = 0 ; j < M ; j ++ ) { for ( int i = 0 ; i < N - K + 1 ; i ++ ) { int mini = INT_MAX ; for ( int k = i ; k < i + K ; k ++ ) { mini = min ( mini , nums [ k ] [ j ] ) ; } nums [ i ] [ j ] = mini ; } } for ( int i = 0 ; i < N - K + 1 ; i ++ ) for ( int j = 0 ; j < M - K + 1 ; j ++ ) res [ i ] [ j ] = nums [ i ] [ j ] ; return res ; } void smallestinKsubmatrices ( vector < vector < int > > arr , int K ) { vector < vector < int > > res = matrixMinimum ( arr , K ) ; for ( int i = 0 ; i < res . size ( ) ; i ++ ) { for ( int j = 0 ; j < res [ 0 ] . size ( ) ; j ++ ) { cout << res [ i ] [ j ] << " ▁ " ; } cout << endl ; } } int main ( ) { vector < vector < int > > arr = { { -1 , 5 , 4 , 1 , -3 } , { 4 , 3 , 1 , 1 , 6 } , { 2 , -2 , 5 , 3 , 1 } , { 8 , 5 , 1 , 9 , -4 } , { 12 , 3 , 5 , 8 , 1 } } ; int K = 3 ; smallestinKsubmatrices ( arr , K ) ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include " bits / stdc + + . h "
using namespace std ; char find_kth_largest ( string str , int k ) { sort ( str . begin ( ) , str . end ( ) , greater < char > ( ) ) ; return str [ k - 1 ] ; } char printCharacter ( string str , int l , int r , int k ) { l = l - 1 ; r = r - 1 ; string temp = str . substr ( l , r - l + 1 ) ; char ans = find_kth_largest ( temp , k ) ; return ans ; } void updateString ( string str , int pos , char s ) { int index = pos - 1 ; char c = s ; str [ index ] = c ; } int main ( ) { string str = " abcddef " ; int Q = 3 ; cout << printCharacter ( str , 1 , 2 , 2 ) << endl ; updateString ( str , 4 , ' g ' ) ; cout << printCharacter ( str , 1 , 5 , 4 ) << endl ; return 0 ; }

Index/key variables: index
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minDiffSubArray ( int arr [ ] , int n ) { int total_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) total_sum += arr [ i ] ; int prefix_sum = 0 ; int minDiff = INT_MAX ; for ( int i = 0 ; i < n - 1 ; i ++ ) { prefix_sum += arr [ i ] ; int diff = abs ( ( total_sum - prefix_sum ) - prefix_sum ) ; if ( diff < minDiff ) minDiff = diff ; } return minDiff ; } int main ( ) { int arr [ ] = { 7 , 9 , 5 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minDiffSubArray ( arr , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, prefix_sum, stdc, total_sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int CtSubarr ( int arr [ ] , int N , int K ) { unordered_set < int > st ; int prefixSum = 0 ; st . insert ( prefixSum ) ; int res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { prefixSum += arr [ i ] ; if ( st . count ( prefixSum - K ) ) { res += 1 ; prefixSum = 0 ; st . clear ( ) ; st . insert ( 0 ) ; } st . insert ( prefixSum ) ; } return res ; } int main ( ) { int arr [ ] = { -2 , 6 , 6 , 3 , 5 , 4 , 1 , 2 , 8 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 10 ; cout << CtSubarr ( arr , N , K ) ; }

Index/key variables: i
Accumulator variables: i, prefixSum, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool is_prime ( int n ) { if ( n <= 1 ) return 0 ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return 0 ; } return 1 ; } int count_prime_subarrays ( int ar [ ] , int n ) { int ans = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( is_prime ( ar [ i ] ) ) count ++ ; else { if ( count ) { ans += count * ( count + 1 ) / 2 ; count = 0 ; } } } if ( count ) ans += count * ( count + 1 ) / 2 ; return ans ; } int main ( ) { int N = 10 ; int ar [ ] = { 2 , 3 , 5 , 6 , 7 , 11 , 3 , 5 , 9 , 3 } ; cout << count_prime_subarrays ( ar , N ) ; }

Index/key variables: i
Accumulator variables: ans, count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minSteps ( int arr [ ] , int n , int k ) { int i , cnt = 0 ; int flag ; if ( k == 1 ) flag = 0 ; else flag = 1 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == flag ) { cnt ++ ; flag = ( flag + 1 ) % 2 ; } } return cnt ; } int main ( ) { int arr [ ] = { 1 , 0 , 1 , 0 , 0 , 1 , 1 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 1 ; cout << minSteps ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minSum ( int a [ ] , int n , int k ) { priority_queue < int > q ; for ( int i = 0 ; i < n ; i ++ ) { q . push ( a [ i ] ) ; } while ( ! q . empty ( ) && k > 0 ) { int top = q . top ( ) / 2 ; q . pop ( ) ; q . push ( top ) ; k -= 1 ; } int sum = 0 ; while ( ! q . empty ( ) ) { sum += q . top ( ) ; q . pop ( ) ; } return sum ; } int main ( ) { int n = 4 ; int k = 3 ; int a [ ] = { 20 , 7 , 5 , 4 } ; cout << ( minSum ( a , n , k ) ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, k, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void add_seg ( int seg [ ] , int start , int end , int current , int index ) { if ( index > end or index < start ) return ; if ( start == end ) { seg [ current ] = 1 ; return ; } int mid = ( start + end ) / 2 ; add_seg ( seg , start , mid , 2 * current + 1 , index ) ; add_seg ( seg , mid + 1 , end , 2 * current + 2 , index ) ; seg [ current ] = seg [ 2 * current + 1 ] + seg [ 2 * current + 2 ] ; } int deleted ( int seg [ ] , int l , int r , int start , int end , int current ) { if ( end < l or start > r ) return 0 ; if ( start >= l and end <= r ) return seg [ current ] ; int mid = ( start + end ) / 2 ; return deleted ( seg , l , r , start , mid , 2 * current + 1 ) + deleted ( seg , l , r , mid + 1 , end , 2 * current + 2 ) ; } void sumOfIndices ( string s ) { int N = s . size ( ) ; int x = int ( ceil ( log2 ( N ) ) ) ; int seg_size = 2 * ( int ) pow ( 2 , x ) - 1 ; int segment [ seg_size ] = { 0 } ; int count = 0 ; map < int , queue < int > > fre ; for ( int i = 0 ; i < N ; i ++ ) { fre [ s [ i ] ] . push ( i ) ; } while ( fre . empty ( ) == false ) { auto it = fre . begin ( ) ; if ( it -> second . empty ( ) == true ) fre . erase ( it -> first ) ; else { int original_index = it -> second . front ( ) ; int curr_index = deleted ( segment , 0 , original_index - 1 , 0 , N - 1 , 0 ) ; int new_index = original_index - curr_index ; count += new_index + 1 ; add_seg ( segment , 0 , N - 1 , 0 , original_index ) ; it -> second . pop ( ) ; } } cout << count << endl ; } int main ( ) { string s = " geeksforgeeks " ; sumOfIndices ( s ) ; }

Index/key variables: current, i, seg_size
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int spf [ 100005 ] ; bool prime [ 100005 ] ; int dp [ 100005 ] ; void sieve ( ) { prime [ 0 ] = prime [ 1 ] = false ; for ( int i = 2 ; i < 100005 ; i ++ ) prime [ i ] = true ; for ( int i = 2 ; i * i < 100005 ; i ++ ) { if ( prime [ i ] ) { for ( int j = i * i ; j < 100005 ; j += i ) { prime [ j ] = false ; } } } } void smallestPrimeFactors ( ) { for ( int i = 0 ; i < 100005 ; i ++ ) spf [ i ] = -1 ; for ( int i = 2 ; i * i < 100005 ; i ++ ) { for ( int j = i ; j < 100005 ; j += i ) { if ( spf [ j ] == -1 ) { spf [ j ] = i ; } } } } int sumOfPrimeFactors ( int n ) { int ans = 0 ; while ( n > 1 ) { ans += spf [ n ] ; n /= spf [ n ] ; } return ans ; } int findLength ( int n ) { if ( prime [ n ] ) { return 1 ; } if ( dp [ n ] ) { return dp [ n ] ; } int sum = sumOfPrimeFactors ( n ) ; return dp [ n ] = 1 + findLength ( sum ) ; } int maxLength ( int n , int m ) { sieve ( ) ; smallestPrimeFactors ( ) ; int ans = INT_MIN ; for ( int i = n ; i <= m ; i ++ ) { if ( i == 4 ) { continue ; } ans = max ( ans , findLength ( i ) ) ; } return ans ; } int main ( ) { int n = 2 , m = 14 ; cout << maxLength ( n , m ) ; }

Index/key variables: i, j, n
Accumulator variables: ans, i, j, n, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int largest_subarray ( int a [ ] , int n ) { unordered_map < int , int > index ; int ans = 0 ; for ( int i = 0 , j = 0 ; i < n ; i ++ ) { j = max ( index [ a [ i ] ] , j ) ; ans = max ( ans , i - j + 1 ) ; index [ a [ i ] ] = i + 1 ; } return ans ; } int32_t main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 1 , 2 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << largest_subarray ( arr , n ) ; }

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