dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
#define infi  1000000000
using namespace std ; class Node { public : int vertexNumber ; vector < pair < int , int > > children ; Node ( int vertexNumber ) { this -> vertexNumber = vertexNumber ; } void add_child ( int vNumber , int length ) { pair < int , int > p ; p . first = vNumber ; p . second = length ; children . push_back ( p ) ; } } ; vector < int > dijkstraDist ( vector < Node * > g , int s , vector < int > & path ) { vector < int > dist ( g . size ( ) ) ; bool visited [ g . size ( ) ] ; for ( int i = 0 ; i < g . size ( ) ; i ++ ) { visited [ i ] = false ; path [ i ] = -1 ; dist [ i ] = infi ; } dist [ s ] = 0 ; path [ s ] = -1 ; int current = s ; unordered_set < int > sett ; while ( true ) { visited [ current ] = true ; for ( int i = 0 ; i < g [ current ] -> children . size ( ) ; i ++ ) { int v = g [ current ] -> children [ i ] . first ; if ( visited [ v ] ) continue ; sett . insert ( v ) ; int alt = dist [ current ] + g [ current ] -> children [ i ] . second ; if ( alt < dist [ v ] ) { dist [ v ] = alt ; path [ v ] = current ; } } sett . erase ( current ) ; if ( sett . empty ( ) ) break ; int minDist = infi ; int index = 0 ; for ( int a : sett ) { if ( dist [ a ] < minDist ) { minDist = dist [ a ] ; index = a ; } } current = index ; } return dist ; } void printPath ( vector < int > path , int i , int s ) { if ( i != s ) { if ( path [ i ] == -1 ) { cout << " Path ▁ not ▁ found ! ! " ; return ; } printPath ( path , path [ i ] , s ) ; cout << path [ i ] << " ▁ " ; } } int main ( ) { vector < Node * > v ; int n = 4 , s = 0 , e = 5 ; for ( int i = 0 ; i < n ; i ++ ) { Node * a = new Node ( i ) ; v . push_back ( a ) ; } v [ 0 ] -> add_child ( 1 , 1 ) ; v [ 0 ] -> add_child ( 2 , 4 ) ; v [ 1 ] -> add_child ( 2 , 2 ) ; v [ 1 ] -> add_child ( 3 , 6 ) ; v [ 2 ] -> add_child ( 3 , 3 ) ; vector < int > path ( v . size ( ) ) ; vector < int > dist = dijkstraDist ( v , s , path ) ; for ( int i = 0 ; i < dist . size ( ) ; i ++ ) { if ( dist [ i ] == infi ) { cout << i << " ▁ and ▁ " << s << " ▁ are ▁ not ▁ connected " << endl ; continue ; } cout << " Distance ▁ of ▁ " << i << " th ▁ vertex ▁ from ▁ source ▁ vertex ▁ " << s << " ▁ is : ▁ " << dist [ i ] << endl ; } return 0 ; }

Index/key variables: a, current, i, s, v
Accumulator variables: i, stdc
Iterator variables: a, i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long
void sortPermutation ( ll arr [ ] , ll n ) { vector < pair < ll , pair < ll , ll > > > ans ; vector < ll > p ; bool visited [ 200005 ] = { 0 } ; for ( ll i = 1 ; i <= n ; i ++ ) { if ( arr [ i ] == i ) { visited [ i ] = 1 ; continue ; } else { if ( ! visited [ i ] ) { ll x = i ; vector < ll > v ; while ( ! visited [ x ] ) { visited [ x ] = 1 ; v . push_back ( x ) ; x = arr [ x ] ; } if ( ( v . size ( ) - 3 ) % 2 == 0 ) { for ( ll i = 1 ; i < v . size ( ) ; i += 2 ) { ans . push_back ( make_pair ( v [ 0 ] , make_pair ( v [ i ] , v [ i + 1 ] ) ) ) ; } continue ; } p . push_back ( v [ 0 ] ) ; p . push_back ( v [ v . size ( ) - 1 ] ) ; for ( ll i = 1 ; i < v . size ( ) - 1 ; i += 2 ) { ans . push_back ( make_pair ( v [ 0 ] , make_pair ( v [ i ] , v [ i + 1 ] ) ) ) ; } } } } if ( p . size ( ) % 4 ) { cout << -1 << " STRNEWLINE " ; return ; } for ( ll i = 0 ; i < p . size ( ) ; i += 4 ) { ans . push_back ( make_pair ( p [ i ] , make_pair ( p [ i + 1 ] , p [ i + 2 ] ) ) ) ; ans . push_back ( make_pair ( p [ i + 2 ] , make_pair ( p [ i ] , p [ i + 3 ] ) ) ) ; } cout << ans . size ( ) << " STRNEWLINE " ; for ( ll i = 0 ; i < ans . size ( ) ; i ++ ) { cout << ans [ i ] . first << " ▁ " << ans [ i ] . second . first << " ▁ " << ans [ i ] . second . second << " STRNEWLINE " ; } } int main ( ) { ll arr [ ] = { 0 , 3 , 2 , 4 , 1 } ; ll n = 4 ; sortPermutation ( arr , n ) ; return 0 ; }

Index/key variables: i, x
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maximizeval10 ( int a [ ] , int n , int k ) { int increments = 0 ; int ans = 0 ; vector < int > v ; for ( int i = 0 ; i < n ; i ++ ) { ans += ( a [ i ] / 10 ) ; if ( a [ i ] == 1000 ) continue ; else { v . push_back ( 10 - a [ i ] % 10 ) ; increments += ( 100 - ( ( a [ i ] ) / 10 ) - 1 ) ; } } sort ( v . begin ( ) , v . end ( ) ) ; int sum = 0 ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) { sum += v [ i ] ; if ( sum <= k ) { ans ++ ; } else break ; } if ( sum < k ) { int remaining = k - sum ; ans += min ( increments , remaining / 10 ) ; } cout << ans ; } int main ( ) { int N = 4 ; int X = 6 ; int A [ N ] = { 4 , 8 , 8 , 8 } ; maximizeval10 ( A , N , X ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: ans, i, increments, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinDif ( int arr [ ] , int N ) { sort ( arr , arr + N ) ; return ( arr [ N - 1 ] - arr [ N - 2 ] ) ; } int main ( ) { int arr [ ] = { 7 , 9 , 5 , 10 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMinDif ( arr , N ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; int partition ( int arr [ ] , int l , int h ) { int pivot = arr [ l ] ; int i = l + 1 ; int j = h ; while ( i <= j ) { while ( i <= h && arr [ i ] < pivot ) { i ++ ; } while ( j > l && arr [ j ] > pivot ) { j -- ; } if ( i < j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; i ++ ; j -- ; } else i ++ ; } arr [ l ] = arr [ j ] ; arr [ j ] = pivot ; return j ; } void sortArray ( int arr [ ] , int l , int h ) { if ( l >= h ) return ; int pivot = partition ( arr , l , h ) ; sortArray ( arr , l , pivot - 1 ) ; sortArray ( arr , pivot + 1 , h ) ; } int findMaxIntervals ( int start [ ] , int end [ ] , int n , int R ) { int ans = 0 ; int prev = 0 ; int currActive = 0 ; int i = 0 ; int j = 0 ; if ( start [ 0 ] > 0 ) ans ++ ; while ( i < n && j < n ) { if ( start [ i ] < end [ j ] ) { i ++ ; currActive ++ ; } else if ( start [ i ] > end [ j ] ) { j ++ ; currActive -- ; } else { i ++ ; j ++ ; } if ( currActive == 0 ) { ans ++ ; } } if ( end [ n - 1 ] < R ) ans ++ ; return ans ; } int main ( ) { int R , N ; R = 10 ; N = 3 ; int start [ N ] = { 2 , 5 , 8 } ; int end [ N ] = { 3 , 9 , 10 } ; sortArray ( start , 0 , N - 1 ) ; sortArray ( end , 0 , N - 1 ) ; cout << findMaxIntervals ( start , end , N , R ) ; }

Index/key variables: N, i, j, l
Accumulator variables: ans, currActive, i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int number ( int a [ ] , int n , int p , int k ) { sort ( a , a + n ) ; int pre [ n ] = { 0 } , val , i , j , ans = 0 ; pre [ 0 ] = a [ 0 ] ; if ( pre [ 0 ] <= p ) ans = 1 ; for ( i = 1 ; i < k - 1 ; i ++ ) { pre [ i ] = pre [ i - 1 ] + a [ i ] ; if ( pre [ i ] <= p ) ans = i + 1 ; } pre [ k - 1 ] = a [ k - 1 ] ; for ( i = k - 1 ; i < n ; i ++ ) { if ( i >= k ) { pre [ i ] += pre [ i - k ] + a [ i ] ; } if ( pre [ i ] <= p ) ans = i + 1 ; } return ans ; } int main ( ) { int n = 5 ; int arr [ ] = { 2 , 4 , 3 , 5 , 7 } ; int p = 11 ; int k = 2 ; cout << number ( arr , n , p , k ) << endl ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sieveOfEratosthenes ( bool prime [ ] , int n ) { prime [ 0 ] = prime [ 1 ] = false ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } } void sortSpecialPrimes ( int arr [ ] , int n ) { int maxVal = * max_element ( arr , arr + n ) ; bool prime [ maxVal + 1 ] ; memset ( prime , true , sizeof ( prime ) ) ; sieveOfEratosthenes ( prime , maxVal ) ; vector < int > list ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] && prime [ arr [ i ] - 2 ] ) { list . push_back ( arr [ i ] ) ; arr [ i ] = -1 ; } } sort ( list . begin ( ) , list . end ( ) ) ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == -1 ) cout << list [ j ++ ] << " ▁ " ; else cout << arr [ i ] << " ▁ " ; } } int main ( ) { int arr [ ] = { 31 , 5 , 2 , 1 , 7 } ; int n = sizeof ( arr ) / sizeof ( int ) ; sortSpecialPrimes ( arr , n ) ; return 0 ; }

Index/key variables: i, p
Accumulator variables: i, j, p, stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxProfit ( int arr [ ] , int n ) { sort ( arr , arr + n , greater < int > ( ) ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] - ( 1 * i ) ) > 0 ) ans += ( arr [ i ] - ( 1 * i ) ) ; if ( ( arr [ i ] - ( 1 * i ) ) == 0 ) break ; } return ans ; } int main ( ) { int arr [ ] = { 6 , 6 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxProfit ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void check_vector ( vector < int > A , int n , vector < int > p ) { vector < int > pos ( A . size ( ) ) ; for ( int i = 0 ; i < p . size ( ) ; i ++ ) { pos [ p [ i ] - 1 ] = 1 ; } int flag = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( pos [ i ] == 0 ) continue ; int j = i ; while ( j < n && pos [ j ] ) ++ j ; sort ( A . begin ( ) + i , A . begin ( ) + j + 1 ) ; i = j ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( A [ i ] > A [ i + 1 ] ) { flag = 0 ; break ; } } if ( flag == 1 ) cout << " Yes " ; else cout << " No " ; } int main ( ) { vector < int > A { 3 , 2 , 1 } ; vector < int > p { 1 , 2 } ; check_vector ( A , A . size ( ) , p ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; unordered_map < char , int > mp ; bool comp ( string & a , string & b ) { for ( int i = 0 ; i < min ( a . size ( ) , b . size ( ) ) ; i ++ ) { if ( mp [ a [ i ] ] != mp [ b [ i ] ] ) return mp [ a [ i ] ] < mp [ b [ i ] ] ; } return ( a . size ( ) < b . size ( ) ) ; } void printSorted ( vector < string > words , string order ) { for ( int i = 0 ; i < order . size ( ) ; i ++ ) mp [ order [ i ] ] = i ; sort ( words . begin ( ) , words . end ( ) , comp ) ; for ( auto x : words ) cout << x << " ▁ " ; } int main ( ) { vector < string > words = { " word " , " world " , " row " } ; string order = { " worldabcefghijkmnpqstuvxyz " } ; printSorted ( words , order ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortDiff ( vector < int > arr , int n ) { sort ( arr . begin ( ) , arr . end ( ) ) ; vector < int > out ; while ( n > 0 ) { out . push_back ( arr [ n / 2 ] ) ; arr . erase ( arr . begin ( ) + n / 2 ) ; n = n - 1 ; } for ( auto i : out ) cout << i << " ▁ " ; } int main ( ) { vector < int > a = { 8 , 1 , 2 , 3 , 0 } ; int n = 5 ; sortDiff ( a , n ) ; }

Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minimumCost ( int arr [ ] , int N , int M ) { sort ( arr , arr + N ) ; int pref [ N ] ; pref [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { pref [ i ] = arr [ i ] + pref [ i - 1 ] ; } for ( int i = M ; i < N ; i ++ ) { pref [ i ] += pref [ i - M ] ; } for ( int i = 0 ; i < N ; i ++ ) { cout << pref [ i ] << ' ▁ ' ; } } int main ( ) { int arr [ ] = { 6 , 19 , 3 , 4 , 4 , 2 , 6 , 7 , 8 } ; int M = 2 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; minimumCost ( arr , N , M ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string one [ ] = { " " , " one ▁ " , " two ▁ " , " three ▁ " , " four ▁ " , " five ▁ " , " six ▁ " , " seven ▁ " , " eight ▁ " , " nine ▁ " , " ten ▁ " , " eleven ▁ " , " twelve ▁ " , " thirteen ▁ " , " fourteen ▁ " , " fifteen ▁ " , " sixteen ▁ " , " seventeen ▁ " , " eighteen ▁ " , " nineteen ▁ " } ; string ten [ ] = { " " , " " , " twenty ▁ " , " thirty ▁ " , " forty ▁ " , " fifty ▁ " , " sixty ▁ " , " seventy ▁ " , " eighty ▁ " , " ninety ▁ " } ; string numToWords ( int n , string s ) { string str = " " ; if ( n > 19 ) str += ten [ n / 10 ] + one [ n % 10 ] ; else str += one [ n ] ; if ( n ) str += s ; return str ; } string convertToWords ( int n ) { string out ; out += numToWords ( ( n / 10000000 ) , " crore ▁ " ) ; out += numToWords ( ( ( n / 100000 ) % 100 ) , " lakh ▁ " ) ; out += numToWords ( ( ( n / 1000 ) % 100 ) , " thousand ▁ " ) ; out += numToWords ( ( ( n / 100 ) % 10 ) , " hundred ▁ " ) ; if ( n > 100 && n % 100 ) out += " and ▁ " ; out += numToWords ( ( n % 100 ) , " " ) ; return out ; } void sortArr ( int arr [ ] , int n ) { vector < pair < string , int > > vp ; for ( int i = 0 ; i < n ; i ++ ) { vp . push_back ( make_pair ( convertToWords ( arr [ i ] ) , arr [ i ] ) ) ; } sort ( vp . begin ( ) , vp . end ( ) ) ; for ( int i = 0 ; i < vp . size ( ) ; i ++ ) cout << vp [ i ] . second << " ▁ " ; } int main ( ) { int arr [ ] = { 12 , 10 , 102 , 31 , 15 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortArr ( arr , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, out, stdc, str
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool Comparator ( pair < int , int > p1 , pair < int , int > p2 ) { return p1 . second > p2 . second ; } int FindMaxRating ( int N , int Point [ ] , int Upvote [ ] , int K ) { vector < pair < int , int > > vec ; for ( int i = 0 ; i < N ; i ++ ) { vec . push_back ( make_pair ( Point [ i ] , Upvote [ i ] ) ) ; } sort ( vec . begin ( ) , vec . end ( ) , Comparator ) ; priority_queue < int , vector < int > , greater < int > > pq ; int total_points = 0 , max_rating = 0 ; for ( int i = 0 ; i < K ; i ++ ) { total_points = total_points + vec [ i ] . first ; max_rating = max ( max_rating , total_points * vec [ i ] . second ) ; pq . push ( vec [ i ] . first ) ; } for ( int i = K ; i < N ; i ++ ) { if ( pq . top ( ) < vec [ i ] . first ) { total_points = total_points - pq . top ( ) + vec [ i ] . first ; max_rating = max ( max_rating , total_points * vec [ i ] . second ) ; pq . pop ( ) ; pq . push ( vec [ i ] . first ) ; } } return max_rating ; } int main ( ) { int Point [ ] = { 2 , 10 , 3 , 1 , 5 , 8 } ; int Upvote [ ] = { 5 , 4 , 3 , 9 , 7 , 2 } ; int N = sizeof ( Point ) / sizeof ( Point [ 0 ] ) ; int K = 2 ; cout << " Maximum ▁ Rating ▁ of ▁ Coding ▁ Contest ▁ is : ▁ " << FindMaxRating ( N , Point , Upvote , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int uniqueSum ( int A [ ] , int R [ ] [ 2 ] , int N , int M ) { for ( int i = 0 ; i < M ; ++ i ) { int l = R [ i ] [ 0 ] , r = R [ i ] [ 1 ] + 1 ; l -- ; r -- ; A [ l ] ++ ; if ( r < N ) A [ r ] -- ; } for ( int i = 1 ; i < N ; ++ i ) { A [ i ] += A [ i - 1 ] ; } int ans = 0 ; unordered_set < int > s ; for ( int i = 0 ; i < N ; ++ i ) { if ( s . find ( A [ i ] ) == s . end ( ) ) ans += A [ i ] ; s . insert ( A [ i ] ) ; } return ans ; } int main ( ) { int A [ ] = { 0 , 0 , 0 , 0 , 0 , 0 } ; int R [ ] [ 2 ] = { { 1 , 3 } , { 4 , 6 } , { 3 , 4 } , { 3 , 3 } } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int M = sizeof ( R ) / sizeof ( R [ 0 ] ) ; cout << uniqueSum ( A , R , N , M ) ; return 0 ; }

Index/key variables: i, l, r
Accumulator variables: ans, l, r, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void kthpair ( int n , int k , int arr [ ] ) { int i , t ; sort ( arr , arr + n ) ; -- k ; for ( i = 0 ; i < n ; i += t ) { for ( t = 1 ; arr [ i ] == arr [ i + t ] ; ++ t ) ; if ( t * n > k ) break ; k = k - t * n ; } cout << arr [ i ] << ' ▁ ' << arr [ k / t ] ; } int main ( ) { int n = 3 , k = 2 ; int arr [ n ] = { 3 , 1 , 5 } ; kthpair ( n , k , arr ) ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i, t
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperations ( string s ) { int freq [ 26 ] = { 0 } ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { freq [ s [ i ] - ' A ' ] ++ ; } sort ( freq , freq + 26 , greater < int > ( ) ) ; int answer = n ; for ( int i = 1 ; i <= 26 ; i ++ ) { if ( n % i == 0 ) { int x = n / i ; int y = 0 ; for ( int j = 0 ; j < i ; j ++ ) { y += min ( freq [ j ] , x ) ; } answer = min ( answer , n - y ) ; } } return answer ; } int main ( ) { string s = " BBC " ; cout << minOperations ( s ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, y
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool fun ( int arr [ ] , int n , int k ) { vector < int > v ; for ( int i = 0 ; i < k ; i ++ ) { for ( int j = i ; j < n ; j += k ) { v . push_back ( arr [ j ] ) ; } sort ( v . begin ( ) , v . end ( ) ) ; int x = 0 ; for ( int j = i ; j < n ; j += k ) { arr [ j ] = v [ x ] ; x ++ ; } v . clear ( ) ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) return false ; } return true ; } int main ( ) { int arr [ ] = { 4 , 2 , 3 , 7 , 6 } ; int K = 2 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( fun ( arr , n , K ) ) cout << " yes " << endl ; else cout << " no " << endl ; return 0 ; }

Index/key variables: i, j, x
Accumulator variables: i, j, stdc, x
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortedAdjacentDifferences ( int arr [ ] , int n ) { int ans [ n ] ; sort ( arr + 0 , arr + n ) ; int l = 0 , r = n - 1 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( i % 2 ) { ans [ i ] = arr [ l ] ; l ++ ; } else { ans [ i ] = arr [ r ] ; r -- ; } } for ( int i = 0 ; i < n ; i ++ ) { cout << ans [ i ] << " ▁ " ; } } int main ( ) { int arr [ ] = { 5 , -2 , 4 , 8 , 6 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortedAdjacentDifferences ( arr , n ) ; return 0 ; }

Index/key variables: i, l, n, r
Accumulator variables: i, l, r, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int get_permutation ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { result += abs ( arr [ i ] - ( i + 1 ) ) ; } return result ; } int main ( ) { int arr [ ] = { 0 , 2 , 3 , 4 , 1 , 6 , 8 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << get_permutation ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, result, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 1000 ] [ 1000 ] ; int minimumIncDec ( int arr [ ] , int N , int maxE , int minE ) { if ( N == 0 ) { return 0 ; } if ( dp [ N ] [ maxE ] ) return dp [ N ] [ maxE ] ; int ans = INT_MAX ; for ( int k = minE ; k <= maxE ; k ++ ) { int x = minimumIncDec ( arr , N - 1 , k , minE ) ; ans = min ( ans , x + abs ( arr [ N - 1 ] - k ) ) ; } dp [ N ] [ maxE ] = ans ; return dp [ N ] [ maxE ] ; } int main ( ) { int arr [ ] = { 5 , 4 , 3 , 2 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int minE = * min_element ( arr , arr + N ) ; int maxE = * max_element ( arr , arr + N ) ; cout << minimumIncDec ( arr , N , maxE , minE ) ; return 0 ; }

Index/key variables: N, maxE
Accumulator variables: k, stdc
Iterator variables: k
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortDiagonal ( int a [ 2 ] [ 2 ] , int M , int N ) { for ( int i = 0 ; i < M ; i ++ ) { int sm = a [ i ] [ i ] ; int pos = i ; for ( int j = i + 1 ; j < N ; j ++ ) { if ( sm > a [ j ] [ j ] ) { sm = a [ j ] [ j ] ; pos = j ; } } swap ( a [ i ] [ i ] , a [ pos ] [ pos ] ) ; } for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) cout << a [ i ] [ j ] << " ▁ " ; cout << endl ; } } int main ( ) { int a [ 2 ] [ 2 ] = { { 4 , 2 } , { 3 , 1 } } ; sortDiagonal ( a , 2 , 2 ) ; return 0 ; }

Index/key variables: i, j, pos
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int make_permutation ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) ans += abs ( i + 1 - arr [ i ] ) ; return ans ; } int main ( ) { int arr [ ] = { 5 , 3 , 8 , 1 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << make_permutation ( arr , n ) ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSum ( vector < vector < int > > & V , int n , int m ) { int ans = 0 ; for ( int i = n - 2 ; i >= 0 ; -- i ) { vector < pair < int , int > > aux ; for ( int j = 0 ; j < m ; ++ j ) { aux . push_back ( { V [ i + 1 ] [ j ] , j } ) ; } sort ( aux . begin ( ) , aux . end ( ) ) ; reverse ( aux . begin ( ) , aux . end ( ) ) ; for ( int j = 0 ; j < m ; ++ j ) { for ( int k = 0 ; k < m ; ++ k ) { if ( aux [ k ] . second - j == 0 || abs ( aux [ k ] . second - j ) > 1 ) { V [ i ] [ j ] += aux [ k ] . first ; break ; } } } } for ( int i = 0 ; i < m ; ++ i ) { ans = max ( ans , V [ 0 ] [ i ] ) ; } return ans ; } int main ( ) { vector < vector < int > > V { { 1 , 2 , 3 , 4 } , { 8 , 7 , 6 , 5 } , { 10 , 11 , 12 , 13 } } ; int n = V . size ( ) ; int m = V [ 0 ] . size ( ) ; cout << maxSum ( V , n , m ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int SumofDigits ( int digit ) { int sum = 0 ; while ( digit != 0 ) { int rem = digit % 10 ; sum += rem ; digit /= 10 ; } return sum ; } int findCountofNumbers ( int arr [ ] , int n , int M ) { vector < int > SumDigits ; for ( int i = 0 ; i < n ; i ++ ) { int s = SumofDigits ( arr [ i ] ) ; SumDigits . push_back ( s ) ; } sort ( SumDigits . begin ( ) , SumDigits . end ( ) ) ; vector < int > :: iterator ip ; ip = unique ( SumDigits . begin ( ) , SumDigits . end ( ) ) ; SumDigits . resize ( distance ( SumDigits . begin ( ) , ip ) ) ; int count = 0 ; int sum = 0 ; for ( int i = 0 ; i < SumDigits . size ( ) ; i ++ ) { if ( sum > M ) break ; sum += SumDigits [ i ] ; if ( sum <= M ) count ++ ; } return count ; } int main ( ) { int arr [ ] = { 1 , 45 , 16 , 17 , 219 , 32 , 22 } , M = 10 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findCountofNumbers ( arr , n , M ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, digit, i, stdc, sum
Iterator variables: i
C++ program:
#include " bits / stdc + + . h "
using namespace std ; int minimumProduct ( int * arr , int n ) { sort ( arr , arr + n ) ; int product = 1 ; for ( int i = 0 ; i < n ; i += 2 ) { product *= ( arr [ i ] + arr [ i + 1 ] ) ; } return product ; } int main ( ) { int arr [ ] = { 1 , 6 , 3 , 1 , 7 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minimumProduct ( arr , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, product
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minRemovals ( vector < vector < int > > & ranges ) { int size = ranges . size ( ) , rem = 0 ; if ( size <= 1 ) return 0 ; sort ( ranges . begin ( ) , ranges . end ( ) , [ ] ( const vector < int > & a , const vector < int > & b ) { return a [ 0 ] < b [ 0 ] ; } ) ; int end = ranges [ 0 ] [ 1 ] ; for ( int i = 1 ; i < ranges . size ( ) ; i ++ ) { if ( ranges [ i ] [ 0 ] < end ) { rem ++ ; end = min ( ranges [ i ] [ 1 ] , end ) ; } else end = ranges [ i ] [ 1 ] ; } return rem ; } int main ( ) { vector < vector < int > > input = { { 19 , 25 } , { 10 , 20 } , { 16 , 20 } } ; cout << minRemovals ( input ) << endl ; }

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