dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; using System . Collections . Generic ; class GFG { static List < int > [ ] vec = new List < int > [ 100001 ] ; static bool [ ] vis = new bool [ 100001 ] ; static int cc = 1 ; static void dfs ( int node ) { vis [ node ] = true ; foreach ( int x in vec [ node ] ) { if ( ! vis [ x ] ) { cc ++ ; dfs ( x ) ; } } } static void addEdge ( int u , int v ) { vec [ u ] . Add ( v ) ; vec [ v ] . Add ( u ) ; } static void minEdgeRemoved ( int N , int M , int [ , ] Edges ) { for ( int i = 0 ; i < M ; i ++ ) { addEdge ( Edges [ i , 0 ] , Edges [ i , 1 ] ) ; } int k = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( ! vis [ i ] ) { cc = 1 ; dfs ( i ) ; k ++ ; } } Console . Write ( M - N + k + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int N = 3 , M = 2 ; int [ , ] Edges = { { 1 , 2 } , { 2 , 3 } } ; for ( int i = 0 ; i < vec . Length ; i ++ ) vec [ i ] = new List < int > ( ) ; minEdgeRemoved ( N , M , Edges ) ; } }

Index/key variables: i, node, u, v, x
Accumulator variables: cc, i, k
Iterator variables: i, x
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static bool pairFound = false ; class Node { public int data ; public Node left , right ; } ; static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static void pairSum ( Node root , int target , HashSet < int > S ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { if ( S . Contains ( target - root . data ) ) { Console . Write ( target - root . data + " ▁ " + root . data ) ; pairFound = true ; return ; } else S . Add ( root . data ) ; } pairSum ( root . left , target , S ) ; pairSum ( root . right , target , S ) ; } public static void Main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right = newNode ( 3 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; root . right . right . right = newNode ( 8 ) ; HashSet < int > S = new HashSet < int > ( ) ; int K = 13 ; pairSum ( root , K , S ) ; if ( pairFound == false ) Console . Write ( " - 1" ) ; } }

Boolean variables: pairFound
Class/struct names: GFG, Node
C# program:
using System ; class GFG { private static void countRooks ( int n , int k , int [ , ] pos ) { int [ ] row = new int [ n ] ; int [ ] col = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { row [ i ] = 0 ; col [ i ] = 0 ; } for ( int i = 0 ; i < k ; i ++ ) { row [ pos [ i , 0 ] - 1 ] = 1 ; col [ pos [ i , 1 ] - 1 ] = 1 ; } int res = n - k ; Console . WriteLine ( res + " ▁ " ) ; int ri = 0 , ci = 0 ; while ( res -- > 0 ) { while ( row [ ri ] == 1 ) { ri ++ ; } while ( col [ ci ] == 1 ) { ci ++ ; } Console . WriteLine ( ( ri + 1 ) + " ▁ " + ( ci + 1 ) + " ▁ " ) ; ri ++ ; ci ++ ; } } public static void Main ( String [ ] args ) { int N = 4 ; int K = 2 ; int [ , ] pos = { { 1 , 4 } , { 2 , 2 } } ; countRooks ( N , K , pos ) ; } }

Index/key variables: ci, i, n, ri
Accumulator variables: ci, i, res, ri
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; public class GFG { static int minInsertion ( String str ) { int n = str . Length ; int res = 0 ; int [ ] count = new int [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) count [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( count [ i ] % 2 == 1 ) res ++ ; } return ( res == 0 ) ? 0 : res - 1 ; } public static void Main ( ) { string str = " geeksforgeeks " ; Console . WriteLine ( minInsertion ( str ) ) ; } }

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static bool check ( String ans , String [ ] s , int n , int m ) { for ( int i = 1 ; i < n ; ++ i ) { int count = 0 ; for ( int j = 0 ; j < m ; ++ j ) { if ( ans [ j ] != s [ i ] [ j ] ) count ++ ; } if ( count > 1 ) return false ; } return true ; } static String findString ( String [ ] s ) { int n = s . Length ; String ans = s [ 0 ] ; int m = ans . Length ; int flag = 0 ; for ( int i = 0 ; i < m ; ++ i ) { for ( int j = 0 ; j < 26 ; ++ j ) { String x = ans ; x = x . Replace ( x [ i ] , ( char ) ( j + ' a ' ) ) ; if ( check ( x , s , n , m ) ) { ans = x ; flag = 1 ; break ; } } if ( flag == 1 ) break ; } if ( flag == 0 ) return " - 1" ; else return ans ; } public static void Main ( String [ ] args ) { String [ ] s = { " geeks " , " teeds " } ; Console . WriteLine ( findString ( s ) ) ; } }

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public static int getMinOps ( int [ ] arr ) { int ans = 0 ; for ( int i = 0 ; i < arr . Length - 1 ; i ++ ) { ans += Math . Max ( arr [ i ] - arr [ i + 1 ] , 0 ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 1 , 2 , 4 } ; Console . WriteLine ( getMinOps ( arr ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int maxdiff ( int [ ] arr , int n ) { Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq . ContainsKey ( arr [ i ] ) ) freq [ arr [ i ] ] ++ ; else freq . Add ( arr [ i ] , 1 ) ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( freq [ arr [ i ] ] > freq [ arr [ j ] ] && arr [ i ] > arr [ j ] ) ans = Math . Max ( ans , freq [ arr [ i ] ] - freq [ arr [ i ] ] ) ; else if ( freq [ arr [ i ] ] < freq [ arr [ j ] ] && arr [ i ] < arr [ j ] ) ans = Math . Max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] ) ; } } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 1 , 3 , 2 , 3 , 2 } ; int n = arr . Length ; Console . WriteLine ( maxdiff ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System . Collections . Generic ; using System ; class GFG { static int maxdiff ( int [ ] arr , int n ) { Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; List < int > dist = new List < int > ( ) ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq . ContainsKey ( arr [ i ] ) == false ) { dist . Add ( arr [ i ] ) ; j ++ ; } if ( freq . ContainsKey ( arr [ i ] ) ) freq [ arr [ i ] ] ++ ; else freq [ arr [ i ] ] = 1 ; } dist . Sort ( ) ; int min_freq = n + 1 ; int ans = 0 ; for ( int i = 0 ; i < j ; i ++ ) { int cur_freq = freq [ dist [ i ] ] ; ans = Math . Max ( ans , cur_freq - min_freq ) ; min_freq = Math . Min ( min_freq , cur_freq ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 1 , 3 , 2 , 3 , 2 } ; int n = arr . Length ; Console . WriteLine ( maxdiff ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int n , m , X ; public static int maxSum ( int [ , ] grid ) { int [ , ] prefsum = new int [ n , m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int x = 0 ; x < m ; x ++ ) { if ( x == 0 ) prefsum [ i , x ] = grid [ i , x ] ; else prefsum [ i , x ] = prefsum [ i , x - 1 ] + grid [ i , x ] ; } } int [ , ] dp = new int [ n , X + 1 ] ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 1 ; j <= X ; ++ j ) dp [ i , j ] = int . MinValue ; for ( int i = 0 ; i < n ; i ++ ) dp [ i , 0 ] = 0 ; for ( int i = 1 ; i <= Math . Min ( m , X ) ; ++ i ) { dp [ 0 , i ] = dp [ 0 , i - 1 ] + grid [ 0 , i - 1 ] ; } for ( int i = 1 ; i < n ; ++ i ) { for ( int j = 1 ; j <= X ; ++ j ) { dp [ i , j ] = dp [ i - 1 , j ] ; for ( int x = 1 ; x <= Math . Min ( j , m ) ; x ++ ) { dp [ i , j ] = Math . Max ( dp [ i , j ] , dp [ i - 1 , j - x ] + prefsum [ i , x - 1 ] ) ; } } } return dp [ n - 1 , X ] ; } public static void Main ( String [ ] args ) { n = 4 ; m = 4 ; X = 6 ; int [ , ] grid = { { 3 , 2 , 6 , 1 } , { 1 , 9 , 2 , 4 } , { 4 , 1 , 3 , 9 } , { 3 , 8 , 2 , 1 } } ; int ans = maxSum ( grid ) ; Console . WriteLine ( ans ) ; } }

Accumulator variables: i, x
Iterator variables: i, j, x
Class/struct names: GFG
C# program:
using System ; class GFG { static int findDiff ( int [ ] arr , int n ) { Array . Sort ( arr ) ; int count = 0 , max_count = 0 , min_count = n ; for ( int i = 0 ; i < ( n - 1 ) ; i ++ ) { if ( arr [ i ] == arr [ i + 1 ] ) { count += 1 ; continue ; } else { max_count = Math . Max ( max_count , count ) ; min_count = Math . Min ( min_count , count ) ; count = 0 ; } } return ( max_count - min_count ) ; } public static void Main ( ) { int [ ] arr = { 7 , 8 , 4 , 5 , 4 , 1 , 1 , 7 , 7 , 2 , 5 } ; int n = arr . Length ; Console . WriteLine ( findDiff ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int min_operations ( int [ ] A , int n ) { if ( n == 0 ) return 0 ; int ans = A [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( A [ i ] > A [ i - 1 ] ) { ans += A [ i ] - A [ i - 1 ] ; } } return ans ; } public static void Main ( ) { int n = 5 ; int [ ] A = { 1 , 2 , 3 , 2 , 1 } ; Console . WriteLine ( min_operations ( A , n ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int findDiff ( int [ ] arr , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( arr [ i ] ) ) { var val = mp [ arr [ i ] ] ; mp . Remove ( arr [ i ] ) ; mp . Add ( arr [ i ] , val + 1 ) ; } else { mp . Add ( arr [ i ] , 1 ) ; } } int max_count = 0 , min_count = n ; foreach ( KeyValuePair < int , int > entry in mp ) { max_count = Math . Max ( max_count , entry . Value ) ; min_count = Math . Min ( min_count , entry . Value ) ; } return ( max_count - min_count ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 7 , 8 , 4 , 5 , 4 , 1 , 1 , 7 , 7 , 2 , 5 } ; int n = arr . Length ; Console . WriteLine ( findDiff ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: entry, i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GfG { class Node { public int data ; public Node left , right ; } static bool areIdentical ( Node root1 , Node root2 ) { if ( root1 == null && root2 == null ) return true ; if ( root1 == null root2 == null ) return false ; Queue < Node > q1 = new Queue < Node > ( ) ; Queue < Node > q2 = new Queue < Node > ( ) ; q1 . Enqueue ( root1 ) ; q2 . Enqueue ( root2 ) ; while ( q1 . Count != 0 && q2 . Count != 0 ) { Node n1 = q1 . Peek ( ) ; Node n2 = q2 . Peek ( ) ; if ( n1 . data != n2 . data ) return false ; q1 . Dequeue ( ) ; q2 . Dequeue ( ) ; if ( n1 . left != null && n2 . left != null ) { q1 . Enqueue ( n1 . left ) ; q2 . Enqueue ( n2 . left ) ; } else if ( n1 . left != null n2 . left != null ) return false ; if ( n1 . right != null && n2 . right != null ) { q1 . Enqueue ( n1 . right ) ; q2 . Enqueue ( n2 . right ) ; } else if ( n1 . right != null n2 . right != null ) return false ; } return true ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = null ; temp . right = null ; return temp ; } public static void Main ( String [ ] args ) { Node root1 = newNode ( 1 ) ; root1 . left = newNode ( 2 ) ; root1 . right = newNode ( 3 ) ; root1 . left . left = newNode ( 4 ) ; root1 . left . right = newNode ( 5 ) ; Node root2 = newNode ( 1 ) ; root2 . left = newNode ( 2 ) ; root2 . right = newNode ( 3 ) ; root2 . left . left = newNode ( 4 ) ; root2 . left . right = newNode ( 5 ) ; if ( areIdentical ( root1 , root2 ) == true ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }

Class/struct names: GfG, Node
C# program:
using System ; class GFG { static readonly int MAX_NODES = 100005 ; static int [ ] parent = new int [ MAX_NODES ] ; static int [ ] size_set = new int [ MAX_NODES ] ; static void make_set ( int v ) { parent [ v ] = v ; size_set [ v ] = 1 ; } static int find_set ( int v ) { if ( v == parent [ v ] ) return v ; return parent [ v ] = find_set ( parent [ v ] ) ; } static void union_set ( int a , int b ) { a = find_set ( a ) ; b = find_set ( b ) ; if ( a != b ) { if ( size_set [ a ] < size_set [ b ] ) { a = a + b ; b = a - b ; a = a - b ; } parent [ b ] = a ; size_set [ a ] += size_set [ b ] ; } } static String check ( int a , int b ) { a = find_set ( a ) ; b = find_set ( b ) ; return ( a == b ) ? " Yes " : " No " ; } public static void Main ( String [ ] args ) { int n = 5 , m = 3 ; make_set ( 1 ) ; make_set ( 2 ) ; make_set ( 3 ) ; make_set ( 4 ) ; make_set ( 5 ) ; union_set ( 1 , 3 ) ; union_set ( 3 , 4 ) ; union_set ( 3 , 5 ) ; Console . Write ( check ( 1 , 5 ) + " STRNEWLINE " ) ; Console . Write ( check ( 3 , 2 ) + " STRNEWLINE " ) ; Console . Write ( check ( 5 , 2 ) + " STRNEWLINE " ) ; } }

Index/key variables: MAX_NODES, a, b, v
Class/struct names: GFG
C# program:
using System ; class GFG { public static long count ( int N , int A , int B ) { if ( N == 1 ) { return 9 / B + 1 ; } int max_sum = 9 * N ; int odd_count = N / 2 + N % 2 ; int even_count = N - odd_count ; long [ , ] dp = new long [ even_count , max_sum + 1 ] ; for ( int i = 0 ; i <= 9 ; i ++ ) dp [ 0 , i % A ] ++ ; for ( int i = 1 ; i < even_count ; i ++ ) { for ( int j = 0 ; j <= 9 ; j ++ ) { for ( int k = 0 ; k <= max_sum ; k ++ ) { if ( dp [ i - 1 , k ] > 0 ) dp [ i , ( j + k ) % A ] += dp [ i - 1 , k ] ; } } } long [ , ] dp1 = new long [ odd_count , max_sum + 1 ] ; for ( int i = 1 ; i <= 9 ; i ++ ) dp1 [ 0 , i % B ] ++ ; for ( int i = 1 ; i < odd_count ; i ++ ) { for ( int j = 0 ; j <= 9 ; j ++ ) { for ( int k = 0 ; k <= max_sum ; k ++ ) { if ( dp1 [ i - 1 , k ] > 0 ) dp1 [ i , ( j + k ) % B ] += dp1 [ i - 1 , k ] ; } } } return dp [ even_count - 1 , 0 ] * dp1 [ odd_count - 1 , 0 ] ; } public static void Main ( String [ ] args ) { int N = 2 , A = 2 , B = 5 ; Console . WriteLine ( count ( N , A , B ) ) ; } }

Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; public class GFG { static int maxDiff ( int [ ] arr , int n ) { int SubsetSum_1 = 0 , SubsetSum_2 = 0 ; for ( int i = 0 ; i <= n - 1 ; i ++ ) { bool isSingleOccurance = true ; for ( int j = i + 1 ; j <= n - 1 ; j ++ ) { if ( arr [ i ] == arr [ j ] ) { isSingleOccurance = false ; arr [ i ] = arr [ j ] = 0 ; break ; } } if ( isSingleOccurance ) { if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ; else SubsetSum_2 += arr [ i ] ; } } return Math . Abs ( SubsetSum_1 - SubsetSum_2 ) ; } static public void Main ( ) { int [ ] arr = { 4 , 2 , - 3 , 3 , - 2 , - 2 , 8 } ; int n = arr . Length ; Console . WriteLine ( " Maximum ▁ Difference ▁ = ▁ " + maxDiff ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: SubsetSum_1, SubsetSum_2, i, j
Iterator variables: i, j
Boolean variables: isSingleOccurance
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int NN = ( int ) 3e5 ; static List < int > [ ] G = new List < int > [ NN + 1 ] ; static int dfs ( int node , int A , int [ ] subtree_size , int [ ] visited , int [ ] check_subtree ) { visited [ node ] = 1 ; subtree_size [ node ] = 1 ; if ( node == A ) { check_subtree [ node ] = 1 ; } else check_subtree [ node ] = 0 ; foreach ( int v in G [ node ] ) { if ( visited [ v ] == 0 ) { subtree_size [ node ] += dfs ( v , A , subtree_size , visited , check_subtree ) ; check_subtree [ node ] = check_subtree [ node ] | check_subtree [ v ] ; } } return subtree_size [ node ] ; } static void addedge ( int node1 , int node2 ) { G [ node1 ] . Add ( node2 ) ; G [ node2 ] . Add ( node1 ) ; } static int numberOfPairs ( int N , int B , int A ) { int [ ] subtree_size = new int [ N + 1 ] ; int [ ] visited = new int [ N + 1 ] ; int [ ] check_subtree = new int [ N + 1 ] ; dfs ( B , A , subtree_size , visited , check_subtree ) ; int difference = 0 ; foreach ( int v in G [ B ] ) { if ( check_subtree [ v ] > 0 ) { difference = N - subtree_size [ v ] ; break ; } } return ( N * ( N - 1 ) ) - difference * ( subtree_size [ A ] ) ; } public static void Main ( String [ ] args ) { int N = 9 ; int X = 5 , Y = 3 ; for ( int i = 0 ; i < G . Length ; i ++ ) G [ i ] = new List < int > ( ) ; addedge ( 0 , 2 ) ; addedge ( 1 , 2 ) ; addedge ( 2 , 3 ) ; addedge ( 3 , 4 ) ; addedge ( 4 , 6 ) ; addedge ( 4 , 5 ) ; addedge ( 5 , 7 ) ; addedge ( 5 , 8 ) ; Console . Write ( numberOfPairs ( N , Y , X ) ) ; } }

Index/key variables: A, B, i, node, node1, node2, v
Accumulator variables: i
Iterator variables: i, v
Class/struct names: GFG
C# program:
using System ; class GFG { static int equalXORandOR ( int n ) { int m = 0 ; int MSB = ( int ) Math . Log ( n ) ; for ( int i = 0 ; i <= MSB ; i ++ ) { if ( ( n & ( 1 << i ) ) <= 0 ) { m += ( 1 << i ) ; } } return m ; } public static void Main ( String [ ] args ) { int n = 14 ; Console . Write ( equalXORandOR ( n ) ) ; } }

Accumulator variables: i, m
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; public class GFG { static int maxDiff ( int [ ] arr , int n ) { int result = 0 ; Array . Sort ( arr ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] != arr [ i + 1 ] ) result += Math . Abs ( arr [ i ] ) ; else i ++ ; } if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += Math . Abs ( arr [ n - 1 ] ) ; return result ; } static public void Main ( ) { int [ ] arr = { 4 , 2 , - 3 , 3 , - 2 , - 2 , 8 } ; int n = arr . Length ; Console . WriteLine ( " Maximum ▁ Difference ▁ = ▁ " + maxDiff ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static long findNewString ( String s ) { long ans = 0 ; int [ ] freq = new int [ 26 ] ; int n = s . Length ; for ( int i = 0 ; i < ( int ) s . Length ; ++ i ) { ans += freq [ s [ i ] - ' a ' ] ; freq [ s [ i ] - ' a ' ] ++ ; } return ans ; } public static void Main ( String [ ] args ) { String s = " aaabaaa " ; Console . Write ( findNewString ( s ) ) ; } }

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int maxDiff ( int [ ] arr , int n ) { Dictionary < int , int > hashPositive = new Dictionary < int , int > ( ) ; Dictionary < int , int > hashNegative = new Dictionary < int , int > ( ) ; int SubsetSum_1 = 0 , SubsetSum_2 = 0 ; for ( int i = 0 ; i <= n - 1 ; i ++ ) { if ( arr [ i ] > 0 ) { if ( hashPositive . ContainsKey ( arr [ i ] ) ) { hashPositive [ arr [ i ] ] += 1 ; } else { hashPositive . Add ( arr [ i ] , 1 ) ; } } } for ( int i = 0 ; i <= n - 1 ; i ++ ) { if ( arr [ i ] > 0 && hashPositive . ContainsKey ( arr [ i ] ) ) { if ( hashPositive [ arr [ i ] ] == 1 ) { SubsetSum_1 += arr [ i ] ; } } } for ( int i = 0 ; i <= n - 1 ; i ++ ) { if ( arr [ i ] < 0 ) { if ( hashNegative . ContainsKey ( Math . Abs ( arr [ i ] ) ) ) { hashNegative [ Math . Abs ( arr [ i ] ) ] += 1 ; } else { hashNegative . Add ( Math . Abs ( arr [ i ] ) , 1 ) ; } } } for ( int i = 0 ; i <= n - 1 ; i ++ ) { if ( arr [ i ] < 0 && hashNegative . ContainsKey ( Math . Abs ( arr [ i ] ) ) ) { if ( hashNegative [ Math . Abs ( arr [ i ] ) ] == 1 ) { SubsetSum_2 += arr [ i ] ; } } } return Math . Abs ( SubsetSum_1 - SubsetSum_2 ) ; } static void Main ( ) { int [ ] arr = { 4 , 2 , - 3 , 3 , - 2 , - 2 , 8 } ; int n = arr . Length ; Console . WriteLine ( " Maximum ▁ Difference ▁ = ▁ " + maxDiff ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: SubsetSum_1, SubsetSum_2, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static string proofreadSpell ( string str ) { ArrayList result = new ArrayList ( ) ; List < char > result = new List < char > ( ) ; foreach ( char c in str ) { result . Add ( c ) ; int n = result . Count ; if ( n >= 3 ) { if ( result [ n - 1 ] == result [ n - 2 ] && result [ n - 1 ] == result [ n - 3 ] ) { result . RemoveAt ( n - 1 ) ; } } n = result . Count ; if ( n >= 4 ) { if ( result [ n - 1 ] == result [ n - 2 ] && result [ n - 3 ] == result [ n - 4 ] ) { result . RemoveAt ( n - 1 ) ; } } } string resultStr = " " ; foreach ( char c in result ) { resultStr += c ; } return resultStr ; } public static void Main ( string [ ] args ) { string str = " hello " ; Console . Write ( proofreadSpell ( str ) ) ; } }

Accumulator variables: resultStr
Iterator variables: c
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { public static void minRange ( int [ ] arr , int n , int k ) { int l = 0 , r = n ; for ( int i = 0 ; i < n ; i ++ ) { ISet < int > s = new HashSet < int > ( ) ; int j ; for ( j = i ; j < n ; j ++ ) { s . Add ( arr [ j ] ) ; if ( s . Count == k ) { if ( ( j - i ) < ( r - l ) ) { r = j ; l = i ; } break ; } } if ( j == n ) { break ; } } if ( l == 0 && r == n ) { Console . WriteLine ( " Invalid ▁ k " ) ; } else { Console . WriteLine ( l + " ▁ " + r ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = new int [ ] { 1 , 2 , 3 , 4 , 5 } ; int n = arr . Length ; int k = 3 ; minRange ( arr , n , k ) ; } }

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void minRange ( int [ ] arr , int n , int k ) { int l = 0 , r = n ; int j = - 1 ; Dictionary < int , int > hm = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { while ( j < n ) { j ++ ; if ( j < n && hm . Count < k ) if ( hm . ContainsKey ( arr [ j ] ) ) hm [ arr [ j ] ] = hm [ arr [ j ] ] + 1 ; else hm . Add ( arr [ j ] , 1 ) ; if ( hm . Count == k && ( ( r - l ) >= ( j - i ) ) ) { l = i ; r = j ; break ; } } if ( hm . Count < k ) break ; while ( hm . Count == k ) { if ( hm . ContainsKey ( arr [ i ] ) && hm [ arr [ i ] ] == 1 ) hm . Remove ( arr [ i ] ) ; else { if ( hm . ContainsKey ( arr [ i ] ) ) hm [ arr [ i ] ] = hm [ arr [ i ] ] - 1 ; } i ++ ; if ( hm . Count == k && ( r - l ) >= ( j - i ) ) { l = i ; r = j ; } } if ( hm . ContainsKey ( arr [ i ] ) && hm [ arr [ i ] ] == 1 ) hm . Remove ( arr [ i ] ) ; else if ( hm . ContainsKey ( arr [ i ] ) ) hm [ arr [ i ] ] = hm [ arr [ i ] ] - 1 ; } if ( l == 0 && r == n ) Console . WriteLine ( " Invalid ▁ k " ) ; else Console . WriteLine ( l + " ▁ " + r ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 2 , 2 , 3 , 3 , 4 , 5 } ; int n = arr . Length ; int k = 3 ; minRange ( arr , n , k ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GfG { public static int sum ( int [ ] a , int n ) { IDictionary < int , int > cnt = new Dictionary < int , int > ( ) ; int ans = 0 , pre_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += ( i * a [ i ] ) - pre_sum ; pre_sum += a [ i ] ; if ( cnt . ContainsKey ( a [ i ] - 1 ) ) { ans -= cnt [ a [ i ] - 1 ] ; } if ( cnt . ContainsKey ( a [ i ] + 1 ) ) { ans += cnt [ a [ i ] + 1 ] ; } if ( cnt . ContainsKey ( a [ i ] ) ) { cnt [ a [ i ] ] = cnt [ a [ i ] ] + 1 ; } else { cnt [ a [ i ] ] = 1 ; } } return ans ; } public static void Main ( string [ ] args ) { int [ ] a = new int [ ] { 1 , 2 , 3 , 1 , 3 } ; int n = a . Length ; Console . WriteLine ( sum ( a , n ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i, pre_sum
Iterator variables: i
Class/struct names: GfG