A. Dars Vaqti
#include<iostream>
using namespace std;
int main(){
int s1, m1, s2, m2;
char b;
cin >> s1 >> b >> m1;
cin >> s2 >> b >> m2;
int res = (m2 - m1) * 60;
if(s2 < s1) res += (24 - s1 + s2) * 3600;
else res += (s2 - s1) * 3600;
cout << res;
return 0;
}
B. Behruzbek va Geometriya
#include<iostream>
using namespace std;
int main(){
int x1, x2 ,x3 ,y1, y2 ,y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
cout.precision(1);
cout << fixed << abs(1LL * x1 * (y2 - y3) + 1LL * x2 * (y3 - y1) + 1LL * x3 * (y1 - y2)) / 2.0;
return 0;
}
C. Static Range Sum Queries
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> tree, arr;
#define endl '\n'
const int mod = 1e9 + 7;
void build(int v, int l, int r){
if(l == r) tree[v] = arr[l - 1];
else{
int m = (l + r) / 2;
build(v * 2, l, m);
build(v * 2 + 1, m + 1, r);
tree[v] = tree[v * 2] + tree[v * 2 + 1];
}
}
int get(int v, int l, int r, int L, int R){
if(l == L && r == R){
return tree[v];
}
else{
int m = (l + r) / 2;
if(L > m) return get(v * 2 + 1, m + 1, r, L, R);
else if(R <= m) return get(v * 2, l, m, L, R);
return get(v * 2, l, m, L, m) + get(v * 2 + 1, m + 1, r, m + 1, R);
}
}
signed main(){
int n; cin >> n;
int q; cin >> q;
arr.resize(n);
for(int &x : arr) cin >> x;
tree.resize(4 * n);
build(1, 1, n);
for(int i = 0; i < q; i++){
int l, r;
cin >> l >> r;
cout << get(1, 1, n, l, r) << endl;
}
}
D. Noutbuk va PC
#include<bits/stdc++.h>
using namespace std;
struct BigInt{
vector<int> digits;
int sign;
void clear_leading_zeros(){
while(!digits.empty() && digits.back() == 0)
digits.pop_back();
if(digits.empty())
sign = 0;
}
BigInt(){
sign = 0;
}
BigInt(long long a){
*this = BigInt(to_string(a));
}
BigInt(string s){
if(s.empty()){
cerr << "Son kiritilmadi!\n";
exit(1);
}
if(!isdigit(s[0])){
if(s[0] == '+'){
*this = BigInt(s.substr(1));
}
else if(s[0] == '-'){
*this = BigInt(s.substr(1));
this->sign *= -1;
}
else{
cerr << "Butun son kiritilmadi!\n";
exit(2);
}
}
else{
sign = 1;
for(int i = (int)s.size() - 1; i >= 0; i --){
if(!isdigit(s[i])){
cerr << "Butun son kiritilmadi!\n";
exit(3);
}
digits.push_back(s[i] - 48);
}
clear_leading_zeros();
}
}
BigInt operator -(){
BigInt res = *this;
res.sign *= -1;
return res;
}
};
istream& operator >>(istream &cin, BigInt &a){
string s;
cin >> s;
a = BigInt(s);
return cin;
}
ostream& operator <<(ostream &cout, BigInt a){
if(a.sign == -1) cout << '-';
if(a.sign == 0) cout << 0;
for(int i = (int)a.digits.size() - 1; i >= 0; i --)
cout << a.digits[i];
return cout;
}
bool operator <(BigInt a, BigInt b){
if(a.sign != b.sign) return a.sign < b.sign;
if(a.sign == 0) return false;
if(a.digits.size() != b.digits.size())
return a.digits.size() * a.sign < b.digits.size() * b.sign;
int i = (int)a.digits.size() - 1;
while(i > 0 && a.digits[i] == b.digits[i]) i --;
return a.digits[i] * a.sign < b.digits[i] * b.sign;
}
bool operator >(BigInt a, BigInt b){
return b < a;
}
bool operator <= (BigInt a, BigInt b){
return !(b < a);
}
bool operator >= (BigInt a, BigInt b){
return !(a < b);
}
bool operator ==(BigInt a, BigInt b){
return a.sign == b.sign && a.digits == b.digits;
}
bool operator !=(BigInt a, BigInt b){
return !(a == b);
}
BigInt operator +(BigInt, BigInt);
BigInt operator -(BigInt a, BigInt b){
if(a.sign == 0) return -b;
if(b.sign == 0) return a;
if(b.sign == -1) return a + -b;
if(a.sign == -1) return -(-a+b);
if(a < b) return -(b-a);
for(int i = 0; i < a.digits.size(); i ++){
if(b.digits.size() > i)
a.digits[i] -= b.digits[i];
if(a.digits[i] < 0){
a.digits[i] += 10;
a.digits[i+1] --;
}
}
a.clear_leading_zeros();
return a;
}
BigInt operator +(BigInt a, BigInt b){
if(a.sign == 0) return b;
if(b.sign == 0) return a;
if(a.sign != b.sign){
if(a.sign == -1) return b - -a;
else return a - -b;
}
BigInt c;
c.sign = a.sign;
int d = 0, s;
for(int i = 0; i < a.digits.size() || i < b.digits.size(); i ++){
s = d;
if(a.digits.size() > i) s += a.digits[i];
if(b.digits.size() > i) s += b.digits[i];
c.digits.push_back(s%10);
d = s / 10;
}
if(d > 0) c.digits.push_back(d);
return c;
}
BigInt operator *(BigInt a, long long b){
if(b == 0 || a.sign == 0) return 0;
BigInt res;
res.sign = a.sign;
if(b < 0){
res.sign *= -1;
b = -b;
}
long long d = 0;
for(int i = 0; i < a.digits.size(); i ++){
d += a.digits[i] * b;
res.digits.push_back(d % 10);
d /= 10;
}
while(d > 0){
res.digits.push_back(d % 10);
d /= 10;
}
return res;
}
BigInt operator /(BigInt a, long long b){
if(a.sign == 0) return 0;
if(b == 0){
cerr << "0 ga bo'lish mumkin emas!\n";
exit(4);
}
BigInt res;
res.sign = a.sign;
if(b < 0){
res.sign = -res.sign;
b = -b;
}
long long q = 0;
for(int i = (int)a.digits.size() - 1; i >= 0; i --){
q = q * 10 + a.digits[i];
res.digits.push_back(q / b);
q %= b;
}
reverse(res.digits.begin(), res.digits.end());
res.clear_leading_zeros();
return res;
}
long long operator %(BigInt a, long long b){
if(a.sign == 0) return 0;
if(b == 0){
cerr << "0 ga qoldiqli bo'lish mumkin emas!\n";
exit(5);
}
if(b < 0)
b = -b;
long long q = 0;
for(int i = (int)a.digits.size() - 1; i >= 0; i --){
q = q * 10 + a.digits[i];
q %= b;
}
return q * a.sign;
}
BigInt operator *(BigInt a, BigInt b){
if(a.sign == 0 || b.sign == 0) return 0;
BigInt res;
res.sign = a.sign * b.sign;
res.digits.resize(a.digits.size() + b.digits.size());
for(int i = 0; i < a.digits.size(); i ++)
for(int j = 0; j < b.digits.size(); j ++)
res.digits[i+j] += a.digits[i] * b.digits[j];
for(int i = 0; i < res.digits.size(); i ++)
if(res.digits[i] > 9){
res.digits[i+1] += res.digits[i] / 10;
res.digits[i] %= 10;
}
res.clear_leading_zeros();
return res;
}
BigInt abs(BigInt a){
return (a < 0 ? -a : a);
}
int main(){
BigInt b, p, n;
cin >> b >> p >> n;
BigInt ans = (b + p * 8 / 10) - n;
cout << abs(ans);
}
E. Chiptalar son
n = int(input()) // 2
dp = [[0] * (n * 9 + 1) for i in range(n+1)]
dp[0][0] = 1
for x in range(1, n+1):
for s in range(x * 9 + 1):
dp[x][s] = sum(dp[x - 1][max(s - 9, 0): s + 1])
print(sum([x * x for x in dp[n]]))