dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
#define ll  long long int
using namespace std ; ll lis ( ll arr [ ] , ll n ) { ll mpis [ n ] ; for ( int i = 0 ; i < n ; i ++ ) mpis [ i ] = arr [ i ] ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 0 ; j < i ; j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ; return * max_element ( mpis , mpis + n ) ; } int main ( ) { ll arr [ ] = { 3 , 100 , 4 , 5 , 150 , 6 } ; ll n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printf ( " % lld " , lis ( arr , n ) ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Hosoya ( int n , int m ) { if ( ( n == 0 && m == 0 ) || ( n == 1 && m == 0 ) || ( n == 1 && m == 1 ) || ( n == 2 && m == 1 ) ) return 1 ; if ( n > m ) return Hosoya ( n - 1 , m ) + Hosoya ( n - 2 , m ) ; else if ( m == n ) return Hosoya ( n - 1 , m - 1 ) + Hosoya ( n - 2 , m - 2 ) ; else return 0 ; } void printHosoya ( int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) cout << Hosoya ( i , j ) << " ▁ " ; cout << endl ; } } int main ( ) { int n = 5 ; printHosoya ( n ) ; return 0 ; }

Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int eulerian ( int n , int m ) { if ( m >= n n == 0 ) return 0 ; if ( m == 0 ) return 1 ; return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ; } int main ( ) { int n = 3 , m = 1 ; cout << eulerian ( n , m ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int largestSubset ( int a [ ] , int n ) { int dp [ n ] ; dp [ n - 1 ] = 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { int mxm = 0 ; for ( int j = i + 1 ; j < n ; j ++ ) if ( a [ j ] % a [ i ] == 0 a [ i ] % a [ j ] == 0 ) mxm = max ( mxm , dp [ j ] ) ; dp [ i ] = 1 + mxm ; } return * max_element ( dp , dp + n ) ; } int main ( ) { int a [ ] = { 1 , 3 , 6 , 13 , 17 , 18 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << largestSubset ( a , n ) << endl ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
int dp [ MAXN ] ; int solve ( int n ) { if ( n < 0 ) return 0 ; if ( n == 0 ) return 1 ; if ( dp [ n ] != -1 ) return dp [ n ] ; return dp [ n ] = solve ( n - 1 ) + solve ( n - 3 ) + solve ( n - 5 ) ; }

Index/key variables: MAXN, n
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countFriendsPairings ( int n ) { int dp [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { if ( i <= 2 ) dp [ i ] = i ; else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ; } return dp [ n ] ; } int main ( ) { int n = 4 ; cout << countFriendsPairings ( n ) << endl ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countFriendsPairings ( int n ) { int a = 1 , b = 2 , c = 0 ; if ( n <= 2 ) { return n ; } for ( int i = 3 ; i <= n ; i ++ ) { c = b + ( i - 1 ) * a ; a = b ; b = c ; } return c ; } int main ( ) { int n = 4 ; cout << countFriendsPairings ( n ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define R  5
#define C  3
using namespace std ; void precompute ( int mat [ R ] [ C ] , int ryt [ ] [ C + 2 ] , int dwn [ R + 2 ] [ C + 2 ] ) { for ( int j = C - 1 ; j >= 0 ; j -- ) { for ( int i = 0 ; i < R ; ++ i ) { if ( mat [ i ] [ j ] == 0 ) ryt [ i ] [ j ] = 0 ; else ryt [ i ] [ j ] = ryt [ i ] [ j + 1 ] + 1 ; } } for ( int i = R - 1 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < C ; ++ j ) { if ( mat [ i ] [ j ] == 0 ) dwn [ i ] [ j ] = 0 ; else dwn [ i ] [ j ] = dwn [ i + 1 ] [ j ] + 1 ; } } } int solveRowSwap ( int ryt [ R + 2 ] [ C + 2 ] ) { int b [ R ] = { 0 } , ans = 0 ; for ( int j = 0 ; j < C ; j ++ ) { for ( int i = 0 ; i < R ; i ++ ) b [ i ] = ryt [ i ] [ j ] ; sort ( b , b + R ) ; for ( int i = 0 ; i < R ; ++ i ) ans = max ( ans , b [ i ] * ( R - i ) ) ; } return ans ; } int solveColumnSwap ( int dwn [ R + 2 ] [ C + 2 ] ) { int b [ C ] = { 0 } , ans = 0 ; for ( int i = 0 ; i < R ; ++ i ) { for ( int j = 0 ; j < C ; ++ j ) b [ j ] = dwn [ i ] [ j ] ; sort ( b , b + C ) ; for ( int i = 0 ; i < C ; ++ i ) ans = max ( ans , b [ i ] * ( C - i ) ) ; } return ans ; } void findMax1s ( int mat [ R ] [ C ] ) { int ryt [ R + 2 ] [ C + 2 ] , dwn [ R + 2 ] [ C + 2 ] ; memset ( ryt , 0 , sizeof ryt ) ; memset ( dwn , 0 , sizeof dwn ) ; precompute ( mat , ryt , dwn ) ; int rswap = solveRowSwap ( ryt ) ; int cswap = solveColumnSwap ( dwn ) ; ( rswap > cswap ) ? ( cout << " Row ▁ Swap STRNEWLINE " << rswap << endl ) : ( cout << " Column ▁ Swap STRNEWLINE " << cswap << endl ) ; } int main ( ) { int mat [ R ] [ C ] = { { 0 , 0 , 0 } , { 1 , 1 , 0 } , { 1 , 1 , 0 } , { 0 , 0 , 0 } , { 1 , 1 , 0 } } ; findMax1s ( mat ) ; return 0 ; }

Index/key variables: C, R, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int lcsOf3 ( string X , string Y , string Z , int m , int n , int o ) { int L [ m + 1 ] [ n + 1 ] [ o + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { for ( int k = 0 ; k <= o ; k ++ ) { if ( i == 0 j == 0 k == 0 ) L [ i ] [ j ] [ k ] = 0 ; else if ( X [ i - 1 ] == Y [ j - 1 ] && X [ i - 1 ] == Z [ k - 1 ] ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ; else L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ; } } } return L [ m ] [ n ] [ o ] ; } int main ( ) { string X = " AGGT12" ; string Y = "12TXAYB " ; string Z = "12XBA " ; int m = X . length ( ) ; int n = Y . length ( ) ; int o = Z . length ( ) ; cout << " Length ▁ of ▁ LCS ▁ is ▁ " << lcsOf3 ( X , Y , Z , m , n , o ) ; return 0 ; }

Index/key variables: i, j, k, m, n, o
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestSubsequence ( int n , int arr [ ] ) { if ( n == 1 ) return 1 ; int dp [ n ] ; unordered_map < int , int > mapp ; dp [ 0 ] = 1 ; mapp [ arr [ 0 ] ] = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( abs ( arr [ i ] - arr [ i - 1 ] ) == 1 ) dp [ i ] = dp [ i - 1 ] + 1 ; else { if ( mapp . count ( arr [ i ] + 1 ) > 0 || mapp . count ( arr [ i ] - 1 ) ) { dp [ i ] = 1 + max ( mapp [ arr [ i ] + 1 ] , mapp [ arr [ i ] - 1 ] ) ; } else dp [ i ] = 1 ; } mapp [ arr [ i ] ] = dp [ i ] ; } return ( * max_element ( dp , dp + n ) ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 3 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << longestSubsequence ( n , arr ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string printShortestSuperSeq ( string X , string Y ) { int m = X . length ( ) ; int n = Y . length ( ) ; int dp [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 ) dp [ i ] [ j ] = j ; else if ( j == 0 ) dp [ i ] [ j ] = i ; else if ( X [ i - 1 ] == Y [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } string str ; int i = m , j = n ; while ( i > 0 && j > 0 ) { if ( X [ i - 1 ] == Y [ j - 1 ] ) { str . push_back ( X [ i - 1 ] ) ; i -- , j -- ; } else if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j - 1 ] ) { str . push_back ( Y [ j - 1 ] ) ; j -- ; } else { str . push_back ( X [ i - 1 ] ) ; i -- ; } } while ( i > 0 ) { str . push_back ( X [ i - 1 ] ) ; i -- ; } while ( j > 0 ) { str . push_back ( Y [ j - 1 ] ) ; j -- ; } reverse ( str . begin ( ) , str . end ( ) ) ; return str ; } int main ( ) { string X = " AGGTAB " ; string Y = " GXTXAYB " ; cout << printShortestSuperSeq ( X , Y ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
#include <string>
using namespace std ; int findLongestRepeatingSubSeq ( string str ) { int n = str . length ( ) ; int dp [ n + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j <= n ; j ++ ) dp [ i ] [ j ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ; } } return dp [ n ] [ n ] ; } int main ( ) { string str = " aabb " ; cout << " The ▁ length ▁ of ▁ the ▁ largest ▁ subsequence ▁ that " " ▁ repeats ▁ itself ▁ is ▁ : ▁ " << findLongestRepeatingSubSeq ( str ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; unsigned long long int lookup [ 50 ] [ 1000 ] [ 1000 ] [ 2 ] ; unsigned long long int countRec ( int digits , int esum , int osum , bool isOdd , int n ) { if ( digits == n ) return ( esum - osum == 1 ) ; if ( lookup [ digits ] [ esum ] [ osum ] [ isOdd ] != -1 ) return lookup [ digits ] [ esum ] [ osum ] [ isOdd ] ; unsigned long long int ans = 0 ; if ( isOdd ) for ( int i = 0 ; i <= 9 ; i ++ ) ans += countRec ( digits + 1 , esum , osum + i , false , n ) ; for ( int i = 0 ; i <= 9 ; i ++ ) ans += countRec ( digits + 1 , esum + i , osum , true , n ) ; return lookup [ digits ] [ esum ] [ osum ] [ isOdd ] = ans ; } unsigned long long int finalCount ( int n ) { int digits = 0 ; memset ( lookup , -1 , sizeof lookup ) ; unsigned long long int ans = 0 ; int esum = 0 , osum = 0 ; for ( int i = 1 ; i <= 9 ; i ++ ) ans += countRec ( digits + 1 , esum + i , osum , true , n ) ; return ans ; } int main ( ) { int n = 3 ; cout << " Count ▁ of ▁ " << n << " ▁ digit ▁ numbers ▁ is ▁ " << finalCount ( n ) ; return 0 ; }

Index/key variables: digits, esum, isOdd, osum
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int numberOfPaths ( int m , int n ) { int dp [ n ] = { 1 } ; dp [ 0 ] = 1 ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 1 ; j < n ; j ++ ) { dp [ j ] += dp [ j - 1 ] ; } } return dp [ n - 1 ] ; } int main ( ) { cout << numberOfPaths ( 3 , 3 ) ; }

Index/key variables: j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Solution ( vector < int > A ) { int ans = 2 ; int n = A . size ( ) ; if ( n <= 2 ) return n ; vector < int > llap ( n , 2 ) ; sort ( A . begin ( ) , A . end ( ) ) ; for ( int j = n - 2 ; j >= 0 ; j -- ) { int i = j - 1 ; int k = j + 1 ; while ( i >= 0 && k < n ) { if ( A [ i ] + A [ k ] == 2 * A [ j ] ) { llap [ j ] = max ( llap [ k ] + 1 , llap [ j ] ) ; ans = max ( ans , llap [ j ] ) ; i -= 1 ; k += 1 ; } else if ( A [ i ] + A [ k ] < 2 * A [ j ] ) k += 1 ; else i -= 1 ; } } return ans ; } int main ( ) { vector < int > a ( { 9 , 4 , 7 , 2 , 10 } ) ; cout << Solution ( a ) << endl ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minumumOperation ( int N , int arr [ ] ) { int sum_arr = 0 ; sum_arr = accumulate ( arr , arr + N , sum_arr ) ; if ( sum_arr >= N ) cout << sum_arr - N << endl ; else cout << 1 << endl ; } int main ( ) { int N = 4 ; int arr [ ] = { 8 , 4 , 6 , 2 } ; minumumOperation ( N , arr ) ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Substr ( string s2 , string s1 ) { int i = 0 ; for ( ; i < s1 . length ( ) ; i ++ ) { if ( counter == s2 . length ( ) ) break ; if ( s2 [ counter ] == s1 [ i ] ) { counter ++ ; } else { if ( counter > 0 ) { i -= counter ; } counter = 0 ; } } return counter < s2 . length ( ) ? -1 : i - counter ; } int main ( ) { string s1 = " geeksfffffoorrfoorforgeeks " ; cout << Substr ( " for " , s1 ) ; return 0 ; }

Index/key variables: counter, i
Accumulator variables: counter, i, stdc
C++ program:
#include <bits/stdc++.h>
#define ll  long long
#define mod  1000000007
#define N  1000001
using namespace std ; void Precomputefact ( unordered_map < ll , ll > & fac ) { ll ans = 1 ; for ( ll i = 1 ; i <= N ; i ++ ) { ans = ( ans * i ) % mod ; fac [ i ] = ans ; } return ; } bool isVowel ( char a ) { if ( a == ' A ' a == ' E ' a == ' I ' a == ' O ' a == ' U ' ) return true ; else return false ; } void countAnagrams ( string s , int n ) { unordered_map < ll , ll > fac ; Precomputefact ( fac ) ; unordered_map < char , ll > count ; int vo = 0 , co = 0 ; for ( int i = 0 ; i < n ; i ++ ) { count [ s [ i ] ] ++ ; if ( isVowel ( s [ i ] ) ) vo ++ ; else co ++ ; } if ( ( co == vo + 1 ) || ( co == vo ) ) { ll deno = 1 ; for ( auto c : count ) { deno = ( deno * fac [ c . second ] ) % mod ; } ll nume = fac [ co ] % mod ; nume = ( nume * fac [ vo ] ) % mod ; ll ans = nume / deno ; cout << ans ; } else { cout << 0 ; } } int main ( ) { string S = " GADO " ; int l = S . size ( ) ; countAnagrams ( S , l ) ; return 0 ; }

Index/key variables: co, i, vo
Accumulator variables: co, i, stdc, vo
Iterator variables: c, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > generateHammingCode ( vector < int > msgBits , int m , int r ) { vector < int > hammingCode ( r + m ) ; for ( int i = 0 ; i < r ; ++ i ) { hammingCode [ pow ( 2 , i ) - 1 ] = -1 ; } int j = 0 ; for ( int i = 0 ; i < ( r + m ) ; i ++ ) { if ( hammingCode [ i ] != -1 ) { hammingCode [ i ] = msgBits [ j ] ; j ++ ; } } for ( int i = 0 ; i < ( r + m ) ; i ++ ) { if ( hammingCode [ i ] != -1 ) continue ; int x = log2 ( i + 1 ) ; int one_count = 0 ; for ( int j = i + 2 ; j <= ( r + m ) ; ++ j ) { if ( j & ( 1 << x ) ) { if ( hammingCode [ j - 1 ] == 1 ) { one_count ++ ; } } } if ( one_count % 2 == 0 ) { hammingCode [ i ] = 0 ; } else { hammingCode [ i ] = 1 ; } } return hammingCode ; } void findHammingCode ( vector < int > & msgBit ) { int m = msgBit . size ( ) ; int r = 1 ; while ( pow ( 2 , r ) < ( m + r + 1 ) ) { r ++ ; } vector < int > ans = generateHammingCode ( msgBit , m , r ) ; cout << " Message ▁ bits ▁ are : ▁ " ; for ( int i = 0 ; i < msgBit . size ( ) ; i ++ ) cout << msgBit [ i ] << " ▁ " ; cout << " Hamming code is : " ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) cout << ans [ i ] << " ▁ " ; } int main ( ) { vector < int > msgBit = { 0 , 1 , 0 , 1 } ; findHammingCode ( msgBit ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, one_count, r, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; string util ( string sub ) { int n = sub . length ( ) ; int i = 0 ; string ret = " " ; while ( i < n ) { int t = ( sub [ i ] - ' a ' ) + n - 1 - i ; char ch = ( char ) ( t % 26 + 97 ) ; ret = ret + ch ; i ++ ; } return ret ; } void manipulate ( string s ) { int n = s . length ( ) ; int i = 0 , j = 0 ; string res = " " ; while ( i < n ) { if ( s [ i ] == ' ▁ ' ) { res += util ( s . substr ( j , i ) ) ; res = res + " ▁ " ; j = i + 1 ; i = j + 1 ; } else { i ++ ; } } res = res + util ( s . substr ( j , i ) ) ; cout << res << endl ; } int main ( ) { string s = " acm ▁ fkz " ; manipulate ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, res, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isInBigString ( string bigString , string smallString ) ; bool isInBigStringHelper ( string bigString , string smallString , int startIdx ) ; vector < bool > multiStringSearch ( string bigString , vector < string > smallStrings ) { vector < bool > solution ; for ( string smallString : smallStrings ) { solution . push_back ( isInBigString ( bigString , smallString ) ) ; } return solution ; } bool isInBigString ( string bigString , string smallString ) { for ( int i = 0 ; i < bigString . length ( ) ; i ++ ) { if ( i + smallString . length ( ) > bigString . length ( ) ) { break ; } if ( isInBigStringHelper ( bigString , smallString , i ) ) { return true ; } } return false ; } bool isInBigStringHelper ( string bigString , string smallString , int startIdx ) { int leftBigIdx = startIdx ; int rightBigIdx = startIdx + smallString . length ( ) - 1 ; int leftSmallIdx = 0 ; int rightSmallIdx = smallString . length ( ) - 1 ; while ( leftBigIdx <= rightBigIdx ) { if ( bigString [ leftBigIdx ] != smallString [ leftSmallIdx ] bigString [ rightBigIdx ] != smallString [ rightSmallIdx ] ) { return false ; } leftBigIdx ++ ; rightBigIdx -- ; leftSmallIdx ++ ; rightSmallIdx -- ; } return true ; } int main ( int argc , char * argv [ ] ) { string str = " this ▁ is ▁ a ▁ big ▁ string " ; vector < string > substr = { " this " , " yo " , " is " , " a " , " bigger " , " string " , " kappa " } ; vector < bool > ans = multiStringSearch ( str , substr ) ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { if ( ans [ i ] == 1 ) { cout << " true " << " ▁ " ; } else { cout << " false " << " ▁ " ; } } return 0 ; }

Index/key variables: i, leftBigIdx, leftSmallIdx, rightBigIdx, rightSmallIdx
Accumulator variables: i, leftBigIdx, leftSmallIdx, rightBigIdx, rightSmallIdx, stdc
Iterator variables: i, smallString
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countSmaller ( string str ) { int n = str . length ( ) ; int arr [ 26 ] = { 0 } ; int ans [ n ] ; for ( int i = n - 1 ; i >= 0 ; i -- ) { arr [ str [ i ] - ' a ' ] ++ ; int ct = 0 ; for ( int j = 0 ; j < str [ i ] - ' a ' ; j ++ ) { ct += arr [ j ] ; } ans [ i ] = ct ; } for ( int i = 0 ; i < n ; i ++ ) { cout << ans [ i ] << " ▁ " ; } } int main ( ) { string str = " edcbaa " ; countSmaller ( str ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: ct, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > z_function ( string s ) { int n = s . size ( ) ; vector < int > z ( n ) ; for ( int i = 1 , l = 0 , r = 0 ; i < n ; i ++ ) { if ( i <= r ) z [ i ] = min ( r - i + 1 , z [ i - l ] ) ; while ( i + z [ i ] < n && s [ z [ i ] ] == s [ i + z [ i ] ] ) z [ i ] ++ ; if ( i + z [ i ] - 1 > r ) l = i , r = i + z [ i ] - 1 ; } return z ; } int n , len = 0 ; int bit [ 1000005 ] ; string s ; vector < int > z ; map < int , int > m ; void update ( int idx , int val ) { if ( idx == 0 ) return ; while ( idx <= n ) { bit [ idx ] += val ; idx += ( idx & - idx ) ; } } int pref ( int idx ) { int ans = 0 ; while ( idx > 0 ) { ans += bit [ idx ] ; idx -= ( idx & - idx ) ; } return ans ; } int main ( ) { s = " geeksisforgeeksinplatformgeeks " ; n = s . size ( ) ; z = z_function ( s ) ; for ( int i = 1 ; i < n ; i ++ ) { update ( z [ i ] , 1 ) ; } for ( int i = n - 1 ; i > 1 ; i -- ) { if ( z [ i ] != ( n - i ) ) continue ; if ( pref ( n ) - pref ( z [ i ] - 1 ) >= 2 ) { len = max ( len , z [ i ] ) ; } } if ( ! len ) cout << " - 1" ; else cout << s . substr ( 0 , len ) ; return 0 ; }

Index/key variables: i, idx
Accumulator variables: ans, i, idx, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; template < size_t N > void splitString ( string ( & arr ) [ N ] , string str ) { int n = 0 ; istringstream iss ( str ) ; for ( auto it = istream_iterator < string > ( iss ) ; it != istream_iterator < string > ( ) && n < N ; ++ it , ++ n ) arr [ n ] = * it ; } inline bool ends_with ( std :: string const & value , std :: string const & ending ) { if ( ending . size ( ) > value . size ( ) ) return false ; return std :: equal ( ending . rbegin ( ) , ending . rend ( ) , value . rbegin ( ) ) ; } int endingWith ( string str , string suff ) { int cnt = 0 ; const int size = 50 ; string words [ size ] ; splitString ( words , str ) ; for ( int i = 0 ; i < size ; i ++ ) { if ( ends_with ( words [ i ] , suff ) ) cnt ++ ; } return cnt ; } int main ( ) { string str = " GeeksForGeeks ▁ is ▁ a ▁ computer ▁ " " science ▁ portal ▁ for ▁ geeks " ; string suff = " ks " ; cout << endingWith ( str , suff ) ; }

Index/key variables: N, i, n, size
Accumulator variables: cnt, i, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isFrequencyEqual ( string str , int len ) { if ( len % 2 == 1 ) return false ; int i , freq [ 26 ] = { 0 } ; for ( i = 0 ; i < len ; i ++ ) freq [ str [ i ] - ' a ' ] ++ ; for ( i = 0 ; i < 26 ; i ++ ) if ( freq [ i ] == len / 2 ) return true ; return false ; } int main ( ) { string str = " geeksforgeeks " ; int len = str . length ( ) ; if ( isFrequencyEqual ( str , len ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countMinimalReplacements ( string s ) { int n = s . length ( ) ; int cnt = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( s [ i ] == s [ i - 1 ] ) { cnt += 1 ; if ( i != ( n - 1 ) ) { for ( auto it : "012" ) { if ( it != s [ i + 1 ] && it != s [ i - 1 ] ) { s [ i ] = it ; break ; } } } { for ( auto it : "012" ) { if ( it != s [ i - 1 ] ) { s [ i ] = it ; break ; } } } } } return cnt ; } int main ( ) { string s = "201220211" ; cout << countMinimalReplacements ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, i, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; int nextIndex ( string str , int start , char c ) { for ( int i = start ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == c ) return i ; } return -1 ; } int countSubStrings ( string str ) { int i , n = str . length ( ) ; int countX [ n ] ; int count = 0 ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == ' x ' ) count ++ ; countX [ i ] = count ; } int nextIndexX = nextIndex ( str , 0 , ' x ' ) ; int nextIndexY = nextIndex ( str , 0 , ' y ' ) ; count = 0 ; while ( nextIndexX != -1 && nextIndexY != -1 ) { if ( nextIndexX > nextIndexY ) { nextIndexY = nextIndex ( str , nextIndexY + 1 , ' y ' ) ; continue ; } else { count += countX [ nextIndexY ] ; nextIndexX = nextIndex ( str , nextIndexX + 1 , ' x ' ) ; } } return count ; } int main ( ) { string s = " xyyxx " ; cout << countSubStrings ( s ) ; }

Index/key variables: i, n, nextIndexY
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPrime ( int n ) { int i ; if ( n == 1 ) return false ; for ( i = 2 ; i <= sqrt ( n ) ; i ++ ) if ( n % i == 0 ) return false ; return true ; } bool check_frequency ( string s ) { map < char , int > m ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) m [ s [ i ] ] ++ ; for ( char ch = ' a ' ; ch <= ' z ' ; ch ++ ) if ( m [ ch ] > 0 && ! isPrime ( m [ ch ] ) ) return false ; return true ; } int main ( ) { string s = " geeksforgeeks " ; if ( check_frequency ( s ) ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }

Index/key variables: ch, i
Accumulator variables: ch, i, stdc
Iterator variables: ch, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSubstringCount ( string str ) { int result = 0 ; int n = str . size ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( str [ i ] + 1 == str [ i + 1 ] ) { result ++ ; while ( str [ i ] + 1 == str [ i + 1 ] ) { i ++ ; } } } return result ; } int main ( ) { string str = " alphabet " ; cout << findSubstringCount ( str ) << endl ; return 0 ; }

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