dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; void solve ( long long n ) { long long initial_array [ n - 1 ] [ n - 1 ] , final_array [ n ] [ n ] ; for ( long long i = 0 ; i < n - 1 ; ++ i ) initial_array [ 0 ] [ i ] = i + 1 ; for ( long long i = 1 ; i < n - 1 ; ++ i ) for ( long long j = 0 ; j < n - 1 ; ++ j ) initial_array [ i ] [ j ] = initial_array [ i - 1 ] [ ( j + 1 ) % ( n - 1 ) ] ; for ( long long i = 0 ; i < n - 1 ; ++ i ) for ( long long j = 0 ; j < n - 1 ; ++ j ) final_array [ i ] [ j ] = initial_array [ i ] [ j ] ; for ( long long i = 0 ; i < n ; ++ i ) final_array [ i ] [ n - 1 ] = final_array [ n - 1 ] [ i ] = 0 ; for ( long long i = 0 ; i < n ; ++ i ) { long long t0 = final_array [ i ] [ i ] ; long long t1 = final_array [ i ] [ n - 1 ] ; swap ( final_array [ i ] [ i ] , final_array [ i ] [ n - 1 ] ) ; final_array [ n - 1 ] [ i ] = t0 ; } for ( long long i = 0 ; i < n ; ++ i ) { for ( long long j = 0 ; j < n ; ++ j ) cout << final_array [ i ] [ j ] << " ▁ " ; cout << endl ; } } int main ( ) { long long n = 5 ; solve ( n ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findPerm ( int n , vector < int > & differences ) { vector < int > ans ; ans . clear ( ) ; ans . push_back ( 0 ) ; int x = 0 ; for ( int i = 0 ; i <= n - 2 ; ++ i ) { int diff = differences [ i ] ; x = x + diff ; ans . push_back ( x ) ; } vector < int > anss = ans ; sort ( ans . begin ( ) , ans . end ( ) ) ; int flag = -1 ; for ( int i = 1 ; i <= n - 1 ; ++ i ) { int res = ans [ i ] - ans [ i - 1 ] ; if ( res != 1 ) { flag = 0 ; } } if ( flag == 0 ) { cout << -1 ; return ; } else { unordered_map < int , int > mpp ; mpp . clear ( ) ; int j = 1 ; vector < int > value_at_index ; for ( auto & x : ans ) { mpp [ x ] = j ; ++ j ; } for ( auto & x : anss ) { value_at_index . push_back ( mpp [ x ] ) ; } for ( auto & x : value_at_index ) { cout << x << " ▁ " ; } cout << endl ; } } int main ( ) { vector < int > differences ; differences . push_back ( 2 ) ; differences . push_back ( -3 ) ; differences . push_back ( 2 ) ; int n = differences . size ( ) + 1 ; findPerm ( n , differences ) ; return 0 ; }

Index/key variables: i, x
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getMinVal ( int p , int q ) { if ( q % p == 0 ) return p ; return -1 ; } int main ( ) { int p = 24 , q = 48 ; cout << getMinVal ( p , q ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sumOfDigit ( int n ) { int sum = 0 ; while ( n > 0 ) { sum += n % 10 ; n = n / 10 ; } return sum ; } void sortArr ( int arr [ ] , int n ) { vector < pair < int , int > > vp ; for ( int i = 0 ; i < n ; i ++ ) { vp . push_back ( make_pair ( sumOfDigit ( 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 [ ] = { 14 , 1101 , 10 , 35 , 0 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortArr ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPalindrome ( string str , int i , int j ) { while ( i < j ) { if ( str [ i ] != str [ j ] ) return false ; i ++ ; j -- ; } return true ; } int countPrimePalindrome ( string str , int len ) { bool prime [ len + 1 ] ; memset ( prime , true , sizeof ( prime ) ) ; prime [ 0 ] = prime [ 1 ] = false ; for ( int p = 2 ; p * p <= len ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * p ; i <= len ; i += p ) prime [ i ] = false ; } } int count = 0 ; for ( int j = 2 ; j <= len ; j ++ ) { if ( prime [ j ] ) { for ( int i = 0 ; i + j - 1 < len ; i ++ ) { if ( isPalindrome ( str , i , i + j - 1 ) ) count ++ ; } } } return count ; } int main ( ) { string s = " geeksforgeeks " ; int len = s . length ( ) ; cout << countPrimePalindrome ( s , len ) ; return 0 ; }

Index/key variables: i, j, p
Accumulator variables: count, i, j, p, stdc
Iterator variables: i, j, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperations ( int N ) { double x = log2 ( N ) ; int ans = ceil ( x ) ; return ans ; } int main ( ) { int N = 10 ; cout << minOperations ( N ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int find_greatest_divisor ( int l , int r ) { if ( l == r ) return l ; return 1 ; } int main ( ) { int l = 2 , r = 12 ; cout << find_greatest_divisor ( l , r ) ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; double getProbability ( double p , double q ) { p /= 100 ; q /= 100 ; double probability = ( p * p + q * q ) / ( p + q ) ; return probability ; } int main ( ) { double p , q ; p = 80 ; q = 40 ; cout << fixed << setprecision ( 15 ) << getProbability ( p , q ) << endl ; return 0 ; }

Accumulator variables: p, q, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool check ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] & 1 ) return true ; } return false ; } int main ( ) { int arr [ ] = { 3 , 9 , 12 , 13 , 15 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( check ( arr , n ) ) cout << " Odd ▁ Bit - wise ▁ OR " ; else cout << " Even ▁ Bit - wise ▁ OR " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits / stdc++.h>
using namespace std ; int main ( ) { char str [ ] = "10010111" ; int length = strlen ( str ) ; int i = length - 1 ; while ( str [ i ] == '1' ) { str [ i ] = '0' ; i -- ; } if ( i >= 0 ) str [ i ] = '1' ; printf ( " % ▁ s " , str ) ; }

Index/key variables: i
Accumulator variables: i, stdc
C++ program:
#include <iostream>
#include <time.h>
using namespace std ; int main ( ) { int n = 800000 ; clock_t t = clock ( ) ; long long int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += i ; t = clock ( ) - t ; cout << " sum ▁ is : ▁ " << sum << endl ; cout << " time ▁ taken ▁ by ▁ normal ▁ loops : " " ( float ) t ▁ / ▁ CLOCKS _ PER _ SEC ▁ < < ▁ " seconds " << endl ; t = clock ( ) ; sum = 0 ; for ( int i = 1 ; i <= n ; i += 8 ) { sum += i sum += ( i + 1 ) ; sum += ( i + 2 ) ; sum += ( i + 3 ) ; sum += ( i + 4 ) ; sum += ( i + 5 ) ; sum += ( i + 6 ) ; sum += ( i + 7 ) ; } t = clock ( ) - t ; cout << " Sum ▁ is : ▁ " << sum << endl ; cout << " Time ▁ taken ▁ by ▁ unrolling : ▁ " " ( float ) t ▁ / ▁ CLOCKS _ PER _ SEC ▁ < < ▁ " seconds " return 0 ; }

Accumulator variables: i, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int _log ( double x , double base ) { return ( int ) ( log ( x ) / log ( base ) ) ; } double recursiveLogStar ( double n , double b ) { if ( n > 1.0 ) return 1.0 + recursiveLogStar ( _log ( n , b ) , b ) ; else return 0 ; } int main ( ) { int n = 100 , base = 5 ; cout << " Log * ( " << n << " ) ▁ = ▁ " << recursiveLogStar ( n , base ) << " STRNEWLINE " ; return 0 ; }

Accumulator variables: stdc
C++ program:
int iterativeLogStar ( double n , double b ) { int count = 0 ; while ( n >= 1 ) { n = _log ( n , b ) ; count ++ ; } return count ; }

Accumulator variables: count
C++ program:
void function ( int n ) { int count = 0 ; for ( int i = n / 2 ; i <= n ; i ++ ) for ( int j = 1 ; j <= n ; j = 2 * j ) for ( int k = 1 ; k <= n ; k = k * 2 ) count ++ ; }

Accumulator variables: count, i
Iterator variables: i, j, k
C++ program:
#include " bits / stdc + + . h "
using namespace std ; int findMaximum ( int arr [ ] , int size ) { int i = 0 , j = size - 1 , mid ; while ( i <= j ) { mid = i + ( j - i ) / 2 ; if ( arr [ mid ] < 0 ) i = mid + 1 ; else if ( arr [ mid ] > 0 ) j = mid - 1 ; } return max ( i , size - i ) ; } int main ( ) { int arr [ ] = { -9 , -7 , -4 , 1 , 5 , 8 , 9 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMaximum ( arr , N ) ; return 0 ; }

Index/key variables: mid
C++ program:
#include <bits/stdc++.h>
using namespace std ; void solve ( int n , int m , int * * queries ) { int countE1 = 0 ; set < int > removed ; for ( int i = 0 ; i < m ; i ++ ) { if ( queries [ i ] [ 0 ] == 1 ) ++ countE1 ; else if ( queries [ i ] [ 0 ] == 2 ) removed . insert ( queries [ i ] [ 1 ] ) ; else { int position = queries [ i ] [ 1 ] - countE1 ; if ( removed . find ( queries [ i ] [ 1 ] ) != removed . end ( ) position <= 0 ) cout << " - 1 STRNEWLINE " ; else { for ( int it : removed ) { if ( it > queries [ i ] [ 1 ] ) break ; position -- ; } cout << position << " STRNEWLINE " ; } } } } int main ( ) { int N = 5 , Q = 3 ; int * * queries = new int * [ Q ] ; for ( int i = 0 ; i < Q ; i ++ ) { queries [ i ] = new int [ 2 ] ; } queries [ 0 ] [ 0 ] = 1 ; queries [ 0 ] [ 1 ] = 0 ; queries [ 1 ] [ 0 ] = 3 ; queries [ 1 ] [ 1 ] = 3 ; queries [ 2 ] [ 0 ] = 2 ; queries [ 2 ] [ 1 ] = 2 ; solve ( N , Q , queries ) ; return 0 ; }

Index/key variables: Q, i
Accumulator variables: i, position, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxIndex ( int N , int B ) { int maximumIndexReached = 0 ; vector < int > Ans ; for ( int i = 1 ; i <= N ; i ++ ) { maximumIndexReached += i ; Ans . push_back ( i ) ; } reverse ( Ans . begin ( ) , Ans . end ( ) ) ; for ( int i = 1 ; i < ( int ) Ans . size ( ) ; i ++ ) { Ans [ i ] += Ans [ i - 1 ] ; } while ( maximumIndexReached ) { auto it = lower_bound ( Ans . begin ( ) , Ans . end ( ) , maximumIndexReached - B ) ; if ( it == Ans . end ( ) ) { break ; } if ( * it == maximumIndexReached - B ) { maximumIndexReached -- ; } else { break ; } } return maximumIndexReached ; } int main ( ) { int N = 3 , B = 2 ; cout << maxIndex ( N , B ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, maximumIndexReached, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; double maxKth ( int arr [ ] , int N , int C , int K ) { if ( N + C < K ) { return -1 ; } int iter = 300 ; double l = 0 , r = 1000000000.0 ; while ( iter -- ) { double mid = ( l + r ) * 0.5 ; double a = 0 ; double b = 0 ; for ( int i = 0 ; i < N ; i ++ ) { a += int ( ( double ) arr [ i ] / mid ) ; if ( ( double ) arr [ i ] >= mid ) { b ++ ; } } if ( a >= K && b + C >= K ) { l = mid ; } else { r = mid ; } } return l ; } int main ( ) { int arr [ ] = { 5 , 8 } ; int K = 1 , C = 1 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxKth ( arr , N , C , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: a, b, i, iter, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPossibleToSelect ( int arr [ ] , int N , int dif , int K ) { int count = 1 ; int prev = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] >= ( prev + dif ) ) { count ++ ; if ( count == K ) return true ; prev = arr [ i ] ; } } return false ; } int binarySearch ( int arr [ ] , int left , int right , int K , int N ) { int ans = 1 ; while ( left <= right ) { int dif = left + ( right - left ) / 2 ; if ( isPossibleToSelect ( arr , N , dif , K ) ) { ans = max ( ans , dif ) ; left = dif + 1 ; } else right = dif - 1 ; } return ans ; } int main ( ) { int N , K ; N = 7 , K = 4 ; int arr [ ] = { 1 , 4 , 9 , 0 , 2 , 13 , 3 } ; sort ( arr , arr + N ) ; cout << binarySearch ( arr , 0 , arr [ N - 1 ] , K , N ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int cal ( vector < int > arr , int mid ) { int chocolate = 0 ; for ( auto i : arr ) { if ( i >= mid ) chocolate += i - mid ; } return chocolate ; } int maximumCut ( vector < int > arr , int K ) { int low = 0 ; int high = * max_element ( arr . begin ( ) , arr . end ( ) ) ; while ( low <= high ) { int mid = ( low + high ) / 2 ; int chocolate = cal ( arr , mid ) ; if ( chocolate == K ) return mid ; else if ( chocolate < K ) high = mid - 1 ; else { low = mid + 1 ; if ( mid > high ) high = mid ; } } return high ; } int main ( ) { int N = 4 ; int K = 7 ; vector < int > arr { 15 , 20 , 8 , 17 } ; cout << ( maximumCut ( arr , K ) ) ; }

Accumulator variables: chocolate, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < vector < int > > edges ; void add_edge ( int x , int y ) { edges . push_back ( { x , y } ) ; } vector < int > merge ( vector < int > & a , vector < int > & b ) { vector < int > res ; int i = 0 , j = 0 ; int n = a . size ( ) , m = b . size ( ) ; while ( i < n && j < m ) { if ( a [ i ] < b [ j ] ) res . push_back ( a [ i ++ ] ) ; else if ( b [ j ] < a [ i ] ) res . push_back ( b [ j ++ ] ) ; } while ( i < n ) res . push_back ( a [ i ++ ] ) ; while ( j < m ) res . push_back ( b [ j ++ ] ) ; return res ; } vector < int > help ( vector < int > tree [ ] , int x , int p , vector < int > & c , vector < int > & sol ) { vector < int > res ; res . push_back ( c [ x ] ) ; for ( auto i : tree [ x ] ) { if ( i != p ) { vector < int > tmp = help ( tree , i , x , c , sol ) ; res = merge ( res , tmp ) ; } } int l = 0 , r = res . size ( ) - 1 ; int ans = res . size ( ) ; while ( l <= r ) { int mid = ( l + r ) / 2 ; if ( res [ mid ] > mid ) r = mid - 1 ; else { ans = mid + 1 ; l = mid + 1 ; } } if ( res [ 0 ] != 0 ) ans = 0 ; sol [ x ] = ans ; return res ; } void solve ( int A , vector < int > C ) { int n = A ; vector < int > tree [ n + 1 ] ; for ( auto i : edges ) { tree [ i [ 0 ] ] . push_back ( i [ 1 ] ) ; tree [ i [ 1 ] ] . push_back ( i [ 0 ] ) ; } vector < int > sol ( n , 0 ) ; help ( tree , 0 , -1 , C , sol ) ; for ( auto i : sol ) cout << i << " ▁ " ; } int main ( ) { int N = 6 ; add_edge ( 0 , 1 ) ; add_edge ( 1 , 2 ) ; add_edge ( 0 , 3 ) ; add_edge ( 3 , 4 ) ; add_edge ( 3 , 5 ) ; vector < int > val = { 4 , 3 , 5 , 1 , 0 , 2 } ; solve ( N , val ) ; return 0 ; }

Index/key variables: i, j, mid, x
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool check ( vector < int > & bananas , int mid_val , int H ) { int time = 0 ; for ( int i = 0 ; i < bananas . size ( ) ; i ++ ) { if ( bananas [ i ] % mid_val != 0 ) { time += ( ( bananas [ i ] / mid_val ) + 1 ) ; } else { time += ( bananas [ i ] / mid_val ) ; } } if ( time <= H ) { return true ; } else { return false ; } } int minEatingSpeed ( vector < int > & piles , int H ) { int start = 1 ; int end = * max_element ( piles . begin ( ) , piles . end ( ) ) ; while ( start < end ) { int mid = start + ( end - start ) / 2 ; if ( ( check ( piles , mid , H ) ) == true ) { end = mid ; } else { start = mid + 1 ; } } return end ; } int main ( ) { vector < int > piles = { 30 , 11 , 23 , 4 , 20 } ; int H = 6 ; cout << minEatingSpeed ( piles , H ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, time
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minSumPair ( int arr [ ] , int N ) { if ( N < 5 ) { return -1 ; } int prefixMin [ N ] ; prefixMin [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < N - 1 ; i ++ ) { prefixMin [ i ] = min ( arr [ i ] , prefixMin [ i - 1 ] ) ; } int ans = INT_MAX ; for ( int i = 3 ; i < N - 1 ; i ++ ) { ans = min ( ans , arr [ i ] + prefixMin [ i - 2 ] ) ; } return ans ; } int main ( ) { int arr [ ] = { 5 , 2 , 4 , 6 , 3 , 7 } ; int N = sizeof ( arr ) / sizeof ( int ) ; cout << minSumPair ( arr , N ) << endl ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; long check ( long H [ ] , long A [ ] , long mid , long N , long M , long L ) { long sum = 0 ; for ( long i = 0 ; i < N ; i ++ ) { long speed = mid * A [ i ] + H [ i ] ; if ( speed >= L ) { sum += speed ; } } return sum ; } long buzzTime ( long N , long M , long L , long H [ ] , long A [ ] ) { long low = 0 , high = 1e10 ; long ans = 0 ; while ( high >= low ) { long mid = low + ( high - low ) / 2 ; if ( check ( H , A , mid , N , M , L ) >= M ) { ans = mid ; high = mid - 1 ; } else low = mid + 1 ; } return ans ; } int main ( ) { long M = 400 , L = 120 ; long H [ ] = { 20 , 50 , 20 } ; long A [ ] = { 20 , 70 , 90 } ; long N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << buzzTime ( N , M , L , H , A ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findCount ( string number ) { int sum = 0 ; for ( int i = 0 ; i < number . length ( ) ; ++ i ) { sum += number [ i ] - 48 ; } int count = 0 ; for ( int i = 0 ; i < number . length ( ) ; ++ i ) { int remaining_sum = sum - ( number [ i ] - 48 ) ; for ( int j = 0 ; j <= 9 ; ++ j ) { if ( ( remaining_sum + j ) % 3 == 0 && j != number [ i ] - 48 ) { ++ count ; } } } cout << count ; } int main ( ) { string number = "235" ; findCount ( number ) ; }

Index/key variables: i
Accumulator variables: stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool is_possible ( vector < int > & teams , int T , int k ) { int sum = 0 ; for ( int i = 0 ; i < teams . size ( ) ; i ++ ) { sum += min ( T , teams [ i ] ) ; } return ( sum >= ( T * k ) ) ; } int countOfTeams ( vector < int > & teams_list , int N , int K ) { int lb = 0 , ub = 1e9 ; while ( lb <= ub ) { int mid = lb + ( ub - lb ) / 2 ; if ( is_possible ( teams_list , mid , K ) ) { if ( ! is_possible ( teams_list , mid + 1 , K ) ) { return mid ; } else { lb = mid + 1 ; } } else { ub = mid - 1 ; } } return 0 ; } int main ( ) { vector < int > arr = { 2 , 3 , 4 } ; int K = 2 ; int N = arr . size ( ) ; cout << countOfTeams ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minimumOperations ( int arr [ ] , int N ) { int mx = 0 , pos = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= mx ) { mx = arr [ i ] ; pos = i ; } } cout << ( mx - 1 ) * N + pos + 1 ; } int main ( ) { int arr [ ] = { 2 , 0 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; minimumOperations ( arr , N ) ; 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
ll n , m , k , l , r , i ; ll check ( ll v , vector < ll > & a ) { ll tec = 0 , ans = 0 ; vector < ll > b ( n + k + 1 ) ; for ( i = 0 ; i < n ; i ++ ) { tec -= b [ i ] ; if ( a [ i ] + tec < v ) { ll mov = v - a [ i ] - tec ; ans = ans + mov ; tec += mov ; b [ i + k ] = mov ; } } return ( ans <= m ) ; } ll FindLargest ( vector < ll > a ) { l = 1 ; r = pow ( 10 , 10 ) ; while ( r - l > 0 ) { ll tm = ( l + r + 1 ) / 2 ; if ( check ( tm , a ) ) l = tm ; else r = tm - 1 ; } return l ; } int main ( ) { vector < ll > a { 2 , 2 , 2 , 2 , 1 , 1 } ; m = 2 ; k = 3 ; n = a . size ( ) ; cout << FindLargest ( a ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, tec
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int largestAltitude ( int L , int B ) { if ( L > B ) { swap ( B , L ) ; } int low = 0 , high = L ; int res = 0 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( mid <= ( B / 2 ) ) { res = mid ; low = mid + 1 ; } else high = mid - 1 ; } return res ; } int main ( ) { int L = 3 ; int B = 4 ; cout << largestAltitude ( L , B ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printFreq ( vector < int > & arr , int N ) { int freq = 1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] ) { freq ++ ; } else { cout << " Frequency ▁ of ▁ " << arr [ i - 1 ] << " ▁ is : ▁ " << freq << endl ; freq = 1 ; } } cout << " Frequency ▁ of ▁ " << arr [ N - 1 ] << " ▁ is : ▁ " << freq << endl ; } int main ( ) { vector < int > arr = { 1 , 1 , 1 , 2 , 3 , 3 , 5 , 5 , 8 , 8 , 8 , 9 , 9 , 10 } ; int N = arr . size ( ) ; printFreq ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: freq, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countPairSum ( int arr [ ] , int L , int R , int N ) { sort ( arr , arr + N ) ; int right = N - 1 , count = 0 ; while ( right > 0 ) { auto it1 = lower_bound ( arr , arr + N , L - arr [ right ] ) ; int start = it1 - arr ; auto it2 = upper_bound ( arr , arr + N , R - arr [ right ] ) ; -- it2 ; int end = it2 - arr ; end = min ( end , right - 1 ) ; if ( end - start >= 0 ) { count += ( end - start + 1 ) ; } right -- ; } return count ; } int main ( ) { int arr [ ] = { 5 , 1 , 2 , 4 , 3 } ; int L = 5 , R = 8 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countPairSum ( arr , L , R , N ) ; return 0 ; }

Index/key variables: right
Accumulator variables: count, right, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isMaximumMedian ( vector < vector < int > > & arr , int N , int K , int mid ) { vector < vector < int > > Pre ( N + 5 , vector < int > ( N + 5 , 0 ) ) ; for ( int i = 0 ; i < N ; ++ i ) { for ( int j = 0 ; j < N ; ++ j ) { Pre [ i + 1 ] [ j + 1 ] = Pre [ i + 1 ] [ j ] + Pre [ i ] [ j + 1 ] - Pre [ i ] [ j ] ; if ( arr [ i ] [ j ] <= mid ) Pre [ i + 1 ] [ j + 1 ] ++ ; } } int required = ( K * K + 1 ) / 2 ; bool flag = 0 ; for ( int i = K ; i <= N ; ++ i ) { for ( int j = K ; j <= N ; ++ j ) { int X = Pre [ i ] [ j ] - Pre [ i - K ] [ j ] - Pre [ i ] [ j - K ] + Pre [ i - K ] [ j - K ] ; if ( X < required ) flag = 1 ; } } return flag ; } int maximumMedian ( vector < vector < int > > & arr , int N , int K ) { int low = 0 , high = 1e9 ; while ( low < high ) { int mid = low + ( high - low ) / 2 ; if ( isMaximumMedian ( arr , N , K , mid ) ) { low = mid + 1 ; } else { high = mid ; } } return low ; } int main ( ) { vector < vector < int > > arr = { { 1 , 5 , 12 } , { 6 , 7 , 11 } , { 8 , 9 , 10 } } ; int N = arr . size ( ) ; int K = 2 ; cout << maximumMedian ( arr , N , K ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMinDays ( int arr [ ] , int R [ ] , int N , int X , int K ) { int low = 0 , high = X ; int minDays ; while ( low <= high ) { int mid = ( low + high ) / 2 ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int temp = arr [ i ] + R [ i ] * mid ; if ( temp >= K ) { sum += temp ; } } if ( sum >= X ) { minDays = mid ; high = mid - 1 ; } else { low = mid + 1 ; } } cout << minDays ; } int main ( ) { int X = 100 , K = 45 ; int arr [ ] = { 2 , 5 , 2 , 6 } ; int R [ ] = { 10 , 13 , 15 , 12 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findMinDays ( arr , R , N , X , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getPairsCount ( int a [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( ( a [ i ] * a [ j ] ) == abs ( i - j ) ) count ++ ; } } return count ; } int main ( ) { int arr [ ] = { 1 , 1 , 2 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << getPairsCount ( arr , N ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; string lexicographicallySmallestString ( string S , int N ) { int LastZe = -1 ; string ans ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( S [ i ] == '0' ) { LastZe = i ; break ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( i <= LastZe && S [ i ] == '0' ) ans += S [ i ] ; else if ( i > LastZe ) ans += S [ i ] ; } return ans ; } int main ( ) { string S = "11001101" ; int N = S . size ( ) ; cout << lexicographicallySmallestString ( S , N ) ; return 0 ; }

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