akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
ac = 0
wa = 0

memo = [0] * n
for i in range(m):
    p, s = input().split()
    p = int(p)
    p -= 1
    if memo[p] == -1:
        continue
    if s == "AC":
        ac += 1
        wa += memo[p]
        memo[p] = -1
    else:
        memo[p] += 1

print(ac, wa)

Measured memory_bytes: 3828
N, K = map(int, input().split())


def hoge(n, k):
    if N == K:
        return len(str(n))
    for i in range(n + 1):
        tmp = k ** i
        if tmp > n:
            # if tmp < K:
            return i
            # else:
            #    continue


print(hoge(N, K))


Measured memory_bytes: 2940
#coding: utf-8

left = ['Q','W','E','R','T','A','S','D','F','G','Z','X','C','V','B']

while True: 
    s = str(raw_input())
    if s == '#':
        break
    else:
        s = s.upper()
        num = 0
        hand = ''
        for i in range(len(s)):
            if s[i] in left:
                if hand == 'right':
                    num = num + 1
                hand = 'left'
            else:
                if hand == 'left':
                    num = num + 1
                hand = 'right'
        print num

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi a(n), b;
    rep(i,n) cin>>a[i];
    RFOR(i,n-1,0){
        if (a[i]==1){
            b.pb(i+1);
            int o=i+1;
            for(int j=1; j*j<=o; j++){
                if (o%j==0){
                    a[j-1]=(a[j-1]+1)%2;
                    if (j*j!=o) a[o/j-1]=(a[o/j-1]+1)%2;
                }
            }
        }
    }
    reverse(all(b));
    cout<<b.size()<<endl;
    for(auto e:b){
        cout<<e<<" ";
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 2424
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
bool is_prime(int x)
{
	bool f=true;
	for(int i=2;i<=sqrt(x);i++)
		if(x%i==0)
			f=false;
	return f;
}
int main()
{
	bool num[100005];
	int a[100005];
	memset(num,false,sizeof(num));
	memset(a,0,sizeof(a));
	for(int i=1;i<=100000;i+=2)
		if(is_prime(i))
			num[i]=true;
	num[1]=false;
	num[2]=true;
	for(int i=1;i<=100000;i++)
		if(num[i]&&num[(i+1)/2])
			a[i]=a[i-1]+1;
		else
			a[i]=a[i-1];
	int n;
	int x,y;
	cin>>n;
	while(n--)
	{
		cin>>x>>y;
		cout<<a[y]-a[x-1]<<endl;
	}
	return 0;
}

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

#define llong long long
#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))

using namespace std;

int main(){
	int N;
	cin >> N;
	int a[N];
	rep(i,0,N) cin >> a[i];
	
	int count=0;
	
	rep(i,0,N){
		if( !(i&1) && (a[i]&1) ){
			count++;
		}
	}
	
	cout << count;
	
	return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    int n[1000], i;
    for (i = 0; i < 3; i++)
    {
        cin >> n[i];
    }
    for (i = 0; i <= 2; i++)
    {
        sort(n, n + 3);
        if (i != 2)
            cout << n[i] << ' ';
        else
            cout << n[i] << endl;
    }
    return 0;
}

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

const int mnx = 1e6 + 9;
const int mod = 1e9 + 7;

ll n, w;
ll a[mnx];
ll b[mnx];
ll dp[mnx];

int main(){
    cin >> n >> w;

    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }

    for(int i = 1; i <= n; i++){
        for(int j = w; j >= a[i]; j--) {
            dp[j] = max(dp[j], dp[j - a[i]] + b[i]);
        }
    }

    ll ans = 0;

    for (int i = 0; i <= w; i++) {
        ans = max(ans, dp[i]);
    }

    cout << ans << '\n';

    return 0;
}

/*
3
10 40 70
20 50 80
30 60 90

10  40  70
90  120 120
150 180 210
*/


















Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int count = sc.nextInt();

		int max = -1000000, min = 1000000;
		long sum = 0;
		for(int i=0; i<count; i++) {
			int n = sc.nextInt();
			if(n > max) max = n;
			if(n < min) min = n;
			sum += n;
			// System.out.println(n);
		}

		sc.close();

		System.out.println(min + " " + max + " " + sum);

	}

}



Measured memory_bytes: 42048
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int a, b, x;
	cin >> a >> b >> x;
	if (a <= x && x <= a + b)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    int M = N / 2;
    vector<int> odd(M);
    vector<int> even(M);
    rep(i,M){
        cin >> odd[i];
        cin >> even[i];
    }
    sort(all(odd));
    sort(all(even));
    odd.push_back(0);
    even.push_back(0);
    int count_odd = 1;
    int odd_main = 0;
    int odd_ans = 0;
    int odd_ans_sub = 0;
    rep(i,M){
        if (odd[i] == odd[i + 1]){
            count_odd++;
        }
        else{
            if (count_odd > odd_ans){
                odd_main = odd[i];
                odd_ans_sub = odd_ans;
                odd_ans = count_odd;
            }
            else if (count_odd > odd_ans_sub){
                odd_ans_sub = count_odd;
            }
            count_odd = 1;
        }
    }
    int count_even = 1;
    int even_main = 0;
    int even_ans = 0;
    int even_ans_sub = 0;
    rep(i,M){
        if (even[i] == even[i + 1]){
            count_even++;
        }
        else{
            if (count_even > even_ans){
                even_main = even[i];
                even_ans_sub = even_ans;
                even_ans = count_even;
            }
            else if (count_even > even_ans_sub){
                even_ans_sub = count_even;
            }
            count_even = 1;
        }
    }
    if (even_main != odd_main){
        cout << N - odd_ans - even_ans << endl;
    }
    else{
        int ans = max(odd_ans + even_ans_sub, even_ans + odd_ans_sub);
        cout << N - ans << endl;
    }
}


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

using namespace std;
typedef long long ll;
const int MAX_N=1e6;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;cin>>n>>k;
  ll ans=k;
  for(int i=1;i<n;i++){
      ans*=(k-1);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
A,B,C = map(int,input().split())
K = int(input())
flag = True

    
  
for i in range(K+1):
  num = K-i
  for j in range(num+1):
    num2 = num-j
    if A*2**i<B*2**j:
      if B*2**j<C*2**num2:
        print("Yes")
        flag = False
        break
  if flag ==False:
    break
        
if flag == True:
  print('No')
        
    
    



Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////


int main(){fastio;
    ll n,m,c;cin>>n>>m>>c;
    ll b[m];rep(i,0,m-1)cin>>b[i];
    ll ans=0;
    while(n--){
        ll a[m];
        rep(i,0,m-1)cin>>a[i];
        ll sum=0;
        rep(i,0,m-1)sum+=a[i]*b[i];
        if(sum+c>0)ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}








Measured memory_bytes: 256
'use strict'

function main(inp) {
  inp = inp.trim().split('\n')
  const NK = inp[0].split(' ').map(n => Number(n));
  inp = inp[1].split(' ').map(n => Number(n));
  
  let sum = 0
  let index = 0
  for (let i = 0; i < NK[1]; i++) {
    sum += inp[i]
    index = i
  }

  let max = sum
  for (let i = NK[1]; i < inp.length; i++) {
    sum = sum - inp[i - NK[1]] + inp[i]
    if (max < sum) {
      max = sum
      index = i
    }
  }

  let kitai = 0
  for (let i = index - NK[1] + 1; i <= index; i++) {
    let sumNum = (1 + inp[i]) * inp[i] / 2
    kitai += sumNum / inp[i]
  }
  console.log(kitai)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 32716
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)

def main():
    N = int(input())
    memo = []
    base = 0
    for i in range(N-1):
        memo.append(base)
        base += N-i-1
    edge = [[] for _ in range((N*(N-1))//2)]
    
    for i in range(N):
        a = list(map(int,input().split()))
        b = []
        for j in a:
            j -= 1
            if i < j:
                b.append(memo[i]+j-i-1)
            else:
                b.append(memo[j]+i-j-1)
        for i in range(N-2):
            edge[b[i+1]].append(b[i])

    go = [False]*((N*(N-1))//2)
    cul = [False]*((N*(N-1))//2)
    dp = [0]*((N*(N-1))//2)
    
    def dfs(v):
        if go[v]:
            if not cul[v]:
                return -1
            return dp[v]
        go[v] = True
        dp[v] = 1
        for u in edge[v]:
            ret = dfs(u)
            if ret == -1:
                return -1
            dp[v] = max(dp[v],ret+1)
        cul[v] = True
        return dp[v]
    
    ans = 0
    for i in range((N*(N-1))//2):
        ret = dfs(i)
        if ret == -1:
            print(-1)
            exit()
        ans = max(ans,ret)
        
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 209024
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    long n,W;
    cin>>n>>W;
    vector<pair<ll,ll> >item(n+1);
    for(int i=1;i<=n;i++)
        cin>>item[i].first>>item[i].second;
    sort(item.begin(),item.end());
    ll dp[n+1][W+1],mx=LONG_MIN;
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=W;j++)
        {
            if(j<item[i].first)
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-item[i].first]+item[i].second);
            if(i==n)
            mx=max(mx,dp[i][j]);
        }
    }
    cout<<mx<<endl;
}

Measured memory_bytes: 79104
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

template<typename T>
vector <T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e:t) fill_v(e, v);
}

typedef pair<int, int> P;

bool isYY (string s) {
    int n = stoi(s);
    return 0 <= n;
}
bool isMM (string s) {
    int n = stoi(s);
    return 1 <= n && n <= 12;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    string s;
    cin >> s;

    int b1 = 0;
    if (isYY(s.substr(0, 2))) b1 += 1;
    if (isMM(s.substr(0, 2))) b1 += 2;

    int b2 = 0;
    if (isYY(s.substr(2, 2))) b2 += 1;
    if (isMM(s.substr(2, 2))) b2 += 2;

    if (b1 == 3 && b2 == 3) {
        cout << "AMBIGUOUS" << endl;
    }
    else if ((b1 & 1) == 1 && (b2 & 2) == 2) {
        cout << "YYMM" << endl;
    }
    else if ((b1 & 2) == 2 && (b2 & 1) == 1) {
        cout << "MMYY" << endl;
    }
    else {
        cout << "NA" << endl;
    }

    return 0;
}


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

using namespace std;
using ll = long long;
const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }

    mint &operator/=(const mint a) { return *this *= a.inv(); }

    mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, const mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }


int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> A, B;

    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int f = 0, b = 0;
        for (int j = 0; j < s.size(); ++j) {
            if (f > 0 && s[j] == ')') {
                f--;
            } else {
                if (s[j] == '(')f++;
                else b++;
            }
        }
        if (f >= b)A.push_back(make_pair(b, -f));
        else B.push_back(make_pair(-f, b));
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int f = 0, b = 0;
    for (auto x:A) {
        if (x.first > f-b) {
            cout << "No" << endl;
            return 0;
        }
        b += x.first;
        f += -x.second;
    }
    for (auto x:B) {
        if (x.second > f-b) {
            cout << "No" << endl;
            return 0;
        }
        b += x.second;
        f += -x.first;
    }
    if (f == b)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 11344
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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 prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    REP(i, n) cin >> a[i];
    FOR(i, k, n) {
        if (a[i - k] < a[i]) cout << "Yes" << endl; else cout << "No" << endl;
    }
}


Measured memory_bytes: 3988
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll N, A, B;
	cin >> N >> A >> B;

	ll ans = 1;

	cout << max(ll(0), A + B * (N - 1) - (A*(N - 1) + B) + 1);



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const long long MOD = 1000000007;
const double EPS = 1e-9;

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

  string S;
  cin >> S;
  int n = S.length();

  vector<int> dp(13);
  dp[0] = 1;

  REP(i, n) {
    vector<int> dp_nxt(13);
    int c;
    if (S[i] == '?') c = -1;
    else c = S[i] - '0';

    REP(j, 10) {
      if (c != -1 && c != j) continue;
      REP(ki, 13) {
        (dp_nxt[(ki * 10 + j) % 13] += dp[ki]) %= MOD;
      }
    }
    dp = dp_nxt;
  }

  cout << dp[5] << endl;
  return 0;
}


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

void show( int arr[], unsigned int size )
{
	cout<<arr[0]<<flush;
	for( unsigned int i=1; i<size; i++ ){
		cout<<' '<<arr[i]<<flush;
	}
	cout<<endl;
}

int merge( int arr[], unsigned int arr_s, unsigned int lft, unsigned int md, unsigned int rgt )
{//??????????????????????????????lft??\???md?????????md??\???rgt???????????????
	int cnt=0;

	//?????????????????????????????????( ???????????????????????????????????????????????????????????? )
	int left_s=md-lft+1, right_s=rgt-md+1, *left=new int[left_s], *right=new int[right_s];
	for( int i=0; i<left_s-1; i++ ){
		left[i]=arr[lft+i];
	}
	left[left_s-1]=INT_MAX;
	for( int i=0; i<right_s-1; i++ ){
		right[i]=arr[md+i];
	}
	right[right_s-1]=INT_MAX; //???????????????????????±???????????¨???????????????????????????

	//??????????????????????????????????????±???,??????
	for( int i=0, left_i=0, right_i=0; i<left_s+right_s-2; i++, cnt++ ){
		if( left[left_i] < right[right_i] ){
			arr[lft+i]=left[left_i];
			++left_i;
		}else{
			arr[lft+i]=right[right_i];
			++right_i;
		}
	}

	delete[] right;delete[] left;
	return cnt;
}

int mergeSort( int arr[], unsigned int arr_s, unsigned int lft, unsigned int rgt ) //??????????????????mergeSort???????????¨???????????¨?????????????????????????????????
{
	static int cnt=0;
		unsigned int md=(lft + rgt)/2;
	if( rgt - lft >=2 ){

		//????????????????????¨???????????????.??±????????????????????\????????´?????????
		mergeSort(arr, arr_s, lft, md);  
		mergeSort(arr, arr_s, md, rgt);
		//??????(????????????)! ?????§?????????????????????????????????????????°?????????????????????????????????????????????????????§????????????
		cnt+= merge(arr, arr_s, lft, md, rgt); //if ?????????????????????????????????????¨?
	
	}
	return cnt;
}

int main()
{
	int arr_s;
	cin>>arr_s;
	int *arr=new int[arr_s];
	for( int i=0; i<arr_s; i++ ){
		cin>>arr[i];
	}

	int cnt=mergeSort(arr, arr_s, 0, arr_s);
	show(arr, arr_s);
	cout<<cnt<<endl;

	delete[] arr;
}

Measured memory_bytes: 5060
N,x=map(int,input().split())
a=list(map(int,input().split()))

ans=0
for i in range(N-1):
    if a[i]+a[i+1]>x:
        ans+=a[i]+a[i+1]-x
        if a[i]<=x:
            a[i+1]=x-a[i]
        else:
            a[i+1]=0
print(ans)

Measured memory_bytes: 14252
#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 <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
        int N, K;
        cin >> N >> K;
        vector<int> B(N + 1, 0);

        rep(i, N)
        {
                int a;
                cin >> a;
                B[a--]++;
        }

        sort(all(B));
        // rep(i, N + 1)
        // {
        //         cout << B[i] << ' ';
        // }
        // cout << endl;

        int ans = 0;
        rep(i, N - K + 1)
            ans += B[i];

        cout << ans << endl;

        return 0;
}


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

int main (){
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    if( K <= A){
        cout << K << endl;
    }
    else if( K <= ( A + B)){
        cout << A << endl;
    }
    else{
        cout << ( A + A + B - K);
    }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
struct UnionFind{
public:
    vector<int> par;
    vector<int> rank;
    vector<int> s;
    int cnt;
 
    UnionFind(int n){
        rep(i,n){
            par.push_back(i);
            rank.push_back(0);
            s.push_back(1);
        }
        cnt=n;
    }
 
    int find(int x){
        if(par[x]==x) return x;
        else return par[x]=find(par[x]);
    }
 
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){
            par[x]=y;
            s[y]+=s[x];
        }else{
            par[y]=x;
            s[x]+=s[y];
            if(rank[x]==rank[y]) rank[x]++;
        }
        cnt--;
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }

    int size(int x){
        return s[find(x)];
    }
};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        a--,b--;
        uf.unite(a,b);
    }
    set<ll> st;
    rep(i,n) st.insert(uf.find(i));
    cout<<st.size()-1<<endl;
}

Measured memory_bytes: 8188
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+10,inf=1e9+7;
typedef long long ll;
ll h,w,node[maxn],n,a,b,cnt=0,zero,ans[15];

int main(){
    scanf("%lld%lld%lld",&h,&w,&n);
    zero=(h-2)*(w-2);
    while(n--){
        scanf("%lld%lld",&a,&b);
        for (int i=-2;i<=0;i++){
            for (int j=-2;j<=0;j++){
                if(a+i>=1 && a+i <=h-2 && b+j>=1 &&b+j <=w-2){
                    node[cnt++]=inf*(a+i)+(b+j);
                }
            }
        }
    }
    sort(node,node+cnt);
    for (int i=0,tmp=1;i<cnt;i++){
        if(node[i]==node[i+1]) tmp++;
        else ans[tmp]++,zero--,tmp=1;
    }
    printf("%lld\n",zero);
    for (int i=1;i<10;i++)
        printf("%lld\n",ans[i]);
    return 0;
}

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

using namespace std;

struct Piece {
  int w,d;
  Piece(int w=0,int d=0) : w(w), d(d) {}
};

int main() {
  int n, w, d;
  while (cin >> n >> w>>d, n||w||d) {
    vector<Piece> pieces(1);
    pieces[0] = Piece(w,d);
    for(int i =0; i<n; i++) {
      int p,s;
      cin >>p>>s;
      p--;
      Piece target = pieces[p];
      pieces.erase(pieces.begin()+p );
      int dir = 0;
      int ds[] = {target.w, target.d, target.w, target.d};
      while (ds[dir] < s) s -= ds[dir], dir = (dir + 1)%4;
      Piece p1,p2;
      if(dir%2==0) {  // cut vertical
	p1 = Piece(s, target.d);
	p2 = Piece(target.w-s, target.d);
      } else {  // cut horizontal
	p1 = Piece(target.w, s);
	p2 = Piece(target.w, target.d-s);
      }
      if (p1.w*p1.d > p2.w*p2.d) swap(p1,p2);
      pieces.push_back(p1);
      pieces.push_back(p2);
    }

    vector<int> as;
    for(int i =0;i < pieces.size();i++) as.push_back(pieces[i].w*pieces[i].d);
    sort(as.begin(), as.end());
    cout <<as[0];
    for(int i = 1; i < pieces.size(); i++) {
      //int sum = 0;
      //while (ppieces[i].w*pieces[i].d == pieces[i+1].w*pieces[i+1].d)
      cout << " "<<as[i];
    }
    cout<<endl;
  }
} 

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
int n;
int main(){
	cin >> n;
	cout << (n + 1) / 2 << endl;	
    return 0;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define int ll
#define pll pair<ll, ll> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;

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

signed main(){
	FASTIO
	int n, k;
	cin >> n >> k;
	int p[n+1], c[n+1];
	rep(i, 1, n+1)
		cin >> p[i];
	rep(i, 1, n+1)
		cin >> c[i];
	vector<bool> vis(n+1, false);
	int sol = *max_element(c + 1, c + n + 1);
	rep(i, 1, n + 1){
		int ans = c[i];
		rep(i, 1, n + 1)
			vis[i] = false;
		int temp = 0, sum = 0;
		int u = i, y = k, l = 0;
		while(!vis[u] && y > 0){
			vis[u] = true;
			u = p[u];
			sum += c[u];
			l++;
		}
		if(y / l > 1 && sum > 0){
			temp = temp + sum * ((y / l) - 1);
			ans = max(ans, temp);
		}
		if(y / l > 0){
			rep(i, 1, n + 1)
				vis[i] = false;
			u = i;
			while(!vis[u]){
				vis[u] = true;
				u = p[u];
				temp = temp + c[u];
				ans = max(ans, temp);
			}	
		}
		rep(i, 1, n + 1)
			vis[i] = false;
		y = y % l;
		u = i;
		if(temp < 0) temp = 0;
		while(!vis[u] && y > 0){
			vis[u] = true;
			u = p[u];
			y--;
			temp = temp + c[u];
			ans = max(ans, temp);
		}
		sol = max(sol, ans);
	}
	cout << sol;
    return 0;
}
 

Measured memory_bytes: 3720
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args){
        Scanner r =new Scanner(System.in);
        int w = r.nextInt();
        int h = r.nextInt();
        int x = r.nextInt();
        int y = r.nextInt();
        int z = r.nextInt();
        if(z <= x && x <= (w -z) && z <= y && y <= (h - z)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
 
}

Measured memory_bytes: 26384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int n, h, w;
  cin >> n >> h >> w;
  int count = 0;

  int a, b;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    if (a >= h && b >= w) ++count;
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int n, x;

    cin >> n >> x;

    int mn = 2000;
    forn(i, n) {
        int a;
        cin >> a;
        x -= a;
        chmin(mn, a);
    }

    cout << n + x / mn << endl;

    return 0;
}

Measured memory_bytes: 256
#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;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return (ans.x+m)%m;
}
int fact[N];
void calfac(int n ){
fact[0] = 1;
for(int i = 1 ; i <= n+2; i++){
 fact[i] = (((fact[i-1]%mod)*(i%mod))%mod + mod)%mod;
}
 }
int calc(int n , int r){
 if(r > n)return 0;
 if(r == n)return 1;
 int ans = 1;
 ans = ((ans%mod)*(fact[n])%mod + mod)%mod;
 ans = ((ans%mod)*(mmInverse(fact[n-r] , mod)%mod) + mod)%mod;
 ans = ((ans%mod)*(mmInverse(fact[r] , mod)%mod) + mod)%mod;
 return (ans+mod)%mod;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
//vector<int>p;
int p[n];
int q[n];
//vector<int>q;
//cin>>n;
for(int i = 0 ; i < n ; i++){
  cin>>p[i];
}
for(int i = 0 ; i < n ;i++){
  cin>>q[i];
}
int small = -1;
for(int i = 0 ; i < n ;i++){
  if(p[i] < q[i]){
   small = 1;
   break;
  }
  else if(p[i] > q[i]){
    small = 0;
    break;

}
}
if(small == -1){
 cout<<0<<endl;
 return 0;
}
if(small != 1){
 for(int i=  0 ; i < n ;i++){
  swap(p[i] , q[i]);
 }
}
  
vector<int> v;
for(int i = 0 ; i < n ;i++){
    v.pb(i+1);
}
int fir = -1 , sec = -1;
int cnt = 0;
sort(v.begin() , v.end());
//for(int i = 0 ; i <  n;i++)cout<<v[i]<<" ";
do{
	cnt++;
	bool ok = true;
	for(int i = 0 ; i < n ;i++){
	 if(v[i] != p[i]){
	  ok = false;
	 }
 }
 if(ok){
  if(fir == -1){
       fir = cnt;
  }
  else if(sec == -1){
   sec = cnt;
  }
 }
 else{
  bool okk = true;
	for(int i = 0 ; i < n ;i++){
	 if(v[i] != q[i]){
	  okk = false;
	 }
 }
 if(okk){
  if(fir == -1){
       fir = cnt;
  }
  else if(sec == -1){
   sec = cnt;
  }
 }
 }
 
}while(next_permutation(v.begin() , v.end()));
cout<<abs(fir - sec)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)

int get_min_d(int i, int j, int x, int y){
  return min(abs(j-i),min(abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x)));
}




int main(){
  int n, x, y;
  int d[2000] = {0};
  cin >> n >> x >> y;

  for(int i=1; i<=n;i++){
    for(int j=i+1;j<=n;j++){
      d[get_min_d(i, j, x, y)]++;
    }
  }
  for(int i=1;i<n;i++){
    cout << d[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <cmath>
#include <iomanip>

#define vec vector

using namespace std;

using ll = long long;
using vl = vector<long long>;
using vi = vector<int>;
using vvl = vector<vl>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using ld = long double;

int main()
{   
    int n, k;
    cin >> n >> k;
    ll mod = 1e9 + 7;
    vi a(n);
    for (auto &e : a)
        cin >> e;
    vl dp(k + 1), dpt(k + 1, 0);
    for (int i = 0; i <= a[0]; i++)
        dp[i] = 1;
    for (int i = 1; i < n; i++)
    {
        ll ways = 0;
        for (int j = 0; j < k + 1; j++)
        {
            ways = (ways + dp[j]) % mod;
            dpt[j] = ways;
            if (j >= a[i])
                ways = (mod + ways - dp[j - a[i]]) % mod;
        }
        dp = vl(dpt.begin(), dpt.end());
    }
    cout << dp[k];
    return 0;
}

Measured memory_bytes: 2560
N = int(input())
A = list(int(input()) for _ in range(N))

A_max = sorted(A, reverse = True)[0]
A_second = sorted(A, reverse=True)[1]

for i in range(N):
    if A[i] == A_max:
        print(A_second)
    else:
        print(A_max)
        

Measured memory_bytes: 19016
/*
*
*Problem Link : https://atcoder.jp/contests/dp/tasks/dp_b
*Platform: atcoder
*Status: Correct
*Author: Mayukh Chakrabarti
*
*/

#include<bits/stdc++.h>
#define speed ios_base::sync_with_stdio(false)
#define boost cin.tie(NULL)
#define booster cout.tie(NULL)
#define endl "\n"
typedef long long int lld;

#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;

using namespace std;


int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector<int> ar(N);
	F(ar,N);
	
	vector<int> dp(N,INT_MAX);
	
	dp[0]=0; //we have to step on the first stone without any cost
	
	for(int i=0;i<N-1;i++) //for looping stones
		for(int j=1; j<=K; j++ ) //for looping jumps
			if(i+j < N)
				dp[i+j]= min(dp[i+j], dp[i]+ abs(ar[i]-ar[i+j]) );
	
	cout<<dp[N-1];
	
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
typedef vector<int> vi;

//d[i][j]はi番目からj番目のスライムについて最小
lli d[402][402];
lli s[402][402];
lli sum[402];

int main(){
	int N;
	cin>>N;
	
	lli a[401];
	
	rep1(i,N){
		cin>>a[i];
		sum[i]+=sum[i-1]+a[i];
	}
	rep1(i,N)for(int j=i;j<=N;j++)s[i][j]=sum[j]-sum[i-1];
	
//	rep1(j,N)d[j][j]=a[j];
	rep1(i,N-1)rep1(j,N-i){
		lli x=1e18;
		for(int k=j;k<=i+j-1;k++){
			x=min(x,d[j][k]+d[k+1][j+i]);
		}
		d[j][j+i]=x+s[j][j+i];
	}
	cout<<d[1][N];
}

Measured memory_bytes: 2816
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  while (1) {
    cin >> n;
    if (n == 0) break;
    vector<int> s(n);
    double m = 0;
    rep(i, n) {
      cin >> s[i];
      m += s[i];
    }
    m = m / n;
    double bunsan = 0;
    rep(i, n) bunsan += (s[i] - m) * (s[i] - m);

    printf("%f\n", sqrt(bunsan / n));
  }
  return 0;
}


Measured memory_bytes: 3132
#include <iostream>
using namespace std;
typedef long long ll;
int main(void){
    int n, r, g, b, d[3000], m=0;
    cin>>r>>g>>b>>n;
    fill(d, d+n+1, 0);
    for(int i=0;i*r<=n;i++){
        for(int j=0;i*r+j*g<=n;j++){
            d[i*r+j*g]++;
        }
    }
    for(int i=0;i*b<=n;i++){
        m+=d[n-i*b];
    }
    cout<<m<<endl;
}


Measured memory_bytes: 256
#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>

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 = 1e9 + 7;
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

int w, a, b;

int main() {
	cin >> w >> a >> b;
	if (b - (a + w) > 0) {
		cout << b - (a + w) << endl;
		return 0;
	}
	if (a - (b + w) > 0) {
		cout << a - (b + w) << endl;
		return 0;
	}
	cout << 0 << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll T,X;

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

  cin>>T>>X;
  printf("%.10f\n", (double)T/(double)X);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e9;

int N, M;
vector<int> A;

int num[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[100010];

string f() {
  string S = "";
  int i = N;
  while (1) {
    if (i == 0) {
      return S;
    }
    for (int j = 0; j < M; j++) {
      int k = i - num[A[j]];
      if (k >= 0 && dp[k] == dp[i] - 1) {
        S = S + to_string(A[j]);
        i -= num[A[j]];
        break;
      }
    }
  }
  return S;
}
void abc118d() {
  sort(A.rbegin(), A.rend());

  for (int i = 1; i <= N; i++) {
    dp[i] = -INF;
  }
  dp[0] = 0;

  for (int i = 1; i <= N; i++) {
    int dp_tmp = -INF;
    for (int j = 0; j < M; j++) {
      int k = i - num[A[j]];
      if (k >= 0 && dp[k] != -INF) {
        dp_tmp = max(dp_tmp, dp[i - num[A[j]]] + 1);
      }
    }
    dp[i] = dp_tmp;
  }

  cout << f() << "\n";
  return;
}

int main() {
  cin >> N >> M;
  A.assign(M, 0);
  for (int i = 0; i < M; i++) {
    cin >> A[i];
  }
  abc118d();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;


int main(int argc, char* argv[]){
	int N;
	scanf("%d", &N);
	long long A[N];
	long long ans=1;
	bool zero_flag=false;
	for(int i=0; i<N; i++){
		scanf("%lld", &A[i]);
		if(A[i]==0)zero_flag=true;
	}
	if(zero_flag){
		ans=0;
	}else{
		for(int i=0; i<N; i++){
			long long prev_ans=ans;
			ans*=A[i];
			if(ans/A[i] != prev_ans||ans>1000000000000000000||ans<0 || prev_ans>ans){
				ans=-1;
				break;
			}
		}
	}
	printf("%lld\n", ans);



	return 0;
}







Measured memory_bytes: 4540
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	while(cin>>n,n){
		int t=0;
		vint v(n);
		rep(i,n) cin>>v[i];
		rep(i,n){
			cout<<v[i];
			if(i==n-1){
				cout<<endl;
				break;
			}
			if(v[i+1]-v[i]==1){
				reep(j,i+1,n){
					// cout<<"j "<<j<<" "<<v[j]<<endl;
					if(v[j]-v[j-1]==1);
					else{
						cout<<"-"<<v[j-1]<<" ";
						i=j-1;
						break;
					}
					if(j==n-1){
						cout<<"-";
						i=n-2;
						break;
					}
				}
			}
			else{
				cout<<" ";
			}
		}
	}
}

Measured memory_bytes: 1196
MOD = 1000000007
INF = float("inf")

n = int(input())
k = int(input())

len_n = len(str(n))
# print(len_n)
if len_n < k:
    print(0)
    exit()

base = [[0]*4 for _ in range(200)]

for i in range(200):
    base[i][0] = 1
for i in range(1, 200):
    base[i][1] = 9 * i
for i in range(2, 200):
    base[i][2] = 9 * 9 * i*(i-1)//2
for i in range(3, 200):
    base[i][3] = 9 * 9 * 9 * i * (i - 1) * (i-2) // 6

ans = 0
len_n = len(str(n))
n_str = str(n)

for i in range(len(n_str)):
    # print(len_n)
    if int(n_str[i]) > 0:
        ans += (int(n_str[i])-1)*base[len_n-1][k-1] + base[len_n-1][k]
        # print(ans)
        if k == 1:
            ans += 1
        k -= 1
    len_n -= 1
    if k == 0:
        break

print(ans)


Measured memory_bytes: 38384
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    let n: usize = read!();
    let mut va: Vec<usize> = vec![];

    let mut count = vec![0; 1000005];
    for _ in 0..n {
        let a: usize = read!();
        va.push(a);
        count[a] += 1;
    }

    let mut ok = vec![true; n];

    for (j, &a) in va.iter().enumerate() {
        if a == 1 {
            if count[1] == 1 {
                println!("{}", 1);
                std::process::exit(0);
            } else {
                println!("{}", 0);
                std::process::exit(0);
            }
        } else if count[a] != 1 {
            ok[j] = false;
        } else {
            for m in 2..=a {
                if m * m > a {
                    break;
                } else {
                    match (a / m, a % m) {
                        (d, 0) => {
                            if count[d] != 0 || count[m] != 0 {
                                ok[j] = false;
                                break;
                            }
                        }
                        (_, _) => (),
                    }
                }
            }
        }
    }

    // for i in 0..n {
    //     println!("{} {} {}", va[i], ng[i], count[i]);
    // }

    println!("{}", ok.iter().filter(|&&m| m).count());
}


Measured memory_bytes: 7580