dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Query { int L , R ; } ; void fillPrefixArray ( int arr [ ] , int n , int prefixArray [ ] ) { prefixArray [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { prefixArray [ i ] = prefixArray [ i - 1 ] + arr [ i ] ; } else { prefixArray [ i ] = prefixArray [ i - 1 ] - arr [ i ] ; } } } int findResultUtil ( int prefixArray [ ] , int L , int R ) { int result ; if ( L == 0 ) { result = prefixArray [ R ] ; } else { result = prefixArray [ R ] - prefixArray [ L - 1 ] ; } if ( L & 1 ) { result = result * ( -1 ) ; } return result ; } void findResult ( int arr [ ] , int n , Query q [ ] , int m ) { int prefixArray [ n ] ; fillPrefixArray ( arr , n , prefixArray ) ; for ( int i = 0 ; i < m ; i ++ ) { cout << findResultUtil ( prefixArray , q [ i ] . L , q [ i ] . R ) << " ▁ " ; } } int main ( ) { int arr [ ] = { 10 , 13 , 15 , 2 , 45 , 31 , 22 , 3 , 27 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; Query q [ ] = { { 2 , 5 } , { 6 , 8 } , { 1 , 7 } , { 4 , 8 } , { 0 , 5 } } ; int m = sizeof ( q ) / sizeof ( q [ 0 ] ) ; findResult ( arr , n , q , m ) ; return 0 ; }

Index/key variables: R, i, n
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Query
C++ program:
#include <bits/stdc++.h>
using namespace std ; int validSubArrLength ( int arr [ ] , int N , int K ) { int dp [ N + 1 ] ; int pos = 0 ; int ans = 0 ; int mx = 0 ; int pre = 0 ; deque < int > q ; for ( int i = 0 ; i < N ; i ++ ) { while ( ! q . empty ( ) && arr [ q . back ( ) ] < arr [ i ] ) q . pop_back ( ) ; q . push_back ( i ) ; if ( i == 0 ) { mx = arr [ i ] ; dp [ i ] = arr [ i ] ; } else if ( mx <= arr [ i ] ) { dp [ i ] = dp [ i - 1 ] + arr [ i ] ; mx = arr [ i ] ; } else { dp [ i ] = dp [ i - 1 ] + arr [ i ] ; } if ( pre == 0 ) pos = 0 ; else pos = pre - 1 ; while ( ( i - pre + 1 ) * mx - ( dp [ i ] - dp [ pos ] ) > K && pre < i ) { pos = pre ; pre ++ ; while ( ! q . empty ( ) && q . front ( ) < pre && pre < i ) { q . pop_front ( ) ; mx = arr [ q . front ( ) ] ; } } ans = max ( ans , i - pre + 1 ) ; } return ans ; } int main ( ) { int N = 6 ; int K = 8 ; int arr [ ] = { 2 , 7 , 1 , 3 , 4 , 5 } ; cout << validSubArrLength ( arr , N , K ) ; return 0 ; }

Index/key variables: i, pos
Accumulator variables: i, pre, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isKPartitionPossible ( int arr [ ] , int N , int K ) { if ( K == 1 ) return true ; if ( N < K ) return false ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; if ( sum % K != 0 ) return false ; int target = sum / K ; int dp [ ( 1 << 15 ) ] ; for ( int i = 0 ; i < ( 1 << N ) ; i ++ ) dp [ i ] = -1 ; dp [ 0 ] = 0 ; for ( int mask = 0 ; mask < ( 1 << N ) ; mask ++ ) { if ( dp [ mask ] == -1 ) continue ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! ( mask & ( 1 << i ) ) && dp [ mask ] + arr [ i ] <= target ) { dp [ mask ( 1 << i ) ] = ( dp [ mask ] + arr [ i ] ) % target ; } } } if ( dp [ ( 1 << N ) - 1 ] == 0 ) return true ; else return false ; } int main ( ) { int arr [ ] = { 2 , 1 , 4 , 5 , 3 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 3 ; if ( isKPartitionPossible ( arr , N , K ) ) { cout << " Partitions ▁ into ▁ equal ▁ " ; cout << " sum ▁ is ▁ possible . STRNEWLINE " ; } else { cout << " Partitions ▁ into ▁ equal ▁ " ; cout << " sum ▁ is ▁ not ▁ possible . STRNEWLINE " ; } }

Index/key variables: i, mask
Accumulator variables: i, mask, stdc, sum
Iterator variables: i, mask
C++ program:
#include <bits/stdc++.h>
using namespace std ; const long long MAX = 1e18 ; long long n , m ; vector < long long > v [ 151 ] ; long long dp [ 151 ] [ 151 ] ; long long min_operation ( long long i , long long j , long long val , long long x ) { if ( i == n - 1 && j == m - 1 ) { if ( val > v [ i ] [ j ] ) { return dp [ i ] [ j ] = MAX ; } else { return dp [ i ] [ j ] = v [ i ] [ j ] - val ; } } if ( i == n j == m ) { return dp [ i ] [ j ] = MAX ; } if ( dp [ i ] [ j ] != -1 ) { return dp [ i ] [ j ] ; } if ( val > v [ i ] [ j ] ) { return dp [ i ] [ j ] = MAX ; } long long tmp = v [ i ] [ j ] - val ; tmp += min ( min_operation ( i + 1 , j , val + x , x ) , min_operation ( i , j + 1 , val + x , x ) ) ; return dp [ i ] [ j ] = tmp ; } long long solve ( long long x ) { long long ans = INT64_MAX ; for ( long long i = 0 ; i < n ; i ++ ) { for ( long long j = 0 ; j < m ; j ++ ) { long long val = v [ i ] [ j ] - x * ( i + j ) ; memset ( dp , -1 , sizeof ( dp ) ) ; val = min_operation ( 0 , 0 , val , x ) ; ans = min ( ans , val ) ; } } return ans ; } int main ( ) { n = 2 , m = 2 ; long long x = 3 ; v [ 0 ] = { 15 , 153 } ; v [ 1 ] = { 135 , 17 } ; cout << solve ( x ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, tmp
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int printAllSubsetsRec ( int arr [ ] , int n , vector < int > v , int sum ) { if ( sum == 0 ) { return ( int ) v . size ( ) ; } if ( sum < 0 ) return INT_MAX ; if ( n == 0 ) return INT_MAX ; int x = printAllSubsetsRec ( arr , n - 1 , v , sum ) ; v . push_back ( arr [ n - 1 ] ) ; int y = printAllSubsetsRec ( arr , n , v , sum - arr [ n - 1 ] ) ; return min ( x , y ) ; } int printAllSubsets ( int arr [ ] , int n , int sum ) { vector < int > v ; return printAllSubsetsRec ( arr , n , v , sum ) ; } int main ( ) { int arr [ ] = { 2 , 1 , 4 , 3 , 5 , 6 } ; int sum = 6 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << printAllSubsets ( arr , n , sum ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Count ( int S [ ] , int m , int n ) { vector < vector < int > > table ( m + 1 , vector < int > ( n + 1 , 0 ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { table [ 0 ] [ i ] = INT_MAX - 1 ; } for ( int i = 1 ; i <= m ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( S [ i - 1 ] > j ) { table [ i ] [ j ] = table [ i - 1 ] [ j ] ; } else { table [ i ] [ j ] = min ( table [ i - 1 ] [ j ] , table [ i ] [ j - S [ i - 1 ] ] + 1 ) ; } } } return table [ m ] [ n ] ; } int main ( ) { int arr [ ] = { 9 , 6 , 5 , 1 } ; int m = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << Count ( arr , m , 11 ) ; return 0 ; }

Index/key variables: i, j, m, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define INF  10000000
int maximum ( int A , int B , int C , int D ) { return max ( max ( A , B ) , max ( C , D ) ) ; } int maxProductUtil ( int X , int Y , int * A , int * B , vector < vector < int > > & dp ) { if ( X < 0 or Y < 0 ) return - INF ; if ( dp [ X ] [ Y ] != -1 ) return dp [ X ] [ Y ] ; dp [ X ] [ Y ] = maximum ( A [ X ] * B [ Y ] + maxProductUtil ( X - 1 , Y - 1 , A , B , dp ) , A [ X ] * B [ Y ] , maxProductUtil ( X - 1 , Y , A , B , dp ) , maxProductUtil ( X , Y - 1 , A , B , dp ) ) ; return dp [ X ] [ Y ] ; } int maxProduct ( int A [ ] , int N , int B [ ] , int M ) { vector < vector < int > > dp ( N , vector < int > ( M , -1 ) ) ; return maxProductUtil ( N - 1 , M - 1 , A , B , dp ) ; } int main ( ) { int a [ ] = { -2 , 6 , -2 , -5 } ; int b [ ] = { -3 , 4 , -2 , 8 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int m = sizeof ( b ) / sizeof ( b [ 0 ] ) ; cout << maxProduct ( a , n , b , m ) ; }

Index/key variables: X, Y
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void twoStringsEquality ( string s , string t ) { int n = s . length ( ) ; vector < vector < int > > dp ( n , vector < int > ( n + 1 , 0 ) ) ; if ( s [ n - 1 ] == t [ 0 ] ) dp [ n - 1 ] [ 1 ] = 1 ; if ( s [ n - 1 ] == t [ n - 1 ] ) dp [ n - 1 ] [ 0 ] = 1 ; for ( int i = n - 1 ; i > 0 ; i -- ) { for ( int j = 0 ; j <= n - i ; j ++ ) { if ( dp [ i ] [ j ] ) { if ( s [ i - 1 ] == t [ j ] ) dp [ i - 1 ] [ j + 1 ] = 1 ; if ( s [ i - 1 ] == t [ i + j - 1 ] ) dp [ i - 1 ] [ j ] = 1 ; } } } bool ans = false ; for ( int i = 0 ; i <= n ; i ++ ) { if ( dp [ 0 ] [ i ] == 1 ) { ans = true ; break ; } } if ( ans == true ) cout << " Yes " << " STRNEWLINE " ; else cout << " No " << " STRNEWLINE " ; } int main ( ) { string S = " abab " ; string T = " baab " ; twoStringsEquality ( S , T ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
Boolean variables: ans
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSum ( int * arr , int n ) { int totalSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { totalSum += arr [ i ] ; } int dp [ 2 ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { dp [ 0 ] [ i ] = 1 ; dp [ 1 ] [ i ] = arr [ i ] ; } for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ i ] > arr [ j ] ) { if ( dp [ 0 ] [ i ] < dp [ 0 ] [ j ] + 1 ) { dp [ 0 ] [ i ] = dp [ 0 ] [ j ] + 1 ; dp [ 1 ] [ i ] = dp [ 1 ] [ j ] + arr [ i ] ; } else if ( dp [ 0 ] [ i ] == dp [ 0 ] [ j ] + 1 ) { dp [ 1 ] [ i ] = min ( dp [ 1 ] [ i ] , dp [ 1 ] [ j ] + arr [ i ] ) ; } } } } int maxm = 0 ; int subtractSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( dp [ 0 ] [ i ] > maxm ) { maxm = dp [ 0 ] [ i ] ; subtractSum = dp [ 1 ] [ i ] ; } else if ( dp [ 0 ] [ i ] == maxm ) { subtractSum = min ( subtractSum , dp [ 1 ] [ i ] ) ; } } return totalSum - subtractSum ; } int main ( ) { int arr [ ] = { 4 , 6 , 1 , 2 , 3 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findSum ( arr , n ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc, totalSum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count ( int n ) { if ( n == 2 ) return 1 ; else if ( n == 4 ) return 2 ; else if ( n == 6 ) return 4 ; int table [ n + 1 ] , i ; for ( i = 0 ; i < n + 1 ; i ++ ) table [ i ] = 0 ; table [ 0 ] = 0 ; table [ 2 ] = 1 ; table [ 4 ] = 2 ; table [ 6 ] = 4 ; for ( i = 8 ; i <= n ; i = i + 2 ) { table [ i ] = table [ i - 2 ] + table [ i - 4 ] + table [ i - 6 ] ; } return table [ n ] ; } int main ( void ) { int n = 8 ; cout << count ( n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MOD  1000000007
bool isPrime ( string number ) { int num = stoi ( number ) ; for ( int i = 2 ; i * i <= num ; i ++ ) if ( ( num % i ) == 0 ) return false ; return num > 1 ? true : false ; } int countPrimeStrings ( string & number , int i ) { if ( i == 0 ) return 1 ; int cnt = 0 ; for ( int j = 1 ; j <= 6 ; j ++ ) { if ( i - j >= 0 && number [ i - j ] != '0' && isPrime ( number . substr ( i - j , j ) ) ) { cnt += countPrimeStrings ( number , i - j ) ; cnt %= MOD ; } } return cnt ; } int main ( ) { string s1 = "3175" ; int l = s1 . length ( ) ; cout << countPrimeStrings ( s1 , l ) ; return 0 ; }

Accumulator variables: cnt, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MOD = 1000000007 ; bool sieve [ 1000000 ] ; void buildSieve ( ) { for ( auto & i : sieve ) i = true ; sieve [ 0 ] = false ; sieve [ 1 ] = false ; for ( int p = 2 ; p * p <= 1000000 ; p ++ ) { if ( sieve [ p ] == true ) { for ( int i = p * p ; i <= 1000000 ; i += p ) sieve [ i ] = false ; } } } bool isPrime ( string number ) { int num = stoi ( number ) ; return sieve [ num ] ; } int rec ( string & number , int i , vector < int > & dp ) { if ( dp [ i ] != -1 ) return dp [ i ] ; int cnt = 0 ; for ( int j = 1 ; j <= 6 ; j ++ ) { if ( i - j >= 0 && number [ i - j ] != '0' && isPrime ( number . substr ( i - j , j ) ) ) { cnt += rec ( number , i - j , dp ) ; cnt %= MOD ; } } return dp [ i ] = cnt ; } int countPrimeStrings ( string & number ) { int n = number . length ( ) ; vector < int > dp ( n + 1 , -1 ) ; dp [ 0 ] = 1 ; return rec ( number , n , dp ) ; } int main ( ) { buildSieve ( ) ; string s1 = "3175" ; cout << countPrimeStrings ( s1 ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: i, num, p
Accumulator variables: cnt, i, j, p, stdc
Iterator variables: i, j, p
Boolean variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool hasSquareOfZeroes ( vector < vector < int > > & matrix , int r1 , int c1 , int r2 , int c2 , unordered_map < string , bool > & cache ) ; bool isSquareOfZeroes ( vector < vector < int > > & matrix , int r1 , int c1 , int r2 , int c2 ) ; bool squareOfZeroes ( vector < vector < int > > matrix ) { int lastIdx = matrix . size ( ) - 1 ; unordered_map < string , bool > cache ; return hasSquareOfZeroes ( matrix , 0 , 0 , lastIdx , lastIdx , cache ) ; } bool hasSquareOfZeroes ( vector < vector < int > > & matrix , int r1 , int c1 , int r2 , int c2 , unordered_map < string , bool > & cache ) { if ( r1 >= r2 c1 >= c2 ) return false ; string key = to_string ( r1 ) + ' - ' + to_string ( c1 ) + ' - ' + to_string ( r2 ) + ' - ' + to_string ( c2 ) ; if ( cache . find ( key ) != cache . end ( ) ) return cache [ key ] ; cache [ key ] = isSquareOfZeroes ( matrix , r1 , c1 , r2 , c2 ) || hasSquareOfZeroes ( matrix , r1 + 1 , c1 + 1 , r2 - 1 , c2 - 1 , cache ) || hasSquareOfZeroes ( matrix , r1 , c1 + 1 , r2 - 1 , c2 , cache ) || hasSquareOfZeroes ( matrix , r1 + 1 , c1 , r2 , c2 - 1 , cache ) || hasSquareOfZeroes ( matrix , r1 + 1 , c1 + 1 , r2 , c2 , cache ) || hasSquareOfZeroes ( matrix , r1 , c1 , r2 - 1 , c2 - 1 , cache ) ; return cache [ key ] ; } bool isSquareOfZeroes ( vector < vector < int > > & matrix , int r1 , int c1 , int r2 , int c2 ) { for ( int row = r1 ; row < r2 + 1 ; row ++ ) { if ( matrix [ row ] [ c1 ] != 0 matrix [ row ] [ c2 ] != 0 ) return false ; } for ( int col = c1 ; col < c2 + 1 ; col ++ ) { if ( matrix [ r1 ] [ col ] != 0 matrix [ r2 ] [ col ] != 0 ) return false ; } return true ; } int main ( ) { vector < vector < int > > matrix { { 1 , 1 , 1 , 0 , 1 , 0 } , { 0 , 0 , 0 , 0 , 0 , 1 } , { 0 , 1 , 1 , 1 , 0 , 1 } , { 0 , 0 , 0 , 1 , 0 , 1 } , { 0 , 1 , 1 , 1 , 0 , 1 } , { 0 , 0 , 0 , 0 , 0 , 1 } } ; int ans ; ans = squareOfZeroes ( matrix ) ; if ( ans == 1 ) { cout << " True " << endl ; } else { cout << " False " << endl ; } }

Index/key variables: c1, c2, col, key, r1, r2, row
Accumulator variables: col, row, stdc
Iterator variables: col, row
C++ program:
#include <bits/stdc++.h>
using namespace std ; void CountWays ( int a , int b , int c ) { int x = b + c + 1 ; int arr [ x ] = { 0 } ; for ( int i = a ; i <= b ; i ++ ) { for ( int j = b ; j <= c ; j ++ ) { arr [ i + j ] ++ ; } } for ( int i = 1 ; i < x ; i ++ ) { cout << arr [ i ] << " ▁ " ; } cout << endl ; } int main ( ) { int a = 1 ; int b = 2 ; int c = 2 ; CountWays ( a , b , c ) ; return 0 ; }

Index/key variables: i, x
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void CountWays ( int a , int b , int c ) { int x = b + c + 2 ; int arr [ x ] = { 0 } ; for ( int i = 1 ; i <= b ; i ++ ) { arr [ i + b ] ++ ; arr [ i + c + 1 ] -- ; } for ( int i = 1 ; i < x - 1 ; i ++ ) { arr [ i ] += arr [ i - 1 ] ; cout << arr [ i ] << " ▁ " ; } cout << endl ; } int main ( ) { int a = 1 ; int b = 2 ; int c = 2 ; CountWays ( a , b , c ) ; return 0 ; }

Index/key variables: i, x
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include using namespace std ; void differentStrings ( string s ) { int n = s . length ( ) ; vector dp ( n + 1 ) ; dp [ 0 ] = dp [ 1 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( s [ i ] == s [ i - 1 ] && ( s [ i ] == '1' s [ i ] == '2' ) ) dp [ i + 1 ] = dp [ i ] + dp [ i - 1 ] ; else dp [ i + 1 ] = dp [ i ] ; } cout << dp [ n ] << " STRNEWLINE " ; } int main ( ) { string S = "0111022110" ; differentStrings ( S ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; const int Col = 3 ; int fact ( int n ) ; int nCr ( int n , int r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } int sumPathCost ( int grid [ ] [ Col ] , int m , int n ) { int sum = 0 , count ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { count = nCr ( i + j , i ) * nCr ( m + n - i - j , m - i ) ; sum += count * grid [ i ] [ j ] ; } } return sum ; } int main ( ) { int m = 2 ; int n = 2 ; int grid [ ] [ Col ] = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; cout << sumPathCost ( grid , m , n ) ; return 0 ; }

Index/key variables: Col, i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long int
ll K ; ll N ; vector < int > v ; ll dp [ 20 ] [ 1000 ] [ 10 ] [ 2 ] [ 2 ] ; void init ( ll x ) { memset ( dp , -1 , sizeof ( dp ) ) ; v . clear ( ) ; while ( x > 0 ) { v . push_back ( x % 10 ) ; x /= 10 ; } reverse ( v . begin ( ) , v . end ( ) ) ; N = v . size ( ) ; } ll fun ( ll pos , ll sum , ll st , ll check , ll f ) { if ( pos == N ) { return ( sum == 0 and check == 1 ) ; } if ( dp [ pos ] [ sum ] [ st ] [ check ] [ f ] != -1 ) return dp [ pos ] [ sum ] [ st ] [ check ] [ f ] ; ll lmt = 9 ; if ( ! f ) lmt = v [ pos ] ; ll ans = 0 ; for ( int digit = 0 ; digit <= lmt ; digit ++ ) { ll nf = f ; ll new_sum = ( sum + digit ) % K ; ll new_check = check ; ll new_st = st ; if ( f == 0 and digit < lmt ) nf = 1 ; if ( check == 0 and digit != 0 ) { new_st = digit ; new_check = 1 ; } if ( pos == N - 1 and new_st == digit ) continue ; ans += fun ( pos + 1 , new_sum , new_st , new_check , nf ) ; } return dp [ pos ] [ sum ] [ st ] [ check ] [ f ] = ans ; } void findCount ( int L , int R , int K ) { init ( R ) ; ll r_ans = fun ( 0 , 0 , 0 , 0 , 0 ) ; init ( L - 1 ) ; ll l_ans = fun ( 0 , 0 , 0 , 0 , 0 ) ; cout << r_ans - l_ans ; } int main ( ) { ll L = 10 ; ll R = 20 ; K = 2 ; findCount ( L , R , K ) ; return 0 ; }

Index/key variables: check, f, pos, st, sum
Accumulator variables: ans, digit, stdc, x
Iterator variables: digit
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minSumProd ( string S , int K ) { int len = S . length ( ) ; if ( K > len ) return -1 ; if ( K == len ) return 0 ; vector < int > dp ( len ) ; int count_zero = 0 , count_one = 0 ; for ( int j = 0 ; j < len ; j ++ ) { ( S [ j ] == '0' ) ? count_zero ++ : count_one ++ ; dp [ j ] = count_zero * count_one ; } for ( int i = 1 ; i < K ; i ++ ) { for ( int j = len ; j >= i ; j -- ) { count_zero = 0 , count_one = 0 ; dp [ j ] = INT_MAX ; for ( int k = j ; k >= i ; k -- ) { ( S [ k ] == '0' ) ? count_zero ++ : count_one ++ ; dp [ j ] = min ( dp [ j ] , count_zero * count_one + dp [ k - 1 ] ) ; } } } return dp [ len - 1 ] ; } int main ( ) { string S = "1011000110110100" ; int K = 5 ; cout << minSumProd ( S , K ) << ' ' ; return 0 ; }

Index/key variables: j, k
Accumulator variables: count_one, count_zero, i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minPrizes ( int arr [ ] , int n ) { int dpLeft [ n ] ; dpLeft [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) { dpLeft [ i ] = dpLeft [ i - 1 ] + 1 ; } else { dpLeft [ i ] = 1 ; } } int dpRight [ n ] ; dpRight [ n - 1 ] = 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > arr [ i + 1 ] ) { dpRight [ i ] = dpRight [ i + 1 ] + 1 ; } else { dpRight [ i ] = 1 ; } } int totalPrizes = 0 ; for ( int i = 0 ; i < n ; i ++ ) { totalPrizes += max ( dpLeft [ i ] , dpRight [ i ] ) ; } cout << totalPrizes << endl ; return 0 ; } int main ( ) { int arr [ ] = { 1 , 2 , 2 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; minPrizes ( arr , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc, totalPrizes
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int get_max_sum ( int arr [ ] , int n ) { unordered_map < int , int > freq ; for ( int i = 0 ; i < n ; i ++ ) { freq [ arr [ i ] ] ++ ; } int dp [ 100001 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; dp [ 0 ] = 0 ; dp [ 1 ] = freq [ 0 ] ; for ( int i = 2 ; i <= 100000 ; i ++ ) { dp [ i ] = max ( dp [ i - 1 ] , dp [ i - 2 ] + i * freq [ i ] ) ; } return dp [ 100000 ] ; } int main ( ) { int N = 3 ; int arr [ ] = { 2 , 2 , 3 } ; cout << get_max_sum ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minFlip ( string a ) { int n = a . size ( ) ; vector < vector < int > > dp ( n + 1 , vector < int > ( 2 , 0 ) ) ; dp [ 0 ] [ 0 ] = ( a [ 0 ] == '1' ) ; dp [ 0 ] [ 1 ] = ( a [ 0 ] == '0' ) ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + ( a [ i ] == '1' ) ; dp [ i ] [ 1 ] = min ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) + ( a [ i ] == '0' ) ; } int answer = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { answer = min ( answer , dp [ i ] [ 1 ] + dp [ n - 1 ] [ 0 ] - dp [ i ] [ 0 ] ) ; } return min ( answer , dp [ n - 1 ] [ 0 ] ) ; } int main ( ) { string s = "1100111000101" ; cout << ( minFlip ( s ) ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int LIIDS ( int arr [ ] , int N ) { int dp [ N + 1 ] ; int ans = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { dp [ i ] = 1 ; } for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = i + i ; j <= N ; j += i ) { if ( arr [ j ] > arr [ i ] ) { dp [ j ] = max ( dp [ j ] , dp [ i ] + 1 ) ; } } ans = max ( ans , dp [ i ] ) ; } return ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 7 , 9 , 10 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << LIIDS ( 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 ; bool isPerfectSquare ( long double x ) { long double sr = sqrt ( x ) ; return ( ( sr - floor ( sr ) ) == 0 ) ; } int findSubarraySum ( int arr [ ] , int n , int K ) { unordered_map < int , int > prevSum ; int res = 0 ; int currsum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { currsum += arr [ i ] ; if ( currsum == K ) { res ++ ; } if ( prevSum . find ( currsum - K ) != prevSum . end ( ) ) res += ( prevSum [ currsum - K ] ) ; prevSum [ currsum ] ++ ; } return res ; } void countSubarray ( int arr [ ] , int n , int K ) { for ( int i = 0 ; i < n ; i ++ ) { if ( isPerfectSquare ( arr [ i ] ) ) { arr [ i ] = 1 ; } else { arr [ i ] = 0 ; } } cout << findSubarraySum ( arr , n , K ) ; } int main ( ) { int arr [ ] = { 2 , 4 , 9 , 2 } ; int K = 2 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; countSubarray ( arr , N , K ) ; return 0 ; }

Index/key variables: currsum, i
Accumulator variables: currsum, i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int mod = 1000000007 ; int calculate ( int pos , int left , int k , int L , int R ) { if ( pos == k ) { if ( left == 0 ) return 1 ; else return 0 ; } if ( left == 0 ) return 0 ; int answer = 0 ; for ( int i = L ; i <= R ; i ++ ) { if ( i > left ) break ; answer = ( answer + calculate ( pos + 1 , left - i , k , L , R ) ) % mod ; } return answer ; } int countWaystoDivide ( int n , int k , int L , int R ) { return calculate ( 0 , n , k , L , R ) ; } int main ( ) { int N = 12 ; int K = 3 ; int L = 1 ; int R = 5 ; cout << countWaystoDivide ( N , K , L , R ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void PossibleSum ( int n , int m , vector < vector < int > > v , int k ) { int dp [ n + 1 ] [ k + 1 ] = { 0 } ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= k ; j ++ ) { if ( dp [ i ] [ j ] == 1 ) { for ( int d = 0 ; d < m ; d ++ ) { if ( ( j + v [ i ] [ d ] ) <= k ) { dp [ i + 1 ] [ j + v [ i ] [ d ] ] = 1 ; } } } } } if ( dp [ n ] [ k ] == 1 ) cout << " YES STRNEWLINE " ; else cout << " NO STRNEWLINE " ; } int main ( ) { int N = 2 , M = 10 , K = 5 ; vector < vector < int > > arr = { { 4 , 0 , 15 , 3 , 2 , 20 , 10 , 1 , 5 , 4 } , { 4 , 0 , 10 , 3 , 2 , 25 , 4 , 1 , 5 , 4 } } ; PossibleSum ( N , M , arr , K ) ; return 0 ; }

Index/key variables: d, i, j, k, n
Accumulator variables: d, i, j, stdc
Iterator variables: d, i, j