akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int h, n;
    cin >> h >> n;
    vec a(n), b(n);
    init(a, b);

    vec dp(h + 1, INF);
    dp[0] = 0;
    For(i, 0, h - 1) rep (j, n) {
        if (i + a[j] <= h)
            chmin(dp[i + a[j]], dp[i] + b[j]);
        else
            chmin(dp[h], dp[i] + b[j]);
    }
    print(dp[h]);

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define mp(a,b) make_pair(a,b)
#define inf 1000000007


ll H,W;
char s[52][52];
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};

int main() {
    rep(i,52){
        rep(j,52){
            s[i][j] = '#';
        }
    }
    ll white = 0;
    cin >> H >> W;
    rep(i,H){
        rep(j,W){
            cin >> s[i+1][j+1];
            if (s[i+1][j+1] == '.') white++;
        }
    }
    map<pl,ll>D;
    D[mp(1,1)] = 0;
    queue<pl> q;
    q.push(mp(1,1));
    
    while(!q.empty()){
        pl cur = q.front();
        q.pop();
        rep(i,4){
            ll x = cur.fi+dx[i];
            ll y = cur.se+dy[i];
            if (s[x][y] == '.' && D[mp(x,y)] == 0){
                D[mp(x,y)] = D[cur]+1;
                q.push(mp(x,y));
            }
        }
    }
    if (D[mp(H,W)] == 0) cout << -1 << endl;
    else{
        cout << white-(D[mp(H,W)]+1) << endl;
    }
   
   
    return 0;
}


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);





void solve4ts()
{
  
  
  int n;
  cin>>n;
  map<string,int> mp;
  rep(i,n){
    string s;
    cin>>s;
    mp[s]++;
  }

  cout<<"AC x " << mp["AC"]<<endl;
  cout<<"WA x " << mp["WA"]<<endl;
  cout<<"TLE x " << mp["TLE"]<<endl;
  cout<<"RE x " << mp["RE"]<<endl;
  
  
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

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

ll N, K;
vector<ll> Vl, Vr;

ll get_jem(ll l, ll r) {
  if (l + r > min(N, K)) {
    return -1000000000000;
  }
  ll res = 0;
  priority_queue<ll, vector<ll>, greater<ll>> D;
  for (ll i = 0; i < l; i++) {
    res += Vl[i];
    D.push(Vl[i]);
  }
  for (ll i = 0; i < r; i++) {
    res += Vr[i];
    D.push(Vr[i]);
  }
  for (ll i = 0; i < K - l - r; i++) {
    if (D.empty()) {
      break;
    }
    ll a = D.top();
    if (a < 0) {
      res -= a;
      D.pop();
    } else {
      break;
    }
  }
  return res;
}

void solve() {
  ll res = -1000000000000;
  for (ll l = 0; l <= K; l++) {
    for (ll r = 0; r <= K; r++) {
      if (l + r > min(N, K)) {
        continue;
      }
      res = max(res, get_jem(l, r));
    }
  }
  cout << res << "\n";
}

int main() {
  cin >> N >> K;
  Vl.resize(N);
  Vr.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> Vl[i];
  }
  Vr = Vl;
  reverse(Vr.begin(), Vr.end());
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
    ll H,W;
    cin>>H>>W;
    if(H==1 || W==1){
        cout<<1<<"\n";
        return;
    }

    cout<<(H*W+1)/2<<"\n";
    return;
}
 
int main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    ll n, m, d;
    cin >> n >> m >> d;
    if (d == 0) {
        double si = 1.0 * n;
        double kita = si / n / n;
        double ans = kita * (m - 1);
//        cout << ans << endl;
        printf("%.7lf\n",ans);
    } else {
        double si = 2.0 * n - 2.0 * d;
        double kita = si / n / n;
        double ans = kita * (m - 1);
        printf("%.7lf\n",ans);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int n, f[maxn + 10];
vector<int> g[maxn + 10];

void dfs(int p, int fa) {
	int cnt[20]; memset(cnt, 0, sizeof cnt);
	for (int i = 0; i < g[p].size(); ++i) {
		int e = g[p][i];
		if (e != fa) {
			dfs(e, p);
			for (int j = 0; j < 20; ++j) cnt[j] += (f[e] >> j & 1);
		}
	}
	int now;
	for (int i = 19; i >= 0; --i)
		if (cnt[i] > 1) break; else if (!cnt[i]) now = i;
	for (int i = 0; i <= 19; ++i)
		if (i == now) f[p] |= 1 << i;
		else if (i > now) f[p] |= (bool(cnt[i]) * (1 << i));
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int l, r; scanf("%d%d", &l, &r);
		g[l].push_back(r); g[r].push_back(l);
	}
	dfs(1, 0);
	for (int i = 19; i >= 0; --i)
		if (f[1] >> i & 1) {
			printf("%d", i); return 0;
		}
}


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

int a, b, c;

int main()
{
	cin >> a >> b >> c;
	if (a == b && b == c)
		cout << 1 << endl;
	else if (a == b || b == c || c == a)
		cout << 2 << endl;
	else
		cout << 3 << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()
nums = getList()

ans = 0
tmp = nums[0]
cur = 0
for num in nums[1:]:
    if tmp >= num:
        cur += 1
    else:
        if ans < cur:
            ans = cur
        cur = 0

    tmp = num


if ans < cur:
    ans = cur
print(ans)

Measured memory_bytes: 59632
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define msg(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define pri(a) cout << a << endl;

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

  ll n,ans=0;
  cin >> n;

  ll k = n/100;

  ll l = n-k*100;

  if(l>=0 && l<=5*k){
    cout << "1" << endl;
  }
  else{
    cout << "0" << endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define see(x) cout<<#x<<" : "<<(x)<<endl;
#define ya cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define ff first
#define sc second
typedef long long ll;
using namespace std;

const ll N=100009;
ll i,n,u,vv,w;
vector<ll>v[N],ww[N];
bool vis[N];
ll ans[N];
void dfs(ll i)
{
    vis[i]=1;
    for(int j=0;j<v[i].size();j++)
    {
        u=v[i][j];
        w=ww[i][j];
        if(!vis[u])
        {
            if(w&1)
            {
                ans[u]=!ans[i];
            }
            else
            {
                ans[u]=ans[i];
            }
            //cout << i << " " << j << endl;
            dfs(u);
            //cout << i << " " << j << endl;
        }
    }
}
int main()
{
    cin >>n;
    for(i=1;i<n;i++)
    {
        cin >> u >> vv >> w;
        v[u].pb(vv);
        v[vv].pb(u);
        ww[u].pb(w);
        ww[vv].pb(w);
    }
    dfs(1);
    for(i=1;i<=n;i++)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 17948
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[100005];
vector<int> ans;
int main(){
	int n, l;
	scanf("%d%d", &n, &l);
	LL sum = 0, il = 1, ir = n;
	for(int i=1;i<=n;i++) scanf("%d", &a[i]);
	
	int idx = 0;
	for(int i=1;i<n;i++){
		if(a[i]+a[i+1] >= l) idx = i;
	}
	if(idx == 0) printf("Impossible\n");
	else{
		printf("Possible\n");
		for(int i=1;i<idx;i++) printf("%d\n", i);
		for(int i=n-1;i>idx;i--) printf("%d\n", i);
		printf("%d\n", idx);
	}
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
#include <math.h>

using namespace std;

void func(int num,int need){

	int table[101] = {0},tmp,conv_day;

	for(int i = 0; i < num; i++){
		scanf("%d",&tmp);

		for(int k = 0; k < tmp; k++){
			scanf("%d",&conv_day);
			table[conv_day]++;
		}

	}

	int max = 0,max_day;

	for(int i = 0; i < 101; i++){
		if(table[i] > max){
			max = table[i];
			max_day = i;
		}
	}

	if(max >= need){
		printf("%d\n",max_day);
	}else{
		printf("0\n");
	}
}


int main(){

	int num,need;

	while(true){
		scanf("%d %d",&num,&need);
		if(num == 0 && need == 0)break;

		func(num,need);
	}

    return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX_N = 1e5+10;
int a[MAX_N];
int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++) cin>>a[i];
	int ans = 0, flag = 0;
	for(int i = 1; a[i] != i; i = a[i]){;
		ans++;
		if(a[i] == 2){
			flag = 1;
			break;
		}
		if(ans > n)break;
	}
	if(flag) cout<< ans << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 640
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
ll arr[100005];

int main() {
	scanf("%lld", &N);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
	}
	arr[0]--;
	for(int i = 1; i < N; i++) {
		if(arr[i - 1] < arr[i]) {
			arr[i] -= 1;
		}
	}
	for(int i = 0; i < N - 1; i++) {
		if(arr[i] > arr[i + 1]) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define st stack<ll>
#define v64 vector<ll>
#define v32 vector<int>
#define vv32 vector<vector<int>>
//#define s set<ll>
#define ms multiset<int>
#define p pair<ll,ll>
#define mp map<char,ll>
#define us unordered_set<ll>
#define pq64 priority_queue<ll>
#define pq32 priority_queue<ll>
#define q dequeue<ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define ls last
#define forab(i,a,b) for(ll i=a;i<b;i++) 
#define forn(i,n) for(ll i=0;i<n;i++)
#define pf push_front
#define ull unsigned long long
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 1e6+2
using namespace std;
int is_prime[1000001];

void sieve()
{
  for(int i=0;i<MAX;i++)
  {
    is_prime[i]=1;
  }
  is_prime[0]=is_prime[1]=0;
  for(int i=2;i*i<=MAX;i++)
  {
    if(is_prime[i])
    {
      for(int j=i*i;j<=MAX;j+=i)
      {
        is_prime[j]=0;
      }
    }
  }
}

/*
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/
int32_t main()
{
  int t,d;
  cin>>t>>d;
  int cnt=0;
  while(t--)
  {
    int x,y;
    cin>>x>>y;
    if((x*x+y*y)<=d*d)
      cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 3648
N = int(input())

N2 = int(N**0.5)

cnt = [0] * (90000)

for x in range(1,N2+1):
  for y in range(1,N2+1):
    for z in range(1,N2+1):
      xyz = x*x + y*y + z*z + x*y + y*z + z*x
      cnt[xyz] += 1
#
for i in range(1,N+1):
  print( cnt[i] )
  


Measured memory_bytes: 10184
from bisect import bisect_left
N = int(input())
L = list(map(int, input().split()))
L.sort()
res = 0
for i in range(N):
    for j in range(i+1, N):
        idx = bisect_left(L, L[i]+L[j])
        res += max(0,idx-(j+1))
print(res)

Measured memory_bytes: 3188
//ALDS1_6_B Sort II - Quick Sort
#include <cstdio>
#include <utility>
#define MAX 100000
#define SENTINAL 2000000000
struct Card
{
	char kind;
	int number;
};
int cnt,n;
Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(Card *A, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;

    for (int i = 0; i < n1; i++)
    {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; i++)
    {
        R[i] = A[mid + i];
    }
    L[n1].number = R[n2].number = SENTINAL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++)
    {
        cnt++;
        if (L[i].number <= R[j].number)
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
        }
    }
}

void mergeSort(Card *A, int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int partition(Card* A, int p, int r)
{
	Card x = A[r];
	Card temp;
	int i = p - 1;
	for (int j = p; j < r; j++)
	{
		if (A[j].number <= x.number)
		{
			i++;
			std::swap(A[i],A[j]);
		}
	}
	std::swap(A[i+1],A[r]);
	return i+1;
}

void quickSort(Card* A, int p, int r)
{
	int q;
	if (p < r)
	{
		q = partition(A,p,r);
		quickSort(A,p,q-1);
		quickSort(A,q+1,r);
	}
}

int main(void)
{
	int n;
	Card Q[MAX];
	Card M[MAX];
	scanf("%d\n",&n);
	for (int i = 0; i < n; i++)
	{
		scanf("%c %d\n",&Q[i].kind, &Q[i].number);
		M[i]=Q[i];
	}

	mergeSort(M,0,n);	
	quickSort(Q,0,n-1);
	bool stable = true;
	for (int i = 0; i < n; i++)
	{
		if(Q[i].kind != M[i].kind) stable = false;
	}
	stable?printf("Stable\n"):printf("Not stable\n");
	for (int i = 0; i < n; i++)
	{
		printf("%c %d\n", Q[i].kind, Q[i].number);
	}

	return 0;
}


Measured memory_bytes: 5048
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;

    x3 = x2 - (y2 - y1);
    y3 = y2 + (x2 - x1);
    x4 = x1 - (y2 - y1);
    y4 = y1 + (x2 - x1);

    cout << x3 << " " << y3 << " "
         << x4 << " " << y4 << "\n";
    return 0;
}


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}
map<ll,ll> s;
ll a,b,c,d;
void f(ll n){
	if(s.find(n)!=s.end()) return;
	ld ans = d;
	ans*=n;
	if(ans>1e15) ans=1e15;
	ll fns = ans;
	repA(i,max(1ll,n-1),n+1){
		if(i%2==0) {
			f(i/2);
			fns=min(fns,abs(n-i)*d+s[i/2]+a);
		}
	}
	repA(i,max(1ll,n-2),n+2){
		if(i%3==0) {
			f(i/3);
			fns=min(fns,abs(n-i)*d+s[i/3]+b);
		}
	}
	repA(i,max(1ll,n-4),n+4){
		if(i%5==0) {
			f(i/5);
			fns=min(fns,abs(n-i)*d+s[i/5]+c);
		}
	}
	s[n]=fns;
}
void solve(){
	ll n;cin>>n>>a>>b>>c>>d;
	s.clear();
	s[0]=0;
	s[1]=d;
	f(n);
	cout<<s[n]<<'\n';
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	rep(i,n) solve();
	return 0;
}



Measured memory_bytes: 4524
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()
#define rall(i) (i).begin(),(i).end(),greater<int>()
using namespace std;
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T> void print(T x) { std::cout << x << '\n'; }

typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
#define TENFIVE2 200005

// #define int long long



signed main(){
    int N;
    
    ll M,B[TENFIVE]={0};
    map<ll, ll>mp;
    cin>>N>>M;
    mp[0]++;
    rep1(i,N+1){
        ll tmp;cin>>tmp;
        B[i] =B[i-1]+tmp;
        mp[B[i] % M ]++; 
    }
    ll ans=0;

    for(auto itr = mp.begin();itr != mp.end();itr++){
        if(itr->second >0)
        ans+=(itr->second)*(itr->second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#include <atcoder/all>
using namespace atcoder;

int main() {
  int n, m;
  cin >> n >> m;
  dsu d(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    d.merge(a, b);
  }
  vector<vector<int>> list = d.groups();
  cout << list.size() - 1 << endl;

  return 0;
}


Measured memory_bytes: 8888
#include<iostream>
#include<cstdlib>
#include <algorithm>   

using namespace std;

int main () {
	int n,l;
	cin >> n >> l;
	int apple[n];
	int apple_abs[n];
	int i;
	for(i=0;i<n;i++){
		apple[i] = l+(i+1)-1;
		apple_abs[i] = abs(apple[i]);
	}
	
	int flavor_count = 0;
	for(i=0;i<n;i++) flavor_count += apple[i];
	
	sort(apple_abs,apple_abs+n);
	int min = apple_abs[0];
	for(i=0;i<n;i++){
		if(apple[i] == min) flavor_count -= min;
		else if(apple[i] == -min)flavor_count += min;
	}
	cout << flavor_count << " ";
	
	return 0;
	
	
	
}

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

#define debug(x) cerr<<#x<<'='<<x<<'\n'
#define Int const int &

int main(void) {
	long long a, b;
	int ans=1;
	cin>>a>>b;
	while ((a<<1)<=b) {
		a<<=1;
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	
	void run() {
		while (sc.hasNext()) {
			String str = sc.next();
			String[] spt = str.split(",");
			
			int[] seg = new int[10];
			int va,vb;
			double x,t;
			double p;
			for(int i=0;i<10;i++) seg[i] = Integer.parseInt(spt[i]);
			va = Integer.parseInt(spt[10]);
			vb = Integer.parseInt(spt[11]);
			x = 0;
			
			for(int i=0;i<10;i++) x += seg[i];
			
			t = x/(va+vb);
			
			p = t*va;
			int sum = 0;
			int i;
			for(i=0;i<10;i++) {
				sum += seg[i];
				if( p <= sum ) break;
			}
			System.out.println((i+1));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
	
}

Measured memory_bytes: 12000
//#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
//#define int long long
typedef long long ll;
typedef float f80;
//#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=1e9;
//const int mod=998244353;
int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}


void solve() {
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(n*a,b)<<endl;
}
signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	fr(i,1,t)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=1e5+10;
struct Node{
    int b;
	ll c;
    bool operator<( const Node & rhs)const{
        return c>rhs.c;      
    }
}p[M];
int n,m,x,b;
int main (){
	cin>>n>>m;
    priority_queue<ll,vector<ll>,greater<ll> > que;
    for (int i=0;i<n;i++){
		cin>>x;
        que.push ((ll)x);
    }    
    for (int i=0;i<m;i++){
	    cin>>p[i].b>>p[i].c;
	}
    sort(p,p+m);
    for (int i=0;i<m;i++){
        b=p[i].b;
        if (p[i].c<=que.top()){
		   break;
		}
        while (b--){
            if (que.top()<p[i].c){
                que.pop();
                que.push(p[i].c);
            }else{
                break;
            }
        }
    }  
    ll sum=0;   
    while (!que.empty()){
        x=que.top();
		que.pop();
        sum+=x;
    }    
    cout <<sum;  
    return 0;
    
}

Measured memory_bytes: 2676
import sys

sys.setrecursionlimit(1000000)
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

cnt = 0
for A in range(1, N + 1):
    last_digit = A % 10
    if last_digit == 0:
        continue
    first_digit = int(list(str(A))[0])
    for l in range(1, 7):
        if l == 1:
            if last_digit == first_digit:
                cnt += 1
        elif l < len(str(N)):
            cnt += 10 ** (l - 2)
        elif len(str(N)) == l:
            if last_digit < int(list(str(N))[0]):
                cnt += 10 ** (l - 2)
            elif last_digit == int(list(str(N))[0]):
                maybe, ok = 1, 0
                for j in range(1, l - 1):
                    ok = ok * 10 + maybe * int(list(str(N))[j])
                if first_digit <= N % 10:
                    ok += maybe
                cnt += ok
print(cnt)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <climits>

const int MAXN = 402;
uint64_t dp[MAXN][MAXN];
uint64_t sum[MAXN];
uint64_t a[MAXN];

int main() {
	int n;
	std::cin>>n;
	for (int i = 1; i <= n; ++i) {
		std::cin>>a[i];
		sum[i] = sum[i-1] + a[i];
	}
	for (int len = 2; len <= n; ++len) {
		for (int i = 1; i <= n; ++i) {
			int j = len + i - 1;
			if (j <= n) {
				dp[i][j] = UINT64_MAX;
			}
			for (int k = i; k < j && j <= n; ++k) {
				dp[i][j] = std::min(dp[i][k] + dp[k+1][j] + sum[j]-sum[i-1], dp[i][j]);
			}
		}
	}
	printf("%lld\n", dp[1][n]);
	return 0;
}


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

#define  int        long long int
 #define    sp(x)                 setprecision(x)
#define    bp(x)           __builtin_popcount(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    fast
    int n,ans=0;
    cin>>n;
    int x;
    f(i,1,n)
    {
        cin>>x;
        if(i%2 && x%2)
            ans++;
    }

    cout<<ans;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cassert>
#include<iomanip>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)
#define PI 3.14159265358979
#define MAX 45
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long double ld;
int n,m;
ld p[MAX];
//ld area[MAX][MAX][MAX];//area[start point][last point][new point] := the area
ld dp[MAX][MAX][MAX];//dp[start point][last point][the number] := maximum area

double getArea(int i,int j)
{
  assert(i < n && j < n);
  return sin((p[j]-p[i])*2*PI)/2.0;//S = (b*c*sinA)/2,in this case, b = c = 1
}


int main()
{
  while(cin >> n >> m,n|m)
    {
      rep(i,n)cin >> p[i];

      //init_area();

      rep(i,MAX)rep(j,MAX)rep(k,MAX)dp[i][j][k] = -inf;
      rep(i,MAX)rep(j,MAX)dp[i][j][2] = 0;
      ld ans = -inf;
      rep(sp,n)
	{
	  REP(cnt,2,m)
	    {
	      REP(lp,sp+1,n)
		{
		  REP(np,lp+1,n)
		    {
		      if(dp[sp][lp][cnt] == -inf)continue;

		      dp[sp][np][cnt+1] = max(dp[sp][np][cnt+1],
					      dp[sp][lp][cnt]+getArea(sp,lp)+getArea(lp,np)+getArea(np,sp));
	
		     
		      if(cnt+1 <= m)
			ans = max(ans,dp[sp][np][cnt+1]);  
		    }
		}
	    }
	}

      cout << setiosflags(ios::fixed) << setprecision(6) << ans << endl;

    }
  return 0;
}

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

int pool[9000000]; //9 MB
int header;

int *assign(int block)
{
	int *ret = &pool[header];
	header += block;
	return (ret);
}

vector<int *> seg;
int wbin, hbin;
 
void update(int y, int x, int v)
{
    y += hbin - 1;
    x += wbin - 1;
     
    seg[y][x] = v;
     
    while (y >= 0){
        int _x = x;
        while (_x){
            _x = (_x - 1) / 2;
            seg[y][_x] = min(seg[y][_x * 2 + 1], seg[y][_x * 2 + 2]);
        }
        if (y == 0) break;
        y = (y - 1) / 2;
        seg[y][x] = min(seg[y * 2 + 1][x], seg[y * 2 + 2][x]);
    }
}
 
int r1, c1, r2, c2, G;
 
int _query(int k = 0, int l = 0, int r = wbin)
{
    if (c2 <= l || r <= c1) return (INT_MAX);
    if (c1 <= l && r <= c2) return (seg[G][k]);
     
    int lval = _query(k * 2 + 1, l, (l + r) / 2);
    int rval = _query(k * 2 + 2, (l + r) / 2, r);
     
    return (min(lval, rval));
}
 
int query(int k = 0, int l = 0, int r = hbin)
{
    if (r2 <= l || r <= r1) return (INT_MAX);
    if (r1 <= l && r <= r2){
        G = k;
        return (_query());
    }
     
    int lval = query(k * 2 + 1, l, (l + r) / 2);
    int rval = query(k * 2 + 2, (l + r) / 2, r);
     
    return (min(lval, rval));
}
 
int main()
{
    int w, h, q;
     
    while (scanf("%d %d %d", &h, &w, &q) && w){
        wbin = hbin = 1;
        while (wbin < w) wbin *= 2;
        while (hbin < h) hbin *= 2;
		
		header = 0;
        seg.resize(hbin * 2 - 1);
        for (int i = 0; i < seg.size(); i++) seg[i] = assign(wbin * 2 - 1);
        
        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++){
                int a;
                scanf("%d", &a);
                update(i, j, a);
            }
        }
        
        for (int i = 0; i < q; i++){
            scanf("%d %d %d %d", &r1, &c1, &r2, &c2);
            ++r2; ++c2;
            printf("%d\n", query());
        }
    }
    
    return (0);
}

Measured memory_bytes: 31352
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll n;
    cin>>n;
    ll s[n],t[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
        cin>>t[i];
    }
    reverse(s,s+n);
    reverse(t,t+n);
    ll sub=0;
    for(int i=0;i<n;i++){
        if(s[i]+sub==0)sub=0;
        else sub+=((sub+s[i]-1)/t[i]+1)*t[i]-s[i]-sub;
    }
    cout<<sub<<endl;
}


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())

priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    llint n;
    cin >> n;
    vector<llint>s(n+1,0);
    for(int i=1;i<=n;i++)s[i]=i;
    llint sum=0;
    llint k;
    for(llint x:s){
      sum+=x;
      if(sum>=n){
        k=x;
        break;
      }

    }
    llint t=sum-n;
    for(llint i=1;i<=k;i++){
      if(i==t)continue;
      cout << i << endl;
    }
    
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 81308
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        //int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        //Console.WriteLine(Console.ReadLine().Replace("2017", "2018"));
        for (int i = 0; i <= a[0]; i++)
        {
            for (int j = 0; j <= a[0] - i; j++)
            {
                if(a[1] == i * 1000 + j * 5000 + (a[0] - i - j) * 10000)
                {
                    Console.WriteLine($"{(a[0] - i - j)} {j} {i}");
                    return;
                }
            }
        }
        Console.WriteLine("-1 -1 -1");
    }
}

Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = System.Console.ReadLine().Split(' ');
            List<int> x = new List<int>(); 
            for (int i = 0; i < 3; i++)
                x.Add( int.Parse(s[i]) );

            x.Sort();

            Console.WriteLine(x[2] * 10 + x[1] + x[0]);
//            for (int i = 0; i < 3; i++)
//               Console.WriteLine(x[i]);
        }
    }
}


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

#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    int n;
    cin>>n;
    string a;
    string b;
    cin>>a>>b;
    int ans=2*n;
    for(int i=n-1;i>=0;i--)
    {
        int j=0;
        int ti=i;
        bool flag=true;
        for(;j<=n-1 && ti<=n-1;j++,ti++)
        {
            if(a[ti]!=b[j])
                flag=false;
        }
        if(flag)
        ans=min(ans,2*n-(n-i));
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    long long a,b;
    bool flag = false;
    cin >> a >> b;
    for(int i = 0; i<max(a,b); i++){
        if(abs(a-i) == abs(b-i)){
            cout << i << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const int N = 101010;

int n;
int t[2 * N];

void modify(int l, int r, int value) {
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l&1) t[l++] += value;
    if (r&1) t[--r] += value;
  }
}

int query(int p) {
  int res = 0;
  for (p += n; p > 0; p >>= 1) res += t[p];
  return res;
}

int main() {
    int m;
    cin >> n >> m;
    memset(t, 0, sizeof(t));
    while(m) {
        int a, b; cin >> a >> b;
        a--; b--;
        modify(min(a,b), max(a,b), 1); m--;
    }
    for(int i = 0; i < n-1; i++) {
        if(query(i)%2 != 0) {
            cout << "NO"; return 0;
        }
    }
    cout << "YES";
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;



int main() {
  int n,k;
  scanf("%d%d",&n,&k);
  vvi ds(n);
  rep(i,n) {
    int t,d;
    scanf("%d%d",&t,&d);
    --t;
    ds[t].pb(d);
  }
  vp p;
  rep(i,n) if (sz(ds[i])) {
    sort(rng(ds[i]));
    rep(j,sz(ds[i])) {
      p.pb(P(ds[i][j],j==sz(ds[i])-1));
    }
  }
  sort(rng(p));
  PQ(int) q;
  int kind = 0, choose = 0;
  ll sum = 0;
  ll ans = 0;
  drep(i,sz(p)) {
    int d = p[i].fi, fst = p[i].se;
    sum += d;
    choose++;
    kind += fst;
    if (!fst) q.push(d);
    if (choose > k) {
      --choose;
      if (!sz(q)) break;
      sum -= q.top();
      q.pop();
    }
    if (choose == k) maxs(ans, sum+(ll)kind*kind);
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 6904
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n, m;

struct edge {
	ll to, cost;
};

vector<edge> G[1010];

ll d[1010];

bool find_negative_loop(int s) {
	fill(d, d + 1010, INF);
	d[s] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			rep(k, G[j].size()) {
				edge e = G[j][k];
				if (d[j] != INF&&d[e.to] > d[j] + e.cost) {
					d[e.to] = d[j] + e.cost;
				}
			}
		}
	}
	ll c = d[n - 1];
	for (int j = 0; j < n; j++) {
		rep(k, G[j].size()) {
			edge e = G[j][k];
			if (d[j] != INF&&d[e.to] > d[j] + e.cost) {
				d[e.to] = d[j] + e.cost;
			}
		}
	}
	if (c == d[n - 1])return false;
	return true;
}
int main() {
	cin >> n >> m;
	rep(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		G[a].push_back({ b,-c });
	}
	if (find_negative_loop(0))cout << "inf" << endl;
	else cout << -d[n - 1] << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n, c1 = 0, c2 = 0, c3 = 0, c4 = 0;
  cin>>n;
  string st;
  while(n--)
  {
    cin>>st;
    if(st == "AC") c1++;
    else if(st == "WA") c2++;
    else if(st == "TLE") c3++;
    else c4++;
  }
  cout<<"AC x "<<c1<<endl;
  cout<<"WA x "<<c2<<endl;
  cout<<"TLE x "<<c3<<endl;
  cout<<"RE x "<<c4<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
    int N; cin >> N;
    vector<ll> luka(87);
    luka[0] = 2; luka[1] = 1;
    for (int n = 2; n <= N; n++) luka[n] = luka[n - 1] + luka[n - 2];
    cout << luka[N] << endl;
    return 0;
}

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

int main(){
    int x, y, z, temp;
    cin >> x >> y >> z;
    
    temp = x;
    x = y;
    y = temp;
    temp = x;
    x = z;
    z = temp;

    cout << x << " " << y << " "<< z << endl;

}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = 1;
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            String s = in.next();
            if (s.toCharArray()[s.length() - 1] == 's')
            {
                out.println(s + "es");
            } else
            {
                out.println(s + "s");
            }
        }

    }
}



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

using namespace std;

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]) {

  bool all_visited = true;

  for(int i = 0; i < N; i++) {
    if(visited[i] == false) {
      all_visited = false;
    }
  }

  if(all_visited) {
    return 1;
  }

  int ret = 0;

  for(int i = 0; i < N; i++) {
    if(graph[v][i] == false) continue;
    if(visited[i]) continue;

    visited[i] = true;
    ret += dfs(i, N, visited);
    visited[i] = false;
  }

  return ret;
}

int main(void) {
  int N, M;
  cin >> N >> M;

  for(int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    graph[A - 1][B - 1] = graph[B - 1][A - 1] = true;
  }

  bool visited[nmax];
  for(int i = 0; i < N; i++) {
    visited[i] = false;
  }

  visited[0] = true;
  cout << dfs(0, N, visited) << endl;
  return 0;
}

Measured memory_bytes: 256