dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool mycmp ( pair < int , int > a , pair < int , int > b ) { return a . first > b . first ; } int minSwapsAsc ( vector < int > arr , int n ) { pair < int , int > arrPos [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arrPos [ i ] . first = arr [ i ] ; arrPos [ i ] . second = i ; } sort ( arrPos , arrPos + n ) ; vector < bool > vis ( n , false ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( vis [ i ] arrPos [ i ] . second == i ) continue ; int cycle_size = 0 ; int j = i ; while ( ! vis [ j ] ) { vis [ j ] = 1 ; j = arrPos [ j ] . second ; cycle_size ++ ; } if ( cycle_size > 0 ) { ans += ( cycle_size - 1 ) ; } } return ans ; } int minSwapsDes ( vector < int > arr , int n ) { pair < int , int > arrPos [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arrPos [ i ] . first = arr [ i ] ; arrPos [ i ] . second = i ; } sort ( arrPos , arrPos + n , mycmp ) ; vector < bool > vis ( n , false ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( vis [ i ] arrPos [ i ] . second == i ) continue ; int cycle_size = 0 ; int j = i ; while ( ! vis [ j ] ) { vis [ j ] = 1 ; j = arrPos [ j ] . second ; cycle_size ++ ; } if ( cycle_size > 0 ) { ans += ( cycle_size - 1 ) ; } } return ans ; } int minimumSwaps ( vector < int > arr ) { int S1 = minSwapsAsc ( arr , arr . size ( ) ) ; int S2 = minSwapsDes ( arr , arr . size ( ) ) ; return min ( S1 , S2 ) ; } int main ( ) { vector < int > arr { 3 , 4 , 2 , 5 , 1 } ; cout << minimumSwaps ( arr ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: ans, cycle_size, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortArray ( int arr [ ] , int N ) { int i = 0 , j = N - 1 , mid = 0 ; while ( mid <= j ) { if ( arr [ mid ] == 0 ) { swap ( arr [ i ] , arr [ mid ] ) ; i ++ ; mid ++ ; } else if ( arr [ mid ] == 3 ) { swap ( arr [ mid ] , arr [ j ] ) ; j -- ; } else if ( arr [ mid ] == 1 arr [ mid ] == 2 ) { mid ++ ; } } while ( i <= j ) { if ( arr [ i ] == 2 ) { swap ( arr [ i ] , arr [ j ] ) ; j -- ; } else { i ++ ; } } for ( int i = 0 ; i < N ; i ++ ) { cout << arr [ i ] << " ▁ " ; } } int main ( ) { int arr [ ] = { 3 , 2 , 1 , 0 , 2 , 3 , 1 , 0 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortArray ( arr , N ) ; return 0 ; }

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

Index/key variables: i, index
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortVowels ( string S ) { int n = S . size ( ) ; string vow = " " ; for ( int i = 0 ; i < n ; i ++ ) { if ( S [ i ] == ' a ' S [ i ] == ' e ' S [ i ] == ' i ' S [ i ] == ' o ' S [ i ] == ' u ' ) { vow += S [ i ] ; } } if ( vow . size ( ) == 0 ) { cout << S ; return ; } sort ( vow . begin ( ) , vow . end ( ) ) ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( S [ i ] == ' a ' S [ i ] == ' e ' S [ i ] == ' i ' S [ i ] == ' o ' S [ i ] == ' u ' ) { S [ i ] = vow [ j ++ ] ; } } cout << S ; } int main ( ) { string S = " geeksforgeeks " ; sortVowels ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, j, stdc, vow
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getBuckets ( int arr [ ] , int N ) { int availableWater = N * ( N - 1 ) / 2 ; sort ( arr , arr + N ) ; int i = 0 , sum = 0 ; while ( sum <= availableWater ) { sum += arr [ i ] ; i ++ ; } cout << i - 1 ; } int main ( ) { int arr [ ] = { 1 , 5 , 3 , 4 , 7 , 9 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; getBuckets ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumIncreasingSubsequences ( int arr [ ] , int N ) { sort ( arr , arr + N ) ; int count = 0 ; int i = 0 ; while ( i < N ) { int x = arr [ i ] ; int freqX = 0 ; while ( i < N && arr [ i ] == x ) { freqX ++ ; i ++ ; } count = max ( count , freqX ) ; } cout << count ; } int main ( ) { int arr [ ] = { 2 , 1 , 2 , 1 , 4 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; minimumIncreasingSubsequences ( arr , N ) ; }

Index/key variables: i
Accumulator variables: freqX, i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getCount ( int arr [ ] , int N ) { sort ( arr , arr + N ) ; int count = 0 ; if ( N < 3 ) return 0 ; for ( int b = 0 ; b < N ; b ++ ) { int a = 0 , c = N - 1 ; int d = arr [ b ] * arr [ b ] / 4 ; while ( a < c ) { if ( a == b ) { a ++ ; continue ; } if ( c == b ) { c -- ; continue ; } if ( arr [ a ] * arr <= d ) { if ( a < b && b < c ) { count += c - a - 1 ; } else { count += c - a ; } a ++ ; } else { c -- ; } } } return count * 2 ; } int main ( ) { int arr [ ] = { 3 , 6 , 10 , 13 , 21 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << getCount ( arr , N ) ; return 0 ; }

Index/key variables: a, b
Accumulator variables: a, b, c, count, stdc
Iterator variables: b
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMaxDifference ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int Leftsum = 0 ; int Totalsum = 0 ; int Min = INT_MAX , Max = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) Totalsum += arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) { int leftNumbers = i ; int rightNumbers = n - i - 1 ; Totalsum = Totalsum - arr [ i ] ; int sum = ( leftNumbers * arr [ i ] ) - Leftsum + Totalsum - ( rightNumbers * arr [ i ] ) ; Min = min ( Min , sum ) ; Max = max ( Max , sum ) ; Leftsum += arr [ i ] ; } cout << Max - Min ; } int main ( ) { int arr [ ] = { 1 , 2 , 4 , 7 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findMaxDifference ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: Leftsum, Totalsum, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxcntPairsSumKRemoved ( vector < int > arr , int k ) { int cntPairs = 0 ; if ( arr . size ( ) <= 1 ) return cntPairs ; sort ( arr . begin ( ) , arr . end ( ) ) ; int left = 0 ; int right = arr . size ( ) - 1 ; while ( left < right ) { int s = arr [ left ] + arr [ right ] ; if ( s == k ) { cntPairs += 1 ; left += 1 ; right -= 1 ; } else if ( s > k ) right -= 1 ; else left += 1 ; } return cntPairs ; } int main ( ) { vector < int > arr = { 1 , 2 , 3 , 4 } ; int K = 5 ; cout << ( maxcntPairsSumKRemoved ( arr , K ) ) ; return 0 ; }

Index/key variables: left, right
Accumulator variables: cntPairs, left, right, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getMinCost ( int * arr , int n , int k ) { sort ( arr , arr + n , greater < int > ( ) ) ; int min_cost = 0 ; int X = 0 ; for ( int i = 0 ; i < n ; i += k ) { for ( int j = i ; j < i + k && j < n ; j ++ ) { min_cost += arr [ j ] * ( X + 1 ) ; } X ++ ; } return min_cost ; } int main ( ) { int arr [ ] = { 9 , 20 , 7 , 8 } ; int K = 2 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << getMinCost ( arr , N , K ) << endl ; }

Index/key variables: j
Accumulator variables: X, i, j, min_cost, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minDiff ( int A [ ] , int K , int n ) { sort ( A , A + n ) ; if ( n <= K ) return 0 ; int mindiff = A [ n - 1 ] - A [ 0 ] ; if ( K == 0 ) return mindiff ; for ( int i = 0 , j = n - 1 - K ; j < n ; ) { mindiff = min ( mindiff , A [ j ] - A [ i ] ) ; i ++ ; j ++ ; } return mindiff ; } int main ( ) { int A [ ] = { -1 , 3 , -1 , 8 , 5 , 4 } ; int K = 3 ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << minDiff ( A , K , n ) ; 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 minDiff ( int A [ ] , int K , int N ) { if ( N <= K + 1 ) return 0 ; priority_queue < int , vector < int > , greater < int > > maxHeap ; priority_queue < int > minHeap ; for ( int i = 0 ; i < N ; i ++ ) { maxHeap . push ( A [ i ] ) ; if ( maxHeap . size ( ) > K + 1 ) maxHeap . pop ( ) ; minHeap . push ( A [ i ] ) ; if ( minHeap . size ( ) > K + 1 ) minHeap . pop ( ) ; } vector < int > maxList ; while ( maxHeap . size ( ) > 0 ) { maxList . push_back ( maxHeap . top ( ) ) ; maxHeap . pop ( ) ; } vector < int > minList ; while ( minHeap . size ( ) > 0 ) { minList . push_back ( minHeap . top ( ) ) ; minHeap . pop ( ) ; } int mindiff = INT_MAX ; for ( int i = 0 ; i <= K ; i ++ ) { mindiff = min ( mindiff , maxList [ i ] - minList [ K - i ] ) ; } return mindiff ; } int main ( ) { int A [ ] = { -1 , 3 , -1 , 8 , 5 , 4 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int K = 3 ; cout << minDiff ( A , K , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortArrayInDescAsc ( int arr [ ] , int N , int K ) { sort ( arr , arr + N , greater < int > ( ) ) ; sort ( arr + K , arr + N ) ; for ( int i = 0 ; i < N ; i ++ ) { cout << arr [ i ] << " ▁ " ; } } int main ( ) { int arr [ ] = { 7 , 6 , 8 , 9 , 0 , 1 , 2 , 2 , 1 , 8 , 9 , 6 , 7 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 6 ; sortArrayInDescAsc ( arr , N , K ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMedianOfsubSum ( int arr [ ] , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } sort ( arr , arr + N ) ; int dp [ N ] [ sum + 1 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; for ( int i = 0 ; i < N ; i ++ ) { dp [ i ] [ 0 ] = 1 ; } dp [ 0 ] [ arr [ 0 ] ] = 1 ; for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { if ( j >= arr [ i ] ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - arr [ i ] ] ; } else { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; } } } vector < int > sumSub ; for ( int j = 1 ; j <= sum ; j ++ ) { int M = dp [ N - 1 ] [ j ] ; for ( int i = 1 ; i <= M ; i ++ ) { sumSub . push_back ( j ) ; } } int mid = sumSub [ sumSub . size ( ) / 2 ] ; return mid ; } int main ( ) { int arr [ ] = { 2 , 3 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMedianOfsubSum ( arr , N ) ; 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 printIndex ( int arr [ ] , int N ) { int B [ N ] ; int save = -1 ; for ( int i = 0 ; i < N ; i ++ ) { B [ i ] = arr [ i ] ; } sort ( B , B + N ) ; for ( int i = N - 1 ; i >= 1 ; i -- ) { if ( B [ i ] != B [ i - 1 ] ) { save = B [ i ] ; break ; } } if ( save == -1 ) { cout << -1 << endl ; return ; } if ( save == arr [ 0 ] && save != arr [ 1 ] ) { cout << 1 ; } else if ( save == arr [ N - 1 ] && save != arr [ N - 2 ] ) { cout << N ; } for ( int i = 1 ; i < N - 1 ; i ++ ) { if ( save == arr [ i ] && ( save != arr [ i - 1 ] save != arr [ i + 1 ] ) ) { cout << i + 1 ; break ; } } } int main ( ) { int arr [ ] = { 5 , 3 , 4 , 4 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printIndex ( arr , N ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void firstSubsequence ( string s ) { vector < string > allsubseq ; string k ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { k = s ; k . erase ( i , 1 ) ; allsubseq . push_back ( k ) ; } sort ( allsubseq . begin ( ) , allsubseq . end ( ) ) ; cout << allsubseq [ 0 ] ; } int main ( ) { string S = " geeksforgeeks " ; firstSubsequence ( S ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int evenSumK ( int arr [ ] , int N , int K ) { if ( K > N ) { return -1 ; } int maxSum = 0 ; vector < int > Even ; vector < int > Odd ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 ) { Odd . push_back ( arr [ i ] ) ; } else { Even . push_back ( arr [ i ] ) ; } } sort ( Odd . begin ( ) , Odd . end ( ) ) ; sort ( Even . begin ( ) , Even . end ( ) ) ; int i = Even . size ( ) - 1 ; int j = Odd . size ( ) - 1 ; while ( K > 0 ) { if ( K % 2 == 1 ) { if ( i >= 0 ) { maxSum += Even [ i ] ; i -- ; } else { return -1 ; } K -- ; } else if ( i >= 1 && j >= 1 ) { if ( Even [ i ] + Even [ i - 1 ] <= Odd [ j ] + Odd [ j - 1 ] ) { maxSum += Odd [ j ] + Odd [ j - 1 ] ; j -= 2 ; } else { maxSum += Even [ i ] + Even [ i - 1 ] ; i -= 2 ; } K -= 2 ; } else if ( i >= 1 ) { maxSum += Even [ i ] + Even [ i - 1 ] ; i -= 2 ; K -= 2 ; } else if ( j >= 1 ) { maxSum += Odd [ j ] + Odd [ j - 1 ] ; j -= 2 ; K -= 2 ; } } return maxSum ; } int main ( ) { int arr [ ] = { 2 , 4 , 10 , 3 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 3 ; cout << evenSumK ( arr , N , K ) ; }

Index/key variables: i, j
Accumulator variables: K, i, j, maxSum, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void weightedMedian ( vector < int > arr , vector < float > W ) { vector < pair < int , float > > pr ; for ( int index = 0 ; index < arr . size ( ) ; index ++ ) pr . push_back ( { arr [ index ] , W [ index ] } ) ; sort ( pr . begin ( ) , pr . end ( ) ) ; if ( arr . size ( ) % 2 != 0 ) { float sums = 0 ; for ( auto element : pr ) { sums += element . second ; if ( sums > 0.5 ) cout << " The ▁ Weighted ▁ Median ▁ is ▁ element ▁ " << element . first << endl ; } } else { float sums = 0 ; for ( auto element : pr ) { sums += element . second ; if ( sums >= 0.5 ) { cout << " Lower ▁ Weighted ▁ Median ▁ is ▁ element ▁ " << element . first << endl ; break ; } } sums = 0 ; for ( int index = pr . size ( ) - 1 ; index >= 0 ; index -- ) { int element = pr [ index ] . first ; float weight = pr [ index ] . second ; sums += weight ; if ( sums >= 0.5 ) { cout << " Upper ▁ Weighted ▁ Median ▁ is ▁ element ▁ " << element ; break ; } } } } int main ( ) { vector < int > arr = { 4 , 1 , 3 , 2 } ; vector < float > W = { 0.25 , 0.49 , 0.25 , 0.01 } ; weightedMedian ( arr , W ) ; }

Index/key variables: index
Accumulator variables: index, stdc, sums
Iterator variables: element, index
C++ program:
#include <bits/stdc++.h>
using namespace std ; int KthSmallestNum ( pair < int , int > arr [ ] , int n , int k ) { priority_queue < pair < int , int > , vector < pair < int , int > > , greater < pair < int , int > > > pq ; for ( int i = 0 ; i < n ; i ++ ) { pq . push ( { arr [ i ] . first , arr [ i ] . second } ) ; } int cnt = 1 ; while ( cnt < k ) { pair < int , int > interval = pq . top ( ) ; pq . pop ( ) ; if ( interval . first < interval . second ) { pq . push ( { interval . first + 1 , interval . second } ) ; } cnt ++ ; } return pq . top ( ) . first ; } int main ( ) { pair < int , int > arr [ ] = { { 5 , 11 } , { 10 , 15 } , { 12 , 20 } } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 12 ; cout << KthSmallestNum ( arr , n , k ) ; }

Index/key variables: i
Accumulator variables: cnt, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void MaxDist ( vector < pair < int , int > > & A , int N ) { int maximum = INT_MIN ; for ( int i = 0 ; i < N ; i ++ ) { int sum = 0 ; for ( int j = i + 1 ; j < N ; j ++ ) { sum = abs ( A [ i ] . first - A [ j ] . first ) + abs ( A [ i ] . second - A [ j ] . second ) ; maximum = max ( maximum , sum ) ; } } cout << maximum ; } int main ( ) { int N = 3 ; vector < pair < int , int > > A = { { 1 , 2 } , { 2 , 3 } , { 3 , 4 } } ; MaxDist ( A , 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 ; int LongestSequence ( int a [ ] , int n ) { map < int , int > m ; int ar [ n + 1 ] , i , j ; for ( i = 1 ; i <= n ; i ++ ) { ar [ i ] = a [ i - 1 ] ; } sort ( a , a + n ) ; int c = 1 ; m [ a [ 0 ] ] = c ; for ( i = 1 ; i <= n ; i ++ ) { if ( a [ i ] != a [ i - 1 ] ) { c ++ ; m [ a [ i ] ] = c ; } } map < int , int > cnt ; int dp [ n + 1 ] [ 3 ] = { 0 } ; cnt [ 0 ] = 0 ; for ( i = 1 ; i <= n ; i ++ ) { ar [ i ] = m [ ar [ i ] ] ; cnt [ ar [ i ] ] ++ ; } int ans = 0 , x ; for ( i = 1 ; i <= n ; i ++ ) { x = ar [ i ] ; if ( dp [ x ] [ 0 ] == 0 ) { if ( dp [ x - 1 ] [ 0 ] == cnt [ x - 1 ] ) { dp [ x ] [ 1 ] = dp [ x - 1 ] [ 1 ] ; dp [ x ] [ 2 ] = dp [ x - 1 ] [ 1 ] ; } else { dp [ x ] [ 1 ] = dp [ x - 1 ] [ 0 ] ; } } dp [ x ] [ 2 ] = max ( dp [ x - 1 ] [ 0 ] , dp [ x ] [ 2 ] ) ; if ( dp [ x - 1 ] [ 0 ] == cnt [ x - 1 ] ) { dp [ x ] [ 2 ] = max ( dp [ x ] [ 2 ] , dp [ x - 1 ] [ 1 ] ) ; } for ( j = 0 ; j < 3 ; j ++ ) { dp [ x ] [ j ] ++ ; ans = max ( ans , dp [ x ] [ j ] ) ; } } return ans ; } int main ( ) { int arr [ ] = { 2 , 6 , 4 , 8 , 2 , 9 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << LongestSequence ( arr , N ) ; return 0 ; }

Index/key variables: i, j, x
Accumulator variables: c, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int * * findMatrix ( int N , int K ) { int * * mat = ( int * * ) malloc ( N * sizeof ( int * ) ) ; for ( int i = 0 ; i < N ; ++ i ) { mat [ i ] = ( int * ) malloc ( N * sizeof ( int ) ) ; } int element = 1 ; for ( int i = 0 ; i < N ; ++ i ) { for ( int j = 0 ; j < K - 1 ; ++ j ) { mat [ i ] [ j ] = element ++ ; } } for ( int i = 0 ; i < N ; ++ i ) { for ( int j = K - 1 ; j < N ; ++ j ) { mat [ i ] [ j ] = element ++ ; } } return mat ; } void printMatrix ( int * * mat , int N ) { for ( int i = 0 ; i < N ; ++ i ) { for ( int j = 0 ; j < N ; ++ j ) { cout << mat [ i ] [ j ] << " ▁ " ; } cout << endl ; } } int main ( ) { int N = 3 , K = 2 ; int * * mat = findMatrix ( N , K ) ; printMatrix ( mat , N ) ; }

Index/key variables: i, j
Accumulator variables: element, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int range_sum ( vector < int > & arr , int a , int b ) { int sum = 0 ; if ( a - 2 < 0 ) sum = arr [ b - 1 ] ; else sum = arr [ b - 1 ] - arr [ a - 2 ] ; return sum ; } void precompute_sum ( vector < int > & arr , vector < int > & brr ) { int N = ( int ) arr . size ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { arr [ i ] = arr [ i ] + arr [ i - 1 ] ; brr [ i ] = brr [ i ] + brr [ i - 1 ] ; } } void find_sum ( vector < int > & arr , int q , int Queries [ ] [ 3 ] ) { vector < int > brr ( arr ) ; int N = ( int ) arr . size ( ) ; sort ( brr . begin ( ) , brr . end ( ) ) ; precompute_sum ( arr , brr ) ; for ( int i = 0 ; i < q ; i ++ ) { int m = Queries [ i ] [ 0 ] ; int a = Queries [ i ] [ 1 ] ; int b = Queries [ i ] [ 2 ] ; if ( m == 1 ) { cout << range_sum ( arr , a , b ) << ' ▁ ' ; } else if ( m == 2 ) { cout << range_sum ( brr , a , b ) << ' ▁ ' ; } } } int main ( ) { vector < int > arr = { 0 , 6 , 4 , 2 , 7 , 2 , 7 } ; int Q = 1 ; int Queries [ ] [ 3 ] = { { 2 , 3 , 6 } } ; find_sum ( arr , Q , Queries ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int XorSum ( int A [ ] , int B [ ] , int N ) { const int maxBit = 29 ; int ans = 0 ; for ( int k = 0 ; k < maxBit ; k ++ ) { int C [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { C [ i ] = B [ i ] % ( 1 << ( k + 1 ) ) ; } sort ( C , C + N ) ; long long count = 0 ; long long l , r ; for ( int i = 0 ; i < N ; i ++ ) { int x = A [ i ] % ( 1 << ( k + 1 ) ) ; l = lower_bound ( C , C + N , ( 1 << k ) - x ) - C ; r = lower_bound ( C , C + N , ( 1 << k ) * 2 - x ) - C ; count += ( r - l ) ; l = lower_bound ( C , C + N , ( 1 << k ) * 3 - x ) - C ; r = lower_bound ( C , C + N , ( 1 << k ) * 4 - x ) - C ; count += ( r - l ) ; } if ( count & 1 ) ans += ( 1 << k ) ; } return ans ; } int main ( ) { int A [ ] = { 4 , 6 , 0 , 0 , 3 , 3 } ; int B [ ] = { 0 , 5 , 6 , 5 , 0 , 3 } ; int N = sizeof A / sizeof A [ 0 ] ; cout << XorSum ( A , B , N ) << endl ; return 0 ; }

Index/key variables: N, i
Accumulator variables: ans, count, i, k, stdc
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findCount ( int arr [ ] , int N , int K ) { sort ( arr , arr + N ) ; int result = 1 ; int cur_max = arr [ 0 ] ; int cur_min = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { cur_max = arr [ i ] ; if ( cur_max - cur_min > K ) { result ++ ; cur_max = arr [ i ] ; cur_min = arr [ i ] ; } } return result ; } int main ( ) { int arr [ ] = { 1 , 10 , 8 , 3 , 9 } ; int K = 3 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findCount ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, result, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define ll  long long
using namespace std ; const int mod = ( int ) 1e9 + 7 ; bool comp ( ll a , ll b ) { if ( a > b ) return true ; else return false ; } ll findMinValue ( vector < ll > & a , vector < ll > & b ) { int n = a . size ( ) ; vector < ll > pro ( n ) ; for ( int i = 0 ; i < n ; ++ i ) { pro [ i ] = ( ( ll ) ( i + 1 ) * ( ll ) ( n - i ) ) ; pro [ i ] *= ( 1LL * a [ i ] ) ; ; } sort ( b . begin ( ) , b . end ( ) , comp ) ; sort ( pro . begin ( ) , pro . end ( ) ) ; ll ans = 0 ; for ( int i = 0 ; i < n ; ++ i ) { ans += ( pro [ i ] % mod * b [ i ] ) % mod ; ans %= mod ; } return ans ; } int main ( ) { vector < ll > a = { 1 , 2 , 3 } ; vector < ll > b = { 2 , 3 , 2 } ; cout << findMinValue ( a , b ) << endl ; }

Index/key variables: i
Accumulator variables: ans, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findTriplets ( int ar [ ] , int n ) { unordered_map < int , int > mp ; for ( int x = 0 ; x < n ; x ++ ) mp [ ar [ x ] ] ++ ; priority_queue < pair < int , int > > pq ; for ( auto & pa : mp ) pq . push ( { pa . second , pa . first } ) ; vector < array < int , 3 > > ans ; while ( pq . size ( ) >= 3 ) { pair < int , int > ar [ 3 ] ; for ( int x = 0 ; x < 3 ; x ++ ) { ar [ x ] = pq . top ( ) ; pq . pop ( ) ; } ans . push_back ( { ar [ 0 ] . second , ar [ 1 ] . second , ar [ 2 ] . second } ) ; for ( int x = 0 ; x < 3 ; x ++ ) { ar [ x ] . first -- ; if ( ar [ x ] . first ) pq . push ( ar [ x ] ) ; } } cout << " Maximum ▁ number ▁ of ▁ " << " possible ▁ triples : ▁ " ; cout << ans . size ( ) << endl ; for ( auto & pa : ans ) { for ( int v : pa ) cout << v << " ▁ " ; cout << endl ; } } int main ( ) { int arr [ ] = { 2 , 2 , 3 , 3 , 4 , 4 , 4 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findTriplets ( arr , n ) ; return 0 ; }

Index/key variables: x
Accumulator variables: first, stdc, x
Iterator variables: v, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void rearrange ( int a [ ] , int N ) { int i = 0 , j = N - 1 ; int min = 0 , k , x = 0 , temp ; while ( i < j ) { for ( k = i ; k <= j ; k ++ ) { if ( a [ k ] < a [ min ] ) min = k ; } if ( x % 2 == 0 ) { temp = a [ i ] ; a [ i ] = a [ min ] ; a [ min ] = temp ; i ++ ; min = i ; } else { temp = a [ j ] ; a [ j ] = a [ min ] ; a [ min ] = temp ; j -- ; min = j ; } x ++ ; } for ( i = 0 ; i < N ; i ++ ) cout << a [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 1 , 3 , 3 , 4 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; rearrange ( arr , N ) ; return 0 ; }

Index/key variables: i, j, k, min
Accumulator variables: i, j, k, stdc, x
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; void redistribute ( int arr [ ] , int n , int x ) { sort ( arr , arr + n , greater < int > ( ) ) ; int i , sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( sum / ( i + 1 ) < x ) { cout << i << endl ; break ; } } if ( i == n ) cout << n << endl ; } int main ( ) { int arr [ ] = { 5 , 1 , 2 , 1 } ; int x = 3 ; redistribute ( arr , 4 , x ) ; return 0 ; }

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