dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxDistance ( int arr [ ] , int K , int N ) { map < int , int > Map ; int maxDist = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( Map . find ( arr [ i ] ) == Map . end ( ) ) Map [ arr [ i ] ] = i ; if ( Map . find ( arr [ i ] + K ) != Map . end ( ) ) { maxDist = max ( maxDist , i - Map [ arr [ i ] + K ] ) ; } if ( Map . find ( arr [ i ] - K ) != Map . end ( ) ) { maxDist = max ( maxDist , i - Map [ arr [ i ] - K ] ) ; } } if ( maxDist == 0 ) return -1 ; else return maxDist ; } int main ( ) { int arr [ ] = { 11 , 2 , 3 , 8 , 5 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 2 ; cout << maxDistance ( arr , K , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int no_of_substring ( string s , int N ) { int fre [ 26 ] ; int str_len ; str_len = ( int ) s . length ( ) ; int count = 0 ; for ( int i = 0 ; i < str_len ; i ++ ) { memset ( fre , 0 , sizeof ( fre ) ) ; int max_index = 0 ; int dist = 0 ; for ( int j = i ; j < str_len ; j ++ ) { int x = s [ j ] - ' a ' ; if ( fre [ x ] == 0 ) dist ++ ; fre [ x ] ++ ; max_index = max ( max_index , fre [ x ] ) ; if ( dist >= N && ( ( max_index * dist ) == ( j - i + 1 ) ) ) count ++ ; } } return count ; } int main ( ) { string s = " abhay " ; int N = 3 ; cout << no_of_substring ( s , N ) ; return 0 ; }

Index/key variables: j, x
Accumulator variables: count, dist, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void solve ( int n ) { int ans = 0 ; for ( int y = n + 1 ; y <= n * n + n ; y ++ ) { if ( ( n * n ) % ( y - n ) == 0 ) { ans += 1 ; } } cout << ans ; } int main ( ) { int n = 5 ; solve ( n ) ; return 0 ; }

Accumulator variables: ans, stdc, y
Iterator variables: y
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > adj [ 100005 ] ; int visited [ 100005 ] = { 0 } ; int ans = 0 ; void dfs ( int node , int count , int m , int arr [ ] , int k ) { visited [ node ] = 1 ; if ( arr [ node - 1 ] == k ) { count ++ ; } else { count = 0 ; } if ( count > m ) { return ; } if ( adj [ node ] . size ( ) == 1 && node != 1 ) { ans ++ ; } for ( auto x : adj [ node ] ) { if ( ! visited [ x ] ) { dfs ( x , count , m , arr , k ) ; } } } int main ( ) { int arr [ ] = { 2 , 1 , 3 , 2 , 1 , 2 , 1 } ; int N = 7 , K = 2 , M = 2 ; adj [ 1 ] . push_back ( 2 ) ; adj [ 2 ] . push_back ( 1 ) ; adj [ 1 ] . push_back ( 3 ) ; adj [ 3 ] . push_back ( 1 ) ; adj [ 2 ] . push_back ( 4 ) ; adj [ 4 ] . push_back ( 2 ) ; adj [ 2 ] . push_back ( 5 ) ; adj [ 5 ] . push_back ( 2 ) ; adj [ 3 ] . push_back ( 6 ) ; adj [ 6 ] . push_back ( 3 ) ; adj [ 3 ] . push_back ( 7 ) ; adj [ 7 ] . push_back ( 3 ) ; int counter = 0 ; dfs ( 1 , counter , M , arr , K ) ; cout << ans << " STRNEWLINE " ; return 0 ; }

Index/key variables: node, x
Accumulator variables: ans, count, stdc
Iterator variables: x
C++ program:
#include <bits/stdc++.h>
using namespace std ; long reverse ( long num ) { long rev = 0 ; while ( num > 0 ) { int r = ( int ) ( num % 10 ) ; rev = rev * 10 + r ; num /= 10 ; } return rev ; } long count ( int N , int A , int B ) { long l = ( long ) pow ( 10 , N - 1 ) , r = ( long ) pow ( 10 , N ) - 1 ; if ( l == 1 ) l = 0 ; long ans = 0 ; for ( long i = l ; i <= r ; i ++ ) { int even_sum = 0 , odd_sum = 0 ; long itr = 0 , num = reverse ( i ) ; while ( num > 0 ) { if ( itr % 2 == 0 ) odd_sum += num % 10 ; else even_sum += num % 10 ; num /= 10 ; itr ++ ; } if ( even_sum % A == 0 && odd_sum % B == 0 ) ans ++ ; } return ans ; } int main ( ) { int N = 2 , A = 5 , B = 3 ; cout << ( count ( N , A , B ) ) ; }

Accumulator variables: ans, even_sum, i, itr, num, odd_sum, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int calc_distance ( int A [ ] , int B [ ] , int n ) { int distance_traveled_A = 0 ; int distance_traveled_B = 0 ; int answer = 0 ; for ( int i = 0 ; i < 5 ; i ++ ) { distance_traveled_A += A [ i ] ; distance_traveled_B += B [ i ] ; if ( ( distance_traveled_A == distance_traveled_B ) && ( A [ i ] == B [ i ] ) ) { answer += A [ i ] ; } } return answer ; } int main ( ) { int A [ 5 ] = { 1 , 2 , 3 , 2 , 4 } ; int B [ 5 ] = { 2 , 1 , 3 , 1 , 4 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << calc_distance ( A , B , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: answer, distance_traveled_A, distance_traveled_B, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < vector < int > > constructTree ( int n , vector < vector < int > > edges ) { vector < vector < int > > adjl ( n ) ; for ( auto e : edges ) { int u = e [ 0 ] ; int v = e [ 1 ] ; adjl [ u ] . push_back ( v ) ; adjl [ v ] . push_back ( u ) ; } return adjl ; } void DFS ( vector < vector < int > > adjl , vector < int > & parent , int u , int p ) { parent [ u ] = p ; for ( int v : adjl [ u ] ) { if ( v != p ) { DFS ( adjl , parent , v , u ) ; } } } vector < int > valuesFromChildren ( vector < int > parent , vector < int > values ) { vector < int > valuesChildren ( parent . size ( ) ) ; for ( int i = 0 ; i < parent . size ( ) ; i ++ ) { if ( parent [ i ] == -1 ) continue ; else { int p = parent [ i ] ; valuesChildren [ p ] += values [ i ] ; } } return valuesChildren ; } int findSumOfValues ( int v , vector < int > parent , vector < int > valuesChildren ) { int cur_node = v ; int sum = 0 ; while ( cur_node != -1 ) { sum += valuesChildren [ cur_node ] ; cur_node = parent [ cur_node ] ; } return sum ; } int main ( ) { int n = 8 ; vector < vector < int > > edges = { { 0 , 1 } , { 0 , 2 } , { 0 , 3 } , { 1 , 4 } , { 1 , 5 } , { 4 , 7 } , { 3 , 6 } } ; int v = 7 ; vector < int > values = { 1 , 2 , 3 , 0 , 0 , 4 , 3 , 6 } ; vector < vector < int > > adjl = constructTree ( n , edges ) ; vector < int > parent ( n ) ; DFS ( adjl , parent , 0 , -1 ) ; vector < int > valuesChildren = valuesFromChildren ( parent , values ) ; int sum = findSumOfValues ( v , parent , valuesChildren ) ; sum += values [ 0 ] ; cout << sum << endl ; }

Index/key variables: cur_node, i, p, u, v
Accumulator variables: i, stdc, sum
Iterator variables: e, i, v
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxProduct ( int arr [ ] , int N ) { if ( N < 3 ) { return ; } int a = arr [ 0 ] , b = arr [ 1 ] ; int c = 0 , d = 0 ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = i + 1 ; j < N ; j ++ ) { if ( arr [ i ] * arr [ j ] > a * b ) { c = a , d = b ; a = arr [ i ] , b = arr [ j ] ; } if ( arr [ i ] * arr [ j ] < a * b && arr [ i ] * arr [ j ] > c * d ) c = arr [ i ] , d = arr [ j ] ; } cout << c << " ▁ " << d ; } int main ( ) { int arr [ ] = { 5 , 2 , 67 , 45 , 160 , 78 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; maxProduct ( arr , N ) ; 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 ; bool isVowel ( char c ) { if ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) return true ; return false ; } void countSubstrings ( string s , int n ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int count = 0 ; for ( int j = i ; j < n ; j ++ ) { if ( isVowel ( s [ j ] ) ) { count ++ ; } if ( count % 2 == 0 ) result ++ ; } } cout << result ; } int main ( ) { int n = 5 ; string s = " abcde " ; countSubstrings ( s , n ) ; return 0 ; }

Index/key variables: j
Accumulator variables: count, i, j, result, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isVowel ( char c ) { if ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) return true ; return false ; } void countSubstrings ( string s , int n ) { int temp [ ] = { 1 , 0 } ; int result = 0 , sum = 0 ; for ( int i = 0 ; i <= n - 1 ; i ++ ) { sum += ( isVowel ( s [ i ] ) ? 1 : 0 ) ; sum %= 2 ; temp [ sum ] ++ ; } result += ( ( temp [ 0 ] * ( temp [ 0 ] - 1 ) ) / 2 ) ; result += ( ( temp [ 1 ] * ( temp [ 1 ] - 1 ) ) / 2 ) ; cout << result ; } int main ( ) { int n = 5 ; string s = " abcde " ; countSubstrings ( s , n ) ; }

Index/key variables: i, sum
Accumulator variables: i, result, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; 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 ) ; } int findLevel ( Node * root , int k , int level ) { queue < pair < Node * , int > > qt ; qt . push ( make_pair ( root , 0 ) ) ; int count = 1 , b , a = 0 ; while ( ! qt . empty ( ) ) { pair < Node * , int > temp = qt . front ( ) ; qt . pop ( ) ; if ( count == 1 ) { b = temp . second ; } if ( ( temp . first ) -> left ) { qt . push ( make_pair ( temp . first -> left , 2 * temp . second ) ) ; } if ( temp . first -> right ) { qt . push ( make_pair ( temp . first -> right , 2 * temp . second + 1 ) ) ; } count -- ; if ( count == 0 ) { if ( b - a + 1 == k ) return level ; pair < Node * , int > secondLabel = qt . front ( ) ; a = secondLabel . second ; level += 1 ; count = qt . size ( ) ; } } return -1 ; } int main ( ) { Node * root = newNode ( 5 ) ; root -> left = newNode ( 6 ) ; root -> right = newNode ( 2 ) ; root -> right -> right = newNode ( 8 ) ; root -> left -> left = newNode ( 7 ) ; root -> left -> left -> left = newNode ( 5 ) ; root -> left -> right = newNode ( 3 ) ; root -> left -> right -> right = newNode ( 4 ) ; int k = 4 ; cout << findLevel ( root , k , 1 ) << endl ; return 0 ; }

Accumulator variables: count, level, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool possible ( int arr [ ] , int N , int mid , int K ) { int add = 0 ; for ( int i = N / 2 - ( N + 1 ) % 2 ; i < N ; ++ i ) { if ( mid - arr [ i ] > 0 ) { add += ( mid - arr [ i ] ) ; if ( add > K ) return false ; } } if ( add <= K ) return true ; else return false ; } int findMaxMedian ( int arr [ ] , int N , int K ) { int low = 1 ; int mx = 0 ; for ( int i = 0 ; i < N ; ++ i ) { mx = max ( mx , arr [ i ] ) ; } long long int high = K + mx ; while ( low <= high ) { int mid = ( high + low ) / 2 ; if ( possible ( arr , N , mid , K ) ) { low = mid + 1 ; } else { high = mid - 1 ; } } if ( N % 2 == 0 ) { if ( low - 1 < arr [ N / 2 ] ) { return ( arr [ N / 2 ] + low - 1 ) / 2 ; } } return low - 1 ; } int main ( ) { int arr [ ] = { 1 , 3 , 6 } ; int K = 10 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sort ( arr , arr + N ) ; cout << findMaxMedian ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: add, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define LL  long long
bool countLessThanMid ( LL mid , LL N , LL M , LL K ) { LL count = 0 ; for ( int i = 1 ; i <= min ( ( LL ) N , mid ) ; ++ i ) { count = count + min ( mid / i , M ) ; } if ( count >= K ) return false ; else return true ; } LL findKthElement ( LL N , LL M , LL K ) { LL low = 1 , high = N * M ; while ( low <= high ) { LL mid = low + ( high - low ) / 2 ; if ( countLessThanMid ( mid , N , M , K ) ) low = mid + 1 ; else high = mid - 1 ; } return high + 1 ; } int main ( ) { LL N = 2 , M = 3 ; LL int K = 5 ; cout << findKthElement ( N , M , K ) << endl ; return 0 ; }

Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countSubString ( string S , char C ) { int count = 0 ; int conCount = 0 ; for ( char ch : S ) { if ( ch == C ) conCount ++ ; else { count += ( conCount * ( conCount + 1 ) ) / 2 ; conCount = 0 ; } } count += ( conCount * ( conCount + 1 ) ) / 2 ; cout << count ; } int main ( ) { string S = " geeksforgeeks " ; char C = ' e ' ; countSubString ( S , C ) ; return 0 ; }

Accumulator variables: conCount, count, stdc
Iterator variables: ch
C++ program:
#include <bits/stdc++.h>
using namespace std ; void checkPalindrome ( string S ) { int N = S . size ( ) ; bool first_half = true ; bool second_half = true ; int cnt = ( N / 2 ) - 1 ; for ( int i = 0 ; i < ( ( N / 2 ) / 2 ) ; i ++ ) { if ( S [ i ] != S [ cnt ] ) { first_half = false ; break ; } if ( S [ N / 2 + i ] != S [ N / 2 + cnt ] ) { second_half - false ; break ; } cnt -- ; } if ( first_half && second_half ) { cout << " Yes " << endl ; } else { cout << " No " << endl ; } } int main ( ) { string S = " momdad " ; checkPalindrome ( S ) ; return 0 ; }

Index/key variables: cnt, i
Accumulator variables: cnt, i, stdc
Iterator variables: i
Boolean variables: first_half, second_half
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getCount ( int N , vector < string > & s ) { map < vector < int > , int > mp ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { vector < int > a ( 26 , 0 ) ; for ( int j = 0 ; j < s [ i ] . size ( ) ; j ++ ) { a [ s [ i ] [ j ] - ' a ' ] ++ ; } for ( int j = 0 ; j < 26 ; j ++ ) { a [ j ] = a [ j ] % 2 ; } ans += mp [ a ] ; for ( int j = 0 ; j < 26 ; j ++ ) { vector < int > changedCount = a ; if ( a [ j ] == 0 ) changedCount [ j ] = 1 ; else changedCount [ j ] = 0 ; ans += mp [ changedCount ] ; } mp [ a ] ++ ; } return ans ; } int main ( ) { int N = 6 ; vector < string > A = { " aab " , " abcac " , " dffe " , " ed " , " aa " , " aade " } ; cout << getCount ( N , A ) ; return 0 ; }

Index/key variables: a, changedCount, i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int key ; Node * left , * right ; } ; Node * newNode ( int item ) { Node * temp = new Node ; temp -> key = item ; temp -> left = temp -> right = NULL ; return temp ; } Node * insert ( Node * node , int key ) { if ( node == NULL ) return newNode ( key ) ; if ( key < node -> key ) node -> left = insert ( node -> left , key ) ; else if ( key > node -> key ) node -> right = insert ( node -> right , key ) ; return node ; } bool KSmallestPerfectBST ( Node * root , int k , int treeSize , int & kth_smallest ) { if ( root == NULL ) return false ; int median_loc = ( treeSize / 2 ) + 1 ; if ( k == median_loc ) { kth_smallest = root -> key ; return true ; } int newTreeSize = treeSize / 2 ; if ( k < median_loc ) { return KSmallestPerfectBST ( root -> left , k , newTreeSize , kth_smallest ) ; } int newK = k - median_loc ; return KSmallestPerfectBST ( root -> right , newK , newTreeSize , kth_smallest ) ; } int main ( ) { Node * root = NULL ; root = insert ( root , 50 ) ; insert ( root , 30 ) ; insert ( root , 20 ) ; insert ( root , 40 ) ; insert ( root , 70 ) ; insert ( root , 60 ) ; insert ( root , 80 ) ; insert ( root , 14 ) ; insert ( root , 25 ) ; insert ( root , 35 ) ; insert ( root , 45 ) ; insert ( root , 55 ) ; insert ( root , 65 ) ; insert ( root , 75 ) ; insert ( root , 85 ) ; int n = 15 , k = 5 ; int ans = -1 ; if ( KSmallestPerfectBST ( root , k , n , ans ) ) { cout << ans << " ▁ " ; } return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkrules ( string s ) { if ( s . length ( ) == 0 ) return true ; if ( s [ 0 ] != '1' ) return false ; if ( s . length ( ) > 2 ) { if ( s [ 1 ] == '0' && s [ 2 ] == '0' ) return checkrules ( s . substr ( 3 ) ) ; } return checkrules ( s . substr ( 1 ) ) ; } int main ( ) { string str = "1111" ; if ( checkrules ( str ) ) { cout << " Valid ▁ String " ; } else { cout << " Invalid ▁ String " ; } return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isNudeNum ( int n ) { int copy , length , flag = 0 ; copy = n ; string temp ; temp = to_string ( copy ) ; length = temp . length ( ) ; for ( int i = 0 ; i < length ; i ++ ) { int num = temp [ i ] - '0' ; if ( num == 0 or n % num != 0 ) { flag = 1 ; } } if ( flag == 1 ) return false ; else return true ; } int longestNudeSubseq ( int arr [ ] , int n ) { int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isNudeNum ( arr [ i ] ) ) answer ++ ; } return answer ; } int main ( ) { int arr [ ] = { 34 , 34 , 2 , 2 , 3 , 333 , 221 , 32 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << longestNudeSubseq ( arr , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: answer, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestSubarray ( int arr [ ] , int n , int k ) { int i , j , Max = 1 ; set < int > s ; for ( i = 0 ; i < n - 1 ; i ++ ) { s . insert ( arr [ i ] ) ; for ( j = i + 1 ; j < n ; j ++ ) { if ( abs ( arr [ i ] - arr [ j ] ) == 0 || abs ( arr [ i ] - arr [ j ] ) == k ) { if ( ! s . count ( arr [ j ] ) ) { if ( s . size ( ) == 2 ) break ; else s . insert ( arr [ j ] ) ; } } else break ; } if ( s . size ( ) == 2 ) { Max = max ( Max , j - i ) ; s . clear ( ) ; } else s . clear ( ) ; } return Max ; } int main ( ) { int arr [ ] = { 1 , 0 , 2 , 2 , 5 , 5 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 1 ; int length = longestSubarray ( arr , N , K ) ; if ( length == 1 ) cout << -1 ; else cout << length ; 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 longestSubarray ( int a [ ] , int n ) { int l [ n ] ; int r [ n ] ; for ( int i = 0 , count = 0 ; i < n ; i ++ ) { if ( a [ i ] == 1 ) count ++ ; else { l [ i ] = count ; count = 0 ; } } for ( int i = n - 1 , count = 0 ; i >= 0 ; i -- ) { if ( a [ i ] == 1 ) count ++ ; else { r [ i ] = count ; count = 0 ; } } int ans = -1 ; for ( int i = 0 ; i < n ; ++ i ) { if ( a [ i ] == 0 ) ans = max ( ans , l [ i ] + r [ i ] ) ; } return ans < 0 ? n : ans ; } int main ( ) { int arr [ ] = { 0 , 1 , 1 , 1 , 0 , 1 , 0 , 1 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << longestSubarray ( arr , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMaxValue ( int N , int K ) { int packages ; int maxi = 1 ; for ( int i = 1 ; i <= K ; i ++ ) { if ( N % i == 0 ) maxi = max ( maxi , i ) ; } packages = N / maxi ; cout << packages << endl ; } int main ( ) { int N = 8 , K = 7 ; findMaxValue ( N , K ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxSide ( int a [ ] , int n ) { int sideLength = 0 ; sort ( a , a + n ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( a [ i ] > sideLength ) { sideLength ++ ; } else { break ; } } cout << sideLength << endl ; } int main ( ) { int N = 6 ; int arr [ ] = { 3 , 2 , 1 , 5 , 2 , 4 } ; maxSide ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, sideLength, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void Solution_dfs ( int v , int color [ ] , int red , int blue , int * sub_red , int * sub_blue , int * vis , map < int , vector < int > > & adj , int * ans ) { vis [ v ] = 1 ; for ( int i = 0 ; i < adj [ v ] . size ( ) ; i ++ ) { if ( vis [ adj [ v ] [ i ] ] == 0 ) { Solution_dfs ( adj [ v ] [ i ] , color , red , blue , sub_red , sub_blue , vis , adj , ans ) ; sub_red [ v ] += sub_red [ adj [ v ] [ i ] ] ; sub_blue [ v ] += sub_blue [ adj [ v ] [ i ] ] ; } } if ( color [ v ] == 1 ) { sub_red [ v ] ++ ; } if ( color [ v ] == 2 ) { sub_blue [ v ] ++ ; } if ( sub_red [ v ] == red && sub_blue [ v ] == 0 ) { ( * ans ) ++ ; } if ( sub_red [ v ] == 0 && sub_blue [ v ] == blue ) { ( * ans ) ++ ; } } int countRed ( int color [ ] , int n ) { int red = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( color [ i ] == 1 ) red ++ ; } return red ; } int countBlue ( int color [ ] , int n ) { int blue = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( color [ i ] == 2 ) blue ++ ; } return blue ; } void buildTree ( int edge [ ] [ 2 ] , map < int , vector < int > > & m , int n ) { int u , v , i ; for ( i = 0 ; i < n - 1 ; i ++ ) { u = edge [ i ] [ 0 ] - 1 ; v = edge [ i ] [ 1 ] - 1 ; m [ u ] . push_back ( v ) ; m [ v ] . push_back ( u ) ; } } void countSubtree ( int color [ ] , int n , int edge [ ] [ 2 ] ) { map < int , vector < int > > adj ; int ans = 0 ; int sub_red [ n + 3 ] = { 0 } ; int sub_blue [ n + 3 ] = { 0 } ; int vis [ n + 3 ] = { 0 } ; int red = countRed ( color , n ) ; int blue = countBlue ( color , n ) ; buildTree ( edge , adj , n ) ; Solution_dfs ( 0 , color , red , blue , sub_red , sub_blue , vis , adj , & ans ) ; cout << ans ; } int main ( ) { int N = 5 ; int color [ ] = { 1 , 0 , 0 , 0 , 2 } ; int edge [ ] [ 2 ] = { { 1 , 2 } , { 2 , 3 } , { 3 , 4 } , { 4 , 5 } } ; countSubtree ( color , N , edge ) ; return 0 ; }

Index/key variables: i, u, v
Accumulator variables: blue, i, red, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long
void minDiff ( vector < ll > a , int n ) { for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 1 ) a . push_back ( a [ i ] * 2 ) ; } sort ( a . begin ( ) , a . end ( ) ) ; ll mindifference = a [ 1 ] - a [ 0 ] ; for ( int i = 1 ; i < a . size ( ) ; i ++ ) { mindifference = min ( mindifference , a [ i ] - a [ i - 1 ] ) ; } cout << mindifference << endl ; } int main ( ) { vector < ll > arr = { 3 , 8 , 13 , 30 , 50 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; minDiff ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > v ; int bin ( int val , int k , int n ) { int lo = 0 ; int hi = n ; int mid ; int ans = -1 ; while ( lo <= hi ) { mid = lo + ( hi - lo ) / 2 ; if ( v [ mid ] - val <= k ) { lo = mid + 1 ; ans = mid ; } else hi = mid - 1 ; } return ans ; } void findSubarraySumK ( int arr [ ] , int N , int K ) { int sum = 0 ; v . push_back ( 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; v . push_back ( sum ) ; } int l = 0 , ans = 0 , r ; for ( int i = 0 ; i < N ; i ++ ) { r = bin ( v [ i ] , K , N ) ; ans = max ( ans , r - i ) ; } cout << ans ; } int main ( ) { int arr [ ] = { 6 , 8 , 14 , 9 , 4 , 11 , 10 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 13 ; findSubarraySumK ( arr , N , K ) ; return 0 ; }

Index/key variables: i, mid
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minRev ( vector < vector < int > > edges , int n ) { unordered_map < int , vector < int > > graph ; unordered_map < int , vector < int > > graph_rev ; for ( int i = 0 ; i < edges . size ( ) ; i ++ ) { int x = edges [ i ] [ 0 ] ; int y = edges [ i ] [ 1 ] ; graph [ x ] . push_back ( y ) ; graph_rev [ y ] . push_back ( x ) ; } queue < int > q ; vector < int > visited ( n , 0 ) ; q . push ( 0 ) ; int ans = 0 ; while ( ! q . empty ( ) ) { int curr = q . front ( ) ; visited [ curr ] = 1 ; int count = 0 ; q . pop ( ) ; for ( int i = 0 ; i < graph_rev [ curr ] . size ( ) ; i ++ ) { if ( ! visited [ graph_rev [ curr ] [ i ] ] ) { q . push ( graph_rev [ curr ] [ i ] ) ; } } for ( int i = 0 ; i < graph [ curr ] . size ( ) ; i ++ ) { if ( ! visited [ graph [ curr ] [ i ] ] ) { q . push ( graph [ curr ] [ i ] ) ; count ++ ; } } ans += count ; } return ans ; } int main ( ) { vector < vector < int > > edges ; edges = { { 0 , 1 } , { 1 , 3 } , { 2 , 3 } , { 4 , 0 } , { 4 , 5 } } ; int n = 6 ; cout << minRev ( edges , n ) ; return 0 ; }

Index/key variables: curr, i, x, y
Accumulator variables: ans, count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int splitArray ( int arr [ ] , int N ) { sort ( arr , arr + N ) ; int result = INT_MAX ; for ( int i = 1 ; i < N ; i ++ ) { result = min ( result , arr [ i ] - arr [ i - 1 ] ) ; } return result ; } int main ( ) { int arr [ ] = { 3 , 1 , 2 , 6 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << splitArray ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findValue ( int R , int C ) { int k = ( R * ( R - 1 ) ) / 2 + 1 ; int diff = R + 1 ; for ( int i = 1 ; i < C ; i ++ ) { k = ( k + diff ) ; diff ++ ; } return k ; } int main ( ) { int R = 4 ; int C = 4 ; int k = findValue ( R , C ) ; cout << k ; return 0 ; }

Accumulator variables: diff, i, stdc
Iterator variables: i