message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251 | instruction | 0 | 67,040 | 23 | 134,080 |
"Correct Solution:
```
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
n, m, k = [int(_) for _ in input().split()]
mod = 10**9+7 #出力の制限
N = n * m
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
ans = 0
C = cmb(n * m - 2, k - 2, mod)
for d in range(1, n):
ans += ((n - d) * m ** 2) * d
ans %= mod
for d in range(1, m):
ans += ((m - d) * n ** 2) * d
ans %= mod
ans = (ans * C) % mod
print(ans)
``` | output | 1 | 67,040 | 23 | 134,081 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251 | instruction | 0 | 67,041 | 23 | 134,082 |
"Correct Solution:
```
n, m, k = map(int, input().split())
mod = 10**9 + 7
# (n * m - 2)C(k - 2)
# 距離xの組 - n - x + 1
# 横 n - x + 1
# 縦 m * m
ans = 0
for y in range(1, n):
ans += y * (n - y) * m * m % mod
for x in range(1, m):
ans += x * (m - x) * n * n % mod
def inv(x):
return pow(x, mod - 2, mod)
# comb
for i in range(k - 2):
ans = ans * (n * m - 2 - i) * inv(i + 1) % mod
print(ans)
``` | output | 1 | 67,041 | 23 | 134,083 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251 | instruction | 0 | 67,042 | 23 | 134,084 |
"Correct Solution:
```
n, m, k = map(int, input().split())
mod = 10**9 + 7
cum_n = 0
t = 0
for i in range(1, n):
t += i
cum_n += t
cum_m = 0
t = 0
for i in range(1, m):
t += i
cum_m += t
ans = (cum_n * m**2 + cum_m * n**2) % mod
def nCr(n,r,mod = 10**9+7):
r = min(n-r,r)
numer = denom = 1
for i in range(1,r+1):
numer = numer * (n+1-i) %mod
denom = denom * i % mod
return numer * pow(denom,mod-2,mod) %mod
if n*m-2 == 0:
p = 1
else:
p = nCr(n*m-2, k-2)
ans = (ans*p)%mod
print(ans)
``` | output | 1 | 67,042 | 23 | 134,085 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251 | instruction | 0 | 67,043 | 23 | 134,086 |
"Correct Solution:
```
def cmb(n, r):
return fact[n] * inv_fact[r] * inv_fact[n - r] % MOD
MOD = 10 ** 9 + 7
N, M, K = map(int, input().split())
fact = [1]
for i in range(1, N * M - 2 + 1):
fact.append(fact[-1] * i % MOD)
inv_fact = [-1] * (N * M - 1)
inv_fact[-1] = pow(fact[-1], MOD - 2, MOD)
for i in range(N * M - 3, -1, -1):
inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD
pat = cmb(N * M - 2, K - 2)
ans = 0
for i in range(M):
ans += i * (M - i) * N ** 2
for i in range(N):
ans += i * (N - i) * M ** 2
ans = (ans * pat) % MOD
print(ans)
``` | output | 1 | 67,043 | 23 | 134,087 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251 | instruction | 0 | 67,044 | 23 | 134,088 |
"Correct Solution:
```
def cmb(n,r,mod):
if r<0 or r>n:
return 0
r=min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
N,M,k=map(int,input().split())
m=10**9+7
g1=[1,1]
g2=[1,1]
inverse=[0,1]
for i in range(2,N*M):
g1.append((g1[-1]*i)%m)
inverse.append((-inverse[m%i]*(m//i))%m)
g2.append((g2[-1]*inverse[-1])%m)
c=cmb(N*M-2,k-2,m)
ans=0
for i in range(N):
ans+=((N-i)*M*M*i*c)%m
ans%=m
for i in range(M):
ans+=((M-i)*N*N*i*c)%m
ans%=m
print(ans%m)
``` | output | 1 | 67,044 | 23 | 134,089 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251
Submitted Solution:
```
N,M,K = map(int,input().split())
MOD = 10**9+7
a = 0
for i in range(N):
j = N-1-i
a += i*(i+1)//2 + j*(j+1)//2
b = 0
for i in range(M):
j = M-1-i
b += i*(i+1)//2 + j*(j+1)//2
MAX = N*M+5
fac = [1,1] + [0]*MAX
finv = [1,1] + [0]*MAX
inv = [0,1] + [0]*MAX
for i in range(2,MAX+2):
fac[i] = fac[i-1] * i % MOD
inv[i] = -inv[MOD%i] * (MOD // i) % MOD
finv[i] = finv[i-1] * inv[i] % MOD
def ncr(n,r):
if n < r: return 0
if n < 0 or r < 0: return 0
return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD
ans = (a * inv[N]**2 + b * inv[M]**2) * inv[N*M-1] * (N*M)
ans *= K*(K-1)//2
ans *= ncr(N*M, K)
print(ans % MOD)
``` | instruction | 0 | 67,045 | 23 | 134,090 |
Yes | output | 1 | 67,045 | 23 | 134,091 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251
Submitted Solution:
```
mod = 10 ** 9 + 7
kkai = [1]
for i in range(1, 3 * 10 ** 5):
kkai.append(kkai[-1] * i % mod)
def kai(x, p=mod):
return kkai[x]
def comb(a, b, p=mod):
if a < 0 or b < 0:
return 0
elif a < b:
return 0
c = 1
c *= kai(a, p)
c *= pow(kai(b, p), p - 2, p)
c *= pow(kai(a - b, p), p - 2, p)
return c % p
n, m, k = [int(i) for i in input().split()]
ans = 0
for i in range(1, n):
ans += (n - i) * i * comb(n * m - 2, k - 2) * m ** 2
ans %= mod
for i in range(1, m):
ans += (m - i) * i * comb(n * m - 2, k - 2) * n ** 2
ans %= mod
print(ans)
``` | instruction | 0 | 67,046 | 23 | 134,092 |
Yes | output | 1 | 67,046 | 23 | 134,093 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251
Submitted Solution:
```
MOD = 10**9+7
N,M,K = map(int,input().split())
U = N*M
fact = [1]*(U+1)
for i in range(1,U+1):
fact[i] = (fact[i-1]*i)%MOD
def comb(n,k):
x = fact[n]
x *= pow(fact[n-k],MOD-2,MOD)
x %= MOD
x *= pow(fact[k],MOD-2,MOD)
return x
res = 0
for i in range(1,N):
res += i*M*M*(N-i)%MOD
res %= MOD
for i in range(1,M):
res += i*N*N*(M-i)%MOD
res %= MOD
res *= comb(N*M-2,K-2)
res %= MOD
print(res)
``` | instruction | 0 | 67,047 | 23 | 134,094 |
Yes | output | 1 | 67,047 | 23 | 134,095 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251
Submitted Solution:
```
def init():
global factorial
MOD = 10 ** 9 + 7
factorial = [0] * 200001
factorial[0] = 1
for i in range(1, 200001):
factorial[i] = (factorial[i - 1] * i) % MOD
def main():
init()
n, m, k = map(int, input().split())
s = 0
MOD = 10 ** 9 + 7
for i in range(n):
s += (((((n - 1 - i) * (n - i)) // 2) % MOD) * ((m * m) % MOD)) % MOD
for i in range(m):
s += (((((m - 1 - i) * (m - i)) // 2) % MOD) * ((n * n) % MOD)) % MOD
print((((s * ((factorial[n * m - 2] * pow(factorial[k - 2], MOD - 2, MOD)) % MOD)) % MOD) * pow(factorial[n * m - k], MOD - 2, MOD)) % MOD)
main()
``` | instruction | 0 | 67,048 | 23 | 134,096 |
Yes | output | 1 | 67,048 | 23 | 134,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251
Submitted Solution:
```
from operator import mul
from functools import reduce
def cmb(n,r):
r = min(n-r,r)
if r == 0: return 1
over = reduce(mul, range(n, n - r, -1))
under = reduce(mul, range(1,r + 1))
return over // under
N, M, K = map(int, input().split())
c = cmb(N*M-2,K-2)
ans = c * (M**2 * (N**2 * (N+1)//2 - N*(N+1)*(2*N+1)//6) + N**2 * (M**2 * (M+1)//2 - M*(M+1)*(2*M+1)//6)) % 1000000007
print(ans)
``` | instruction | 0 | 67,049 | 23 | 134,098 |
No | output | 1 | 67,049 | 23 | 134,099 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251
Submitted Solution:
```
a, b, c = map(int,input().split())
e = [23] * 3000000
e[-1] += 1
for i in range(100):
w = max(e)
print(1)
``` | instruction | 0 | 67,050 | 23 | 134,100 |
No | output | 1 | 67,050 | 23 | 134,101 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251
Submitted Solution:
```
n, m, k = map(int, input().split())
mod = 10**9+7
N = 10**5+50
fac = [1]*(N+1)
finv = [1]*(N+1)
for i in range(N):
fac[i+1] = fac[i] * (i+1) % mod
finv[-1] = pow(fac[-1], mod-2, mod)
for i in reversed(range(N)):
finv[i] = finv[i+1] * (i+1) % mod
def cmb1(n, r, mod):
if r <0 or r > n:
return 0
r = min(r, n-r)
return fac[n] * finv[r] * finv[n-r] % mod
ans = 0
for i in range(n*m):
x, y = divmod(i, m)
# x
ans += x*m*cmb1(n*m-2, k-2, mod)*x
ans -= (n-1-x)*m*cmb1(n*m-2, k-2, mod)*x
# y
ans += y*n*cmb1(n*m-2, k-2, mod)*y
ans -= (m-1-y)*n*cmb1(n*m-2, k-2, mod)*y
ans %= mod
print(ans)
``` | instruction | 0 | 67,051 | 23 | 134,102 |
No | output | 1 | 67,051 | 23 | 134,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is computed as:
\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)
Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo 10^9+7.
We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.
Constraints
* 2 \leq N \times M \leq 2 \times 10^5
* 2 \leq K \leq N \times M
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the sum of the costs of all possible arrangements of the pieces, modulo 10^9+7.
Examples
Input
2 2 2
Output
8
Input
4 5 4
Output
87210
Input
100 100 5000
Output
817260251
Submitted Solution:
```
from math import factorial
def comb(n, r):
return factorial(n) // (factorial(n - r) * factorial(r))
N,M,K = map(int,input().split())
C = comb(N*M-2, K-2)
print(int(C))
A = int(0)
for d in range(N):
a = (N-d)*(M**2)
A += int(d*a)
B = int(0)
for d in range(M):
b = (M-d)*(N**2)
B += int(d*b)
ans = int((A+B)*C)
print(ans)
``` | instruction | 0 | 67,052 | 23 | 134,104 |
No | output | 1 | 67,052 | 23 | 134,105 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image> | instruction | 0 | 67,658 | 23 | 135,316 |
Tags: implementation, math
Correct Solution:
```
a, b = [int(i) for i in input().split()]
count = 0
while a and b:
if a > b:
n, a = divmod(a, b)
else:
n, b = divmod(b, a)
count += n
print(count)
``` | output | 1 | 67,658 | 23 | 135,317 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image> | instruction | 0 | 67,659 | 23 | 135,318 |
Tags: implementation, math
Correct Solution:
```
a,b = list(map(int,input().split()))
ans = 0
while True:
if b>a:
a,b = b,a
if a%b==0:
ans+=a//b
break
else:
ans+=a//b
a = a%b
print(ans)
``` | output | 1 | 67,659 | 23 | 135,319 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image> | instruction | 0 | 67,660 | 23 | 135,320 |
Tags: implementation, math
Correct Solution:
```
f = lambda: input()
a,b = map(int, f().split())
c = 0
while( a != b and a != 0 and b != 0):
lo = min(a, b)
hi = max(a, b)
a = hi % lo
b = lo
c += int(hi / lo)
print(c)
``` | output | 1 | 67,660 | 23 | 135,321 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image> | instruction | 0 | 67,661 | 23 | 135,322 |
Tags: implementation, math
Correct Solution:
```
a,b = map(int,input().split())
k = 0
while b > 0:
k += a // b
a, b= b, a % b
print(k)
``` | output | 1 | 67,661 | 23 | 135,323 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image> | instruction | 0 | 67,662 | 23 | 135,324 |
Tags: implementation, math
Correct Solution:
```
a, b = map(int, input().split())
ret = 0
while 1:
if a is b or b == 0:
break
ret += a // b
a, b = max(b, a % b), min(b, a % b)
print(ret)
``` | output | 1 | 67,662 | 23 | 135,325 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image> | instruction | 0 | 67,663 | 23 | 135,326 |
Tags: implementation, math
Correct Solution:
```
#!/c/Python34/python
# coding: utf-8
def main():
[a, b] = map(int, input().split())
ans = 0
while 1:
if a > b:
ans += a//b
if a % b == 0:
break
a = a % b
else:
ans += b//a
if b % a == 0:
break
b = b % a
print(ans)
return
if __name__ == '__main__':
main()
``` | output | 1 | 67,663 | 23 | 135,327 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image> | instruction | 0 | 67,664 | 23 | 135,328 |
Tags: implementation, math
Correct Solution:
```
x,y =map(int, input().split())
count1 = 0
while min(x,y)>0:
(x,y) = (max(x,y), min(x,y))
count1 += x//y
x = x%y
print(count1)
``` | output | 1 | 67,664 | 23 | 135,329 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image> | instruction | 0 | 67,665 | 23 | 135,330 |
Tags: implementation, math
Correct Solution:
```
d = [int(x) for x in input().split()]
a,b = d[0], d[1]
sq = 0
while a != b and a != 0 and b != 0:
if a > b:
x = a//b
sq += x
a -= x*b
else:
x = b//a
sq += x
b -= x*a
if a == b:
print(sq+1)
else:
print(sq)
``` | output | 1 | 67,665 | 23 | 135,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image>
Submitted Solution:
```
s = input().split()
for i in range(2):
s[i]=int(s[i])
s = sorted(s)
a = int(s[1])
b = int(s[0])
res=1
hooks=int(1)
if a%b==0:
print(int(a/b))
hooks=int(2)
else:
while True:
if a%2==0 and b%2==0:
a=int(a/2)
b=int(b/2)
else:
break
if a>(b**2):
res+=a//b
a,b=max(b,a-(b*(a//b))),min(b,a-(b*(a//b)))
while a!=b and a>0 and b>0:
a,b=max(b,(a-b)),min(b,(a-b))
if a%b==0:
res+=int(a/b)
print(res)
hooks=int(2)
break
res+=1
if hooks==1:
print(res)
``` | instruction | 0 | 67,666 | 23 | 135,332 |
Yes | output | 1 | 67,666 | 23 | 135,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image>
Submitted Solution:
```
n,m=map(int,input().split())
s=0
while n!=m and n!=0 and m!=0:
n,m=max(n,m),min(n,m)
s+=n//m
n=n%m
print(s)
``` | instruction | 0 | 67,667 | 23 | 135,334 |
Yes | output | 1 | 67,667 | 23 | 135,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image>
Submitted Solution:
```
import math
from decimal import *
getcontext().prec = 30
a,b=map(int,input().split())
ans=0
def fn():
global a,b
if a<b:
a,b=b,a
if (a-b)%b==0:
x=(a-b)//b
a-=a
b-=b
return x+1
x=math.ceil((a-b)/b)
a-=x*b
return x
while a*b:
#print(a,b)
ans+=fn()
print(ans)
``` | instruction | 0 | 67,668 | 23 | 135,336 |
Yes | output | 1 | 67,668 | 23 | 135,337 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image>
Submitted Solution:
```
def how_many_squares(A, B):
remainder = 0
if A > B:
return A // B, A % B, B
elif B > A:
return B // A, B % A, A
else:
return 1, 0, 0
A, B = [int(x) for x in input().split()]
total_count = 0
while A != 0 and B != 0:
count, A, B = how_many_squares(A, B)
total_count += count
print(total_count)
``` | instruction | 0 | 67,669 | 23 | 135,338 |
Yes | output | 1 | 67,669 | 23 | 135,339 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image>
Submitted Solution:
```
a, b = list(map(int, input().split()))
ans = 0
while a > 0 and b > 0:
if a >= b:
ans = ans + a / b
a = a % b
else:
ans = ans + b / a
b = b % a
print(ans)
``` | instruction | 0 | 67,670 | 23 | 135,340 |
No | output | 1 | 67,670 | 23 | 135,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image>
Submitted Solution:
```
a,b=[int(x) for x in input().split()]
k=0
while a>1 and b>1:
if a>b:
k+=a//b
a=a-(a//b)*b
else:
k+=b//a
b=b-a*(b//a)
print(k+abs(a-b)+1)
``` | instruction | 0 | 67,671 | 23 | 135,342 |
No | output | 1 | 67,671 | 23 | 135,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image>
Submitted Solution:
```
a,b=map(int, input().split())
n=0
y=0
while a!=b and y==0:
if b>a:
x=b
b=a
a=x
if b==1:
y=1
n+=a-2
if b==2:
y=1
n+=a//2-2
a=a-b
n+=1
print(n+1)
``` | instruction | 0 | 67,672 | 23 | 135,344 |
No | output | 1 | 67,672 | 23 | 135,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
<image>
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Examples
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
Note
Pictures to the first and second sample test.
<image>
Submitted Solution:
```
a, b = tuple(map(int, input().split(' ')))
ships = 1
while a != b:
a = a - b
if b > a:
a, b = b, a
if b == 1:
ships += a
break
if b == 2:
ships += a//2
break
else:
ships += 1
print(ships)
``` | instruction | 0 | 67,673 | 23 | 135,346 |
No | output | 1 | 67,673 | 23 | 135,347 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle. | instruction | 0 | 67,674 | 23 | 135,348 |
Tags: brute force, combinatorics, data structures, geometry, math, sortings
Correct Solution:
```
def main():
import sys
from collections import defaultdict
from fractions import gcd
precalc_gcd = [[gcd(i, j) for j in range(201)] for i in range(201)]
tokens = [int(i) for i in sys.stdin.read().split()]
tokens.reverse()
n = tokens.pop()
points = [(tokens.pop(), tokens.pop()) for i in range(n)]
result = 0
for i in range(n):
x0, y0 = points[i]
angles = defaultdict(int)
for j in range(i + 1, n):
x, y = points[j]
x -= x0
y -= y0
if x < 0 or x == 0 and y < 0:
x = -x
y = -y
g = precalc_gcd[abs(x)][abs(y)]
x //= g
y //= g
angles[x * 1000 + y] += 1
for j in angles.keys():
result += angles[j] * (n - i - 1 - angles[j])
print(result // 2)
main()
``` | output | 1 | 67,674 | 23 | 135,349 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle. | instruction | 0 | 67,675 | 23 | 135,350 |
Tags: brute force, combinatorics, data structures, geometry, math, sortings
Correct Solution:
```
__author__ = 'JS'
n = int(input())
k = [0] * 2015
X = [0] * 2015
Y = [0] * 2015
eps = 1e-12
for i in range (n):
X[i], Y[i] = map(int, input().split(" "))
ans = (n-2) * (n-1) * n // 6
sum = 0
for i in range (n):
tot = 0
cnt = 0
for j in range (i+1, n):
if X[i] != X[j]:
k[tot] = (Y[j] - Y[i]) / (X[j] - X[i])
tot += 1
else:
cnt += 1
#cnt -= 1
sum += (cnt - 1) * cnt // 2
k = sorted(k[:tot]) + k[tot:]
cnt = 1
for j in range (1, tot):
if abs(k[j] - k[j-1]) < eps:
cnt += 1
else:
sum += (cnt - 1) * cnt // 2
cnt = 1
sum += (cnt -1) * cnt // 2
ans -= sum
print(ans)
``` | output | 1 | 67,675 | 23 | 135,351 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle. | instruction | 0 | 67,676 | 23 | 135,352 |
Tags: brute force, combinatorics, data structures, geometry, math, sortings
Correct Solution:
```
from fractions import *
n,s=int(input()),0
p=[tuple(map(int, input().split())) for _ in range(n)]
def f(a,b): g=gcd(a,b);return a//g + 1024*1024*(b//g)
for i in range(n):
k,(x,y)=0,p[i]
l=sorted(f(x-X, y-Y) for X,Y in p[:i])
for j in range(1, i):
k=k+1 if l[j]==l[j-1] else 0
s+=k
print(n*(n-1)*(n-2)//6-s)
``` | output | 1 | 67,676 | 23 | 135,353 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle. | instruction | 0 | 67,677 | 23 | 135,354 |
Tags: brute force, combinatorics, data structures, geometry, math, sortings
Correct Solution:
```
def main():
import sys
from collections import defaultdict
from fractions import gcd
normalize = [[0] * 405 for i in range(405)]
for x in range(-200, 201):
for y in range(-200, 201):
if x == 0 and y == 0:
continue
nx, ny = x, y
g = abs(gcd(x, y))
nx //= g
ny //= g
if nx < 0 or nx == 0 and ny < 0:
nx = -nx
ny = -ny
nx += 200
ny += 200
normalize[x][y] = nx * 401 + ny
tokens = [int(i) for i in sys.stdin.read().split()]
tokens.reverse()
n = tokens.pop()
points = [(tokens.pop(), tokens.pop()) for i in range(n)]
result = n * (n - 1) * (n - 2) // 6
angles = [0] * 170000
for i in range(n):
x0, y0 = points[i]
for j in range(i + 1, n):
x, y = points[j]
v = normalize[x - x0][y - y0]
result -= angles[v]
angles[v] += 1
for j in range(i + 1, n):
x, y = points[j]
angles[normalize[x - x0][y - y0]] = 0
print(result)
main()
``` | output | 1 | 67,677 | 23 | 135,355 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle. | instruction | 0 | 67,678 | 23 | 135,356 |
Tags: brute force, combinatorics, data structures, geometry, math, sortings
Correct Solution:
```
def main():
import sys
from collections import defaultdict
from fractions import gcd
normalize = [[0] * 405 for i in range(405)]
for x in range(-200, 201):
for y in range(-200, 201):
if x == 0 and y == 0:
continue
nx, ny = x, y
g = abs(gcd(x, y))
nx //= g
ny //= g
if nx < 0 or nx == 0 and ny < 0:
nx = -nx
ny = -ny
nx += 200
ny += 200
normalize[x][y] = nx * 401 + ny
tokens = [int(i) for i in sys.stdin.read().split()]
tokens.reverse()
n = tokens.pop()
points = [(tokens.pop(), tokens.pop()) for i in range(n)]
result = n * (n - 1) * (n - 2) // 6
angles = [0] * 162000
for i in range(n):
x0, y0 = points[i]
for j in range(i + 1, n):
x, y = points[j]
v = normalize[x - x0][y - y0]
result -= angles[v]
angles[v] += 1
for j in range(i + 1, n):
x, y = points[j]
angles[normalize[x - x0][y - y0]] = 0
sys.stdout.write(str(result))
main()
``` | output | 1 | 67,678 | 23 | 135,357 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle. | instruction | 0 | 67,679 | 23 | 135,358 |
Tags: brute force, combinatorics, data structures, geometry, math, sortings
Correct Solution:
```
n = int(input())
p = []
for _ in range(n):
x, y = input().split()
p.append((int(x), int(y)))
k = []
from math import gcd
def getk(x1, y1, x2, y2):
if x1 == x2: return (1, 0)
if y1 == y2: return (0, 1)
num = y2 - y1
den = x2 - x1
g = gcd(abs(num), abs(den))
num //= g
den //= g
if den < 0:
num = -num
den = -den
return (num, den)
for i in range(n):
tk = {}
for j in range(n):
if i == j: continue
tmp = getk(*p[i], *p[j])
tk[getk(*p[i], *p[j])] = tk.get(tmp, 0) + 1
k.append(tk)
ans = 0
for i in range(n):
for j in range(i + 1, n):
ans += n - 1 - k[i][getk(*p[i], *p[j])]
print(ans // 3)
# print(k)
``` | output | 1 | 67,679 | 23 | 135,359 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle. | instruction | 0 | 67,680 | 23 | 135,360 |
Tags: brute force, combinatorics, data structures, geometry, math, sortings
Correct Solution:
```
import math
n=int(input())
def nc2(n):
return ((n)*(n-1))//2
points=[]
ans=0
for i in range(n):
points.append(list(map(int,input().split())))
for i in range(n):
dct={}
for j in range(i+1,n):
if(i==j):
continue
a=points[i][1]-points[j][1]
b=points[i][0]-points[j][0]
x=math.gcd(a,b)
a//=x
b//=x
if(b<0 or (b==0 and a<0)):
a*=-1
b*=-1
s=str(a)+"/"+str(b)
if s in dct:
dct[s]+=1
else:
dct[s]=1
ans+=nc2(n-i-1)
for k in dct:
ans-=nc2(dct[k])
# print(dct,ans)
print(ans)
``` | output | 1 | 67,680 | 23 | 135,361 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle. | instruction | 0 | 67,681 | 23 | 135,362 |
Tags: brute force, combinatorics, data structures, geometry, math, sortings
Correct Solution:
```
from fractions import *
n=int(input())
s=n*(n-1)*(n-2)//6
p=[list(map(int,input().split()))for _ in range(n)]
for i in range(n):
k,l=0,sorted(1e9 if p[i][1]==Y else (p[i][0]-X)/(p[i][1]-Y)for X,Y in p[:i])
for j in range(1,i):k=k+1 if l[j]==l[j-1]else 0;s-=k
print(s)
``` | output | 1 | 67,681 | 23 | 135,363 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle.
Submitted Solution:
```
n=int(input())
s=n*(n-1)*(n-2)//6
p=[list(map(int,input().split()))for _ in range(n)]
for i in range(n):
k,l=0,sorted(1e9 if p[i][1]==Y else (p[i][0]-X)/(p[i][1]-Y)for X,Y in p[:i])
for j in range(1,i):k=k+1 if l[j]==l[j-1]else 0;s-=k
print(s)
``` | instruction | 0 | 67,682 | 23 | 135,364 |
Yes | output | 1 | 67,682 | 23 | 135,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle.
Submitted Solution:
```
import random, math, sys
from copy import deepcopy as dc
from bisect import bisect_left, bisect_right
from collections import Counter
input = sys.stdin.readline
# Function to call the actual solution
def solution(li):
n = len(li)
co = (n * (n-1) *(n-2))/6
for i in range(len(li)):
x, y = li[i]
ma = {}
for j in range(i+1, n):
x1, y1 = li[j]
if x1-x == 0:
slope = 1e999
else:
slope = (y1-y)/(x1-x)
if slope not in ma:
ma[slope] = 0
co -= ma[slope]
ma[slope] += 1
return int(co)
# Function to take input
def input_test():
li1 = []
for _ in range(int(input())):
# n = int(input())
# x, y = map(int, input().strip().split(" "))
# a, b, c = map(int, input().strip().split(" "))
li = list(map(int, input().strip().split(" ")))
li1.append(li)
out = solution(li1)
print(out)
# Function to test my code
def test():
pass
input_test()
# test()
``` | instruction | 0 | 67,683 | 23 | 135,366 |
Yes | output | 1 | 67,683 | 23 | 135,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle.
Submitted Solution:
```
from fractions import gcd
import sys
def solve():
n = int(input())
if n < 3:
print(0)
return
xs, ys = list(), list()
for i in range(n):
x, y = map(int, input().split())
xs.append(x)
ys.append(y)
mem = [0] * 2002
for i in range(n):
slopes = dict()
x, y = xs[i], ys[i]
for o in range(n):
if o != i:
xo, yo = xs[o], ys[o]
xdiff, ydiff = x - xo, y - yo
div = gcd(xdiff, ydiff)
xdiff //= div
ydiff //= div
tup = (xdiff, ydiff)
if tup in slopes:
slopes[tup] += 1
else: slopes[tup] = 2
for val in slopes:
mem[slopes[val]] += 1
for i in range(2, len(mem)):
mem[i] //= i
res = fact(n, 3)
for i in range(3, len(mem)):
res -= mem[i] * fact(i, 3)
print(res)
def fact(n, k):
large, small = max(k, n - k), min(k, n - k)
res = 1
for i in range(large + 1, n + 1): res *= i
for i in range(2, small + 1): res //= i
return res
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()
``` | instruction | 0 | 67,684 | 23 | 135,368 |
Yes | output | 1 | 67,684 | 23 | 135,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle.
Submitted Solution:
```
import math
n = int(input())
c = []
l = []
for i in range(n):
l.append(tuple(map(int, input().split())))
s = set(l.copy())
l.sort()
if n < 3:
print(0)
else:
ct = 0
for i in range(n-2):
for j in range(i+1, n-1):
ap = n-j-1
pta = l[i]
ptb = l[j]
rs = l[j][1]-l[i][1]
rn = l[j][0]-l[i][0]
g = math.gcd(rs, rn)
rs //= g
rn //= g
x = l[j][0]+rn
y = l[j][1]+rs
while x <= 100 and y <= 100:
if (x, y) in s:
ap -= 1
x += rn
y += rs
ct += ap
# print(i, j, ap, ct)
print(ct)
``` | instruction | 0 | 67,685 | 23 | 135,370 |
Yes | output | 1 | 67,685 | 23 | 135,371 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle.
Submitted Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
import heapq
raw_input = stdin.readline
pr = stdout.write
def in_num():
return int(raw_input())
def in_arr():
return map(int,raw_input().split())
def pr_num(n):
stdout.write(str(n)+'\n')
def pr_arr(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return map(int,stdin.read().split())
range = xrange # not for python 3.0+
n=in_num()
l=[]
for i in range(n):
x,y=in_arr()
l.append((x,y))
ans=(n*(n-1)*(n-2))/6
d=defaultdict(set)
for i in range(n):
for j in range(i+1,n):
a,b=l[j][1]-l[i][1],l[i][0]-l[j][0]
if not a:
a,b=0,1
elif not b:
a,b=1,0
c=-((a*l[i][0])+(b*l[i][1]))
d[(a,b,c)].add(i)
d[(a,b,c)].add(j)
#ans=0
for i in d:
x=len(d[i])
ans-=(x*(x-1)*(x-2))/6
pr_num(ans)
``` | instruction | 0 | 67,686 | 23 | 135,372 |
No | output | 1 | 67,686 | 23 | 135,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle.
Submitted Solution:
```
from fractions import gcd
from collections import defaultdict
N = int(input())
directs = defaultdict(dict)
points = []
for i in range(N):
x, y = map(int, input().split())
points.append( (x, y) )
mapping = {}
isum = 0
for i in range(2001):
isum += i
mapping[isum] = i+1
points.sort()
for i in range(N):
for j in range(i+1, N):
dx = points[j][0]-points[i][0]
dy = points[j][1]-points[i][1]
_gcd = gcd(dx, dy)
dx = int(dx / _gcd if _gcd else dx)
dy = int(dy / _gcd if _gcd else dy)
x = int( (points[i][0] + 100) % dx if dx else (points[i][0] + 100) )
y = int( (points[i][1] + 100) % dy if dy else (points[i][1] + 100) )
if (dx, dy) not in directs[(x, y)]:
directs[(x,y)][(dx,dy)] = 1
else:
directs[(x,y)][(dx,dy)] += 1
res = int(N*(N-1)*(N-2)/3/2)
for key in directs.keys():
for a_key in directs[key]:
num = directs[key][a_key]
if num in mapping:
num = mapping[num]
if num >= 3:
num = (N-num) * int(num*(num-1)*(num-2)/3/2)
res -= num
print( int(res) )
``` | instruction | 0 | 67,687 | 23 | 135,374 |
No | output | 1 | 67,687 | 23 | 135,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle.
Submitted Solution:
```
def gcd(dx, dy):
if dy==0: return dx
return gcd(dy, dx%dy)
def cleand(dx,dy):
if dx<0:
dx = -dx
dy = -dy
if dx!=0 and dy!=0:
g = gcd(dx, abs(dy))
dx /= g
dy /= g
return (dx,dy)
def nc3(n):
if n<3: return 0
return int(n*(n-1)*(n-2)/6)
def main():
n = int(input())
vts = []
for _ in range(n):
rds = input().split()
x = int(rds[0])
y = int(rds[1])
vts.append((x,y))
ans = nc3(n)
mtset = set()
for va in vts:
lines = {}
for vb in vts:
if va==vb or (va,vb) in mtset or (vb,va) in mtset: continue
dx = va[0]-vb[0]
dy = va[1]-vb[1]
dx,dy = cleand(dx,dy)
if (dx,dy) not in lines:
lines[(dx,dy)] = [va]
lines[(dx,dy)].append(vb)
for key,vs in lines.items():
for v0 in vs:
for v1 in vs:
if v0 == v1: continue
mtset.add((v0,v1))
ll = len(vs)
if ll >= 3:
ans -= nc3(ll)
print(ans)
if __name__=='__main__':
main()
``` | instruction | 0 | 67,688 | 23 | 135,376 |
No | output | 1 | 67,688 | 23 | 135,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle.
Submitted Solution:
```
from sys import stdin
from collections import defaultdict
from math import atan2, degrees
rints = lambda: [int(x) for x in stdin.readline().split()]
rints_2d = lambda n: [rints() for _ in range(n)]
def slop():
deg = degrees(atan2(a[j][1] - a[i][1], a[j][0] - a[i][0]))
if deg == 180:
deg = 0
elif abs(deg) == 90:
deg = 90
return (deg + 180) % 180
n = int(input())
a, ans, mem = rints_2d(n), 0, defaultdict(int)
for i in range(n - 1):
for j in range(i + 1, n):
slope = slop()
mem[i, slope] += 1
for i in range(n - 1):
for j in range(i + 1, n):
slope = slop()
ans += (n - (i + 2)) - (mem[i, slope] - 1)
# print(ans)
print(ans // 2)
``` | instruction | 0 | 67,689 | 23 | 135,378 |
No | output | 1 | 67,689 | 23 | 135,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Examples
Input
4
0 0
1 1
2 0
2 2
Output
3
Input
3
0 0
1 1
2 0
Output
1
Input
1
1 1
Output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle.
Submitted Solution:
```
import itertools
def factorial(n):
num = 1
while n >= 1:
num = num * n
n = n - 1
return num
def dependency(subset):
x = subset[1][0] * subset[0][0] - subset[1][1] * subset[0][1]
y = subset[1][0] * subset[2][0] - subset[1][1] * subset[2][1]
if x == 0 and y == 0:
return True
return False
n = int(input())
pos = []
if n < 3:
print(0)
exit(0)
for i in range(n):
x, y = map(int,input().split())
pos.append((x,y))
max = factorial(n)/(factorial(3)*factorial(n-3))
for subset in itertools.combinations(pos, 3):
if dependency(subset):
max = max -1
print(max)
``` | instruction | 0 | 67,690 | 23 | 135,380 |
No | output | 1 | 67,690 | 23 | 135,381 |
Provide a correct Python 3 solution for this coding contest problem.
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D.
Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
Constraints
* All input values are integers.
* 1≤A≤10^4
* 1≤B≤10^4
* 1≤C≤10^4
* 1≤D≤10^4
Input
The input is given from Standard Input in the following format:
A B C D
Output
Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
Examples
Input
3 5 2 7
Output
15
Input
100 600 200 300
Output
60000 | instruction | 0 | 68,005 | 23 | 136,010 |
"Correct Solution:
```
[A,B,C,D] = list(map(int,input().split()))
print(max(A*B,C*D))
``` | output | 1 | 68,005 | 23 | 136,011 |
Provide a correct Python 3 solution for this coding contest problem.
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D.
Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
Constraints
* All input values are integers.
* 1≤A≤10^4
* 1≤B≤10^4
* 1≤C≤10^4
* 1≤D≤10^4
Input
The input is given from Standard Input in the following format:
A B C D
Output
Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
Examples
Input
3 5 2 7
Output
15
Input
100 600 200 300
Output
60000 | instruction | 0 | 68,006 | 23 | 136,012 |
"Correct Solution:
```
a,b,c,d = map(int, input().split(" "))
print(max(a*b, c*d))
``` | output | 1 | 68,006 | 23 | 136,013 |
Provide a correct Python 3 solution for this coding contest problem.
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D.
Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
Constraints
* All input values are integers.
* 1≤A≤10^4
* 1≤B≤10^4
* 1≤C≤10^4
* 1≤D≤10^4
Input
The input is given from Standard Input in the following format:
A B C D
Output
Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
Examples
Input
3 5 2 7
Output
15
Input
100 600 200 300
Output
60000 | instruction | 0 | 68,007 | 23 | 136,014 |
"Correct Solution:
```
a,b,c,d = map(int,input().split())
aa = a * b
ab = c * d
print(max(aa,ab))
``` | output | 1 | 68,007 | 23 | 136,015 |
Provide a correct Python 3 solution for this coding contest problem.
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D.
Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
Constraints
* All input values are integers.
* 1≤A≤10^4
* 1≤B≤10^4
* 1≤C≤10^4
* 1≤D≤10^4
Input
The input is given from Standard Input in the following format:
A B C D
Output
Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
Examples
Input
3 5 2 7
Output
15
Input
100 600 200 300
Output
60000 | instruction | 0 | 68,008 | 23 | 136,016 |
"Correct Solution:
```
# cook your dish here
a,b,c,d= map(int,input().split())
print(max([a*b,c*d]))
``` | output | 1 | 68,008 | 23 | 136,017 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.