dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findCount ( int arr [ ] , int n ) { int prefix_sum [ n ] ; prefix_sum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ; int suffix_sum [ n ] ; suffix_sum [ n - 1 ] = arr [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) suffix_sum [ i ] = suffix_sum [ i + 1 ] + arr [ i ] ; int s = 1 , e = 1 ; int curr_subarray_sum = 0 , count = 0 ; while ( s < n - 1 && e < n - 1 ) { while ( e < n - 1 && curr_subarray_sum < prefix_sum [ s - 1 ] ) { curr_subarray_sum += arr [ e ++ ] ; } if ( curr_subarray_sum <= suffix_sum [ e ] ) { count ++ ; } curr_subarray_sum -= arr [ s ++ ] ; } return count ; } int32_t main ( ) { int arr [ ] = { 2 , 3 , 1 , 7 } ; int n = sizeof arr / sizeof arr [ 0 ] ; cout << ( findCount ( arr , n ) ) ; }

Index/key variables: e, i, n
Accumulator variables: count, curr_subarray_sum, e, i, s, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperation ( string s , int n ) { int cnt1 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == '1' ) cnt1 ++ ; } int cnt0 = 0 ; for ( int i = 0 ; i < cnt1 ; i ++ ) { if ( s [ i ] == '0' ) cnt0 ++ ; } return cnt0 ; } int main ( ) { int n = 8 ; string s = "01001011" ; int ans = minOperation ( s , n ) ; cout << ans << endl ; }

Index/key variables: i
Accumulator variables: cnt0, cnt1, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperation ( string s , int n ) { int ans = 0 ; int i = 0 , j = n - 1 ; while ( i < j ) { if ( s [ i ] == '0' && s [ j ] == '1' ) { ans ++ ; i ++ ; j -- ; continue ; } if ( s [ i ] == '1' ) { i ++ ; } if ( s [ j ] == '0' ) { j -- ; } } return ans ; } int main ( ) { int n = 8 ; string s = "10100101" ; int ans = minOperation ( s , n ) ; cout << ans << endl ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void count ( int N ) { if ( N == 1 ) { cout << ( 10 ) << endl ; return ; } int dp [ N ] [ 10 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; for ( int i = 1 ; i < 10 ; i ++ ) dp [ 0 ] [ i ] = 1 ; for ( int i = 1 ; i < N ; i ++ ) { int temp = 0 ; for ( int j = 0 ; j < 10 ; j ++ ) temp += dp [ i - 1 ] [ j ] ; for ( int j = 0 ; j < 10 ; j ++ ) dp [ i ] [ j ] = temp - dp [ i - 1 ] [ j ] ; } int ans = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) ans += dp [ N - 1 ] [ i ] ; cout << ans << endl ; } int main ( ) { int N = 2 ; count ( N ) ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: ans, i, j, stdc, temp
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int power ( int x , int y , int mod ) { int res = 1 ; x = x % mod ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % mod ; y = y >> 1 ; x = ( x * x ) % mod ; } return res ; } void count ( int N ) { if ( N == 1 ) { cout << 10 << endl ; return ; } cout << ( power ( 9 , N , 1000000007 ) ) << endl ; } int main ( ) { int N = 3 ; count ( N ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int * kmp ( string & s ) { int n = s . size ( ) ; int * lps = new int [ n ] ; lps [ 0 ] = 0 ; int i = 1 , len = 0 ; while ( i < n ) { if ( s [ i ] == s [ len ] ) { len ++ ; lps [ i ] = len ; i ++ ; } else { if ( len != 0 ) { len = lps [ len - 1 ] ; } else { lps [ i ] = 0 ; i ++ ; } } } return lps ; } string findString ( string & s , int k ) { int n = s . length ( ) ; int * lps = kmp ( s ) ; string ans = " " ; string suff = s . substr ( 0 , n - lps [ n - 1 ] ) ; for ( int i = 0 ; i < k - 1 ; ++ i ) { ans += suff ; } ans += s ; return ans ; } int main ( ) { int k = 3 ; string s = " geeksforgeeks " ; cout << findString ( s , k ) << endl ; }

Index/key variables: i, len, n
Accumulator variables: ans, i, len, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool check ( int arr [ ] , int n ) { int i , g ; g = 0 ; for ( i = 1 ; i < n ; i ++ ) { if ( arr [ i ] - arr [ i - 1 ] > 0 && g == 1 ) return false ; if ( arr [ i ] - arr [ i - 1 ] < 0 ) g = 1 ; } return true ; } int main ( ) { int arr [ ] = { 2 , 3 , 4 , 10 , 4 , 3 , 1 } ; int n = sizeof ( arr ) / sizeof ( int ) ; if ( check ( arr , n ) == true ) cout << " Yes " " STRNEWLINE " ; else cout << " No " << " STRNEWLINE " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int ctr = 0 ; int find ( vector < int > & parent , int x ) { if ( parent [ x ] == x ) return x ; parent [ x ] = find ( parent , parent [ x ] ) ; return parent [ x ] ; } void setUnion ( vector < int > & parent , vector < int > & rank , int x , int y ) { int parentx = find ( parent , x ) ; int parenty = find ( parent , y ) ; if ( parenty == parentx ) return ; ctr -- ; if ( rank [ parentx ] < rank [ parenty ] ) { parent [ parentx ] = parenty ; } else if ( rank [ parentx ] > rank [ parenty ] ) { parent [ parenty ] = parentx ; } else { parent [ parentx ] = parenty ; rank [ parenty ] ++ ; } } vector < int > solve ( int n , int m , vector < pair < int , int > > & query ) { vector < int > result ( query . size ( ) ) ; vector < int > parent ( n * m ) ; for ( int i = 0 ; i < n * m ; i ++ ) parent [ i ] = i ; vector < int > rank ( n * m , 1 ) ; vector < bool > grid ( n * m , 0 ) ; for ( int i = 0 ; i < query . size ( ) ; i ++ ) { int x = query [ i ] . first ; int y = query [ i ] . second ; if ( grid [ m * x + y ] == 1 ) { result [ i ] = ctr ; continue ; } grid [ m * x + y ] = 1 ; ctr ++ ; if ( x > 0 and grid [ m * ( x - 1 ) + y ] == 1 ) setUnion ( parent , rank , m * x + y , m * ( x - 1 ) + y ) ; if ( y > 0 and grid [ m * ( x ) + y - 1 ] == 1 ) setUnion ( parent , rank , m * x + y , m * ( x ) + y - 1 ) ; if ( x < n - 1 and grid [ m * ( x + 1 ) + y ] == 1 ) setUnion ( parent , rank , m * x + y , m * ( x + 1 ) + y ) ; if ( y < m - 1 and grid [ m * ( x ) + y + 1 ] == 1 ) setUnion ( parent , rank , m * x + y , m * ( x ) + y + 1 ) ; result [ i ] = ctr ; } return result ; } int main ( ) { int N = 3 , M = 3 , K = 4 ; vector < pair < int , int > > query = { { 0 , 0 } , { 1 , 1 } , { 1 , 0 } , { 1 , 2 } } ; vector < int > result = solve ( N , M , query ) ; for ( int i = 0 ; i < K ; i ++ ) cout << result [ i ] << " ▁ " ; }

Index/key variables: i, parentx, parenty, x
Accumulator variables: ctr, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMinSum ( int A [ ] , int K , int len ) { int n = len ; int suffix_min [ n ] = { 0 } ; suffix_min [ n - 1 ] = A [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) suffix_min [ i ] = min ( suffix_min [ i + 1 ] , A [ i ] ) ; int min_sum = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { if ( i + K < n ) min_sum = min ( min_sum , A [ i ] + suffix_min [ i + K ] ) ; } cout << min_sum ; } int main ( ) { int A [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int K = 2 ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; findMinSum ( A , K , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxEnvelopes ( vector < vector < int > > envelopes ) { int N = envelopes . size ( ) ; if ( N == 0 ) return N ; sort ( envelopes . begin ( ) , envelopes . end ( ) ) ; int dp [ N ] ; int max_envelope = 1 ; dp [ 0 ] = 1 ; for ( int i = 1 ; i < N ; ++ i ) { dp [ i ] = 1 ; for ( int j = 0 ; j < i ; ++ j ) { if ( envelopes [ i ] [ 0 ] > envelopes [ j ] [ 0 ] && envelopes [ i ] [ 1 ] > envelopes [ j ] [ 1 ] && dp [ i ] < dp [ j ] + 1 ) dp [ i ] = dp [ j ] + 1 ; } max_envelope = max ( max_envelope , dp [ i ] ) ; } return max_envelope ; } int main ( ) { vector < vector < int > > envelopes = { { 4 , 3 } , { 5 , 3 } , { 5 , 6 } , { 1 , 2 } } ; cout << maxEnvelopes ( envelopes ) ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long FindMaxDif ( vector < long long > a , int m ) { int n = m / 3 ; vector < long long > l ( m + 5 ) , r ( m + 5 ) ; multiset < long long > s ; for ( int i = 1 ; i <= m ; i ++ ) { if ( i <= n ) { l [ i ] = a [ i - 1 ] + l [ i - 1 ] ; s . insert ( a [ i - 1 ] ) ; } else { l [ i ] = l [ i - 1 ] ; long long d = * s . begin ( ) ; if ( a [ i - 1 ] > d ) { l [ i ] -= d ; l [ i ] += a [ i - 1 ] ; s . erase ( s . find ( d ) ) ; s . insert ( a [ i - 1 ] ) ; } } } s . clear ( ) ; for ( int i = m ; i >= 1 ; i -- ) { if ( i >= m - n + 1 ) { r [ i ] = a [ i - 1 ] + r [ i + 1 ] ; s . insert ( a [ i - 1 ] ) ; } else { r [ i ] = r [ i + 1 ] ; long long d = * s . rbegin ( ) ; if ( a [ i - 1 ] < d ) { r [ i ] -= d ; r [ i ] += a [ i - 1 ] ; s . erase ( s . find ( d ) ) ; s . insert ( a [ i - 1 ] ) ; } } } long long ans = -9e18L ; for ( int i = n ; i <= m - n ; i ++ ) { ans = max ( ans , l [ i ] - r [ i + 1 ] ) ; } return ans ; } int main ( ) { vector < long long > vtr = { 3 , 1 , 4 , 1 , 5 , 9 } ; int n = vtr . size ( ) ; cout << FindMaxDif ( vtr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include using namespace std ; string checkPossible ( int A [ ] , int B [ ] , int n ) { unordered_set values ; for ( int i = 0 ; i < n ; i ++ ) { values . insert ( B [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( values . find ( A [ i ] + A [ j ] ) != values . end ( ) ) { values . erase ( A [ i ] + A [ j ] ) ; if ( values . empty ( ) ) break ; } } } if ( values . size ( ) == 0 ) return " Yes " ; else return " No " ; } int main ( ) { int N = 5 ; int A [ ] = { 3 , 5 , 1 , 4 , 2 } ; int B [ ] = { 3 , 4 , 5 , 6 , 7 } ; cout << checkPossible ( A , B , N ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int N = 2e5 ; const int V = 500 ; void solve ( int n , int d , int input [ ] ) { int a [ N ] ; int cnt [ V + 1 ] ; for ( int i = 0 ; i < n ; ++ i ) a [ i ] = input [ i ] ; int answer = 0 ; for ( int i = 0 ; i < d ; ++ i ) cnt [ a [ i ] ] ++ ; for ( int i = d ; i <= n - 1 ; ++ i ) { int acc = 0 ; int low_median = -1 , high_median = -1 ; for ( int v = 0 ; v <= V ; ++ v ) { acc += cnt [ v ] ; if ( low_median == -1 && acc >= int ( floor ( ( d + 1 ) / 2.0 ) ) ) low_median = v ; if ( high_median == -1 && acc >= int ( ceil ( ( d + 1 ) / 2.0 ) ) ) high_median = v ; } int double_median = low_median + high_median ; if ( a [ i ] >= double_median ) answer ++ ; cnt [ a [ i - d ] ] -- ; cnt [ a [ i ] ] ++ ; } cout << answer << endl ; } int main ( ) { int input [ ] = { 1 , 2 , 2 , 4 , 5 } ; int n = sizeof input / sizeof input [ 0 ] ; int k = 3 ; solve ( n , k , input ) ; return 0 ; }

Index/key variables: N, i, v
Accumulator variables: acc, answer, stdc
Iterator variables: i, v
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinSoln ( int n , int k ) { int minSoln = INT_MAX ; for ( int i = 1 ; i < k ; i ++ ) { if ( n % i == 0 ) minSoln = min ( minSoln , ( n / i ) * k + i ) ; } return minSoln ; } int main ( ) { int n = 4 , k = 6 ; cout << findMinSoln ( n , k ) ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getSum ( int BITree [ ] , int index ) { int ans = 0 ; index += 1 ; while ( index > 0 ) { ans += BITree [ index ] ; index -= index & ( - index ) ; } return ans ; } static void updateBIT ( int BITree [ ] , int n , int index , int val ) { index = index + 1 ; while ( index <= n ) { BITree [ index ] += val ; index += index & ( - index ) ; } } int * constructBITree ( int arr [ ] , int n ) { int * BITree = new int [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) BITree [ i ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) updateBIT ( BITree , n , i , arr [ i ] ) ; return BITree ; } int getLowerBound ( int BITree [ ] , int arr [ ] , int n , int k ) { int lb = -1 ; int l = 0 , r = n - 1 ; while ( l <= r ) { int mid = l + ( r - l ) / 2 ; if ( getSum ( BITree , mid ) >= k ) { r = mid - 1 ; lb = mid ; } else l = mid + 1 ; } return lb ; } void performQueries ( int A [ ] , int n , int q [ ] [ 3 ] ) { int * BITree = constructBITree ( A , n ) ; for ( int i = 0 ; i < sizeof ( q [ 0 ] ) / sizeof ( int ) ; i ++ ) { int id = q [ i ] [ 0 ] ; if ( id == 1 ) { int idx = q [ i ] [ 1 ] ; int val = q [ i ] [ 2 ] ; A [ idx ] += val ; updateBIT ( BITree , n , idx , val ) ; } else { int k = q [ i ] [ 1 ] ; int lb = getLowerBound ( BITree , A , n , k ) ; cout << lb << endl ; } } } int main ( ) { int A [ ] = { 1 , 2 , 3 , 5 , 8 } ; int n = sizeof ( A ) / sizeof ( int ) ; int q [ ] [ 3 ] = { { 1 , 0 , 2 } , { 2 , 5 , 0 } , { 1 , 3 , 5 } } ; performQueries ( A , n , q ) ; }

Index/key variables: i, idx, index
Accumulator variables: ans, i, index, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int cnt = 0 ; void dfs ( int * val , int * cost , vector < vector < int > > & tr , int u , int s ) { s = s + cost [ u ] ; if ( s < 0 ) s = 0 ; if ( s > val [ u ] ) return ; cnt ++ ; for ( int i = 0 ; i < tr [ u ] . size ( ) ; i ++ ) { dfs ( val , cost , tr , tr [ u ] [ i ] , s ) ; } } int main ( ) { int n = 9 ; int val [ ] = { 88 , 22 , 83 , 14 , 95 , 91 , 98 , 53 , 11 } ; int cost [ ] = { -1 , 24 , -8 , 67 , 64 , 65 , 12 , -80 , 8 } ; vector < vector < int > > tr ( n + 1 ) ; tr [ 0 ] . push_back ( 3 ) ; tr [ 0 ] . push_back ( 4 ) ; tr [ 4 ] . push_back ( 6 ) ; tr [ 6 ] . push_back ( 2 ) ; tr [ 2 ] . push_back ( 1 ) ; tr [ 2 ] . push_back ( 8 ) ; tr [ 8 ] . push_back ( 5 ) ; tr [ 5 ] . push_back ( 7 ) ; dfs ( val , cost , tr , 0 , 0 ) ; cout << n - cnt ; return 0 ; }

Index/key variables: i, u
Accumulator variables: cnt, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool ContinuousElements ( int a [ ] , int n ) { if ( n == 1 ) return false ; int curr = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] != a [ i - 1 ] ) { if ( curr == 1 ) return false ; else curr = 0 ; } curr ++ ; } if ( curr == 1 ) return false ; return true ; } int main ( ) { int a [ ] = { 1 , 1 , 2 , 2 , 1 , 3 , 3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; if ( ContinuousElements ( a , n ) ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: curr, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int BFS ( vector < vector < int > > & mat , int row , int col ) { int area = 0 ; queue < pair < int , int > > Q ; Q . push ( { row , col } ) ; while ( ! Q . empty ( ) ) { auto it = Q . front ( ) ; Q . pop ( ) ; int r = it . first , c = it . second ; if ( r < 0 c < 0 r > 4 c > 4 ) continue ; if ( mat [ r ] == 0 ) continue ; if ( mat [ r ] == 1 ) { mat [ r ] = 0 ; area ++ ; } Q . push ( { r + 1 , c } ) ; Q . push ( { r - 1 , c } ) ; Q . push ( { r , c + 1 } ) ; Q . push ( { r , c - 1 } ) ; } return area ; } void sizeOfConnections ( vector < vector < int > > mat ) { vector < int > result ; for ( int row = 0 ; row < 5 ; ++ row ) { for ( int col = 0 ; col < 5 ; ++ col ) { if ( mat [ row ] [ col ] == 1 ) { int area = BFS ( mat , row , col ) ; result . push_back ( area ) ; } } } for ( int val : result ) cout << val << " ▁ " ; } int main ( ) { vector < vector < int > > mat = { { 1 , 1 , 0 , 0 , 0 } , { 1 , 1 , 0 , 1 , 1 } , { 1 , 0 , 0 , 1 , 1 } , { 1 , 0 , 0 , 0 , 0 } , { 0 , 0 , 1 , 1 , 1 } } ; sizeOfConnections ( mat ) ; return 0 ; }

Index/key variables: col, r, row
Accumulator variables: area, stdc
Iterator variables: col, row, val
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxProduct ( int arr [ ] , int N ) { if ( N < 3 ) { return ; } sort ( arr , arr + N ) ; int smallest1 = arr [ 0 ] ; int smallest3 = arr [ 2 ] ; int largest1 = arr [ N - 1 ] ; int largest3 = arr [ N - 3 ] ; if ( smallest1 * smallest3 >= largest1 * largest3 ) { cout << smallest1 << " ▁ " << smallest3 ; } else { cout << largest1 << " ▁ " << largest3 ; } } int main ( ) { int arr [ ] = { 5 , 2 , 67 , 45 , 160 , 78 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; maxProduct ( arr , N ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxLen ( int A [ ] , int N ) { vector < vector < int > > v ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] == 1 ) { int s = i , len ; while ( A [ i ] == 1 && i < N ) { i ++ ; } len = i - s ; v . push_back ( { len , s , i - 1 } ) ; } } if ( v . size ( ) == 0 ) { return -1 ; } int ans = 0 ; for ( int i = 0 ; i < v . size ( ) - 1 ; i ++ ) { ans = max ( ans , v [ i ] [ 0 ] ) ; if ( v [ i + 1 ] [ 1 ] - v [ i ] [ 2 ] - 1 == 2 ) { ans = max ( ans , v [ i ] [ 0 ] + v [ i + 1 ] [ 0 ] ) ; } if ( v [ i + 1 ] [ 1 ] - v [ i ] [ 2 ] - 1 == 1 ) { ans = max ( ans , v [ i ] [ 0 ] + v [ i + 1 ] [ 0 ] - 1 ) ; } } ans = max ( v [ v . size ( ) - 1 ] [ 0 ] , ans ) ; return ans ; } int main ( ) { int arr [ ] = { 1 , 0 , 1 , 0 , 0 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxLen ( arr , N ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int t , n , m , a ; stack < int > s ; vector < int > tsort ; vector < int > adj [ int ( 1e5 ) + 1 ] ; vector < int > visited ( int ( 1e5 ) + 1 ) ; void dfs ( int u ) { visited [ u ] = 1 ; for ( auto it : adj [ u ] ) { if ( visited [ it ] == 0 ) dfs ( it ) ; } s . push ( u ) ; } bool check_cycle ( ) { unordered_map < int , int > pos ; int ind = 0 ; while ( ! s . empty ( ) ) { pos [ s . top ( ) ] = ind ; tsort . push_back ( s . top ( ) ) ; ind += 1 ; s . pop ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( auto it : adj [ i ] ) { if ( pos [ i ] > pos [ it ] ) { return true ; } } } return false ; } void addEdge ( int u , int v ) { adj [ u ] . push_back ( v ) ; } int main ( ) { n = 4 , m = 5 ; addEdge ( 0 , 1 ) ; addEdge ( 0 , 2 ) ; addEdge ( 1 , 2 ) ; addEdge ( 2 , 0 ) ; addEdge ( 2 , 3 ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( visited [ i ] == 0 ) { dfs ( i ) ; } } if ( check_cycle ( ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i, it, u
Accumulator variables: i, ind, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printNewArray ( vector < int > a , int n ) { vector < pair < int , int > > v ; for ( int i = 0 ; i < n ; i ++ ) { v . push_back ( { a [ i ] , i } ) ; } sort ( v . begin ( ) , v . end ( ) ) ; int ans [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ans [ v [ ( i + 1 ) % n ] . second ] = v [ i ] . first ; } for ( int i = 0 ; i < n ; i ++ ) { cout << ans [ i ] << " ▁ " ; } } int main ( ) { vector < int > a = { 4 , 1 , 2 , 5 , 3 } ; int n = a . size ( ) ; printNewArray ( a , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int min_remove ( int arr [ ] , int n , int k ) { sort ( arr , arr + n ) ; int ans = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { if ( arr [ j ] - arr [ i ] <= k ) { ans = min ( ans , n - j + i - 1 ) ; } } } return ans ; } int main ( ) { int k = 3 ; int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = sizeof arr / sizeof arr [ 0 ] ; cout << min_remove ( arr , n , k ) ; 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 ; void solve ( int arr [ ] , int n ) { int countzeroes = 0 ; int countones = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) countzeroes ++ ; else countones ++ ; } if ( abs ( countzeroes - countones ) == 1 ) cout << " Yes " ; else cout << " No " ; } int main ( ) { int arr [ ] = { 0 , 1 , 0 , 0 , 1 , 1 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; solve ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: countones, countzeroes, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; char bs ( char ar [ ] , int n , int ele ) { int start = 0 ; int end = n - 1 ; char ch = ' @ ' ; while ( start <= end ) { int mid = start + ( end - start ) / 2 ; if ( ar [ mid ] == ele ) end = mid - 1 ; else if ( ar [ mid ] < ele ) { ch = ar [ mid ] ; start = mid + 1 ; } else end = mid - 1 ; } return ch ; } int main ( ) { char ar [ ] = { ' e ' , ' g ' , ' t ' , ' y ' } ; int n = sizeof ( ar ) / sizeof ( ar [ 0 ] ) ; char K = ' u ' ; char ch = bs ( ar , n , K ) ; if ( ch == ' @ ' ) cout << " - 1" ; else cout << ch ; return 0 ; }

Index/key variables: mid
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
#define ll  long long
using namespace std ; int findMaxLen ( vector < ll > & a , ll k ) { int n = a . size ( ) ; sort ( a . begin ( ) , a . end ( ) ) ; vector < bool > vis ( n , 0 ) ; map < int , int > mp ; for ( int i = 0 ; i < n ; i ++ ) { mp [ a [ i ] ] = i ; } int c = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( vis [ i ] == false ) { int check = a [ i ] * k ; if ( mp . find ( check ) != mp . end ( ) ) { c ++ ; vis [ mp [ check ] ] = true ; } } } return n - c ; } int main ( ) { int K = 3 ; vector < ll > arr = { 1 , 4 , 3 , 2 } ; cout << findMaxLen ( arr , K ) ; }

Index/key variables: check, i
Accumulator variables: c, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getPrefixLength ( string srcStr , string targetStr ) { if ( targetStr . length ( ) == 0 ) return 0 ; transform ( srcStr . begin ( ) , srcStr . end ( ) , srcStr . begin ( ) , :: tolower ) ; transform ( targetStr . begin ( ) , targetStr . end ( ) , targetStr . begin ( ) , :: tolower ) ; map < char , int > dictCount ; int nUnique = 0 ; for ( char ch : targetStr ) { if ( dictCount . find ( ch ) == dictCount . end ( ) ) { nUnique += 1 ; dictCount [ ch ] = 0 ; } dictCount [ ch ] += 1 ; } for ( int i = 0 ; i < srcStr . length ( ) ; i ++ ) { char ch = srcStr [ i ] ; if ( dictCount . find ( ch ) == dictCount . end ( ) ) continue ; dictCount [ ch ] -= 1 ; if ( dictCount [ ch ] == 0 ) nUnique -= 1 ; if ( nUnique == 0 ) return ( i + 1 ) ; } return -1 ; } int main ( ) { string S = " MarvoloGaunt " ; string T = " Tom " ; cout << getPrefixLength ( S , T ) ; return 0 ; }

Index/key variables: ch, i
Accumulator variables: i, nUnique, stdc
Iterator variables: ch, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool check ( string & str , int mid , char a ) { int n = str . size ( ) ; int previous = -1 , i ; for ( i = 0 ; i < n ; ++ i ) { if ( str [ i ] == a ) { if ( i - previous > mid ) { return false ; } previous = i ; } } if ( i - previous > mid ) return false ; else return true ; } bool possible ( string & str , int mid ) { for ( int i = 0 ; i < 26 ; ++ i ) { if ( check ( str , mid , i + ' a ' ) ) return true ; } return false ; } int findMinLength ( string & str ) { int low = 1 , high = str . length ( ) ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( possible ( str , mid ) ) high = mid - 1 ; else low = mid + 1 ; } return high + 1 ; } bool ifAllDistinct ( string str ) { set < char > s ; for ( char c : str ) { s . insert ( c ) ; } return s . size ( ) == str . size ( ) ; } int main ( ) { string str = " geeksforgeeks " ; if ( ifAllDistinct ( str ) ) cout << -1 << endl ; else cout << findMinLength ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc
Iterator variables: c, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int solve ( int A [ ] , int N ) { int i = 0 ; int k = 0 ; for ( int j = 1 ; j < N ; j ++ ) { int tempK = min ( A [ i ] , A [ j ] ) / ( j - i ) ; if ( tempK > k ) { k = tempK ; } if ( A [ j ] >= A [ i ] / ( j - i ) ) i = j ; } return k ; } int main ( ) { int A [ ] = { 10 , 5 , 12 , 15 , 8 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << solve ( A , N ) ; return 0 ; }

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