akhauriyash/Code-Regression huggingface dataset:
import math
import collections
import fractions
import itertools

def solve():
    k,s = map(int, input().split())
    ans = 0
    for x in range(k+1):
        for y in range(k+1):
            z = s - x - y
            if 0 <= z <= k:
                ans += 1
    print(ans)
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 10412
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  map<int, int> ct;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ct[a[i]]++;
  }
  long res = 0;
  for (pair<int, int> p : ct) {
    long x = p.second;
    res += x*(x-1)/2;
  }
  for (int i = 0; i < n; ++i) {
    long x = ct[a[i]];
    long ores = res;
    ores -= x*(x-1)/2;
    ores += (x-1)*(x-2)/2;
    cout << ores << "\n";
  }
}


Measured memory_bytes: 8320
def solve1(n):
    # n = k ^ a
    res = []
    for i in xrange(1, 100):
        u = int(pow(n, 1.0 / i) + 0.1)
        if u ** i == n:
            res.append(u)
    return set(res)

def solve2(n):
    # n = a * k + 1
    m = n - 1

    i = 1
    res = set()
    while i * i <= m:
        if m % i == 0:
            res.add(i)
            res.add(m / i)
        i += 1
    return res ^ set([1])

def solve3(n):
    i = 2
    res = set()
    while i * i <= n:
        if n % i == 0:
            m = n / i
            while m and m % i == 0:
                m /= i
            if m % i == 1:
                res.add(i)
        i += 1
    return res

def brute_force(n):
    res = []
    for i in xrange(2, n + 1):
        m = n
        while m % i == 0:
            m /= i
        m %= i
        if m == 1:
            res.append(i)
    # print res
    return len(res)

def solve(n):
    s1 = solve1(n)
    s2 = solve2(n)
    s3 = solve3(n)
    # print sorted(s1 | s2 | s3)
    return len(s1 | s2 | s3)

assert solve(6) == 3
assert solve(3141) == 13
assert solve(314159265358) == 9

assert solve(10 ** 12)

import random
for i in xrange(2, 100):
    assert brute_force(i) == solve(i)

n = int(raw_input())
print solve(n)


Measured memory_bytes: 3444
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <stack>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr ll MAX_N = 100000 + 1;

vector<p> G[MAX_N + 1];
ll Nodes[MAX_N + 1];

bool dfs(ll node) {
    bool ret = true;
    for (auto g : G[node]) {
        ll n = g.first;
        ll w = g.second;
        if (Nodes[n] == INF) {
            Nodes[n] = Nodes[node] + w;
            ret &= dfs(n);
        } else if (Nodes[n] != Nodes[node] + w) {
            return false;
        }
    }

    return ret;
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M;
    cin >> N >> M;

    fill(Nodes + 1, Nodes + N + 1, INF);

    for (ll i = 0; i < M; i++) {
        ll l, r, d;
        cin >> l >> r >> d;
        G[l].push_back(p(r,  d));
        G[r].push_back(p(l, -d));
    }

    for (ll i = 1; i <= N; i++) {
        if (Nodes[i] == INF) {
            Nodes[i] = 0;
            if (!dfs(i)) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}



Measured memory_bytes: 16512
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define INF 5000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll N, K;
	cin >> N >> K;

	vector<ll> A(N);
	rep(i, N) {
		cin >> A[i];
		A[i]--;
	}
	

	vector<ll> a(N,INF);
	ll now = 0, cnt = 0;
	vector<ll> p;
	
	while (1) {
		if (a[now] != INF)  {
			p.push_back(now);
			ll loopcnt = cnt - a[now]; // ループしてる数
			ll loopstart = a[now]; // ループのスタート
			//cout << ((K - loopstart) % loopcnt) + loopstart + 1 << endl;
			if(K>=loopstart){
				ans = p[((K - loopstart) % loopcnt) + loopstart] + 1;
			}
			else{
				ans = p[K] + 1;
			}
			break;
		}

		a[now] = cnt;
		p.push_back(now);

		now = A[now];
		cnt++;
	}


	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 8460
#include <bits/stdc++.h>

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s,t;
cin>>s>>t;
int n=s.size();
int ans=0;
rep(i,n){
    if(s[i]!=t[i])ans++;
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3824
import std.stdio;
import std.string : chomp;
import std.conv : to;
import std.array : split;
import std.math : round;
import std.algorithm : map;



void main() {
    string[] input;
    int[] data = new int[](2);
    int num = 0, sum = 0, count = 0;

    while ((input = readln.chomp.split(",")).length != 0) {
        data[0] = input[0].to!int;
        data[1] = input[1].to!int;

        sum += data[0] * data[1];
        num += data[1];
        count++;
    }

    writeln(sum);
    writeln((num.to!double / count.to!double).round);
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 2147483647
#define double long double
#include <math.h>/* M_PI */
string s;
ll memo[105][10][2];
int done[105][10][2];
ll dp(int i, int j, int k) //indexでiまで決めた時に0以外をj個使って、k=0の時はNよりも小さいことが保証されている。k=1の時、Nと等しくなっている。
{
    if (done[i][j][k] == 1)
    {
        return memo[i][j][k];
    }
    ll res = 0;
    if (i == -1 && j == 0 && k == 1)
    {
        return 1;
    }
    else if (i == -1)
    {
        return 0;
    }
    else if (j == -1)
    {
        return 0;
    }
    if (k == 0)
    {

        res = dp(i - 1, j, 0) * 1 + dp(i - 1, j - 1, 0) * 9;
        //+dp(i - 1, j-1, 1)* dp(i - 1, j, 1)s[i]が0でなければ入る。
        if (s[i] != '0')
        {
            //cout << s[i] << endl;
            res += dp(i - 1, j, 1) + (s[i] - '0' - 1) * dp(i - 1, j - 1, 1);
        }
    }
    else //Nと等しいよって時
    {
        if (s[i] == '0')
        {
            res += dp(i - 1, j, 1);
        }
        else
        {
            res = dp(i - 1, j - 1, 1);
        }
    }
    memo[i][j][k] = res;
    done[i][j][k] = 1;
    return res;
}

int main()
{
    cin >> s;
    ll n = s.size();
    int k;
    cin >> k;

    cout << dp(n - 1, k, 0) + dp(n - 1, k, 1);
    //cout << dp(5, 2, 0); //1,1だけ使ってnより小さいことが確定
}


Measured memory_bytes: 256
#include <iostream>
 using namespace std;
 	int main(){
 		int W , H , x , y , r ;
 		cin >> W >> H >> x >> y >> r ;
 	if ( x + r <= W && x - r >= 0 && y + r <= H && y - r >= 0 )
 	cout << "Yes" << endl;
 	else 
 	cout << "No" << endl;	
 	}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.14159265358979323846264338327950288;

int main(){
    int N;
    cin>>N;
    vll A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(ALL(A));
    ll ans=1;
    ll big=1000000000000000000;
    for(int i=0;i<N;i++){
        if(A[i]==0){
            ans=0;
            break;
        }
        if(ans>big/A[i]){
            ans=-1;
            break;
        }else{
            ans*=A[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3964
N, M, X = map(int, input().split())
 
C = []
A = []
for i in range(N):
    # この1行をtとする
    t = list(map(int, input().split()))
    C.append(t[0])
    # c以降はそれぞれAに代入
    A.append(t[1:])
 
result = -1
for i in range(1, 2 ** N):
    # 0をm個分複製 これはカウントだから別
    t = [0] * M
    c = 0
    # ここでのjは縦軸
    for j in range(N):
        # 1番目を右にシフトして 1 と論理積を取る　これがtrueならcにカウントしてt[k]に代入
        if (i >> j) & 1 == 0:
            continue
        # trueならc[j]円カウントする　最終的に180円になる
        c += C[j]
        for k in range(M):
            # Aj冊目のkをリストtにいれる 0 1 2 と順番に
            t[k] += A[j][k]
    # xが指定のXの理解度に達するまで上のtをチェック
    if all(x >= X for x in t):
        if result == -1:
            result = c
        else:
            # 上の結果のそうわの最小パターン
            result = min(result, c)
print(result)
# 出力結果
# [0, 0, 0]001
# [2, 2, 4]010
# [8, 7, 9]011
# [10, 9, 13]
# [2, 3, 9]
# [4, 5, 13]
# [10, 10, 18]
# [12, 12, 22]

Measured memory_bytes: 9228
import java.util.*;
public class Main {
	public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
	  int a = sc.nextInt();
      String s = sc.next();
      
      if(a>=3200){
        System.out.println(s);
      }else{
        System.out.println("red");
      }
    }
}

Measured memory_bytes: 35440
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int a,b,c,d;
  	cin>>a>>b>>c>>d;
  	if(a*b>=c*d) cout<<a*b<<endl;
  	else cout<<c*d<<endl;
}

Measured memory_bytes: 3616
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
    return a * a;
}

template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
    int N;
    double T, A;
    cin >> N >> T >> A;

    double H[N];
    for (int i = 0; i < N; ++i) {
        cin >> H[i];
        H[i] = T - H[i] * 0.006;
    }

    int ans = 0;
    for (int i = 1; i < N; ++i) {
        if (abs(A - H[i]) < abs(A - H[ans])) {
            ans = i;
        }
    }

    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    const int LENGH = 3;
    int mountains[10];

    for (int i = 0; i < 10; ++i) {
        scanf("%d", &mountains[i]);
    }

    {
        bool finished = false;
        while (!finished) {
            finished = true;

            for (int i = 0; i < 10 - 1; ++i) {
                if (mountains[i] < mountains[i + 1]) {
                    int temp = mountains[i + 1];
                    mountains[i + 1] = mountains[i];
                    mountains[i] = temp;
                    finished = false;
                }
            }
        }
    }

    for (int i = 0; i < LENGH; ++i) {
        printf("%d\n", mountains[i]);
    }
}

Measured memory_bytes: 1032
N = int(input())
W = list(map(int, input().split()))
ans = 1000000
for i in range(N-1):
    if abs(sum(W[:i+1]) - sum(W[i+1:])) < ans:
        ans = abs(sum(W[:i+1]) - sum(W[i+1:]))
print(ans)

Measured memory_bytes: 38768
#! -*- coding:utf-8 -*-
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a
 
def lcm(a, b):
    return a * b // gcd(a, b)

n = int(input())
k = []
for i in range(n):
    k.append(int(input()))

if n == 1:
    print(k[0])
else:
    p = lcm(k[0],k[1])
    for i in range(n):
        p = lcm(p,k[i])
    print(int(p))


Measured memory_bytes: 3060
#include "iostream"
#include "algorithm"
#include "math.h"
#include "vector"
#include "string"
#include "map"
using namespace std;
typedef long long ll;
int main()
{
    
    ll a,b,c,d;
    cin>>a>>b>>c>>d;       
    ll s = max(a*c , a*d);
    ll s1 = max(b*c , b*d);
    ll s2 = max(s,s1);
    cout<<s2;
 
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {
	int x, y;
	cin >> x >> y;
	int count = 0;
	for (int i = 0; i <= x; i++)
	{
		for (int j = 0; j <= x; j++)
		{
			if (0 <= y - i - j&& y - i - j <= x)
				count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    int a, b, t;
    cin >> a >> b >> t;
    cout << t/a * b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

int main(){
  int n;cin>>n;
  vi a(n);vi b(n);
  rep(i,n) cin>>a.at(i);
  rep(i,n) cin>>b.at(i);
  vi c(n);
  rep(i,n) c.at(i)=(i+1);
  int req=0;
  int ans_a,ans_b;
  do{
    req++;
    if(c==a){
      ans_a=req;
    }
    if(c==b){
      ans_b=req;
    }
  }while(next_permutation(all(c)));
  cout<<abs(ans_b-ans_a)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }

void yes() { cout << "Yay!\n"; }
void no() { cout << ":(\n"; }

int main() {
    init();

    ll t1, t2; cin >> t1 >> t2;
    ll a1, a2; cin >> a1 >> a2;
    ll b1, b2; cin >> b1 >> b2;

    b1 = t1 * (b1 - a1);
    b2 = t2 * (b2 - a2);
    if (b1 < 0) {
        b1 *= -1;
        b2 *= -1;
    }

    if (b1 + b2 > 0)cout << "0\n";
    else if (b1 + b2 == 0)cout << "infinity\n";
    else {
        ll ans = -b1 / (b1 + b2) * 2 + bool(b1 % (b1 + b2));
        cout << ans << "\n";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll A, C;
    double B;

    cin >> A;
    cin >> B;

    C = ((B+0.001) * 100);

    //cout << A << "," << C << endl;
    

    ll ans = (A*C - (A*C%100))/100;

    cout << ans << endl;
    //cout << floor(A*(B+0.09)) << endl;

    return 0;


    
}



Measured memory_bytes: 3712
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a[n],count=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    int min=a[0];
    for(int i=1;i<n;i++)
    {
        if(min>=a[i])
        {
            count++;
            min=a[i];
        }
    }
    printf("%d",count+1);
    return 0;
}


Measured memory_bytes: 896
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    grid = list(map(string_to_int, inputs))

    for x in range(101):
        a = [-1, -1, -1]
        b = [-1, -1, -1]
        a[0] = x
        for j in range(3):
            b[j] = grid[0][j] - a[0]
        a[1] = grid[1][0] - b[0]
        a[2] = grid[2][0] - b[0]

        for i in range(3):
            for j in range(3):
                if grid[i][j] != a[i] + b[j]:
                    return 'No'
    return 'Yes'


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(3))
    print(ret)


Measured memory_bytes: 3812
#include<stdio.h>

int main(){
    int  n  ;
    scanf("%d", &n);
    int arr[3] ;
    int x  , y = n , j =2 , i , z = 0;
    for (i = 0 ; i <3 ; i++ ){
         x = y %10 ;
         y = y / 10 ;
         if(x == 1 ){
            x = 9 ;
         } else {
            x = 1 ;
         }

         //printf(" : == %d   ",x );
         arr[j] = x ;
         j-- ;
    }

    for(i = 0 ; i <3 ; i++){

        printf("%d",arr[i]);
    }
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int A, V, B, W, T;
	
	cin>>A>>V;
	
	cin>>B>>W;
	
	cin>>T;
	
	if(V <= W) {
		cout<<"NO"<<endl;
	} else {
		if(abs(A - B)  <= T * (V - W)) {
			cout<<"YES"<<endl;
		} else {
			cout<<"NO"<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3652
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        char c = (char) System.in.read();
        int b=0;
        if( c>=97 && c<122){
            b = c + 1;
        }
        else {
            System.out.println("Not allowed");
        }
        c =(char)b;
        System.out.println(c);
    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector< vector<long long>
#define mi map<int,int>
#define pi pair<int,int>

#define Fori(i,a,b) for(int i=a; i<b; i++)
#define Ford(i, a, b) for(int i=a; i>=b; i--)

#define pb push_back
#define mp make_pair

#define read(a, n) for(int i=0; i<n; i++) cin >> a[i];
#define print(x) cout << "X: == " << x << endl;
#define printMap(a) for(auto it=a.begin() ; it!= a.end() ; it++) {cout << it->first << "  " << it->second << endl; }
#define printVector(a) for(auto it = a.begin() ; it!= a.end() ;it++) {cout << *it << endl;}

using namespace std;
int main() {
    IOS
    int n, k;
    cin >> n >> k;
    vi a(n);
    read(a, n);
    vi dp(n, INT_MAX);
    dp[0] = 0;
    Fori(i, 1, n) {
        Ford(j, i-1, max(0, i-k)) {
            dp[i] = min(dp[i], dp[j] + abs(a[j] - a[i]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
using ll = long long;
const ll INF = 1e18L + 5;
const ll MOD = 1e9 + 7;
const int res = 0;


int main(){
	int n, c;
	scanf("%d%d", &n, &c);
	vector<ll> dp(c+1, 0); // 0....c
	for(int item = 0; item < n; ++item) {
		int w;
		ll v;
		cin >> w >> v;
		for(int upto = c - w; upto >= 0; --upto) {
			dp[upto + w] = max(dp[upto + w], dp[upto] + v);
		}
	}
	printf("%lld\n", dp[c]);
	
}



Measured memory_bytes: 1024
integerinput = input()
con = int(integerinput) >= 100 and int(integerinput) <= 999
count = 0
if con == True:
    for i in integerinput:
        if int(i) == 7:
            count = count + 1
        else:
            count = count
    if count >= 1:
        print("Yes")
    else:
        print("No")
else:
    print()


Measured memory_bytes: 9176
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<set>
#include<functional>
#include<cmath>

#define Vi vector<int>
#define Vs vector<string>
#define PB push_back
#define ALL(a) a.begin(),a.end()
#define FOR(i,n) for(int i=0;i<n;i++)
#define DEB cout<<"!"
using namespace std;

typedef pair<int,int> pii;
typedef pair<int,pii> piii;

long long combi(int p,int q){
  if(q==0||q==p)
    return 1;
  else if(q==1)
    return p;
  else
    return combi(p-1,q-1)+combi(p-1,q);
}

int main(){
  int n,p,ki=0,gu=0;
  unsigned long long ans = 0;
  cin>>n>>p;
  Vi a(n);
  FOR(i,n)
    cin>>a[i];
  FOR(i,n){
    if(a[i]%2)
      ki++;
    else
      gu++;
  }
  switch(p){
  case 1:
    for(int i=1;i<=ki;i+=2){
      ans+=combi(ki,i)*pow(2,gu);
    }
    break;
  case 0:
    for(int i=0;i<=ki;i+=2){
      ans+=combi(ki,i)*pow(2,gu);
    }
    break;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

const int M = 2002;

int h, w, L[M][M], R[M][M], U[M][M], D[M][M];
string s[M];

int main() {
	cin >> h >> w;
	inc1(i, h) { cin >> s[i]; s[i] = "#" + s[i] + "#"; }
	s[0] = s[h + 1] = string(w + 2, '#');
	
	int p;
	inc1(i, h) {
		incII(j, 0, w + 1) { if(s[i][j] == '#') { p = j; } L[i][j] = p; }
		decII(j, 0, w + 1) { if(s[i][j] == '#') { p = j; } R[i][j] = p; }
	}
	inc1(j, w) {
		incII(i, 0, h + 1) { if(s[i][j] == '#') { p = i; } U[i][j] = p; }
		decII(i, 0, h + 1) { if(s[i][j] == '#') { p = i; } D[i][j] = p; }
	}
	
	int ans = 0;
	inc1(i, h) {
	inc1(j, w) {
		if(s[i][j] == '#') { continue; }
		setmax(ans, (R[i][j] - L[i][j]) + (D[i][j] - U[i][j]) - 3);
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <unordered_map>
#include <algorithm> // std::sort(begin,end)
#include <utility> // std::swap
#include <tuple>

using namespace std;
using ll = long long;

int main(int argc, char const* argv[])
{
  int n,p;
  string s;
  vector<tuple<string,int,int>> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s>>p;
    v.push_back(make_tuple(s,-p,i+1));
  }
  sort(v.begin(),v.end());

  for(auto p : v){
    cout << get<2>(p) << endl;
  }
  



  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

int N, M;
map< string, int > node;
multimap< int, string > rnode;
map< string, vector< string > > graph;
set< string > used;
int dfs(string name, int cost)
{
  if(used.find(name) != used.end()) return(node.find(name) -> second);
  used.insert(name);
  node.find(name) -> second = cost;
  if(graph.find(name) != graph.end()) {
    vector< string >::iterator Begin = graph.find(name) -> second.begin();
    vector< string >::iterator End   = graph.find(name) -> second.end();
    for(; Begin != End; ++Begin) dfs(*Begin, cost);
  }
  return(cost);
}

int main()
{
  cin >> N;
  for(int i = 0; i < N; i++) {
    string S;
    int V;
    cin >> S >> V;
    node.insert(make_pair(S, V));
    rnode.insert(make_pair(V, S));
  }
  cin >> M;
  for(int i = 0; i < M; i++) {
    string U, V;
    cin >> U >> V;
    graph[U].push_back(V);
    graph[V].push_back(U);
  }
  int ret = 0;
  for(multimap< int, string >::iterator it = rnode.begin(); it != rnode.end(); ++it) {
    ret += dfs(it -> second, it -> first);
  }
  cout << ret << endl;
  return(0);
}

Measured memory_bytes: 2564
#include<bits/stdc++.h>
#define F first
#define S second
#define INF 1<<28
using namespace std;
 
int c, n, s, d;
typedef pair < int, int > P;
typedef pair < int, P > PP;
vector < P > vec[111];
 
int solve(){
 
  int dist[111][11]; for(int i=0;i<111;i++)for(int j=0;j<11;j++) dist[i][j] = INF;
  priority_queue < PP, vector<PP>, greater<PP> > que;
 
  dist[s][c] = 0;
  que.push( PP(0, P(s, c)) ); //Now_cost, Now_node, Now_ticket
 
  while(!que.empty()){
    PP p = que.top(); que.pop();
    int cost = p.F, now = p.S.F, tic = p.S.S;
 
    //if(dist[now][tic] < cost) continue;
    for(int i=0;i<vec[now].size();i++){
      P to = vec[now][i];
      if(dist[to.S][tic] > cost + to.F){
	dist[to.S][tic] = cost + to.F;
	que.push( PP(dist[to.S][tic], P(to.S, tic)) );
      }
      if(tic && dist[to.S][tic-1] > cost + to.F/2){
	dist[to.S][tic-1] = cost + to.F/2;
	que.push( PP(dist[to.S][tic-1], P(to.S, tic-1)) );
      }
    }
  }
   
  int ans = INF;
  for(int i=0;i<=c;i++){ ans = min(ans, dist[d][i]); } //cout << ans << endl; }
  return ans;
}
 
int main(){
 
  int m, a, b, p;
 
   
  while(cin >> c >> n >> m >> s >> d){
    if((c|n|m|s|d) == 0) break;
    for(int i=0;i<111;i++) vec[i].clear();
    for(;m--;){
      cin >> a >> b >> p;
      vec[a].push_back(P(p, b)); //[now] P(cost, next);
      vec[b].push_back(P(p, a));
    }
     
    cout << solve() << endl;
  }
   
}

Measured memory_bytes: 1240
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  1e+5+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n;
ll a[200005];
//<<-----Implement Functions Here---->>//


//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n;ll count1 = 0;
		for(ll i=0;i<n;i++)cin>>a[i];
		sort(a,a+n);ll ans = a[n-1];
		ll h = (n-2)/2;
		for(ll i=n-2;i>=0;i--){
			if(count1==h){
				if(n&1)ans += a[i];
				break;
			}
			ans += 2*a[i];
			count1++;
		}
		cout<<ans<<endl;

}

int main(){
	fastio;randomINIT;

	//cin>>t;
	while(t--){
		MAIN();
	}

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}

Measured memory_bytes: 7524
n, k = list(map(int, input().split()))

a = []
for _ in range(k):
    d = int(input())
    a.append(list(map(int, input().split())))

sunuke = [0] * (n)

for i in a:
    for j in i:
        #print(j)
        sunuke[j-1] += 1
#print (sunuke)

ans = 0
for i in sunuke:
    if i == 0:
        ans += 1
print(ans)


Measured memory_bytes: 9064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<numeric>

int main(){
	int N,K;

	std::cin >> N >> K;

	if(K==1) std::cout << 0 << std::endl;
	else std::cout << N-K << std::endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val d = sc.nextInt()
    val x = sc.nextInt()
    val a = (0 until n).map { sc.next().toInt() }
    println(problem092b(n, d, x, a))
}

fun problem092b(n: Int, d: Int, x: Int, a: List<Int>): Int {
    var res = 0
    for (i in 0 until n) {
        val ai = a[i]
        var count = 0
        for (j in 1..d) {
            val ans = count * ai + 1
            if (ans > d) break
            res++
            count++
        }
    }
    return res + x
}

Measured memory_bytes: 31392
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long i = (long) Math.ceil(Math.sqrt(n));
        long j = (long) Math.floor(Math.sqrt(n));
        boolean b = true;
        int answer=0;
        while (b){
            if (n%i==0){
                answer = Math.max(Long.toString(i).length(),Long.toString(n/i).length());
                b = false;
            }
            i++;
            if (n%j==0){
                answer = Math.max(Long.toString(j).length(),Long.toString(n/j).length());
                b = false;
            }
            j--;
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 23764
# input
n, k = map(int, list(input().split()))
r, s, p = map(int, list(input().split()))
t = input()

# process
tlist = [[] for _ in range(k)]
for i in range(k):
    j = i
    while j < n:
        tlist[i].append(t[j])
        j += k

ans = 0    
for l in tlist:
    pt = ""
    pr = True
    for i in l:
        if i == pt and pr == True:
            pr = False
        else:
            pr = True
            if i == "r": ans += p
            elif i == "s": ans += r
            elif i == "p": ans += s
        pt = i

# output
print(ans)


Measured memory_bytes: 13428
#include<bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int maxn=5e5+5;
const ll inf=0x3f3f3f3f;
const ll mod=1e9+7;

int a[maxn];

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int sum=0;
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		sum+=a[i];
	}
	int num=0;
	for(int i=1;i<=n;i++){
		if(a[i]*4*m>=sum) num++;
	}
	if(num>=m) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;


//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int p = 1; p < N; p++) cout << ", " << v[p]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
	


int main() {
	int a, b;
	char op;
	cin >> a >> op >> b;
	cout << (op == '+' ? a + b : a - b) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

int main()
{
    int N;
    cin >> N;
    vector<pint> A(N);
    rep(i,N) {
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(A.rbegin(), A.rend());
    vector<vector<ll>> dp(N+2, vector<ll>(N+2,-1));
    // until i-th element, there are j number id satisfying p[id] > id
    dp[0][0] = 0;
    rep(i,N) {
        ll cost = A[i].first;
        int id = A[i].second;
        rep(j,i+1) {
            if (dp[i][j] >= 0) {
                chmax(dp[i+1][j+1], dp[i][j] + cost * abs(j - id));
                chmax(dp[i+1][j], dp[i][j] + cost * abs((N - 1) - id - (i - j)));
            }
        }
    }
    ll ans = 0;
    rep(i,N) chmax(ans, dp[N][i]);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 34652
from itertools import permutations
n = int(input())
p = ''.join([x for x in input().split()])
q = ''.join([x for x in input().split()])

a = [str(x) for x in range(1, n+1)]
a = [''.join(list(x)) for x in permutations(a)]

p_idx = -1
q_idx = -1
for i, x in enumerate(a):
  if p == x:
    p_idx = i
  if q == x:
    q_idx = i

print(abs(p_idx - q_idx))

Measured memory_bytes: 11708
def fibonacci(n):
    global F

    if F[n] != -1:
        return F[n]
    elif n in [0, 1]:
        F[n] = 1
        return F[n]
    else:
        F[n] = fibonacci(n-1) + fibonacci(n-2)
        return F[n]


n = int(input())
F = [-1] * 45

print(fibonacci(n))



Measured memory_bytes: 5596
s = str(input())
ans = ""
for i in range(len(s)):
    if s[i] == "0":
        ans += "0"
    elif s[i] == "1":
        ans += "1"
    else:
        if len(ans) == 0:
            continue
        else:
            ans = ans[:-1]
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std ;
 
typedef pair < int , int > pii ;
typedef long long LL ;
 
#define clr( a , x ) memset ( a , x , sizeof a )
 
const int MAXN = 305 ;
 
char s[MAXN][MAXN] ;
int dp[MAXN][MAXN] ;
int val[MAXN][MAXN] ;
int n , m ;
 
void solve () {
	for ( int i = 1 ; i <= n ; ++ i ) {
		scanf ( "%s" , s[i] + 1 ) ;
	}
	int ans = 0 ;
	for ( int i = 1 ; i < m ; ++ i ) {
		for ( int j = 1 ; j <= n ; ++ j ) {
			for ( int k = 1 ; k <= n ; ++ k ) {
				val[j][k] = val[j - 1][k - 1] + ( s[j][i] == s[k][i + 1] ) ;
				dp[j][k] = min ( dp[j - 1][k] , dp[j][k - 1] ) + val[j][k] ;
			}
		}
		ans += dp[n][n] ;
	}
	printf ( "%d\n" , ans ) ;
}
 
int main () {
	while ( ~scanf ( "%d%d" , &n , &m ) ) solve () ;
	return 0 ;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b;
    cin>>a>>b;
    if(a%2==0||b%2==0)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
   
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main()
{
    ll N, K;
    cin >> N >> K;
    ll out = (N - 1) / (K - 1);
    if((N-1)%(K-1)!= 0)
        out++;
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    int ABCD;
    cin >> ABCD;
    vector<int> nyuryoku(4);
    nyuryoku[0]=ABCD/1000;
    int BCD=ABCD%1000;
    nyuryoku[1]=BCD/100;
    int CD=BCD%100;
    nyuryoku[2]=CD/10;
    nyuryoku[3]=CD%10;
    
    int N=3;
    vector<int> sw(N,0);
    
    vector<char> sign(2);
    sign[0] = '-';
    sign[1] = '+';
    
    for (int i=0; i<pow(2, N); i++) {
        int ans=nyuryoku[0];
        for (int j=0; j<3; j++) {
            if (sw[j]==0) {
                ans-=nyuryoku[j+1];
            }
            else{
                ans+=nyuryoku[j+1];
            }
        }
        
        if (ans==7) {
            cout << nyuryoku[0];
            for (int j=0; j<3; j++) {
                cout << sign[sw[j]] << nyuryoku[j+1];
            }
            cout << "=7" << endl;
            break;
        }
        
        // bit全探索
        sw[0]++;
        for (int j=0; j<N; j++) {
            if (i==pow(2, N)-1) {
                break;
            }
            if (sw[j]>1) {
                sw[j]=0;
                sw[j+1]++;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans[100001];
vector<vector<int> > vec;
long long mem[100005];
long long dfs(int x){
	if(mem[x] != 0)return mem[x];
	mem[x] = 0;
	for(auto xp : vec[x]){
		mem[x] = max(mem[x], dfs(xp) + 1);
	}
	return mem[x];
}
int main(){
	cin>>n>>m;
	vec.resize(n);
	for(int i = 0; i < m; ++i){
		int u, v;
		cin>>u>>v;
		u--, v--;
		vec[u].push_back(v);
	}
	vector<int> indegree(n, 0);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < vec[i].size(); ++j){
			indegree[vec[i][j]]++;
		}
	}
	int res = 0;
	for(int i = 0; i < n; ++i){
		if(indegree[i]==0){
			dfs(i);
		}
	}
	long long ans = 0;
	for(int i = 0; i < n; ++i)ans = max(ans, mem[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 9984
#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    float a[n],x,t = 0;
    for(i = 0; i < n; i++)
    {
        scanf("%f",&a[i]);
    }
    for(i = 0; i < n; i++)
    {
        x = 1/(t+ (1/a[i]));
        t = 1/x;
    }
    printf("%f\n",x);
    return 0;
}

Measured memory_bytes: 256