dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int solution ( vector < int > & arr , int x ) { sort ( arr . begin ( ) , arr . end ( ) ) ; int closestSum = 1000000000 ; for ( int i = 0 ; i < arr . size ( ) - 2 ; i ++ ) { int ptr1 = i + 1 , ptr2 = arr . size ( ) - 1 ; while ( ptr1 < ptr2 ) { int sum = arr [ i ] + arr [ ptr1 ] + arr [ ptr2 ] ; if ( abs ( 1LL * x - sum ) < abs ( 1LL * x - closestSum ) ) { closestSum = sum ; } if ( sum > x ) { ptr2 -- ; } else { ptr1 ++ ; } } } return closestSum ; } int main ( ) { vector < int > arr = { -1 , 2 , 1 , -4 } ; int x = 1 ; cout << solution ( arr , x ) ; return 0 ; }

Index/key variables: i, ptr1, ptr2
Accumulator variables: i, ptr1, ptr2, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; class Node { public : int data ; Node * left ; Node * right ; Node ( int x ) { data = x ; left = right = NULL ; } } ; void inorder ( Node * root ) { if ( root != NULL ) { inorder ( root -> left ) ; cout << root -> data << " ▁ " ; inorder ( root -> right ) ; } } void merge ( Node * root1 , Node * root2 ) { if ( ! root1 && ! root2 ) return ; if ( ! root1 ) { inorder ( root2 ) ; return ; } if ( ! root2 ) { inorder ( root1 ) ; return ; } Node * temp1 = root1 ; Node * prev1 = NULL ; while ( temp1 -> left ) { prev1 = temp1 ; temp1 = temp1 -> left ; } Node * temp2 = root2 ; Node * prev2 = NULL ; while ( temp2 -> left ) { prev2 = temp2 ; temp2 = temp2 -> left ; } if ( temp1 -> data <= temp2 -> data ) { cout << temp1 -> data << " ▁ " ; if ( prev1 == NULL ) { merge ( root1 -> right , root2 ) ; } else { prev1 -> left = temp1 -> right ; merge ( root1 , root2 ) ; } } else { cout << temp2 -> data << " ▁ " ; if ( prev2 == NULL ) { merge ( root1 , root2 -> right ) ; } else { prev2 -> left = temp2 -> right ; merge ( root1 , root2 ) ; } } } int main ( ) { Node * root1 = NULL , * root2 = NULL ; root1 = new Node ( 3 ) ; root1 -> left = new Node ( 1 ) ; root1 -> right = new Node ( 5 ) ; root2 = new Node ( 4 ) ; root2 -> left = new Node ( 2 ) ; root2 -> right = new Node ( 6 ) ; merge ( root1 , root2 ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void print_in_order ( int a1 [ ] , int a2 [ ] , int n , int m ) { map < int , int > mp ; map < int , int > :: iterator itr ; for ( int i = 0 ; i < n ; i ++ ) mp [ a1 [ i ] ] ++ ; for ( int i = 0 ; i < m ; i ++ ) { if ( mp . find ( a2 [ i ] ) != mp . end ( ) ) { itr = mp . find ( a2 [ i ] ) ; for ( int j = 0 ; j < itr -> second ; j ++ ) cout << itr -> first << " ▁ " ; mp . erase ( a2 [ i ] ) ; } } for ( itr = mp . begin ( ) ; itr != mp . end ( ) ; itr ++ ) { for ( int j = 0 ; j < itr -> second ; j ++ ) cout << itr -> first << " ▁ " ; } cout << endl ; } int main ( ) { int a1 [ ] = { 2 , 1 , 2 , 5 , 7 , 1 , 9 , 3 , 6 , 8 , 8 } ; int a2 [ ] = { 2 , 1 , 8 , 3 } ; int n = sizeof ( a1 ) / sizeof ( a1 [ 0 ] ) ; int m = sizeof ( a2 ) / sizeof ( a2 [ 0 ] ) ; print_in_order ( a1 , a2 , n , m ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, itr, j, stdc
Iterator variables: i, itr, j
C++ program:
#include <iostream>
using namespace std ; bool IsSorted ( int A [ ] , int B [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { int x , y ; x = max ( A [ i ] , B [ i ] ) ; y = min ( A [ i ] , B [ i ] ) ; A [ i ] = x ; B [ i ] = y ; } for ( int i = 1 ; i < n ; i ++ ) { if ( A [ i ] <= A [ i - 1 ] B [ i ] <= B [ i - 1 ] ) return false ; } return true ; } int main ( ) { int A [ ] = { 1 , 4 , 3 , 5 , 7 } ; int B [ ] = { 2 , 2 , 5 , 8 , 9 } ; int n = sizeof ( A ) / sizeof ( int ) ; cout << ( IsSorted ( A , B , n ) ? " True " : " False " ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void K_multiple ( int a [ ] , int n , int k ) { sort ( a , a + n ) ; set < int > s ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( a [ i ] % k == 0 && s . find ( a [ i ] / k ) == s . end ( ) ) a [ i ] % k != 0 ) s . insert ( a [ i ] ) ; } for ( auto i = s . begin ( ) ; i != s . end ( ) ; i ++ ) { cout << * i << " ▁ " ; } } int main ( ) { int a [ ] = { 2 , 3 , 4 , 5 , 6 , 10 } ; int k = 2 ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; K_multiple ( a , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxWater ( int height [ ] , int n ) { int maximum = 0 ; int i = 0 , j = n - 1 ; while ( i < j ) { if ( height [ i ] < height [ j ] ) { maximum = max ( maximum , ( j - i - 1 ) * height [ i ] ) ; i ++ ; } else if ( height [ j ] < height [ i ] ) { maximum = max ( maximum , ( j - i - 1 ) * height [ j ] ) ; j -- ; } else { maximum = max ( maximum , ( j - i - 1 ) * height [ i ] ) ; i ++ ; j -- ; } } return maximum ; } int main ( ) { int height [ ] = { 2 , 1 , 3 , 4 , 6 , 5 } ; int n = sizeof ( height ) / sizeof ( height [ 0 ] ) ; cout << ( maxWater ( height , n ) ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSelectionCount ( int a [ ] , int n ) { int res = 0 ; sort ( a , a + n ) ; int select = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= select ) { res ++ ; select ++ ; } } return res ; } int main ( ) { int arr [ ] = { 4 , 2 , 1 , 3 , 5 , 1 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxSelectionCount ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, res, select, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findCombinationsUtil ( int arr [ ] , int index , int n , int red_num ) { set < int > s ; int sum = 0 ; if ( red_num < 0 ) { return ; } if ( red_num == 0 ) { for ( int i = 0 ; i < index ; i ++ ) { s . insert ( arr [ i ] ) ; } for ( auto itr = s . begin ( ) ; itr != s . end ( ) ; itr ++ ) { sum = sum + ( * itr ) ; } if ( sum == n ) { for ( auto i = s . begin ( ) ; i != s . end ( ) ; i ++ ) { cout << * i << " ▁ " ; } cout << endl ; return ; } } int prev = ( index == 0 ) ? 1 : arr [ index - 1 ] ; for ( int k = prev ; k <= n ; k ++ ) { arr [ index ] = k ; findCombinationsUtil ( arr , index + 1 , n , red_num - k ) ; } } void findCombinations ( int n ) { int a [ n ] ; findCombinationsUtil ( a , 0 , n , n ) ; } int main ( ) { int n = 7 ; findCombinations ( n ) ; return 0 ; }

Index/key variables: i, index, n
Accumulator variables: i, itr, k, stdc
Iterator variables: i, itr, k
C++ program:
#include <iostream>
using namespace std ; bool check ( int arr [ ] , int n ) { int modify = 0 ; if ( arr [ 0 ] > arr [ 1 ] ) { arr [ 0 ] = arr [ 1 ] / 2 ; modify ++ ; } for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( ( arr [ i - 1 ] < arr [ i ] && arr [ i + 1 ] < arr [ i ] ) || ( arr [ i - 1 ] > arr [ i ] && arr [ i + 1 ] > arr [ i ] ) ) { arr [ i ] = ( arr [ i - 1 ] + arr [ i + 1 ] ) / 2 ; if ( arr [ i ] == arr [ i - 1 ] arr [ i ] == arr [ i + 1 ] ) return false ; modify ++ ; } } if ( arr [ n - 1 ] < arr [ n - 2 ] ) modify ++ ; if ( modify > 1 ) return false ; return true ; } int main ( ) { int arr [ ] = { 2 , 4 , 8 , 6 , 9 , 12 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( check ( arr , n ) ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, modify
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  2
#define M  2
bool isMatrixInc ( int a [ N ] [ M ] ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( i - 1 >= 0 ) { if ( a [ i ] [ j ] <= a [ i - 1 ] [ j ] ) return false ; } if ( j - 1 >= 0 ) { if ( a [ i ] [ j ] <= a [ i ] [ j - 1 ] ) return false ; } } } return true ; } int main ( ) { int a [ N ] [ M ] = { { 2 , 10 } , { 11 , 20 } } ; if ( isMatrixInc ( a ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: M, N, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int N = 1e7 + 5 ; bool prime [ N ] ; void seive ( ) { for ( int i = 2 ; i < N ; i ++ ) { if ( ! prime [ i ] ) { for ( int j = i + i ; j < N ; j += i ) { prime [ j ] = 1 ; } } } prime [ 1 ] = 1 ; } int maxSizeArr ( int * arr , int n , int k ) { vector < int > v , diff ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) v . push_back ( i ) ; } for ( int i = 1 ; i < v . size ( ) ; i ++ ) { diff . push_back ( v [ i ] - v [ i - 1 ] - 1 ) ; } sort ( diff . begin ( ) , diff . end ( ) ) ; for ( int i = 1 ; i < diff . size ( ) ; i ++ ) { diff [ i ] += diff [ i - 1 ] ; } if ( k > n || ( k == 0 && v . size ( ) ) ) { return -1 ; } else if ( v . size ( ) <= k ) { return ( n - k ) ; } else if ( v . size ( ) > k ) { int tt = v . size ( ) - k ; int sum = 0 ; sum += diff [ tt - 1 ] ; int res = n - ( v . size ( ) + sum ) ; return res ; } } int main ( ) { seive ( ) ; int arr [ ] = { 2 , 4 , 2 , 2 , 4 , 2 , 4 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; cout << maxSizeArr ( arr , n , k ) ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortArr ( int arr [ ] , int n ) { multimap < int , int > map ; for ( int i = 0 ; i < n ; i ++ ) { int count = 0 ; int k = arr [ i ] ; while ( k ) { k = k & k - 1 ; count ++ ; } map . insert ( make_pair ( 32 - count , arr [ i ] ) ) ; } for ( auto it = map . begin ( ) ; it != map . end ( ) ; it ++ ) { cout << ( * it ) . second << " ▁ " ; } } int main ( ) { int arr [ ] = { 5 , 2 , 3 , 9 , 4 , 6 , 7 , 15 , 32 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortArr ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, it, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSmallestNumber ( vector < int > & arr , int n ) { vector < int > dp ( n , numeric_limits < int > :: max ( ) - 5 ) ; vector < pair < int , int > > result ( n , make_pair ( -1 , 0 ) ) ; sort ( arr . begin ( ) , arr . end ( ) ) ; queue < int > q ; for ( auto i : arr ) { if ( i != 0 ) { if ( dp [ i % n ] > 1e9 ) { q . push ( i % n ) ; dp [ i % n ] = 1 ; result [ i % n ] = { -1 , i } ; } } } while ( ! q . empty ( ) ) { int u = q . front ( ) ; q . pop ( ) ; for ( auto i : arr ) { int v = ( u * 10 + i ) % n ; if ( dp [ u ] + 1 < dp [ v ] ) { dp [ v ] = dp [ u ] + 1 ; q . push ( v ) ; result [ v ] = { u , i } ; } } } if ( dp [ 0 ] > 1e9 ) return -1 ; else { vector < int > ans ; int u = 0 ; while ( u != -1 ) { ans . push_back ( result [ u ] . second ) ; u = result [ u ] . first ; } reverse ( ans . begin ( ) , ans . end ( ) ) ; for ( auto i : ans ) { return i ; } } } int main ( ) { vector < int > arr = { 5 , 2 , 3 } ; int n = 12 ; cout << findSmallestNumber ( arr , n ) ; return 0 ; }

Index/key variables: u, v
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <algorithm>
#include <iostream>
using namespace std ; long long mod = 1000000007 ; int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } int nCr ( int n , int r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } long long powmod ( long long a , long long n ) { if ( ! n ) return 1 ; long long pt = powmod ( a , n / 2 ) ; pt = ( pt * pt ) % mod ; if ( n % 2 ) return ( pt * a ) % mod ; else return pt ; } long long CountSubset ( int * arr , int n ) { long long ans = powmod ( 2 , n - 1 ) ; sort ( arr , arr + n ) ; for ( int i = 0 ; i < n ; ++ i ) { int j = i + 1 ; while ( j < n && arr [ j ] == arr [ i ] ) { int r = n - 1 - j ; int l = i ; ans = ( ans + nCr ( l + r , l ) ) % mod ; j ++ ; } } return ans ; } int main ( ) { int arr [ ] = { 2 , 3 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << CountSubset ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
C++ program:
#include <algorithm>
#include <iostream>
using namespace std ; long long mod = 1000000007 ; long long arr [ 1001 ] [ 1001 ] ; void Preprocess ( ) { arr [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= 1000 ; ++ i ) { arr [ i ] [ 0 ] = 1 ; for ( int j = 1 ; j < i ; ++ j ) { arr [ i ] [ j ] = ( arr [ i - 1 ] [ j - 1 ] + arr [ i - 1 ] [ j ] ) % mod ; } arr [ i ] [ i ] = 1 ; } } long long powmod ( long long a , long long n ) { if ( ! n ) return 1 ; long long pt = powmod ( a , n / 2 ) ; pt = ( pt * pt ) % mod ; if ( n % 2 ) return ( pt * a ) % mod ; else return pt ; } long long CountSubset ( int * val , int n ) { long long ans = powmod ( 2 , n - 1 ) ; sort ( val , val + n ) ; for ( int i = 0 ; i < n ; ++ i ) { int j = i + 1 ; while ( j < n && val [ j ] == val [ i ] ) { int r = n - 1 - j ; int l = i ; ans = ( ans + arr [ l + r ] [ l ] ) % mod ; j ++ ; } } return ans ; } int main ( ) { Preprocess ( ) ; int val [ ] = { 2 , 3 , 2 } ; int n = sizeof ( val ) / sizeof ( val [ 0 ] ) ; cout << CountSubset ( val , n ) << endl ; return 0 ; }

Index/key variables: i, j, l
Accumulator variables: j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void reArrange ( string words [ ] , int n ) { map < string , int > mp ; for ( int i = 0 ; i < n ; i ++ ) mp [ words [ i ] ] = i + 1 ; sort ( words , words + n ) ; for ( int i = 0 ; i < n ; i ++ ) cout << mp [ words [ i ] ] << " ▁ " ; } int main ( ) { string words [ ] = { " live " , " place " , " travel " , " word " , " sky " } ; int n = sizeof ( words ) / sizeof ( words [ 0 ] ) ; reArrange ( words , n ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; #define MAX  100000
int findSumofEle ( int arr1 [ ] , int m , int arr2 [ ] , int n ) { int hash [ MAX ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) hash [ arr2 [ i ] ] ++ ; for ( int i = 1 ; i < MAX ; i ++ ) hash [ i ] = hash [ i ] + hash [ i - 1 ] ; int maximumFreq = 0 ; for ( int i = 0 ; i < m ; i ++ ) maximumFreq = max ( maximumFreq , hash [ arr1 [ i ] ] ) ; int sumOfElements = 0 ; for ( int i = 0 ; i < m ; i ++ ) sumOfElements += ( maximumFreq == hash [ arr1 [ i ] ] ) ? arr1 [ i ] : 0 ; return sumOfElements ; } int main ( ) { int arr1 [ ] = { 2 , 5 , 6 , 8 } ; int arr2 [ ] = { 4 , 10 } ; int m = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; int n = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; cout << findSumofEle ( arr1 , m , arr2 , n ) ; return 0 ; }

Index/key variables: MAX, i
Accumulator variables: i, sumOfElements
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void Print ( int x [ ] , int y [ ] , int n ) { map < pair < int , int > , int > m ; for ( int i = 0 ; i < n ; i ++ ) m [ make_pair ( x [ i ] , y [ i ] ) ] ++ ; map < pair < int , int > , int > :: iterator i ; for ( i = m . begin ( ) ; i != m . end ( ) ; i ++ ) { cout << ( i -> first ) . first << " ▁ " << ( i -> first ) . second << " ▁ " << i -> second << " STRNEWLINE " ; } } int main ( ) { int x [ ] = { 1 , 2 , 1 , 1 , 1 } ; int y [ ] = { 1 , 1 , 3 , 1 , 3 } ; int n = sizeof ( x ) / sizeof ( int ) ; Print ( x , y , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void PrintBothArrays ( int a [ ] , int n ) { vector < int > v1 , v2 ; unordered_map < int , int > mpp ; for ( int i = 0 ; i < n ; i ++ ) { mpp [ a [ i ] ] ++ ; if ( mpp [ a [ i ] ] == 1 ) v1 . push_back ( a [ i ] ) ; else if ( mpp [ a [ i ] ] == 2 ) v2 . push_back ( a [ i ] ) ; else { cout << " Not ▁ possible " ; return ; } } sort ( v1 . begin ( ) , v1 . end ( ) ) ; cout << " Strictly ▁ increasing ▁ array ▁ is : STRNEWLINE " ; for ( auto it : v1 ) cout << it << " ▁ " ; sort ( v2 . begin ( ) , v2 . end ( ) , greater < int > ( ) ) ; cout << " Strictly decreasing array is : " for ( auto it : v2 ) cout << it << " ▁ " ; } int main ( ) { int a [ ] = { 7 , 2 , 7 , 3 , 3 , 1 , 4 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; PrintBothArrays ( a , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, it
C++ program:
#include <iostream>
using namespace std ; struct Node { int data ; struct Node * next ; } Node ; struct Node * swap ( struct Node * ptr1 , struct Node * ptr2 ) { struct Node * tmp = ptr2 -> next ; ptr2 -> next = ptr1 ; ptr1 -> next = tmp ; return ptr2 ; } int bubbleSort ( struct Node * * head , int count ) { struct Node * * h ; int i , j , swapped ; for ( i = 0 ; i <= count ; i ++ ) { h = head ; swapped = 0 ; for ( j = 0 ; j < count - i - 1 ; j ++ ) { struct Node * p1 = * h ; struct Node * p2 = p1 -> next ; if ( p1 -> data > p2 -> data ) { * h = swap ( p1 , p2 ) ; swapped = 1 ; } h = & ( * h ) -> next ; } if ( swapped == 0 ) break ; } } void printList ( struct Node * n ) { while ( n != NULL ) { cout << n -> data << " ▁ - > ▁ " ; n = n -> next ; } cout << endl ; } void insertAtTheBegin ( struct Node * * start_ref , int data ) { struct Node * ptr1 = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; ptr1 -> data = data ; ptr1 -> next = * start_ref ; * start_ref = ptr1 ; } int main ( ) { int arr [ ] = { 78 , 20 , 10 , 32 , 1 , 5 } ; int list_size , i ; struct Node * start = NULL ; list_size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; for ( i = 0 ; i < list_size ; i ++ ) insertAtTheBegin ( & start , arr [ i ] ) ; cout << " Linked ▁ list ▁ before ▁ sorting STRNEWLINE " ; printList ( start ) ; bubbleSort ( & start , list_size ) ; cout << " Linked ▁ list ▁ after ▁ sorting STRNEWLINE " ; printList ( start ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isUgly ( int n ) { while ( n % 2 == 0 ) n = n / 2 ; while ( n % 3 == 0 ) n = n / 3 ; while ( n % 5 == 0 ) n = n / 5 ; if ( n == 1 ) return true ; return false ; } void sortUglyNumbers ( int arr [ ] , int n ) { vector < int > list ; int i ; for ( i = 0 ; i < n ; i ++ ) { if ( isUgly ( arr [ i ] ) ) { list . push_back ( arr [ i ] ) ; arr [ i ] = -1 ; } } sort ( list . begin ( ) , list . end ( ) ) ; int j = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == -1 ) cout << list [ j ++ ] << " ▁ " ; else cout << arr [ i ] << " ▁ " ; } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 7 , 12 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortUglyNumbers ( arr , n ) ; }

Index/key variables: i
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printArr ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << ( arr [ i ] ) << " ▁ " ; } void sortArr ( int arr [ ] , int n , int k ) { int prev = -1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) { if ( prev != -1 ) sort ( arr + prev + 1 , arr + i ) ; prev = i ; } } printArr ( arr , n ) ; } int main ( ) { int arr [ ] = { 2 , 1 , 13 , 3 , 7 , 8 , 21 , 13 , 12 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; sortArr ( arr , n , k ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printNumbers ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int A = arr [ n - 1 ] , B = -1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( A % arr [ i ] != 0 ) { B = arr [ i ] ; break ; } if ( i - 1 >= 0 && arr [ i ] == arr [ i - 1 ] ) { B = arr [ i ] ; break ; } } cout << " A ▁ = ▁ " << A << " , ▁ B ▁ = ▁ " << B ; } int main ( ) { int arr [ ] = { 1 , 2 , 4 , 8 , 16 , 1 , 2 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printNumbers ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } void removeMin ( int arr [ ] , int n ) { int i , minVal = arr [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) minVal = min ( minVal , arr [ i ] ) ; for ( i = 0 ; i < n ; i ++ ) arr [ i ] = arr [ i ] - minVal ; } void removeFromMax ( int arr [ ] , int n ) { int i , maxVal = arr [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) maxVal = max ( maxVal , arr [ i ] ) ; for ( i = 0 ; i < n ; i ++ ) arr [ i ] = maxVal - arr [ i ] ; } void modifyArray ( int arr [ ] , int n , int k ) { if ( k % 2 == 0 ) removeMin ( arr , n ) ; else removeFromMax ( arr , n ) ; printArray ( arr , n ) ; } int main ( ) { int arr [ ] = { 4 , 8 , 12 , 16 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; modifyArray ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long int
ll maxProd ( int arr [ ] , int n , int k ) { ll product = 1 ; unordered_map < int , int > s ; sort ( arr , arr + n ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ arr [ i ] ] == 0 ) { product = product * arr [ i ] ; } s [ arr [ i ] ] = s [ arr [ i ] ] + 1 ; } for ( int j = n - 1 ; j >= 0 && k > 0 ; j -- ) { if ( ( k > ( s [ arr [ j ] ] - 1 ) ) && ( ( s [ arr [ j ] ] - 1 ) > 0 ) ) { product *= pow ( arr [ j ] , s [ arr [ j ] ] - 1 ) ; k = k - s [ arr [ j ] ] + 1 ; s [ arr [ j ] ] = 0 ; } if ( k <= ( s [ arr [ j ] ] - 1 ) && ( ( s [ arr [ j ] ] - 1 ) > 0 ) ) { product *= pow ( arr [ j ] , k ) ; break ; } } return product ; } int main ( ) { int arr [ ] = { 5 , 6 , 7 , 8 , 2 , 5 , 6 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; cout << maxProd ( arr , n , k ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, product, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
#include <vector>
using namespace std ; vector < int > mergeTwoArrays ( vector < int > l , vector < int > r ) { vector < int > ret ; int l_in = 0 , r_in = 0 ; while ( l_in + r_in < l . size ( ) + r . size ( ) ) { if ( l_in != l . size ( ) && ( r_in == r . size ( ) l [ l_in ] < r [ r_in ] ) ) { ret . push_back ( l [ l_in ] ) ; l_in ++ ; } else { ret . push_back ( r [ r_in ] ) ; r_in ++ ; } } return ret ; } vector < int > mergeArrays ( vector < vector < int > > arr ) { vector < vector < int > > arr_s ; while ( arr . size ( ) != 1 ) { arr_s . clear ( ) ; for ( int i = 0 ; i < arr . size ( ) ; i += 2 ) { if ( i == arr . size ( ) - 1 ) arr_s . push_back ( arr [ i ] ) ; else arr_s . push_back ( mergeTwoArrays ( arr [ i ] , arr [ i + 1 ] ) ) ; } arr = arr_s ; } return arr [ 0 ] ; } int main ( ) { vector < vector < int > > arr { { 3 , 13 } , { 8 , 10 , 11 } , { 9 , 15 } } ; vector < int > output = mergeArrays ( arr ) ; for ( int i = 0 ; i < output . size ( ) ; i ++ ) cout << output [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i, l_in, r_in
Accumulator variables: i, l_in, r_in
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; unsigned long long findAnswer ( int n , vector < int > & arr ) { sort ( arr . begin ( ) , arr . end ( ) ) ; unsigned long long sum = 0 ; for ( int i = 0 ; i < n / 2 ; ++ i ) { sum += ( arr [ i ] + arr [ n - i - 1 ] ) * ( arr [ i ] + arr [ n - i - 1 ] ) ; } return sum ; } int main ( ) { std :: vector < int > arr = { 53 , 28 , 143 , 5 } ; int n = arr . size ( ) ; cout << findAnswer ( n , arr ) ; }

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