dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define M  1000000
int cntSubXor ( int arr [ ] , int N ) { int prefixXor = 0 ; int Even [ M ] ; int Odd [ M ] ; int cntSub = 0 ; Odd [ 0 ] = 1 ; for ( int i = 0 ; i < N ; i ++ ) { prefixXor ^= arr [ i ] ; if ( i % 2 == 1 ) { cntSub += Odd [ prefixXor ] ; Odd [ prefixXor ] ++ ; } else { cntSub += Even [ prefixXor ] ; Even [ prefixXor ] ++ ; } } return cntSub ; } int main ( ) { int arr [ ] = { 2 , 2 , 3 , 3 , 6 , 7 , 8 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << cntSubXor ( arr , N ) ; return 0 ; }

Index/key variables: M, i, prefixXor
Accumulator variables: cntSub, i, prefixXor, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMaxSum ( vector < int > arr , int n , vector < int > min , int k , int & S ) { vector < pair < int , int > > A ; for ( int i = 0 ; i < n ; i ++ ) { A . push_back ( { arr [ i ] , min [ i ] } ) ; } sort ( A . begin ( ) , A . end ( ) , greater < pair < int , int > > ( ) ) ; int K = 0 ; for ( int i = 0 ; i < n ; i ++ ) { S += max ( A [ i ] . first - K , A [ i ] . second ) ; K += k ; } } int main ( ) { vector < int > arr , min ; arr = { 3 , 5 , 2 , 1 } ; min = { 3 , 2 , 1 , 3 } ; int N = arr . size ( ) ; int K = 3 ; int S = 0 ; findMaxSum ( arr , N , min , K , S ) ; cout << S ; return 0 ; }

Index/key variables: i
Accumulator variables: K, S, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minLength ( string a , string b ) { map < char , int > Char ; for ( int i = 0 ; i < b . length ( ) ; i ++ ) { Char [ b [ i ] ] ++ ; } map < char , vector < int > > CharacterIndex ; for ( int i = 0 ; i < a . length ( ) ; i ++ ) { char x = a [ i ] ; if ( Char . find ( x ) != Char . end ( ) ) { CharacterIndex [ x ] . push_back ( i ) ; } } int len = INT_MAX ; int flag ; while ( true ) { flag = 1 ; int firstVar , lastVar ; for ( int i = 0 ; i < b . length ( ) ; i ++ ) { if ( i == 0 ) { if ( CharacterIndex . find ( b [ i ] ) == CharacterIndex . end ( ) ) { flag = 0 ; break ; } else { int x = * ( CharacterIndex [ b [ i ] ] . begin ( ) ) ; CharacterIndex [ b [ i ] ] . erase ( CharacterIndex [ b [ i ] ] . begin ( ) ) ; firstVar = x ; lastVar = x ; } } else { int elementFound = 0 ; for ( auto e : CharacterIndex [ b [ i ] ] ) { if ( e > lastVar ) { elementFound = 1 ; lastVar = e ; break ; } } if ( elementFound == 0 ) { flag = 0 ; break ; } } } if ( flag == 0 ) { break ; } len = min ( len , abs ( lastVar - firstVar ) + 1 ) ; } return len ; } int main ( ) { string a = " abcdefababaef " ; string b = " abf " ; int len = minLength ( a , b ) ; if ( len != INT_MAX ) { cout << len << endl ; } else { cout << " Impossible " << endl ; } }

Index/key variables: i, x
Accumulator variables: i, stdc
Iterator variables: e, 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 ; } void countSmallerPrimes ( int ar [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { int count = 0 ; for ( int j = i + 1 ; j < N ; j ++ ) { if ( ar [ j ] <= ar [ i ] && is_prime ( ar [ j ] ) ) { count ++ ; } } cout << count << " ▁ " ; } } int main ( ) { int ar [ ] = { 43 , 3 , 5 , 7 , 2 , 41 } ; int N = sizeof ar / sizeof ar [ 0 ] ; countSmallerPrimes ( ar , N ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkConcat ( string str1 , string str2 ) { int N = str1 . length ( ) ; int M = str2 . length ( ) ; if ( N % M != 0 ) { return false ; } for ( int i = 0 ; i < N ; i ++ ) { if ( str1 [ i ] != str2 [ i % M ] ) { return false ; } } return true ; } int main ( ) { string str1 = " abcabcabc " ; string str2 = " abc " ; if ( checkConcat ( str1 , str2 ) ) { cout << " Yes " ; } else { cout << " No " ; } }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MinLen ( string str , int K ) { int N = str . length ( ) ; int i = 0 ; while ( i < N - 1 ) { if ( str [ i ] != str [ i + 1 ] ) { break ; } i ++ ; } if ( i == N - 1 ) { return N ; } return max ( 1 , N - K ) ; } int main ( ) { string str = " aabc " ; int K = 1 ; cout << MinLen ( str , K ) ; }

Index/key variables: i
Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long
#define pb  push_back
double temp ( int n , int x ) { return pow ( x * 1.0 / n , n ) ; } bool check ( int n , int y , int x ) { double v = temp ( n , x ) ; return ( v >= y ) ; } void find ( int x , int y ) { int high = ( int ) floor ( x / exp ( 1.0 ) ) ; int low = 1 ; if ( x == y ) cout << 1 << endl ; else if ( ! check ( high , y , x ) ) cout << -1 << endl ; else { while ( high - low > 1 ) { int mid = ( high + low ) / 2 ; if ( check ( mid , y , x ) ) high = mid ; else low = mid ; } cout << high << endl ; } } int main ( ) { int x = 9 , y = 8 ; find ( x , y ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct node { int data ; struct node * left ; struct node * right ; } ; struct node * newnode ( int d ) { struct node * temp = ( struct node * ) malloc ( sizeof ( struct node ) ) ; temp -> data = d ; temp -> left = NULL ; temp -> right = NULL ; return temp ; } void dfs ( node * root , int l , map < int , vector < int > > & M ) { if ( root == NULL ) return ; M [ l ] . push_back ( root -> data ) ; dfs ( root -> left , l + 1 , M ) ; dfs ( root -> right , l + 1 , M ) ; } void printMidNodes ( node * root ) { map < int , vector < int > > M ; dfs ( root , 0 , M ) ; for ( auto & it : M ) { int size = it . second . size ( ) ; if ( size & 1 ) { cout << it . second [ ( size - 1 ) / 2 ] << endl ; } else { cout << it . second [ ( size - 1 ) / 2 ] << ' ▁ ' << it . second [ ( size - 1 ) / 2 + 1 ] << endl ; } } } int main ( ) { struct node * root = newnode ( 1 ) ; root -> left = newnode ( 2 ) ; root -> right = newnode ( 3 ) ; root -> left -> left = newnode ( 4 ) ; root -> left -> right = newnode ( 5 ) ; root -> left -> right -> left = newnode ( 11 ) ; root -> left -> right -> right = newnode ( 6 ) ; root -> left -> right -> right -> left = newnode ( 7 ) ; root -> left -> right -> right -> right = newnode ( 9 ) ; root -> right -> left = newnode ( 10 ) ; root -> right -> right = newnode ( 8 ) ; printMidNodes ( root ) ; return 0 ; }

Index/key variables: l
Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minLength ( int arr [ ] , int N ) { for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ 0 ] != arr [ i ] ) { return 1 ; } } return N ; } int main ( ) { int arr [ ] = { 2 , 1 , 3 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minLength ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : node * left ; node * right ; } ; void insert ( int x , node * head ) { node * curr = head ; for ( int i = 30 ; i >= 0 ; i -- ) { int val = ( x >> i ) & 1 ; if ( val == 0 ) { if ( ! curr -> left ) curr -> left = new node ( ) ; curr = curr -> left ; } else { if ( ! curr -> right ) curr -> right = new node ( ) ; curr = curr -> right ; } } } int findMaximumXOR ( int arr [ ] , int n ) { node * head = new node ( ) ; for ( int i = 0 ; i < n ; i ++ ) { insert ( arr [ i ] , head ) ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int curr_xor = 0 ; int M = pow ( 2 , 30 ) ; node * curr = head ; for ( int j = 30 ; j >= 0 ; j -- ) { int val = ( arr [ i ] >> j ) & 1 ; if ( val == 0 ) { if ( curr -> right ) { curr_xor += M ; curr = curr -> right ; } else { curr = curr -> left ; } } else { if ( curr -> left ) { curr_xor += M ; curr = curr -> left ; } else { curr = curr -> right ; } } M /= 2 ; } ans = max ( ans , curr_xor ) ; } return ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMaximumXOR ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: M, curr_xor, i, j, stdc
Iterator variables: i, j
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void PrintIndexes ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { int currSubSum = 0 ; for ( int j = i ; j < N ; j ++ ) { currSubSum += arr [ j ] ; int sq = sqrt ( currSubSum ) ; if ( sq * sq == currSubSum ) { cout << " ( " << i << " , ▁ " << j << " ) ▁ " ; } } } } int main ( ) { int arr [ ] = { 65 , 79 , 81 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; PrintIndexes ( arr , N ) ; }

Index/key variables: j
Accumulator variables: currSubSum, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countPosition ( vector < vector < int > > mat ) { int n = mat . size ( ) ; int m = mat [ 0 ] . size ( ) ; vector < int > row ( n ) ; vector < int > col ( m ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) { col [ j ] ++ ; row [ i ] ++ ; } } } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( row [ i ] == col [ j ] ) { count ++ ; } } } return count ; } int main ( ) { vector < vector < int > > mat = { { 0 , 1 } , { 1 , 1 } } ; cout << ( countPosition ( mat ) ) ; }

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 maxAtLevel ( int N , int M , vector < int > Value , int Edges [ ] [ 2 ] ) { vector < int > adj [ N ] ; for ( int i = 0 ; i < M ; i ++ ) { int u = Edges [ i ] [ 0 ] ; int v = Edges [ i ] [ 1 ] ; adj [ u ] . push_back ( v ) ; } queue < int > q ; q . push ( 0 ) ; while ( ! q . empty ( ) ) { int count = q . size ( ) ; int maxVal = 0 ; while ( count -- ) { int temp = q . front ( ) ; q . pop ( ) ; maxVal = max ( maxVal , Value [ temp ] ) ; for ( int i = 0 ; i < adj [ temp ] . size ( ) ; i ++ ) { q . push ( adj [ temp ] [ i ] ) ; } } cout << maxVal << " ▁ " ; } } int main ( ) { int N = 10 ; int Edges [ ] [ 2 ] = { { 0 , 1 } , { 0 , 2 } , { 0 , 3 } , { 1 , 4 } , { 1 , 5 } , { 3 , 6 } , { 6 , 7 } , { 6 , 8 } , { 6 , 9 } } ; vector < int > Value = { 1 , 2 , -1 , 3 , 4 , 5 , 8 , 6 , 12 , 7 } ; maxAtLevel ( N , N - 1 , Value , Edges ) ; return 0 ; }

Index/key variables: N, i, temp, u
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void ctTriplets ( int arr [ ] , int N ) { sort ( arr , arr + N ) ; vector < int > temp ( N ) ; int index = 0 ; for ( int i = 1 ; i < N ; i += 2 ) { temp [ i ] = arr [ index ++ ] ; } for ( int i = 0 ; i < N ; i += 2 ) { temp [ i ] = arr [ index ++ ] ; } int ct = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i > 0 && i + 1 < N ) { if ( temp [ i ] < temp [ i + 1 ] && temp [ i ] < temp [ i - 1 ] ) { ct ++ ; } } } cout << " Count ▁ of ▁ triplets : " << ct << endl ; cout << " Array : " ; for ( int i = 0 ; i < N ; i ++ ) { cout << temp [ i ] << " ▁ " ; } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; ctTriplets ( arr , N ) ; }

Index/key variables: i
Accumulator variables: ct, i, index, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool check ( int a [ ] , int n ) { int b [ n ] ; int minElement = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = a [ i ] ; minElement = min ( minElement , a [ i ] ) ; } sort ( b , b + n ) ; int k = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] && a [ i ] % minElement != 0 ) { k = 0 ; break ; } } return k == 1 ? true : false ; } int main ( ) { int a [ ] = { 4 , 3 , 6 , 6 , 2 , 9 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; if ( check ( a , n ) == true ) cout << " Yes ▁ STRNEWLINE " ; else cout << " No ▁ STRNEWLINE " ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int numSpecial ( vector < vector < int > > & mat ) { int m = mat . size ( ) , n = mat [ 0 ] . size ( ) ; int rows [ m ] ; int cols [ n ] ; int i , j ; for ( i = 0 ; i < m ; i ++ ) { rows [ i ] = 0 ; for ( j = 0 ; j < n ; j ++ ) rows [ i ] += mat [ i ] [ j ] ; } for ( i = 0 ; i < n ; i ++ ) { cols [ i ] = 0 ; for ( j = 0 ; j < m ; j ++ ) cols [ i ] += mat [ j ] [ i ] ; } int cnt = 0 ; for ( i = 0 ; i < m ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( mat [ i ] [ j ] == 1 && rows [ i ] == 1 && cols [ j ] == 1 ) cnt ++ ; } } return cnt ; } int main ( ) { vector < vector < int > > mat = { { 1 , 0 , 0 } , { 0 , 0 , 1 } , { 0 , 0 , 0 } } ; cout << numSpecial ( mat ) << endl ; return 0 ; }

Index/key variables: i, j, m, n
Accumulator variables: cnt, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > minmaxNumbers ( vector < vector < int > > & matrix , vector < int > & res ) { unordered_set < int > set ; for ( int i = 0 ; i < matrix . size ( ) ; i ++ ) { int minr = INT_MAX ; for ( int j = 0 ; j < matrix [ i ] . size ( ) ; j ++ ) { minr = min ( minr , matrix [ i ] [ j ] ) ; } set . insert ( minr ) ; } for ( int j = 0 ; j < matrix [ 0 ] . size ( ) ; j ++ ) { int maxc = INT_MIN ; for ( int i = 0 ; i < matrix . size ( ) ; i ++ ) { maxc = max ( maxc , matrix [ i ] [ j ] ) ; } if ( set . find ( maxc ) != set . end ( ) ) { res . push_back ( maxc ) ; } } return res ; } int main ( ) { vector < vector < int > > mat = { { 1 , 10 , 4 } , { 9 , 3 , 8 } , { 15 , 16 , 17 } } ; vector < int > ans ; minmaxNumbers ( mat , ans ) ; if ( ans . size ( ) == 0 ) cout << " - 1" << endl ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) cout << ans [ i ] << endl ; 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 mini = 105 , ans , n ; vector < vector < int > > g ( 100 ) ; int size [ 100 ] ; void create_graph ( ) { g [ 1 ] . push_back ( 2 ) ; g [ 2 ] . push_back ( 1 ) ; g [ 1 ] . push_back ( 3 ) ; g [ 3 ] . push_back ( 1 ) ; g [ 1 ] . push_back ( 4 ) ; g [ 4 ] . push_back ( 1 ) ; g [ 2 ] . push_back ( 5 ) ; g [ 5 ] . push_back ( 2 ) ; g [ 2 ] . push_back ( 6 ) ; g [ 6 ] . push_back ( 2 ) ; } void dfs ( int node , int parent ) { size [ node ] = 1 ; int mx = 0 ; for ( int y : g [ node ] ) { if ( y == parent ) continue ; dfs ( y , node ) ; size [ node ] += size [ y ] ; mx = max ( mx , size [ y ] ) ; } mx = max ( mx , n - size [ node ] ) ; if ( mx < mini ) { mini = mx ; ans = node ; } } int main ( ) { n = 6 ; create_graph ( ) ; dfs ( 1 , -1 ) ; cout << ans << " STRNEWLINE " ; return 0 ; }

Index/key variables: node, y
Accumulator variables: stdc
Iterator variables: y
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperation ( string s ) { int n = s . length ( ) ; int temp1 = -1 , temp2 = -1 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int curr = s [ i ] ; if ( curr == '0' ) { if ( temp1 == -1 && temp2 == -1 ) { temp1 = i ; } else if ( temp1 != -1 && temp2 == -1 && i - temp1 == 1 ) { temp2 = i ; } else if ( temp1 != -1 ) { temp1 = -1 ; ans ++ ; } else if ( temp1 == -1 && temp2 != -1 && i - temp2 != 1 ) { temp2 = -1 ; ans ++ ; } } } if ( temp1 != -1 && temp2 != -1 ) { ans += 2 ; } else if ( temp1 != -1 temp2 != -1 ) { ans += 1 ; } return ans ; } int main ( ) { string s = "110010" ; cout << ( minOperation ( s ) ) ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinLength ( vector < int > & arr ) { int index = ( int ) arr . size ( ) - 1 ; while ( index > 0 && arr [ index ] >= arr [ index - 1 ] ) { index -- ; } return index ; } int main ( ) { vector < int > arr = { 7 , 8 , 5 , 0 , -1 , -1 , 0 , 1 , 2 , 3 , 4 } ; cout << findMinLength ( arr ) ; return 0 ; }

Index/key variables: index
Accumulator variables: index, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countPrecedingK ( int a [ ] , int n , int K ) { int prefix [ n ] ; prefix [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] + a [ i ] ; } int ctr = 0 ; if ( prefix [ K - 1 ] < a [ K ] ) ctr ++ ; for ( int i = K + 1 ; i < n ; i ++ ) { if ( prefix [ i - 1 ] - prefix [ i - K - 1 ] < a [ i ] ) ctr ++ ; } return ctr ; } int main ( ) { int arr [ ] = { 2 , 3 , 8 , 10 , -2 , 7 , 5 , 5 , 9 , 15 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 2 ; cout << countPrecedingK ( arr , N , K ) ; return 0 ; }

Index/key variables: K, i, n
Accumulator variables: ctr, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void convertBfromA ( int a , int b ) { int moves = 0 ; int x = abs ( a - b ) ; for ( int i = 10 ; i > 0 ; i -- ) { moves += x / i ; x = x % i ; } cout << moves << " ▁ " ; } int main ( ) { int A = 188 , B = 4 ; convertBfromA ( A , B ) ; return 0 ; }

Accumulator variables: i, moves, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define M  1000
int countNum ( int N , int sum , int K , bool st , int dp [ M ] [ M ] [ 2 ] ) { if ( N == 0 and sum == 0 ) { return 1 ; } if ( N < 0 ) { return 0 ; } if ( dp [ N ] [ sum ] [ st ] != -1 ) { return dp [ N ] [ sum ] [ st ] ; } int res = 0 ; int start = st == 1 ? 0 : 1 ; for ( int i = start ; i <= 9 ; i ++ ) { res += countNum ( N - 1 , ( sum + i ) % K , K , ( st i > 0 ) , dp ) ; } return dp [ N ] [ sum ] [ st ] = res ; } int main ( ) { int N = 2 , K = 7 ; int dp [ M ] [ M ] [ 2 ] ; memset ( dp , -1 , sizeof ( dp ) ) ; cout << countNum ( N , 0 , K , 0 , dp ) ; }

Index/key variables: M, N, st, sum
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int smallestNth ( int A , int B , int N ) { int res = INT_MAX ; for ( int i = 1 ; i < N ; i ++ ) { for ( int j = N ; j > i ; j -- ) { if ( ( B - A ) % ( j - i ) == 0 ) { int D = ( B - A ) / ( j - i ) ; int FirstTerm = A - ( i - 1 ) * D ; int NthTerm = FirstTerm + ( N - 1 ) * D ; if ( FirstTerm > 0 ) res = min ( res , NthTerm ) ; } } } return res ; } int main ( ) { int N = 3 ; int A = 1 ; int B = 6 ; cout << smallestNth ( A , B , N ) ; }

Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sieve ( bool prime [ ] ) { for ( int i = 0 ; i < 1000000 ; i ++ ) { prime [ i ] = true ; } prime [ 0 ] = prime [ 1 ] = false ; for ( int i = 2 ; i * i <= 1000000 ; i ++ ) { if ( prime [ i ] ) { for ( int j = i * i ; j <= 1000000 ; j += i ) { prime [ j ] = false ; } } } } void subPrimeSum ( int N , int K , int arr [ ] , bool prime [ ] ) { int currSum = 0 ; for ( int i = 0 ; i < K ; i ++ ) { currSum += arr [ i ] ; } if ( prime [ currSum ] ) { for ( int i = 0 ; i < K ; i ++ ) { cout << arr [ i ] << " ▁ " ; } return ; } int st = 1 , en = K ; while ( en < N ) { currSum += arr [ en ] - arr [ st - 1 ] ; if ( prime [ currSum ] ) { for ( int i = st ; i <= en ; i ++ ) { cout << arr [ i ] << " ▁ " ; } return ; } en ++ ; st ++ ; } } int main ( ) { int arr [ ] = { 20 , 7 , 5 , 4 , 3 , 11 , 99 , 87 , 23 , 45 } ; int K = 4 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; bool prime [ 1000000 ] ; sieve ( prime ) ; subPrimeSum ( N , K , arr , prime ) ; }

Index/key variables: currSum, en, i, j
Accumulator variables: currSum, en, i, j, st, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minDeletion ( string str ) { int n = str . length ( ) ; int firstIdx1 = -1 ; int lastIdx0 = -1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == '1' ) { firstIdx1 = i ; break ; } } for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == '0' ) { lastIdx0 = i ; break ; } } if ( firstIdx1 == -1 lastIdx0 == -1 ) return 0 ; int count1 = 0 , count0 = 0 ; for ( int i = 0 ; i < lastIdx0 ; i ++ ) { if ( str [ i ] == '1' ) { count1 ++ ; } } for ( int i = firstIdx1 + 1 ; i < n ; i ++ ) { if ( str [ i ] == '1' ) { count0 ++ ; } } return min ( count0 , count1 ) ; } int main ( ) { string str = "1000101" ; cout << minDeletion ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count0, count1, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumSum ( int a [ ] , int b [ ] , int n , int index , int lastpicked ) { if ( index == n ) return 0 ; int option1 = 0 , option2 = 0 ; if ( lastpicked == -1 a [ lastpicked ] != a [ index ] ) option1 = b [ index ] + maximumSum ( a , b , n , index + 1 , index ) ; option2 = maximumSum ( a , b , n , index + 1 , lastpicked ) ; return max ( option1 , option2 ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 3 , 3 , 1 } ; int brr [ ] = { -1 , 2 , 10 , 20 , -10 , -9 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << ( maximumSum ( arr , brr , N , 0 , -1 ) ) ; }

Index/key variables: index, lastpicked
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sumOfKElements ( int arr [ ] , int n , int k ) { bool rev = false ; if ( k < 0 ) { rev = true ; k *= -1 ; int l = 0 , r = n - 1 ; while ( l < r ) { int tmp = arr [ l ] ; arr [ l ] = arr [ r ] ; arr [ r ] = tmp ; l ++ ; r -- ; } } int dp [ n ] = { 0 } ; dp [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] += dp [ i - 1 ] + arr [ i ] ; } int ans [ n ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { if ( i + k < n ) ans [ i ] = dp [ i + k ] - dp [ i ] ; else { int x = k - ( n - 1 - i ) ; int y = x / n ; int rem = x % n ; ans [ i ] = dp [ n - 1 ] - dp [ i ] + y * dp [ n - 1 ] + ( rem - 1 >= 0 ? dp [ rem - 1 ] : 0 ) ; } } if ( rev ) { for ( int i = n - 1 ; i >= 0 ; i -- ) { cout << ans [ i ] << " ▁ " ; } } else { for ( int i = 0 ; i < n ; i ++ ) { cout << ans [ i ] << " ▁ " ; } } } int main ( ) { int arr [ ] = { 4 , 2 , -5 , 11 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 3 ; sumOfKElements ( arr , N , K ) ; }

Index/key variables: i, l, n, r
Accumulator variables: i, k, l, r, stdc
Iterator variables: i
Boolean variables: rev
C++ program:
#include <bits/stdc++.h>
using namespace std ; int binaryInsert ( vector < int > & boundary , int i ) { int l = 0 ; int r = boundary . size ( ) - 1 ; while ( l <= r ) { int m = ( l + r ) / 2 ; if ( boundary [ m ] < i ) l = m + 1 ; else r = m - 1 ; } boundary . insert ( boundary . begin ( ) + l , i ) ; return l ; } vector < int > countingSubarray ( vector < int > arr , int n ) { unordered_map < int , int > index ; for ( int i = 0 ; i < n ; i ++ ) index [ arr [ i ] ] = i ; vector < int > boundary = { -1 , n } ; sort ( arr . begin ( ) , arr . end ( ) ) ; vector < int > ans ( n , 0 ) ; for ( int num : arr ) { int i = binaryInsert ( boundary , index [ num ] ) ; int l = boundary [ i ] - boundary [ i - 1 ] - 1 ; int r = boundary [ i + 1 ] - boundary [ i ] - 1 ; int cnt = l + r + l * r + 1 ; ans [ index [ num ] ] += cnt ; } return ans ; } int main ( ) { int N = 5 ; vector < int > arr = { 3 , 2 , 4 , 1 , 5 } ; auto a = countingSubarray ( arr , N ) ; cout << " [ " ; int n = a . size ( ) - 1 ; for ( int i = 0 ; i < n ; i ++ ) cout << a [ i ] << " , ▁ " ; cout << a [ n ] << " ] " ; return 0 ; }

Index/key variables: i, m, n, num
Accumulator variables: i, stdc
Iterator variables: i, num