dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dfs ( int nums [ ] , int S , int curr_sum , int index , int n ) { if ( index == n ) { if ( S == curr_sum ) return 1 ; else return 0 ; } return dfs ( nums , S , curr_sum + nums [ index ] , index + 1 , n ) + dfs ( nums , S , curr_sum - nums [ index ] , index + 1 , n ) ; } int findWays ( int nums [ ] , int S , int n ) { return dfs ( nums , S , 0 , 0 , n ) ; } int main ( ) { int S = 3 ; int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int answer = findWays ( arr , S , n ) ; cout << ( answer ) ; return 0 ; }

Index/key variables: index
Accumulator variables: stdc
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 ) ; } void frequencyCounts ( unordered_map < int , int > & map , Node * root ) { if ( root == NULL ) return ; map [ root -> key ] ++ ; frequencyCounts ( map , root -> left ) ; frequencyCounts ( map , root -> right ) ; } int computeDistance ( Node * root , int value ) { if ( root == NULL ) { return -1 ; } int left = computeDistance ( root -> left , value ) ; int right = computeDistance ( root -> right , value ) ; if ( left == -1 && right == -1 ) { if ( root -> key == value ) { return 1 ; } else return -1 ; } if ( left == -1 ) { return right + 1 ; } if ( right == -1 ) { return left + 1 ; } else { return 1 + max ( left , right ) ; } return -1 ; } void solve ( Node * root , int dist ) { unordered_map < int , int > map ; frequencyCounts ( map , root ) ; int flag = 0 ; for ( auto it = map . begin ( ) ; it != map . end ( ) ; it ++ ) { if ( it -> second > 1 ) { int result = computeDistance ( root , it -> first ) ; if ( result > dist result == -1 ) { flag = 1 ; break ; } } } flag == 0 ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 3 ) ; root -> right -> right = newNode ( 4 ) ; root -> right -> left = newNode ( 4 ) ; int dist = 7 ; solve ( root , dist ) ; return 0 ; }

Accumulator variables: it, stdc
Iterator variables: it
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMinSum ( int A [ ] , int K , int n ) { int minimum_sum = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { int mini = INT_MAX ; for ( int j = i + K ; j < n ; j ++ ) mini = min ( mini , A [ j ] ) ; if ( mini == INT_MAX ) continue ; minimum_sum = min ( minimum_sum , A [ i ] + mini ) ; } cout << ( minimum_sum ) ; } int main ( ) { int A [ ] = { 4 , 2 , 5 , 4 , 3 , 2 , 5 } ; int K = 3 ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; findMinSum ( A , K , 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 ; struct Node { int data ; Node * next ; } ; void push ( Node * * head_ref , int new_data ) { Node * new_node = new Node ( ) ; new_node -> data = new_data ; new_node -> next = ( * head_ref ) ; ( * head_ref ) = new_node ; } int distinctCount ( Node * head_1 ) { Node * ptr = head_1 ; unordered_set < int > s ; while ( ptr != NULL ) { s . insert ( abs ( ptr -> data ) ) ; ptr = ptr -> next ; } return s . size ( ) ; } int main ( ) { Node * head1 = NULL ; push ( & head1 , -1 ) ; push ( & head1 , -2 ) ; push ( & head1 , 0 ) ; push ( & head1 , 4 ) ; push ( & head1 , 5 ) ; push ( & head1 , 8 ) ; int k = distinctCount ( head1 ) ; cout << k ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int lcm ( int a , int b ) { return ( a * b ) / __gcd ( a , b ) ; } int countPair ( int N ) { int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { if ( __gcd ( i , j ) + lcm ( i , j ) == N ) { count ++ ; } } } return count ; } int main ( ) { int N = 14 ; cout << countPair ( N ) ; return 0 ; }

Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  10
vector < int > adj [ MAX ] ; void addEdge ( int u , int v ) { adj [ u ] . push_back ( v ) ; adj [ v ] . push_back ( u ) ; } void dfs ( int v , int cost [ ] , bool vis [ ] , int & min_cost_node ) { vis [ v ] = true ; min_cost_node = min ( min_cost_node , cost [ v - 1 ] ) ; for ( int i = 0 ; i < adj [ v ] . size ( ) ; i ++ ) { if ( vis [ adj [ v ] [ i ] ] == false ) { dfs ( adj [ v ] [ i ] , cost , vis , min_cost_node ) ; } } } int minimumCost ( int V , int cost [ ] ) { bool vis [ V + 1 ] ; memset ( vis , false , sizeof ( vis ) ) ; int min_cost = 0 ; for ( int i = 1 ; i <= V ; i ++ ) { if ( ! vis [ i ] ) { int min_cost_node = INT_MAX ; dfs ( i , cost , vis , min_cost_node ) ; min_cost += min_cost_node ; } } return min_cost ; } int main ( ) { int V = 6 , E = 5 ; int cost [ ] = { 12 , 25 , 8 , 11 , 10 , 7 } ; addEdge ( 1 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 3 , 2 ) ; addEdge ( 2 , 5 ) ; addEdge ( 4 , 6 ) ; int min_cost = minimumCost ( V , cost ) ; cout << min_cost << endl ; return 0 ; }

Index/key variables: MAX, i, u, v
Accumulator variables: i, min_cost, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxm = 0 ; struct Node { int val ; Node * left , * right ; Node ( int x ) { val = x ; left = NULL ; right = NULL ; } } ; void maxm_setbits ( Node * root , int ans ) { if ( ! root ) return ; if ( root -> left == NULL && root -> right == NULL ) { ans += __builtin_popcount ( root -> val ) ; maxm = max ( ans , maxm ) ; return ; } maxm_setbits ( root -> left , ans + __builtin_popcount ( root -> val ) ) ; maxm_setbits ( root -> right , ans + __builtin_popcount ( root -> val ) ) ; } int main ( ) { Node * root = new Node ( 15 ) ; root -> left = new Node ( 3 ) ; root -> right = new Node ( 7 ) ; root -> left -> left = new Node ( 5 ) ; root -> left -> right = new Node ( 1 ) ; root -> right -> left = new Node ( 31 ) ; root -> right -> right = new Node ( 9 ) ; maxm_setbits ( root , 0 ) ; cout << maxm << endl ; return 0 ; }

Accumulator variables: ans, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getMinimumMoves ( int n , int k , int d , vector < int > a ) { int MAX = 100000 ; vector < int > v [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { int cnt = 0 ; v [ a [ i ] ] . push_back ( 0 ) ; while ( a [ i ] > 0 ) { a [ i ] /= d ; cnt ++ ; v [ a [ i ] ] . push_back ( cnt ) ; } } int ans = INT_MAX ; for ( int i = 0 ; i < MAX ; i ++ ) { if ( v [ i ] . size ( ) >= k ) { int move = 0 ; sort ( v [ i ] . begin ( ) , v [ i ] . end ( ) ) ; for ( int j = 0 ; j < k ; j ++ ) { move += v [ i ] [ j ] ; } ans = min ( ans , move ) ; } } return ans ; } int main ( ) { int N = 5 , K = 3 , D = 2 ; vector < int > A = { 1 , 2 , 3 , 4 , 5 } ; cout << getMinimumMoves ( N , K , D , A ) ; return 0 ; }

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

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > get_submaxarr ( int * arr , int n , int y ) { int j = 0 ; stack < int > stk ; vector < int > maxarr ( n ) ; stk . push ( 0 ) ; for ( int i = 1 ; i < n ; i ++ ) { while ( stk . empty ( ) == false and arr [ i ] > arr [ stk . top ( ) ] ) { maxarr [ stk . top ( ) ] = i - 1 ; stk . pop ( ) ; } stk . push ( i ) ; } while ( ! stk . empty ( ) ) { maxarr [ stk . top ( ) ] = n - 1 ; stk . pop ( ) ; } vector < int > submax ; for ( int i = 0 ; i <= n - y ; i ++ ) { while ( maxarr [ j ] < i + y - 1 or j < i ) { j ++ ; } submax . push_back ( arr [ j ] ) ; } return submax ; } vector < int > get_subminarr ( int * arr , int n , int y ) { int j = 0 ; stack < int > stk ; vector < int > minarr ( n ) ; stk . push ( 0 ) ; for ( int i = 1 ; i < n ; i ++ ) { while ( stk . empty ( ) == false and arr [ i ] < arr [ stk . top ( ) ] ) { minarr [ stk . top ( ) ] = i ; stk . pop ( ) ; } stk . push ( i ) ; } while ( ! stk . empty ( ) ) { minarr [ stk . top ( ) ] = n ; stk . pop ( ) ; } vector < int > submin ; for ( int i = 0 ; i <= n - y ; i ++ ) { while ( minarr [ j ] <= i + y - 1 or j < i ) { j ++ ; } submin . push_back ( arr [ j ] ) ; } return submin ; } void getMinDifference ( int Arr [ ] , int N , int Y ) { vector < int > submin = get_subminarr ( Arr , N , Y ) ; vector < int > submax = get_submaxarr ( Arr , N , Y ) ; int minn = submax [ 0 ] - submin [ 0 ] ; int b = submax . size ( ) ; for ( int i = 1 ; i < b ; i ++ ) { int dif = submax [ i ] - submin [ i ] ; minn = min ( minn , dif ) ; } cout << minn << " STRNEWLINE " ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 3 , 2 , 2 } ; int N = sizeof arr / sizeof arr [ 0 ] ; int Y = 4 ; getMinDifference ( arr , N , Y ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int func ( int A , int B , int C , int x ) { return ( A * x * x + B * x + C ) ; } int findMinx ( int A , int B , int C , int K ) { int start = 1 ; int end = ceil ( sqrt ( K ) ) ; while ( start <= end ) { int mid = start + ( end - start ) / 2 ; int x = func ( A , B , C , mid ) ; int Y = func ( A , B , C , mid - 1 ) ; if ( x >= K && Y < K ) { return mid ; } else if ( x < K ) { start = mid + 1 ; } else { end = mid - 1 ; } } return -1 ; } int main ( ) { int A = 3 , B = 4 , C = 5 , K = 6 ; cout << findMinx ( A , B , C , K ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; map < int , vector < int > > tree ; bool getDiameterPath ( int vertex , int targetVertex , int parent , vector < int > & path ) { if ( vertex == targetVertex ) { path . push_back ( vertex ) ; return true ; } for ( auto i : tree [ vertex ] ) { if ( i == parent ) continue ; if ( getDiameterPath ( i , targetVertex , vertex , path ) ) { path . push_back ( vertex ) ; return true ; } } return false ; } void farthestNode ( int vertex , int parent , int height , int & maxHeight , int & maxHeightNode ) { if ( height > maxHeight ) { maxHeight = height ; maxHeightNode = vertex ; } for ( auto i : tree [ vertex ] ) { if ( i == parent ) continue ; farthestNode ( i , vertex , height + 1 , maxHeight , maxHeightNode ) ; } } void addedge ( int a , int b ) { tree [ a ] . push_back ( b ) ; tree [ b ] . push_back ( a ) ; } void FindCenter ( int n ) { int maxHeight = -1 ; int maxHeightNode = -1 ; farthestNode ( 0 , -1 , 0 , maxHeight , maxHeightNode ) ; int leaf1 = maxHeightNode ; maxHeight = -1 ; farthestNode ( maxHeightNode , -1 , 0 , maxHeight , maxHeightNode ) ; int leaf2 = maxHeightNode ; vector < int > path ; getDiameterPath ( leaf1 , leaf2 , -1 , path ) ; int pathSize = path . size ( ) ; if ( pathSize % 2 ) { cout << path [ pathSize / 2 ] << endl ; } else { cout << path [ pathSize / 2 ] << " , ▁ " << path [ ( pathSize - 1 ) / 2 ] << endl ; } } int main ( ) { int N = 4 ; addedge ( 1 , 0 ) ; addedge ( 1 , 2 ) ; addedge ( 1 , 3 ) ; FindCenter ( N ) ; return 0 ; }

Index/key variables: a, b, vertex
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define maxm  1000000000
int count ( vector < int > v , int n ) { int i , odd = 0 , even = 0 ; int j , d , count ; int t = ( int ) 1 << v . size ( ) ; int size = v . size ( ) ; for ( i = 1 ; i < t ; i ++ ) { d = 1 , count = 0 ; for ( j = 0 ; j < size ; j ++ ) { if ( i & ( 1 << j ) ) { d *= v [ j ] ; count ++ ; } } if ( count & 1 ) odd += n / d ; else even += n / d ; } return ( odd - even ) ; } int BinarySearch ( int l , int r , vector < int > v , int key ) { int mid ; while ( r - l > 1 ) { mid = ( l + r ) / 2 ; if ( key <= count ( v , mid ) ) { r = mid ; } else { l = mid ; } } if ( key == count ( v , l ) ) return l ; else return r ; } int main ( ) { int N = 2 , K = 10 ; vector < int > v = { 2 , 3 } ; cout << BinarySearch ( 1 , maxm , v , K ) << endl ; return 0 ; }

Index/key variables: j
Accumulator variables: count, d, even, i, j, odd, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minDistancePoints ( int A [ ] , int K , int n ) { map < int , int > m ; queue < int > q ; for ( int i = 0 ; i < n ; ++ i ) { m [ A [ i ] ] = 1 ; q . push ( A [ i ] ) ; } vector < int > ans ; while ( K > 0 ) { int x = q . front ( ) ; q . pop ( ) ; if ( ! m [ x - 1 ] && K > 0 ) { m [ x - 1 ] = 1 ; q . push ( x - 1 ) ; ans . push_back ( x - 1 ) ; K -- ; } if ( ! m [ x + 1 ] && K > 0 ) { m [ x + 1 ] = 1 ; q . push ( x + 1 ) ; ans . push_back ( x + 1 ) ; K -- ; } } for ( auto i : ans ) cout << i << " ▁ " ; } int main ( ) { int A [ ] = { -1 , 4 , 6 } ; int K = 3 ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; minDistancePoints ( A , K , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: K, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define N  3
using namespace std ; int search ( int mat [ ] [ 3 ] , int n , int m ) { int i , a = INT_MAX ; for ( i = 0 ; i < n ; i ++ ) { int low = 0 ; int high = m - 1 ; int mid ; int ans = INT_MAX ; while ( low <= high ) { mid = ( low + high ) / 2 ; if ( mat [ i ] [ mid ] == 1 ) { if ( mid == 0 ) { ans = 0 ; break ; } else if ( mat [ i ] [ mid - 1 ] == 0 ) { ans = mid ; break ; } } if ( mat [ i ] [ mid ] == 1 ) high = mid - 1 ; else low = mid + 1 ; } if ( ans < a ) a = ans ; } if ( a == INT_MAX ) return -1 ; return a + 1 ; } int main ( ) { int mat [ 3 ] [ 3 ] = { 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 1 } ; cout << search ( mat , 3 , 3 ) ; return 0 ; }

Index/key variables: i, mid
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxSubstring ( string & S , int K , int N ) { int freq [ 26 ] ; memset ( freq , 0 , sizeof freq ) ; for ( int i = 0 ; i < N ; ++ i ) { freq [ S [ i ] - ' a ' ] = 1 ; } vector < pair < char , int > > answer ; for ( int i = 0 ; i < 26 ; ++ i ) { if ( freq [ i ] == 0 ) continue ; char ch = i + 97 ; int count = 0 ; int index = -1 ; for ( int j = 0 ; j < N ; ++ j ) { if ( S [ j ] == ch ) count ++ ; if ( count == K ) index = j ; } answer . push_back ( { ch , index } ) ; } int flag = 0 ; for ( int i = 0 ; i < ( int ) answer . size ( ) ; ++ i ) { if ( answer [ i ] . second > -1 ) { flag = 1 ; cout << answer [ i ] . first << " ▁ " << answer [ i ] . second << endl ; } } if ( flag == 0 ) cout << " - 1" << endl ; } int main ( ) { string S = " cbaabaacbcd " ; int K = 2 ; int N = S . length ( ) ; maxSubstring ( S , K , N ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; typedef long long ll ; #define pb  push_back
void greaterK ( ll n , ll k ) { vector < ll > p ; ll x = n ; while ( x ) { p . pb ( x % k ) ; x /= k ; } int idx = 0 ; for ( ll i = 0 ; i < ( ll ) p . size ( ) - 1 ; ++ i ) { if ( p [ i ] >= 2 ) { p [ i ] = 0 ; p [ i + 1 ] ++ ; for ( int j = idx ; j < i ; ++ j ) { p [ j ] = 0 ; } idx = i + 1 ; } if ( p [ i ] == k ) { p [ i ] = 0 ; p [ i + 1 ] ++ ; } } ll j = ( ll ) p . size ( ) - 1 ; if ( p [ j ] >= 2 ) { for ( auto & i : p ) i = 0 ; p . pb ( 1 ) ; } ll ans = 0 ; for ( ll i = p . size ( ) - 1 ; i >= 0 ; -- i ) { ans = ans * k + p [ i ] ; } cout << ans << endl ; } int main ( ) { ll n = 29 , k = 7 ; greaterK ( n , k ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: stdc, x
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool canBeBalanced ( string s , int n ) { int count = 0 , count_1 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ( ' ) count ++ ; else count -- ; count_1 = min ( count_1 , count ) ; } if ( count_1 >= -1 && count == 0 ) return true ; return false ; } int main ( ) { string s = " ( ) ) ( ) ( " ; int n = s . length ( ) ; if ( canBeBalanced ( s , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculateDifference ( int arr [ ] , int n ) { int max_val = * max_element ( arr , arr + n ) ; vector < bool > prime ( max_val + 1 , true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } int X1 = 1 , X2 = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) { X1 ^= arr [ i ] ; } else if ( arr [ i ] != 1 ) { X2 ^= arr [ i ] ; } } return abs ( X1 - X2 ) ; } int main ( ) { int arr [ ] = { 1 , 3 , 5 , 10 , 15 , 7 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << calculateDifference ( arr , n ) ; return 0 ; }

Index/key variables: i, p
Accumulator variables: X1, X2, i, p, stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define CHILDREN  26
#define MAX  100
struct trie { trie * child [ CHILDREN ] ; bool endOfWord ; } ; trie * createNode ( ) { trie * temp = new trie ( ) ; temp -> endOfWord = false ; for ( int i = 0 ; i < CHILDREN ; i ++ ) { temp -> child [ i ] = NULL ; } return temp ; } void insertRecursively ( trie * itr , string str , int i ) { if ( i < str . length ( ) ) { int index = str [ i ] - ' a ' ; if ( itr -> child [ index ] == NULL ) { itr -> child [ index ] = createNode ( ) ; } insertRecursively ( itr -> child [ index ] , str , i + 1 ) ; } else { itr -> endOfWord = true ; } } void insert ( trie * itr , string str ) { insertRecursively ( itr , str , 0 ) ; } bool searchRecursively ( trie * itr , char str [ ] , int i , int len ) { if ( itr == NULL ) return false ; if ( itr -> endOfWord == true && i == len - 1 ) { return true ; } int index = str [ i ] - ' a ' ; return searchRecursively ( itr -> child [ index ] , str , i + 1 , len ) ; } void search ( trie * root , string str ) { char arr [ str . length ( ) + 1 ] ; strcpy ( arr , str . c_str ( ) ) ; if ( searchRecursively ( root , arr , 0 , str . length ( ) + 1 ) ) cout << " found " << endl ; else { cout << " not ▁ found " << endl ; } } int main ( ) { trie * root = createNode ( ) ; insert ( root , " thier " ) ; insert ( root , " there " ) ; insert ( root , " answer " ) ; insert ( root , " any " ) ; search ( root , " anywhere " ) ; search ( root , " answer " ) ; return 0 ; }

Index/key variables: CHILDREN, i, index
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: endOfWord
Class/struct names: trie
C++ program:
#include <iostream>
#include <unordered_set>
using namespace std ; struct Node { int data ; Node * next ; } ; void insert ( Node * * head , int item ) { Node * temp = new Node ( ) ; temp -> data = item ; temp -> next = * head ; * head = temp ; } int countNode ( Node * head ) { int count = 0 ; while ( head -> next != NULL ) { Node * ptr = head -> next ; while ( ptr != NULL ) { if ( head -> data == ptr -> data ) { count ++ ; break ; } ptr = ptr -> next ; } head = head -> next ; } return count ; } int main ( ) { Node * head = NULL ; insert ( & head , 5 ) ; insert ( & head , 7 ) ; insert ( & head , 5 ) ; insert ( & head , 1 ) ; insert ( & head , 7 ) ; cout << countNode ( head ) ; return 0 ; }

Accumulator variables: count
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPossible ( string A , string B , int b , int m ) { vector < int > S [ 26 ] ; vector < int > box ( A . length ( ) , 0 ) ; for ( int i = 0 ; i < A . length ( ) ; i ++ ) { S [ A [ i ] - ' a ' ] . push_back ( i ) ; } int low = 0 ; for ( int i = 0 ; i < B . length ( ) ; i ++ ) { auto it = lower_bound ( S [ B [ i ] - ' a ' ] . begin ( ) , S [ B [ i ] - ' a ' ] . end ( ) , low ) ; if ( it == S [ B [ i ] - ' a ' ] . end ( ) ) return false ; int count = ( * it ) / b ; box [ count ] = box [ count ] + 1 ; if ( box [ count ] >= m ) { count ++ ; low = ( count ) * b ; } else low = ( * it ) + 1 ; } return true ; } int main ( ) { string A = " abcbbcdefxyz " ; string B = " acdxyz " ; int b = 5 ; int m = 2 ; if ( isPossible ( A , B , b , m ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: count, i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSumArray ( int arr [ ] , int n ) { int sum = 0 ; unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; mp [ arr [ i ] ] ++ ; } int minimum = INT_MAX ; for ( auto x : mp ) minimum = min ( minimum , x . second * x . first ) ; return ( sum - minimum ) ; } int main ( ) { int arr [ ] = { 1 , 1 , 3 , 3 , 2 , 2 , 1 , 1 , 1 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << maxSumArray ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  1001
static int prefix [ MAX ] [ MAX ] ; int ar [ MAX ] ; void cal_prefix ( int n , int arr [ ] ) { int i , j ; for ( i = 0 ; i < n ; i ++ ) ar [ i + 1 ] = arr [ i ] ; for ( i = 1 ; i <= 1000 ; i ++ ) { for ( j = 0 ; j <= n ; j ++ ) prefix [ i ] [ j ] = 0 ; for ( j = 1 ; j <= n ; j ++ ) { prefix [ i ] [ j ] = prefix [ i ] [ j - 1 ] + ( int ) ( ar [ j ] <= i ? 1 : 0 ) ; } } } int ksub ( int l , int r , int n , int k ) { int lo , hi , mid ; lo = 1 ; hi = 1000 ; while ( lo + 1 < hi ) { mid = ( lo + hi ) / 2 ; if ( prefix [ mid ] [ r ] - prefix [ mid ] [ l - 1 ] >= k ) hi = mid ; else lo = mid + 1 ; } if ( prefix [ lo ] [ r ] - prefix [ lo ] [ l - 1 ] >= k ) hi = lo ; return hi ; } int main ( ) { int arr [ ] = { 1 , 4 , 2 , 3 , 5 , 7 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 4 ; cal_prefix ( n , arr ) ; int queries [ ] [ 3 ] = { { 1 , n , 1 } , { 2 , n - 2 , 2 } , { 3 , n - 1 , 3 } } ; int q = sizeof ( queries ) / sizeof ( queries [ 0 ] ) ; for ( int i = 0 ; i < q ; i ++ ) cout << ksub ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , n , queries [ i ] [ 2 ] ) << endl ; return 0 ; }

Index/key variables: MAX, i, j, lo, mid, r
Accumulator variables: i, j, stdc
Iterator variables: i, j