akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
struct point{
    double x,y,r;
};
const ll MOD=1000000007;
double xs,ys,xt,yt;
int N;
vector<point> v;
const int MAX_V=1100000;
const double INF=1e12;
struct edge {int to; double cost; };

int V;
vector <edge> G[MAX_V];
double d[MAX_V];

void dijkstra (int s){
    //小さい順に取り出す firstは最短距離、secondは頂点の番号
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s));
    
    while (!que.empty()) {
        P p=que.top();  que.pop();
        int v=p.second;
        if (d[v]<p.first) continue;
        rep(i,0,G[v].size()){
            edge e=G[v][i];
            if (d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>xs>>ys>>xt>>yt;
    cin>>N;
    v.resize(N+2);
    v[0].x=xs; v[0].y=ys; v[0].r=0;
    v[1].x=xt; v[1].y=yt; v[1].r=0;
    rep(i,2,N+2){
        cin>>v[i].x>>v[i].y>>v[i].r;
    }
    V=N+2;
    rep(i,0,N+2){
        rep(j,0,N+2){
            if(i!=j){
                G[i].pb(edge{int(j), max(double(0),sqrt((v[i].x-v[j].x)*(v[i].x-v[j].x)+(v[i].y-v[j].y)*(v[i].y-v[j].y))-v[j].r-v[i].r)});
            }
        }
    }
    dijkstra(0);
    cout <<setprecision(15)<<d[1]<<"\n";
}

Measured memory_bytes: 44660
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;

using namespace std;

//Binary exponent
ll Bin_pow(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        {
            res=res*a;
        }
        a=a*a;
        b>>=1;
    }
    return res;
}

//GCD
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}

//LCM
ll lcm(ll a,ll b)
{
	return (a*b)/gcd(a,b);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n,k;
	cin>>n>>k;
	
	ll a[n];
	
	for(ll i=0;i<n;i++)
	{
	    cin>>a[i];
	}
	sort(a,a+n);
	ll sum=0;
	for(ll i=0;i<k;i++)
	    sum+=a[i];
	    
	    cout<<sum<<"\n";
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

using namespace std;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

using ll = long long;
constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u * v / gcd(u, v);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<int>A(N);
    cin >> A;

    A.insert(A.begin(), 0);
    A.emplace_back(0);
    int sum = 0;
    FOR(i, 1, N + 2) {
        sum += abs(A[i - 1] - A[i]);
    }

    FOR(i, 1, N + 1) {
        int ans = sum;
        ans -= abs(A[i - 1] - A[i]);
        ans -= abs(A[i] - A[i + 1]);
        ans += abs(A[i + 1] - A[i - 1]);
        cout << ans << endl;
    }
    return 0;

}

Measured memory_bytes: 1656
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(c%2==0 || b%2==0 || a%2==0) puts("0");
    else printf("%lld\n",min({a*1ll*b,b*1ll*c,c*1ll*a}));
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    int x,t;
    cin >> x >> t;
    if(x-t<=0){
        cout << 0 << endl;
    }else{
        cout << x-t << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;

int main(){
    int n;
    ll tmp,sum;
    vector<ll> a,b;

    cin>>n;
    for(int i=0; i<n-1; i++){
        cin>>tmp;
        b.push_back(tmp);
    }
    a.push_back(b[0]);
    for(int i=1; i<n-1; i++){
        a.push_back(min(b[i-1],b[i]));
    }
    a.push_back(b[n-2]);

    sum=0;
    for(int i=0; i<n; i++){
        //cout<<"a : "<<a[i]<<endl;
        sum+=a[i];
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())

    xn = []
    yn = []
    hn = []

    for i in range(N):
        xi, yi, hi = map(int, input().split())

        xn.append(xi)
        yn.append(yi)
        hn.append(hi)

    for Cx in range(101):
        for Cy in range(101):

            last = None
            flg = True

            for i in range(N):

                if 0 == hn[i]:
                    continue

                H = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]

                if H < 0:
                    continue

                if last:
                    if H != last:
                        flg = False
                        break

                last = H

            if not flg:
                continue

            for i in range(N):

                if 0 == hn[i]:
                    h = abs(xn[i] - Cx) + abs(yn[i] - Cy)
                    if h < H:
                        flg = False
                        break

            if not flg:
                continue

            print(Cx, Cy, H)
            return


main()


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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF (1LL<<60)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

template<class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline void init(vector<T>& v, T n=0) {
	for(auto &a: v) {
		cin>>a; a+=n;
	}
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v, pair<T,U> n={0,0}) {
	for(auto &a: v) {
		cin>>a.first>>a.second;
		a.first+=n.first; a.second+=n.second;
	}
}
template<class N, class T>
inline void init(N siz, vector<T>& v, T n=0) {
	v.resize(siz);
	for(auto &a: v) {
		cin>>a; a+=n;
	}
}
template<class N, class T, class U>
inline void init(N siz, vector<pair<T,U>>& v, pair<T,U> n={0,0}) {
	v.resize(siz);
	for(auto &a: v) {
		cin>>a.first>>a.second;
		a.first+=n.first; a.second+=n.second;
	}
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}



int N,M,R;
intvec r;
matrix<int> dist;
ll res=LLINF;

void input() {
	cin>>N>>M>>R;
	init(R,r,-1);
	dist.resize(N,vector<int>(N,INTINF));
	for(int i=0; i<N; i++) {
		dist[i][i]=0;
	}
	for(int i=0; i<M; i++) {
		int A,B,C; cin>>A>>B>>C; A--,B--;
		dist[A][B]=dist[B][A]=C;
	}
}

void solve() {
	for(int k=0; k<N; k++)for(int i=0; i<N; i++)for(int j=0; j<N; j++) {
		chmin(dist[i][j],dist[i][k]+dist[k][j]);
	}

	sort(all(r));
	do {
		ll tmp=0;
		for(int i=0; i<R-1; i++) tmp+=dist[r[i]][r[i+1]];
		chmin(res,tmp);
	} while(next_permutation(all(r)));
	cout<<res<<endl;
}

int main() {
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3744
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, X[505];
int rem[505];
int seq[252525];
int valid[252525];

void fuee()
{
	puts("No");
	exit(0);
}

bool oks[505];

int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", X + i);
		rem[i] = N;
		valid[X[i]] = i;
	}
	for (int i = 1; i <= N * N; ++i) seq[i] = -1;

	vector<pair<int, int> > due;
	for (int i = 1; i <= N; ++i) due.push_back({ X[i], i });
	sort(due.begin(), due.end());

	int hole = 1;
	for (int i = 0; i < N; ++i) {
		int v = due[i].second;

		for (int j = 0; j < v - 1; ++j) {
			while (seq[hole] != -1 && hole < X[v]) ++hole;
			if (hole >= X[v]) fuee();
			seq[hole++] = v;
			--rem[v];
		}
		if (seq[X[v]] != -1) fuee();
		seq[X[v]] = v;
		--rem[v];
	}
	for (int i = 1; i <= N * N; ++i) {
		if (valid[i] != 0) {
			oks[valid[i]] = true;
		}
		if (seq[i] != -1) continue;

		for (int j = 1; j <= N; ++j) {
			if (rem[j] > 0 && oks[j]) {
				seq[i] = j;
				--rem[j];
				break;
			}
		}
		if (seq[i] == -1) fuee();
	}

	puts("Yes");
	for (int i = 1; i <= N * N; ++i) {
		printf("%d%c", seq[i], i == N * N ? '\n' : ' ');
	}
	return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code

int main(int argc, char const* argv[])
{
	map<char,int> mp;
	for (int i = 0; i < 4; i++) {
		char c;
		cin >> c;
		mp[c]++;
	}
	for (auto&& var : mp) {
		if (var.second != 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 764
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    string s; cin >> s;

    vector<int> r(26),l(26);

    int ans = 0;

    for(int i = 0;i < n-1;i ++){
        int count = 0;
        for(int j = 0;j < 26;j ++){
            l.at(j) = 0;
            r.at(j) = 0;
        }

        for(int j = 0;j < i+1;j ++){
            l.at(s.at(j)-'a') ++;
        }
        for(int j = n-1;j > i;j --){
            r.at(s.at(j)-'a') ++;
        }

        for(int j = 0;j < 26;j ++){
            if(l.at(j) && r.at(j)) count ++;
        }

        ans = max(ans,count);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

#define MAX_N 200020
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r-1);
}

int N;
ll K;
vector<ll> A;

ll b[2020];
ll c[2020];

int main(){
  cin>>N>>K;
  A.resize(N);
  for(int i=0;i<N;i++) cin>>A[i];

  setComb();

  for(int i=0;i<N;i++){
    for(int j=0;j<i;j++){
      if(A[j]>A[i]) b[i]++;
    }
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(A[i]>A[j]) c[i]++;
    }
  }

  ll ans=0;
  ll cost=(K)*(K-1)%MOD;
  cost=cost*inv[2]%MOD;
  cost=(cost+MOD)%MOD;
  for(int i=0;i<N;i++){
    ll r=b[i]*K%MOD;
    ans=(ans+r)%MOD;
    ll res=c[i]*cost%MOD;
    ans=(ans+res)%MOD;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 4992
# %% constants & libraries
# ------------------------

# %% body
# -------

function main(io = stdin)
    readto(target = '\n') = readuntil(io, target)
    readnum(T::Type{<:Number} = Int; dlm = isspace, kwargs...) =
        parse.(T, split(readto(), dlm; kwargs...))::Vector{T}

    # handle IO and and stuff
    N, = readnum()
    A = readnum()
    println(solve(N, A))
end

function solve(N, A)
    ret = 0
    m = typemin(Int)
    for Ai in A
        if m > Ai
            ret += m - Ai
        else
            m = Ai
        end
    end
    return ret
end

@static if @isdefined(Juno) || @isdefined(VSCodeServer)
    main(open(replace(@__FILE__, r"(.+)\.jl" => s"\1.in")))
else
    main()
end


Measured memory_bytes: 207776
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		
		sc.close();

		//全問正解できる確率
		// (1/2)^M (=pとする）
		
		//1回の実行時間
		//(N-M)*100 + M*1900
		
		//確率pを成功するまで試行する回数の期待値は1/p
		
		out.println( (int)( ((N-M)*100 + M*1900) * Math.pow(2, M)));
		
		
		
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
	
	@SuppressWarnings("unused")
	private String join(String delimiter, int[] a) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < a.length; i++) {
			sb.append(a[i]);
			sb.append(delimiter);
		}
		return sb.substring(0, Math.max(sb.length() - delimiter.length(), 0));
	}
	
	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

vector<pair<int,int>> ps;
vector<vector<int>> g;
vector<bool> used;

void dfs(int cur, int &cnt, set<int> &xs, set<int> &ys) {
    if (used[cur]) return;
    cnt++;
    used[cur] = true;
    xs.insert(ps[cur].first);
    ys.insert(ps[cur].second);

    for(int to : g[cur]) {
        dfs(to, cnt, xs, ys);
    }
}

int main(void){
    int n;
    cin >> n;
    ps.resize(n);
    g.resize(n);
    used.resize(n);
    rep(i,n){
        int x,y;
        cin >> x >> y;
        ps[i] = {x,y};
    }

    vector<int> ord(n);
    iota(all(ord), 0);

    sort(all(ord), [&](int i, int j){
        return ps[i].first != ps[j].first ? ps[i].first < ps[j].first : ps[i].second < ps[j].second;
    });
    rep(i,n-1){
        if (ps[ord[i]].first == ps[ord[i+1]].first){
            g[ord[i]].push_back(ord[i+1]);
            g[ord[i+1]].push_back(ord[i]);
        }
    }

    sort(all(ord), [&](int i, int j){
        return ps[i].second != ps[j].second ? ps[i].second < ps[j].second : ps[i].first < ps[j].first;
    });
    rep(i,n-1){
        if (ps[ord[i]].second == ps[ord[i+1]].second){
            g[ord[i]].push_back(ord[i+1]);
            g[ord[i+1]].push_back(ord[i]);
        }
    }

    ll res = 0;
    rep(i,n){
        int cnt = 0;
        set<int> xs, ys;
        dfs(i, cnt, xs, ys);
        res += xs.size() * ys.size() - cnt;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 16256
def eratosthenes(n):
  multiples = set()
  for i in range(2, n+1):
    if i not in multiples:
      yield i
      multiples.update(range(i*i, n+1, i))

while True:
  try:
    print(len(list(eratosthenes(int(input())))))
  except:
    break


Measured memory_bytes: 101616
x,y,z=list(map(int, input().split()))
a=list(map(int, input().split()))
ans=0
for i in range(x-1):
	if (a[i+1]-a[i])*y-z<0:
		ans=ans+(a[i+1]-a[i])*y
	else:
		ans=ans+z
print(ans)

Measured memory_bytes: 15020
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INF 1145141919
typedef long long int ll;
using namespace std;

int main(){
          int a,b;
          cin >> a >> b;
          if(a==1){
                    cout << 1 << endl;
                    exit(0);
          }
          if(a>b)   cout << a-1 << endl;
          else cout << a << endl;
          return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    int a[t];int c1=0,c2=0;
    for(int i=0;i<t;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<t;i++)
    {
        if(a[i]%2==0)
        {
            c1++;
            if(a[i]%3==0 || a[i]%5==0)
            {
                c2++;
            }
        }
    }
    if(c1==c2)
        cout<<"APPROVED";
    else
        cout<<"DENIED";
    return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    };
    let set = a.into_iter().collect::<std::collections::BTreeSet<i64>>();
    let ans = set.len() - if set.len() % 2 == 0 { 1 } else { 0 };
    println!("{}", ans);
}


Measured memory_bytes: 5336
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int max = a+b;
		
		if(a-b>max)
			max = a-b;
		if(a*b>max)
			max = a*b;
		
		System.out.println(max);
	}
}


Measured memory_bytes: 23764
# jsc2019_qual_a.py
M,D = map(int,input().split())
cnt = 0
for j in range(1,M+1):
    for i in range(11,D+1):
        a,b = list(str(i))
        a = int(a)
        b = int(b)
        if a*b==j and a>1 and b>1:
            cnt+=1
print(cnt)

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    int cnt=0;
    while(1){
        if(A<B)break;
        B*=2;
        cnt++;
    }
    while(1){
        if(B<C)break;
        C*=2;
        cnt++;
    }
    if(cnt<=K){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
using namespace std;

int main(){
	int n;
	string s;
	while( getline( cin , s ) , s != "END OF INPUT" ){
		n = 0;
		for(int i=0 ; i < (int)s.size() ; i++ ){
			if( i == (int)s.size()-1 ){
				cout << (n+1) << endl;
			}else if( s[i] == ' ' ){
				cout << n;
				n = 0;
			}else{
				n++;
			}
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
#define MAXN 1000001

vector<bool> prime;
void seive(){
    prime = vector<bool> ( MAXN , true );
    prime[0] = prime[1] = false;
    for(int i=2; i*i< MAXN ; i++){
	if( !prime[i] ) continue;
	for(int j=2*i; j < MAXN;j += i ) prime[j] = false;
    }
}



int main(){
    seive();
    while(1){
	int a,d,n;
	cin>>a>>d>>n;
	if( a == 0 )break;;
	while( n != 0 ){
	    if( prime [a] ) n--;
	    a+=d;
	}
	cout<<a-d<<endl;
    }
    return 0;
}



Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A;
  A.pb(0);
  ll ans = 0;
  ll pre = 0;
  for(int i=0;i<n;i++){
    ll a;cin>>a;
    ans += abs(a-pre);
    pre = a;
    A.pb(a);
  }
  A.pb(0);
  ans += abs(abs(pre));
  for(int i=1;i<=n;i++){
    if(A[i-1] <= A[i] && A[i] <= A[i+1]){
      cout<<ans<<endl;
    }else if(A[i-1] >= A[i] && A[i] >= A[i+1]){
      cout<<ans<<endl;
    }else{
      cout<<ans-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 2164
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
	string S; long long K;
	cin >> S >> K;
	for (int i = 0; i < min((long long)S.size(), K); i++) {
		if (S[i] >= '2'){cout << S[i] << endl; return 0;}
	}
	cout << '1' << endl;
	return 0;
}

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

bool f(int n)
{
    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) return false;
    }
    return true;
}

int main()
{
    int n; cin >> n;
    while (true) {
        if (f(n)) {
            cout << n << endl;
            return 0;
        }
        n++;
    }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = 0
for a in A:
    x -= a
    if x >= 0:
        ans += 1
    else:
        break
if x > 0:
    ans -= 1
print(ans)


Measured memory_bytes: 3316
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int r = input.nextInt();
        int d = input.nextInt();
        int x = input.nextInt();
        int result = 0;

        for (int i = 0; i < 10; i++) {
            result = (r*x)-d;
            System.out.println(result);
            x = result;

        }
    }

}


Measured memory_bytes: 23892
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

typedef pair<int,int> P;
typedef long long ll;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
#define MOD 1000000007
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
bool losed[100000];
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main() { 
  int n,k;cin>>n>>k;
  int r,s,p;cin>>r>>s>>p;
  string t;cin>>t;
  long long ans = 0;
  

  for(int i = 0; n > i; i++){
    if(i >= k){
      if(t[i-k] == t[i] && !losed[i-k]){
        losed[i] = true;
        continue;
      }
    }
    if(t[i] == 'r')ans += p;
    else if(t[i] == 's')ans += r;
    else ans += s;
  }
  cout << ans << endl;

}

Measured memory_bytes: 592
#include <iostream>
#include <string.h>
using namespace std;

int main() {
  char c[6];
  for(int i = 0; i < 6; i++) {
    cin >> c[i];
  }

  if(c[2] == c[3] && c[4] == c[5]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int i,a[100000];
    int sum[100000]={0};
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum[i+1]=sum[i]+a[i];
    }
    int minn=10000000;
    for(i=1;i<=n;i++)
        {sum[i]=abs(sum[n]-2*sum[i]);
        minn=minn<sum[i]?minn:sum[i];}
    printf("%d\n",minn);
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int gcd(int a,int b)
{
	if ( b==0 ) return a;
	return gcd(b,a%b);
}

int main()
{
	int n;
	cin >> n;
	vector<int> A(n);
	for ( int i = 0 ; i < n ; i++ )
		cin >> A[i];

	vector<int> prefix(n+1),postfix(n+1);
	prefix[0] = postfix[n] = 0;

	for ( int i = 0 ; i < n ; i++ )
	{
		prefix[i+1] = gcd(A[i],prefix[i]);
	}

	for ( int i = n ; i > 0 ; i-- )
	{
		postfix[i-1] = gcd(A[i-1],postfix[i]);
	}

	int res = 0;
	for ( int i = 0 ; i < n ; i++ )
	{
		int pre = prefix[i];
		int post = postfix[i+1];

		res = max(res,gcd(post,pre));
	}

	cout << res << endl;




	return 0;
}


Measured memory_bytes: 1408
fun main() {
    val (n, m, d) = readLine()!!.split(' ').map { it.toInt() }
    val ans = if (d == 0) {
        1.0 / n * (m - 1)
    } else {
        2.0 * (n - d) / n / n * (m - 1)
    }
    println(ans)
}


Measured memory_bytes: 36544
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repll(i, a, b) for(ll i=(a); i<(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define COUT(a) cout << a << endl
#define ALL(a) (a).begin(),(a).end()
const long long int mod = 1e9 + 7;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    if(A>=K){
        cout << K << endl;
    }else{
        if(A+B>=K){
            cout << A << endl;
        }else{
            cout << A - (K-A-B) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF (1LL<<31)-1
typedef struct RUQ{
ll n;
	vector<ll> a;
	//vector<bool> f;
	void init(int size){
		n = 1;
		while(n<size) n*=2;
		a = vector<ll> (2*n-1,INF);
		//f = vector<bool> (2*n-1,true);
	}
	
	void init(vector<ll> &b){
		int size = b.size();
		n = 1;
		while(n<size)n*=2;
		a = vector<ll> (2*n-1,INF);
		//f = vector<bool> (n,true);
		for(int i=0;i<size;i++) a[i+n-1] = b[i];
	}
	//
	void update(ll aa,ll b ,ll k,ll l,ll r ,ll x){
		if(r<= aa|| b<= l)return ;
		if(aa<=l && r<=b ) a[k] = x;
		else{
			if(a[k] != INF){
				a[k*2+1] = a[k];
				a[k*2+2] = a[k];
				a[k] = INF;
			}
			update(aa,b,k*2+1,l,(l+r)/2,x);
			update(aa,b,k*2+2,(l+r)/2,r,x);
		}
		return ;
	}
	ll find(ll aa,ll b,ll k,ll l,ll r){
		if(r<=aa|| b<=l) return INF;
		if(aa<=l && r<= b) return a[k];
		if(a[k]!=INF){
			a[k*2+1] = a[k];
			a[k*2+2] = a[k];
			a[k] = INF;
		}
		return min(find(aa,b,k*2+1,l,(l+r)/2),find(aa,b,k*2+2,(l+r)/2,r) );
	}
	//[s,t]
	void update(ll s,ll t,ll x){
		update(s,t+1,0,0,n,x);
	}
	ll find(ll s){
		return find(s,s+1,0,0,n);
	}
	
}RUQ;



int main(){
	ll n,q;
	cin>>n>>q;
	RUQ seg;
	seg.init(n);
	//cout<<seg.a.size()<<endl;
	for(ll i=0;i<q;i++){
		ll d,s,t,x;
		cin>>d;		
		if(d==0){
			cin>>s>>t>>x;
			seg.update(s,t,x);
		}else{
			cin>>s;
			cout<<seg.find(s)<<endl;
		}
	}

	return 0;
}



Measured memory_bytes: 7104
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include<unordered_map>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int N;
bool graph[51][51];
bool visited[51];

void dfs(int x) {
	if (visited[x]) return;
	visited[x] = true;
	rep(i, N) {
		if (graph[x][i]) {
			dfs(i);
		}
	}
}


int main() {
	cin >> N;
	int m;
	cin >> m;
	vector<int>a(m), b(m);
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
	}
	int count = 0;
	rep(i, m) {
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
		rep(i, N) {
			visited[i] = false;
		}
		dfs(0);
		bool connected = true;
		rep(i, N) {
			if (!visited[i]) {
				connected = false;
			}
		}
		if (!connected) {
			count++;
		}
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
	}
	cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main() {
	int x,y,temp;
	while(1) {
		cin >> x >> y;
		if (x == 0 && y == 0) {
			break;
		}
		if (x>y) {
			temp=x;
			x=y;
			y=temp;
		}
		cout << x << " "  << y << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include<stdio.h>
#define nil -1

struct node{
  int parent;
  int left;
  int right;
};

typedef struct node tree;
tree A[100000];

int number;


void Preorder(int root){
  
  if (root==nil){return ;}

  printf(" %d",root);

  Preorder(A[root].left);
  Preorder(A[root].right);
}



void Inorder(int root){
   if (root==nil){return ;}

   Inorder(A[root].left);
   printf(" %d",root);
   Inorder(A[root].right);
}




void Postorder(int root){
if (root==nil){return ;}

 Postorder(A[root].left);
 Postorder(A[root].right);

 printf(" %d",root);

}

int main(){
  scanf("%d",&number);
  
  int i;
  
  
  
  for(i=0;i<number;i++){
    A[i].parent=A[i].right=A[i].left=-1;
  }
  
  
  int r1,r2;
  int a;
  for(i=0;i<number;i++){
    scanf("%d%d%d",&a,&r1,&r2);
    
    A[a].left=r1;
    A[a].right=r2;
    
    if(r1!=-1)A[r1].parent=a;
    if(r2!=-1)A[r2].parent=a;
    
  }
  
  int root=0;

   for(i=0 ; i<number ; i++){
    if(A[i].parent==-1){root=i;}
  }

   
   printf("Preorder\n");
   Preorder(root);
   printf("\n");

   printf("Inorder\n");
   Inorder(root);
   printf("\n");

   
   printf("Postorder\n");
   Postorder(root);
   printf("\n");
   
  
  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;



int main(){
    double l;
    cin >> l;
    double ans=l*l*l;
    ans /= 27;
    printf("%.8f",ans);
   

}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],b,c,m,k,sum,minn=1e8,ans;
char s[100001];
int main()
{
	string x;
	cin>>n;
	cin>>x;
	for(int i=0;i<n;i++)
	{
		if(x[i]=='I')
		{
			ans++;
			sum=max(sum,ans);
		}
		else
		ans--;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <queue>
#include <stack>
#include <bitset>

#include <unordered_set>

using namespace std;

typedef long long ll;


int dd[5] = {1,0,-1,0,1};

int q_count = 0;

int check[1010][1010];

bool q(int dir, int y, int x){
  if(check[y+dd[dir]][x+dd[dir+1]] == 1)
    return false;
  
  char c = "DLUR"[dir];
  char res[5];
  
  printf("? %c\n", c);
  //fprintf(stderr, "%d %d\n", y, x);
  fflush(stdout);

  scanf("%s", res);
  q_count++;

  assert(q_count <= 800000);
  return res[0] == 'Y';
}

void answer(int y, int x){
  printf("! %d %d\n", y, x);
  fflush(stdout);
}

int h, w;
char block[510][510];

int main(){

  scanf("%d%d", &h, &w);

  for(int i=0;i<h;i++){
    scanf("%s", block[i]);
  }

  int B = 505;
  
  stack<pair<pair<int,int>,pair<int,int> > > st;

  st.push({{B, B},{0, -1}});
  
  while(st.size()){
    auto p = st.top(); st.pop();

    int y = p.first.first;
    int x = p.first.second;
    int s = p.second.first;
    int back = p.second.second;
    
    if(check[y][x] && s == 0) continue;
    check[y][x] = 2;
    
    bool f = false;
    
    for(int i=s;i<4;i++){
      if(check[y+dd[i]][x+dd[i+1]]) continue;

      bool res = q(i, y, x);
      
      if(res){
        st.push({{y,x},{i+1,back}});
        st.push({{y+dd[i], x+dd[i+1]},{0,(i+2)%4}});
        y += dd[i]; x += dd[i+1]; 
        f = true;
        break;
      }else{
        check[y+dd[i]][x+dd[i+1]] = 1;
      }
    }

    if(!f){
      if(back != -1){
        assert(q(back, y, x));
        y += dd[back]; x += dd[back+1];
      }
    }
  }

  int l = 1e9, u = 1e9, r = 0, d = 0;
  
  for(int i=0;i<1010;i++){
    for(int j=0;j<1010;j++){
      if(check[i][j] == 2){
        u = min(u, i);
        l = min(l, j);
        d = max(d, i);
        r = max(r, j);
      }
    }
  }

  int CC = 0;
  
  for(int i=u;i<=d;i++){
    for(int j=l;j<=r;j++){
      //printf("%c", " #"[check[i][j]==2]);
      CC += check[i][j] == 2;
    }
    //puts("");
  }


  int su = u;
  int sl = 1e9;

  for(int i=l;i<=r;i++) if(check[su][i] == 2) sl = min(sl, i);

  bool visited[1010][1010] = {};
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(visited[i][j] || block[i][j] == '.') continue;

      queue<pair<int,int> > que;
      que.push({i,j});

      int cc = 0;
      
      while(que.size()){
        auto p = que.front(); que.pop();
        
        if(visited[p.first][p.second]) continue;
        visited[p.first][p.second] = true;

        //printf("%d\n", check[p.first-i+su][p.second-j+sl]);
        
        if(check[p.first-i+su][p.second-j+sl] != 2){
          cc = -1e9;
        }

        cc++;
        
        for(int k=0;k<4;k++){
          if(0 > p.first + dd[k] || 0 > p.second + dd[k+1]) continue;
          if(block[p.first + dd[k]][p.second + dd[k+1]] == '#'){
            que.push({p.first + dd[k], p.second + dd[k+1]});
          }
        }
      }

      
      //printf("%d %d %d %d\n", i, j, cc, CC);
      
      if(cc == CC){
        answer(i + B - su,j + B - sl);
        return 0;
      }
    }
  }

  assert(false);
}



Measured memory_bytes: 8752
/*
对于一组选取组的最优方案为，走到一点，然后顺着路径往回取点
设选取点坐标升序为{a,b,c,d} 
那么消耗为d+(d - c) + 4* (d - c) + 9 * (c - d) + 16 * (b - a) + a * 25
化简后为5d + 5c + 7b - 9a,那个对于这组k的最优解显然是让最远的点系数最小
考虑把序列划分为n / k组,枚举这个k计算,那么复杂度是调和级数的
*/
#include<cstdio> 
#include<cstring> 
#include<algorithm> 
#define gc getchar() 
#define pc putchar 
#define int long long
inline int read() { 
	int x = 0,f = 1; 
	char c = gc; 
	while(c < '0' || c > '9') {if(c == '-')f = -1; char c = getchar();} 
	while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar(); 
	return x * f; 
} 
void print(long long  x) { 
	if(x < 0) { 
		pc('-'); 
		x = -x; 
	} 
	if(x >= 10) print(x / 10); 
	pc(x % 10 + '0'); 
} 
const int maxn = 500007; 
#define LL long long 
LL ans; 
LL sum[maxn],a[maxn]; 
main() { 
	LL n = read(), x = read(); 
	for(int i = 1;i <= n;++ i) a[i] = read(),sum[i] = sum[i - 1] + a[i],ans += 1ll * 5 * a[i] + 2ll * x; 
	for(int k = 1;k < n;++ k) { 
		LL tmp = k * x; 
		for(int nxj,j = n,cnt = 1;j > 0;j = nxj,cnt ++) {
			nxj = std::max(j - k,0ll); 
			LL s = sum[j] - sum[nxj]; 
			tmp += std::max(5ll,cnt * 2ll + 1ll) * s;  
			if(tmp > ans) break;  
		} 
		ans = std::min(ans,tmp); 
	} 
	print(ans + 1ll * n * x); pc('\n'); 
	return 0; 
} 

Measured memory_bytes: 5760
#include <stdio.h>

int main(){
  int i,a,b;

  scanf("%d %d",&a,&b);
  char s[a+b+2];

  scanf(" %s",&s);
  for(i=0;i<=a+b;i++){
    if(i==a){
      if(s[i]!='-'){
        printf("No");
        return 0;
      }
      continue;
    }
    if(s[i]<'0'||s[i]>'9'){
      printf("No");
      return 0;
    }
  }

  printf("Yes");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1000000007;
const int nmax=2000010;
ll fac[nmax],finv[nmax],inv[nmax];
 
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;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;
  }
}
ll com(int n,int k){
  if(n<k||n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
 
int main(){
  COMinit();
  ll n,m,k;cin >> n >> m >> k;
  ll ans=0;
  for(ll i=0;i<n;i++){
    ans+=i*(n-i)%mod*m%mod*m%mod;
    ans%=mod;
  }
  for(ll i=0;i<m;i++){
    ans+=i*(m-i)%mod*n%mod*n%mod;
    ans%=mod;
  }
  ans*=com(n*m-2,k-2);
  ans%=mod;
  cout << ans << endl;
}

Measured memory_bytes: 47104
#!/usr/bin/env python3
import sys
INF = float("inf")


def main():
    # i回目 Ti : Ai
    N = int(input())
    T, A = [], []
    for i in range(N):
        t, a = map(int, input().split())
        T.append(t)
        A.append(a)

    num = [0, 0]
    for i, (t, a) in enumerate(zip(T, A)):
        # print(i, t, a, num)
        while True:
            if num[0] <= t and num[1] <= a:
                break
            if num[0] <= t:
                # print("B", t, a, num)
                c = -(-num[1]//a)
                a *= c
                t *= c
                continue
            if num[1] <= a:
                # print("C", t, a, num)
                c = -(-num[0]//t)
                199, 17
                a *= c
                t *= c
                continue
            c = max(-(-num[0]//t), -(-num[1]//a))
            # print("D", t, a, num, c)
            a *= c
            t *= c
            continue
        num[0] = t
        num[1] = a
        # print(a, t)
    print(num[0]+num[1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 67668
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, x;
    cin >> n >> m >> x;
    vector<lint> c(n);
    vector<vector<lint>> a(n, vector<lint>(m));
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    lint ret = inf;
    for (int i = 0; i < 1 << n; ++i) {
        vector<lint> und(m, 0);
        lint cost = 0;
        for (int j = 0; j < n; ++j) {
            if (i >> j & 1) {
                cost += c[j];
                for (int k = 0; k < m; ++k) {
                    und[k] += a[j][k];
                }
            }
        }
        bool ok = true;
        for (int j = 0; j < m; ++j) {
            if (und[j] < x) {
                ok = false;
                break;
            }
        }
        if (ok)
            chmin(ret, cost);
    }
    if (ret == inf)
        cout << -1 << "\n";
    else
        cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
main(){for(int q,b,c,d,r,A,N;std::cin>>q>>b>>c>>d>>r,q;A?printf("%d %d\n",A,N):printf("NA\n"))for(A=0;r;r--){N=(b-r*c)/d;if(b>=r*c&&N+r>=q){A=r;r=1;}}}

Measured memory_bytes: 0
#include<iostream>
#include <string>
using namespace std;

int main() {
    int dic[26];
    string str;
    cin >> str;
    for(int i = 0; i < 26; i++){
        dic[i] = 0;
    }
    for(int j = 0; j < str.length(); j++){
        dic[(int)str[j] - 97] = 1;
    }
    for(int i = 0; i < 26; i++){
        if(dic[i] == 0){
            cout << (char)(i + 97) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    Int x;
    cin >> x;

    int goo = 0, g = 0;
    while (500 <= x) {
        goo++;
        x -= 500;
    }
    while (5 <= x) {
        g++;
        x -= 5;
    }

    cout << goo * 1000 + g * 5 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;

int di[] = {-1, 0, 1, 0};
int dj[] = {0, -1, 0, 1};

struct Info {
    int li, lj, ri, rj;
    Info(int i, int j, int k, int l) : li(i), lj(j), ri(k), rj(l) {}
};

int used[55][55][55][55];

int main() {
    int w, h;
    while (cin >> w >> h, w | h) {
        string L[h], R[h];
        for (int i = 0; i < h; i++) cin >> L[i] >> R[i];
        int yl, xl, yr, xr;
        int yt, xt, yk, xk;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (L[i][j] == '%') {
                    L[i][j] == '.';
                    yl = i, xl = j;
                } else if (L[i][j] == 'L') {
                    yt = i, xt = j;
                }
                if (R[i][j] == '%') {
                    yr = i, xr = j;
                    R[i][j] == '.';
                } else if (R[i][j] == 'R') {
                    yk = i, xk = j;
                }
            }
        }
        queue<Info> q;
        q.push(Info(yt, xt, yk, xk));
        memset(used, 0, sizeof(used));
        bool flag = false;
        used[yt][xt][yk][yt] = 1;
        while (!q.empty()) {
            int li = q.front().li;
            int lj = q.front().lj;
            int ri = q.front().ri;
            int rj = q.front().rj;
            q.pop();
            if (li == yl && lj == xl || ri == yr && rj == xr) {
                if (li == yl && lj == xl && ri == yr && rj == xr){
                    flag = true;
                    break;
                }
                continue;
            }
            for (int i = 0; i < 4; i++) {
                int nli = li + di[i];
                int nlj = lj + dj[i];
                int nri = ri + di[i];
                int nrj = rj - dj[i];
                if (nli < 0 || nlj < 0 || nli >= h || nlj >= w || L[nli][nlj] == '#') {
                    nli = li, nlj = lj;
                }
                if (nri < 0 || nrj < 0 || nri >= h || nrj >= w || R[nri][nrj] == '#') {
                    nri = ri, nrj = rj;
                }
                if (!used[nli][nlj][nri][nrj]) {
                    used[nli][nlj][nri][nrj] = 1;
                    q.push(Info(nli, nlj, nri, nrj));
                }
            }
        }
        if (flag) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 39676