#include<bits/stdc++.h> usingnamespace std; #define int long long intread() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x= x * 10 + ch - '0'; ch = getchar(); } return x * f; }
signedmain(){ int n = read(); vector<int> a(n); int ans = 0; for(int i = 0; i < n; i++) a[i] = read(); for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) ans += a[i] * a[j]; cout << ans << endl; return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long intread() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x= x * 10 + ch - '0'; ch = getchar(); } return x * f; }
signedmain(){ int n = read(); vector<int> l(n); for(int i = 0; i < n; i++) l[i] = read(); sort(l.begin(), l.end()); int ans = 0; for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) { int x = (lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin()); ans += x - j - 1; } cout << ans << endl; return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long intread() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x= x * 10 + ch - '0'; ch = getchar(); } return x * f; }
constint N = 310, M = N * N; int dis[N][N], h[N], idx; /** struct Edge { int e, ne, w; }E[M]; void add(int a, int b, int c) { E[idx] = {b, h[a], c}; h[a] = idx++; } */ signedmain() { int n = read(), m = read(), l = read(); memset(dis, 0x3f, sizeof dis); for(int i = 0; i < m; i++) { int a = read(), b = read(); dis[a][b] = dis[b][a] = read(); } for (int i = 1; i <= n; i++) dis[i][i] = 0; for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) { if (i == j) dis[i][j] = 0; elseif (dis[i][j] <= l) dis[i][j] = 1; else dis[i][j] = 0x3f3f3f3f; } for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); int q = read(); for(int i = 0; i < q; i++) { int s = read(), t = read(); if(dis[s][t] == 0x3f3f3f3f) cout << -1 << endl; else cout << dis[s][t] - 1 << endl; } return0; }