dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  100
#define INF  1000000
int dp [ N ] [ N ] ; bool vis [ N ] [ N ] ; int findSum ( int * arr , int n , int k , int l , int r ) { if ( ( l ) + ( n - 1 - r ) == k ) return arr [ r ] - arr [ l ] ; if ( vis [ l ] [ r ] ) return dp [ l ] [ r ] ; vis [ l ] [ r ] = 1 ; return dp [ l ] [ r ] = min ( findSum ( arr , n , k , l , r - 1 ) , findSum ( arr , n , k , l + 1 , r ) ) ; } int32_t main ( ) { int arr [ ] = { 1 , 2 , 100 , 120 , 140 } ; int k = 2 ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << findSum ( arr , n , k , 0 , n - 1 ) ; }

Index/key variables: N, l, r
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getNumber ( int n , int k ) { int pos ; if ( n % 2 == 0 ) { pos = n / 2 ; } else { pos = ( n / 2 ) + 1 ; } if ( k <= pos ) { return ( k * 2 - 1 ) ; } else return ( ( k - pos ) * 2 ) ; } int main ( ) { int n = 8 , k = 5 ; cout << getNumber ( n , k ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void unique_combination ( int l , int sum , int K , vector < int > & local , vector < int > & A ) { if ( sum == K ) { cout << " { " ; for ( int i = 0 ; i < local . size ( ) ; i ++ ) { if ( i != 0 ) cout << " ▁ " ; cout << local [ i ] ; if ( i != local . size ( ) - 1 ) cout << " , ▁ " ; } cout << " } " << endl ; return ; } for ( int i = l ; i < A . size ( ) ; i ++ ) { if ( sum + A [ i ] > K ) continue ; if ( i > l and A [ i ] == A [ i - 1 ] ) continue ; local . push_back ( A [ i ] ) ; unique_combination ( i + 1 , sum + A [ i ] , K , local , A ) ; local . pop_back ( ) ; } } void Combination ( vector < int > A , int K ) { sort ( A . begin ( ) , A . end ( ) ) ; vector < int > local ; unique_combination ( 0 , 0 , K , local , A ) ; } int main ( ) { vector < int > A = { 10 , 1 , 2 , 7 , 6 , 1 , 5 } ; int K = 8 ; Combination ( A , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool compare ( string s1 , string s2 ) { return s1 . size ( ) > s2 . size ( ) ; } bool canbuildword ( string & s , bool isoriginalword , map < string , bool > & mp ) { if ( mp . find ( s ) != mp . end ( ) && mp [ s ] == 0 ) return false ; if ( mp . find ( s ) != mp . end ( ) && mp [ s ] == 1 && isoriginalword == 0 ) { return true ; } for ( int i = 1 ; i < s . length ( ) ; i ++ ) { string left = s . substr ( 0 , i ) ; string right = s . substr ( i ) ; if ( mp . find ( left ) != mp . end ( ) && mp [ left ] == 1 && canbuildword ( right , 0 , mp ) ) { return true ; } } mp [ s ] = 0 ; return false ; } string printlongestword ( vector < string > listofwords ) { map < string , bool > mp ; for ( string s : listofwords ) { mp [ s ] = 1 ; } sort ( listofwords . begin ( ) , listofwords . end ( ) , compare ) ; for ( string s : listofwords ) { if ( canbuildword ( s , 1 , mp ) ) return s ; } return " - 1" ; } int main ( ) { vector < string > listofwords = { " geeks " , " for " , " geeksfor " , " geeksforgeeks " } ; cout << printlongestword ( listofwords ) ; return 0 ; }

Index/key variables: left, s
Accumulator variables: i, stdc
Iterator variables: i, s
C++ program:
#include <bits/stdc++.h>
using namespace std ; int solution ( vector < int > & arr , int x ) { int closestSum = INT_MAX ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { for ( int j = i + 1 ; j < arr . size ( ) ; j ++ ) { for ( int k = j + 1 ; k < arr . size ( ) ; k ++ ) { if ( abs ( x - closestSum ) > abs ( x - ( arr [ i ] + arr [ j ] + arr [ k ] ) ) ) closestSum = ( arr [ i ] + arr [ j ] + arr [ k ] ) ; } } } return closestSum ; } int main ( ) { vector < int > arr = { -1 , 2 , 1 , -4 } ; int x = 1 ; cout << solution ( arr , x ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; void addEdge ( vector < int > adj [ ] , int u , int v ) { adj [ u ] . push_back ( v ) ; } void getindeg ( vector < int > adj [ ] , int V , vector < int > & indeg ) { for ( int i = 0 ; i < V ; i ++ ) { for ( auto x : adj [ i ] ) { indeg [ x ] ++ ; } } } vector < int > topo ( vector < int > adj [ ] , int V , vector < int > & indeg ) { queue < int > q ; for ( int i = 0 ; i < V ; i ++ ) { if ( indeg [ i ] == 0 ) q . push ( i ) ; } vector < int > res ; while ( ! q . empty ( ) ) { int u = q . front ( ) ; q . pop ( ) ; res . push_back ( u ) ; for ( auto x : adj [ u ] ) { indeg [ x ] -- ; if ( indeg [ x ] == 0 ) q . push ( x ) ; } } return res ; } vector < int > makearray ( vector < vector < int > > v , int V ) { vector < int > adj [ V ] ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) { for ( int j = 0 ; j < v [ i ] . size ( ) - 1 ; j ++ ) { addEdge ( adj , v [ i ] [ j ] , v [ i ] [ j + 1 ] ) ; } } vector < int > indeg ( V , 0 ) ; getindeg ( adj , V , indeg ) ; vector < int > res = topo ( adj , V , indeg ) ; return res ; } int main ( ) { int n = 10 ; vector < vector < int > > subseqs { { 9 , 1 , 2 , 8 , 3 } , { 6 , 1 , 2 } , { 9 , 6 , 3 , 4 } , { 5 , 2 , 7 } , { 0 , 9 , 5 , 4 } } ; vector < int > res = makearray ( subseqs , n ) ; for ( auto x : res ) { cout << x << " ▁ " ; } return 0 ; }

Index/key variables: V, i, j, u, x
Accumulator variables: i, j, stdc
Iterator variables: i, j, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long int
vector < ll > pr ; bool prime [ 10000000 + 1 ] ; void sieve ( ll n ) { for ( int i = 2 ; i <= n ; i += 1 ) { prime [ i ] = 1 ; } for ( ll p = 2 ; ( ll ) p * ( ll ) p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( ll i = ( ll ) p * ( ll ) p ; i <= n ; i += p ) prime [ i ] = false ; } } for ( ll p = 2 ; p <= n ; p ++ ) if ( prime [ p ] ) pr . push_back ( p ) ; } ll SemiPrimeSum ( ll N ) { ll ans = 0 ; for ( int i = 0 ; i < pr . size ( ) ; i += 1 ) { for ( int j = i ; j < pr . size ( ) ; j += 1 ) { if ( ( ll ) pr [ i ] * ( ll ) pr [ j ] > N ) break ; ans += ( ll ) pr [ i ] * ( ll ) pr [ j ] ; } } return ans ; } int main ( ) { ll N = 6 ; sieve ( N ) ; cout << SemiPrimeSum ( N ) ; return 0 ; }

Index/key variables: i, j, p
Accumulator variables: ans, i, j, p, stdc
Iterator variables: i, j, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; void compressArr ( int arr [ ] , int n ) { int i = 0 , j = 0 ; sort ( arr , arr + n ) ; while ( i < n ) { j = i ; while ( ( j + 1 < n ) && ( arr [ j + 1 ] == arr [ j ] + 1 ) ) { j ++ ; } if ( i == j ) { cout << arr [ i ] << " ▁ " ; i ++ ; } else { cout << arr [ i ] << " - " << arr [ j ] << " ▁ " ; i = j + 1 ; } } } int main ( ) { int n = 7 ; int arr [ n ] = { 1 , 3 , 4 , 5 , 6 , 9 , 10 } ; compressArr ( arr , n ) ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void removeElements ( int arr [ ] , int n ) { int brr [ n ] , l = 1 ; brr [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( brr [ l - 1 ] <= arr [ i ] ) { brr [ l ] = arr [ i ] ; l ++ ; } } for ( int i = 0 ; i < l ; i ++ ) cout << brr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 10 , 12 , 9 , 10 , 2 , 13 , 14 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; removeElements ( arr , n ) ; return 0 ; }

Index/key variables: i, l, n
Accumulator variables: i, l, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void removeElements ( int arr [ ] , int n ) { int l = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ l - 1 ] <= arr [ i ] ) { arr [ l ] = arr [ i ] ; l ++ ; } } for ( int i = 0 ; i < l ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 10 , 12 , 9 , 10 , 2 , 13 , 14 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; removeElements ( arr , n ) ; return 0 ; }

Index/key variables: i, l
Accumulator variables: i, l, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findX ( int a [ ] , int n ) { sort ( a , a + n ) ; int x = a [ 0 ] * a [ n - 1 ] ; vector < int > vec ; for ( int i = 2 ; i * i <= x ; i ++ ) { if ( x % i == 0 ) { vec . push_back ( i ) ; if ( ( x / i ) != i ) vec . push_back ( x / i ) ; } } sort ( vec . begin ( ) , vec . end ( ) ) ; if ( vec . size ( ) != n ) return -1 ; else { int i = 0 ; for ( auto it : vec ) { if ( a [ i ++ ] != it ) return -1 ; } } return x ; } int main ( ) { int a [ ] = { 2 , 5 , 4 , 10 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << findX ( a , n ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; void pendulumArrangement ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int odd , temp , in , pos ; pos = n - 1 ; if ( n % 2 == 0 ) odd = n - 1 ; else odd = n - 2 ; while ( odd > 0 ) { temp = arr [ odd ] ; in = odd ; while ( in != pos ) { arr [ in ] = arr [ in + 1 ] ; in ++ ; } arr [ in ] = temp ; odd = odd - 2 ; pos = pos - 1 ; } int start = 0 , end = ( n - 1 ) / 2 ; for ( ; start < end ; start ++ , end -- ) { temp = arr [ start ] ; arr [ start ] = arr [ end ] ; arr [ end ] = temp ; } for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 11 , 2 , 4 , 55 , 6 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; pendulumArrangement ( arr , n ) ; return 0 ; }

Index/key variables: end, i, in, odd, start
Accumulator variables: end, i, in, start, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right , * root ; Node ( int data ) { this -> data = data ; left = NULL ; right = NULL ; root = NULL ; } } ; Node * AddNode ( Node * root , int data ) { if ( root == NULL ) { root = new Node ( data ) ; return root ; } if ( root -> data < data ) root -> right = AddNode ( root -> right , data ) ; else if ( root -> data > data ) root -> left = AddNode ( root -> left , data ) ; return root ; } void TargetPair ( Node * node , int tar ) { vector < Node * > LeftList ; vector < Node * > RightList ; Node * curr_left = node ; Node * curr_right = node ; while ( curr_left != NULL || curr_right != NULL || LeftList . size ( ) > 0 && RightList . size ( ) > 0 ) { while ( curr_left != NULL ) { LeftList . push_back ( curr_left ) ; curr_left = curr_left -> left ; } while ( curr_right != NULL ) { RightList . push_back ( curr_right ) ; curr_right = curr_right -> right ; } Node * LeftNode = LeftList [ LeftList . size ( ) - 1 ] ; Node * RightNode = RightList [ RightList . size ( ) - 1 ] ; int leftVal = LeftNode -> data ; int rightVal = RightNode -> data ; if ( leftVal >= rightVal ) break ; if ( leftVal + rightVal < tar ) { LeftList . pop_back ( ) ; curr_left = LeftNode -> right ; } else if ( leftVal + rightVal > tar ) { RightList . pop_back ( ) ; curr_right = RightNode -> left ; } else { cout << LeftNode -> data << " ▁ " << RightNode -> data << endl ; RightList . pop_back ( ) ; LeftList . pop_back ( ) ; curr_left = LeftNode -> right ; curr_right = RightNode -> left ; } } } int main ( ) { Node * root = NULL ; root = AddNode ( root , 2 ) ; root = AddNode ( root , 6 ) ; root = AddNode ( root , 5 ) ; root = AddNode ( root , 3 ) ; root = AddNode ( root , 4 ) ; root = AddNode ( root , 1 ) ; root = AddNode ( root , 7 ) ; int sum = 8 ; TargetPair ( root , sum ) ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findNumber ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int max = arr [ n - 1 ] ; int table [ ( 2 * max ) + 1 ] ; table [ 0 ] = 0 ; for ( int i = 1 ; i < ( 2 * max ) + 1 ; i ++ ) table [ i ] = INT_MAX ; int ans = -1 ; for ( int i = 1 ; i < ( 2 * max ) + 1 ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ j ] <= i ) { int res = table [ i - arr [ j ] ] ; if ( res != INT_MAX && res + 1 < table [ i ] ) table [ i ] = res + 1 ; } } if ( i > arr [ n - 1 ] && table [ i ] == INT_MAX ) { ans = i ; break ; } } return ans ; } int main ( ) { int arr [ ] = { 6 , 7 , 15 } ; int n = ( sizeof ( arr ) / sizeof ( int ) ) ; cout << findNumber ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MOD  1000000007
#define ll  long long
#define max  101
ll C [ max - 1 ] [ max - 1 ] ; ll power ( ll x , unsigned ll y ) { unsigned ll res = 1 ; x = x % MOD ; while ( y > 0 ) { if ( y & 1 ) { res = ( res * x ) % MOD ; } y = y >> 1 ; x = ( x * x ) % MOD ; } return res % MOD ; } void combi ( int n , int k ) { int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= min ( i , k ) ; j ++ ) { if ( j == 0 j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] % MOD + C [ i - 1 ] [ j ] % MOD ) % MOD ; } } } unsigned ll product ( ll a [ ] , int n , int k ) { unsigned ll ans = 1 ; sort ( a , a + n ) ; ll powa = C [ n - 1 ] [ k - 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { ll powla = C [ i ] [ k - 1 ] ; ll powfa = C [ n - i - 1 ] [ k - 1 ] ; ll powe = ( ( powa % MOD ) - ( powla + powfa ) % MOD + MOD ) % MOD ; unsigned ll mul = power ( a [ i ] , powe ) % MOD ; ans = ( ( ans % MOD ) * ( mul % MOD ) ) % MOD ; } return ans % MOD ; } int main ( ) { combi ( 100 , 100 ) ; ll arr [ ] = { 1 , 2 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof arr [ 0 ] ; int k = 3 ; unsigned ll ans = product ( arr , n , k ) ; cout << ans << endl ; 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 makeEqualLength ( string & a , string & b ) { int len_a = a . length ( ) ; int len_b = b . length ( ) ; int num_zeros = abs ( len_a - len_b ) ; if ( len_a < len_b ) { for ( int i = 0 ; i < num_zeros ; i ++ ) { a = '0' + a ; } return len_b ; } else { for ( int i = 0 ; i < num_zeros ; i ++ ) { b = '0' + b ; } } return len_a ; } string andOperationBitwise ( string s1 , string s2 ) { int length = makeEqualLength ( s1 , s2 ) ; string res = " " ; for ( int i = 0 ; i < length ; i ++ ) { res = res + ( char ) ( ( s1 [ i ] - '0' & s2 [ i ] - '0' ) + '0' ) ; } return res ; } int main ( ) { string arr [ ] = { "101" , "110110" , "111" } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; string result ; if ( n < 2 ) { cout << arr [ n - 1 ] << endl ; return 0 ; } result = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { result = andOperationBitwise ( result , arr [ i ] ) ; } cout << result << endl ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countPoints ( int n , int m , vector < int > a , vector < int > b , int x , int y ) { sort ( a . begin ( ) , a . end ( ) ) ; sort ( b . begin ( ) , b . end ( ) ) ; int j = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { while ( j < m ) { if ( a [ i ] + y < b [ j ] ) break ; if ( b [ j ] >= a [ i ] - x && b [ j ] <= a [ i ] + y ) { count ++ ; j ++ ; break ; } else j ++ ; } } return count ; } int main ( ) { int x = 1 , y = 4 ; vector < int > a = { 1 , 5 } ; int n = a . size ( ) ; vector < int > b = { 1 , 1 , 2 } ; int m = a . size ( ) ; cout << countPoints ( n , m , a , b , x , y ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  4
void merge_and_sort ( int * output , int arr [ ] [ N ] , int n , int k ) { for ( int i = 0 ; i < k ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { output [ i * n + j ] = arr [ i ] [ j ] ; } } sort ( output , output + n * k ) ; } int main ( ) { int arr [ ] [ N ] = { { 5 , 7 , 15 , 18 } , { 1 , 8 , 9 , 17 } , { 1 , 4 , 7 , 7 } } ; int n = N ; int k = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int * output = new int [ n * k ] ; merge_and_sort ( output , arr , n , k ) ; for ( int i = 0 ; i < n * k ; i ++ ) cout << output [ i ] << " ▁ " ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperations ( int n , int m , int k , vector < vector < int > > & matrix ) { vector < int > arr ; int mod ; if ( matrix [ 0 ] [ 0 ] < 0 ) { mod = k - ( abs ( matrix [ 0 ] [ 0 ] ) % k ) ; } else { mod = matrix [ 0 ] [ 0 ] % k ; } for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { arr . push_back ( matrix [ i ] [ j ] ) ; int val = matrix [ i ] [ j ] ; if ( val < 0 ) { int res = k - ( abs ( val ) % k ) ; if ( res != mod ) { return -1 ; } } else { int foo = matrix [ i ] [ j ] ; if ( foo % k != mod ) { return -1 ; } } } } sort ( arr . begin ( ) , arr . end ( ) ) ; int median = arr [ ( n * m ) / 2 ] ; int minOperations = 0 ; for ( int i = 0 ; i < n * m ; ++ i ) minOperations += abs ( arr [ i ] - median ) / k ; if ( ( n * m ) % 2 == 0 ) { int median2 = arr [ ( ( n * m ) / 2 ) - 1 ] ; int minOperations2 = 0 ; for ( int i = 0 ; i < n * m ; ++ i ) minOperations2 += abs ( arr [ i ] - median2 ) / k ; minOperations = min ( minOperations , minOperations2 ) ; } return minOperations ; } int main ( ) { vector < vector < int > > matrix = { { 2 , 4 , 6 } , { 8 , 10 , 12 } , { 14 , 16 , 18 } , { 20 , 22 , 24 } } ; int n = matrix . size ( ) ; int m = matrix [ 0 ] . size ( ) ; int k = 2 ; cout << minOperations ( n , m , k , matrix ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: minOperations, minOperations2, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minSubarray ( int A [ ] , int n ) { int minValue = * min_element ( A , A + n ) ; int maxValue = * max_element ( A , A + n ) ; int pos_min = -1 , pos_max = -1 , ans = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { if ( A [ i ] == minValue ) pos_min = i ; if ( A [ i ] == maxValue ) pos_max = i ; if ( pos_max != -1 and pos_min != -1 ) ans = min ( ans , abs ( pos_min - pos_max ) + 1 ) ; } return ans ; } int main ( ) { int A [ ] = { 1 , 5 , 9 , 7 , 1 , 9 , 4 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << minSubarray ( A , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSequences ( int arr [ ] , int n ) { int count = 1 ; sort ( arr , arr + n ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ; return count ; } int main ( ) { int arr [ ] = { 1 , 7 , 3 , 5 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countSequences ( arr , n ) ; return 0 ; }

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

Index/key variables: i
Accumulator variables: i, operations, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printCase ( int n ) { if ( n <= 2 ) { cout << -1 ; return ; } for ( int i = n ; i >= 1 ; i -- ) cout << i << " ▁ " ; } int main ( ) { int n = 3 ; printCase ( n ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMissingNumber ( vector < pair < int , int > > ranges , int m ) { sort ( ranges . begin ( ) , ranges . end ( ) ) ; vector < int > ans ; int prev = 0 ; for ( int j = 0 ; j < ranges . size ( ) ; j ++ ) { int start = ranges [ j ] . first ; int end = ranges [ j ] . second ; for ( int i = prev + 1 ; i < start ; i ++ ) ans . push_back ( i ) ; prev = end ; } for ( int i = prev + 1 ; i <= m ; i ++ ) ans . push_back ( i ) ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { if ( ans [ i ] <= m ) cout << ans [ i ] << " ▁ " ; } } int main ( ) { int N = 2 , M = 6 ; vector < pair < int , int > > ranges ; ranges . push_back ( { 1 , 2 } ) ; ranges . push_back ( { 4 , 5 } ) ; findMissingNumber ( ranges , M ) ; 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 ; static bool check ( int n , int k , int * a , int * b ) { sort ( a , a + n ) ; sort ( b , b + n ) ; bool fl = false ; int ind = -1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] ) { if ( fl == true ) { return false ; } fl = true ; ind = i ; } } if ( ind == -1 | abs ( a [ ind ] - b [ ind ] ) <= k ) { return true ; } return false ; } int main ( ) { int n = 2 , k = 4 ; int a [ ] = { 1 , 5 } ; int b [ ] = { 1 , 1 } ; if ( check ( n , k , a , b ) ) { printf ( " Yes " ) ; } else { printf ( " No " ) ; } return 0 ; }

Index/key variables: i, ind
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: fl
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MOD  1000000007
int SubseqWidths ( int A [ ] , int n ) { sort ( A , A + n ) ; int pow2 [ n ] ; pow2 [ 0 ] = 1 ; for ( int i = 1 ; i < n ; ++ i ) pow2 [ i ] = ( pow2 [ i - 1 ] * 2 ) % MOD ; int ans = 0 ; for ( int i = 0 ; i < n ; ++ i ) ans = ( ans + ( pow2 [ i ] - pow2 [ n - 1 - i ] ) * A [ i ] ) % MOD ; return ans ; } int main ( ) { int A [ ] = { 5 , 6 , 4 , 3 , 8 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << SubseqWidths ( A , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: stdc
Iterator variables: i
C++ program:
# include <bits/stdc++.h>
using namespace std ; int maxArrayCover ( vector < int > a , int n , int x ) { sort ( a . begin ( ) , a . end ( ) ) ; int cc = 0 ; int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { s += a [ i ] ; if ( s > x ) { break ; } cc += 1 ; } if ( accumulate ( a . begin ( ) , a . end ( ) , 0 ) == x ) { return n ; } else { if ( cc == n ) { return n - 1 ; } else { return cc ; } } } int main ( ) { int n = 3 ; int x = 70 ; vector < int > a = { 10 , 20 , 30 } ; printf ( " % d STRNEWLINE " , maxArrayCover ( a , n , x ) ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cc, i, s, stdc
Iterator variables: i
C++ program:
#include <algorithm>
#include <iostream>
using namespace std ; void QRsort ( int arr [ ] , int size ) { int MAX = * max_element ( arr , arr + size ) ; int MIN = * min_element ( arr , arr + size ) ; cout << " Maximum ▁ Element ▁ found ▁ is ▁ : ▁ " << MAX << endl ; cout << " Minimum ▁ Element ▁ found ▁ is ▁ : ▁ " << MIN << endl ; int COL = MIN ; int ROW = MAX / MIN + 1 ; int matrix [ ROW ] [ COL ] = { 0 } ; for ( int i = 0 ; i < size ; i ++ ) { int quotient = arr [ i ] / MIN ; int remainder = arr [ i ] % MIN ; matrix [ quotient ] [ remainder + 1 ] = arr [ i ] ; } int k = 0 ; for ( int i = 0 ; i < ROW ; i ++ ) { for ( int j = 0 ; j < COL ; j ++ ) { if ( matrix [ i ] [ j ] != 0 ) { arr [ k ++ ] = matrix [ i ] [ j ] ; } } } } void printArray ( int arr [ ] , int size ) { for ( int i = 0 ; i < size ; i ++ ) cout << arr [ i ] << " ▁ " ; cout << endl ; } int main ( ) { int arr [ ] = { 5 , 3 , 7 , 4 , 8 , 2 , 6 } ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Initial ▁ Array ▁ : ▁ " << endl ; printArray ( arr , size ) ; QRsort ( arr , size ) ; cout << " Array ▁ after ▁ sorting ▁ : ▁ " << endl ; printArray ( arr , size ) ; }

Index/key variables: COL, ROW, i, j, quotient
Accumulator variables: i, j, k
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; struct Node { int data ; struct Node * next ; } ; bool isPairWiseSorted ( struct Node * head ) { bool flag = true ; struct Node * temp = head ; while ( temp != NULL && temp -> next != NULL ) { if ( temp -> data > temp -> next -> data ) { flag = false ; break ; } temp = temp -> next -> next ; } return flag ; } void push ( struct Node * * head_ref , int new_data ) { struct Node * new_node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; new_node -> data = new_data ; new_node -> next = ( * head_ref ) ; ( * head_ref ) = new_node ; } int main ( ) { struct Node * start = NULL ; push ( & start , 5 ) ; push ( & start , 1 ) ; push ( & start , 9 ) ; push ( & start , 9 ) ; push ( & start , 15 ) ; push ( & start , 10 ) ; if ( isPairWiseSorted ( start ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }

Boolean variables: flag
Class/struct names: Node