import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; if ( k == 0 ) { System . out . print ( ( long ) n * n ) ; return ; } long sum = 0 ; for ( int i = k + 1 ; i <= n ; i ++ ) { sum += ( long ) ( n / i ) * ( i - k ) + Math . max ( n % i - k + 1 , 0 ) ; } System . out . print ( sum ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] tmpArray = br . readLine ( ) . split ( " ▁ " ) ; int n = Integer . parseInt ( tmpArray [ 0 ] ) ; int k = Integer . parseInt ( tmpArray [ 1 ] ) ; long result = 0 ; for ( int b = 1 ; b <= n ; b ++ ) { int p = n / b ; int r = n % b ; result += p * Math . max ( 0 , b - k ) + Math . max ( 0 , r - k + 1 ) ; } if ( k == 0 ) { result -= n ; } System . out . println ( result ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; int k = sc . nextInt ( ) ; sc . close ( ) ; if ( k == 0 ) { System . out . println ( n * n ) ; return ; } long ans = ( n - k + 1 ) * ( n - k ) / 2 ; for ( int i = k + 1 ; i < n ; i ++ ) { long tmp = ( ( n - i ) / i ) * ( i - k ) ; if ( n % i >= k ) { tmp += n % i - k + 1 ; } ans += tmp ; } System . out . println ( ans ) ; } }

import java . util . * ; import java . io . * ; import java . lang . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader bf = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( bf . readLine ( ) ) ; int n = Integer . parseInt ( st . nextToken ( ) ) ; int k = Integer . parseInt ( st . nextToken ( ) ) ; long ans = 0 ; for ( int b = 1 ; b <= n ; b ++ ) { if ( b <= k ) continue ; int remainders_per_b = b - 1 - k + 1 ; ans += 1L * n / b * remainders_per_b ; if ( n % b >= k ) ans += ( n % b ) - k + 1 ; if ( k == 0 ) ans -- ; } System . out . println ( ans ) ; } }

import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { solve ( ) ; } public static void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; long count = 0 ; if ( k == 0 ) { count = ( long ) n * ( long ) n ; } else { for ( int i = 2 ; i <= n ; i ++ ) { if ( i > k ) { count += ( long ) Math . max ( 0 , n / i * ( i - k ) ) ; count += ( long ) Math . max ( 0 , ( n % i ) - k + 1 ) ; } } } System . out . println ( count ) ; } }

N , K = map ( int , input ( ) . split ( ) ) NEW_LINE ans = 0 NEW_LINE for b in range ( 1 , N + 1 ) : NEW_LINE INDENT p = N // b NEW_LINE r = N % b NEW_LINE ans += max ( 0 , b - K ) * p + max ( 0 , r - K + 1 ) NEW_LINE if K == 0 : NEW_LINE INDENT ans -= 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

N , K = map ( int , input ( ) . split ( ) ) NEW_LINE Ans = 0 NEW_LINE if K == 0 : NEW_LINE INDENT print ( N ** 2 ) NEW_LINE DEDENT else : NEW_LINE INDENT def Mods ( i , N , K ) : NEW_LINE INDENT lim = N // i NEW_LINE pattern = i - K NEW_LINE total = lim * pattern NEW_LINE if N - i * lim < K : NEW_LINE INDENT return total NEW_LINE DEDENT else : NEW_LINE INDENT extra = N - i * lim - K + 1 NEW_LINE return total + extra NEW_LINE DEDENT DEDENT for i in range ( K + 1 , N + 1 ) : NEW_LINE INDENT Ans += Mods ( i , N , K ) NEW_LINE DEDENT print ( Ans ) NEW_LINE DEDENT

N , K = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE ans = 0 NEW_LINE for mod in range ( K + 1 , N + 1 ) : NEW_LINE INDENT ans += ( mod - K ) * ( N // mod ) + max ( N % mod - max ( K - 1 , 0 ) , 0 ) NEW_LINE DEDENT print ( ans ) NEW_LINE

n , k = map ( int , input ( ) . split ( ) ) NEW_LINE a = ( n - k ) * ( n - k + 1 ) // 2 NEW_LINE for i in range ( k + 1 , n ) : NEW_LINE INDENT j = n // i * i NEW_LINE a += ( j // i - 1 ) * ( i - k ) + max ( n - j + 1 - max ( k , 1 ) , 0 ) NEW_LINE DEDENT print ( a ) NEW_LINE

N , K = map ( int , input ( ) . split ( ) ) NEW_LINE if K == 0 : print ( N ** 2 ) ; exit ( 0 ) NEW_LINE ans = ( N - K ) * ( N - K + 1 ) // 2 NEW_LINE for b in range ( K + 1 , N ) : NEW_LINE INDENT n = ( N - b + 1 ) // b NEW_LINE ans += ( n ) * ( b - K ) NEW_LINE if n * b + b - 1 != N : NEW_LINE INDENT if N % b >= K : NEW_LINE INDENT ans += N % b - K + 1 NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE


import java . util . Scanner ; import java . util . Arrays ; class Main { static int dp [ ] [ ] [ ] = new int [ 301 ] [ 301 ] [ 301 ] ; public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String S = scan . next ( ) ; int K = scan . nextInt ( ) ; int N = S . length ( ) ; for ( int i = 0 ; i < N ; ++ i ) for ( int k = 0 ; k <= K ; ++ k ) { dp [ i ] [ i + 1 ] [ k ] = 1 ; dp [ i ] [ i ] [ k ] = 0 ; } for ( int k = 0 ; k <= K ; ++ k ) { for ( int L = 2 ; L <= N ; ++ L ) { int i = 0 , j = L ; while ( j <= N ) { if ( k == 0 ) dp [ i ] [ j ] [ k ] = Math . max ( dp [ i + 1 ] [ j ] [ k ] , Math . max ( dp [ i ] [ j - 1 ] [ k ] , ( ( S . charAt ( i ) == S . charAt ( j - 1 ) ? dp [ i + 1 ] [ j - 1 ] [ k ] + 2 : dp [ i + 1 ] [ j - 1 ] [ k ] ) ) ) ) ; else dp [ i ] [ j ] [ k ] = Math . max ( dp [ i + 1 ] [ j ] [ k ] , Math . max ( dp [ i ] [ j - 1 ] [ k ] , Math . max ( dp [ i ] [ j ] [ k - 1 ] , ( ( S . charAt ( i ) == S . charAt ( j - 1 ) ? dp [ i + 1 ] [ j - 1 ] [ k ] + 2 : dp [ i + 1 ] [ j - 1 ] [ k - 1 ] + 2 ) ) ) ) ) ; ++ i ; ++ j ; } } } System . out . println ( dp [ 0 ] [ N ] [ K ] ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ; public class Main { public static void main ( String args [ ] ) throws IOException { Scanner sc = new Scanner ( System . in ) ; char s [ ] = sc . next ( ) . toCharArray ( ) ; int k = sc . nextInt ( ) ; int dp [ ] [ ] [ ] = new int [ s . length ] [ s . length ] [ k + 1 ] ; for ( int i = 0 ; i <= k ; i ++ ) { for ( int r = 0 ; r < s . length ; r ++ ) { for ( int l = r ; l >= 0 ; l -- ) { if ( l == r ) { dp [ l ] [ r ] [ i ] = 1 ; continue ; } if ( r == l + 1 ) { dp [ l ] [ r ] [ i ] = s [ l ] == s [ r ] || i > 0 ? 2 : 1 ; continue ; } if ( s [ l ] == s [ r ] ) { dp [ l ] [ r ] [ i ] = dp [ l + 1 ] [ r - 1 ] [ i ] + 2 ; } else { dp [ l ] [ r ] [ i ] = Math . max ( dp [ l + 1 ] [ r ] [ i ] , dp [ l ] [ r - 1 ] [ i ] ) ; } if ( i > 0 ) { dp [ l ] [ r ] [ i ] = Math . max ( dp [ l ] [ r ] [ i ] , dp [ l + 1 ] [ r - 1 ] [ i - 1 ] + 2 ) ; } } } } System . out . println ( dp [ 0 ] [ s . length - 1 ] [ k ] ) ; } }

public class Main { static int dp [ ] [ ] [ ] ; static String s ; public static int solve ( int i , int j , int k ) { if ( dp [ i ] [ j ] [ k ] >= 0 ) return dp [ i ] [ j ] [ k ] ; else { int ans ; if ( i > j ) ans = 0 ; else if ( i == j ) ans = 1 ; else if ( s . charAt ( i ) == s . charAt ( j ) ) ans = solve ( i + 1 , j - 1 , k ) + 2 ; else { ans = solve ( i + 1 , j , k ) ; ans = Math . max ( ans , solve ( i , j - 1 , k ) ) ; if ( k > 0 ) ans = Math . max ( ans , solve ( i + 1 , j - 1 , k - 1 ) + 2 ) ; } dp [ i ] [ j ] [ k ] = ans ; return ans ; } } public static void main ( String [ ] args ) { java . util . Scanner scan = new java . util . Scanner ( System . in ) ; s = scan . next ( ) ; int t = scan . nextInt ( ) ; dp = new int [ s . length ( ) ] [ s . length ( ) ] [ t + 1 ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { for ( int j = 0 ; j < s . length ( ) ; j ++ ) { for ( int k = 0 ; k <= t ; k ++ ) dp [ i ] [ j ] [ k ] = - 1 ; } } System . out . println ( solve ( 0 , s . length ( ) - 1 , t ) ) ; } }

def solve ( s , k ) : NEW_LINE INDENT n = len ( s ) NEW_LINE if k >= n // 2 : NEW_LINE INDENT return n NEW_LINE DEDENT dpp = [ [ 1 ] * ( k + 1 ) , [ 0 ] * ( k + 1 ) ] NEW_LINE for r in range ( 1 , n ) : NEW_LINE INDENT dpc = [ [ 0 ] * ( k + 1 ) for _ in range ( r + 2 ) ] NEW_LINE dpc [ r ] = [ 1 ] * ( k + 1 ) NEW_LINE for l in range ( r - 1 , - 1 , - 1 ) : NEW_LINE INDENT dpl , dpl1 = dpc [ l ] , dpp [ l + 1 ] NEW_LINE if s [ l ] == s [ r ] : NEW_LINE INDENT dpc [ l ] = [ c + 2 for c in dpl1 ] NEW_LINE DEDENT else : NEW_LINE INDENT dppl , dpcl1 = dpp [ l ] , dpc [ l + 1 ] NEW_LINE dpl [ 0 ] = max ( dppl [ 0 ] , dpcl1 [ 0 ] ) NEW_LINE for p in range ( 1 , k + 1 ) : NEW_LINE INDENT dpl [ p ] = max ( dppl [ p ] , dpcl1 [ p ] , dpl1 [ p - 1 ] + 2 ) NEW_LINE DEDENT DEDENT DEDENT dpp = dpc NEW_LINE DEDENT return dpp [ 0 ] [ k ] NEW_LINE DEDENT print ( solve ( input ( ) , int ( input ( ) ) ) ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] [ ] A = new int [ M ] [ 2 ] ; for ( int i = 0 ; i < M ; i ++ ) { A [ i ] [ 0 ] = sc . nextInt ( ) - 1 ; A [ i ] [ 1 ] = sc . nextInt ( ) - 1 ; } int [ ] [ ] B = new int [ N ] [ 2 ] ; for ( int i = 0 ; i < N ; i ++ ) { B [ i ] [ 0 ] = i ; B [ i ] [ 1 ] = 1 ; } long [ ] inconv = new long [ M + 1 ] ; inconv [ M ] = ( long ) N * ( N - 1 ) / 2 ; for ( int i = M - 1 ; i >= 0 ; i -- ) { int v1 = A [ i ] [ 0 ] ; int v2 = A [ i ] [ 1 ] ; int l1 = findRoot ( B , B [ v1 ] [ 0 ] ) ; int l2 = findRoot ( B , B [ v2 ] [ 0 ] ) ; inconv [ i ] = inconv [ i + 1 ] ; if ( l1 != l2 ) { int s1 = B [ l1 ] [ 1 ] ; int s2 = B [ l2 ] [ 1 ] ; inconv [ i ] -= s1 * s2 ; if ( s1 < s2 ) { int temp = l1 ; l1 = l2 ; l2 = temp ; } B [ l1 ] [ 1 ] += B [ l2 ] [ 1 ] ; B [ l2 ] [ 0 ] = l1 ; B [ l2 ] [ 1 ] = 0 ; } } for ( int i = 1 ; i < M + 1 ; i ++ ) { System . out . println ( inconv [ i ] ) ; } } static private int findRoot ( int [ ] [ ] leaders , int n ) { if ( leaders [ n ] [ 0 ] == n ) return n ; return findRoot ( leaders , leaders [ n ] [ 0 ] ) ; } }

import java . util . * ; import java . util . stream . * ; public class Main { private static Scanner scanner = new Scanner ( System . in ) ; public static void main ( String [ ] $ ) { int n = scanner . nextInt ( ) , m = scanner . nextInt ( ) , a [ ] = new int [ m ] , b [ ] = new int [ m ] , num [ ] = new int [ n + 1 ] ; long [ ] ans = new long [ m ] ; fa = IntStream . rangeClosed ( 0 , n ) . toArray ( ) ; for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; b [ i ] = scanner . nextInt ( ) ; } Arrays . fill ( num , 1 ) ; ans [ m - 1 ] = ( long ) n * ( n - 1 ) / 2 ; for ( int i = m - 1 ; i > 0 ; i -- ) { ans [ i - 1 ] = ans [ i ] ; if ( fd ( a [ i ] ) != fd ( b [ i ] ) ) { ans [ i - 1 ] -= num [ fa [ a [ i ] ] ] * num [ fa [ b [ i ] ] ] ; num [ fa [ b [ i ] ] ] += num [ fa [ a [ i ] ] ] ; fa [ fa [ a [ i ] ] ] = fa [ b [ i ] ] ; } } Arrays . stream ( ans ) . forEach ( System . out :: println ) ; } static int [ ] fa ; static int fd ( int a ) { return fa [ a ] == a ? a : ( fa [ a ] = fd ( fa [ a ] ) ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] a = new int [ m ] ; int [ ] b = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = sc . nextInt ( ) - 1 ; b [ i ] = sc . nextInt ( ) - 1 ; } long [ ] answer = new long [ m ] ; answer [ m - 1 ] = ( long ) n * ( n - 1 ) / 2 ; UnionFind uf = new UnionFind ( n ) ; for ( int i = m - 1 ; i >= 1 ; i -- ) { answer [ i - 1 ] = answer [ i ] ; if ( uf . root ( a [ i ] ) != uf . root ( b [ i ] ) ) { answer [ i - 1 ] -= ( long ) uf . size ( a [ i ] ) * uf . size ( b [ i ] ) ; uf . connect ( a [ i ] , b [ i ] ) ; } } for ( int i = 0 ; i < m ; i ++ ) { System . out . println ( answer [ i ] ) ; } } } class UnionFind { private int [ ] parents ; UnionFind ( int n ) { parents = new int [ n ] ; Arrays . fill ( parents , - 1 ) ; } int size ( int node ) { return - parents [ root ( node ) ] ; } int root ( int node ) { if ( parents [ node ] < 0 ) return node ; else return parents [ node ] = root ( parents [ node ] ) ; } boolean connect ( int node1 , int node2 ) { int root1 = root ( node1 ) ; int root2 = root ( node2 ) ; if ( root1 == root2 ) return false ; else { if ( root1 < root2 ) { int temp = root1 ; root1 = root2 ; root2 = temp ; } parents [ root1 ] += parents [ root2 ] ; parents [ root2 ] = root1 ; return true ; } } }

class uf : NEW_LINE INDENT def __init__ ( self , n ) : NEW_LINE INDENT self . table = [ - 1 ] * ( n + 1 ) NEW_LINE self . size = [ 1 ] * ( n + 1 ) NEW_LINE DEDENT def merge ( self , r1 , r2 ) : NEW_LINE INDENT self . table [ r1 ] = r2 NEW_LINE self . size [ r2 ] += self . size [ r1 ] NEW_LINE self . size [ r1 ] = 0 NEW_LINE DEDENT def find_root ( self , k ) : NEW_LINE INDENT path = [ ] NEW_LINE curr = k NEW_LINE while self . table [ curr ] != - 1 : NEW_LINE INDENT path . append ( curr ) NEW_LINE curr = self . table [ curr ] NEW_LINE DEDENT self . defrag ( curr , path ) NEW_LINE return curr , path NEW_LINE DEDENT def defrag ( self , r , p ) : NEW_LINE INDENT for i in p : NEW_LINE INDENT self . table [ i ] = r NEW_LINE DEDENT DEDENT DEDENT def solve ( string ) : NEW_LINE INDENT n , m , * ab = map ( int , string . split ( ) ) NEW_LINE ab = ab [ : : - 1 ] NEW_LINE ans = [ n * ( n - 1 ) // 2 ] NEW_LINE table = uf ( n ) NEW_LINE for _b , _a in zip ( ab [ : : 2 ] , ab [ 1 : : 2 ] ) : NEW_LINE INDENT r_a , _ = table . find_root ( _a ) NEW_LINE r_b , _ = table . find_root ( _b ) NEW_LINE if r_a == r_b : NEW_LINE INDENT ans . append ( ans [ - 1 ] ) NEW_LINE continue NEW_LINE DEDENT ans . append ( ans [ - 1 ] - table . size [ r_a ] * table . size [ r_b ] ) NEW_LINE table . merge ( r_a , r_b ) NEW_LINE DEDENT return " \n " . join ( [ str ( a ) for a in ans [ : - 1 ] [ : : - 1 ] ] ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n , m = map ( int , input ( ) . split ( ) ) NEW_LINE print ( solve ( ' { } ▁ { } \n ' . format ( n , m ) + ' \n ' . join ( [ input ( ) for _ in range ( m ) ] ) ) ) NEW_LINE DEDENT

N , M = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE bridge = [ ] NEW_LINE for i in range ( M ) : NEW_LINE INDENT bridge . append ( [ int ( i ) - 1 for i in input ( ) . split ( ) ] ) NEW_LINE DEDENT nod = [ [ i , [ i ] ] for i in range ( N ) ] NEW_LINE e = 0 NEW_LINE totale = int ( N * ( N - 1 ) / 2 ) NEW_LINE def joint ( a , b , e ) : NEW_LINE INDENT na = nod [ a ] [ 0 ] NEW_LINE nb = nod [ b ] [ 0 ] NEW_LINE if na == nb : NEW_LINE INDENT return e NEW_LINE DEDENT else : NEW_LINE INDENT e += len ( nod [ na ] [ 1 ] ) * len ( nod [ nb ] [ 1 ] ) NEW_LINE if na < nb : NEW_LINE INDENT nod [ na ] [ 1 ] . extend ( nod [ nb ] [ 1 ] ) NEW_LINE for i in nod [ nb ] [ 1 ] : NEW_LINE INDENT nod [ i ] [ 0 ] = na NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT nod [ nb ] [ 1 ] . extend ( nod [ na ] [ 1 ] ) NEW_LINE for i in nod [ na ] [ 1 ] : NEW_LINE INDENT nod [ i ] [ 0 ] = nb NEW_LINE DEDENT DEDENT return e NEW_LINE DEDENT DEDENT ans = [ ] NEW_LINE for i in range ( M - 1 , - 1 , - 1 ) : NEW_LINE INDENT ans . append ( totale - e ) NEW_LINE e = joint ( bridge [ i ] [ 0 ] , bridge [ i ] [ 1 ] , e ) NEW_LINE DEDENT for i in range ( M - 1 , - 1 , - 1 ) : NEW_LINE INDENT print ( ans [ i ] ) NEW_LINE DEDENT

import numpy as np NEW_LINE def solve ( n , m , a , b ) : NEW_LINE INDENT p = [ - 1 ] * ( n + 1 ) NEW_LINE u = [ 1 ] * ( n + 1 ) NEW_LINE def find ( x ) : NEW_LINE INDENT if p [ x ] == - 1 : NEW_LINE INDENT return x NEW_LINE DEDENT else : NEW_LINE INDENT return find ( p [ x ] ) NEW_LINE DEDENT DEDENT total = n * ( n - 1 ) // 2 NEW_LINE res = [ total ] NEW_LINE for i in range ( m - 1 , 0 , - 1 ) : NEW_LINE INDENT x , y = a [ i ] , b [ i ] NEW_LINE px = find ( x ) NEW_LINE py = find ( y ) NEW_LINE if px > py : NEW_LINE INDENT px , py = py , px NEW_LINE DEDENT if px != py : NEW_LINE INDENT n1 = u [ px ] NEW_LINE n2 = u [ py ] NEW_LINE p [ py ] = px NEW_LINE u [ px ] = n1 + n2 NEW_LINE total -= n1 * n2 NEW_LINE DEDENT res . append ( total ) NEW_LINE DEDENT return res [ : : - 1 ] NEW_LINE DEDENT n , m = map ( int , input ( ) . split ( ) ) NEW_LINE a = np . zeros ( m , dtype = int ) NEW_LINE b = np . zeros ( m , dtype = int ) NEW_LINE for i in range ( m ) : NEW_LINE INDENT a [ i ] , b [ i ] = map ( int , input ( ) . split ( ) ) NEW_LINE DEDENT print ( " \n " . join ( map ( str , solve ( n , m , a , b ) ) ) ) NEW_LINE

N , M = map ( int , input ( ) . split ( ) ) NEW_LINE AB = [ ] NEW_LINE for _ in range ( M ) : NEW_LINE INDENT A_i , B_i = map ( int , input ( ) . split ( ) ) NEW_LINE AB . append ( [ A_i , B_i ] ) NEW_LINE DEDENT class UnionFind ( ) : NEW_LINE INDENT def __init__ ( self , n ) : NEW_LINE INDENT self . parent = [ - 1 for _ in range ( n ) ] NEW_LINE DEDENT def root ( self , x ) : NEW_LINE INDENT if self . parent [ x ] < 0 : NEW_LINE INDENT return x NEW_LINE DEDENT else : NEW_LINE INDENT self . parent [ x ] = self . root ( self . parent [ x ] ) NEW_LINE return self . parent [ x ] NEW_LINE DEDENT DEDENT def size ( self , x ) : NEW_LINE INDENT x = self . root ( x ) NEW_LINE return - 1 * self . parent [ x ] NEW_LINE DEDENT def union ( self , x , y ) : NEW_LINE INDENT x = self . root ( x ) NEW_LINE y = self . root ( y ) NEW_LINE if x == y : NEW_LINE INDENT return False NEW_LINE DEDENT x_size = self . size ( x ) NEW_LINE y_size = self . size ( y ) NEW_LINE if x_size < y_size : NEW_LINE INDENT x , y = y , x NEW_LINE DEDENT self . parent [ x ] += self . parent [ y ] NEW_LINE self . parent [ y ] = x NEW_LINE return True NEW_LINE DEDENT DEDENT max_inconvenience = N * ( N - 1 ) // 2 NEW_LINE ans = [ max_inconvenience ] NEW_LINE uf = UnionFind ( N ) NEW_LINE for bridge in reversed ( AB ) : NEW_LINE INDENT x = uf . root ( bridge [ 0 ] - 1 ) NEW_LINE y = uf . root ( bridge [ 1 ] - 1 ) NEW_LINE if x != y : NEW_LINE INDENT x_size = uf . size ( x ) NEW_LINE y_size = uf . size ( y ) NEW_LINE ans_tmp = max_inconvenience - x_size * y_size NEW_LINE max_inconvenience = ans_tmp NEW_LINE uf . union ( x , y ) NEW_LINE DEDENT else : NEW_LINE INDENT ans_tmp = max_inconvenience NEW_LINE DEDENT ans . append ( ans_tmp ) NEW_LINE DEDENT for a in reversed ( ans [ : - 1 ] ) : NEW_LINE INDENT print ( a ) NEW_LINE DEDENT

N , M = map ( int , input ( ) . split ( ) ) NEW_LINE a_list = [ ] NEW_LINE b_list = [ ] NEW_LINE for i in range ( M ) : NEW_LINE INDENT a , b = map ( int , input ( ) . split ( ) ) NEW_LINE a_list . append ( a ) NEW_LINE b_list . append ( b ) NEW_LINE DEDENT par = [ i for i in range ( N + 1 ) ] NEW_LINE rank = [ 0 ] * ( N + 1 ) NEW_LINE size = [ 1 ] * ( N + 1 ) NEW_LINE def find ( x ) : NEW_LINE INDENT if par [ x ] == x : NEW_LINE INDENT return par [ x ] NEW_LINE DEDENT else : NEW_LINE INDENT par [ x ] = find ( par [ x ] ) NEW_LINE return par [ x ] NEW_LINE DEDENT DEDENT def unite ( x , y ) : NEW_LINE INDENT x_par = find ( x ) NEW_LINE y_par = find ( y ) NEW_LINE if x_par == y_par : NEW_LINE INDENT return NEW_LINE DEDENT if rank [ x_par ] < rank [ y_par ] : NEW_LINE INDENT par [ x_par ] = y_par NEW_LINE size [ y_par ] += size [ x_par ] NEW_LINE DEDENT else : NEW_LINE INDENT par [ y_par ] = x_par NEW_LINE size [ x_par ] += size [ y_par ] NEW_LINE if rank [ x_par ] == rank [ y_par ] : NEW_LINE INDENT rank [ x_par ] += 1 NEW_LINE DEDENT DEDENT DEDENT def bool_func ( x , y ) : NEW_LINE INDENT if find ( x ) == find ( y ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT ans_list = [ ] NEW_LINE ans = int ( N * ( N - 1 ) / 2 ) NEW_LINE for i in range ( M ) : NEW_LINE INDENT ans_list . append ( ans ) NEW_LINE a = a_list [ M - 1 - i ] NEW_LINE b = b_list [ M - 1 - i ] NEW_LINE p = size [ find ( a ) ] NEW_LINE q = size [ find ( b ) ] NEW_LINE if bool_func ( a , b ) : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT ans -= p * q NEW_LINE unite ( a , b ) NEW_LINE DEDENT DEDENT for i in range ( M ) : NEW_LINE INDENT print ( ans_list [ M - 1 - i ] ) NEW_LINE DEDENT


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Amida amida = new Amida ( ) ; amida . startAmida ( ) ; amida . printHitLine ( ) ; } } class Amida { String [ ] [ ] amida ; int currentIndex ; int lineCount ; int rowCount ; public Amida ( ) { Scanner sc = new Scanner ( System . in ) ; this . lineCount = 2 * ( sc . nextInt ( ) ) - 1 ; this . rowCount = sc . nextInt ( ) ; this . amida = new String [ rowCount ] [ lineCount ] ; String [ ] tmpArr = new String [ rowCount + 1 ] ; for ( int i = rowCount ; i >= 0 ; i -- ) { tmpArr [ i ] = sc . nextLine ( ) ; } for ( int i = 0 ; i < rowCount ; i ++ ) { char [ ] charArr = tmpArr [ i ] . toCharArray ( ) ; for ( int j = 0 ; j < lineCount ; j ++ ) { this . amida [ i ] [ j ] = String . valueOf ( charArr [ j ] ) ; } } String currentPoint = sc . nextLine ( ) ; char [ ] currArr = currentPoint . toCharArray ( ) ; for ( int i = 0 ; i < currArr . length ; i ++ ) { if ( currArr [ i ] == " o " . toCharArray ( ) [ 0 ] ) { this . currentIndex = i ; } } } public void startAmida ( ) { for ( int i = 0 ; i < rowCount ; i ++ ) { if ( currentIndex < lineCount - 1 && amida [ i ] [ currentIndex + 1 ] . equalsIgnoreCase ( " - " ) ) { currentIndex += 2 ; } else if ( currentIndex > 0 && amida [ i ] [ currentIndex - 1 ] . equalsIgnoreCase ( " - " ) ) { currentIndex -= 2 ; } } } public void printHitLine ( ) { int ans = currentIndex / 2 + 1 ; System . out . println ( ans ) ; } }

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskB solver = new TaskB ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskB { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) ; int l = in . nextInt ( ) ; in . nextLine ( ) ; String [ ] amida = new String [ l + 1 ] ; for ( int i = 0 ; i < l + 1 ; i ++ ) { amida [ i ] = in . nextLine ( ) ; } int pos = amida [ l ] . indexOf ( ' o ' ) ; for ( int i = l - 1 ; i >= 0 ; i -- ) { String s = amida [ i ] ; if ( pos > 0 && s . charAt ( pos - 1 ) == ' - ' ) pos -= 2 ; else if ( pos < s . length ( ) - 1 && s . charAt ( pos + 1 ) == ' - ' ) pos += 2 ; } out . println ( pos / 2 + 1 ) ; } } }

import java . util . Collections ; import java . util . List ; import java . util . Scanner ; import java . util . stream . Collectors ; import java . util . stream . IntStream ; public class Main { static Scanner s = new Scanner ( System . in ) ; static int getInt ( ) { return Integer . parseInt ( s . next ( ) ) ; } static IntStream REPS ( int v ) { return IntStream . range ( 0 , v ) ; } static IntStream REPS ( int l , int r ) { return IntStream . rangeClosed ( l , r ) ; } static IntStream INS ( int n ) { return REPS ( n ) . map ( i -> getInt ( ) ) ; } static class Pair < T , U > { T l ; U r ; Pair ( T L , U R ) { l = L ; r = R ; } T getL ( ) { return l ; } U getR ( ) { return r ; } } public static void main ( String [ ] $ ) { int n = getInt ( ) , h = getInt ( ) ; s . nextLine ( ) ; List < Integer > l = REPS ( 1 , n ) . boxed ( ) . collect ( Collectors . toList ( ) ) ; for ( int i = 0 ; i < h ; ++ i ) { String in = s . nextLine ( ) . replaceAll ( " [ | ] " , " " ) ; for ( int j = 0 ; j < in . length ( ) ; ++ j ) { if ( in . charAt ( j ) == ' - ' ) Collections . swap ( l , j , j + 1 ) ; } } String e = s . nextLine ( ) ; for ( int i = 0 ; i < n ; ++ i ) if ( e . charAt ( i * 2 ) == ' o ' ) System . out . println ( l . get ( i ) ) ; } }

import java . io . * ; import java . util . * ; import java . math . * ; public class Main { static boolean debug = false ; static boolean debug2 = false ; public static void main ( String [ ] args ) throws java . io . IOException { debug = 1 <= args . length ; debug2 = 2 <= args . length ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] ia = in . readLine ( ) . split ( " ▁ " ) ; final int N = Integer . parseInt ( ia [ 0 ] ) ; final int L = Integer . parseInt ( ia [ 1 ] ) ; String [ ] lines = new String [ L ] ; for ( int i = 0 ; i < lines . length ; ++ i ) { lines [ i ] = in . readLine ( ) ; } int i = in . readLine ( ) . indexOf ( ' o ' ) ; for ( int n = L - 1 ; 0 <= n ; -- n ) { final int l = i - 1 ; final int r = i + 1 ; if ( 0 <= l && l < lines [ n ] . length ( ) && lines [ n ] . charAt ( l ) == ' - ' ) { i -= 2 ; } else if ( 0 <= r && r < lines [ n ] . length ( ) && lines [ n ] . charAt ( r ) == ' - ' ) { i += 2 ; } } System . out . println ( ( i + 2 ) / 2 ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { static int [ ] amida ; public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String a = br . readLine ( ) ; String [ ] b = a . split ( " ▁ " ) ; int N = Integer . parseInt ( b [ 0 ] ) ; int L = Integer . parseInt ( b [ 1 ] ) ; amida = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { amida [ i ] = i + 1 ; } for ( int i = 0 ; i < L ; i ++ ) { String s = br . readLine ( ) ; for ( int j = 0 ; j < N - 1 ; j ++ ) { if ( s . charAt ( 2 * j + 1 ) == ' - ' ) { swap ( j ) ; } } } String s = br . readLine ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( s . charAt ( 2 * i ) == ' o ' ) { pl ( amida [ i ] ) ; break ; } } } static void swap ( int p ) { int a = amida [ p ] ; amida [ p ] = amida [ p + 1 ] ; amida [ p + 1 ] = a ; } public static void pl ( Object o ) { System . out . println ( o ) ; } public static void pl ( ) { System . out . println ( ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } }

n , l = map ( int , input ( ) . split ( ) ) NEW_LINE s = [ input ( ) for _ in range ( l ) ] NEW_LINE y = input ( ) NEW_LINE goal = 0 NEW_LINE while y [ goal ] != ' o ' : NEW_LINE INDENT goal += 2 NEW_LINE DEDENT goal //= 2 NEW_LINE for i in range ( n ) : NEW_LINE INDENT now = i NEW_LINE for ss in s : NEW_LINE INDENT if now != 0 and ss [ 2 * now - 1 ] == ' - ' : NEW_LINE INDENT now -= 1 NEW_LINE DEDENT elif now != n - 1 and ss [ 2 * now + 1 ] == ' - ' : NEW_LINE INDENT now += 1 NEW_LINE DEDENT DEDENT if now == goal : NEW_LINE INDENT print ( i + 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT

from sys import stdin NEW_LINE input = stdin . readline NEW_LINE n , l = map ( int , input ( ) . split ( ) ) NEW_LINE L = [ ] NEW_LINE for _ in range ( l + 1 ) : NEW_LINE INDENT L_ = list ( input ( ) ) NEW_LINE L . append ( L_ ) NEW_LINE DEDENT now = L [ l ] . index ( " o " ) NEW_LINE for i in range ( l - 1 , - 1 , - 1 ) : NEW_LINE INDENT if L [ i ] [ now - 1 ] == " - " : NEW_LINE INDENT now -= 2 NEW_LINE DEDENT elif L [ i ] [ now + 1 ] == " - " : NEW_LINE INDENT now += 2 NEW_LINE DEDENT DEDENT print ( now // 2 + 1 ) NEW_LINE

n , l = map ( int , input ( ) . split ( ) ) NEW_LINE line = [ ] NEW_LINE line . append ( " ▁ " ) NEW_LINE for i in range ( l + 1 ) : NEW_LINE INDENT line . append ( list ( input ( ) ) ) NEW_LINE DEDENT pos_ld = line [ l + 1 ] . index ( " o " ) NEW_LINE def route_amida ( line , length , width , n ) : NEW_LINE INDENT if width == 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT if length == 1 : NEW_LINE INDENT return int ( ( n + 2 ) / 2 ) NEW_LINE DEDENT else : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT if line [ length - 1 ] [ 1 ] == ' - ' : NEW_LINE INDENT n += 2 NEW_LINE DEDENT DEDENT elif n == 2 * width - 2 : NEW_LINE INDENT if line [ length - 1 ] [ 2 * width - 3 ] == ' - ' : NEW_LINE INDENT n -= 2 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if line [ length - 1 ] [ n + 1 ] == ' - ' : NEW_LINE INDENT n += 2 NEW_LINE DEDENT elif line [ length - 1 ] [ n - 1 ] == ' - ' : NEW_LINE INDENT n -= 2 NEW_LINE DEDENT DEDENT return route_amida ( line [ : length - 1 ] , ( length - 1 ) , width , n ) NEW_LINE DEDENT DEDENT DEDENT print ( route_amida ( line [ : l + 1 ] , l + 1 , n , pos_ld ) ) NEW_LINE

N , L = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE b = [ input ( ) . split ( " | " ) for i in range ( L ) ] NEW_LINE x = input ( ) . find ( " o " ) // 2 + 1 NEW_LINE for y in range ( L - 1 , - 1 , - 1 ) : NEW_LINE INDENT if b [ y ] [ x - 1 ] == " - " : NEW_LINE INDENT x -= 1 NEW_LINE DEDENT elif b [ y ] [ x ] == " - " : NEW_LINE INDENT x += 1 NEW_LINE DEDENT DEDENT print ( x ) NEW_LINE

N , L = map ( int , input ( ) . split ( ) ) NEW_LINE kuji = [ ] NEW_LINE for _ in range ( L ) : NEW_LINE INDENT kuji . append ( input ( ) ) NEW_LINE DEDENT atari = input ( ) NEW_LINE a_idx = atari . index ( ' o ' ) NEW_LINE kuji = kuji [ : : - 1 ] NEW_LINE for line in kuji : NEW_LINE INDENT try : NEW_LINE INDENT if line [ a_idx - 1 ] == ' - ' : NEW_LINE INDENT a_idx -= 2 NEW_LINE DEDENT elif line [ a_idx + 1 ] == ' - ' : NEW_LINE INDENT a_idx += 2 NEW_LINE DEDENT DEDENT except IndexError : NEW_LINE INDENT continue NEW_LINE DEDENT DEDENT if a_idx == 0 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT elif a_idx == 2 : NEW_LINE INDENT print ( 2 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( a_idx // 2 + 1 ) NEW_LINE DEDENT


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; double ans = ( double ) ( 9 * n ) / ( double ) 5 + 32 ; System . out . println ( ans ) ; } }

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { out . println ( 32.0 + 9.0 / 5.0 * in . nextDouble ( ) ) ; } } static class FastScanner { private InputStream in ; private byte [ ] buffer = new byte [ 1024 ] ; private int bufPointer ; private int bufLength ; public FastScanner ( InputStream in ) { this . in = in ; this . bufPointer = 0 ; this . bufLength = 0 ; } private int readByte ( ) { if ( bufPointer >= bufLength ) { if ( bufLength == - 1 ) throw new InputMismatchException ( ) ; bufPointer = 0 ; try { bufLength = in . read ( buffer ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } if ( bufLength <= 0 ) return - 1 ; } return buffer [ bufPointer ++ ] ; } private static boolean isPrintableChar ( int c ) { return c >= 33 && c <= 126 ; } public String next ( ) { StringBuilder sb = new StringBuilder ( ) ; int b = readByte ( ) ; while ( ! isPrintableChar ( b ) ) b = readByte ( ) ; while ( isPrintableChar ( b ) ) { sb . appendCodePoint ( b ) ; b = readByte ( ) ; } return sb . toString ( ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }

import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; System . out . println ( ( 9.0 / 5 * n ) + 32 ) ; } private static boolean isDebug = System . getProperty ( " sun . desktop " ) != null ; private static void debug ( Object ... o ) { if ( isDebug ) { System . err . println ( Arrays . deepToString ( o ) ) ; } } }

import java . io . * ; import java . math . * ; import java . text . * ; import java . util . * ; import java . util . regex . * ; public class Main { private static final Scanner scan = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int cel = scan . nextInt ( ) ; float mul = 9f / 5f ; System . out . println ( mul * cel + 32 ) ; } }

import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; double n = scanner . nextDouble ( ) ; double ans = 9 * n / 5 + 32 ; System . out . println ( ans ) ; } }

print ( 9 / 5 * ( int ( input ( ) ) ) + 32.0 ) NEW_LINE

def ans ( ) : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE x = 9 / 5 * N + 32 NEW_LINE if ( x == int ( x ) ) : NEW_LINE INDENT print ( int ( x ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( x ) NEW_LINE DEDENT DEDENT ans ( ) NEW_LINE

import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE n = int ( input ( ) ) NEW_LINE print ( 9 / 5 * n + 32 ) NEW_LINE

def main ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE print ( 9 * n / 5 + 32 ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

print ( int ( input ( ) ) * 1.8 + 32 ) NEW_LINE


import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; int N = Integer . parseInt ( str ) ; long mod = 1_000_000_007 ; long [ ] [ ] [ ] [ ] dp = new long [ N + 1 ] [ 4 ] [ 4 ] [ 4 ] ; dp [ 0 ] [ 3 ] [ 3 ] [ 3 ] = 1 ; for ( int len = 0 ; len < N ; len ++ ) { for ( int c1 = 0 ; c1 < 4 ; c1 ++ ) { for ( int c2 = 0 ; c2 < 4 ; c2 ++ ) { for ( int c3 = 0 ; c3 < 4 ; c3 ++ ) { if ( dp [ len ] [ c1 ] [ c2 ] [ c3 ] == 0 ) { continue ; } for ( int a = 0 ; a < 4 ; a ++ ) { if ( a == 2 && c1 == 1 && c2 == 0 ) { continue ; } else if ( a == 2 && c1 == 0 && c2 == 1 ) { continue ; } else if ( a == 1 && c1 == 2 && c2 == 0 ) { continue ; } else if ( a == 2 && c1 == 1 && c3 == 0 ) { continue ; } else if ( a == 2 && c2 == 1 && c3 == 0 ) { continue ; } dp [ len + 1 ] [ a ] [ c1 ] [ c2 ] += dp [ len ] [ c1 ] [ c2 ] [ c3 ] ; dp [ len + 1 ] [ a ] [ c1 ] [ c2 ] %= mod ; } } } } } long ans = 0 ; for ( int c1 = 0 ; c1 < 4 ; c1 ++ ) { for ( int c2 = 0 ; c2 < 4 ; c2 ++ ) { for ( int c3 = 0 ; c3 < 4 ; c3 ++ ) { ans += dp [ N ] [ c1 ] [ c2 ] [ c3 ] ; } } } System . out . println ( ans %= mod ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long answer = 0 ; long [ ] [ ] dp = new long [ n + 1 ] [ 4 ] ; dp [ 1 ] = new long [ ] { 1 , 1 , 1 , 1 } ; dp [ 2 ] = new long [ ] { 4 , 4 , 4 , 4 } ; dp [ 3 ] = new long [ ] { 16 , 14 , 15 , 16 } ; if ( n >= 4 ) { for ( int i = 4 ; i <= n ; i ++ ) { long sum = 0 ; for ( int j = 0 ; j < 4 ; j ++ ) { sum += dp [ i - 1 ] [ j ] ; } sum %= 1000000007 ; dp [ i ] [ 0 ] = sum ; dp [ i ] [ 3 ] = sum ; dp [ i ] [ 1 ] = sum - dp [ i - 2 ] [ 0 ] - dp [ i - 2 ] [ 2 ] - dp [ i - 3 ] [ 0 ] * 3 ; dp [ i ] [ 2 ] = sum - dp [ i - 2 ] [ 0 ] + dp [ i - 3 ] [ 2 ] ; sum = 0 ; } } for ( int j = 0 ; j < 4 ; j ++ ) { answer += dp [ n ] [ j ] ; } answer %= 1000000007 ; System . out . println ( answer ) ; } }

import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws IOException { final int A = 0 , C = 1 , G = 2 , T = 3 , mod = 1000000007 ; PrintWriter out = new PrintWriter ( System . out ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int [ ] [ ] [ ] [ ] dp = new int [ 111 ] [ 4 ] [ 4 ] [ 4 ] ; int ans = 0 ; dp [ 0 ] [ 0 ] [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 0 ; j < 4 ; j ++ ) { for ( int k = 0 ; k < 4 ; k ++ ) { for ( int l = 0 ; l < 4 ; l ++ ) { for ( int m = 0 ; m < 4 ; m ++ ) { if ( i > 2 ) { if ( k == A && l == G && m == C ) continue ; if ( k == A && l == C && m == G ) continue ; if ( k == G && l == A && m == C ) continue ; } if ( i > 3 ) { if ( j == A && l == G && m == C ) continue ; if ( j == A && k == G && m == C ) continue ; } dp [ i ] [ k ] [ l ] [ m ] += dp [ i - 1 ] [ j ] [ k ] [ l ] ; dp [ i ] [ k ] [ l ] [ m ] %= mod ; } } } } } for ( int i = 0 ; i < 4 ; i ++ ) { for ( int j = 0 ; j < 4 ; j ++ ) { for ( int k = 0 ; k < 4 ; k ++ ) { ans += dp [ n ] [ i ] [ j ] [ k ] ; ans %= mod ; } } } out . println ( ans ) ; out . flush ( ) ; } }

import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Scanner ; public class Main { private static int N = 0 ; private static long MOD = 1000000007L ; private static List < Map < String , Long > > memo = new ArrayList < Map < String , Long > > ( ) ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; for ( int i = 0 ; i <= N ; i ++ ) { memo . add ( new HashMap < String , Long > ( ) ) ; } System . out . println ( dfs ( 0 , " TTT " ) ) ; } private static boolean ok ( String last4 ) { for ( int i = 0 ; i < 4 ; i ++ ) { char [ ] t = last4 . toCharArray ( ) ; if ( i >= 1 ) { char buf = t [ i - 1 ] ; t [ i - 1 ] = t [ i ] ; t [ i ] = buf ; } if ( String . valueOf ( t ) . indexOf ( " AGC " ) >= 0 ) { return false ; } } return true ; } private static long dfs ( int cur , String last3 ) { if ( memo . get ( cur ) . containsKey ( last3 ) ) { return memo . get ( cur ) . get ( last3 ) ; } if ( cur == N ) { return 1 ; } long ret = 0 ; char [ ] cList = { ' A ' , ' C ' , ' G ' , ' T ' } ; for ( char c : cList ) { if ( ok ( last3 + c ) ) { ret = ( ret + dfs ( cur + 1 , last3 . substring ( 1 ) + c ) ) % MOD ; } } memo . get ( cur ) . put ( last3 , ret ) ; return ret ; } }

MOD = 10 ** 9 + 7 NEW_LINE N = int ( input ( ) ) NEW_LINE countA = 4 NEW_LINE countG = 4 NEW_LINE countAG = 1 NEW_LINE countGA = 1 NEW_LINE countAC = 1 NEW_LINE countAGX = 0 NEW_LINE countAXG = 0 NEW_LINE countAT = 1 NEW_LINE ans = 16 NEW_LINE nextnums = [ 0 for _ in range ( 7 ) ] NEW_LINE for i in range ( N - 2 ) : NEW_LINE INDENT nextans = ans * 4 - countAG - countGA - countAC - countAXG - countAGX NEW_LINE nextA = ans NEW_LINE nextG = ans - countAC NEW_LINE nextAG = countA NEW_LINE nextGA = countG NEW_LINE nextAC = countA - countGA NEW_LINE nextAGX = 2 * countAG NEW_LINE nextAXG = countAT NEW_LINE nextAT = countA NEW_LINE ans = nextans % MOD NEW_LINE countA = nextA % MOD NEW_LINE countAC = nextAC % MOD NEW_LINE countAG = nextAG % MOD NEW_LINE countAGX = nextAGX % MOD NEW_LINE countAT = nextAT % MOD NEW_LINE countAXG = nextAXG % MOD NEW_LINE countG = nextG % MOD NEW_LINE countGA = nextGA % MOD NEW_LINE DEDENT print ( ans ) NEW_LINE

import itertools NEW_LINE N = int ( input ( ) ) NEW_LINE AGCs = [ ' AGC ' , ' GAC ' , ' ACG ' , ' AGAC ' , ' AGGC ' , ' AGTC ' , ' ACGC ' , ' ATGC ' , ] NEW_LINE seq = [ " A " , " G " , " C " , " T " ] NEW_LINE from collections import Counter NEW_LINE memo = Counter ( ) NEW_LINE count = 0 NEW_LINE new_S = [ ] NEW_LINE def memo_saiki ( n , start_memo ) : NEW_LINE INDENT if n == 1 : NEW_LINE INDENT print ( 4 ) NEW_LINE exit ( ) NEW_LINE DEDENT if n == 2 : NEW_LINE INDENT print ( 16 ) NEW_LINE exit ( ) NEW_LINE DEDENT memo = start_memo NEW_LINE new_memo = Counter ( ) NEW_LINE for _ in range ( n - 3 ) : NEW_LINE INDENT for k , v in memo . items ( ) : NEW_LINE INDENT for char in ' AGCT ' : NEW_LINE INDENT target = k + char NEW_LINE if any ( [ agc in target for agc in AGCs ] ) : NEW_LINE INDENT continue NEW_LINE DEDENT new_memo . update ( { target [ - 3 : ] : v } ) NEW_LINE DEDENT DEDENT memo = new_memo NEW_LINE new_memo = Counter ( ) NEW_LINE DEDENT print ( sum ( [ v for v in memo . values ( ) ] ) % ( 10 ** 9 + 7 ) ) NEW_LINE DEDENT def saiki ( n = 6 ) : NEW_LINE INDENT S = [ ' ' ] NEW_LINE new_S = [ ] NEW_LINE memo = { } NEW_LINE for _ in range ( n ) : NEW_LINE INDENT for i , s in enumerate ( S ) : NEW_LINE INDENT for c in ' AGCT ' : NEW_LINE INDENT memo [ s [ - 3 : ] ] = 1 NEW_LINE hoge = s [ - 3 : ] + c NEW_LINE if any ( [ agc in hoge for agc in AGCs ] ) : NEW_LINE INDENT continue NEW_LINE DEDENT new_S . append ( hoge ) NEW_LINE DEDENT DEDENT S = new_S NEW_LINE new_S = [ ] NEW_LINE DEDENT return S NEW_LINE DEDENT memo_saiki ( n = N , start_memo = Counter ( saiki ( 3 ) ) ) NEW_LINE

N = int ( input ( ) ) NEW_LINE MOD = int ( 1e9 + 7 ) NEW_LINE tokens = [ ' A ' , ' C ' , ' G ' , ' T ' ] NEW_LINE suffixes = [ ] NEW_LINE for suffix_1 in tokens : NEW_LINE INDENT for suffix_2 in tokens : NEW_LINE INDENT for suffix_3 in tokens : NEW_LINE INDENT suffixes . append ( suffix_1 + suffix_2 + suffix_3 ) NEW_LINE DEDENT DEDENT DEDENT dp = [ [ 0 for _ in suffixes ] for _ in range ( N + 1 ) ] NEW_LINE reverse_index = { } NEW_LINE for i , s in enumerate ( suffixes ) : NEW_LINE INDENT reverse_index [ s ] = i NEW_LINE DEDENT def pprint ( dp ) : NEW_LINE INDENT N = len ( dp ) NEW_LINE M = len ( dp [ 0 ] ) NEW_LINE for i in dp : NEW_LINE INDENT st = " " NEW_LINE for j in i : NEW_LINE INDENT st += str ( j ) NEW_LINE st += " ▁ " NEW_LINE DEDENT print ( st ) NEW_LINE DEDENT DEDENT for i , s in enumerate ( suffixes ) : NEW_LINE INDENT if not s in [ ' AGC ' , ' ACG ' , ' GAC ' ] : NEW_LINE INDENT dp [ 3 ] [ i ] = 1 NEW_LINE DEDENT DEDENT valid_str_4 = set ( ) NEW_LINE def swap ( s , i , j ) : NEW_LINE INDENT s_new = list ( s ) NEW_LINE s_new [ i ] , s_new [ j ] = s [ j ] , s [ i ] NEW_LINE return ' ' . join ( s_new ) NEW_LINE DEDENT def valid ( str4 ) : NEW_LINE INDENT if ' AGC ' in str4 : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 3 ) : NEW_LINE INDENT s_new = swap ( str4 , i , i + 1 ) NEW_LINE if ' AGC ' in s_new : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT for s in suffixes : NEW_LINE INDENT for c in tokens : NEW_LINE INDENT ss = s + c NEW_LINE if valid ( ss ) : NEW_LINE INDENT valid_str_4 . add ( ss ) NEW_LINE DEDENT DEDENT DEDENT for n in range ( 4 , N + 1 ) : NEW_LINE INDENT for s in suffixes : NEW_LINE INDENT for c in tokens : NEW_LINE INDENT ss = s + c NEW_LINE if ss in valid_str_4 : NEW_LINE INDENT dp [ n ] [ reverse_index [ ss [ 1 : ] ] ] += dp [ n - 1 ] [ reverse_index [ s ] ] NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( sum ( dp [ N ] ) % MOD ) NEW_LINE

import sys NEW_LINE import numpy as np NEW_LINE readInt = lambda : int ( sys . stdin . readline ( ) ) NEW_LINE readIntN = lambda : [ int ( v ) for v in sys . stdin . readline ( ) . split ( " ▁ " ) ] NEW_LINE n = readInt ( ) NEW_LINE M = 10 ** 9 + 7 NEW_LINE dp = np . zeros ( ( n + 1 , 256 ) , dtype = np . uint32 ) NEW_LINE dp [ 0 , 255 ] = 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j4 in [ 0 , 64 , 128 , 192 ] : NEW_LINE INDENT for j3 in [ 0 , 16 , 32 , 48 ] : NEW_LINE INDENT j43 = j4 + j3 NEW_LINE for j2 in [ 0 , 4 , 8 , 12 ] : NEW_LINE INDENT j432 = j43 + j2 NEW_LINE for j1 in range ( 4 ) : NEW_LINE INDENT j = j432 + j1 NEW_LINE l321 = 4 * ( j3 + j2 + j1 ) NEW_LINE for l0 in range ( 4 ) : NEW_LINE INDENT if ( 6 == ( j3 + 4 * j1 + l0 ) ) or ( 6 == ( j3 + j2 + l0 ) ) or ( 6 == ( 4 * j2 + 4 * j1 + l0 ) ) or ( 6 == ( 16 * j1 + j2 + l0 ) ) or ( 6 == ( 4 * j2 + 4 * l0 + j1 ) ) : NEW_LINE INDENT continue NEW_LINE DEDENT l = l321 + l0 NEW_LINE dp [ i + 1 , l ] = ( dp [ i + 1 , l ] + dp [ i , j ] ) % M NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT DEDENT ret = 0 NEW_LINE for v in dp [ - 1 ] : NEW_LINE INDENT ret = ( ret + v ) % M NEW_LINE DEDENT print ( ret ) NEW_LINE

N = int ( input ( ) ) NEW_LINE mod = 1000000007 NEW_LINE data = dict ( [ ( i + j + k , 1 ) for i in ' ACGT ' for j in ' AGCT ' for k in ' ACGT ' ] ) NEW_LINE data [ ' AGC ' ] = 0 NEW_LINE data [ ' ACG ' ] = 0 NEW_LINE data [ ' GAC ' ] = 0 NEW_LINE def check ( text ) : NEW_LINE INDENT if ' AGC ' in text : NEW_LINE INDENT return False NEW_LINE DEDENT if ' AGC ' in text [ 1 ] + text [ 0 ] + text [ 2 ] + text [ 3 ] : NEW_LINE INDENT return False NEW_LINE DEDENT if ' AGC ' in text [ 0 ] + text [ 2 ] + text [ 1 ] + text [ 3 ] : NEW_LINE INDENT return False NEW_LINE DEDENT if ' AGC ' in text [ 0 ] + text [ 1 ] + text [ 3 ] + text [ 2 ] : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT for x in range ( 0 , N - 3 ) : NEW_LINE INDENT new_data = dict ( [ ( i + j + k , 0 ) for i in ' ACGT ' for j in ' AGCT ' for k in ' ACGT ' ] ) NEW_LINE for y in data . keys ( ) : NEW_LINE INDENT for z in ' ACGT ' : NEW_LINE INDENT if check ( y + z ) : NEW_LINE INDENT new_data [ y [ 1 : ] + z ] += data [ y ] % mod NEW_LINE DEDENT DEDENT DEDENT data = new_data . copy ( ) NEW_LINE DEDENT print ( sum ( data . values ( ) ) % mod ) NEW_LINE


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String c1 = sc . next ( ) ; String c2 = sc . next ( ) ; if ( c1 . charAt ( 0 ) == c2 . charAt ( 2 ) && c1 . charAt ( 1 ) == c2 . charAt ( 1 ) && c1 . charAt ( 2 ) == c2 . charAt ( 0 ) ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } }

import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String word1 = input . readLine ( ) ; String word2 = input . readLine ( ) ; boolean state = true ; for ( int i = 0 , j = word2 . length ( ) - 1 ; i < word1 . length ( ) ; i ++ , j -- ) { if ( word1 . charAt ( i ) != word2 . charAt ( j ) ) { state = false ; break ; } } if ( state ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; char [ ] a = scn . nextLine ( ) . toCharArray ( ) ; char [ ] b = scn . nextLine ( ) . toCharArray ( ) ; boolean ans = true ; for ( int i = 0 ; i < 3 ; i ++ ) { ans &= a [ i ] == b [ 2 - i ] ; } System . out . println ( ans ? " YES " : " NO " ) ; } }

import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . nextLine ( ) ; String b = sc . nextLine ( ) ; String c11 = a . substring ( 0 , 1 ) ; String c12 = a . substring ( 1 , 2 ) ; String c13 = a . substring ( 2 , 3 ) ; String c21 = b . substring ( 0 , 1 ) ; String c22 = b . substring ( 1 , 2 ) ; String c23 = b . substring ( 2 , 3 ) ; if ( c11 . equals ( c23 ) && c12 . equals ( c22 ) && c13 . equals ( c21 ) ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; char [ ] c1 = sc . next ( ) . toCharArray ( ) ; char [ ] c2 = sc . next ( ) . toCharArray ( ) ; sc . close ( ) ; boolean ans = false ; if ( c1 [ 0 ] == c2 [ 2 ] && c1 [ 1 ] == c2 [ 1 ] && c1 [ 2 ] == c2 [ 0 ] ) ans = true ; System . out . println ( ans ? " YES " : " NO " ) ; } }

C1 = input ( ) NEW_LINE C2 = input ( ) NEW_LINE C1a = C1 [ 2 ] + C1 [ 1 ] + C1 [ 0 ] NEW_LINE C2a = C2 [ 2 ] + C2 [ 1 ] + C2 [ 0 ] NEW_LINE if C1 == C2a and C2 == C1a : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT

import numpy as np NEW_LINE C = np . array ( [ list ( input ( ) ) for i in range ( 2 ) ] ) NEW_LINE C_r = np . array ( [ [ '0' ] * 3 for i in range ( 2 ) ] ) NEW_LINE for i in range ( 2 ) : NEW_LINE INDENT for j in range ( 3 ) : NEW_LINE INDENT C_r [ 1 - i , 2 - j ] = C [ i , j ] NEW_LINE DEDENT DEDENT if np . all ( C == C_r ) : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT

print ( [ " YES " , " NO " ] [ not ( " " . join ( reversed ( input ( ) ) ) == input ( ) ) ] ) NEW_LINE

c1 = input ( ) NEW_LINE c2 = input ( ) NEW_LINE print ( ' YES ' if c1 == c2 [ : : - 1 ] else ' NO ' ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int L = sc . nextInt ( ) ; int [ ] a = new int [ L ] ; int [ ] b = new int [ L ] ; for ( int i = 0 ; i < L ; i ++ ) { b [ i ] = sc . nextInt ( ) ; } int xor = b [ 0 ] ^ b [ 1 ] ; for ( int i = 2 ; i < L - 1 ; i ++ ) { xor = xor ^ b [ i ] ; } if ( L == 2 && b [ 0 ] != b [ 1 ] ) { System . out . println ( - 1 ) ; } else if ( L != 2 && b [ L - 1 ] != xor ) { System . out . println ( - 1 ) ; } else { a [ 0 ] = 0 ; System . out . println ( a [ 0 ] ) ; for ( int i = 1 ; i < L ; i ++ ) { a [ i ] = a [ i - 1 ] ^ b [ i - 1 ] ; System . out . println ( a [ i ] ) ; } } } }

import java . util . * ; public class Main { private static int L ; private static int b [ ] ; private static int a [ ] ; public static void input ( ) { Scanner scan = new Scanner ( System . in ) ; L = scan . nextInt ( ) ; b = new int [ L ] ; a = new int [ L ] ; for ( int i = 0 ; i < L ; i ++ ) { b [ i ] = scan . nextInt ( ) ; } } public static void main ( String args [ ] ) { input ( ) ; boolean flag = true ; int xor = b [ 0 ] ^ b [ 1 ] ; for ( int i = 2 ; i < L - 1 ; i ++ ) { xor = xor ^ b [ i ] ; } if ( L == 2 && b [ 0 ] != b [ 1 ] ) { System . out . println ( - 1 ) ; flag = false ; } if ( L != 2 && b [ L - 1 ] != xor ) { System . out . println ( - 1 ) ; flag = false ; } if ( flag ) { a [ 0 ] = 0 ; System . out . println ( a [ 0 ] ) ; for ( int i = 1 ; i < L ; i ++ ) { a [ i ] = a [ i - 1 ] ^ b [ i - 1 ] ; System . out . println ( a [ i ] ) ; } } } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int L = sc . nextInt ( ) ; int [ ] B = new int [ L + 2 ] ; int check = 0 ; for ( int i = 0 ; i < L ; i ++ ) { B [ i ] = sc . nextInt ( ) ; if ( i != L - 1 ) check = check ^ B [ i ] ; } if ( check != B [ L - 1 ] ) { System . out . println ( - 1 ) ; return ; } int A [ ] = new int [ L + 2 ] ; A [ 0 ] = 0 ; for ( int i = 1 ; i < L - 1 ; i ++ ) { A [ i ] = A [ i - 1 ] ^ B [ i - 1 ] ; } A [ L - 1 ] = A [ 0 ] ^ B [ L - 1 ] ; for ( int i = 0 ; i < L ; i ++ ) { System . out . println ( A [ i ] ) ; } } }

n = int ( input ( ) ) NEW_LINE b = [ int ( input ( ) ) for _ in range ( n ) ] NEW_LINE l = [ 0 ] * ( n + 1 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT l [ i + 1 ] = l [ i ] ^ b [ i ] NEW_LINE DEDENT if l [ - 1 ] != 0 : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT l . pop ( ) NEW_LINE for i in l : NEW_LINE INDENT print ( i ) NEW_LINE DEDENT DEDENT

def b_xored ( L , B ) : NEW_LINE INDENT a = [ 0 ] * L NEW_LINE for k in range ( L - 1 ) : NEW_LINE INDENT a [ k + 1 ] = B [ k ] ^ a [ k ] NEW_LINE DEDENT ans = ' \n ' . join ( map ( str , a ) ) if B [ L - 1 ] ^ a [ L - 1 ] == a [ 0 ] else ' - 1' NEW_LINE return ans NEW_LINE DEDENT L = int ( input ( ) ) NEW_LINE B = [ int ( input ( ) ) for _ in [ 0 ] * L ] NEW_LINE print ( b_xored ( L , B ) ) NEW_LINE

L , * B = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE s = 0 NEW_LINE for b in B : NEW_LINE INDENT s ^= b NEW_LINE DEDENT if s != 0 : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( 0 ) NEW_LINE DEDENT e = 0 NEW_LINE ans = [ 0 ] NEW_LINE for i in range ( L - 1 ) : NEW_LINE INDENT e ^= B [ i ] NEW_LINE ans . append ( e ) NEW_LINE DEDENT print ( * ans , sep = ' \n ' ) NEW_LINE

def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE L = int ( input ( ) ) NEW_LINE B = [ int ( input ( ) ) for _ in range ( L ) ] NEW_LINE A = [ 0 ] * L NEW_LINE for i in range ( 1 , L ) : NEW_LINE INDENT A [ i ] = A [ i - 1 ] ^ B [ i - 1 ] NEW_LINE DEDENT if A [ - 1 ] ^ B [ - 1 ] == A [ 0 ] : NEW_LINE INDENT print ( * A , sep = " \n " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT

L = int ( input ( ) ) NEW_LINE B = [ int ( input ( ) ) for _ in range ( L ) ] NEW_LINE z = B [ 0 ] NEW_LINE for y in B [ 1 : ] : NEW_LINE INDENT z = z ^ y NEW_LINE DEDENT if z == 0 : NEW_LINE INDENT g = 0 NEW_LINE A = [ 0 ] NEW_LINE for c in B : NEW_LINE INDENT g = g ^ c NEW_LINE A . append ( g ) NEW_LINE DEDENT for t in A [ : - 1 ] : NEW_LINE INDENT print ( t ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] a = new int [ N ] ; int [ ] b = new int [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; b [ i + 1 ] = b [ i ] + a [ i ] ; } if ( b [ N ] == K ) { System . out . println ( 1 ) ; sc . close ( ) ; return ; } int [ ] [ ] dp = new int [ N + 1 ] [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) Arrays . fill ( dp [ i ] , Integer . MAX_VALUE ) ; dp [ 0 ] [ 0 ] = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { dp [ i + 1 ] [ j ] = Math . min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j ] ) ; long x = i == 0 ? 1 : ( long ) dp [ i ] [ j ] * a [ i ] / b [ i ] + 1 ; if ( x <= a [ i ] ) dp [ i + 1 ] [ j + 1 ] = Math . min ( dp [ i + 1 ] [ j + 1 ] , dp [ i ] [ j ] + ( int ) x ) ; } } int ans = 0 ; for ( int i = 1 ; i <= N ; i ++ ) if ( dp [ N ] [ i ] <= K ) ans = i ; System . out . println ( ans ) ; sc . close ( ) ; } }

import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } public void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long K = sc . nextLong ( ) ; int [ ] a = new int [ N + 1 ] ; long [ ] sum = new long [ N + 1 ] ; for ( int i = 1 ; i < a . length ; i ++ ) { a [ i ] = sc . nextInt ( ) ; sum [ i ] = sum [ i - 1 ] + a [ i ] ; } long [ ] [ ] dp = new long [ N + 1 ] [ N + 1 ] ; for ( long [ ] v : dp ) Arrays . fill ( v , Long . MAX_VALUE ) ; dp [ 1 ] [ 0 ] = 0 ; dp [ 1 ] [ 1 ] = 1 ; for ( int j = 1 ; j < N ; j ++ ) { for ( int i = 0 ; i <= j ; i ++ ) { if ( dp [ j ] [ i ] < Long . MAX_VALUE ) { dp [ j + 1 ] [ i ] = Math . min ( dp [ j ] [ i ] , dp [ j + 1 ] [ i ] ) ; long temp = dp [ j ] [ i ] * a [ j + 1 ] / sum [ j ] + 1 ; if ( temp <= a [ j + 1 ] ) dp [ j + 1 ] [ i + 1 ] = Math . min ( dp [ j ] [ i ] + temp , dp [ j + 1 ] [ i + 1 ] ) ; } } } if ( sum [ N ] == K ) { System . out . println ( "1" ) ; } else { int max = 0 ; for ( int i = 0 ; i < dp [ N ] . length ; i ++ ) { if ( dp [ N ] [ i ] <= K ) max = Math . max ( max , i ) ; } System . out . println ( max ) ; } } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int k = s . nextInt ( ) ; int [ ] as = new int [ n ] ; long [ ] asum = new long [ n + 1 ] ; asum [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { long a = s . nextLong ( ) ; asum [ i ] = asum [ i - 1 ] + a ; } if ( asum [ n ] == k ) { System . out . println ( 1 ) ; return ; } long [ ] [ ] dptable = new long [ n + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { dptable [ i ] [ j ] = Long . MAX_VALUE ; } } dptable [ 0 ] [ 0 ] = 0 ; dptable [ 1 ] [ 0 ] = 0 ; dptable [ 1 ] [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { dptable [ i ] [ 0 ] = 0 ; for ( int j = 1 ; j <= i ; j ++ ) { dptable [ i ] [ j ] = dptable [ i - 1 ] [ j ] ; if ( dptable [ i - 1 ] [ j - 1 ] < Long . MAX_VALUE ) { long temp = dptable [ i - 1 ] [ j - 1 ] * asum [ i ] / asum [ i - 1 ] + 1 ; if ( temp - dptable [ i - 1 ] [ j - 1 ] <= asum [ i ] - asum [ i - 1 ] ) { dptable [ i ] [ j ] = Math . min ( dptable [ i ] [ j ] , temp ) ; } } } } for ( int i = 0 ; i < n ; i ++ ) { if ( dptable [ n ] [ i + 1 ] > k ) { System . out . println ( i ) ; return ; } } System . out . println ( n ) ; } }

from itertools import accumulate NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE a = [ int ( input ( ) ) for _ in [ 0 ] * N ] NEW_LINE if sum ( a ) == K or K == 0 : NEW_LINE INDENT print ( int ( K > 0 ) ) NEW_LINE exit ( ) NEW_LINE DEDENT inf , acc = float ( " inf " ) , tuple ( accumulate ( a ) ) NEW_LINE dp = [ inf ] * ( N + 1 ) NEW_LINE dp [ 1 ] = 1 NEW_LINE for i , ( p_game , c_game ) in enumerate ( zip ( acc , acc [ 1 : ] ) , start = 2 ) : NEW_LINE INDENT for j , win in zip ( range ( i + 1 , 0 , - 1 ) , dp [ i : : - 1 ] ) : NEW_LINE INDENT req = ( c_game * win ) // p_game + 1 NEW_LINE if req <= K and req <= c_game : NEW_LINE INDENT dp [ j ] = min ( dp [ j ] , req ) NEW_LINE DEDENT DEDENT DEDENT for i , n in zip ( range ( N , 0 , - 1 ) , dp [ : : - 1 ] ) : NEW_LINE INDENT if n < inf : NEW_LINE INDENT print ( i ) NEW_LINE break NEW_LINE DEDENT DEDENT

import sys NEW_LINE input = sys . stdin . readline NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE A = [ int ( input ( ) ) for i in range ( N ) ] NEW_LINE if sum ( A ) == K : NEW_LINE INDENT print ( 1 ) NEW_LINE exit ( 0 ) NEW_LINE DEDENT inf = 10 ** 18 NEW_LINE dp = [ inf ] * ( N + 1 ) NEW_LINE dp [ 0 ] = 0 NEW_LINE asum = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT a = A [ i ] NEW_LINE for j in range ( N - 1 , - 1 , - 1 ) : NEW_LINE INDENT if dp [ j ] == inf : NEW_LINE INDENT continue NEW_LINE DEDENT k = ( a * dp [ j ] // asum + 1 ) if asum else 1 NEW_LINE if k <= a : NEW_LINE INDENT dp [ j + 1 ] = min ( dp [ j + 1 ] , dp [ j ] + k ) NEW_LINE DEDENT DEDENT asum += a NEW_LINE DEDENT if sum ( A ) != K : NEW_LINE INDENT print ( sum ( x <= K for x in dp ) - 1 ) NEW_LINE DEDENT

from math import ceil NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE a = [ int ( input ( ) ) for _ in [ None ] * N ] NEW_LINE if K == 0 : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT elif N == 1 or sum ( a ) == K : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT inf = float ( " inf " ) NEW_LINE dp = [ inf ] * ( ( N - 1 ) * N ) NEW_LINE dp [ 0 ] = 0 NEW_LINE dp [ 1 ] = 1 NEW_LINE result = 1 NEW_LINE old_total = a [ 0 ] NEW_LINE for i in range ( 1 , N - 1 ) : NEW_LINE INDENT new_total = old_total + a [ i ] NEW_LINE m = new_total / old_total NEW_LINE next_max = i * N + result NEW_LINE next_min = max ( next_max - ( N - 2 - i + 1 ) , i * N ) NEW_LINE for j in range ( next_max , next_min - 1 , - 1 ) : NEW_LINE INDENT n = dp [ j - N ] NEW_LINE v = ceil ( m * n + 0.000000001 ) NEW_LINE if dp [ j ] > n : NEW_LINE INDENT dp [ j ] = n NEW_LINE DEDENT if v <= new_total and v <= K and dp [ j + 1 ] > v : NEW_LINE INDENT dp [ j + 1 ] = v NEW_LINE if j == next_max : NEW_LINE INDENT result += 1 NEW_LINE DEDENT DEDENT DEDENT old_total = new_total NEW_LINE DEDENT last = dp [ ( N - 2 ) * N + result ] NEW_LINE new_total = old_total + a [ N - 1 ] NEW_LINE m = new_total / old_total NEW_LINE v = ceil ( m * last + 0.000000001 ) NEW_LINE if v <= new_total and v <= K : NEW_LINE INDENT result += 1 NEW_LINE DEDENT print ( result ) NEW_LINE DEDENT

from itertools import accumulate NEW_LINE n , k = map ( int , input ( ) . split ( ) ) NEW_LINE a = list ( map ( int , [ input ( ) for _ in range ( n ) ] ) ) NEW_LINE Sa = list ( accumulate ( a ) ) NEW_LINE dp = [ [ float ( ' inf ' ) ] * n for _ in range ( n ) ] NEW_LINE if Sa [ n - 1 ] == k : NEW_LINE INDENT print ( 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT if k == 0 : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT elif n == 1 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT dp [ 0 ] [ 0 ] = 1 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT dp [ i ] [ 0 ] = 1 NEW_LINE for j in range ( 1 , i + 1 ) : NEW_LINE INDENT tmp = dp [ i - 1 ] [ j - 1 ] * Sa [ i ] // Sa [ i - 1 ] + 1 NEW_LINE dp [ i ] [ j ] = min ( tmp , dp [ i - 1 ] [ j ] ) NEW_LINE DEDENT DEDENT if dp [ n - 1 ] [ n - 1 ] <= k : NEW_LINE INDENT print ( n ) NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT if dp [ n - 1 ] [ i ] <= k : NEW_LINE INDENT ans = i + 1 NEW_LINE DEDENT else : NEW_LINE INDENT print ( ans ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT DEDENT DEDENT

def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE N , K = inpl ( ) NEW_LINE A = [ int ( input ( ) ) for _ in range ( N ) ] NEW_LINE S = [ 0 for _ in range ( N + 1 ) ] NEW_LINE tmp = 0 NEW_LINE for i , a in enumerate ( A ) : NEW_LINE INDENT tmp += a NEW_LINE S [ i ] = tmp NEW_LINE DEDENT if sum ( A ) == K : NEW_LINE INDENT print ( 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT DP = [ 0 , 1 ] + [ 10 ** 10 ] * ( N - 1 ) NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT DP2 = [ 0 , 1 ] + [ 10 ** 10 ] * ( N - 1 ) NEW_LINE for j in range ( 1 , i + 1 ) : NEW_LINE INDENT tmp = DP [ j ] * ( S [ i ] - S [ i - 1 ] ) // S [ i - 1 ] + 1 NEW_LINE DP2 [ j + 1 ] = min ( DP [ j + 1 ] , tmp + DP [ j ] , DP2 [ j + 1 ] ) NEW_LINE DEDENT DP = DP2 NEW_LINE DEDENT for i , d in list ( enumerate ( DP ) ) [ : : - 1 ] : NEW_LINE INDENT if d <= K : NEW_LINE INDENT print ( i ) NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT


import java . util . Scanner ; import java . util . Arrays ; import java . util . Comparator ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] val = new int [ n + 1 ] ; Sushi [ ] box = new Sushi [ n ] ; ArrayList < Long > list = new ArrayList < Long > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int t = sc . nextInt ( ) ; long d = sc . nextLong ( ) ; box [ i ] = new Sushi ( t , d ) ; } Arrays . sort ( box , Comparator . comparing ( Sushi :: getD ) . reversed ( ) ) ; long sum = 0 ; long vali = 0 ; for ( int i = 0 ; i < k ; i ++ ) { sum += box [ i ] . d ; if ( val [ box [ i ] . t ] == 0 ) { vali ++ ; } else { list . add ( box [ i ] . d ) ; } val [ box [ i ] . t ] ++ ; } long ans = vali * vali + sum ; if ( list . size ( ) == 0 ) { System . out . println ( ans ) ; return ; } int min = list . size ( ) - 1 ; for ( int i = k ; i < n ; i ++ ) { if ( val [ box [ i ] . t ] == 0 ) { vali ++ ; val [ box [ i ] . t ] ++ ; sum += box [ i ] . d - list . get ( min ) ; min -- ; ans = Math . max ( ans , vali * vali + sum ) ; if ( min == - 1 ) { break ; } } } System . out . println ( ans ) ; } static class Sushi { int t ; long d ; public Sushi ( int t , long d ) { this . t = t ; this . d = d ; } public long getD ( ) { return this . d ; } } }

import java . util . * ; import java . awt . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; long [ ] f = new long [ k + 1 ] ; Point [ ] sushi = new Point [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { sushi [ i ] = ( new Point ( sc . nextInt ( ) , sc . nextInt ( ) ) ) ; } HashSet < Integer > S = new HashSet < > ( ) ; Arrays . sort ( sushi , ( p1 , p2 ) -> p2 . y - p1 . y ) ; long temp = 0 ; int [ ] s = new int [ n + 1 ] ; for ( int i = 0 ; i < k ; i ++ ) { temp += ( long ) sushi [ i ] . y ; S . add ( sushi [ i ] . x ) ; s [ sushi [ i ] . x ] ++ ; } int size = S . size ( ) ; f [ size ] = temp ; int left = k - 1 , right = k ; while ( 0 <= left && right < n ) { while ( 0 <= left && s [ sushi [ left ] . x ] == 1 ) { left -- ; } while ( right < n && s [ sushi [ right ] . x ] > 0 ) { right ++ ; } if ( 0 <= left && right < n ) { f [ size + 1 ] = f [ size ] - sushi [ left ] . y + sushi [ right ] . y ; size ++ ; s [ sushi [ right ] . x ] ++ ; s [ sushi [ left ] . x ] -- ; left -- ; } } long ans = 0 ; for ( long i = 1 ; i <= k ; i ++ ) { if ( f [ ( int ) i ] > 0 ) ans = max ( ans , f [ ( int ) i ] + i * i ) ; } out . println ( ans ) ; } }

import java . util . * ; public class Main { void run ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , k = sc . nextInt ( ) ; P [ ] ps = new P [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int t = sc . nextInt ( ) - 1 ; int d = sc . nextInt ( ) ; ps [ i ] = new P ( t , d ) ; } Arrays . sort ( ps ) ; long ans = 0 ; long cur = 0 ; boolean [ ] used = new boolean [ n ] ; LinkedList < Integer > pops = new LinkedList < > ( ) ; long cnt = 0 ; for ( int i = 0 ; i < k ; i ++ ) { ans += ps [ i ] . d ; cur += ps [ i ] . d ; if ( used [ ps [ i ] . t ] ) { pops . addFirst ( ps [ i ] . d ) ; } else { cnt ++ ; used [ ps [ i ] . t ] = true ; } } ans += cnt * cnt ; for ( int i = k ; i < n && ! pops . isEmpty ( ) ; i ++ ) { if ( ! used [ ps [ i ] . t ] ) { cur -= pops . removeFirst ( ) ; cur += ps [ i ] . d ; cnt ++ ; ans = Math . max ( ans , cur + cnt * cnt ) ; used [ ps [ i ] . t ] = true ; } } System . out . println ( ans ) ; } class P implements Comparable < P > { int t , d ; public P ( int t , int d ) { this . t = t ; this . d = d ; } @ Override public int compareTo ( P o ) { return o . d - d ; } @ Override public String toString ( ) { return String . format ( " { t : ▁ % d , ▁ d : ▁ % d } " , t , d ) ; } } void debug ( Object ... os ) { System . err . println ( Arrays . deepToString ( os ) ) ; } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } }

import java . util . Arrays ; import java . util . Comparator ; import java . util . Scanner ; import java . util . Stack ; class sushi { public int t ; public long d ; public sushi ( int t , long d ) { this . t = t ; this . d = d ; } public long getD ( ) { return this . d ; } } public class Main { static Scanner sc = new Scanner ( System . in ) ; static Stack st = new Stack ( ) ; static int N = sc . nextInt ( ) ; static int K = sc . nextInt ( ) ; static sushi [ ] S = new sushi [ N ] ; static boolean [ ] used = new boolean [ N + 1 ] ; static long sum_t = 0 ; static long sum_d = 0 ; static long ans = 0 ; public static void main ( String [ ] args ) { for ( int i = 0 ; i < N ; i ++ ) { int t = sc . nextInt ( ) ; long d = sc . nextLong ( ) ; sushi su = new sushi ( t , d ) ; S [ i ] = su ; } Arrays . sort ( S , Comparator . comparing ( sushi :: getD ) . reversed ( ) ) ; for ( int i = 0 ; i < K ; i ++ ) { if ( used [ S [ i ] . t ] ) { st . push ( S [ i ] . d ) ; } else { used [ S [ i ] . t ] = true ; sum_t ++ ; } sum_d += S [ i ] . d ; } ans = sum_d + sum_t * sum_t ; for ( int i = K ; i < N ; i ++ ) { if ( st . empty ( ) ) break ; if ( used [ S [ i ] . t ] ) continue ; used [ S [ i ] . t ] = true ; sum_t ++ ; sum_d += S [ i ] . d - ( long ) st . pop ( ) ; ans = Math . max ( ans , sum_d + sum_t * sum_t ) ; } System . out . println ( ans ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

import java . util . * ; public class Main { public static class Sushi { int t ; int d ; public Sushi ( int t , int d ) { this . t = t ; this . d = d ; } } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; Sushi [ ] sushis = new Sushi [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int t = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; sushis [ i ] = new Sushi ( t , d ) ; } Arrays . sort ( sushis , new Comparator < Sushi > ( ) { public int compare ( Sushi s1 , Sushi s2 ) { return s2 . d - s1 . d ; } } ) ; Stack < Sushi > extras = new Stack < Sushi > ( ) ; HashMap < Integer , Boolean > types = new HashMap < Integer , Boolean > ( ) ; long typeCount = 0 ; long deliciousness = 0 ; for ( int i = 0 ; i < K ; i ++ ) { Sushi s = sushis [ i ] ; if ( ! types . containsKey ( s . t ) ) { types . put ( s . t , true ) ; typeCount ++ ; } else { extras . push ( s ) ; } deliciousness += s . d ; } long satisfaction = typeCount * typeCount + deliciousness ; for ( int i = K ; i < N && extras . size ( ) > 0 ; i ++ ) { Sushi s = sushis [ i ] ; if ( ! types . containsKey ( s . t ) ) { types . put ( s . t , true ) ; typeCount ++ ; deliciousness -= extras . pop ( ) . d ; deliciousness += s . d ; satisfaction = Math . max ( satisfaction , typeCount * typeCount + deliciousness ) ; } } System . out . println ( satisfaction ) ; } }

N , K = map ( int , input ( ) . split ( ) ) NEW_LINE sushi = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT s = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE sushi . append ( s ) NEW_LINE DEDENT sushi . sort ( key = lambda x : x [ 1 ] , reverse = True ) NEW_LINE point = 0 NEW_LINE neta_set = set ( ) NEW_LINE removable_idx = list ( ) NEW_LINE for i in range ( K ) : NEW_LINE INDENT s = sushi [ i ] NEW_LINE point += s [ 1 ] NEW_LINE if s [ 0 ] not in neta_set : NEW_LINE INDENT neta_set . add ( s [ 0 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT removable_idx . append ( i ) NEW_LINE DEDENT DEDENT point += len ( neta_set ) ** 2 NEW_LINE max_point = point NEW_LINE for s in sushi [ K : ] : NEW_LINE INDENT if len ( removable_idx ) == 0 : NEW_LINE INDENT break NEW_LINE DEDENT if s [ 0 ] in neta_set : NEW_LINE INDENT continue NEW_LINE DEDENT idx = removable_idx [ - 1 ] NEW_LINE count = len ( neta_set ) NEW_LINE point += s [ 1 ] - sushi [ idx ] [ 1 ] NEW_LINE point += ( count + 1 ) ** 2 - count ** 2 NEW_LINE neta_set . add ( s [ 0 ] ) NEW_LINE removable_idx = removable_idx [ : - 1 ] NEW_LINE if point > max_point : NEW_LINE INDENT max_point = point NEW_LINE DEDENT DEDENT print ( max_point ) NEW_LINE

import heapq NEW_LINE INF = float ( ' inf ' ) NEW_LINE n , k = map ( int , input ( ) . split ( ) ) NEW_LINE sushi = { } NEW_LINE for _ in range ( n ) : NEW_LINE INDENT t , d = map ( int , input ( ) . split ( ) ) NEW_LINE if t not in sushi : NEW_LINE INDENT sushi [ t ] = [ ] NEW_LINE DEDENT sushi [ t ] . append ( d ) NEW_LINE DEDENT for s in sushi . values ( ) : NEW_LINE INDENT s . sort ( reverse = True ) NEW_LINE DEDENT eat_counts = { s : 0 for s in sushi . keys ( ) } NEW_LINE news = [ ] NEW_LINE repeats = [ ] NEW_LINE eats = [ ] NEW_LINE for name , deli_li in sushi . items ( ) : NEW_LINE INDENT heapq . heappush ( news , ( - deli_li [ 0 ] , name ) ) NEW_LINE DEDENT sum_deli = 0 NEW_LINE variety = 0 NEW_LINE for _ in range ( k ) : NEW_LINE INDENT if news and ( not repeats or news [ 0 ] <= repeats [ 0 ] ) : NEW_LINE INDENT deli , name = heapq . heappop ( news ) NEW_LINE variety += 1 NEW_LINE DEDENT else : NEW_LINE INDENT deli , name = heapq . heappop ( repeats ) NEW_LINE DEDENT sum_deli += - deli NEW_LINE eat_counts [ name ] += 1 NEW_LINE heapq . heappush ( eats , ( - deli , name ) ) NEW_LINE if eat_counts [ name ] < len ( sushi [ name ] ) : NEW_LINE INDENT heapq . heappush ( repeats , ( - sushi [ name ] [ eat_counts [ name ] ] , name ) ) NEW_LINE DEDENT DEDENT ans = sum_deli + variety ** 2 NEW_LINE while True : NEW_LINE INDENT if not news or not eats : NEW_LINE INDENT break NEW_LINE DEDENT ate_min_deli , ate_min_name = heapq . heappop ( eats ) NEW_LINE eat_counts [ ate_min_name ] -= 1 NEW_LINE if eat_counts [ ate_min_name ] <= 0 : NEW_LINE INDENT continue NEW_LINE DEDENT sum_deli -= ate_min_deli NEW_LINE deli , name = heapq . heappop ( news ) NEW_LINE variety += 1 NEW_LINE sum_deli += - deli NEW_LINE eat_counts [ name ] += 1 NEW_LINE ans = max ( ans , sum_deli + variety ** 2 ) NEW_LINE DEDENT print ( ans ) NEW_LINE

import collections NEW_LINE index = 0 NEW_LINE def maxsushi ( sushi_list , eaten_sushi ) : NEW_LINE INDENT global index NEW_LINE max_val = [ 0 , 0 ] NEW_LINE for i in range ( index , len ( sushi_list ) ) : NEW_LINE INDENT if ( sushi_list [ i ] [ 1 ] not in eaten_sushi ) : NEW_LINE INDENT tmp = sushi_list [ i ] NEW_LINE max_val = sushi_list [ i ] NEW_LINE index = i NEW_LINE break NEW_LINE DEDENT DEDENT return max_val NEW_LINE DEDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE sushi = [ ] NEW_LINE umasa = [ ] NEW_LINE for _ in range ( N ) : NEW_LINE INDENT i , j = map ( int , input ( ) . split ( ) ) NEW_LINE sushi . append ( i ) NEW_LINE umasa . append ( j ) NEW_LINE DEDENT l = list ( zip ( umasa , sushi ) ) NEW_LINE l = sorted ( l , reverse = True ) NEW_LINE sushi_list = list ( l ) NEW_LINE eat_sushi = sushi_list [ 0 : K ] NEW_LINE eaten_sushi = set ( ) NEW_LINE double_sushi = [ ] NEW_LINE for i in range ( K ) : NEW_LINE INDENT if ( sushi_list [ i ] [ 1 ] not in eaten_sushi ) : NEW_LINE INDENT eaten_sushi . add ( sushi_list [ i ] [ 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT double_sushi . append ( ( sushi_list [ i ] ) ) NEW_LINE DEDENT DEDENT manzoku = 0 NEW_LINE sushi_list = sushi_list [ K : N ] NEW_LINE for i in range ( len ( eat_sushi ) ) : NEW_LINE INDENT manzoku += eat_sushi [ i ] [ 0 ] NEW_LINE DEDENT manzoku = manzoku + ( len ( eaten_sushi ) ) ** 2 NEW_LINE tmp_manzoku = manzoku NEW_LINE while double_sushi : NEW_LINE INDENT tmp1 = double_sushi . pop ( ) NEW_LINE tmp2 = maxsushi ( sushi_list , eaten_sushi ) NEW_LINE if ( tmp2 [ 0 ] == 0 and tmp2 [ 1 ] == 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT eaten_sushi . add ( tmp2 [ 1 ] ) NEW_LINE tmp_manzoku = tmp_manzoku + tmp2 [ 0 ] - tmp1 [ 0 ] + len ( eaten_sushi ) ** 2 - ( len ( eaten_sushi ) - 1 ) ** 2 NEW_LINE if ( tmp_manzoku > manzoku ) : NEW_LINE INDENT manzoku = tmp_manzoku NEW_LINE DEDENT DEDENT print ( manzoku ) NEW_LINE

from collections import defaultdict NEW_LINE import heapq NEW_LINE def main ( ) : NEW_LINE INDENT n , k = map ( int , input ( ) . split ( ) ) NEW_LINE td = [ 0 ] * n NEW_LINE group = defaultdict ( list ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT td [ i ] = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE group [ td [ i ] [ 0 ] ] . append ( td [ i ] [ 1 ] ) NEW_LINE DEDENT grouplist = list ( group . values ( ) ) NEW_LINE for g in grouplist : NEW_LINE INDENT g . sort ( reverse = True ) NEW_LINE DEDENT grouplist . sort ( key = lambda x : - x [ 0 ] ) NEW_LINE non_maxes = [ ] NEW_LINE result = 0 NEW_LINE base = 0 NEW_LINE for i in range ( min ( len ( grouplist ) , k ) ) : NEW_LINE INDENT bonus = ( i + 1 ) * ( i + 1 ) NEW_LINE for j , basic in enumerate ( grouplist [ i ] ) : NEW_LINE INDENT if j == 0 : NEW_LINE INDENT if len ( non_maxes ) > k - ( i + 1 ) : NEW_LINE INDENT remove = heapq . heappop ( non_maxes ) NEW_LINE DEDENT else : NEW_LINE INDENT remove = 0 NEW_LINE DEDENT base += basic - remove NEW_LINE DEDENT elif len ( non_maxes ) < k - ( i + 1 ) : NEW_LINE INDENT heapq . heappush ( non_maxes , basic ) NEW_LINE base += basic NEW_LINE DEDENT elif non_maxes and non_maxes [ 0 ] < basic : NEW_LINE INDENT base += basic - non_maxes [ 0 ] NEW_LINE heapq . heapreplace ( non_maxes , basic ) NEW_LINE DEDENT DEDENT result = max ( result , base + bonus ) NEW_LINE DEDENT print ( result ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

from heapq import heappush , heappop NEW_LINE n , k = map ( int , input ( ) . split ( ) ) NEW_LINE H = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT t , d = map ( int , input ( ) . split ( ) ) NEW_LINE heappush ( H , ( - d , t ) ) NEW_LINE DEDENT Q = [ ] NEW_LINE used = { } NEW_LINE dsum = 0 NEW_LINE for i in range ( k ) : NEW_LINE INDENT d , t = heappop ( H ) NEW_LINE if t not in used : NEW_LINE INDENT used [ t ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT heappush ( Q , ( - d , t ) ) NEW_LINE DEDENT dsum += - d NEW_LINE DEDENT ans = len ( used ) ** 2 + dsum NEW_LINE while H and Q : NEW_LINE INDENT d , t = heappop ( H ) NEW_LINE if t not in used : NEW_LINE INDENT used [ t ] = 1 NEW_LINE m , _ = heappop ( Q ) NEW_LINE dsum = dsum - m - d NEW_LINE ans = max ( ans , len ( used ) ** 2 + dsum ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE


import java . util . Arrays ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String [ ] dat = scan . nextLine ( ) . split ( " ▁ " ) ; scan . close ( ) ; int [ ] intdat = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) intdat [ i ] = Integer . parseInt ( dat [ i ] ) ; Arrays . sort ( intdat ) ; System . out . println ( intdat [ 0 ] + intdat [ 1 ] ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; int c = in . nextInt ( ) ; int ans = Math . min ( a + b , Math . min ( b + c , a + c ) ) ; out . println ( ans ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; if ( a + b <= b + c ) { if ( a + b <= c + a ) { System . out . println ( a + b ) ; } else { System . out . println ( c + a ) ; } } else if ( b + c <= c + a ) { System . out . println ( b + c ) ; } else { System . out . println ( c + a ) ; } } }

import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int [ ] array = { a , b , c } ; Arrays . sort ( array ) ; System . out . println ( array [ 0 ] + array [ 1 ] ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int [ ] sum = { a + b , b + c , c + a } ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( min > sum [ i ] ) min = sum [ i ] ; } System . out . println ( min ) ; } }

a = [ int ( i ) for i in input ( ) . split ( ' ▁ ' ) ] NEW_LINE a . sort ( ) NEW_LINE print ( a [ 0 ] + a [ 1 ] ) NEW_LINE

a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE if a + b <= b + c and a + b <= a + c : NEW_LINE INDENT print ( a + b ) NEW_LINE DEDENT elif b + c <= a + b and b + c <= a + c : NEW_LINE INDENT print ( b + c ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( a + c ) NEW_LINE DEDENT

print ( sum ( sorted ( map ( int , input ( ) . split ( ) ) ) [ 0 : 2 ] ) ) NEW_LINE

List = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE print ( sorted ( List ) [ 0 ] + sorted ( List ) [ 1 ] ) NEW_LINE

bells = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE print ( sum ( bells ) - max ( bells ) ) NEW_LINE


import java . util . Scanner ; public class Main { static long N , H , W , bmax , kingaku ; static long ayen , bup , cyen , dup , edown ; public static void main ( String [ ] args ) { scanning ( ) ; bup += edown ; dup += edown ; W = N * edown - H ; bmax = W / bup + 1 ; if ( W > 0 ) { long Wtemp ; kingaku = bmax * ayen ; for ( long i = 0 ; i < bmax ; i ++ ) { Wtemp = W - i * bup ; kingaku = min ( kingaku , i * ayen + ( Wtemp / dup + 1 ) * cyen ) ; } } System . out . println ( kingaku ) ; } public static void scanning ( ) { Scanner scan = new Scanner ( System . in ) ; N = scan . nextInt ( ) ; H = scan . nextInt ( ) ; ayen = scan . nextInt ( ) ; bup = scan . nextInt ( ) ; cyen = scan . nextInt ( ) ; dup = scan . nextInt ( ) ; edown = scan . nextInt ( ) ; scan . close ( ) ; } public static long min ( long x , long y ) { return x > y ? y : x ; } }

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; C solver = new C ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class C { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) , h = in . nextInt ( ) ; long a = in . nextLong ( ) , b = in . nextLong ( ) , c = in . nextLong ( ) , d = in . nextLong ( ) , e = in . nextLong ( ) ; long s = b + e , t = d + e , u = e * n - h ; long ans = Long . MAX_VALUE ; int y = 0 ; for ( int x = n ; x >= 0 ; x -- ) { while ( s * x + t * y <= u ) { y ++ ; } if ( x + y > n ) { break ; } ans = Math . min ( ans , a * x + c * y ) ; } out . println ( ans ) ; } } }

import java . util . * ; public class Main { public static void main ( String [ ] $ ) { Scanner scanner = new Scanner ( System . in ) ; long n = scanner . nextInt ( ) , h = scanner . nextInt ( ) , a = scanner . nextInt ( ) , b = scanner . nextInt ( ) , c = scanner . nextInt ( ) , d = scanner . nextInt ( ) , e = scanner . nextInt ( ) ; java . util . stream . LongStream . rangeClosed ( 0 , n ) . map ( x -> a * x + c * ( ( - Math . min ( 0 , h - 1 + b * x - e * ( n - x ) ) + d + e - 1 ) / ( d + e ) ) ) . min ( ) . ifPresent ( System . out :: println ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { long n , a , b , c , d , e ; long h ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextLong ( ) ; h = sc . nextLong ( ) ; a = sc . nextLong ( ) ; b = sc . nextLong ( ) ; c = sc . nextLong ( ) ; d = sc . nextLong ( ) ; e = sc . nextLong ( ) ; solve ( ) ; } void solve ( ) { b += e ; d += e ; long diff = n * e - h ; long ans = Long . MAX_VALUE ; for ( int i = 0 ; i <= n ; i ++ ) { long tempDiff = diff - i * b ; long minJ = tempDiff / d + 1 ; if ( tempDiff < 0 ) { minJ = 0 ; } long tempAns = i * a + minJ * c ; if ( tempAns < ans ) { ans = tempAns ; } } System . out . println ( ans ) ; } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } }

import java . util . * ; import java . awt . * ; import java . awt . Graphics . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; long n = sc . nextLong ( ) ; long h = sc . nextLong ( ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = sc . nextLong ( ) ; long d = sc . nextLong ( ) ; long e = sc . nextLong ( ) ; long ans = h - e * n > 0 ? 0 : Long . MAX_VALUE ; for ( long i = 0 ; i <= n ; i ++ ) { if ( n * e - h - ( b + e ) * i < 0 ) continue ; long j = ( n * e - h - ( b + e ) * i ) / ( d + e ) + 1l ; if ( j >= 0 ) ans = min ( ans , a * i + c * j ) ; } for ( long j = 0 ; j < n + 1 ; j ++ ) { if ( ( n * e - h - ( d + e ) * j ) < 0 ) continue ; long i = ( n * e - h - ( d + e ) * j ) / ( b + e ) + 1l ; if ( i >= 0 ) ans = min ( ans , a * i + c * j ) ; } for ( long i = 0 ; i < n + 1 ; i ++ ) { long f = h + i * b - ( n - i ) * e ; if ( f > 0 ) ans = min ( ans , a * i ) ; } for ( long i = 0 ; i < n + 1 ; i ++ ) { long f = h + i * d - ( n - i ) * e ; if ( f > 0 ) ans = min ( ans , c * i ) ; } out . println ( ans ) ; } }

n , h = map ( int , input ( ) . split ( ) ) NEW_LINE a , b , c , d , e = map ( int , input ( ) . split ( ) ) NEW_LINE ans = float ( " inf " ) NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT j = max ( 0 , ( ( n * e - h ) - ( b + e ) * i ) // ( d + e ) + 1 ) NEW_LINE cost = i * a + j * c NEW_LINE if ( 0 <= j <= n ) and ( ans > cost ) : NEW_LINE INDENT ans = cost NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

import sys NEW_LINE inp = sys . stdin . readline NEW_LINE N , H = map ( int , inp ( ) . split ( ) ) NEW_LINE A , B , C , D , E = map ( int , inp ( ) . split ( ) ) NEW_LINE h = H NEW_LINE K = N * E - H NEW_LINE B += E NEW_LINE D += E NEW_LINE if ( H - E * N > 0 ) : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT m = 10000000000000 NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT if ( K - ( B * i ) <= 0 ) : NEW_LINE INDENT m = min ( m , ( A * i ) ) NEW_LINE DEDENT else : NEW_LINE INDENT m = min ( m , ( K - ( B * i ) ) // D * C + C + A * i ) NEW_LINE DEDENT DEDENT print ( m ) NEW_LINE DEDENT

import math NEW_LINE N , H = map ( int , input ( ) . split ( ) ) NEW_LINE A , B , C , D , E = map ( int , input ( ) . split ( ) ) NEW_LINE flag = False NEW_LINE ans = float ( ' inf ' ) NEW_LINE for x in range ( N ) : NEW_LINE INDENT ansx = - 1 NEW_LINE ansy = - 1 NEW_LINE y = math . ceil ( ( - ( B + E ) * x / ( D + E ) ) + ( ( E * N - H ) / ( D + E ) ) ) NEW_LINE if y != ( ( - ( B + E ) * x / ( D + E ) ) + ( ( E * N - H ) / ( D + E ) ) ) : NEW_LINE INDENT if y <= 0 : NEW_LINE INDENT ansy = 0 NEW_LINE ansx = x NEW_LINE DEDENT else : NEW_LINE INDENT if x + y <= N : NEW_LINE INDENT ansy = y NEW_LINE ansx = x NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT if y <= 0 : NEW_LINE INDENT ansy = 1 NEW_LINE ansx = x NEW_LINE DEDENT else : NEW_LINE INDENT if x + y <= N - 1 : NEW_LINE INDENT ansy = y + 1 NEW_LINE ansx = x NEW_LINE DEDENT DEDENT DEDENT if 0 <= ansx + ansy <= N and 0 <= ansx <= N and 0 <= ansy <= N : NEW_LINE INDENT if ans >= A * ansx + C * ansy : NEW_LINE INDENT ans = A * ansx + C * ansy NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE

import math NEW_LINE N , H = map ( int , input ( ) . split ( ) ) NEW_LINE A , B , C , D , E = map ( int , input ( ) . split ( ) ) NEW_LINE min = float ( ' inf ' ) NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT tmp1 = H + ( B + E ) * i - E * N NEW_LINE j = math . ceil ( - 1 * tmp1 / ( D + E ) ) NEW_LINE if j < 0 : NEW_LINE INDENT j = 0 NEW_LINE DEDENT if tmp1 + ( D + E ) * j == 0 : NEW_LINE INDENT j += 1 NEW_LINE DEDENT tmp2 = A * i + C * j NEW_LINE if tmp2 < min : NEW_LINE INDENT min = tmp2 NEW_LINE DEDENT if j == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( min ) NEW_LINE

N , H = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE A , B , C , D , E = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE min_cost = A * N NEW_LINE for i in range ( 0 , N + 1 ) : NEW_LINE INDENT j = max ( 0 , ( N * E - H - i * ( B + E ) ) // ( D + E ) + 1 ) NEW_LINE k = N - i - j NEW_LINE min_cost = min ( min_cost , A * i + C * j ) NEW_LINE DEDENT print ( min_cost ) NEW_LINE NEW_LINE


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; if ( N >= K ) { System . out . println ( X * K + ( N - K ) * Y ) ; } else { System . out . println ( N * X ) ; } } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . ArrayDeque ; import java . util . Queue ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; int K = in . nextInt ( ) ; int X = in . nextInt ( ) ; int Y = in . nextInt ( ) ; int total = 0 ; if ( N < K ) { for ( int i = 0 ; i < N ; i ++ ) { total += X ; } } else { for ( int i = 0 ; i < K ; i ++ ) { total += X ; } } for ( int i = 0 ; i < N - K ; i ++ ) { total += Y ; } out . println ( total ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; int price = ( N <= K ) ? N * X : ( K * X ) + ( ( N - K ) * Y ) ; System . out . println ( price ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long k = sc . nextLong ( ) ; long x = sc . nextLong ( ) ; long y = sc . nextLong ( ) ; System . out . println ( Math . min ( n , k ) * x + Math . max ( n - k , 0 ) * y ) ; } }

import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = sc . nextInt ( ) , k = sc . nextInt ( ) , x = sc . nextInt ( ) , y = sc . nextInt ( ) ; System . out . println ( Math . min ( n , k ) * x + Math . max ( n - k , 0 ) * y ) ; } }

N , K , X , Y = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE print ( K * X + ( N - K ) * Y if N > K else N * X ) NEW_LINE

def tak_and_hotels ( N : int , K : int , X : int , Y : int ) -> int : NEW_LINE INDENT return min ( N , K ) * X + max ( 0 , N - K ) * Y NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE K = int ( input ( ) ) NEW_LINE X = int ( input ( ) ) NEW_LINE Y = int ( input ( ) ) NEW_LINE ans = tak_and_hotels ( N , K , X , Y ) NEW_LINE print ( ans ) NEW_LINE DEDENT

n = int ( input ( ) ) NEW_LINE k = int ( input ( ) ) NEW_LINE x = int ( input ( ) ) NEW_LINE y = int ( input ( ) ) NEW_LINE sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if i + 1 <= k : NEW_LINE INDENT sum += x NEW_LINE DEDENT else : NEW_LINE INDENT sum += y NEW_LINE DEDENT DEDENT print ( sum ) NEW_LINE

max = int ( input ( ) ) NEW_LINE sam = int ( input ( ) ) NEW_LINE sam_num = int ( input ( ) ) NEW_LINE sam_later = int ( input ( ) ) NEW_LINE if ( max < sam ) : NEW_LINE INDENT print ( sam_num * max ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( sam_num * sam + sam_later * ( max - sam ) ) NEW_LINE DEDENT

n , k , x , y = map ( int , open ( 0 ) ) ; print ( n * x - ( x - y ) * max ( n - k , 0 ) ) NEW_LINE