dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; void parallel ( int n , int a [ ] [ 2 ] ) { bool x = true , y = true ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( a [ i ] [ 0 ] != a [ i + 1 ] [ 0 ] ) x = false ; if ( a [ i ] [ 1 ] != a [ i + 1 ] [ 1 ] ) y = false ; } if ( x ) cout << " parallel ▁ to ▁ Y ▁ Axis " << endl ; else if ( y ) cout << " parallel ▁ to ▁ X ▁ Axis " << endl ; else cout << " Not ▁ parallel ▁ to ▁ X " << " ▁ and ▁ Y ▁ Axis " << endl ; } int main ( ) { int a [ ] [ 2 ] = { { 1 , 2 } , { 1 , 4 } , { 1 , 6 } , { 1 , 0 } } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; parallel ( n , a ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: x, y
C++ program:
#include <bits/stdc++.h>
using namespace std ; int numberOfSticks ( int x ) { return ( 3 * x * ( x + 1 ) ) / 2 ; } int main ( ) { cout << numberOfSticks ( 7 ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Point { int x , y ; } ; int overlappingArea ( Point l1 , Point r1 , Point l2 , Point r2 ) { int area1 = abs ( l1 . x - r1 . x ) * abs ( l1 . y - r1 . y ) ; int area2 = abs ( l2 . x - r2 . x ) * abs ( l2 . y - r2 . y ) ; int x_dist = min ( r1 . x , r2 . x ) - max ( l1 . x , l2 . x ) ; int y_dist = ( min ( r1 . y , r2 . y ) - max ( l1 . y , l2 . y ) ) ; int areaI = 0 ; if ( x_dist > 0 && y_dist > 0 ) { areaI = x_dist * y_dist ; } return ( area1 + area2 - areaI ) ; } int main ( ) { Point l1 = { 2 , 2 } , r1 = { 5 , 7 } ; Point l2 = { 3 , 4 } , r2 = { 6 , 9 } ; cout << overlappingArea ( l1 , r1 , l2 , r2 ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Point
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkValidity ( int a , int b , int c ) { if ( a + b <= c a + c <= b b + c <= a ) return false ; else return true ; } int main ( ) { int a = 7 , b = 10 , c = 5 ; if ( checkValidity ( a , b , c ) ) cout << " Valid " ; else cout << " Invalid " ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int M = 3 ; const int N = 3 ; int contribution_height ( int current , int previous ) { return abs ( current - previous ) ; } int surfaceArea ( int A [ N ] [ M ] ) { int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { int up = 0 ; int left = 0 ; if ( i > 0 ) up = A [ i - 1 ] [ j ] ; if ( j > 0 ) left = A [ i ] [ j - 1 ] ; ans += contribution_height ( A [ i ] [ j ] , up ) + contribution_height ( A [ i ] [ j ] , left ) ; if ( i == N - 1 ) ans += A [ i ] [ j ] ; if ( j == M - 1 ) ans += A [ i ] [ j ] ; } } ans += N * M * 2 ; return ans ; } int main ( ) { int A [ N ] [ M ] = { { 1 , 3 , 4 } , { 2 , 2 , 3 } , { 1 , 2 , 4 } } ; cout << surfaceArea ( A ) << endl ; return 0 ; }

Index/key variables: M, N, i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; float area_equi_triangle ( float side ) { return sqrt ( 3 ) / 4 * side * side ; } float peri_equi_triangle ( float side ) { return 3 * side ; } int main ( ) { float side = 4 ; cout << " Area ▁ of ▁ Equilateral ▁ Triangle : ▁ " << area_equi_triangle ( side ) << endl ; cout << " Perimeter ▁ of ▁ Equilateral ▁ Triangle : ▁ " << peri_equi_triangle ( side ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printSet ( int x , int y ) { set < pair < int , int > > arr ; for ( int i = 0 ; i <= min ( x , y ) ; i ++ ) { pair < int , int > pq ; pq = make_pair ( i , min ( x , y ) - i ) ; arr . insert ( pq ) ; } for ( auto it = arr . begin ( ) ; it != arr . end ( ) ; it ++ ) cout << ( * it ) . first << " ▁ " << ( * it ) . second << endl ; } int main ( ) { int x = 4 , y = 4 ; printSet ( x , y ) ; return 0 ; }

Accumulator variables: i, it, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; double areaCuboid ( double l , double h , double w ) { return ( l * h * w ) ; } double surfaceAreaCuboid ( double l , double h , double w ) { return ( 2 * l * w + 2 * w * h + 2 * l * h ) ; } int main ( ) { double l = 1 ; double h = 5 ; double w = 7 ; cout << " Area ▁ = ▁ " << areaCuboid ( l , h , w ) << endl ; cout << " Total ▁ Surface ▁ Area ▁ = ▁ " << surfaceAreaCuboid ( l , h , w ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int rectCount ( int n , int m ) { return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ; } int main ( ) { int n = 5 , m = 4 ; cout << rectCount ( n , m ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countRect ( int n ) { int ans = 0 ; for ( int length = 1 ; length <= sqrt ( n ) ; ++ length ) for ( int height = length ; height * length <= n ; ++ height ) ans ++ ; return ans ; } int main ( ) { int n = 5 ; printf ( " % d " , countRect ( n ) ) ; return 0 ; }

Accumulator variables: ans, stdc
Iterator variables: height, length
C++ program:
#include <bits/stdc++.h>
using namespace std ; int main ( ) { int ax = 5 , ay = 0 ; int bx = 1 , by = 1 ; int cx = 2 , cy = 5 ; cout << ax + cx - bx << " , ▁ " << ay + cy - by ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <cmath>
#include <iostream>
using namespace std ; void bestApproximate ( int x [ ] , int y [ ] , int n ) { float m , c , sum_x = 0 , sum_y = 0 , sum_xy = 0 , sum_x2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum_x += x [ i ] ; sum_y += y [ i ] ; sum_xy += x [ i ] * y [ i ] ; sum_x2 += pow ( x [ i ] , 2 ) ; } m = ( n * sum_xy - sum_x * sum_y ) / ( n * sum_x2 - pow ( sum_x , 2 ) ) ; c = ( sum_y - m * sum_x ) / n ; cout << " m ▁ = " << m ; cout << " c = " } int main ( ) { int x [ ] = { 1 , 2 , 3 , 4 , 5 } ; int y [ ] = { 14 , 27 , 40 , 55 , 68 } ; int n = sizeof ( x ) / sizeof ( x [ 0 ] ) ; bestApproximate ( x , y , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, sum_x, sum_x2, sum_xy, sum_y
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define size  4
bool checkStar ( int mat [ ] [ size ] ) { int vertexD1 = 0 , vertexDn_1 = 0 ; if ( size == 1 ) return ( mat [ 0 ] [ 0 ] == 0 ) ; if ( size == 2 ) return ( mat [ 0 ] [ 0 ] == 0 && mat [ 0 ] [ 1 ] == 1 && mat [ 1 ] [ 0 ] == 1 && mat [ 1 ] [ 1 ] == 0 ) ; for ( int i = 0 ; i < size ; i ++ ) { int degreeI = 0 ; for ( int j = 0 ; j < size ; j ++ ) if ( mat [ i ] [ j ] ) degreeI ++ ; if ( degreeI == 1 ) vertexD1 ++ ; else if ( degreeI == size - 1 ) vertexDn_1 ++ ; } return ( vertexD1 == ( size - 1 ) && vertexDn_1 == 1 ) ; } int main ( ) { int mat [ size ] [ size ] = { { 0 , 1 , 1 , 1 } , { 1 , 0 , 0 , 0 } , { 1 , 0 , 0 , 0 } , { 1 , 0 , 0 , 0 } } ; checkStar ( mat ) ? cout << " Star ▁ Graph " : cout << " Not ▁ a ▁ Star ▁ Graph " ; return 0 ; }

Index/key variables: i, j, size
Accumulator variables: degreeI, i, j, stdc, vertexD1, vertexDn_1
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int orientation ( pair < int , int > a , pair < int , int > b , pair < int , int > c ) { int res = ( b . second - a . second ) * ( c . first - b . first ) - ( c . second - b . second ) * ( b . first - a . first ) ; if ( res == 0 ) return 0 ; if ( res > 0 ) return 1 ; return -1 ; } int sqDist ( pair < int , int > p1 , pair < int , int > p2 ) { return ( p1 . first - p2 . first ) * ( p1 . first - p2 . first ) + ( p1 . second - p2 . second ) * ( p1 . second - p2 . second ) ; } bool inside ( vector < pair < int , int > > a , pair < int , int > p ) { pair < int , int > mid = { 0 , 0 } ; int n = a . size ( ) ; p . first *= n ; p . second *= n ; for ( int i = 0 ; i < n ; i ++ ) { mid . first += a [ i ] . first ; mid . second += a [ i ] . second ; a [ i ] . first *= n ; a [ i ] . second *= n ; } for ( int i = 0 , j ; i < n ; i ++ ) { j = ( i + 1 ) % n ; int x1 = a [ i ] . first , x2 = a [ j ] . first ; int y1 = a [ i ] . second , y2 = a [ j ] . second ; int a1 = y1 - y2 ; int b1 = x2 - x1 ; int c1 = x1 * y2 - y1 * x2 ; int for_mid = a1 * mid . first + b1 * mid . second + c1 ; int for_p = a1 * p . first + b1 * p . second + c1 ; if ( for_mid * for_p < 0 ) return false ; } return true ; } void addPoint ( vector < pair < int , int > > & a , pair < int , int > p ) { if ( inside ( a , p ) ) return ; int ind = 0 ; int n = a . size ( ) ; for ( int i = 1 ; i < n ; i ++ ) if ( sqDist ( p , a [ i ] ) < sqDist ( p , a [ ind ] ) ) ind = i ; int up = ind ; while ( orientation ( p , a [ up ] , a [ ( up + 1 ) % n ] ) >= 0 ) up = ( up + 1 ) % n ; int low = ind ; while ( orientation ( p , a [ low ] , a [ ( n + low - 1 ) % n ] ) <= 0 ) low = ( n + low - 1 ) % n ; vector < pair < int , int > > ret ; int curr = up ; ret . push_back ( a [ curr ] ) ; while ( curr != low ) { curr = ( curr + 1 ) % n ; ret . push_back ( a [ curr ] ) ; } ret . push_back ( p ) ; a . clear ( ) ; for ( int i = 0 ; i < ret . size ( ) ; i ++ ) a . push_back ( ret [ i ] ) ; } int main ( ) { vector < pair < int , int > > a ; a . push_back ( { 0 , 0 } ) ; a . push_back ( { 3 , -1 } ) ; a . push_back ( { 4 , 5 } ) ; a . push_back ( { -1 , 4 } ) ; int n = a . size ( ) ; pair < int , int > p = { 100 , 100 } ; addPoint ( a , p ) ; for ( auto e : a ) cout << " ( " << e . first << " , ▁ " << e . second << " ) ▁ " ; return 0 ; }

Index/key variables: curr, i, ind, j, low, up
Accumulator variables: first, i, second, stdc
Iterator variables: e, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getDistance ( int x1 , int y1 , int x2 , int y2 ) { return ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1 ) * ( y2 - y1 ) ; } void triangleWithNoPointInside ( int points [ ] [ 2 ] , int N ) { int first = 0 ; int second , third ; int minD = INT_MAX ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == first ) continue ; int d = getDistance ( points [ i ] [ 0 ] , points [ i ] [ 1 ] , points [ first ] [ 0 ] , points [ first ] [ 1 ] ) ; if ( minD > d ) { minD = d ; second = i ; } } minD = INT_MAX ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == first i == second ) continue ; int d = getDistance ( points [ i ] [ 0 ] , points [ i ] [ 1 ] , points [ first ] [ 0 ] , points [ first ] [ 1 ] ) ; if ( ( points [ i ] [ 0 ] - points [ first ] [ 0 ] ) * ( points [ second ] [ 1 ] - points [ first ] [ 1 ] ) != ( points [ second ] [ 0 ] - points [ first ] [ 0 ] ) * ( points [ i ] [ 1 ] - points [ first ] [ 1 ] ) && minD > d ) { minD = d ; third = i ; } } cout << points [ first ] [ 0 ] << " , ▁ " << points [ first ] [ 1 ] << endl ; cout << points [ second ] [ 0 ] << " , ▁ " << points [ second ] [ 1 ] << endl ; cout << points [ third ] [ 0 ] << " , ▁ " << points [ third ] [ 1 ] << endl ; } int main ( ) { int points [ ] [ 2 ] = { { 0 , 0 } , { 0 , 2 } , { 2 , 0 } , { 2 , 2 } , { 1 , 1 } } ; int N = sizeof ( points ) / sizeof ( points [ 0 ] ) ; triangleWithNoPointInside ( points , N ) ; return 0 ; }

Index/key variables: first, i, second, third
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int mxn = 1e4 + 1 ; bool prime [ mxn + 1 ] ; void SieveOfEratosthenes ( ) { memset ( prime , true , sizeof ( prime ) ) ; for ( int p = 2 ; p * p <= mxn ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= mxn ; i += p ) prime [ i ] = false ; } } } int countMin ( int arr [ ] , int n ) { int cMinSwaps = 0 ; int cPrimeIndices = 0 ; int cPrimeNos = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ i + 1 ] ) { cPrimeIndices ++ ; if ( ! prime [ arr [ i ] ] ) cMinSwaps ++ ; else cPrimeNos ++ ; } else if ( prime [ arr [ i ] ] ) { cPrimeNos ++ ; } } if ( cPrimeNos >= cPrimeIndices ) return cMinSwaps ; else return -1 ; } int main ( ) { SieveOfEratosthenes ( ) ; int n = 5 ; int arr [ 5 ] = { 2 , 7 , 8 , 5 , 13 } ; cout << countMin ( arr , n ) ; return 0 ; }

Index/key variables: i, p
Accumulator variables: cMinSwaps, cPrimeIndices, cPrimeNos, i, p, stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; void largestSubset ( int a [ ] , int N ) { int bit [ 32 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { int x = 31 ; while ( a [ i ] > 0 ) { if ( a [ i ] & 1 == 1 ) { bit [ x ] ++ ; } a [ i ] = a [ i ] >> 1 ; x -- ; } } cout << * max_element ( bit , bit + 32 ) ; } int main ( ) { int arr [ ] = { 7 , 13 , 8 , 2 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; largestSubset ( arr , N ) ; return 0 ; }

Index/key variables: i, x
Accumulator variables: i, stdc, x
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Find ( vector < int > & parent , int a ) { return parent [ a ] = ( parent [ a ] == a ) ? a : ( Find ( parent , parent [ a ] ) ) ; } void Union ( vector < int > & parent , vector < int > & rank , vector < int > & maxValue , int a , int b ) { a = Find ( parent , a ) ; b = Find ( parent , b ) ; if ( a == b ) return ; if ( rank [ a ] == rank [ b ] ) { rank [ a ] ++ ; } if ( rank [ a ] < rank [ b ] ) { int temp = a ; a = b ; b = temp ; } parent [ b ] = a ; maxValue [ a ] = max ( maxValue [ a ] , maxValue [ b ] ) ; } void findMaxValueOfSet ( vector < pair < int , int > > & arr , vector < int > & queries , int R , int N , int M ) { vector < int > parent ( R + 1 ) ; vector < int > rank ( R + 1 , 0 ) ; vector < int > maxValue ( R + 1 ) ; for ( int i = 1 ; i < R + 1 ; i ++ ) { parent [ i ] = maxValue [ i ] = i ; } for ( int i = 0 ; i < N ; i ++ ) { Union ( parent , rank , maxValue , arr [ i ] . first , arr [ i ] . second ) ; } for ( int i = 0 ; i < M ; i ++ ) { int P = Find ( parent , queries [ i ] ) ; cout << maxValue [ P ] << " ▁ " ; } } int main ( ) { int R = 5 ; vector < pair < int , int > > arr { { 1 , 2 } , { 2 , 3 } , { 4 , 5 } } ; vector < int > queries { 2 , 4 , 1 , 3 } ; int N = arr . size ( ) ; int M = queries . size ( ) ; findMaxValueOfSet ( arr , queries , R , N , M ) ; return 0 ; }

Index/key variables: P, a, b, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxAns = INT_MIN ; int Find ( vector < int > & parent , int a ) { return parent [ a ] = ( parent [ a ] == a ) ? a : ( Find ( parent , parent [ a ] ) ) ; } void Union ( vector < int > & parent , vector < int > & rank , vector < int > & setSum , int a , int b ) { a = Find ( parent , a ) ; b = Find ( parent , b ) ; if ( a == b ) return ; if ( rank [ a ] > rank [ b ] ) rank [ a ] ++ ; if ( rank [ b ] > rank [ a ] ) swap ( a , b ) ; parent [ b ] = a ; setSum [ a ] += setSum [ b ] ; } void maxValues ( vector < int > arr , vector < int > queries , int N ) { vector < int > parent ( N + 1 ) ; vector < int > rank ( N + 1 , 0 ) ; vector < int > setSum ( N + 1 , 0 ) ; vector < int > currMax ; for ( int i = 1 ; i < N + 1 ; i ++ ) { parent [ i ] = -1 ; setSum [ i ] = arr [ i - 1 ] ; } currMax . push_back ( 0 ) ; for ( int i = N - 1 ; i > 0 ; i -- ) { if ( parent [ queries [ i ] ] == -1 ) { parent [ queries [ i ] ] = queries [ i ] ; } if ( queries [ i ] - 1 >= 0 && parent [ queries [ i ] - 1 ] != -1 ) { Union ( parent , rank , setSum , queries [ i ] , queries [ i ] - 1 ) ; } if ( queries [ i ] + 1 <= N && parent [ queries [ i ] + 1 ] != -1 ) { Union ( parent , rank , setSum , queries [ i ] , queries [ i ] + 1 ) ; } maxAns = max ( setSum [ queries [ i ] ] , maxAns ) ; currMax . push_back ( maxAns ) ; } for ( int i = currMax . size ( ) - 1 ; i >= 0 ; i -- ) { cout << currMax [ i ] << " ▁ " ; } } int main ( ) { vector < int > arr = { 1 , 3 , 2 , 5 } ; vector < int > queries = { 3 , 4 , 1 , 2 } ; int N = arr . size ( ) ; maxValues ( arr , queries , N ) ; return 0 ; }

Index/key variables: a, b, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int val ; vector < Node * > child ; } ; Node * newNode ( int key ) { Node * temp = new Node ; temp -> val = key ; return temp ; } void zigzagLevelOrder ( Node * root ) { if ( root == NULL ) return ; vector < vector < int > > result ; queue < Node * > q ; q . push ( root ) ; while ( ! q . empty ( ) ) { int size = q . size ( ) ; vector < int > curLevel ; for ( int i = 0 ; i < size ; i ++ ) { Node * node = q . front ( ) ; q . pop ( ) ; curLevel . push_back ( node -> val ) ; for ( int j = 0 ; j < node -> child . size ( ) ; j ++ ) { q . push ( node -> child [ j ] ) ; } } result . push_back ( curLevel ) ; } for ( int i = 0 ; i < result . size ( ) ; i ++ ) { if ( ( i + 1 ) % 2 == 0 ) { reverse ( result [ i ] . begin ( ) , result [ i ] . end ( ) ) ; } for ( int j = 0 ; j < result [ i ] . size ( ) ; j ++ ) { cout << result [ i ] [ j ] << " ▁ " ; } cout << endl ; } } zigzagLevelOrder ( root ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long int
void minDisIncludingNode ( int n , int m , int edges [ ] [ 2 ] ) { vector < ll > g [ 10005 ] ; for ( int i = 0 ; i < m ; i ++ ) { int a = edges [ i ] [ 0 ] - 1 ; int b = edges [ i ] [ 1 ] - 1 ; g [ a ] . push_back ( b ) ; g [ b ] . push_back ( a ) ; } queue < pair < ll , ll > > q ; q . push ( { 0 , 0 } ) ; vector < int > dist ( n , 1e9 ) ; dist [ 0 ] = 0 ; while ( ! q . empty ( ) ) { auto up = q . front ( ) ; q . pop ( ) ; int x = up . first ; int lev = up . second ; if ( lev > dist [ x ] ) continue ; if ( x == n - 1 ) continue ; for ( ll y : g [ x ] ) { if ( dist [ y ] > lev + 1 ) { dist [ y ] = lev + 1 ; q . push ( { y , lev + 1 } ) ; } } } queue < pair < ll , ll > > q1 ; q1 . push ( { n - 1 , 0 } ) ; vector < int > dist1 ( n , 1e9 ) ; dist1 [ n - 1 ] = 0 ; while ( ! q1 . empty ( ) ) { auto up = q1 . front ( ) ; q1 . pop ( ) ; int x = up . first ; int lev = up . second ; if ( lev > dist1 [ x ] ) continue ; if ( x == 0 ) continue ; for ( ll y : g [ x ] ) { if ( dist1 [ y ] > lev + 1 ) { dist1 [ y ] = lev + 1 ; q1 . push ( { y , lev + 1 } ) ; } } } for ( int i = 0 ; i < n ; i ++ ) { if ( dist [ i ] + dist1 [ i ] > 1e9 ) cout << -1 << " ▁ " ; else cout << dist [ i ] + dist1 [ i ] << " ▁ " ; } } int main ( ) { int n = 5 ; int m = 7 ; int edges [ m ] [ 2 ] = { { 1 , 2 } , { 1 , 4 } , { 2 , 3 } , { 2 , 5 } , { 4 , 3 } , { 4 , 5 } , { 1 , 5 } } ; minDisIncludingNode ( n , m , edges ) ; return 0 ; }

Index/key variables: a, b, i, m, x, y
Accumulator variables: i, stdc
Iterator variables: i, y
C++ program:
#include <bits/stdc++.h>
using namespace std ; int canPossibleReplacement ( int N , int arr [ ] ) { int S = 0 ; int i ; for ( i = 0 ; i < N ; i ++ ) S += arr [ i ] ; int P = 1 ; for ( i = 0 ; i < N ; i ++ ) { P *= i ; } for ( int i = 0 ; i < N ; i ++ ) { int x = arr [ i ] ; int y = ( S - x ) / ( P / x - 1 ) ; if ( ( S - x + y ) == ( P * y ) / x ) return 1 ; } return 0 ; } int main ( ) { int N = 3 ; int arr [ ] = { 1 , 3 , 4 } ; if ( canPossibleReplacement ( N , arr ) == 1 ) cout << ( " Yes " ) ; else cout << ( " No " ) ; return 0 ; }

Index/key variables: i
Accumulator variables: P, S, i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; string checkSameDigits ( int N ) { int length = ( N ) + 1 ; int M = ( ( 10 , length ) - 1 ) / ( 10 - 1 ) ; M *= N % 10 ; if ( M = N ) return " Yes " ; return " No " ; } int main ( ) { int N = 222 ; cout << checkSameDigits ( N ) ; }

Accumulator variables: M
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int val ; vector < Node * > child ; } ; Node * newNode ( int key ) { Node * temp = new Node ; temp -> val = key ; return temp ; } void DFS ( Node * root , int sum , int & ans ) { if ( root -> child . size ( ) == 0 ) { ans = max ( ans , sum ) ; return ; } for ( int i = 0 ; i < root -> child . size ( ) ; i ++ ) { DFS ( root -> child [ i ] , sum + root -> child [ i ] -> val , ans ) ; } } Node * root = newNode ( 1 ) ; ( root -> child ) . push_back ( newNode ( 2 ) ) ; ( root -> child ) . push_back ( newNode ( 3 ) ) ; ( root -> child [ 0 ] -> child ) . push_back ( newNode ( 4 ) ) ; ( root -> child [ 1 ] -> child ) . push_back ( newNode ( 6 ) ) ; ( root -> child [ 0 ] -> child ) . push_back ( newNode ( 5 ) ) ; ( root -> child [ 1 ] ) -> child . push_back ( newNode ( 7 ) ) ; ( root -> child [ 1 ] -> child ) . push_back ( newNode ( 8 ) ) ; int maxSumPath = 0 ; DFS ( root , root -> val , maxSumPath ) ; cout << maxSumPath ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countTriplets ( int size , int queries , int arr [ ] , int Q [ ] [ 2 ] ) { int arr_even [ size + 1 ] , arr_odd [ size + 1 ] ; int even = 0 , odd = 0 ; arr_even [ 0 ] = 0 ; arr_odd [ 0 ] = 0 ; for ( int i = 0 ; i < size ; i ++ ) { if ( arr [ i ] % 2 ) { odd ++ ; } else { even ++ ; } arr_even [ i + 1 ] = even ; arr_odd [ i + 1 ] = odd ; } for ( int i = 0 ; i < queries ; i ++ ) { int l = Q [ i ] [ 0 ] , r = Q [ i ] [ 1 ] ; int odd = arr_odd [ r ] - arr_odd [ l - 1 ] ; int even = arr_even [ r ] - arr_even [ l - 1 ] ; int ans = ( even * ( even - 1 ) * ( even - 2 ) ) / 6 + ( odd * ( odd - 1 ) / 2 ) * even ; cout << ans << " ▁ " ; } } int main ( ) { int N = 6 , Q = 2 ; int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int queries [ ] [ 2 ] = { { 1 , 3 } , { 2 , 5 } } ; countTriplets ( N , Q , arr , queries ) ; return 0 ; }

Index/key variables: i, r
Accumulator variables: even, i, odd, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void maxRightmostElement ( int N , int k , int p , int arr [ ] ) { while ( k ) { for ( int i = N - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] >= p ) { arr [ i ] = arr [ i ] - p ; arr [ i + 1 ] = arr [ i + 1 ] + p ; break ; } } k -- ; } cout << arr [ N - 1 ] << endl ; } int main ( ) { int N = 4 , p = 2 , k = 5 , arr [ ] = { 3 , 8 , 1 , 4 } ; maxRightmostElement ( N , k , p , arr ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, k
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int nCr ( int n , int r , int f [ ] ) { if ( n < r ) { return 0 ; } return f [ n ] / ( f [ r ] * f [ n - r ] ) ; } int findMean ( int N , int X ) { int f [ N + 1 ] ; f [ 0 ] = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { f [ i ] = f [ i - 1 ] * i ; } int total = nCr ( N , X , f ) ; int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { count += nCr ( N - i , X - 1 , f ) * i ; } double E_X = double ( count ) / double ( total ) ; cout << setprecision ( 10 ) << E_X ; return 0 ; } int main ( ) { int N = 3 , X = 2 ; findMean ( N , X ) ; return 0 ; }

Index/key variables: i, n, r
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumNumberofpairs ( int n , int arr [ ] ) { int x = 0 ; int y = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { x ++ ; } else { y ++ ; } } int answer = min ( x , y ) ; if ( abs ( x - y ) >= 2 ) { answer ++ ; } return answer ; } int main ( ) { int arr [ ] = { 1 , 2 , 4 , 6 , 5 , 10 , 12 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maximumNumberofpairs ( n , arr ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: answer, i, stdc, x, y
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void pairwiseProductSum ( int a [ ] , int l , int r ) { int sum = 0 ; for ( int j = l - 1 ; j <= r - 1 ; j ++ ) { for ( int k = j + 1 ; k <= r - 1 ; k ++ ) { sum += ( a [ j ] * a [ k ] ) ; } } cout << sum << endl ; } void updateArray ( int * a , int p , int x ) { a [ p - 1 ] = x ; } void solveQueries ( int * a , int n , int Q , int query [ ] [ 3 ] ) { for ( int i = 0 ; i < Q ; i ++ ) { if ( query [ i ] [ 0 ] == 1 ) pairwiseProductSum ( a , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; else updateArray ( a , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; } } int main ( ) { int A [ ] = { 5 , 7 , 2 , 3 , 1 } ; int N = sizeof ( A ) / sizeof ( int ) ; int Q = 3 ; int query [ Q ] [ 3 ] = { { 1 , 1 , 3 } , { 2 , 2 , 5 } , { 1 , 2 , 5 } } ; solveQueries ( A , N , Q , query ) ; return 0 ; }

Index/key variables: Q, i, j, k
Accumulator variables: i, j, k, stdc, sum
Iterator variables: i, j, k