id
stringlengths
2
6
java
stringlengths
48
5.92k
python
stringlengths
33
11.1k
T200
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; long res = 0 ; for ( int i = 1 ; i <= n ; i ++ ) res += i ; System . out . println ( res ) ; sc . close ( ) ; } }
N = int ( input ( ) ) NEW_LINE print ( int ( ( 1 + N ) * N / 2 ) ) NEW_LINE
T201
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; long res = 0 ; for ( int i = 1 ; i <= n ; i ++ ) res += i ; System . out . println ( res ) ; sc . close ( ) ; } }
def children_and_candies ( N : int ) -> int : NEW_LINE INDENT return N * ( N + 1 ) // 2 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE ans = children_and_candies ( N ) NEW_LINE print ( ans ) NEW_LINE DEDENT
T202
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; long res = 0 ; for ( int i = 1 ; i <= n ; i ++ ) res += i ; System . out . println ( res ) ; sc . close ( ) ; } }
from sys import stdin NEW_LINE n = int ( stdin . readline ( ) . rstrip ( ) ) NEW_LINE total = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT total += i NEW_LINE DEDENT print ( total ) NEW_LINE
T203
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; long res = 0 ; for ( int i = 1 ; i <= n ; i ++ ) res += i ; System . out . println ( res ) ; sc . close ( ) ; } }
print ( sum ( [ n for n in range ( 1 , int ( input ( ) ) + 1 ) ] ) ) NEW_LINE
T204
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; long res = 0 ; for ( int i = 1 ; i <= n ; i ++ ) res += i ; System . out . println ( res ) ; sc . close ( ) ; } }
n = input ( ) NEW_LINE n = int ( n ) NEW_LINE a = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT a = a + i NEW_LINE DEDENT print ( a ) NEW_LINE
T205
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { int n = scanner . nextInt ( ) ; System . out . println ( n * ( n + 1 ) / 2 ) ; } } }
N = int ( input ( ) ) NEW_LINE print ( int ( ( 1 + N ) * N / 2 ) ) NEW_LINE
T206
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { int n = scanner . nextInt ( ) ; System . out . println ( n * ( n + 1 ) / 2 ) ; } } }
def children_and_candies ( N : int ) -> int : NEW_LINE INDENT return N * ( N + 1 ) // 2 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE ans = children_and_candies ( N ) NEW_LINE print ( ans ) NEW_LINE DEDENT
T207
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { int n = scanner . nextInt ( ) ; System . out . println ( n * ( n + 1 ) / 2 ) ; } } }
from sys import stdin NEW_LINE n = int ( stdin . readline ( ) . rstrip ( ) ) NEW_LINE total = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT total += i NEW_LINE DEDENT print ( total ) NEW_LINE
T208
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { int n = scanner . nextInt ( ) ; System . out . println ( n * ( n + 1 ) / 2 ) ; } } }
print ( sum ( [ n for n in range ( 1 , int ( input ( ) ) + 1 ) ] ) ) NEW_LINE
T209
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { int n = scanner . nextInt ( ) ; System . out . println ( n * ( n + 1 ) / 2 ) ; } } }
n = input ( ) NEW_LINE n = int ( n ) NEW_LINE a = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT a = a + i NEW_LINE DEDENT print ( a ) NEW_LINE
T210
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] p = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 } ; int [ ] pTotal = new int [ p . length ] ; for ( int i = 0 ; i < p . length ; i ++ ) pTotal [ i ] = legendre ( N , p [ i ] ) ; int ans = 0 ; for ( int i = 0 ; i < p . length ; i ++ ) { if ( pTotal [ i ] >= 74 ) ans ++ ; } for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { if ( i != j && pTotal [ i ] >= 2 && pTotal [ j ] >= 24 ) ans ++ ; } } for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { if ( i != j && pTotal [ i ] >= 4 && pTotal [ j ] >= 14 ) ans ++ ; } } int plus = 0 ; for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { for ( int k = 0 ; k < p . length ; k ++ ) { if ( i != j && j != k && k != i && pTotal [ i ] >= 2 && pTotal [ j ] >= 4 && pTotal [ k ] >= 4 ) plus ++ ; } } } ans += plus / 2 ; System . out . println ( ans ) ; } static int legendre ( int n , int p ) { int c = 0 ; int m = p ; while ( m <= n ) { c += n / m ; m *= p ; } return c ; } }
import math NEW_LINE from collections import Counter NEW_LINE import itertools NEW_LINE def prime_factors ( n ) : NEW_LINE INDENT i = 2 NEW_LINE factors = [ ] NEW_LINE while i * i <= n : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT n //= i NEW_LINE factors . append ( i ) NEW_LINE DEDENT else : NEW_LINE INDENT i += 1 NEW_LINE DEDENT DEDENT if n > 1 : NEW_LINE INDENT factors . append ( n ) NEW_LINE DEDENT return factors NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE num = math . factorial ( n ) NEW_LINE factors = prime_factors ( num ) NEW_LINE es = list ( Counter ( factors ) . values ( ) ) NEW_LINE m = len ( es ) NEW_LINE ans = 0 NEW_LINE for i in range ( m ) : NEW_LINE INDENT if es [ i ] >= 74 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if i != j and es [ i ] >= 24 and es [ j ] >= 2 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if i != j and es [ i ] >= 14 and es [ j ] >= 4 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( i + 1 , m ) : NEW_LINE INDENT for k in range ( m ) : NEW_LINE INDENT if i != k and j != k and es [ i ] >= 4 and es [ j ] >= 4 and es [ k ] >= 2 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
T211
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] p = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 } ; int [ ] pTotal = new int [ p . length ] ; for ( int i = 0 ; i < p . length ; i ++ ) pTotal [ i ] = legendre ( N , p [ i ] ) ; int ans = 0 ; for ( int i = 0 ; i < p . length ; i ++ ) { if ( pTotal [ i ] >= 74 ) ans ++ ; } for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { if ( i != j && pTotal [ i ] >= 2 && pTotal [ j ] >= 24 ) ans ++ ; } } for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { if ( i != j && pTotal [ i ] >= 4 && pTotal [ j ] >= 14 ) ans ++ ; } } int plus = 0 ; for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { for ( int k = 0 ; k < p . length ; k ++ ) { if ( i != j && j != k && k != i && pTotal [ i ] >= 2 && pTotal [ j ] >= 4 && pTotal [ k ] >= 4 ) plus ++ ; } } } ans += plus / 2 ; System . out . println ( ans ) ; } static int legendre ( int n , int p ) { int c = 0 ; int m = p ; while ( m <= n ) { c += n / m ; m *= p ; } return c ; } }
import bisect NEW_LINE from math import factorial as fact NEW_LINE import sys NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE prime = [ ] NEW_LINE p_flag = [ False ] * ( 101 ) NEW_LINE p_flag [ 0 ] = p_flag [ 1 ] = True NEW_LINE for i in range ( 2 , 101 ) : NEW_LINE INDENT if not p_flag [ i ] : NEW_LINE INDENT prime . append ( i ) NEW_LINE for j in range ( 2 * i , 101 , i ) : NEW_LINE INDENT p_flag [ j ] = True NEW_LINE DEDENT DEDENT DEDENT M = len ( prime ) NEW_LINE factor = [ 0 ] * M NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT tmp = prime [ j ] NEW_LINE if tmp > i : NEW_LINE INDENT break NEW_LINE DEDENT while i % tmp == 0 : NEW_LINE INDENT factor [ j ] += 1 NEW_LINE tmp *= prime [ j ] NEW_LINE DEDENT DEDENT DEDENT factor = factor [ : : - 1 ] NEW_LINE point74 = M - bisect . bisect_left ( factor , 74 ) NEW_LINE point24 = M - bisect . bisect_left ( factor , 24 ) NEW_LINE point14 = M - bisect . bisect_left ( factor , 14 ) NEW_LINE point4 = M - bisect . bisect_left ( factor , 4 ) NEW_LINE point2 = M - bisect . bisect_left ( factor , 2 ) NEW_LINE if N < 10 : NEW_LINE INDENT ans = 0 NEW_LINE DEDENT else : NEW_LINE INDENT ans = fact ( point4 ) // ( fact ( point4 - 2 ) * fact ( 2 ) ) * ( point2 - 2 ) NEW_LINE if point14 > 0 : NEW_LINE INDENT ans += point14 * ( point4 - 1 ) NEW_LINE DEDENT if point24 > 0 : NEW_LINE INDENT ans += point24 * ( point2 - 1 ) NEW_LINE DEDENT if point74 > 0 : NEW_LINE INDENT ans += point74 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T212
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] p = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 } ; int [ ] pTotal = new int [ p . length ] ; for ( int i = 0 ; i < p . length ; i ++ ) pTotal [ i ] = legendre ( N , p [ i ] ) ; int ans = 0 ; for ( int i = 0 ; i < p . length ; i ++ ) { if ( pTotal [ i ] >= 74 ) ans ++ ; } for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { if ( i != j && pTotal [ i ] >= 2 && pTotal [ j ] >= 24 ) ans ++ ; } } for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { if ( i != j && pTotal [ i ] >= 4 && pTotal [ j ] >= 14 ) ans ++ ; } } int plus = 0 ; for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { for ( int k = 0 ; k < p . length ; k ++ ) { if ( i != j && j != k && k != i && pTotal [ i ] >= 2 && pTotal [ j ] >= 4 && pTotal [ k ] >= 4 ) plus ++ ; } } } ans += plus / 2 ; System . out . println ( ans ) ; } static int legendre ( int n , int p ) { int c = 0 ; int m = p ; while ( m <= n ) { c += n / m ; m *= p ; } return c ; } }
primes = [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 ] NEW_LINE def get_prime ( n , count = { p : 0 for p in primes } ) : NEW_LINE INDENT for p in primes : NEW_LINE INDENT cp = n NEW_LINE while cp != 0 and cp % p == 0 : NEW_LINE INDENT count [ p ] += 1 NEW_LINE cp = cp // p NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT cnt = { p : 0 for p in primes } NEW_LINE for i in range ( 1 , int ( input ( ) ) + 1 ) : NEW_LINE INDENT get_prime ( i , cnt ) NEW_LINE DEDENT res = 0 NEW_LINE for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 4 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 4 and p1 > p2 : NEW_LINE INDENT for p3 in primes : NEW_LINE INDENT if cnt [ p3 ] >= 2 and p3 != p1 and p3 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 14 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 4 and p1 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 24 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 2 and p1 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 74 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE
T213
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] p = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 } ; int [ ] pTotal = new int [ p . length ] ; for ( int i = 0 ; i < p . length ; i ++ ) pTotal [ i ] = legendre ( N , p [ i ] ) ; int ans = 0 ; for ( int i = 0 ; i < p . length ; i ++ ) { if ( pTotal [ i ] >= 74 ) ans ++ ; } for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { if ( i != j && pTotal [ i ] >= 2 && pTotal [ j ] >= 24 ) ans ++ ; } } for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { if ( i != j && pTotal [ i ] >= 4 && pTotal [ j ] >= 14 ) ans ++ ; } } int plus = 0 ; for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { for ( int k = 0 ; k < p . length ; k ++ ) { if ( i != j && j != k && k != i && pTotal [ i ] >= 2 && pTotal [ j ] >= 4 && pTotal [ k ] >= 4 ) plus ++ ; } } } ans += plus / 2 ; System . out . println ( ans ) ; } static int legendre ( int n , int p ) { int c = 0 ; int m = p ; while ( m <= n ) { c += n / m ; m *= p ; } return c ; } }
import sys NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def POW ( x , y ) : NEW_LINE INDENT if y == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif y == 1 : NEW_LINE INDENT return x NEW_LINE DEDENT elif y % 2 == 0 : NEW_LINE INDENT return POW ( x , y // 2 ) ** 2 % MOD NEW_LINE DEDENT else : NEW_LINE INDENT return POW ( x , y // 2 ) ** 2 * x % MOD NEW_LINE DEDENT DEDENT def mod_factorial ( x , y ) : return x * POW ( y , MOD - 2 ) % MOD NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE from collections import Counter NEW_LINE def main ( ) : NEW_LINE INDENT N = II ( ) NEW_LINE factors = Counter ( ) NEW_LINE for k in range ( 1 , N + 1 ) : NEW_LINE INDENT for i in ( 2 , 3 , 5 , 7 ) : NEW_LINE INDENT while k % i == 0 : NEW_LINE INDENT factors [ i ] += 1 NEW_LINE k //= i NEW_LINE DEDENT DEDENT if k != 1 : NEW_LINE INDENT factors [ k ] += 1 NEW_LINE DEDENT DEDENT nfactors = sorted ( factors . values ( ) ) NEW_LINE ans = 0 NEW_LINE dp = [ 0 ] * 76 NEW_LINE dp [ 1 ] = 1 NEW_LINE for cnt in nfactors : NEW_LINE INDENT pre = dp NEW_LINE dp = [ 0 ] * 76 NEW_LINE for c in range ( 1 , cnt + 2 ) : NEW_LINE INDENT for k in range ( 75 // c + 1 ) : NEW_LINE INDENT dp [ k * c ] += pre [ k ] NEW_LINE DEDENT DEDENT DEDENT ans = dp [ 75 ] NEW_LINE return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T214
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] p = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 } ; int [ ] pTotal = new int [ p . length ] ; for ( int i = 0 ; i < p . length ; i ++ ) pTotal [ i ] = legendre ( N , p [ i ] ) ; int ans = 0 ; for ( int i = 0 ; i < p . length ; i ++ ) { if ( pTotal [ i ] >= 74 ) ans ++ ; } for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { if ( i != j && pTotal [ i ] >= 2 && pTotal [ j ] >= 24 ) ans ++ ; } } for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { if ( i != j && pTotal [ i ] >= 4 && pTotal [ j ] >= 14 ) ans ++ ; } } int plus = 0 ; for ( int i = 0 ; i < p . length ; i ++ ) { for ( int j = 0 ; j < p . length ; j ++ ) { for ( int k = 0 ; k < p . length ; k ++ ) { if ( i != j && j != k && k != i && pTotal [ i ] >= 2 && pTotal [ j ] >= 4 && pTotal [ k ] >= 4 ) plus ++ ; } } } ans += plus / 2 ; System . out . println ( ans ) ; } static int legendre ( int n , int p ) { int c = 0 ; int m = p ; while ( m <= n ) { c += n / m ; m *= p ; } return c ; } }
import itertools NEW_LINE from operator import mul NEW_LINE from functools import reduce NEW_LINE N = int ( input ( ) ) NEW_LINE F = 1 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT F = F * i NEW_LINE DEDENT pns = [ ] NEW_LINE for n in range ( 2 , N + 1 ) : NEW_LINE INDENT for pn in pns : NEW_LINE INDENT if n % pn == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT pns . append ( n ) NEW_LINE DEDENT DEDENT c = 0 NEW_LINE for num in pns : NEW_LINE INDENT if F % num ** 74 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT for nums in itertools . combinations ( pns , 2 ) : NEW_LINE INDENT y1 = nums [ 0 ] ** 14 * nums [ 1 ] ** 4 NEW_LINE y2 = nums [ 1 ] ** 14 * nums [ 0 ] ** 4 NEW_LINE z1 = nums [ 0 ] ** 24 * nums [ 1 ] ** 2 NEW_LINE z2 = nums [ 1 ] ** 24 * nums [ 0 ] ** 2 NEW_LINE if F % y1 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % y2 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % z1 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % z2 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT for nums in itertools . combinations ( pns , 3 ) : NEW_LINE INDENT for num in nums : NEW_LINE INDENT num_except = [ n for n in nums if n != num ] NEW_LINE x = num ** 2 * ( num_except [ 0 ] * num_except [ 1 ] ) ** 4 NEW_LINE if F % x == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT DEDENT print ( c ) NEW_LINE
T215
import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . HashMap ; @ SuppressWarnings ( " unchecked " ) public class Main { static HashMap < Integer , Integer > pf ; static void primeFactor ( int n ) { int a = 2 ; while ( a * a <= n ) { if ( n % a == 0 ) { pf . merge ( a , 1 , Integer :: sum ) ; n = n / a ; } else { a ++ ; } } pf . merge ( n , 1 , Integer :: sum ) ; } static int f ( int x ) { int cnt = 0 ; for ( Integer i : pf . values ( ) ) if ( x - 1 <= i ) cnt ++ ; return cnt ++ ; } public static void main ( String [ ] args ) throws IOException { final String s ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { s = reader . readLine ( ) ; } PrintWriter out = new PrintWriter ( System . out ) ; final String [ ] sl = s . split ( " ▁ " ) ; int N = Integer . parseInt ( sl [ 0 ] ) ; pf = new HashMap < > ( ) ; for ( int i = 2 ; i < N + 1 ; i ++ ) primeFactor ( i ) ; int ans = f ( 75 ) + f ( 25 ) * ( f ( 3 ) - 1 ) + f ( 15 ) * ( f ( 5 ) - 1 ) + f ( 5 ) * ( f ( 5 ) - 1 ) * ( f ( 3 ) - 2 ) / 2 ; out . println ( ans ) ; out . flush ( ) ; } }
import math NEW_LINE from collections import Counter NEW_LINE import itertools NEW_LINE def prime_factors ( n ) : NEW_LINE INDENT i = 2 NEW_LINE factors = [ ] NEW_LINE while i * i <= n : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT n //= i NEW_LINE factors . append ( i ) NEW_LINE DEDENT else : NEW_LINE INDENT i += 1 NEW_LINE DEDENT DEDENT if n > 1 : NEW_LINE INDENT factors . append ( n ) NEW_LINE DEDENT return factors NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE num = math . factorial ( n ) NEW_LINE factors = prime_factors ( num ) NEW_LINE es = list ( Counter ( factors ) . values ( ) ) NEW_LINE m = len ( es ) NEW_LINE ans = 0 NEW_LINE for i in range ( m ) : NEW_LINE INDENT if es [ i ] >= 74 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if i != j and es [ i ] >= 24 and es [ j ] >= 2 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if i != j and es [ i ] >= 14 and es [ j ] >= 4 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( i + 1 , m ) : NEW_LINE INDENT for k in range ( m ) : NEW_LINE INDENT if i != k and j != k and es [ i ] >= 4 and es [ j ] >= 4 and es [ k ] >= 2 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
T216
import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . HashMap ; @ SuppressWarnings ( " unchecked " ) public class Main { static HashMap < Integer , Integer > pf ; static void primeFactor ( int n ) { int a = 2 ; while ( a * a <= n ) { if ( n % a == 0 ) { pf . merge ( a , 1 , Integer :: sum ) ; n = n / a ; } else { a ++ ; } } pf . merge ( n , 1 , Integer :: sum ) ; } static int f ( int x ) { int cnt = 0 ; for ( Integer i : pf . values ( ) ) if ( x - 1 <= i ) cnt ++ ; return cnt ++ ; } public static void main ( String [ ] args ) throws IOException { final String s ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { s = reader . readLine ( ) ; } PrintWriter out = new PrintWriter ( System . out ) ; final String [ ] sl = s . split ( " ▁ " ) ; int N = Integer . parseInt ( sl [ 0 ] ) ; pf = new HashMap < > ( ) ; for ( int i = 2 ; i < N + 1 ; i ++ ) primeFactor ( i ) ; int ans = f ( 75 ) + f ( 25 ) * ( f ( 3 ) - 1 ) + f ( 15 ) * ( f ( 5 ) - 1 ) + f ( 5 ) * ( f ( 5 ) - 1 ) * ( f ( 3 ) - 2 ) / 2 ; out . println ( ans ) ; out . flush ( ) ; } }
import bisect NEW_LINE from math import factorial as fact NEW_LINE import sys NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE prime = [ ] NEW_LINE p_flag = [ False ] * ( 101 ) NEW_LINE p_flag [ 0 ] = p_flag [ 1 ] = True NEW_LINE for i in range ( 2 , 101 ) : NEW_LINE INDENT if not p_flag [ i ] : NEW_LINE INDENT prime . append ( i ) NEW_LINE for j in range ( 2 * i , 101 , i ) : NEW_LINE INDENT p_flag [ j ] = True NEW_LINE DEDENT DEDENT DEDENT M = len ( prime ) NEW_LINE factor = [ 0 ] * M NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT tmp = prime [ j ] NEW_LINE if tmp > i : NEW_LINE INDENT break NEW_LINE DEDENT while i % tmp == 0 : NEW_LINE INDENT factor [ j ] += 1 NEW_LINE tmp *= prime [ j ] NEW_LINE DEDENT DEDENT DEDENT factor = factor [ : : - 1 ] NEW_LINE point74 = M - bisect . bisect_left ( factor , 74 ) NEW_LINE point24 = M - bisect . bisect_left ( factor , 24 ) NEW_LINE point14 = M - bisect . bisect_left ( factor , 14 ) NEW_LINE point4 = M - bisect . bisect_left ( factor , 4 ) NEW_LINE point2 = M - bisect . bisect_left ( factor , 2 ) NEW_LINE if N < 10 : NEW_LINE INDENT ans = 0 NEW_LINE DEDENT else : NEW_LINE INDENT ans = fact ( point4 ) // ( fact ( point4 - 2 ) * fact ( 2 ) ) * ( point2 - 2 ) NEW_LINE if point14 > 0 : NEW_LINE INDENT ans += point14 * ( point4 - 1 ) NEW_LINE DEDENT if point24 > 0 : NEW_LINE INDENT ans += point24 * ( point2 - 1 ) NEW_LINE DEDENT if point74 > 0 : NEW_LINE INDENT ans += point74 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T217
import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . HashMap ; @ SuppressWarnings ( " unchecked " ) public class Main { static HashMap < Integer , Integer > pf ; static void primeFactor ( int n ) { int a = 2 ; while ( a * a <= n ) { if ( n % a == 0 ) { pf . merge ( a , 1 , Integer :: sum ) ; n = n / a ; } else { a ++ ; } } pf . merge ( n , 1 , Integer :: sum ) ; } static int f ( int x ) { int cnt = 0 ; for ( Integer i : pf . values ( ) ) if ( x - 1 <= i ) cnt ++ ; return cnt ++ ; } public static void main ( String [ ] args ) throws IOException { final String s ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { s = reader . readLine ( ) ; } PrintWriter out = new PrintWriter ( System . out ) ; final String [ ] sl = s . split ( " ▁ " ) ; int N = Integer . parseInt ( sl [ 0 ] ) ; pf = new HashMap < > ( ) ; for ( int i = 2 ; i < N + 1 ; i ++ ) primeFactor ( i ) ; int ans = f ( 75 ) + f ( 25 ) * ( f ( 3 ) - 1 ) + f ( 15 ) * ( f ( 5 ) - 1 ) + f ( 5 ) * ( f ( 5 ) - 1 ) * ( f ( 3 ) - 2 ) / 2 ; out . println ( ans ) ; out . flush ( ) ; } }
primes = [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 ] NEW_LINE def get_prime ( n , count = { p : 0 for p in primes } ) : NEW_LINE INDENT for p in primes : NEW_LINE INDENT cp = n NEW_LINE while cp != 0 and cp % p == 0 : NEW_LINE INDENT count [ p ] += 1 NEW_LINE cp = cp // p NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT cnt = { p : 0 for p in primes } NEW_LINE for i in range ( 1 , int ( input ( ) ) + 1 ) : NEW_LINE INDENT get_prime ( i , cnt ) NEW_LINE DEDENT res = 0 NEW_LINE for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 4 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 4 and p1 > p2 : NEW_LINE INDENT for p3 in primes : NEW_LINE INDENT if cnt [ p3 ] >= 2 and p3 != p1 and p3 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 14 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 4 and p1 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 24 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 2 and p1 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 74 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE
T218
import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . HashMap ; @ SuppressWarnings ( " unchecked " ) public class Main { static HashMap < Integer , Integer > pf ; static void primeFactor ( int n ) { int a = 2 ; while ( a * a <= n ) { if ( n % a == 0 ) { pf . merge ( a , 1 , Integer :: sum ) ; n = n / a ; } else { a ++ ; } } pf . merge ( n , 1 , Integer :: sum ) ; } static int f ( int x ) { int cnt = 0 ; for ( Integer i : pf . values ( ) ) if ( x - 1 <= i ) cnt ++ ; return cnt ++ ; } public static void main ( String [ ] args ) throws IOException { final String s ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { s = reader . readLine ( ) ; } PrintWriter out = new PrintWriter ( System . out ) ; final String [ ] sl = s . split ( " ▁ " ) ; int N = Integer . parseInt ( sl [ 0 ] ) ; pf = new HashMap < > ( ) ; for ( int i = 2 ; i < N + 1 ; i ++ ) primeFactor ( i ) ; int ans = f ( 75 ) + f ( 25 ) * ( f ( 3 ) - 1 ) + f ( 15 ) * ( f ( 5 ) - 1 ) + f ( 5 ) * ( f ( 5 ) - 1 ) * ( f ( 3 ) - 2 ) / 2 ; out . println ( ans ) ; out . flush ( ) ; } }
import sys NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def POW ( x , y ) : NEW_LINE INDENT if y == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif y == 1 : NEW_LINE INDENT return x NEW_LINE DEDENT elif y % 2 == 0 : NEW_LINE INDENT return POW ( x , y // 2 ) ** 2 % MOD NEW_LINE DEDENT else : NEW_LINE INDENT return POW ( x , y // 2 ) ** 2 * x % MOD NEW_LINE DEDENT DEDENT def mod_factorial ( x , y ) : return x * POW ( y , MOD - 2 ) % MOD NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE from collections import Counter NEW_LINE def main ( ) : NEW_LINE INDENT N = II ( ) NEW_LINE factors = Counter ( ) NEW_LINE for k in range ( 1 , N + 1 ) : NEW_LINE INDENT for i in ( 2 , 3 , 5 , 7 ) : NEW_LINE INDENT while k % i == 0 : NEW_LINE INDENT factors [ i ] += 1 NEW_LINE k //= i NEW_LINE DEDENT DEDENT if k != 1 : NEW_LINE INDENT factors [ k ] += 1 NEW_LINE DEDENT DEDENT nfactors = sorted ( factors . values ( ) ) NEW_LINE ans = 0 NEW_LINE dp = [ 0 ] * 76 NEW_LINE dp [ 1 ] = 1 NEW_LINE for cnt in nfactors : NEW_LINE INDENT pre = dp NEW_LINE dp = [ 0 ] * 76 NEW_LINE for c in range ( 1 , cnt + 2 ) : NEW_LINE INDENT for k in range ( 75 // c + 1 ) : NEW_LINE INDENT dp [ k * c ] += pre [ k ] NEW_LINE DEDENT DEDENT DEDENT ans = dp [ 75 ] NEW_LINE return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T219
import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . HashMap ; @ SuppressWarnings ( " unchecked " ) public class Main { static HashMap < Integer , Integer > pf ; static void primeFactor ( int n ) { int a = 2 ; while ( a * a <= n ) { if ( n % a == 0 ) { pf . merge ( a , 1 , Integer :: sum ) ; n = n / a ; } else { a ++ ; } } pf . merge ( n , 1 , Integer :: sum ) ; } static int f ( int x ) { int cnt = 0 ; for ( Integer i : pf . values ( ) ) if ( x - 1 <= i ) cnt ++ ; return cnt ++ ; } public static void main ( String [ ] args ) throws IOException { final String s ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { s = reader . readLine ( ) ; } PrintWriter out = new PrintWriter ( System . out ) ; final String [ ] sl = s . split ( " ▁ " ) ; int N = Integer . parseInt ( sl [ 0 ] ) ; pf = new HashMap < > ( ) ; for ( int i = 2 ; i < N + 1 ; i ++ ) primeFactor ( i ) ; int ans = f ( 75 ) + f ( 25 ) * ( f ( 3 ) - 1 ) + f ( 15 ) * ( f ( 5 ) - 1 ) + f ( 5 ) * ( f ( 5 ) - 1 ) * ( f ( 3 ) - 2 ) / 2 ; out . println ( ans ) ; out . flush ( ) ; } }
import itertools NEW_LINE from operator import mul NEW_LINE from functools import reduce NEW_LINE N = int ( input ( ) ) NEW_LINE F = 1 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT F = F * i NEW_LINE DEDENT pns = [ ] NEW_LINE for n in range ( 2 , N + 1 ) : NEW_LINE INDENT for pn in pns : NEW_LINE INDENT if n % pn == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT pns . append ( n ) NEW_LINE DEDENT DEDENT c = 0 NEW_LINE for num in pns : NEW_LINE INDENT if F % num ** 74 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT for nums in itertools . combinations ( pns , 2 ) : NEW_LINE INDENT y1 = nums [ 0 ] ** 14 * nums [ 1 ] ** 4 NEW_LINE y2 = nums [ 1 ] ** 14 * nums [ 0 ] ** 4 NEW_LINE z1 = nums [ 0 ] ** 24 * nums [ 1 ] ** 2 NEW_LINE z2 = nums [ 1 ] ** 24 * nums [ 0 ] ** 2 NEW_LINE if F % y1 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % y2 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % z1 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % z2 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT for nums in itertools . combinations ( pns , 3 ) : NEW_LINE INDENT for num in nums : NEW_LINE INDENT num_except = [ n for n in nums if n != num ] NEW_LINE x = num ** 2 * ( num_except [ 0 ] * num_except [ 1 ] ) ** 4 NEW_LINE if F % x == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT DEDENT print ( c ) NEW_LINE
T220
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; HashMap < Integer , Integer > primeCount = new HashMap < > ( ) ; primeCount . put ( 1 , 1 ) ; for ( int i = 2 ; i <= N ; i ++ ) { int value = i ; for ( int j = 2 ; j <= i ; j ++ ) { while ( value % j == 0 ) { primeCount . put ( j , primeCount . containsKey ( j ) ? primeCount . get ( j ) + 1 : 1 ) ; value = value / j ; } } } int ans = 0 ; for ( Map . Entry < Integer , Integer > entry0 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry1 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry2 : primeCount . entrySet ( ) ) { if ( entry0 . getKey ( ) == entry1 . getKey ( ) ) continue ; if ( entry0 . getKey ( ) == entry2 . getKey ( ) ) continue ; if ( entry1 . getKey ( ) == entry2 . getKey ( ) ) continue ; if ( entry1 . getKey ( ) > entry2 . getKey ( ) ) continue ; if ( entry0 . getValue ( ) >= 2 && entry1 . getValue ( ) >= 4 && entry2 . getValue ( ) >= 4 ) ans ++ ; } } } for ( Map . Entry < Integer , Integer > entry0 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry1 : primeCount . entrySet ( ) ) { if ( entry0 . getKey ( ) == entry1 . getKey ( ) ) continue ; if ( entry0 . getValue ( ) >= 4 && entry1 . getValue ( ) >= 14 ) ans ++ ; if ( entry0 . getValue ( ) >= 2 && entry1 . getValue ( ) >= 24 ) ans ++ ; } } for ( Integer count : primeCount . values ( ) ) { if ( count >= 74 ) ans ++ ; } System . out . println ( ans ) ; } }
import math NEW_LINE from collections import Counter NEW_LINE import itertools NEW_LINE def prime_factors ( n ) : NEW_LINE INDENT i = 2 NEW_LINE factors = [ ] NEW_LINE while i * i <= n : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT n //= i NEW_LINE factors . append ( i ) NEW_LINE DEDENT else : NEW_LINE INDENT i += 1 NEW_LINE DEDENT DEDENT if n > 1 : NEW_LINE INDENT factors . append ( n ) NEW_LINE DEDENT return factors NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE num = math . factorial ( n ) NEW_LINE factors = prime_factors ( num ) NEW_LINE es = list ( Counter ( factors ) . values ( ) ) NEW_LINE m = len ( es ) NEW_LINE ans = 0 NEW_LINE for i in range ( m ) : NEW_LINE INDENT if es [ i ] >= 74 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if i != j and es [ i ] >= 24 and es [ j ] >= 2 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if i != j and es [ i ] >= 14 and es [ j ] >= 4 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( i + 1 , m ) : NEW_LINE INDENT for k in range ( m ) : NEW_LINE INDENT if i != k and j != k and es [ i ] >= 4 and es [ j ] >= 4 and es [ k ] >= 2 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
T221
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; HashMap < Integer , Integer > primeCount = new HashMap < > ( ) ; primeCount . put ( 1 , 1 ) ; for ( int i = 2 ; i <= N ; i ++ ) { int value = i ; for ( int j = 2 ; j <= i ; j ++ ) { while ( value % j == 0 ) { primeCount . put ( j , primeCount . containsKey ( j ) ? primeCount . get ( j ) + 1 : 1 ) ; value = value / j ; } } } int ans = 0 ; for ( Map . Entry < Integer , Integer > entry0 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry1 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry2 : primeCount . entrySet ( ) ) { if ( entry0 . getKey ( ) == entry1 . getKey ( ) ) continue ; if ( entry0 . getKey ( ) == entry2 . getKey ( ) ) continue ; if ( entry1 . getKey ( ) == entry2 . getKey ( ) ) continue ; if ( entry1 . getKey ( ) > entry2 . getKey ( ) ) continue ; if ( entry0 . getValue ( ) >= 2 && entry1 . getValue ( ) >= 4 && entry2 . getValue ( ) >= 4 ) ans ++ ; } } } for ( Map . Entry < Integer , Integer > entry0 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry1 : primeCount . entrySet ( ) ) { if ( entry0 . getKey ( ) == entry1 . getKey ( ) ) continue ; if ( entry0 . getValue ( ) >= 4 && entry1 . getValue ( ) >= 14 ) ans ++ ; if ( entry0 . getValue ( ) >= 2 && entry1 . getValue ( ) >= 24 ) ans ++ ; } } for ( Integer count : primeCount . values ( ) ) { if ( count >= 74 ) ans ++ ; } System . out . println ( ans ) ; } }
import bisect NEW_LINE from math import factorial as fact NEW_LINE import sys NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE prime = [ ] NEW_LINE p_flag = [ False ] * ( 101 ) NEW_LINE p_flag [ 0 ] = p_flag [ 1 ] = True NEW_LINE for i in range ( 2 , 101 ) : NEW_LINE INDENT if not p_flag [ i ] : NEW_LINE INDENT prime . append ( i ) NEW_LINE for j in range ( 2 * i , 101 , i ) : NEW_LINE INDENT p_flag [ j ] = True NEW_LINE DEDENT DEDENT DEDENT M = len ( prime ) NEW_LINE factor = [ 0 ] * M NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT tmp = prime [ j ] NEW_LINE if tmp > i : NEW_LINE INDENT break NEW_LINE DEDENT while i % tmp == 0 : NEW_LINE INDENT factor [ j ] += 1 NEW_LINE tmp *= prime [ j ] NEW_LINE DEDENT DEDENT DEDENT factor = factor [ : : - 1 ] NEW_LINE point74 = M - bisect . bisect_left ( factor , 74 ) NEW_LINE point24 = M - bisect . bisect_left ( factor , 24 ) NEW_LINE point14 = M - bisect . bisect_left ( factor , 14 ) NEW_LINE point4 = M - bisect . bisect_left ( factor , 4 ) NEW_LINE point2 = M - bisect . bisect_left ( factor , 2 ) NEW_LINE if N < 10 : NEW_LINE INDENT ans = 0 NEW_LINE DEDENT else : NEW_LINE INDENT ans = fact ( point4 ) // ( fact ( point4 - 2 ) * fact ( 2 ) ) * ( point2 - 2 ) NEW_LINE if point14 > 0 : NEW_LINE INDENT ans += point14 * ( point4 - 1 ) NEW_LINE DEDENT if point24 > 0 : NEW_LINE INDENT ans += point24 * ( point2 - 1 ) NEW_LINE DEDENT if point74 > 0 : NEW_LINE INDENT ans += point74 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T222
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; HashMap < Integer , Integer > primeCount = new HashMap < > ( ) ; primeCount . put ( 1 , 1 ) ; for ( int i = 2 ; i <= N ; i ++ ) { int value = i ; for ( int j = 2 ; j <= i ; j ++ ) { while ( value % j == 0 ) { primeCount . put ( j , primeCount . containsKey ( j ) ? primeCount . get ( j ) + 1 : 1 ) ; value = value / j ; } } } int ans = 0 ; for ( Map . Entry < Integer , Integer > entry0 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry1 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry2 : primeCount . entrySet ( ) ) { if ( entry0 . getKey ( ) == entry1 . getKey ( ) ) continue ; if ( entry0 . getKey ( ) == entry2 . getKey ( ) ) continue ; if ( entry1 . getKey ( ) == entry2 . getKey ( ) ) continue ; if ( entry1 . getKey ( ) > entry2 . getKey ( ) ) continue ; if ( entry0 . getValue ( ) >= 2 && entry1 . getValue ( ) >= 4 && entry2 . getValue ( ) >= 4 ) ans ++ ; } } } for ( Map . Entry < Integer , Integer > entry0 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry1 : primeCount . entrySet ( ) ) { if ( entry0 . getKey ( ) == entry1 . getKey ( ) ) continue ; if ( entry0 . getValue ( ) >= 4 && entry1 . getValue ( ) >= 14 ) ans ++ ; if ( entry0 . getValue ( ) >= 2 && entry1 . getValue ( ) >= 24 ) ans ++ ; } } for ( Integer count : primeCount . values ( ) ) { if ( count >= 74 ) ans ++ ; } System . out . println ( ans ) ; } }
primes = [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 ] NEW_LINE def get_prime ( n , count = { p : 0 for p in primes } ) : NEW_LINE INDENT for p in primes : NEW_LINE INDENT cp = n NEW_LINE while cp != 0 and cp % p == 0 : NEW_LINE INDENT count [ p ] += 1 NEW_LINE cp = cp // p NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT cnt = { p : 0 for p in primes } NEW_LINE for i in range ( 1 , int ( input ( ) ) + 1 ) : NEW_LINE INDENT get_prime ( i , cnt ) NEW_LINE DEDENT res = 0 NEW_LINE for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 4 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 4 and p1 > p2 : NEW_LINE INDENT for p3 in primes : NEW_LINE INDENT if cnt [ p3 ] >= 2 and p3 != p1 and p3 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 14 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 4 and p1 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 24 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 2 and p1 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 74 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE
T223
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; HashMap < Integer , Integer > primeCount = new HashMap < > ( ) ; primeCount . put ( 1 , 1 ) ; for ( int i = 2 ; i <= N ; i ++ ) { int value = i ; for ( int j = 2 ; j <= i ; j ++ ) { while ( value % j == 0 ) { primeCount . put ( j , primeCount . containsKey ( j ) ? primeCount . get ( j ) + 1 : 1 ) ; value = value / j ; } } } int ans = 0 ; for ( Map . Entry < Integer , Integer > entry0 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry1 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry2 : primeCount . entrySet ( ) ) { if ( entry0 . getKey ( ) == entry1 . getKey ( ) ) continue ; if ( entry0 . getKey ( ) == entry2 . getKey ( ) ) continue ; if ( entry1 . getKey ( ) == entry2 . getKey ( ) ) continue ; if ( entry1 . getKey ( ) > entry2 . getKey ( ) ) continue ; if ( entry0 . getValue ( ) >= 2 && entry1 . getValue ( ) >= 4 && entry2 . getValue ( ) >= 4 ) ans ++ ; } } } for ( Map . Entry < Integer , Integer > entry0 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry1 : primeCount . entrySet ( ) ) { if ( entry0 . getKey ( ) == entry1 . getKey ( ) ) continue ; if ( entry0 . getValue ( ) >= 4 && entry1 . getValue ( ) >= 14 ) ans ++ ; if ( entry0 . getValue ( ) >= 2 && entry1 . getValue ( ) >= 24 ) ans ++ ; } } for ( Integer count : primeCount . values ( ) ) { if ( count >= 74 ) ans ++ ; } System . out . println ( ans ) ; } }
import sys NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def POW ( x , y ) : NEW_LINE INDENT if y == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif y == 1 : NEW_LINE INDENT return x NEW_LINE DEDENT elif y % 2 == 0 : NEW_LINE INDENT return POW ( x , y // 2 ) ** 2 % MOD NEW_LINE DEDENT else : NEW_LINE INDENT return POW ( x , y // 2 ) ** 2 * x % MOD NEW_LINE DEDENT DEDENT def mod_factorial ( x , y ) : return x * POW ( y , MOD - 2 ) % MOD NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE from collections import Counter NEW_LINE def main ( ) : NEW_LINE INDENT N = II ( ) NEW_LINE factors = Counter ( ) NEW_LINE for k in range ( 1 , N + 1 ) : NEW_LINE INDENT for i in ( 2 , 3 , 5 , 7 ) : NEW_LINE INDENT while k % i == 0 : NEW_LINE INDENT factors [ i ] += 1 NEW_LINE k //= i NEW_LINE DEDENT DEDENT if k != 1 : NEW_LINE INDENT factors [ k ] += 1 NEW_LINE DEDENT DEDENT nfactors = sorted ( factors . values ( ) ) NEW_LINE ans = 0 NEW_LINE dp = [ 0 ] * 76 NEW_LINE dp [ 1 ] = 1 NEW_LINE for cnt in nfactors : NEW_LINE INDENT pre = dp NEW_LINE dp = [ 0 ] * 76 NEW_LINE for c in range ( 1 , cnt + 2 ) : NEW_LINE INDENT for k in range ( 75 // c + 1 ) : NEW_LINE INDENT dp [ k * c ] += pre [ k ] NEW_LINE DEDENT DEDENT DEDENT ans = dp [ 75 ] NEW_LINE return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T224
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; HashMap < Integer , Integer > primeCount = new HashMap < > ( ) ; primeCount . put ( 1 , 1 ) ; for ( int i = 2 ; i <= N ; i ++ ) { int value = i ; for ( int j = 2 ; j <= i ; j ++ ) { while ( value % j == 0 ) { primeCount . put ( j , primeCount . containsKey ( j ) ? primeCount . get ( j ) + 1 : 1 ) ; value = value / j ; } } } int ans = 0 ; for ( Map . Entry < Integer , Integer > entry0 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry1 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry2 : primeCount . entrySet ( ) ) { if ( entry0 . getKey ( ) == entry1 . getKey ( ) ) continue ; if ( entry0 . getKey ( ) == entry2 . getKey ( ) ) continue ; if ( entry1 . getKey ( ) == entry2 . getKey ( ) ) continue ; if ( entry1 . getKey ( ) > entry2 . getKey ( ) ) continue ; if ( entry0 . getValue ( ) >= 2 && entry1 . getValue ( ) >= 4 && entry2 . getValue ( ) >= 4 ) ans ++ ; } } } for ( Map . Entry < Integer , Integer > entry0 : primeCount . entrySet ( ) ) { for ( Map . Entry < Integer , Integer > entry1 : primeCount . entrySet ( ) ) { if ( entry0 . getKey ( ) == entry1 . getKey ( ) ) continue ; if ( entry0 . getValue ( ) >= 4 && entry1 . getValue ( ) >= 14 ) ans ++ ; if ( entry0 . getValue ( ) >= 2 && entry1 . getValue ( ) >= 24 ) ans ++ ; } } for ( Integer count : primeCount . values ( ) ) { if ( count >= 74 ) ans ++ ; } System . out . println ( ans ) ; } }
import itertools NEW_LINE from operator import mul NEW_LINE from functools import reduce NEW_LINE N = int ( input ( ) ) NEW_LINE F = 1 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT F = F * i NEW_LINE DEDENT pns = [ ] NEW_LINE for n in range ( 2 , N + 1 ) : NEW_LINE INDENT for pn in pns : NEW_LINE INDENT if n % pn == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT pns . append ( n ) NEW_LINE DEDENT DEDENT c = 0 NEW_LINE for num in pns : NEW_LINE INDENT if F % num ** 74 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT for nums in itertools . combinations ( pns , 2 ) : NEW_LINE INDENT y1 = nums [ 0 ] ** 14 * nums [ 1 ] ** 4 NEW_LINE y2 = nums [ 1 ] ** 14 * nums [ 0 ] ** 4 NEW_LINE z1 = nums [ 0 ] ** 24 * nums [ 1 ] ** 2 NEW_LINE z2 = nums [ 1 ] ** 24 * nums [ 0 ] ** 2 NEW_LINE if F % y1 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % y2 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % z1 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % z2 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT for nums in itertools . combinations ( pns , 3 ) : NEW_LINE INDENT for num in nums : NEW_LINE INDENT num_except = [ n for n in nums if n != num ] NEW_LINE x = num ** 2 * ( num_except [ 0 ] * num_except [ 1 ] ) ** 4 NEW_LINE if F % x == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT DEDENT print ( c ) NEW_LINE
T225
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; sc . close ( ) ; int [ ] P = new int [ 48 ] ; int over74 = 0 ; int over24 = 0 ; int over14 = 0 ; int over4 = 0 ; int over2 = 0 ; for ( int i = 2 ; i <= N ; i ++ ) { int x = i ; for ( int j = 2 ; j < Math . min ( N , 48 ) ; j ++ ) { while ( x % j == 0 ) { x /= j ; P [ j ] ++ ; } } } for ( int p : P ) { if ( p > 1 ) over2 ++ ; if ( p > 3 ) over4 ++ ; if ( p > 13 ) over14 ++ ; if ( p > 23 ) over24 ++ ; if ( p > 73 ) over74 ++ ; } int ans = 0 ; ans += over74 ; if ( over14 > 0 && over4 > 1 ) ans += over14 * ( over4 - 1 ) ; if ( over24 > 0 && over2 > 1 ) ans += over24 * ( over2 - 1 ) ; if ( over4 > 1 && over2 > 2 ) ans += ( over4 * ( over4 - 1 ) / 2 ) * ( over2 - 2 ) ; System . out . println ( ans ) ; } }
import math NEW_LINE from collections import Counter NEW_LINE import itertools NEW_LINE def prime_factors ( n ) : NEW_LINE INDENT i = 2 NEW_LINE factors = [ ] NEW_LINE while i * i <= n : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT n //= i NEW_LINE factors . append ( i ) NEW_LINE DEDENT else : NEW_LINE INDENT i += 1 NEW_LINE DEDENT DEDENT if n > 1 : NEW_LINE INDENT factors . append ( n ) NEW_LINE DEDENT return factors NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE num = math . factorial ( n ) NEW_LINE factors = prime_factors ( num ) NEW_LINE es = list ( Counter ( factors ) . values ( ) ) NEW_LINE m = len ( es ) NEW_LINE ans = 0 NEW_LINE for i in range ( m ) : NEW_LINE INDENT if es [ i ] >= 74 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if i != j and es [ i ] >= 24 and es [ j ] >= 2 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if i != j and es [ i ] >= 14 and es [ j ] >= 4 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( i + 1 , m ) : NEW_LINE INDENT for k in range ( m ) : NEW_LINE INDENT if i != k and j != k and es [ i ] >= 4 and es [ j ] >= 4 and es [ k ] >= 2 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
T226
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; sc . close ( ) ; int [ ] P = new int [ 48 ] ; int over74 = 0 ; int over24 = 0 ; int over14 = 0 ; int over4 = 0 ; int over2 = 0 ; for ( int i = 2 ; i <= N ; i ++ ) { int x = i ; for ( int j = 2 ; j < Math . min ( N , 48 ) ; j ++ ) { while ( x % j == 0 ) { x /= j ; P [ j ] ++ ; } } } for ( int p : P ) { if ( p > 1 ) over2 ++ ; if ( p > 3 ) over4 ++ ; if ( p > 13 ) over14 ++ ; if ( p > 23 ) over24 ++ ; if ( p > 73 ) over74 ++ ; } int ans = 0 ; ans += over74 ; if ( over14 > 0 && over4 > 1 ) ans += over14 * ( over4 - 1 ) ; if ( over24 > 0 && over2 > 1 ) ans += over24 * ( over2 - 1 ) ; if ( over4 > 1 && over2 > 2 ) ans += ( over4 * ( over4 - 1 ) / 2 ) * ( over2 - 2 ) ; System . out . println ( ans ) ; } }
import bisect NEW_LINE from math import factorial as fact NEW_LINE import sys NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE prime = [ ] NEW_LINE p_flag = [ False ] * ( 101 ) NEW_LINE p_flag [ 0 ] = p_flag [ 1 ] = True NEW_LINE for i in range ( 2 , 101 ) : NEW_LINE INDENT if not p_flag [ i ] : NEW_LINE INDENT prime . append ( i ) NEW_LINE for j in range ( 2 * i , 101 , i ) : NEW_LINE INDENT p_flag [ j ] = True NEW_LINE DEDENT DEDENT DEDENT M = len ( prime ) NEW_LINE factor = [ 0 ] * M NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT tmp = prime [ j ] NEW_LINE if tmp > i : NEW_LINE INDENT break NEW_LINE DEDENT while i % tmp == 0 : NEW_LINE INDENT factor [ j ] += 1 NEW_LINE tmp *= prime [ j ] NEW_LINE DEDENT DEDENT DEDENT factor = factor [ : : - 1 ] NEW_LINE point74 = M - bisect . bisect_left ( factor , 74 ) NEW_LINE point24 = M - bisect . bisect_left ( factor , 24 ) NEW_LINE point14 = M - bisect . bisect_left ( factor , 14 ) NEW_LINE point4 = M - bisect . bisect_left ( factor , 4 ) NEW_LINE point2 = M - bisect . bisect_left ( factor , 2 ) NEW_LINE if N < 10 : NEW_LINE INDENT ans = 0 NEW_LINE DEDENT else : NEW_LINE INDENT ans = fact ( point4 ) // ( fact ( point4 - 2 ) * fact ( 2 ) ) * ( point2 - 2 ) NEW_LINE if point14 > 0 : NEW_LINE INDENT ans += point14 * ( point4 - 1 ) NEW_LINE DEDENT if point24 > 0 : NEW_LINE INDENT ans += point24 * ( point2 - 1 ) NEW_LINE DEDENT if point74 > 0 : NEW_LINE INDENT ans += point74 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T227
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; sc . close ( ) ; int [ ] P = new int [ 48 ] ; int over74 = 0 ; int over24 = 0 ; int over14 = 0 ; int over4 = 0 ; int over2 = 0 ; for ( int i = 2 ; i <= N ; i ++ ) { int x = i ; for ( int j = 2 ; j < Math . min ( N , 48 ) ; j ++ ) { while ( x % j == 0 ) { x /= j ; P [ j ] ++ ; } } } for ( int p : P ) { if ( p > 1 ) over2 ++ ; if ( p > 3 ) over4 ++ ; if ( p > 13 ) over14 ++ ; if ( p > 23 ) over24 ++ ; if ( p > 73 ) over74 ++ ; } int ans = 0 ; ans += over74 ; if ( over14 > 0 && over4 > 1 ) ans += over14 * ( over4 - 1 ) ; if ( over24 > 0 && over2 > 1 ) ans += over24 * ( over2 - 1 ) ; if ( over4 > 1 && over2 > 2 ) ans += ( over4 * ( over4 - 1 ) / 2 ) * ( over2 - 2 ) ; System . out . println ( ans ) ; } }
primes = [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 ] NEW_LINE def get_prime ( n , count = { p : 0 for p in primes } ) : NEW_LINE INDENT for p in primes : NEW_LINE INDENT cp = n NEW_LINE while cp != 0 and cp % p == 0 : NEW_LINE INDENT count [ p ] += 1 NEW_LINE cp = cp // p NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT cnt = { p : 0 for p in primes } NEW_LINE for i in range ( 1 , int ( input ( ) ) + 1 ) : NEW_LINE INDENT get_prime ( i , cnt ) NEW_LINE DEDENT res = 0 NEW_LINE for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 4 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 4 and p1 > p2 : NEW_LINE INDENT for p3 in primes : NEW_LINE INDENT if cnt [ p3 ] >= 2 and p3 != p1 and p3 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 14 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 4 and p1 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 24 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 2 and p1 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 74 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE
T228
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; sc . close ( ) ; int [ ] P = new int [ 48 ] ; int over74 = 0 ; int over24 = 0 ; int over14 = 0 ; int over4 = 0 ; int over2 = 0 ; for ( int i = 2 ; i <= N ; i ++ ) { int x = i ; for ( int j = 2 ; j < Math . min ( N , 48 ) ; j ++ ) { while ( x % j == 0 ) { x /= j ; P [ j ] ++ ; } } } for ( int p : P ) { if ( p > 1 ) over2 ++ ; if ( p > 3 ) over4 ++ ; if ( p > 13 ) over14 ++ ; if ( p > 23 ) over24 ++ ; if ( p > 73 ) over74 ++ ; } int ans = 0 ; ans += over74 ; if ( over14 > 0 && over4 > 1 ) ans += over14 * ( over4 - 1 ) ; if ( over24 > 0 && over2 > 1 ) ans += over24 * ( over2 - 1 ) ; if ( over4 > 1 && over2 > 2 ) ans += ( over4 * ( over4 - 1 ) / 2 ) * ( over2 - 2 ) ; System . out . println ( ans ) ; } }
import sys NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def POW ( x , y ) : NEW_LINE INDENT if y == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif y == 1 : NEW_LINE INDENT return x NEW_LINE DEDENT elif y % 2 == 0 : NEW_LINE INDENT return POW ( x , y // 2 ) ** 2 % MOD NEW_LINE DEDENT else : NEW_LINE INDENT return POW ( x , y // 2 ) ** 2 * x % MOD NEW_LINE DEDENT DEDENT def mod_factorial ( x , y ) : return x * POW ( y , MOD - 2 ) % MOD NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE from collections import Counter NEW_LINE def main ( ) : NEW_LINE INDENT N = II ( ) NEW_LINE factors = Counter ( ) NEW_LINE for k in range ( 1 , N + 1 ) : NEW_LINE INDENT for i in ( 2 , 3 , 5 , 7 ) : NEW_LINE INDENT while k % i == 0 : NEW_LINE INDENT factors [ i ] += 1 NEW_LINE k //= i NEW_LINE DEDENT DEDENT if k != 1 : NEW_LINE INDENT factors [ k ] += 1 NEW_LINE DEDENT DEDENT nfactors = sorted ( factors . values ( ) ) NEW_LINE ans = 0 NEW_LINE dp = [ 0 ] * 76 NEW_LINE dp [ 1 ] = 1 NEW_LINE for cnt in nfactors : NEW_LINE INDENT pre = dp NEW_LINE dp = [ 0 ] * 76 NEW_LINE for c in range ( 1 , cnt + 2 ) : NEW_LINE INDENT for k in range ( 75 // c + 1 ) : NEW_LINE INDENT dp [ k * c ] += pre [ k ] NEW_LINE DEDENT DEDENT DEDENT ans = dp [ 75 ] NEW_LINE return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T229
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; sc . close ( ) ; int [ ] P = new int [ 48 ] ; int over74 = 0 ; int over24 = 0 ; int over14 = 0 ; int over4 = 0 ; int over2 = 0 ; for ( int i = 2 ; i <= N ; i ++ ) { int x = i ; for ( int j = 2 ; j < Math . min ( N , 48 ) ; j ++ ) { while ( x % j == 0 ) { x /= j ; P [ j ] ++ ; } } } for ( int p : P ) { if ( p > 1 ) over2 ++ ; if ( p > 3 ) over4 ++ ; if ( p > 13 ) over14 ++ ; if ( p > 23 ) over24 ++ ; if ( p > 73 ) over74 ++ ; } int ans = 0 ; ans += over74 ; if ( over14 > 0 && over4 > 1 ) ans += over14 * ( over4 - 1 ) ; if ( over24 > 0 && over2 > 1 ) ans += over24 * ( over2 - 1 ) ; if ( over4 > 1 && over2 > 2 ) ans += ( over4 * ( over4 - 1 ) / 2 ) * ( over2 - 2 ) ; System . out . println ( ans ) ; } }
import itertools NEW_LINE from operator import mul NEW_LINE from functools import reduce NEW_LINE N = int ( input ( ) ) NEW_LINE F = 1 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT F = F * i NEW_LINE DEDENT pns = [ ] NEW_LINE for n in range ( 2 , N + 1 ) : NEW_LINE INDENT for pn in pns : NEW_LINE INDENT if n % pn == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT pns . append ( n ) NEW_LINE DEDENT DEDENT c = 0 NEW_LINE for num in pns : NEW_LINE INDENT if F % num ** 74 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT for nums in itertools . combinations ( pns , 2 ) : NEW_LINE INDENT y1 = nums [ 0 ] ** 14 * nums [ 1 ] ** 4 NEW_LINE y2 = nums [ 1 ] ** 14 * nums [ 0 ] ** 4 NEW_LINE z1 = nums [ 0 ] ** 24 * nums [ 1 ] ** 2 NEW_LINE z2 = nums [ 1 ] ** 24 * nums [ 0 ] ** 2 NEW_LINE if F % y1 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % y2 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % z1 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % z2 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT for nums in itertools . combinations ( pns , 3 ) : NEW_LINE INDENT for num in nums : NEW_LINE INDENT num_except = [ n for n in nums if n != num ] NEW_LINE x = num ** 2 * ( num_except [ 0 ] * num_except [ 1 ] ) ** 4 NEW_LINE if F % x == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT DEDENT print ( c ) NEW_LINE
T230
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; boolean [ ] pr = new boolean [ N + 1 ] ; int count = 0 ; for ( int i = 2 ; i < N + 1 ; i ++ ) pr [ i ] = true ; for ( int i = 2 ; i < N + 1 ; i ++ ) { if ( pr [ i ] ) { count ++ ; for ( int j = 2 * i ; j < N + 1 ; j += i ) pr [ j ] = false ; } } final int C = count ; int [ ] prn = new int [ C ] ; int id = 0 ; for ( int i = 0 ; i < N + 1 ; i ++ ) { if ( pr [ i ] ) { int b = i ; while ( b <= N ) { prn [ id ] += N / b ; b *= i ; } id ++ ; } } int ans = 0 ; for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { for ( int k = j + 1 ; k < C ; k ++ ) { if ( i != j && i != k && prn [ i ] >= 2 && prn [ j ] >= 4 && prn [ k ] >= 4 ) ans ++ ; } } } for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( i != j && prn [ i ] >= 2 && prn [ j ] >= 24 ) ans ++ ; } } for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( i != j && prn [ i ] >= 4 && prn [ j ] >= 14 ) ans ++ ; } } if ( C > 0 && prn [ 0 ] >= 74 ) ans ++ ; System . out . println ( ans ) ; } }
import math NEW_LINE from collections import Counter NEW_LINE import itertools NEW_LINE def prime_factors ( n ) : NEW_LINE INDENT i = 2 NEW_LINE factors = [ ] NEW_LINE while i * i <= n : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT n //= i NEW_LINE factors . append ( i ) NEW_LINE DEDENT else : NEW_LINE INDENT i += 1 NEW_LINE DEDENT DEDENT if n > 1 : NEW_LINE INDENT factors . append ( n ) NEW_LINE DEDENT return factors NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE num = math . factorial ( n ) NEW_LINE factors = prime_factors ( num ) NEW_LINE es = list ( Counter ( factors ) . values ( ) ) NEW_LINE m = len ( es ) NEW_LINE ans = 0 NEW_LINE for i in range ( m ) : NEW_LINE INDENT if es [ i ] >= 74 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if i != j and es [ i ] >= 24 and es [ j ] >= 2 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if i != j and es [ i ] >= 14 and es [ j ] >= 4 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT for j in range ( i + 1 , m ) : NEW_LINE INDENT for k in range ( m ) : NEW_LINE INDENT if i != k and j != k and es [ i ] >= 4 and es [ j ] >= 4 and es [ k ] >= 2 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
T231
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; boolean [ ] pr = new boolean [ N + 1 ] ; int count = 0 ; for ( int i = 2 ; i < N + 1 ; i ++ ) pr [ i ] = true ; for ( int i = 2 ; i < N + 1 ; i ++ ) { if ( pr [ i ] ) { count ++ ; for ( int j = 2 * i ; j < N + 1 ; j += i ) pr [ j ] = false ; } } final int C = count ; int [ ] prn = new int [ C ] ; int id = 0 ; for ( int i = 0 ; i < N + 1 ; i ++ ) { if ( pr [ i ] ) { int b = i ; while ( b <= N ) { prn [ id ] += N / b ; b *= i ; } id ++ ; } } int ans = 0 ; for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { for ( int k = j + 1 ; k < C ; k ++ ) { if ( i != j && i != k && prn [ i ] >= 2 && prn [ j ] >= 4 && prn [ k ] >= 4 ) ans ++ ; } } } for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( i != j && prn [ i ] >= 2 && prn [ j ] >= 24 ) ans ++ ; } } for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( i != j && prn [ i ] >= 4 && prn [ j ] >= 14 ) ans ++ ; } } if ( C > 0 && prn [ 0 ] >= 74 ) ans ++ ; System . out . println ( ans ) ; } }
import bisect NEW_LINE from math import factorial as fact NEW_LINE import sys NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE prime = [ ] NEW_LINE p_flag = [ False ] * ( 101 ) NEW_LINE p_flag [ 0 ] = p_flag [ 1 ] = True NEW_LINE for i in range ( 2 , 101 ) : NEW_LINE INDENT if not p_flag [ i ] : NEW_LINE INDENT prime . append ( i ) NEW_LINE for j in range ( 2 * i , 101 , i ) : NEW_LINE INDENT p_flag [ j ] = True NEW_LINE DEDENT DEDENT DEDENT M = len ( prime ) NEW_LINE factor = [ 0 ] * M NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT tmp = prime [ j ] NEW_LINE if tmp > i : NEW_LINE INDENT break NEW_LINE DEDENT while i % tmp == 0 : NEW_LINE INDENT factor [ j ] += 1 NEW_LINE tmp *= prime [ j ] NEW_LINE DEDENT DEDENT DEDENT factor = factor [ : : - 1 ] NEW_LINE point74 = M - bisect . bisect_left ( factor , 74 ) NEW_LINE point24 = M - bisect . bisect_left ( factor , 24 ) NEW_LINE point14 = M - bisect . bisect_left ( factor , 14 ) NEW_LINE point4 = M - bisect . bisect_left ( factor , 4 ) NEW_LINE point2 = M - bisect . bisect_left ( factor , 2 ) NEW_LINE if N < 10 : NEW_LINE INDENT ans = 0 NEW_LINE DEDENT else : NEW_LINE INDENT ans = fact ( point4 ) // ( fact ( point4 - 2 ) * fact ( 2 ) ) * ( point2 - 2 ) NEW_LINE if point14 > 0 : NEW_LINE INDENT ans += point14 * ( point4 - 1 ) NEW_LINE DEDENT if point24 > 0 : NEW_LINE INDENT ans += point24 * ( point2 - 1 ) NEW_LINE DEDENT if point74 > 0 : NEW_LINE INDENT ans += point74 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T232
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; boolean [ ] pr = new boolean [ N + 1 ] ; int count = 0 ; for ( int i = 2 ; i < N + 1 ; i ++ ) pr [ i ] = true ; for ( int i = 2 ; i < N + 1 ; i ++ ) { if ( pr [ i ] ) { count ++ ; for ( int j = 2 * i ; j < N + 1 ; j += i ) pr [ j ] = false ; } } final int C = count ; int [ ] prn = new int [ C ] ; int id = 0 ; for ( int i = 0 ; i < N + 1 ; i ++ ) { if ( pr [ i ] ) { int b = i ; while ( b <= N ) { prn [ id ] += N / b ; b *= i ; } id ++ ; } } int ans = 0 ; for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { for ( int k = j + 1 ; k < C ; k ++ ) { if ( i != j && i != k && prn [ i ] >= 2 && prn [ j ] >= 4 && prn [ k ] >= 4 ) ans ++ ; } } } for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( i != j && prn [ i ] >= 2 && prn [ j ] >= 24 ) ans ++ ; } } for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( i != j && prn [ i ] >= 4 && prn [ j ] >= 14 ) ans ++ ; } } if ( C > 0 && prn [ 0 ] >= 74 ) ans ++ ; System . out . println ( ans ) ; } }
primes = [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 ] NEW_LINE def get_prime ( n , count = { p : 0 for p in primes } ) : NEW_LINE INDENT for p in primes : NEW_LINE INDENT cp = n NEW_LINE while cp != 0 and cp % p == 0 : NEW_LINE INDENT count [ p ] += 1 NEW_LINE cp = cp // p NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT cnt = { p : 0 for p in primes } NEW_LINE for i in range ( 1 , int ( input ( ) ) + 1 ) : NEW_LINE INDENT get_prime ( i , cnt ) NEW_LINE DEDENT res = 0 NEW_LINE for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 4 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 4 and p1 > p2 : NEW_LINE INDENT for p3 in primes : NEW_LINE INDENT if cnt [ p3 ] >= 2 and p3 != p1 and p3 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 14 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 4 and p1 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 24 : NEW_LINE INDENT for p2 in primes : NEW_LINE INDENT if cnt [ p2 ] >= 2 and p1 != p2 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT for p1 in primes : NEW_LINE INDENT if cnt [ p1 ] >= 74 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE
T233
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; boolean [ ] pr = new boolean [ N + 1 ] ; int count = 0 ; for ( int i = 2 ; i < N + 1 ; i ++ ) pr [ i ] = true ; for ( int i = 2 ; i < N + 1 ; i ++ ) { if ( pr [ i ] ) { count ++ ; for ( int j = 2 * i ; j < N + 1 ; j += i ) pr [ j ] = false ; } } final int C = count ; int [ ] prn = new int [ C ] ; int id = 0 ; for ( int i = 0 ; i < N + 1 ; i ++ ) { if ( pr [ i ] ) { int b = i ; while ( b <= N ) { prn [ id ] += N / b ; b *= i ; } id ++ ; } } int ans = 0 ; for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { for ( int k = j + 1 ; k < C ; k ++ ) { if ( i != j && i != k && prn [ i ] >= 2 && prn [ j ] >= 4 && prn [ k ] >= 4 ) ans ++ ; } } } for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( i != j && prn [ i ] >= 2 && prn [ j ] >= 24 ) ans ++ ; } } for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( i != j && prn [ i ] >= 4 && prn [ j ] >= 14 ) ans ++ ; } } if ( C > 0 && prn [ 0 ] >= 74 ) ans ++ ; System . out . println ( ans ) ; } }
import sys NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def POW ( x , y ) : NEW_LINE INDENT if y == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif y == 1 : NEW_LINE INDENT return x NEW_LINE DEDENT elif y % 2 == 0 : NEW_LINE INDENT return POW ( x , y // 2 ) ** 2 % MOD NEW_LINE DEDENT else : NEW_LINE INDENT return POW ( x , y // 2 ) ** 2 * x % MOD NEW_LINE DEDENT DEDENT def mod_factorial ( x , y ) : return x * POW ( y , MOD - 2 ) % MOD NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE from collections import Counter NEW_LINE def main ( ) : NEW_LINE INDENT N = II ( ) NEW_LINE factors = Counter ( ) NEW_LINE for k in range ( 1 , N + 1 ) : NEW_LINE INDENT for i in ( 2 , 3 , 5 , 7 ) : NEW_LINE INDENT while k % i == 0 : NEW_LINE INDENT factors [ i ] += 1 NEW_LINE k //= i NEW_LINE DEDENT DEDENT if k != 1 : NEW_LINE INDENT factors [ k ] += 1 NEW_LINE DEDENT DEDENT nfactors = sorted ( factors . values ( ) ) NEW_LINE ans = 0 NEW_LINE dp = [ 0 ] * 76 NEW_LINE dp [ 1 ] = 1 NEW_LINE for cnt in nfactors : NEW_LINE INDENT pre = dp NEW_LINE dp = [ 0 ] * 76 NEW_LINE for c in range ( 1 , cnt + 2 ) : NEW_LINE INDENT for k in range ( 75 // c + 1 ) : NEW_LINE INDENT dp [ k * c ] += pre [ k ] NEW_LINE DEDENT DEDENT DEDENT ans = dp [ 75 ] NEW_LINE return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T234
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; boolean [ ] pr = new boolean [ N + 1 ] ; int count = 0 ; for ( int i = 2 ; i < N + 1 ; i ++ ) pr [ i ] = true ; for ( int i = 2 ; i < N + 1 ; i ++ ) { if ( pr [ i ] ) { count ++ ; for ( int j = 2 * i ; j < N + 1 ; j += i ) pr [ j ] = false ; } } final int C = count ; int [ ] prn = new int [ C ] ; int id = 0 ; for ( int i = 0 ; i < N + 1 ; i ++ ) { if ( pr [ i ] ) { int b = i ; while ( b <= N ) { prn [ id ] += N / b ; b *= i ; } id ++ ; } } int ans = 0 ; for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { for ( int k = j + 1 ; k < C ; k ++ ) { if ( i != j && i != k && prn [ i ] >= 2 && prn [ j ] >= 4 && prn [ k ] >= 4 ) ans ++ ; } } } for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( i != j && prn [ i ] >= 2 && prn [ j ] >= 24 ) ans ++ ; } } for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( i != j && prn [ i ] >= 4 && prn [ j ] >= 14 ) ans ++ ; } } if ( C > 0 && prn [ 0 ] >= 74 ) ans ++ ; System . out . println ( ans ) ; } }
import itertools NEW_LINE from operator import mul NEW_LINE from functools import reduce NEW_LINE N = int ( input ( ) ) NEW_LINE F = 1 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT F = F * i NEW_LINE DEDENT pns = [ ] NEW_LINE for n in range ( 2 , N + 1 ) : NEW_LINE INDENT for pn in pns : NEW_LINE INDENT if n % pn == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT pns . append ( n ) NEW_LINE DEDENT DEDENT c = 0 NEW_LINE for num in pns : NEW_LINE INDENT if F % num ** 74 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT for nums in itertools . combinations ( pns , 2 ) : NEW_LINE INDENT y1 = nums [ 0 ] ** 14 * nums [ 1 ] ** 4 NEW_LINE y2 = nums [ 1 ] ** 14 * nums [ 0 ] ** 4 NEW_LINE z1 = nums [ 0 ] ** 24 * nums [ 1 ] ** 2 NEW_LINE z2 = nums [ 1 ] ** 24 * nums [ 0 ] ** 2 NEW_LINE if F % y1 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % y2 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % z1 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if F % z2 == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT for nums in itertools . combinations ( pns , 3 ) : NEW_LINE INDENT for num in nums : NEW_LINE INDENT num_except = [ n for n in nums if n != num ] NEW_LINE x = num ** 2 * ( num_except [ 0 ] * num_except [ 1 ] ) ** 4 NEW_LINE if F % x == 0 : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT DEDENT print ( c ) NEW_LINE
T235
import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . StringTokenizer ; public class Main { public static void main ( String args [ ] ) { ConsoleScanner cin = new ConsoleScanner ( ) ; PrintWriter cout = new PrintWriter ( System . out ) ; solve ( cin , cout ) ; cout . flush ( ) ; } static long now ( ) { return System . currentTimeMillis ( ) ; } static void trace ( Object ... objects ) { assert null != System . out . format ( " trace : % s \n " , Arrays . deepToString ( objects ) ) ; } private static void solve ( ConsoleScanner cin , PrintWriter cout ) { int n = cin . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < a . length ; i ++ ) a [ i ] = cin . nextInt ( ) ; long start = now ( ) ; long ans = solve ( n , a ) ; cout . println ( ans ) ; trace ( " elapsed " , now ( ) - start ) ; } private static long solve ( int n , int [ ] a ) { long total = Arrays . stream ( a ) . mapToLong ( x -> x ) . sum ( ) ; long ans = Long . MAX_VALUE ; long s = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { s += a [ i ] ; ans = Math . min ( ans , Math . abs ( total - 2 * s ) ) ; } return ans ; } static class ConsoleScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ; String next ( ) { try { while ( ! st . hasMoreElements ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return st . nextToken ( ) ; } catch ( IOException e ) { throw new AssertionError ( e ) ; } } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } }
def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE import numpy as np NEW_LINE ans = float ( ' inf ' ) NEW_LINE N = int ( input ( ) ) NEW_LINE a = np . cumsum ( np . array ( inpl ( ) ) ) NEW_LINE suma = a [ - 1 ] NEW_LINE a = np . delete ( a , - 1 ) NEW_LINE for i in a : NEW_LINE INDENT ans = min ( ans , abs ( suma - 2 * i ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T236
import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . StringTokenizer ; public class Main { public static void main ( String args [ ] ) { ConsoleScanner cin = new ConsoleScanner ( ) ; PrintWriter cout = new PrintWriter ( System . out ) ; solve ( cin , cout ) ; cout . flush ( ) ; } static long now ( ) { return System . currentTimeMillis ( ) ; } static void trace ( Object ... objects ) { assert null != System . out . format ( " trace : % s \n " , Arrays . deepToString ( objects ) ) ; } private static void solve ( ConsoleScanner cin , PrintWriter cout ) { int n = cin . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < a . length ; i ++ ) a [ i ] = cin . nextInt ( ) ; long start = now ( ) ; long ans = solve ( n , a ) ; cout . println ( ans ) ; trace ( " elapsed " , now ( ) - start ) ; } private static long solve ( int n , int [ ] a ) { long total = Arrays . stream ( a ) . mapToLong ( x -> x ) . sum ( ) ; long ans = Long . MAX_VALUE ; long s = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { s += a [ i ] ; ans = Math . min ( ans , Math . abs ( total - 2 * s ) ) ; } return ans ; } static class ConsoleScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ; String next ( ) { try { while ( ! st . hasMoreElements ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return st . nextToken ( ) ; } catch ( IOException e ) { throw new AssertionError ( e ) ; } } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } }
n = int ( input ( ) ) ; a = list ( map ( int , input ( ) . split ( ) ) ) ; b = [ 0 ] NEW_LINE for i in a : b . append ( b [ - 1 ] + i ) NEW_LINE b = b [ 1 : ] ; s = b [ - 1 ] ; mi = abs ( b [ 0 ] - ( b [ - 1 ] - b [ 0 ] ) ) NEW_LINE for i in range ( n - 1 ) : mi = min ( abs ( b [ i ] - ( b [ - 1 ] - b [ i ] ) ) , mi ) NEW_LINE print ( mi ) NEW_LINE
T237
import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . StringTokenizer ; public class Main { public static void main ( String args [ ] ) { ConsoleScanner cin = new ConsoleScanner ( ) ; PrintWriter cout = new PrintWriter ( System . out ) ; solve ( cin , cout ) ; cout . flush ( ) ; } static long now ( ) { return System . currentTimeMillis ( ) ; } static void trace ( Object ... objects ) { assert null != System . out . format ( " trace : % s \n " , Arrays . deepToString ( objects ) ) ; } private static void solve ( ConsoleScanner cin , PrintWriter cout ) { int n = cin . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < a . length ; i ++ ) a [ i ] = cin . nextInt ( ) ; long start = now ( ) ; long ans = solve ( n , a ) ; cout . println ( ans ) ; trace ( " elapsed " , now ( ) - start ) ; } private static long solve ( int n , int [ ] a ) { long total = Arrays . stream ( a ) . mapToLong ( x -> x ) . sum ( ) ; long ans = Long . MAX_VALUE ; long s = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { s += a [ i ] ; ans = Math . min ( ans , Math . abs ( total - 2 * s ) ) ; } return ans ; } static class ConsoleScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ; String next ( ) { try { while ( ! st . hasMoreElements ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return st . nextToken ( ) ; } catch ( IOException e ) { throw new AssertionError ( e ) ; } } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } }
from numpy import * ; n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) ; print ( min ( abs ( cumsum ( a [ : : - 1 ] ) [ : : - 1 ] - cumsum ( [ 0 ] + a [ : - 1 ] ) ) [ 1 : ] ) ) NEW_LINE
T238
import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . StringTokenizer ; public class Main { public static void main ( String args [ ] ) { ConsoleScanner cin = new ConsoleScanner ( ) ; PrintWriter cout = new PrintWriter ( System . out ) ; solve ( cin , cout ) ; cout . flush ( ) ; } static long now ( ) { return System . currentTimeMillis ( ) ; } static void trace ( Object ... objects ) { assert null != System . out . format ( " trace : % s \n " , Arrays . deepToString ( objects ) ) ; } private static void solve ( ConsoleScanner cin , PrintWriter cout ) { int n = cin . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < a . length ; i ++ ) a [ i ] = cin . nextInt ( ) ; long start = now ( ) ; long ans = solve ( n , a ) ; cout . println ( ans ) ; trace ( " elapsed " , now ( ) - start ) ; } private static long solve ( int n , int [ ] a ) { long total = Arrays . stream ( a ) . mapToLong ( x -> x ) . sum ( ) ; long ans = Long . MAX_VALUE ; long s = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { s += a [ i ] ; ans = Math . min ( ans , Math . abs ( total - 2 * s ) ) ; } return ans ; } static class ConsoleScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ; String next ( ) { try { while ( ! st . hasMoreElements ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return st . nextToken ( ) ; } catch ( IOException e ) { throw new AssertionError ( e ) ; } } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } }
def getInt ( ) : return int ( input ( ) ) NEW_LINE def getIntList ( ) : return [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE def zeros ( n ) : return [ 0 ] * n NEW_LINE def getIntLines ( n ) : return [ int ( input ( ) ) for i in range ( n ) ] NEW_LINE def getIntMat ( n ) : NEW_LINE INDENT mat = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT mat . append ( getIntList ( ) ) NEW_LINE DEDENT return mat NEW_LINE DEDENT def zeros2 ( n , m ) : return [ zeros ( m ) ] * n NEW_LINE ALPHABET = [ chr ( i + ord ( ' a ' ) ) for i in range ( 26 ) ] NEW_LINE DIGIT = [ chr ( i + ord ( '0' ) ) for i in range ( 10 ) ] NEW_LINE N1097 = 10 ** 9 + 7 NEW_LINE def dmp ( x , cmt = ' ' ) : NEW_LINE INDENT global debug NEW_LINE if debug : NEW_LINE INDENT if cmt != ' ' : NEW_LINE INDENT print ( cmt , ' : ▁ ▁ ' , end = ' ' ) NEW_LINE DEDENT print ( x ) NEW_LINE DEDENT return x NEW_LINE DEDENT def probC ( ) : NEW_LINE INDENT N = getInt ( ) NEW_LINE A = getIntList ( ) NEW_LINE dmp ( ( N , A ) ) NEW_LINE sumFormer = A [ 0 ] NEW_LINE sumLatter = sum ( A [ 1 : ] ) NEW_LINE diff = abs ( sumFormer - sumLatter ) NEW_LINE dmp ( diff , ' init ' ) NEW_LINE for i in range ( 1 , N - 1 ) : NEW_LINE INDENT sumFormer += A [ i ] NEW_LINE sumLatter -= A [ i ] NEW_LINE diff = min ( diff , abs ( sumFormer - sumLatter ) ) NEW_LINE DEDENT return diff NEW_LINE DEDENT def probC_v1 ( ) : NEW_LINE INDENT N = getInt ( ) NEW_LINE A = getIntList ( ) NEW_LINE dmp ( ( N , A ) ) NEW_LINE diff = 10 ** ( 9 + 6 ) NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT diff = min ( diff , abs ( sum ( A [ : i ] ) - sum ( A [ i : ] ) ) ) NEW_LINE DEDENT return diff NEW_LINE DEDENT debug = False NEW_LINE ans = probC ( ) NEW_LINE print ( ans ) NEW_LINE NEW_LINE
T239
import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . StringTokenizer ; public class Main { public static void main ( String args [ ] ) { ConsoleScanner cin = new ConsoleScanner ( ) ; PrintWriter cout = new PrintWriter ( System . out ) ; solve ( cin , cout ) ; cout . flush ( ) ; } static long now ( ) { return System . currentTimeMillis ( ) ; } static void trace ( Object ... objects ) { assert null != System . out . format ( " trace : % s \n " , Arrays . deepToString ( objects ) ) ; } private static void solve ( ConsoleScanner cin , PrintWriter cout ) { int n = cin . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < a . length ; i ++ ) a [ i ] = cin . nextInt ( ) ; long start = now ( ) ; long ans = solve ( n , a ) ; cout . println ( ans ) ; trace ( " elapsed " , now ( ) - start ) ; } private static long solve ( int n , int [ ] a ) { long total = Arrays . stream ( a ) . mapToLong ( x -> x ) . sum ( ) ; long ans = Long . MAX_VALUE ; long s = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { s += a [ i ] ; ans = Math . min ( ans , Math . abs ( total - 2 * s ) ) ; } return ans ; } static class ConsoleScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ; String next ( ) { try { while ( ! st . hasMoreElements ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return st . nextToken ( ) ; } catch ( IOException e ) { throw new AssertionError ( e ) ; } } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } }
from itertools import accumulate NEW_LINE N = int ( input ( ) ) NEW_LINE card = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE acc = list ( accumulate ( card ) ) NEW_LINE s = acc [ - 1 ] NEW_LINE ans = float ( ' inf ' ) NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT t = acc [ i ] NEW_LINE a = s - t NEW_LINE ans = min ( ans , abs ( t - a ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T240
import java . util . * ; public class Main { private static long solve ( Scanner scanner ) { int N = Integer . parseInt ( scanner . nextLine ( ) ) ; long [ ] a = lineToNums ( scanner . nextLine ( ) ) ; long sumAll = Arrays . stream ( a ) . sum ( ) ; long [ ] xSum = new long [ N ] ; long [ ] ySum = new long [ N ] ; xSum [ 0 ] = a [ 0 ] ; ySum [ 0 ] = sumAll - xSum [ 0 ] ; long ret = Math . abs ( xSum [ 0 ] - ySum [ 0 ] ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { xSum [ i ] = xSum [ i - 1 ] + a [ i ] ; ySum [ i ] = sumAll - xSum [ i ] ; ret = Math . min ( ret , Math . abs ( xSum [ i ] - ySum [ i ] ) ) ; } return ret ; } private static final String ex1 = "6 \n " + "1 ▁ 2 ▁ 3 ▁ 4 ▁ 5 ▁ 6" ; private static final String ex2 = "2 \n " + "10 ▁ - 10" ; public static void main ( String [ ] args ) { System . out . println ( solve ( new Scanner ( System . in ) ) ) ; } private static long [ ] lineToNums ( String line ) { String [ ] strNums = line . split ( " ▁ " ) ; long [ ] ret = new long [ strNums . length ] ; for ( int i = 0 ; i < strNums . length ; i ++ ) { ret [ i ] = Long . parseLong ( strNums [ i ] ) ; } return ret ; } }
def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE import numpy as np NEW_LINE ans = float ( ' inf ' ) NEW_LINE N = int ( input ( ) ) NEW_LINE a = np . cumsum ( np . array ( inpl ( ) ) ) NEW_LINE suma = a [ - 1 ] NEW_LINE a = np . delete ( a , - 1 ) NEW_LINE for i in a : NEW_LINE INDENT ans = min ( ans , abs ( suma - 2 * i ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T241
import java . util . * ; public class Main { private static long solve ( Scanner scanner ) { int N = Integer . parseInt ( scanner . nextLine ( ) ) ; long [ ] a = lineToNums ( scanner . nextLine ( ) ) ; long sumAll = Arrays . stream ( a ) . sum ( ) ; long [ ] xSum = new long [ N ] ; long [ ] ySum = new long [ N ] ; xSum [ 0 ] = a [ 0 ] ; ySum [ 0 ] = sumAll - xSum [ 0 ] ; long ret = Math . abs ( xSum [ 0 ] - ySum [ 0 ] ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { xSum [ i ] = xSum [ i - 1 ] + a [ i ] ; ySum [ i ] = sumAll - xSum [ i ] ; ret = Math . min ( ret , Math . abs ( xSum [ i ] - ySum [ i ] ) ) ; } return ret ; } private static final String ex1 = "6 \n " + "1 ▁ 2 ▁ 3 ▁ 4 ▁ 5 ▁ 6" ; private static final String ex2 = "2 \n " + "10 ▁ - 10" ; public static void main ( String [ ] args ) { System . out . println ( solve ( new Scanner ( System . in ) ) ) ; } private static long [ ] lineToNums ( String line ) { String [ ] strNums = line . split ( " ▁ " ) ; long [ ] ret = new long [ strNums . length ] ; for ( int i = 0 ; i < strNums . length ; i ++ ) { ret [ i ] = Long . parseLong ( strNums [ i ] ) ; } return ret ; } }
n = int ( input ( ) ) ; a = list ( map ( int , input ( ) . split ( ) ) ) ; b = [ 0 ] NEW_LINE for i in a : b . append ( b [ - 1 ] + i ) NEW_LINE b = b [ 1 : ] ; s = b [ - 1 ] ; mi = abs ( b [ 0 ] - ( b [ - 1 ] - b [ 0 ] ) ) NEW_LINE for i in range ( n - 1 ) : mi = min ( abs ( b [ i ] - ( b [ - 1 ] - b [ i ] ) ) , mi ) NEW_LINE print ( mi ) NEW_LINE
T242
import java . util . * ; public class Main { private static long solve ( Scanner scanner ) { int N = Integer . parseInt ( scanner . nextLine ( ) ) ; long [ ] a = lineToNums ( scanner . nextLine ( ) ) ; long sumAll = Arrays . stream ( a ) . sum ( ) ; long [ ] xSum = new long [ N ] ; long [ ] ySum = new long [ N ] ; xSum [ 0 ] = a [ 0 ] ; ySum [ 0 ] = sumAll - xSum [ 0 ] ; long ret = Math . abs ( xSum [ 0 ] - ySum [ 0 ] ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { xSum [ i ] = xSum [ i - 1 ] + a [ i ] ; ySum [ i ] = sumAll - xSum [ i ] ; ret = Math . min ( ret , Math . abs ( xSum [ i ] - ySum [ i ] ) ) ; } return ret ; } private static final String ex1 = "6 \n " + "1 ▁ 2 ▁ 3 ▁ 4 ▁ 5 ▁ 6" ; private static final String ex2 = "2 \n " + "10 ▁ - 10" ; public static void main ( String [ ] args ) { System . out . println ( solve ( new Scanner ( System . in ) ) ) ; } private static long [ ] lineToNums ( String line ) { String [ ] strNums = line . split ( " ▁ " ) ; long [ ] ret = new long [ strNums . length ] ; for ( int i = 0 ; i < strNums . length ; i ++ ) { ret [ i ] = Long . parseLong ( strNums [ i ] ) ; } return ret ; } }
from numpy import * ; n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) ; print ( min ( abs ( cumsum ( a [ : : - 1 ] ) [ : : - 1 ] - cumsum ( [ 0 ] + a [ : - 1 ] ) ) [ 1 : ] ) ) NEW_LINE
T243
import java . util . * ; public class Main { private static long solve ( Scanner scanner ) { int N = Integer . parseInt ( scanner . nextLine ( ) ) ; long [ ] a = lineToNums ( scanner . nextLine ( ) ) ; long sumAll = Arrays . stream ( a ) . sum ( ) ; long [ ] xSum = new long [ N ] ; long [ ] ySum = new long [ N ] ; xSum [ 0 ] = a [ 0 ] ; ySum [ 0 ] = sumAll - xSum [ 0 ] ; long ret = Math . abs ( xSum [ 0 ] - ySum [ 0 ] ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { xSum [ i ] = xSum [ i - 1 ] + a [ i ] ; ySum [ i ] = sumAll - xSum [ i ] ; ret = Math . min ( ret , Math . abs ( xSum [ i ] - ySum [ i ] ) ) ; } return ret ; } private static final String ex1 = "6 \n " + "1 ▁ 2 ▁ 3 ▁ 4 ▁ 5 ▁ 6" ; private static final String ex2 = "2 \n " + "10 ▁ - 10" ; public static void main ( String [ ] args ) { System . out . println ( solve ( new Scanner ( System . in ) ) ) ; } private static long [ ] lineToNums ( String line ) { String [ ] strNums = line . split ( " ▁ " ) ; long [ ] ret = new long [ strNums . length ] ; for ( int i = 0 ; i < strNums . length ; i ++ ) { ret [ i ] = Long . parseLong ( strNums [ i ] ) ; } return ret ; } }
def getInt ( ) : return int ( input ( ) ) NEW_LINE def getIntList ( ) : return [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE def zeros ( n ) : return [ 0 ] * n NEW_LINE def getIntLines ( n ) : return [ int ( input ( ) ) for i in range ( n ) ] NEW_LINE def getIntMat ( n ) : NEW_LINE INDENT mat = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT mat . append ( getIntList ( ) ) NEW_LINE DEDENT return mat NEW_LINE DEDENT def zeros2 ( n , m ) : return [ zeros ( m ) ] * n NEW_LINE ALPHABET = [ chr ( i + ord ( ' a ' ) ) for i in range ( 26 ) ] NEW_LINE DIGIT = [ chr ( i + ord ( '0' ) ) for i in range ( 10 ) ] NEW_LINE N1097 = 10 ** 9 + 7 NEW_LINE def dmp ( x , cmt = ' ' ) : NEW_LINE INDENT global debug NEW_LINE if debug : NEW_LINE INDENT if cmt != ' ' : NEW_LINE INDENT print ( cmt , ' : ▁ ▁ ' , end = ' ' ) NEW_LINE DEDENT print ( x ) NEW_LINE DEDENT return x NEW_LINE DEDENT def probC ( ) : NEW_LINE INDENT N = getInt ( ) NEW_LINE A = getIntList ( ) NEW_LINE dmp ( ( N , A ) ) NEW_LINE sumFormer = A [ 0 ] NEW_LINE sumLatter = sum ( A [ 1 : ] ) NEW_LINE diff = abs ( sumFormer - sumLatter ) NEW_LINE dmp ( diff , ' init ' ) NEW_LINE for i in range ( 1 , N - 1 ) : NEW_LINE INDENT sumFormer += A [ i ] NEW_LINE sumLatter -= A [ i ] NEW_LINE diff = min ( diff , abs ( sumFormer - sumLatter ) ) NEW_LINE DEDENT return diff NEW_LINE DEDENT def probC_v1 ( ) : NEW_LINE INDENT N = getInt ( ) NEW_LINE A = getIntList ( ) NEW_LINE dmp ( ( N , A ) ) NEW_LINE diff = 10 ** ( 9 + 6 ) NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT diff = min ( diff , abs ( sum ( A [ : i ] ) - sum ( A [ i : ] ) ) ) NEW_LINE DEDENT return diff NEW_LINE DEDENT debug = False NEW_LINE ans = probC ( ) NEW_LINE print ( ans ) NEW_LINE NEW_LINE
T244
import java . util . * ; public class Main { private static long solve ( Scanner scanner ) { int N = Integer . parseInt ( scanner . nextLine ( ) ) ; long [ ] a = lineToNums ( scanner . nextLine ( ) ) ; long sumAll = Arrays . stream ( a ) . sum ( ) ; long [ ] xSum = new long [ N ] ; long [ ] ySum = new long [ N ] ; xSum [ 0 ] = a [ 0 ] ; ySum [ 0 ] = sumAll - xSum [ 0 ] ; long ret = Math . abs ( xSum [ 0 ] - ySum [ 0 ] ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { xSum [ i ] = xSum [ i - 1 ] + a [ i ] ; ySum [ i ] = sumAll - xSum [ i ] ; ret = Math . min ( ret , Math . abs ( xSum [ i ] - ySum [ i ] ) ) ; } return ret ; } private static final String ex1 = "6 \n " + "1 ▁ 2 ▁ 3 ▁ 4 ▁ 5 ▁ 6" ; private static final String ex2 = "2 \n " + "10 ▁ - 10" ; public static void main ( String [ ] args ) { System . out . println ( solve ( new Scanner ( System . in ) ) ) ; } private static long [ ] lineToNums ( String line ) { String [ ] strNums = line . split ( " ▁ " ) ; long [ ] ret = new long [ strNums . length ] ; for ( int i = 0 ; i < strNums . length ; i ++ ) { ret [ i ] = Long . parseLong ( strNums [ i ] ) ; } return ret ; } }
from itertools import accumulate NEW_LINE N = int ( input ( ) ) NEW_LINE card = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE acc = list ( accumulate ( card ) ) NEW_LINE s = acc [ - 1 ] NEW_LINE ans = float ( ' inf ' ) NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT t = acc [ i ] NEW_LINE a = s - t NEW_LINE ans = min ( ans , abs ( t - a ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T245
import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader stdReader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String c = stdReader . readLine ( ) ; String vals = stdReader . readLine ( ) ; long [ ] ls = new long [ Integer . valueOf ( c ) ] ; String [ ] ss = vals . split ( " ▁ " ) ; long total = 0 ; long [ ] sunu = new long [ Integer . valueOf ( c ) ] ; for ( int i = 0 ; i < ls . length ; i ++ ) { long v = Long . valueOf ( ss [ i ] ) ; ls [ i ] = v ; total += v ; sunu [ i ] = total ; } long min = 0 ; for ( int i = 0 ; i < ls . length - 1 ; i ++ ) { long arai = total - sunu [ i ] ; long current = Math . abs ( arai - sunu [ i ] ) ; if ( i == 0 ) { min = current ; } min = Math . min ( min , current ) ; } System . out . println ( min ) ; } }
def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE import numpy as np NEW_LINE ans = float ( ' inf ' ) NEW_LINE N = int ( input ( ) ) NEW_LINE a = np . cumsum ( np . array ( inpl ( ) ) ) NEW_LINE suma = a [ - 1 ] NEW_LINE a = np . delete ( a , - 1 ) NEW_LINE for i in a : NEW_LINE INDENT ans = min ( ans , abs ( suma - 2 * i ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T246
import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader stdReader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String c = stdReader . readLine ( ) ; String vals = stdReader . readLine ( ) ; long [ ] ls = new long [ Integer . valueOf ( c ) ] ; String [ ] ss = vals . split ( " ▁ " ) ; long total = 0 ; long [ ] sunu = new long [ Integer . valueOf ( c ) ] ; for ( int i = 0 ; i < ls . length ; i ++ ) { long v = Long . valueOf ( ss [ i ] ) ; ls [ i ] = v ; total += v ; sunu [ i ] = total ; } long min = 0 ; for ( int i = 0 ; i < ls . length - 1 ; i ++ ) { long arai = total - sunu [ i ] ; long current = Math . abs ( arai - sunu [ i ] ) ; if ( i == 0 ) { min = current ; } min = Math . min ( min , current ) ; } System . out . println ( min ) ; } }
n = int ( input ( ) ) ; a = list ( map ( int , input ( ) . split ( ) ) ) ; b = [ 0 ] NEW_LINE for i in a : b . append ( b [ - 1 ] + i ) NEW_LINE b = b [ 1 : ] ; s = b [ - 1 ] ; mi = abs ( b [ 0 ] - ( b [ - 1 ] - b [ 0 ] ) ) NEW_LINE for i in range ( n - 1 ) : mi = min ( abs ( b [ i ] - ( b [ - 1 ] - b [ i ] ) ) , mi ) NEW_LINE print ( mi ) NEW_LINE
T247
import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader stdReader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String c = stdReader . readLine ( ) ; String vals = stdReader . readLine ( ) ; long [ ] ls = new long [ Integer . valueOf ( c ) ] ; String [ ] ss = vals . split ( " ▁ " ) ; long total = 0 ; long [ ] sunu = new long [ Integer . valueOf ( c ) ] ; for ( int i = 0 ; i < ls . length ; i ++ ) { long v = Long . valueOf ( ss [ i ] ) ; ls [ i ] = v ; total += v ; sunu [ i ] = total ; } long min = 0 ; for ( int i = 0 ; i < ls . length - 1 ; i ++ ) { long arai = total - sunu [ i ] ; long current = Math . abs ( arai - sunu [ i ] ) ; if ( i == 0 ) { min = current ; } min = Math . min ( min , current ) ; } System . out . println ( min ) ; } }
from numpy import * ; n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) ; print ( min ( abs ( cumsum ( a [ : : - 1 ] ) [ : : - 1 ] - cumsum ( [ 0 ] + a [ : - 1 ] ) ) [ 1 : ] ) ) NEW_LINE
T248
import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader stdReader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String c = stdReader . readLine ( ) ; String vals = stdReader . readLine ( ) ; long [ ] ls = new long [ Integer . valueOf ( c ) ] ; String [ ] ss = vals . split ( " ▁ " ) ; long total = 0 ; long [ ] sunu = new long [ Integer . valueOf ( c ) ] ; for ( int i = 0 ; i < ls . length ; i ++ ) { long v = Long . valueOf ( ss [ i ] ) ; ls [ i ] = v ; total += v ; sunu [ i ] = total ; } long min = 0 ; for ( int i = 0 ; i < ls . length - 1 ; i ++ ) { long arai = total - sunu [ i ] ; long current = Math . abs ( arai - sunu [ i ] ) ; if ( i == 0 ) { min = current ; } min = Math . min ( min , current ) ; } System . out . println ( min ) ; } }
def getInt ( ) : return int ( input ( ) ) NEW_LINE def getIntList ( ) : return [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE def zeros ( n ) : return [ 0 ] * n NEW_LINE def getIntLines ( n ) : return [ int ( input ( ) ) for i in range ( n ) ] NEW_LINE def getIntMat ( n ) : NEW_LINE INDENT mat = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT mat . append ( getIntList ( ) ) NEW_LINE DEDENT return mat NEW_LINE DEDENT def zeros2 ( n , m ) : return [ zeros ( m ) ] * n NEW_LINE ALPHABET = [ chr ( i + ord ( ' a ' ) ) for i in range ( 26 ) ] NEW_LINE DIGIT = [ chr ( i + ord ( '0' ) ) for i in range ( 10 ) ] NEW_LINE N1097 = 10 ** 9 + 7 NEW_LINE def dmp ( x , cmt = ' ' ) : NEW_LINE INDENT global debug NEW_LINE if debug : NEW_LINE INDENT if cmt != ' ' : NEW_LINE INDENT print ( cmt , ' : ▁ ▁ ' , end = ' ' ) NEW_LINE DEDENT print ( x ) NEW_LINE DEDENT return x NEW_LINE DEDENT def probC ( ) : NEW_LINE INDENT N = getInt ( ) NEW_LINE A = getIntList ( ) NEW_LINE dmp ( ( N , A ) ) NEW_LINE sumFormer = A [ 0 ] NEW_LINE sumLatter = sum ( A [ 1 : ] ) NEW_LINE diff = abs ( sumFormer - sumLatter ) NEW_LINE dmp ( diff , ' init ' ) NEW_LINE for i in range ( 1 , N - 1 ) : NEW_LINE INDENT sumFormer += A [ i ] NEW_LINE sumLatter -= A [ i ] NEW_LINE diff = min ( diff , abs ( sumFormer - sumLatter ) ) NEW_LINE DEDENT return diff NEW_LINE DEDENT def probC_v1 ( ) : NEW_LINE INDENT N = getInt ( ) NEW_LINE A = getIntList ( ) NEW_LINE dmp ( ( N , A ) ) NEW_LINE diff = 10 ** ( 9 + 6 ) NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT diff = min ( diff , abs ( sum ( A [ : i ] ) - sum ( A [ i : ] ) ) ) NEW_LINE DEDENT return diff NEW_LINE DEDENT debug = False NEW_LINE ans = probC ( ) NEW_LINE print ( ans ) NEW_LINE NEW_LINE
T249
import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader stdReader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String c = stdReader . readLine ( ) ; String vals = stdReader . readLine ( ) ; long [ ] ls = new long [ Integer . valueOf ( c ) ] ; String [ ] ss = vals . split ( " ▁ " ) ; long total = 0 ; long [ ] sunu = new long [ Integer . valueOf ( c ) ] ; for ( int i = 0 ; i < ls . length ; i ++ ) { long v = Long . valueOf ( ss [ i ] ) ; ls [ i ] = v ; total += v ; sunu [ i ] = total ; } long min = 0 ; for ( int i = 0 ; i < ls . length - 1 ; i ++ ) { long arai = total - sunu [ i ] ; long current = Math . abs ( arai - sunu [ i ] ) ; if ( i == 0 ) { min = current ; } min = Math . min ( min , current ) ; } System . out . println ( min ) ; } }
from itertools import accumulate NEW_LINE N = int ( input ( ) ) NEW_LINE card = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE acc = list ( accumulate ( card ) ) NEW_LINE s = acc [ - 1 ] NEW_LINE ans = float ( ' inf ' ) NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT t = acc [ i ] NEW_LINE a = s - t NEW_LINE ans = min ( ans , abs ( t - a ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T250
import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; MyReader in = new MyReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskC solver = new TaskC ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskC { public void solve ( int testNumber , MyReader in , PrintWriter out ) { int N = in . nextInt ( ) ; long [ ] a = new long [ N ] ; long tot = 0 ; long [ ] s = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = in . nextLong ( ) ; tot += a [ i ] ; s [ i ] = tot ; } long d = Long . MAX_VALUE ; for ( int i = 0 ; i < N - 1 ; i ++ ) { d = Math . min ( d , Math . abs ( s [ i ] - ( tot - s [ i ] ) ) ) ; } out . println ( d ) ; } } static class MyReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public MyReader ( 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 ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } }
def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE import numpy as np NEW_LINE ans = float ( ' inf ' ) NEW_LINE N = int ( input ( ) ) NEW_LINE a = np . cumsum ( np . array ( inpl ( ) ) ) NEW_LINE suma = a [ - 1 ] NEW_LINE a = np . delete ( a , - 1 ) NEW_LINE for i in a : NEW_LINE INDENT ans = min ( ans , abs ( suma - 2 * i ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T251
import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; MyReader in = new MyReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskC solver = new TaskC ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskC { public void solve ( int testNumber , MyReader in , PrintWriter out ) { int N = in . nextInt ( ) ; long [ ] a = new long [ N ] ; long tot = 0 ; long [ ] s = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = in . nextLong ( ) ; tot += a [ i ] ; s [ i ] = tot ; } long d = Long . MAX_VALUE ; for ( int i = 0 ; i < N - 1 ; i ++ ) { d = Math . min ( d , Math . abs ( s [ i ] - ( tot - s [ i ] ) ) ) ; } out . println ( d ) ; } } static class MyReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public MyReader ( 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 ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } }
n = int ( input ( ) ) ; a = list ( map ( int , input ( ) . split ( ) ) ) ; b = [ 0 ] NEW_LINE for i in a : b . append ( b [ - 1 ] + i ) NEW_LINE b = b [ 1 : ] ; s = b [ - 1 ] ; mi = abs ( b [ 0 ] - ( b [ - 1 ] - b [ 0 ] ) ) NEW_LINE for i in range ( n - 1 ) : mi = min ( abs ( b [ i ] - ( b [ - 1 ] - b [ i ] ) ) , mi ) NEW_LINE print ( mi ) NEW_LINE
T252
import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; MyReader in = new MyReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskC solver = new TaskC ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskC { public void solve ( int testNumber , MyReader in , PrintWriter out ) { int N = in . nextInt ( ) ; long [ ] a = new long [ N ] ; long tot = 0 ; long [ ] s = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = in . nextLong ( ) ; tot += a [ i ] ; s [ i ] = tot ; } long d = Long . MAX_VALUE ; for ( int i = 0 ; i < N - 1 ; i ++ ) { d = Math . min ( d , Math . abs ( s [ i ] - ( tot - s [ i ] ) ) ) ; } out . println ( d ) ; } } static class MyReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public MyReader ( 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 ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } }
from numpy import * ; n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) ; print ( min ( abs ( cumsum ( a [ : : - 1 ] ) [ : : - 1 ] - cumsum ( [ 0 ] + a [ : - 1 ] ) ) [ 1 : ] ) ) NEW_LINE
T253
import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; MyReader in = new MyReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskC solver = new TaskC ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskC { public void solve ( int testNumber , MyReader in , PrintWriter out ) { int N = in . nextInt ( ) ; long [ ] a = new long [ N ] ; long tot = 0 ; long [ ] s = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = in . nextLong ( ) ; tot += a [ i ] ; s [ i ] = tot ; } long d = Long . MAX_VALUE ; for ( int i = 0 ; i < N - 1 ; i ++ ) { d = Math . min ( d , Math . abs ( s [ i ] - ( tot - s [ i ] ) ) ) ; } out . println ( d ) ; } } static class MyReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public MyReader ( 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 ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } }
def getInt ( ) : return int ( input ( ) ) NEW_LINE def getIntList ( ) : return [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE def zeros ( n ) : return [ 0 ] * n NEW_LINE def getIntLines ( n ) : return [ int ( input ( ) ) for i in range ( n ) ] NEW_LINE def getIntMat ( n ) : NEW_LINE INDENT mat = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT mat . append ( getIntList ( ) ) NEW_LINE DEDENT return mat NEW_LINE DEDENT def zeros2 ( n , m ) : return [ zeros ( m ) ] * n NEW_LINE ALPHABET = [ chr ( i + ord ( ' a ' ) ) for i in range ( 26 ) ] NEW_LINE DIGIT = [ chr ( i + ord ( '0' ) ) for i in range ( 10 ) ] NEW_LINE N1097 = 10 ** 9 + 7 NEW_LINE def dmp ( x , cmt = ' ' ) : NEW_LINE INDENT global debug NEW_LINE if debug : NEW_LINE INDENT if cmt != ' ' : NEW_LINE INDENT print ( cmt , ' : ▁ ▁ ' , end = ' ' ) NEW_LINE DEDENT print ( x ) NEW_LINE DEDENT return x NEW_LINE DEDENT def probC ( ) : NEW_LINE INDENT N = getInt ( ) NEW_LINE A = getIntList ( ) NEW_LINE dmp ( ( N , A ) ) NEW_LINE sumFormer = A [ 0 ] NEW_LINE sumLatter = sum ( A [ 1 : ] ) NEW_LINE diff = abs ( sumFormer - sumLatter ) NEW_LINE dmp ( diff , ' init ' ) NEW_LINE for i in range ( 1 , N - 1 ) : NEW_LINE INDENT sumFormer += A [ i ] NEW_LINE sumLatter -= A [ i ] NEW_LINE diff = min ( diff , abs ( sumFormer - sumLatter ) ) NEW_LINE DEDENT return diff NEW_LINE DEDENT def probC_v1 ( ) : NEW_LINE INDENT N = getInt ( ) NEW_LINE A = getIntList ( ) NEW_LINE dmp ( ( N , A ) ) NEW_LINE diff = 10 ** ( 9 + 6 ) NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT diff = min ( diff , abs ( sum ( A [ : i ] ) - sum ( A [ i : ] ) ) ) NEW_LINE DEDENT return diff NEW_LINE DEDENT debug = False NEW_LINE ans = probC ( ) NEW_LINE print ( ans ) NEW_LINE NEW_LINE
T254
import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; MyReader in = new MyReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskC solver = new TaskC ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskC { public void solve ( int testNumber , MyReader in , PrintWriter out ) { int N = in . nextInt ( ) ; long [ ] a = new long [ N ] ; long tot = 0 ; long [ ] s = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = in . nextLong ( ) ; tot += a [ i ] ; s [ i ] = tot ; } long d = Long . MAX_VALUE ; for ( int i = 0 ; i < N - 1 ; i ++ ) { d = Math . min ( d , Math . abs ( s [ i ] - ( tot - s [ i ] ) ) ) ; } out . println ( d ) ; } } static class MyReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public MyReader ( 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 ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } }
from itertools import accumulate NEW_LINE N = int ( input ( ) ) NEW_LINE card = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE acc = list ( accumulate ( card ) ) NEW_LINE s = acc [ - 1 ] NEW_LINE ans = float ( ' inf ' ) NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT t = acc [ i ] NEW_LINE a = s - t NEW_LINE ans = min ( ans , abs ( t - a ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T255
import java . util . Scanner ; public class Main { private static long x = 0 ; private static long y = 0 ; private static int N ; private static int a [ ] ; private static long ans ; public static void input ( ) { Scanner scan = new Scanner ( System . in ) ; N = scan . nextInt ( ) ; a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = scan . nextInt ( ) ; } } public static void main ( String args [ ] ) { input ( ) ; x = a [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { y += a [ i ] ; } ans = Math . abs ( x - y ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { x += a [ i ] ; y -= a [ i ] ; ans = Math . min ( Math . abs ( x - y ) , ans ) ; } System . out . println ( ans ) ; } }
def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE import numpy as np NEW_LINE ans = float ( ' inf ' ) NEW_LINE N = int ( input ( ) ) NEW_LINE a = np . cumsum ( np . array ( inpl ( ) ) ) NEW_LINE suma = a [ - 1 ] NEW_LINE a = np . delete ( a , - 1 ) NEW_LINE for i in a : NEW_LINE INDENT ans = min ( ans , abs ( suma - 2 * i ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T256
import java . util . Scanner ; public class Main { private static long x = 0 ; private static long y = 0 ; private static int N ; private static int a [ ] ; private static long ans ; public static void input ( ) { Scanner scan = new Scanner ( System . in ) ; N = scan . nextInt ( ) ; a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = scan . nextInt ( ) ; } } public static void main ( String args [ ] ) { input ( ) ; x = a [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { y += a [ i ] ; } ans = Math . abs ( x - y ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { x += a [ i ] ; y -= a [ i ] ; ans = Math . min ( Math . abs ( x - y ) , ans ) ; } System . out . println ( ans ) ; } }
n = int ( input ( ) ) ; a = list ( map ( int , input ( ) . split ( ) ) ) ; b = [ 0 ] NEW_LINE for i in a : b . append ( b [ - 1 ] + i ) NEW_LINE b = b [ 1 : ] ; s = b [ - 1 ] ; mi = abs ( b [ 0 ] - ( b [ - 1 ] - b [ 0 ] ) ) NEW_LINE for i in range ( n - 1 ) : mi = min ( abs ( b [ i ] - ( b [ - 1 ] - b [ i ] ) ) , mi ) NEW_LINE print ( mi ) NEW_LINE
T257
import java . util . Scanner ; public class Main { private static long x = 0 ; private static long y = 0 ; private static int N ; private static int a [ ] ; private static long ans ; public static void input ( ) { Scanner scan = new Scanner ( System . in ) ; N = scan . nextInt ( ) ; a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = scan . nextInt ( ) ; } } public static void main ( String args [ ] ) { input ( ) ; x = a [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { y += a [ i ] ; } ans = Math . abs ( x - y ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { x += a [ i ] ; y -= a [ i ] ; ans = Math . min ( Math . abs ( x - y ) , ans ) ; } System . out . println ( ans ) ; } }
from numpy import * ; n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) ; print ( min ( abs ( cumsum ( a [ : : - 1 ] ) [ : : - 1 ] - cumsum ( [ 0 ] + a [ : - 1 ] ) ) [ 1 : ] ) ) NEW_LINE
T258
import java . util . Scanner ; public class Main { private static long x = 0 ; private static long y = 0 ; private static int N ; private static int a [ ] ; private static long ans ; public static void input ( ) { Scanner scan = new Scanner ( System . in ) ; N = scan . nextInt ( ) ; a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = scan . nextInt ( ) ; } } public static void main ( String args [ ] ) { input ( ) ; x = a [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { y += a [ i ] ; } ans = Math . abs ( x - y ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { x += a [ i ] ; y -= a [ i ] ; ans = Math . min ( Math . abs ( x - y ) , ans ) ; } System . out . println ( ans ) ; } }
def getInt ( ) : return int ( input ( ) ) NEW_LINE def getIntList ( ) : return [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE def zeros ( n ) : return [ 0 ] * n NEW_LINE def getIntLines ( n ) : return [ int ( input ( ) ) for i in range ( n ) ] NEW_LINE def getIntMat ( n ) : NEW_LINE INDENT mat = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT mat . append ( getIntList ( ) ) NEW_LINE DEDENT return mat NEW_LINE DEDENT def zeros2 ( n , m ) : return [ zeros ( m ) ] * n NEW_LINE ALPHABET = [ chr ( i + ord ( ' a ' ) ) for i in range ( 26 ) ] NEW_LINE DIGIT = [ chr ( i + ord ( '0' ) ) for i in range ( 10 ) ] NEW_LINE N1097 = 10 ** 9 + 7 NEW_LINE def dmp ( x , cmt = ' ' ) : NEW_LINE INDENT global debug NEW_LINE if debug : NEW_LINE INDENT if cmt != ' ' : NEW_LINE INDENT print ( cmt , ' : ▁ ▁ ' , end = ' ' ) NEW_LINE DEDENT print ( x ) NEW_LINE DEDENT return x NEW_LINE DEDENT def probC ( ) : NEW_LINE INDENT N = getInt ( ) NEW_LINE A = getIntList ( ) NEW_LINE dmp ( ( N , A ) ) NEW_LINE sumFormer = A [ 0 ] NEW_LINE sumLatter = sum ( A [ 1 : ] ) NEW_LINE diff = abs ( sumFormer - sumLatter ) NEW_LINE dmp ( diff , ' init ' ) NEW_LINE for i in range ( 1 , N - 1 ) : NEW_LINE INDENT sumFormer += A [ i ] NEW_LINE sumLatter -= A [ i ] NEW_LINE diff = min ( diff , abs ( sumFormer - sumLatter ) ) NEW_LINE DEDENT return diff NEW_LINE DEDENT def probC_v1 ( ) : NEW_LINE INDENT N = getInt ( ) NEW_LINE A = getIntList ( ) NEW_LINE dmp ( ( N , A ) ) NEW_LINE diff = 10 ** ( 9 + 6 ) NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT diff = min ( diff , abs ( sum ( A [ : i ] ) - sum ( A [ i : ] ) ) ) NEW_LINE DEDENT return diff NEW_LINE DEDENT debug = False NEW_LINE ans = probC ( ) NEW_LINE print ( ans ) NEW_LINE NEW_LINE
T259
import java . util . Scanner ; public class Main { private static long x = 0 ; private static long y = 0 ; private static int N ; private static int a [ ] ; private static long ans ; public static void input ( ) { Scanner scan = new Scanner ( System . in ) ; N = scan . nextInt ( ) ; a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = scan . nextInt ( ) ; } } public static void main ( String args [ ] ) { input ( ) ; x = a [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { y += a [ i ] ; } ans = Math . abs ( x - y ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { x += a [ i ] ; y -= a [ i ] ; ans = Math . min ( Math . abs ( x - y ) , ans ) ; } System . out . println ( ans ) ; } }
from itertools import accumulate NEW_LINE N = int ( input ( ) ) NEW_LINE card = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE acc = list ( accumulate ( card ) ) NEW_LINE s = acc [ - 1 ] NEW_LINE ans = float ( ' inf ' ) NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT t = acc [ i ] NEW_LINE a = s - t NEW_LINE ans = min ( ans , abs ( t - a ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T260
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int weight = 0 ; int output = 0 ; for ( int i = 0 ; i < n ; i ++ ) { weight += sc . nextInt ( ) ; if ( weight >= s && weight <= t ) { output ++ ; } } System . out . println ( output ) ; } }
ans = 0 NEW_LINE n , s , t = map ( int , input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT w += int ( input ( ) ) NEW_LINE DEDENT if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT print ( ans ) NEW_LINE
T261
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int weight = 0 ; int output = 0 ; for ( int i = 0 ; i < n ; i ++ ) { weight += sc . nextInt ( ) ; if ( weight >= s && weight <= t ) { output ++ ; } } System . out . println ( output ) ; } }
import sys NEW_LINE n , s , t = [ int ( i ) for i in sys . stdin . readline ( ) . rstrip ( ) . split ( ) ] NEW_LINE w = 0 NEW_LINE ans = 0 NEW_LINE for _ in range ( n ) : NEW_LINE INDENT a = int ( sys . stdin . readline ( ) . rstrip ( ) ) NEW_LINE w += a NEW_LINE if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T262
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int weight = 0 ; int output = 0 ; for ( int i = 0 ; i < n ; i ++ ) { weight += sc . nextInt ( ) ; if ( weight >= s && weight <= t ) { output ++ ; } } System . out . println ( output ) ; } }
def solve ( ) : NEW_LINE INDENT n , s , t = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE if s <= w and w <= t : NEW_LINE INDENT ans = 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = 0 NEW_LINE DEDENT for i in range ( n - 1 ) : NEW_LINE INDENT a = int ( input ( ) ) NEW_LINE w += a NEW_LINE if s <= w and w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT else : NEW_LINE INDENT continue NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT solve ( ) NEW_LINE
T263
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int weight = 0 ; int output = 0 ; for ( int i = 0 ; i < n ; i ++ ) { weight += sc . nextInt ( ) ; if ( weight >= s && weight <= t ) { output ++ ; } } System . out . println ( output ) ; } }
N , S , T = map ( int , input ( ) . split ( ) ) NEW_LINE W = int ( input ( ) ) NEW_LINE if S <= W <= T : NEW_LINE INDENT daycount = 1 NEW_LINE DEDENT else : NEW_LINE INDENT daycount = 0 NEW_LINE DEDENT for i in range ( N - 1 ) : NEW_LINE INDENT A = int ( input ( ) ) NEW_LINE W += A NEW_LINE if S <= W <= T : NEW_LINE INDENT daycount += 1 NEW_LINE DEDENT DEDENT print ( daycount ) NEW_LINE
T264
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int weight = 0 ; int output = 0 ; for ( int i = 0 ; i < n ; i ++ ) { weight += sc . nextInt ( ) ; if ( weight >= s && weight <= t ) { output ++ ; } } System . out . println ( output ) ; } }
n , s , t = map ( int , input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE a_array = [ ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT a_array . append ( int ( input ( ) ) ) NEW_LINE DEDENT cnt = 1 if s <= w <= t else 0 NEW_LINE for a in a_array : NEW_LINE INDENT w += a NEW_LINE if s <= w <= t : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT print ( cnt ) NEW_LINE
T265
import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { int n = nextInt ( ) , s = nextInt ( ) , t = nextInt ( ) ; int w = nextInt ( ) ; int ans = 0 ; if ( s <= w && w <= t ) { ans ++ ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { w += nextInt ( ) ; if ( s <= w && w <= t ) { ans ++ ; } } out . println ( ans ) ; } }
ans = 0 NEW_LINE n , s , t = map ( int , input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT w += int ( input ( ) ) NEW_LINE DEDENT if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT print ( ans ) NEW_LINE
T266
import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { int n = nextInt ( ) , s = nextInt ( ) , t = nextInt ( ) ; int w = nextInt ( ) ; int ans = 0 ; if ( s <= w && w <= t ) { ans ++ ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { w += nextInt ( ) ; if ( s <= w && w <= t ) { ans ++ ; } } out . println ( ans ) ; } }
import sys NEW_LINE n , s , t = [ int ( i ) for i in sys . stdin . readline ( ) . rstrip ( ) . split ( ) ] NEW_LINE w = 0 NEW_LINE ans = 0 NEW_LINE for _ in range ( n ) : NEW_LINE INDENT a = int ( sys . stdin . readline ( ) . rstrip ( ) ) NEW_LINE w += a NEW_LINE if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T267
import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { int n = nextInt ( ) , s = nextInt ( ) , t = nextInt ( ) ; int w = nextInt ( ) ; int ans = 0 ; if ( s <= w && w <= t ) { ans ++ ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { w += nextInt ( ) ; if ( s <= w && w <= t ) { ans ++ ; } } out . println ( ans ) ; } }
def solve ( ) : NEW_LINE INDENT n , s , t = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE if s <= w and w <= t : NEW_LINE INDENT ans = 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = 0 NEW_LINE DEDENT for i in range ( n - 1 ) : NEW_LINE INDENT a = int ( input ( ) ) NEW_LINE w += a NEW_LINE if s <= w and w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT else : NEW_LINE INDENT continue NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT solve ( ) NEW_LINE
T268
import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { int n = nextInt ( ) , s = nextInt ( ) , t = nextInt ( ) ; int w = nextInt ( ) ; int ans = 0 ; if ( s <= w && w <= t ) { ans ++ ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { w += nextInt ( ) ; if ( s <= w && w <= t ) { ans ++ ; } } out . println ( ans ) ; } }
N , S , T = map ( int , input ( ) . split ( ) ) NEW_LINE W = int ( input ( ) ) NEW_LINE if S <= W <= T : NEW_LINE INDENT daycount = 1 NEW_LINE DEDENT else : NEW_LINE INDENT daycount = 0 NEW_LINE DEDENT for i in range ( N - 1 ) : NEW_LINE INDENT A = int ( input ( ) ) NEW_LINE W += A NEW_LINE if S <= W <= T : NEW_LINE INDENT daycount += 1 NEW_LINE DEDENT DEDENT print ( daycount ) NEW_LINE
T269
import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { int n = nextInt ( ) , s = nextInt ( ) , t = nextInt ( ) ; int w = nextInt ( ) ; int ans = 0 ; if ( s <= w && w <= t ) { ans ++ ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { w += nextInt ( ) ; if ( s <= w && w <= t ) { ans ++ ; } } out . println ( ans ) ; } }
n , s , t = map ( int , input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE a_array = [ ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT a_array . append ( int ( input ( ) ) ) NEW_LINE DEDENT cnt = 1 if s <= w <= t else 0 NEW_LINE for a in a_array : NEW_LINE INDENT w += a NEW_LINE if s <= w <= t : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT print ( cnt ) NEW_LINE
T270
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 N = in . nextInt ( ) ; int S = in . nextInt ( ) ; int T = in . nextInt ( ) ; int W = in . nextInt ( ) ; int count = 0 ; if ( S <= W && W <= T ) { count ++ ; } for ( int i = 1 ; i < N ; i ++ ) { W += in . nextInt ( ) ; if ( S <= W && W <= T ) { count ++ ; } } out . println ( count ) ; } } 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 ( ) ) ; } } }
ans = 0 NEW_LINE n , s , t = map ( int , input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT w += int ( input ( ) ) NEW_LINE DEDENT if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT print ( ans ) NEW_LINE
T271
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 N = in . nextInt ( ) ; int S = in . nextInt ( ) ; int T = in . nextInt ( ) ; int W = in . nextInt ( ) ; int count = 0 ; if ( S <= W && W <= T ) { count ++ ; } for ( int i = 1 ; i < N ; i ++ ) { W += in . nextInt ( ) ; if ( S <= W && W <= T ) { count ++ ; } } out . println ( count ) ; } } 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 sys NEW_LINE n , s , t = [ int ( i ) for i in sys . stdin . readline ( ) . rstrip ( ) . split ( ) ] NEW_LINE w = 0 NEW_LINE ans = 0 NEW_LINE for _ in range ( n ) : NEW_LINE INDENT a = int ( sys . stdin . readline ( ) . rstrip ( ) ) NEW_LINE w += a NEW_LINE if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T272
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 N = in . nextInt ( ) ; int S = in . nextInt ( ) ; int T = in . nextInt ( ) ; int W = in . nextInt ( ) ; int count = 0 ; if ( S <= W && W <= T ) { count ++ ; } for ( int i = 1 ; i < N ; i ++ ) { W += in . nextInt ( ) ; if ( S <= W && W <= T ) { count ++ ; } } out . println ( count ) ; } } 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 ( ) ) ; } } }
def solve ( ) : NEW_LINE INDENT n , s , t = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE if s <= w and w <= t : NEW_LINE INDENT ans = 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = 0 NEW_LINE DEDENT for i in range ( n - 1 ) : NEW_LINE INDENT a = int ( input ( ) ) NEW_LINE w += a NEW_LINE if s <= w and w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT else : NEW_LINE INDENT continue NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT solve ( ) NEW_LINE
T273
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 N = in . nextInt ( ) ; int S = in . nextInt ( ) ; int T = in . nextInt ( ) ; int W = in . nextInt ( ) ; int count = 0 ; if ( S <= W && W <= T ) { count ++ ; } for ( int i = 1 ; i < N ; i ++ ) { W += in . nextInt ( ) ; if ( S <= W && W <= T ) { count ++ ; } } out . println ( count ) ; } } 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 ( ) ) ; } } }
N , S , T = map ( int , input ( ) . split ( ) ) NEW_LINE W = int ( input ( ) ) NEW_LINE if S <= W <= T : NEW_LINE INDENT daycount = 1 NEW_LINE DEDENT else : NEW_LINE INDENT daycount = 0 NEW_LINE DEDENT for i in range ( N - 1 ) : NEW_LINE INDENT A = int ( input ( ) ) NEW_LINE W += A NEW_LINE if S <= W <= T : NEW_LINE INDENT daycount += 1 NEW_LINE DEDENT DEDENT print ( daycount ) NEW_LINE
T274
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 N = in . nextInt ( ) ; int S = in . nextInt ( ) ; int T = in . nextInt ( ) ; int W = in . nextInt ( ) ; int count = 0 ; if ( S <= W && W <= T ) { count ++ ; } for ( int i = 1 ; i < N ; i ++ ) { W += in . nextInt ( ) ; if ( S <= W && W <= T ) { count ++ ; } } out . println ( count ) ; } } 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 ( ) ) ; } } }
n , s , t = map ( int , input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE a_array = [ ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT a_array . append ( int ( input ( ) ) ) NEW_LINE DEDENT cnt = 1 if s <= w <= t else 0 NEW_LINE for a in a_array : NEW_LINE INDENT w += a NEW_LINE if s <= w <= t : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT print ( cnt ) NEW_LINE
T275
import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int ans = 0 ; int g [ ] = new int [ a ] ; g [ 0 ] = sc . nextInt ( ) ; if ( b <= g [ 0 ] && g [ 0 ] <= c ) { ans ++ ; } for ( int i = 1 ; i < a ; i ++ ) { g [ i ] = g [ i - 1 ] + sc . nextInt ( ) ; if ( b <= g [ i ] && g [ i ] <= c ) { ans ++ ; } } System . out . println ( ans ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { 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 ; } } }
ans = 0 NEW_LINE n , s , t = map ( int , input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT w += int ( input ( ) ) NEW_LINE DEDENT if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT print ( ans ) NEW_LINE
T276
import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int ans = 0 ; int g [ ] = new int [ a ] ; g [ 0 ] = sc . nextInt ( ) ; if ( b <= g [ 0 ] && g [ 0 ] <= c ) { ans ++ ; } for ( int i = 1 ; i < a ; i ++ ) { g [ i ] = g [ i - 1 ] + sc . nextInt ( ) ; if ( b <= g [ i ] && g [ i ] <= c ) { ans ++ ; } } System . out . println ( ans ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { 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 sys NEW_LINE n , s , t = [ int ( i ) for i in sys . stdin . readline ( ) . rstrip ( ) . split ( ) ] NEW_LINE w = 0 NEW_LINE ans = 0 NEW_LINE for _ in range ( n ) : NEW_LINE INDENT a = int ( sys . stdin . readline ( ) . rstrip ( ) ) NEW_LINE w += a NEW_LINE if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T277
import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int ans = 0 ; int g [ ] = new int [ a ] ; g [ 0 ] = sc . nextInt ( ) ; if ( b <= g [ 0 ] && g [ 0 ] <= c ) { ans ++ ; } for ( int i = 1 ; i < a ; i ++ ) { g [ i ] = g [ i - 1 ] + sc . nextInt ( ) ; if ( b <= g [ i ] && g [ i ] <= c ) { ans ++ ; } } System . out . println ( ans ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { 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 ; } } }
def solve ( ) : NEW_LINE INDENT n , s , t = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE if s <= w and w <= t : NEW_LINE INDENT ans = 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = 0 NEW_LINE DEDENT for i in range ( n - 1 ) : NEW_LINE INDENT a = int ( input ( ) ) NEW_LINE w += a NEW_LINE if s <= w and w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT else : NEW_LINE INDENT continue NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT solve ( ) NEW_LINE
T278
import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int ans = 0 ; int g [ ] = new int [ a ] ; g [ 0 ] = sc . nextInt ( ) ; if ( b <= g [ 0 ] && g [ 0 ] <= c ) { ans ++ ; } for ( int i = 1 ; i < a ; i ++ ) { g [ i ] = g [ i - 1 ] + sc . nextInt ( ) ; if ( b <= g [ i ] && g [ i ] <= c ) { ans ++ ; } } System . out . println ( ans ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { 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 ; } } }
N , S , T = map ( int , input ( ) . split ( ) ) NEW_LINE W = int ( input ( ) ) NEW_LINE if S <= W <= T : NEW_LINE INDENT daycount = 1 NEW_LINE DEDENT else : NEW_LINE INDENT daycount = 0 NEW_LINE DEDENT for i in range ( N - 1 ) : NEW_LINE INDENT A = int ( input ( ) ) NEW_LINE W += A NEW_LINE if S <= W <= T : NEW_LINE INDENT daycount += 1 NEW_LINE DEDENT DEDENT print ( daycount ) NEW_LINE
T279
import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int ans = 0 ; int g [ ] = new int [ a ] ; g [ 0 ] = sc . nextInt ( ) ; if ( b <= g [ 0 ] && g [ 0 ] <= c ) { ans ++ ; } for ( int i = 1 ; i < a ; i ++ ) { g [ i ] = g [ i - 1 ] + sc . nextInt ( ) ; if ( b <= g [ i ] && g [ i ] <= c ) { ans ++ ; } } System . out . println ( ans ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { 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 ; } } }
n , s , t = map ( int , input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE a_array = [ ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT a_array . append ( int ( input ( ) ) ) NEW_LINE DEDENT cnt = 1 if s <= w <= t else 0 NEW_LINE for a in a_array : NEW_LINE INDENT w += a NEW_LINE if s <= w <= t : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT print ( cnt ) NEW_LINE
T280
import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { w += a [ i ] ; if ( s <= w && w <= t ) { ans ++ ; } } System . out . println ( ans ) ; } }
ans = 0 NEW_LINE n , s , t = map ( int , input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT w += int ( input ( ) ) NEW_LINE DEDENT if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT print ( ans ) NEW_LINE
T281
import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { w += a [ i ] ; if ( s <= w && w <= t ) { ans ++ ; } } System . out . println ( ans ) ; } }
import sys NEW_LINE n , s , t = [ int ( i ) for i in sys . stdin . readline ( ) . rstrip ( ) . split ( ) ] NEW_LINE w = 0 NEW_LINE ans = 0 NEW_LINE for _ in range ( n ) : NEW_LINE INDENT a = int ( sys . stdin . readline ( ) . rstrip ( ) ) NEW_LINE w += a NEW_LINE if s <= w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T282
import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { w += a [ i ] ; if ( s <= w && w <= t ) { ans ++ ; } } System . out . println ( ans ) ; } }
def solve ( ) : NEW_LINE INDENT n , s , t = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE if s <= w and w <= t : NEW_LINE INDENT ans = 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = 0 NEW_LINE DEDENT for i in range ( n - 1 ) : NEW_LINE INDENT a = int ( input ( ) ) NEW_LINE w += a NEW_LINE if s <= w and w <= t : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT else : NEW_LINE INDENT continue NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT solve ( ) NEW_LINE
T283
import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { w += a [ i ] ; if ( s <= w && w <= t ) { ans ++ ; } } System . out . println ( ans ) ; } }
N , S , T = map ( int , input ( ) . split ( ) ) NEW_LINE W = int ( input ( ) ) NEW_LINE if S <= W <= T : NEW_LINE INDENT daycount = 1 NEW_LINE DEDENT else : NEW_LINE INDENT daycount = 0 NEW_LINE DEDENT for i in range ( N - 1 ) : NEW_LINE INDENT A = int ( input ( ) ) NEW_LINE W += A NEW_LINE if S <= W <= T : NEW_LINE INDENT daycount += 1 NEW_LINE DEDENT DEDENT print ( daycount ) NEW_LINE
T284
import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { w += a [ i ] ; if ( s <= w && w <= t ) { ans ++ ; } } System . out . println ( ans ) ; } }
n , s , t = map ( int , input ( ) . split ( ) ) NEW_LINE w = int ( input ( ) ) NEW_LINE a_array = [ ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT a_array . append ( int ( input ( ) ) ) NEW_LINE DEDENT cnt = 1 if s <= w <= t else 0 NEW_LINE for a in a_array : NEW_LINE INDENT w += a NEW_LINE if s <= w <= t : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT print ( cnt ) NEW_LINE
T285
import java . util . HashMap ; import java . util . Scanner ; public class Main { static int a ; static int [ ] w ; static HashMap < Integer , Integer > left = new HashMap < Integer , Integer > ( ) ; static HashMap < Integer , Integer > right = new HashMap < Integer , Integer > ( ) ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; w = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { w [ i ] = sc . nextInt ( ) ; } a = N / 2 ; int ans = 0 ; pack ( 0 , a , left , 0 ) ; pack ( a , N , right , 0 ) ; for ( int c : left . keySet ( ) ) { if ( right . containsKey ( X - c ) ) { ans += left . get ( c ) * right . get ( X - c ) ; } } System . out . println ( ans ) ; } static void pack ( int s , int g , HashMap < Integer , Integer > map , int W ) { if ( s == g ) { if ( map . containsKey ( W ) ) { map . put ( W , map . get ( W ) + 1 ) ; } else { map . put ( W , 1 ) ; } } else { pack ( s + 1 , g , map , W ) ; pack ( s + 1 , g , map , W + w [ s ] ) ; } } }
from bisect import bisect , bisect_left NEW_LINE def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE N , X = inpl ( ) NEW_LINE W = [ int ( input ( ) ) for _ in range ( N ) ] NEW_LINE A = N // 2 NEW_LINE B = N - A NEW_LINE C = [ ] NEW_LINE D = [ ] NEW_LINE for i in range ( 2 ** A ) : NEW_LINE INDENT C . append ( sum ( [ W [ a ] * ( i >> a & 1 ) for a in range ( A ) ] ) ) NEW_LINE DEDENT for j in range ( 2 ** B ) : NEW_LINE INDENT D . append ( sum ( [ W [ b + A ] * ( j >> b & 1 ) for b in range ( B ) ] ) ) NEW_LINE DEDENT ans = 0 NEW_LINE C = sorted ( C ) NEW_LINE D = sorted ( D ) NEW_LINE for c in C [ : bisect ( C , X ) ] : NEW_LINE INDENT ans += bisect ( D , X - c ) - bisect_left ( D , X - c ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T286
import java . util . HashMap ; import java . util . Scanner ; public class Main { static int a ; static int [ ] w ; static HashMap < Integer , Integer > left = new HashMap < Integer , Integer > ( ) ; static HashMap < Integer , Integer > right = new HashMap < Integer , Integer > ( ) ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; w = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { w [ i ] = sc . nextInt ( ) ; } a = N / 2 ; int ans = 0 ; pack ( 0 , a , left , 0 ) ; pack ( a , N , right , 0 ) ; for ( int c : left . keySet ( ) ) { if ( right . containsKey ( X - c ) ) { ans += left . get ( c ) * right . get ( X - c ) ; } } System . out . println ( ans ) ; } static void pack ( int s , int g , HashMap < Integer , Integer > map , int W ) { if ( s == g ) { if ( map . containsKey ( W ) ) { map . put ( W , map . get ( W ) + 1 ) ; } else { map . put ( W , 1 ) ; } } else { pack ( s + 1 , g , map , W ) ; pack ( s + 1 , g , map , W + w [ s ] ) ; } } }
import math , string , itertools , fractions , heapq , collections , re , array , bisect , sys , random , time , copy , functools NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE inf = 10 ** 20 NEW_LINE mod = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def F ( ) : return float ( sys . stdin . readline ( ) ) NEW_LINE def S ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT N , X = LI ( ) NEW_LINE W = sorted ( [ I ( ) for _ in range ( N ) ] , reverse = True ) NEW_LINE d = collections . defaultdict ( int ) NEW_LINE d [ 0 ] = 1 NEW_LINE for c in W [ N // 2 : ] : NEW_LINE INDENT t = collections . defaultdict ( int ) NEW_LINE for k , v in d . items ( ) : NEW_LINE INDENT if k + c > X : NEW_LINE INDENT continue NEW_LINE DEDENT t [ k + c ] += v NEW_LINE DEDENT for k , v in t . items ( ) : NEW_LINE INDENT d [ k ] += v NEW_LINE DEDENT DEDENT d2 = collections . defaultdict ( int ) NEW_LINE d2 [ 0 ] = 1 NEW_LINE for c in W [ : N // 2 ] : NEW_LINE INDENT t = collections . defaultdict ( int ) NEW_LINE for k , v in d2 . items ( ) : NEW_LINE INDENT if k + c > X : NEW_LINE INDENT continue NEW_LINE DEDENT t [ k + c ] += v NEW_LINE DEDENT for k , v in t . items ( ) : NEW_LINE INDENT d2 [ k ] += v NEW_LINE DEDENT DEDENT r = 0 NEW_LINE for k , v in d . items ( ) : NEW_LINE INDENT r += v * d2 [ X - k ] NEW_LINE DEDENT return r NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T287
import java . util . HashMap ; import java . util . Scanner ; public class Main { static int a ; static int [ ] w ; static HashMap < Integer , Integer > left = new HashMap < Integer , Integer > ( ) ; static HashMap < Integer , Integer > right = new HashMap < Integer , Integer > ( ) ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; w = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { w [ i ] = sc . nextInt ( ) ; } a = N / 2 ; int ans = 0 ; pack ( 0 , a , left , 0 ) ; pack ( a , N , right , 0 ) ; for ( int c : left . keySet ( ) ) { if ( right . containsKey ( X - c ) ) { ans += left . get ( c ) * right . get ( X - c ) ; } } System . out . println ( ans ) ; } static void pack ( int s , int g , HashMap < Integer , Integer > map , int W ) { if ( s == g ) { if ( map . containsKey ( W ) ) { map . put ( W , map . get ( W ) + 1 ) ; } else { map . put ( W , 1 ) ; } } else { pack ( s + 1 , g , map , W ) ; pack ( s + 1 , g , map , W + w [ s ] ) ; } } }
def make ( n , r ) : NEW_LINE INDENT v = { 0 : 1 } NEW_LINE for _ in range ( n ) : NEW_LINE INDENT s = int ( input ( ) ) NEW_LINE w = dict ( v ) NEW_LINE for k , val in v . items ( ) : NEW_LINE INDENT w [ k + s ] = v . get ( k + s , 0 ) + val NEW_LINE DEDENT v = w NEW_LINE DEDENT return sorted ( v . items ( ) , reverse = r ) NEW_LINE DEDENT N , X = map ( int , input ( ) . split ( ) ) NEW_LINE S = make ( N // 2 , 0 ) NEW_LINE T = make ( N - N // 2 , 1 ) NEW_LINE ans = 0 NEW_LINE it = iter ( T ) NEW_LINE nn = ( None , None ) NEW_LINE t , w = next ( it , nn ) NEW_LINE for s , v in S : NEW_LINE INDENT while w and s + t > X : NEW_LINE INDENT t , w = next ( it , nn ) NEW_LINE DEDENT if w and s + t == X : NEW_LINE INDENT ans += v * w NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T288
import java . util . HashMap ; import java . util . Scanner ; public class Main { static int a ; static int [ ] w ; static HashMap < Integer , Integer > left = new HashMap < Integer , Integer > ( ) ; static HashMap < Integer , Integer > right = new HashMap < Integer , Integer > ( ) ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; w = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { w [ i ] = sc . nextInt ( ) ; } a = N / 2 ; int ans = 0 ; pack ( 0 , a , left , 0 ) ; pack ( a , N , right , 0 ) ; for ( int c : left . keySet ( ) ) { if ( right . containsKey ( X - c ) ) { ans += left . get ( c ) * right . get ( X - c ) ; } } System . out . println ( ans ) ; } static void pack ( int s , int g , HashMap < Integer , Integer > map , int W ) { if ( s == g ) { if ( map . containsKey ( W ) ) { map . put ( W , map . get ( W ) + 1 ) ; } else { map . put ( W , 1 ) ; } } else { pack ( s + 1 , g , map , W ) ; pack ( s + 1 , g , map , W + w [ s ] ) ; } } }
from collections import defaultdict NEW_LINE import sys , heapq , bisect , math , itertools , string , queue , datetime NEW_LINE sys . setrecursionlimit ( 10 ** 8 ) NEW_LINE INF = float ( ' inf ' ) NEW_LINE mod = 10 ** 9 + 7 NEW_LINE eps = 10 ** - 7 NEW_LINE AtoZ = [ chr ( i ) for i in range ( 65 , 65 + 26 ) ] NEW_LINE atoz = [ chr ( i ) for i in range ( 97 , 97 + 26 ) ] NEW_LINE def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def inpl_s ( ) : return list ( input ( ) . split ( ) ) NEW_LINE N , X = inpl ( ) NEW_LINE ww = [ int ( input ( ) ) for i in range ( N ) ] NEW_LINE k = N // 2 NEW_LINE flags1 = itertools . product ( [ 0 , 1 ] , repeat = k ) NEW_LINE flags2 = itertools . product ( [ 0 , 1 ] , repeat = N - k ) NEW_LINE dd1 = defaultdict ( int ) NEW_LINE ed = [ ] NEW_LINE dd2 = defaultdict ( int ) NEW_LINE for flag in flags1 : NEW_LINE INDENT tmp = 0 NEW_LINE for i , fl in enumerate ( flag ) : NEW_LINE INDENT if fl : NEW_LINE INDENT tmp += ww [ i ] NEW_LINE DEDENT DEDENT if dd1 [ tmp ] == 0 : NEW_LINE INDENT ed . append ( tmp ) NEW_LINE DEDENT dd1 [ tmp ] += 1 NEW_LINE DEDENT for flag in flags2 : NEW_LINE INDENT tmp = 0 NEW_LINE for i , fl in enumerate ( flag ) : NEW_LINE INDENT if fl : NEW_LINE INDENT tmp += ww [ i + k ] NEW_LINE DEDENT DEDENT dd2 [ tmp ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for e in ed : NEW_LINE INDENT ans += dd1 [ e ] * dd2 [ X - e ] NEW_LINE DEDENT print ( ans ) NEW_LINE
T289
import java . util . HashMap ; import java . util . Scanner ; public class Main { static int a ; static int [ ] w ; static HashMap < Integer , Integer > left = new HashMap < Integer , Integer > ( ) ; static HashMap < Integer , Integer > right = new HashMap < Integer , Integer > ( ) ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; w = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { w [ i ] = sc . nextInt ( ) ; } a = N / 2 ; int ans = 0 ; pack ( 0 , a , left , 0 ) ; pack ( a , N , right , 0 ) ; for ( int c : left . keySet ( ) ) { if ( right . containsKey ( X - c ) ) { ans += left . get ( c ) * right . get ( X - c ) ; } } System . out . println ( ans ) ; } static void pack ( int s , int g , HashMap < Integer , Integer > map , int W ) { if ( s == g ) { if ( map . containsKey ( W ) ) { map . put ( W , map . get ( W ) + 1 ) ; } else { map . put ( W , 1 ) ; } } else { pack ( s + 1 , g , map , W ) ; pack ( s + 1 , g , map , W + w [ s ] ) ; } } }
import sys NEW_LINE from collections import defaultdict , Counter NEW_LINE from itertools import product , groupby , count , permutations , combinations NEW_LINE from math import pi , sqrt , ceil , floor NEW_LINE from collections import deque NEW_LINE from bisect import bisect , bisect_left , bisect_right NEW_LINE from string import ascii_lowercase NEW_LINE INF = float ( " inf " ) NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE dy = [ 0 , - 1 , 0 , 1 ] NEW_LINE dx = [ 1 , 0 , - 1 , 0 ] NEW_LINE def inside ( y : int , x : int , H : int , W : int ) -> bool : return 0 <= y < H and 0 <= x < W NEW_LINE def main ( ) : NEW_LINE INDENT N , X = map ( int , input ( ) . split ( ) ) NEW_LINE w_list = [ int ( input ( ) ) for _ in range ( N ) ] NEW_LINE w_list1 , w_list2 = w_list [ : N // 2 ] , w_list [ N // 2 : ] NEW_LINE n = len ( w_list1 ) NEW_LINE s = [ ] NEW_LINE for b in range ( 2 ** n ) : NEW_LINE INDENT total = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if b & 1 << i : NEW_LINE INDENT total += w_list1 [ i ] NEW_LINE DEDENT DEDENT s . append ( total ) NEW_LINE DEDENT n = len ( w_list2 ) NEW_LINE d = defaultdict ( int ) NEW_LINE for b in range ( 2 ** n ) : NEW_LINE INDENT total = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if b & 1 << i : NEW_LINE INDENT total += w_list2 [ i ] NEW_LINE DEDENT DEDENT d [ total ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for a in s : NEW_LINE INDENT if a > X : NEW_LINE INDENT continue NEW_LINE DEDENT ans += d [ X - a ] NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
T290
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long x = sc . nextLong ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; Arrays . sort ( a ) ; HashMap < Long , Long > map1 = new HashMap < > ( ) ; HashMap < Long , Long > map2 = new HashMap < > ( ) ; int zen = n / 2 ; int c = 1 ; for ( int i = 0 ; i < zen ; i ++ ) c *= 2 ; for ( int i = 0 ; i < c ; i ++ ) { int d = i ; long v = 0 ; for ( int j = 0 ; j < zen ; j ++ ) { if ( d % 2 == 0 ) v += a [ j ] ; d /= 2 ; } if ( map1 . containsKey ( v ) ) map1 . put ( v , map1 . get ( v ) + 1 ) ; else map1 . put ( v , 1L ) ; } c = 1 ; for ( int i = zen ; i < n ; i ++ ) c *= 2 ; for ( int i = 0 ; i < c ; i ++ ) { int d = i ; long v = 0 ; for ( int j = zen ; j < n ; j ++ ) { if ( d % 2 == 0 ) v += a [ j ] ; d /= 2 ; } if ( map2 . containsKey ( v ) ) map2 . put ( v , map2 . get ( v ) + 1 ) ; else map2 . put ( v , 1L ) ; } long res = 0 ; Set < Long > set = map1 . keySet ( ) ; for ( long lo : set ) { if ( map2 . containsKey ( x - lo ) ) { res += map1 . get ( lo ) * map2 . get ( x - lo ) ; } } System . out . println ( res ) ; } }
from bisect import bisect , bisect_left NEW_LINE def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE N , X = inpl ( ) NEW_LINE W = [ int ( input ( ) ) for _ in range ( N ) ] NEW_LINE A = N // 2 NEW_LINE B = N - A NEW_LINE C = [ ] NEW_LINE D = [ ] NEW_LINE for i in range ( 2 ** A ) : NEW_LINE INDENT C . append ( sum ( [ W [ a ] * ( i >> a & 1 ) for a in range ( A ) ] ) ) NEW_LINE DEDENT for j in range ( 2 ** B ) : NEW_LINE INDENT D . append ( sum ( [ W [ b + A ] * ( j >> b & 1 ) for b in range ( B ) ] ) ) NEW_LINE DEDENT ans = 0 NEW_LINE C = sorted ( C ) NEW_LINE D = sorted ( D ) NEW_LINE for c in C [ : bisect ( C , X ) ] : NEW_LINE INDENT ans += bisect ( D , X - c ) - bisect_left ( D , X - c ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T291
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long x = sc . nextLong ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; Arrays . sort ( a ) ; HashMap < Long , Long > map1 = new HashMap < > ( ) ; HashMap < Long , Long > map2 = new HashMap < > ( ) ; int zen = n / 2 ; int c = 1 ; for ( int i = 0 ; i < zen ; i ++ ) c *= 2 ; for ( int i = 0 ; i < c ; i ++ ) { int d = i ; long v = 0 ; for ( int j = 0 ; j < zen ; j ++ ) { if ( d % 2 == 0 ) v += a [ j ] ; d /= 2 ; } if ( map1 . containsKey ( v ) ) map1 . put ( v , map1 . get ( v ) + 1 ) ; else map1 . put ( v , 1L ) ; } c = 1 ; for ( int i = zen ; i < n ; i ++ ) c *= 2 ; for ( int i = 0 ; i < c ; i ++ ) { int d = i ; long v = 0 ; for ( int j = zen ; j < n ; j ++ ) { if ( d % 2 == 0 ) v += a [ j ] ; d /= 2 ; } if ( map2 . containsKey ( v ) ) map2 . put ( v , map2 . get ( v ) + 1 ) ; else map2 . put ( v , 1L ) ; } long res = 0 ; Set < Long > set = map1 . keySet ( ) ; for ( long lo : set ) { if ( map2 . containsKey ( x - lo ) ) { res += map1 . get ( lo ) * map2 . get ( x - lo ) ; } } System . out . println ( res ) ; } }
import math , string , itertools , fractions , heapq , collections , re , array , bisect , sys , random , time , copy , functools NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE inf = 10 ** 20 NEW_LINE mod = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def F ( ) : return float ( sys . stdin . readline ( ) ) NEW_LINE def S ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT N , X = LI ( ) NEW_LINE W = sorted ( [ I ( ) for _ in range ( N ) ] , reverse = True ) NEW_LINE d = collections . defaultdict ( int ) NEW_LINE d [ 0 ] = 1 NEW_LINE for c in W [ N // 2 : ] : NEW_LINE INDENT t = collections . defaultdict ( int ) NEW_LINE for k , v in d . items ( ) : NEW_LINE INDENT if k + c > X : NEW_LINE INDENT continue NEW_LINE DEDENT t [ k + c ] += v NEW_LINE DEDENT for k , v in t . items ( ) : NEW_LINE INDENT d [ k ] += v NEW_LINE DEDENT DEDENT d2 = collections . defaultdict ( int ) NEW_LINE d2 [ 0 ] = 1 NEW_LINE for c in W [ : N // 2 ] : NEW_LINE INDENT t = collections . defaultdict ( int ) NEW_LINE for k , v in d2 . items ( ) : NEW_LINE INDENT if k + c > X : NEW_LINE INDENT continue NEW_LINE DEDENT t [ k + c ] += v NEW_LINE DEDENT for k , v in t . items ( ) : NEW_LINE INDENT d2 [ k ] += v NEW_LINE DEDENT DEDENT r = 0 NEW_LINE for k , v in d . items ( ) : NEW_LINE INDENT r += v * d2 [ X - k ] NEW_LINE DEDENT return r NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T292
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long x = sc . nextLong ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; Arrays . sort ( a ) ; HashMap < Long , Long > map1 = new HashMap < > ( ) ; HashMap < Long , Long > map2 = new HashMap < > ( ) ; int zen = n / 2 ; int c = 1 ; for ( int i = 0 ; i < zen ; i ++ ) c *= 2 ; for ( int i = 0 ; i < c ; i ++ ) { int d = i ; long v = 0 ; for ( int j = 0 ; j < zen ; j ++ ) { if ( d % 2 == 0 ) v += a [ j ] ; d /= 2 ; } if ( map1 . containsKey ( v ) ) map1 . put ( v , map1 . get ( v ) + 1 ) ; else map1 . put ( v , 1L ) ; } c = 1 ; for ( int i = zen ; i < n ; i ++ ) c *= 2 ; for ( int i = 0 ; i < c ; i ++ ) { int d = i ; long v = 0 ; for ( int j = zen ; j < n ; j ++ ) { if ( d % 2 == 0 ) v += a [ j ] ; d /= 2 ; } if ( map2 . containsKey ( v ) ) map2 . put ( v , map2 . get ( v ) + 1 ) ; else map2 . put ( v , 1L ) ; } long res = 0 ; Set < Long > set = map1 . keySet ( ) ; for ( long lo : set ) { if ( map2 . containsKey ( x - lo ) ) { res += map1 . get ( lo ) * map2 . get ( x - lo ) ; } } System . out . println ( res ) ; } }
def make ( n , r ) : NEW_LINE INDENT v = { 0 : 1 } NEW_LINE for _ in range ( n ) : NEW_LINE INDENT s = int ( input ( ) ) NEW_LINE w = dict ( v ) NEW_LINE for k , val in v . items ( ) : NEW_LINE INDENT w [ k + s ] = v . get ( k + s , 0 ) + val NEW_LINE DEDENT v = w NEW_LINE DEDENT return sorted ( v . items ( ) , reverse = r ) NEW_LINE DEDENT N , X = map ( int , input ( ) . split ( ) ) NEW_LINE S = make ( N // 2 , 0 ) NEW_LINE T = make ( N - N // 2 , 1 ) NEW_LINE ans = 0 NEW_LINE it = iter ( T ) NEW_LINE nn = ( None , None ) NEW_LINE t , w = next ( it , nn ) NEW_LINE for s , v in S : NEW_LINE INDENT while w and s + t > X : NEW_LINE INDENT t , w = next ( it , nn ) NEW_LINE DEDENT if w and s + t == X : NEW_LINE INDENT ans += v * w NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T293
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long x = sc . nextLong ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; Arrays . sort ( a ) ; HashMap < Long , Long > map1 = new HashMap < > ( ) ; HashMap < Long , Long > map2 = new HashMap < > ( ) ; int zen = n / 2 ; int c = 1 ; for ( int i = 0 ; i < zen ; i ++ ) c *= 2 ; for ( int i = 0 ; i < c ; i ++ ) { int d = i ; long v = 0 ; for ( int j = 0 ; j < zen ; j ++ ) { if ( d % 2 == 0 ) v += a [ j ] ; d /= 2 ; } if ( map1 . containsKey ( v ) ) map1 . put ( v , map1 . get ( v ) + 1 ) ; else map1 . put ( v , 1L ) ; } c = 1 ; for ( int i = zen ; i < n ; i ++ ) c *= 2 ; for ( int i = 0 ; i < c ; i ++ ) { int d = i ; long v = 0 ; for ( int j = zen ; j < n ; j ++ ) { if ( d % 2 == 0 ) v += a [ j ] ; d /= 2 ; } if ( map2 . containsKey ( v ) ) map2 . put ( v , map2 . get ( v ) + 1 ) ; else map2 . put ( v , 1L ) ; } long res = 0 ; Set < Long > set = map1 . keySet ( ) ; for ( long lo : set ) { if ( map2 . containsKey ( x - lo ) ) { res += map1 . get ( lo ) * map2 . get ( x - lo ) ; } } System . out . println ( res ) ; } }
from collections import defaultdict NEW_LINE import sys , heapq , bisect , math , itertools , string , queue , datetime NEW_LINE sys . setrecursionlimit ( 10 ** 8 ) NEW_LINE INF = float ( ' inf ' ) NEW_LINE mod = 10 ** 9 + 7 NEW_LINE eps = 10 ** - 7 NEW_LINE AtoZ = [ chr ( i ) for i in range ( 65 , 65 + 26 ) ] NEW_LINE atoz = [ chr ( i ) for i in range ( 97 , 97 + 26 ) ] NEW_LINE def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def inpl_s ( ) : return list ( input ( ) . split ( ) ) NEW_LINE N , X = inpl ( ) NEW_LINE ww = [ int ( input ( ) ) for i in range ( N ) ] NEW_LINE k = N // 2 NEW_LINE flags1 = itertools . product ( [ 0 , 1 ] , repeat = k ) NEW_LINE flags2 = itertools . product ( [ 0 , 1 ] , repeat = N - k ) NEW_LINE dd1 = defaultdict ( int ) NEW_LINE ed = [ ] NEW_LINE dd2 = defaultdict ( int ) NEW_LINE for flag in flags1 : NEW_LINE INDENT tmp = 0 NEW_LINE for i , fl in enumerate ( flag ) : NEW_LINE INDENT if fl : NEW_LINE INDENT tmp += ww [ i ] NEW_LINE DEDENT DEDENT if dd1 [ tmp ] == 0 : NEW_LINE INDENT ed . append ( tmp ) NEW_LINE DEDENT dd1 [ tmp ] += 1 NEW_LINE DEDENT for flag in flags2 : NEW_LINE INDENT tmp = 0 NEW_LINE for i , fl in enumerate ( flag ) : NEW_LINE INDENT if fl : NEW_LINE INDENT tmp += ww [ i + k ] NEW_LINE DEDENT DEDENT dd2 [ tmp ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for e in ed : NEW_LINE INDENT ans += dd1 [ e ] * dd2 [ X - e ] NEW_LINE DEDENT print ( ans ) NEW_LINE
T294
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long x = sc . nextLong ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; Arrays . sort ( a ) ; HashMap < Long , Long > map1 = new HashMap < > ( ) ; HashMap < Long , Long > map2 = new HashMap < > ( ) ; int zen = n / 2 ; int c = 1 ; for ( int i = 0 ; i < zen ; i ++ ) c *= 2 ; for ( int i = 0 ; i < c ; i ++ ) { int d = i ; long v = 0 ; for ( int j = 0 ; j < zen ; j ++ ) { if ( d % 2 == 0 ) v += a [ j ] ; d /= 2 ; } if ( map1 . containsKey ( v ) ) map1 . put ( v , map1 . get ( v ) + 1 ) ; else map1 . put ( v , 1L ) ; } c = 1 ; for ( int i = zen ; i < n ; i ++ ) c *= 2 ; for ( int i = 0 ; i < c ; i ++ ) { int d = i ; long v = 0 ; for ( int j = zen ; j < n ; j ++ ) { if ( d % 2 == 0 ) v += a [ j ] ; d /= 2 ; } if ( map2 . containsKey ( v ) ) map2 . put ( v , map2 . get ( v ) + 1 ) ; else map2 . put ( v , 1L ) ; } long res = 0 ; Set < Long > set = map1 . keySet ( ) ; for ( long lo : set ) { if ( map2 . containsKey ( x - lo ) ) { res += map1 . get ( lo ) * map2 . get ( x - lo ) ; } } System . out . println ( res ) ; } }
import sys NEW_LINE from collections import defaultdict , Counter NEW_LINE from itertools import product , groupby , count , permutations , combinations NEW_LINE from math import pi , sqrt , ceil , floor NEW_LINE from collections import deque NEW_LINE from bisect import bisect , bisect_left , bisect_right NEW_LINE from string import ascii_lowercase NEW_LINE INF = float ( " inf " ) NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE dy = [ 0 , - 1 , 0 , 1 ] NEW_LINE dx = [ 1 , 0 , - 1 , 0 ] NEW_LINE def inside ( y : int , x : int , H : int , W : int ) -> bool : return 0 <= y < H and 0 <= x < W NEW_LINE def main ( ) : NEW_LINE INDENT N , X = map ( int , input ( ) . split ( ) ) NEW_LINE w_list = [ int ( input ( ) ) for _ in range ( N ) ] NEW_LINE w_list1 , w_list2 = w_list [ : N // 2 ] , w_list [ N // 2 : ] NEW_LINE n = len ( w_list1 ) NEW_LINE s = [ ] NEW_LINE for b in range ( 2 ** n ) : NEW_LINE INDENT total = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if b & 1 << i : NEW_LINE INDENT total += w_list1 [ i ] NEW_LINE DEDENT DEDENT s . append ( total ) NEW_LINE DEDENT n = len ( w_list2 ) NEW_LINE d = defaultdict ( int ) NEW_LINE for b in range ( 2 ** n ) : NEW_LINE INDENT total = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if b & 1 << i : NEW_LINE INDENT total += w_list2 [ i ] NEW_LINE DEDENT DEDENT d [ total ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for a in s : NEW_LINE INDENT if a > X : NEW_LINE INDENT continue NEW_LINE DEDENT ans += d [ X - a ] NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
T295
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; long x = scan . nextInt ( ) ; long [ ] w = new long [ n ] ; for ( int i = 0 ; i < n ; ++ i ) w [ i ] = scan . nextInt ( ) ; int m = n / 2 ; long [ ] f = new long [ 1 << m ] ; long [ ] s = new long [ 1 << n - m ] ; for ( int i = 0 ; i < 1 << m ; ++ i ) for ( int j = 0 ; j < m ; ++ j ) if ( ( i & 1 << j ) != 0 ) f [ i ] += w [ j ] ; for ( int i = 0 ; i < 1 << n - m ; ++ i ) for ( int j = 0 ; j < n - m ; ++ j ) if ( ( i & 1 << j ) != 0 ) s [ i ] += w [ m + j ] ; Map < Long , Integer > hs = new HashMap < Long , Integer > ( ) ; for ( long ss : s ) if ( ! hs . containsKey ( ss ) ) hs . put ( ss , 1 ) ; else hs . put ( ss , hs . get ( ss ) + 1 ) ; long total = 0 ; for ( long ff : f ) if ( hs . containsKey ( x - ff ) ) total += hs . get ( x - ff ) ; System . out . println ( total ) ; } }
from bisect import bisect , bisect_left NEW_LINE def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE N , X = inpl ( ) NEW_LINE W = [ int ( input ( ) ) for _ in range ( N ) ] NEW_LINE A = N // 2 NEW_LINE B = N - A NEW_LINE C = [ ] NEW_LINE D = [ ] NEW_LINE for i in range ( 2 ** A ) : NEW_LINE INDENT C . append ( sum ( [ W [ a ] * ( i >> a & 1 ) for a in range ( A ) ] ) ) NEW_LINE DEDENT for j in range ( 2 ** B ) : NEW_LINE INDENT D . append ( sum ( [ W [ b + A ] * ( j >> b & 1 ) for b in range ( B ) ] ) ) NEW_LINE DEDENT ans = 0 NEW_LINE C = sorted ( C ) NEW_LINE D = sorted ( D ) NEW_LINE for c in C [ : bisect ( C , X ) ] : NEW_LINE INDENT ans += bisect ( D , X - c ) - bisect_left ( D , X - c ) NEW_LINE DEDENT print ( ans ) NEW_LINE
T296
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; long x = scan . nextInt ( ) ; long [ ] w = new long [ n ] ; for ( int i = 0 ; i < n ; ++ i ) w [ i ] = scan . nextInt ( ) ; int m = n / 2 ; long [ ] f = new long [ 1 << m ] ; long [ ] s = new long [ 1 << n - m ] ; for ( int i = 0 ; i < 1 << m ; ++ i ) for ( int j = 0 ; j < m ; ++ j ) if ( ( i & 1 << j ) != 0 ) f [ i ] += w [ j ] ; for ( int i = 0 ; i < 1 << n - m ; ++ i ) for ( int j = 0 ; j < n - m ; ++ j ) if ( ( i & 1 << j ) != 0 ) s [ i ] += w [ m + j ] ; Map < Long , Integer > hs = new HashMap < Long , Integer > ( ) ; for ( long ss : s ) if ( ! hs . containsKey ( ss ) ) hs . put ( ss , 1 ) ; else hs . put ( ss , hs . get ( ss ) + 1 ) ; long total = 0 ; for ( long ff : f ) if ( hs . containsKey ( x - ff ) ) total += hs . get ( x - ff ) ; System . out . println ( total ) ; } }
import math , string , itertools , fractions , heapq , collections , re , array , bisect , sys , random , time , copy , functools NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE inf = 10 ** 20 NEW_LINE mod = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def F ( ) : return float ( sys . stdin . readline ( ) ) NEW_LINE def S ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT N , X = LI ( ) NEW_LINE W = sorted ( [ I ( ) for _ in range ( N ) ] , reverse = True ) NEW_LINE d = collections . defaultdict ( int ) NEW_LINE d [ 0 ] = 1 NEW_LINE for c in W [ N // 2 : ] : NEW_LINE INDENT t = collections . defaultdict ( int ) NEW_LINE for k , v in d . items ( ) : NEW_LINE INDENT if k + c > X : NEW_LINE INDENT continue NEW_LINE DEDENT t [ k + c ] += v NEW_LINE DEDENT for k , v in t . items ( ) : NEW_LINE INDENT d [ k ] += v NEW_LINE DEDENT DEDENT d2 = collections . defaultdict ( int ) NEW_LINE d2 [ 0 ] = 1 NEW_LINE for c in W [ : N // 2 ] : NEW_LINE INDENT t = collections . defaultdict ( int ) NEW_LINE for k , v in d2 . items ( ) : NEW_LINE INDENT if k + c > X : NEW_LINE INDENT continue NEW_LINE DEDENT t [ k + c ] += v NEW_LINE DEDENT for k , v in t . items ( ) : NEW_LINE INDENT d2 [ k ] += v NEW_LINE DEDENT DEDENT r = 0 NEW_LINE for k , v in d . items ( ) : NEW_LINE INDENT r += v * d2 [ X - k ] NEW_LINE DEDENT return r NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T297
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; long x = scan . nextInt ( ) ; long [ ] w = new long [ n ] ; for ( int i = 0 ; i < n ; ++ i ) w [ i ] = scan . nextInt ( ) ; int m = n / 2 ; long [ ] f = new long [ 1 << m ] ; long [ ] s = new long [ 1 << n - m ] ; for ( int i = 0 ; i < 1 << m ; ++ i ) for ( int j = 0 ; j < m ; ++ j ) if ( ( i & 1 << j ) != 0 ) f [ i ] += w [ j ] ; for ( int i = 0 ; i < 1 << n - m ; ++ i ) for ( int j = 0 ; j < n - m ; ++ j ) if ( ( i & 1 << j ) != 0 ) s [ i ] += w [ m + j ] ; Map < Long , Integer > hs = new HashMap < Long , Integer > ( ) ; for ( long ss : s ) if ( ! hs . containsKey ( ss ) ) hs . put ( ss , 1 ) ; else hs . put ( ss , hs . get ( ss ) + 1 ) ; long total = 0 ; for ( long ff : f ) if ( hs . containsKey ( x - ff ) ) total += hs . get ( x - ff ) ; System . out . println ( total ) ; } }
def make ( n , r ) : NEW_LINE INDENT v = { 0 : 1 } NEW_LINE for _ in range ( n ) : NEW_LINE INDENT s = int ( input ( ) ) NEW_LINE w = dict ( v ) NEW_LINE for k , val in v . items ( ) : NEW_LINE INDENT w [ k + s ] = v . get ( k + s , 0 ) + val NEW_LINE DEDENT v = w NEW_LINE DEDENT return sorted ( v . items ( ) , reverse = r ) NEW_LINE DEDENT N , X = map ( int , input ( ) . split ( ) ) NEW_LINE S = make ( N // 2 , 0 ) NEW_LINE T = make ( N - N // 2 , 1 ) NEW_LINE ans = 0 NEW_LINE it = iter ( T ) NEW_LINE nn = ( None , None ) NEW_LINE t , w = next ( it , nn ) NEW_LINE for s , v in S : NEW_LINE INDENT while w and s + t > X : NEW_LINE INDENT t , w = next ( it , nn ) NEW_LINE DEDENT if w and s + t == X : NEW_LINE INDENT ans += v * w NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
T298
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; long x = scan . nextInt ( ) ; long [ ] w = new long [ n ] ; for ( int i = 0 ; i < n ; ++ i ) w [ i ] = scan . nextInt ( ) ; int m = n / 2 ; long [ ] f = new long [ 1 << m ] ; long [ ] s = new long [ 1 << n - m ] ; for ( int i = 0 ; i < 1 << m ; ++ i ) for ( int j = 0 ; j < m ; ++ j ) if ( ( i & 1 << j ) != 0 ) f [ i ] += w [ j ] ; for ( int i = 0 ; i < 1 << n - m ; ++ i ) for ( int j = 0 ; j < n - m ; ++ j ) if ( ( i & 1 << j ) != 0 ) s [ i ] += w [ m + j ] ; Map < Long , Integer > hs = new HashMap < Long , Integer > ( ) ; for ( long ss : s ) if ( ! hs . containsKey ( ss ) ) hs . put ( ss , 1 ) ; else hs . put ( ss , hs . get ( ss ) + 1 ) ; long total = 0 ; for ( long ff : f ) if ( hs . containsKey ( x - ff ) ) total += hs . get ( x - ff ) ; System . out . println ( total ) ; } }
from collections import defaultdict NEW_LINE import sys , heapq , bisect , math , itertools , string , queue , datetime NEW_LINE sys . setrecursionlimit ( 10 ** 8 ) NEW_LINE INF = float ( ' inf ' ) NEW_LINE mod = 10 ** 9 + 7 NEW_LINE eps = 10 ** - 7 NEW_LINE AtoZ = [ chr ( i ) for i in range ( 65 , 65 + 26 ) ] NEW_LINE atoz = [ chr ( i ) for i in range ( 97 , 97 + 26 ) ] NEW_LINE def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def inpl_s ( ) : return list ( input ( ) . split ( ) ) NEW_LINE N , X = inpl ( ) NEW_LINE ww = [ int ( input ( ) ) for i in range ( N ) ] NEW_LINE k = N // 2 NEW_LINE flags1 = itertools . product ( [ 0 , 1 ] , repeat = k ) NEW_LINE flags2 = itertools . product ( [ 0 , 1 ] , repeat = N - k ) NEW_LINE dd1 = defaultdict ( int ) NEW_LINE ed = [ ] NEW_LINE dd2 = defaultdict ( int ) NEW_LINE for flag in flags1 : NEW_LINE INDENT tmp = 0 NEW_LINE for i , fl in enumerate ( flag ) : NEW_LINE INDENT if fl : NEW_LINE INDENT tmp += ww [ i ] NEW_LINE DEDENT DEDENT if dd1 [ tmp ] == 0 : NEW_LINE INDENT ed . append ( tmp ) NEW_LINE DEDENT dd1 [ tmp ] += 1 NEW_LINE DEDENT for flag in flags2 : NEW_LINE INDENT tmp = 0 NEW_LINE for i , fl in enumerate ( flag ) : NEW_LINE INDENT if fl : NEW_LINE INDENT tmp += ww [ i + k ] NEW_LINE DEDENT DEDENT dd2 [ tmp ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for e in ed : NEW_LINE INDENT ans += dd1 [ e ] * dd2 [ X - e ] NEW_LINE DEDENT print ( ans ) NEW_LINE
T299
import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; long x = scan . nextInt ( ) ; long [ ] w = new long [ n ] ; for ( int i = 0 ; i < n ; ++ i ) w [ i ] = scan . nextInt ( ) ; int m = n / 2 ; long [ ] f = new long [ 1 << m ] ; long [ ] s = new long [ 1 << n - m ] ; for ( int i = 0 ; i < 1 << m ; ++ i ) for ( int j = 0 ; j < m ; ++ j ) if ( ( i & 1 << j ) != 0 ) f [ i ] += w [ j ] ; for ( int i = 0 ; i < 1 << n - m ; ++ i ) for ( int j = 0 ; j < n - m ; ++ j ) if ( ( i & 1 << j ) != 0 ) s [ i ] += w [ m + j ] ; Map < Long , Integer > hs = new HashMap < Long , Integer > ( ) ; for ( long ss : s ) if ( ! hs . containsKey ( ss ) ) hs . put ( ss , 1 ) ; else hs . put ( ss , hs . get ( ss ) + 1 ) ; long total = 0 ; for ( long ff : f ) if ( hs . containsKey ( x - ff ) ) total += hs . get ( x - ff ) ; System . out . println ( total ) ; } }
import sys NEW_LINE from collections import defaultdict , Counter NEW_LINE from itertools import product , groupby , count , permutations , combinations NEW_LINE from math import pi , sqrt , ceil , floor NEW_LINE from collections import deque NEW_LINE from bisect import bisect , bisect_left , bisect_right NEW_LINE from string import ascii_lowercase NEW_LINE INF = float ( " inf " ) NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE dy = [ 0 , - 1 , 0 , 1 ] NEW_LINE dx = [ 1 , 0 , - 1 , 0 ] NEW_LINE def inside ( y : int , x : int , H : int , W : int ) -> bool : return 0 <= y < H and 0 <= x < W NEW_LINE def main ( ) : NEW_LINE INDENT N , X = map ( int , input ( ) . split ( ) ) NEW_LINE w_list = [ int ( input ( ) ) for _ in range ( N ) ] NEW_LINE w_list1 , w_list2 = w_list [ : N // 2 ] , w_list [ N // 2 : ] NEW_LINE n = len ( w_list1 ) NEW_LINE s = [ ] NEW_LINE for b in range ( 2 ** n ) : NEW_LINE INDENT total = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if b & 1 << i : NEW_LINE INDENT total += w_list1 [ i ] NEW_LINE DEDENT DEDENT s . append ( total ) NEW_LINE DEDENT n = len ( w_list2 ) NEW_LINE d = defaultdict ( int ) NEW_LINE for b in range ( 2 ** n ) : NEW_LINE INDENT total = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if b & 1 << i : NEW_LINE INDENT total += w_list2 [ i ] NEW_LINE DEDENT DEDENT d [ total ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for a in s : NEW_LINE INDENT if a > X : NEW_LINE INDENT continue NEW_LINE DEDENT ans += d [ X - a ] NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT