akhauriyash/Code-Regression huggingface dataset:
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int n,k;
    cin>>n>>k;
    ll r,s,p;
    cin>>r>>s>>p;

    ll total=0;

    string T;
    cin>>T;
    ll dp[n][3];
    for(int i=0;i<n;i++){
        if(i<k){
            if(T[i]=='r'){
                dp[i][0]=0;
                dp[i][1]=0;
                dp[i][2]=p;
            }
            if(T[i]=='s'){
                dp[i][0]=r;
                dp[i][1]=0;
                dp[i][2]=0;
            }
            if(T[i]=='p'){
                dp[i][0]=0;
                dp[i][1]=s;
                dp[i][2]=0;
            }
        }
        else{
            if(T[i]=='r'){
                dp[i][0]=max(dp[i-k][1],dp[i-k][2]);
                dp[i][1]=max(dp[i-k][0],dp[i-k][2]);
                dp[i][2]=max(dp[i-k][1],dp[i-k][0])+p;
            }
            if(T[i]=='s'){
                dp[i][0]=max(dp[i-k][1],dp[i-k][2])+r;
                dp[i][1]=max(dp[i-k][0],dp[i-k][2]);
                dp[i][2]=max(dp[i-k][1],dp[i-k][0]);
            }
            if(T[i]=='p'){
                dp[i][0]=max(dp[i-k][1],dp[i-k][2]);
                dp[i][1]=max(dp[i-k][0],dp[i-k][2])+s;
                dp[i][2]=max(dp[i-k][1],dp[i-k][0]);
            }
        }
    }

    for(int i=n-1,j=0;j<k;j++,i--){
        total+=max(dp[i][0],max(dp[i][1],dp[i][2]));
    }
    cout<<total<<"\n";
}


Measured memory_bytes: 2768
import bisect
n = int(input())
colors = [-int(input())]
for _ in range(n-1):
    a = int(input())
    i = bisect.bisect_right(colors, -a)
    if i == len(colors):
        colors.append(-a)
    else:
        colors[i] = -a
print(len(colors))

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

const ll L = 105;

vector <ll> a(L);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    ll N;
    cin >> N;

    for(ll i=0; i<N; i++)
    {
        cin >> a[i];
    }

    ll cur = -100;
    ll cost = 1e15;

    while(cur<=100)
    {
        ll temp = 0;
        for(ll i=0; i<N; i++)
        {
            temp+=((cur-a[i])*(cur-a[i]));
        }

        cost = min(cost, temp);

        cur++;
    }

    cout << cost << endl;

    

    return 0;
}

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

int main()
{
    int N, K;
    cin >> N >> K;

    if (K * 2 - 1 <= N)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
}

Measured memory_bytes: 256
N, P = list(map(int, input().split()))
A = list(map(int, input().split()))

odd = 0
even = 0

for ai in A:
    if ai % 2 == 0:
        even += 1
    else:
        odd += 1

if odd == 0:
    if P == 1:
        ans = 0
    else:
        ans = (2 ** even) 
else:
    ans = (2 ** even) * ((2 ** odd) // 2)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int n, m, x, y;
    cin >> n >> m >> x >> y;

    vector<int> X(n);
    vector<int> Y(m);

    rep(i, n) cin >> X.at(i);
    rep(i, m) cin >> Y.at(i);

    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());

    int x_max = X.back();
    int y_min = Y.front();

    vector<int> possible;
    for (int i = x_max + 1; i <= y_min; i++) {
        possible.push_back(i);
    }

    for (auto p : possible) {
        if (x < p && p <= y) {
            cout << "No War";
            return 0;
        }
    }

    cout << "War";
    return 0;
}

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


int main(){
  int n;
  cin>>n;
  vector<int>b(n-1);
  for(int i=0;i<n-1;i++)cin>>b[i];
  vector<int>a(n);
  a[0]=b[0];
  a[n-1]=b[n-2];
  for(int i=1;i<n-1;i++){
    a[i]=min(b[i-1],b[i]);
  }
  ll sum=0;
  for(int i=0;i<n;i++)sum+=a[i];
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr int MOD_TYPE = 1;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

#pragma endregion

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

  ll n;
  cin >> n;
  ll a[100010], b[100010];
  rep(i, n + 1) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll sum = 0;
  rep(i, n)
  {
    if (a[i] >= b[i])
    {
      sum += b[i];
    }
    else
    {
      b[i] -= a[i];
      sum += a[i];
      if (a[i + 1] >= b[i])
      {
        a[i + 1] -= b[i];
        sum += b[i];
      }
      else
      {
        sum += a[i + 1];
        a[i + 1] = 0;
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1792
import bisect

N = input()
N = int(N)
L = list(map(int,input().split()))

L_sorted = sorted(L, reverse = False)#昇順

count = 0
for i in range(N):#aの選び方
    for j in range(i+1,N):#bの選び方
        a = L_sorted[i]
        b = L_sorted[j]#b <= c < a+b
        count += bisect.bisect_left(L_sorted, a+b) - j -1
print(count)

Measured memory_bytes: 68164
n, m = gets.chomp.split.map(&:to_i)
a = []
n.times{a << gets.to_i}
vote = Array.new(n, 0)
m.times{
    b = gets.to_i
    v = nil
    a.each_with_index{|cost, i|
        if cost <= b
            v = i
            break
        end
    }
    vote[v] += 1
}
puts vote.index(vote.max) + 1


Measured memory_bytes: 6876
#include <stdio.h>
#include <math.h>
#define TH (0.00001*q)

int main(int argc, char *argv[]){
     int q; double x;

     while(scanf("%d",&q), q!=-1){
	  x = q/2.0;

	  while(fabs(x*x*x - q) >= TH)
	       x = x - (x*x*x-q)/(3*x*x);
	  
	  printf("%lf\n",x);
     }

     return 0;
}

Measured memory_bytes: 0
// Created by sz
#include <bits/stdc++.h>
using namespace std;

map<int,int> cnt;


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int temp;
    while (cin>>temp) {
        cnt[temp] ++;
    }
    if(cnt[5] == 2&& cnt[7] == 1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  int n, a, b;
  cin >> n >> a >> b;

  int up = min(a, b), down = max(0, a + b - n);

  cout << up << " " << down << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define N 1000000007

long long pan(long long n)
{
  //printf("pan called pan(%lld)\n",n);
  if(n<=1)
    return 1;
  else
    return 2*pan((n-3)/2) + 1;
}

long long barger(long long left, long long right, long long x)
{
  //printf("barger called: barger(%lld, %lld, %lld)\n",left,right,x);
  long long mid = (right+left)/2;
  if(left>=mid)
    return 1;
  else if(x==right && (right-left)>0)
    return 0;
  else if(x<mid)
    return barger(left+1, mid-1, x) + 1 + pan(right-mid-1);
  else if(x==mid)
    return 1 + pan(right-mid-1);
  else if(mid<x)
    return barger(mid+1, right-1, x);
}

int main(void)
{
  long long n, layer, x, ans;
  scanf("%lld %lld",&n,&x);
  layer = pow(2, n+2) - 3;
  x = layer-x+1;
  //printf("layer: %lld\n",layer);
  ans = barger(1, layer, x);
  printf("%lld",ans);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
  int A,B;
  
  scanf("%d %d",&A,&B);
  
  if(A>=13)
  {
    printf("%d",B);
  }
  else if(A>=6 && A<13)
  {
    printf("%d",B/2);
  }
  else
  {
    printf("0\n");
  }
  
  return 0;
    
}

Measured memory_bytes: 128
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W; cin >> H >> W ;
  vvi a(H,vi(W));
  int s = 0;
  rep(i,H) rep(j,W){
    cin >> a[i][j] ;
    s += a[i][j];
  }
  vector<string> ans;
  rep(i,H){
    rep(j,W-1){
      if(a[i][j]%2){
        a[i][j+1]++;
        string ss = "";
        ss += to_string(i+1)+" "+to_string(j+1)+" "+to_string(i+1)+" "+to_string(j+2);
        ans.pb(ss);
      }
    }
  }
  rep(i,H-1){
    if(a[i][W-1]%2==0) continue;
    a[i+1][W-1]++;
    string ss = "";
    ss += to_string(i+1)+" "+to_string(W)+" "+to_string(i+2)+" "+to_string(W);
    ans.pb(ss);
  }
  cout << ans.size() << endl;
  for(auto ss:ans) cout << ss << endl;
  return 0;
}


Measured memory_bytes: 9972
import math
from functools import reduce
from copy import deepcopy
n,m = map(int,input().split())
A = list(map(int,input().split()))
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)
Acopy = deepcopy(A)
flag = -1
for i in range(n):
  cnt = 0
  while True:
    if Acopy[i] % 2 == 1:
      break
    else:
      Acopy[i] //= 2
      cnt += 1
  if i == 0:
    flag = cnt
  else:
    if flag != cnt:
      print(0)
      break
else:
  A = [a//2 for a in A]
  lcm = lcm_list(A)
  print((lcm+m)//2//lcm)


Measured memory_bytes: 83764
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        do_(inp);
        inp.close();
    }
    public static void do_(Scanner inp) {
        int a = inp.nextInt();
        int b = inp.nextInt();
        System.out.println(a == b ? "Yes" : "No");
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <iomanip>

using ll = long long;

int main() {
  ll N;
  std::cin >> N;

  ll ans = 0;

  for (ll i=1; i*(i+2)<=N; i++) {
    if (N % i == 0) {
      ans += N / i - 1;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>

#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>
#define push_back pb
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll a[3];
	cin >> a[0] >> a[1] >> a[2];

	rep(i,3){
		if(a[i] % 2 == 0){
			cout << 0 << endl;
			return 0;
		}
	}

	sort(a,a+3);

	cout << (a[0] * a[1]) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long int 
#define def(a,b) ((a>b)?a-b:b-a)
using namespace std;



int main() {
	int a,b,c,d;
	cin >> a >> b >> c >> d;

	if (def(a,c) > d) {
		if (def(a,b) > d || def(b,c) > d) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define MAX_N 200
#define INF 999999999


int edge[MAX_N][MAX_N];

int prim(int n){    //n : ???????????°
    bool used[MAX_N];
    int mincost[MAX_N];
    
    rep(i,n){
        mincost[i]=INF;
        used[i]=false;
    }
    mincost[0]=0;
    int res=0;
    
    while(1){
        int v=-1;
        rep(u,n){
            if(used[u]==false && ( v==-1 || mincost[u]<mincost[v] ))
                v=u;
        }
        if(v==-1)break;
        used[v]=true;
        res+=mincost[v];
        
        rep(u,n){
            mincost[u]=min(mincost[u],edge[v][u]);
        }
    }
    return res;
}

int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        
        rep(i,200)rep(j,200)edge[i][j]=INF;
        rep(i,m){
            int a,b,c;
            cin>>a>>b>>c;
            edge[a][b]=edge[b][a]=c;
        }
        cout<<prim(n)<<endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll s, w;
  cin >> s >> w;

  cout << (w >= s ? "unsafe" : "safe") << endl;
  return 0;
}


Measured memory_bytes: 3624
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto s = readln.chomp.split;
  int[string] cnt;
  foreach (e; s) {
    cnt[e]++;
  }

  if (cnt.keys.length == 3) {
    writeln("Three");
  } else {
    writeln("Four");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

int n;
int pos[2][5000];
int a[5000], c[5000];
int big[2][5000][5000];
int small[2][5000][5000];
int dp[5000][5000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < 2 * n; i++)
    {
        char b;
        cin >> b >> a[i];
        if (b == 'W') c[i] = 1;
        else c[i] = 0;
        pos[c[i]][a[i]] = i;
    }
    for (int i = 0; i < 2 * n; i++)
    {
        if (i) for (int j = 0; j <= n; j++)
        {
            big[0][i][j] = big[0][i - 1][j];
            big[1][i][j] = big[1][i - 1][j];
            small[1][i][j] = small[1][i - 1][j];
            small[1][i][j] = small[1][i - 1][j];
        }
        for (int j = 0; j < a[i]; j++)
        {
            big[c[i]][i][j]++;
        }
        for (int j = a[i] + 1; j <= n; j++)
        {
            small[c[i]][i][j]++;
        }
        //cout << endl;
    }
    int INF = 1e9;
    for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++)
        dp[i][j] = INF;
    dp[0][0] = 0;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            if (i * i + j * j > 0)
            {
                dp[i][j] = min(
                (i > 0 ? dp[i - 1][j] + big[0][pos[0][i]][i] + big[1][pos[0][i]][j] /*- small[1][pos[1][j]][j + 1]*/ : INF),
                (j > 0 ? dp[i][j - 1] + big[1][pos[1][j]][j] + big[0][pos[1][j]][i] /*- small[0][pos[0][i]][i + 1]*/ : INF)
                );
            }
            //cout << dp[i][j] << " ";
        }
        //cout << endl;
    }
    cout << dp[n][n];
}


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

struct P {
    int b;
    ll c;

    bool operator<(const P &another) const {
        if (c == another.c)
            return b > another.b;
        else
            return c > another.c;
    };
};

int main() {
  int N,M;
  cin >> N >> M;
  vector<P> A(N);
  rep(i,N){
    ll a;
    cin >> a;
    A[i] = {1,a};
  }
  rep(i,M){
    int B,C;
    cin >> B >> C;
    A.push_back({B,C});
  }
  sort(all(A));

  ll ans = 0;
  int idx = 0;
  rep(i,N){
    if(A[idx].b == 0){
      idx++;
    }
    ans += A[idx].c;
    A[idx].b--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6240
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

long long sum[51], p[51];

long long rec(long long n, long long x) {
  if (n == 0) {
    if (x >= 1) return 1;
    else return 0;
  }
  if (sum[n-1] + 1 < x) {
    return p[n-1] + 1 + rec(n-1, x-2-sum[n-1]);
  } else {
    return rec(n-1, x-1);
  }
}

int main() {
  long long n, x; cin>>n>>x;
  sum[0] = 1, p[0] = 1;;
  rep(i, 50) {
    sum[i+1] = 3 + 2*sum[i];
    p[i+1] = 1 + 2*p[i];
  }
  print(rec(n, x));

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

int main()
{
	string s;
	cin >> s;
	set<char> S;
	for (int i = 0; i < s.size(); ++i)
	{
		S.insert(s[i]);
	}
	for (char w = 'a'; w <= 'z'; ++w)
	{
		if (S.count(w) == 0)
		{
			cout << w << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  int a,b,c,d;
  a = n/1000; b = (n/100)%10;
  c = (n/10)%10; d = n%10;
  int sum = a+b+c+d;
  if(sum == 7) {
    cout << a << '+' << b << '+' << c << '+' << d << '=' << 7 << endl;
    return 0;
  }
  if(sum-b*2 == 7) {
    cout << a << '-' << b << '+' << c << '+' << d << '=' << 7 << endl;
    return 0;
  }
  if(sum-c*2 == 7) {
    cout << a << '+' << b << '-' << c << '+' << d << '=' << 7 << endl;
    return 0;
  }
  if(sum-d*2 == 7) {
    cout << a << '+' << b << '+' << c << '-' << d << '=' << 7 << endl;
    return 0;
  }
  if(sum-b*2-c*2 == 7) {
    cout << a << '-' << b << '-' << c << '+' << d << '=' << 7 << endl;
    return 0;
  }
  if(sum-b*2-d*2 == 7) {
    cout << a << '-' << b << '+' << c << '-' << d << '=' << 7 << endl;
    return 0;
  }
  if(sum-c*2-d*2 == 7) {
    cout << a << '+' << b << '-' << c << '-' << d << '=' << 7 << endl;
    return 0;
  }
  if(sum-b*2-c*2-d*2 == 7) {
    cout << a << '-' << b << '-' << c << '-' << d << '=' << 7 << endl;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 200005
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
#define mp make_pair
#define ff first
#define ss second

int n,m;

inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int a[maxn],b[maxn],ta[maxn],tb[maxn];

ll calc(int lim){
	ll ret=0;
	for (int i=1,j=n;i<=n;i++){
		while (j&&ta[i]+tb[j]>lim) --j;
		ret+=j;
	}
	return ret;
}

int solve(int x){
	int all=(x<<1)-1;
	for (int i=1;i<=n;i++) ta[i]=a[i]&all;
	for (int i=1;i<=n;i++) tb[i]=b[i]&all;
	sort(ta+1,ta+n+1),sort(tb+1,tb+n+1);
	return (calc((x<<1)-1)-calc(x-1)+calc((x<<2)-1)-calc(3*x-1))&1;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++) b[i]=read(); int ans=0;
	for (int i=0;i<=28;i++) ans+=solve(1<<i)<<i;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main()
{
	int a,b,t;
 	cin>>a>>b>>t;
	int total=0;
	int time=0;
	int i = 1;
	time = time + i*a;
	while(time<=t)
	{
		time = time + i*a;
		total = total+b;
	}	

	cout<<total;
			

        return 0;
}       



Measured memory_bytes: 256
N=int(input())
a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

name=[]

for i in range (20):
    N=N-1
    name.insert(0,a[N%26])
    N=N//26
    if N==0:
        break

print(''.join(name))

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < N; i++) cin >> B.at(i);
  
  vector<int> SA(N), SB(N);
  SA.at(0) = A.at(0);
  SB.at(N - 1) = B.at(N - 1);
  for (int i = 1; i < N; i++) SA.at(i) = SA.at(i - 1) + A.at(i);
  for (int i = 1; i < N; i++) SB.at(N - 1 - i) = SB.at(N - i) + B.at(N - 1 - i);
  
  int ans = 0;
  for (int i = 0; i < N; i++) ans = max(ans, SA.at(i) + SB.at(i));
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    int d = a / b;
    int r = a % b;
    double f = (double) a / b;

    printf("%d %d %.6lf\n", d, r, f);

    return 0;
}


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

template <typename T, typename K> struct P {
	T a;
	K b;
};

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	cout<<fixed<<setprecision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	ll* vec = new ll[N];
	ll ans = 0;
	rep( i, 0, K ){
		cin >> vec[i];
		ans += vec[i];
	}
	ll temp = ans;
	rep( i, K, N ){
		cin >> vec[i];
		temp += vec[i]-vec[i-K];
		ans = max( ans, temp);
	}
	cout << ( double )(ans + K ) / 2 << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


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

int main(){
	int n,y;
	cin >> n >> y;
	
	for(int x=0;x<=y/10000;x++){
		for(int b=0;b<=y/5000;b++){
			int z=n-x-b;
			if(z>=0&&x*10000+b*5000+z*1000==y)
			{
				cout<<x<<' '<<b<<' '<<z;
				return 0;
			}
		}
	}
	
	cout<<"-1 -1 -1";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  string s1,s2,s3;
  C3(s1,s2,s3);
  cout << s1[0] << s2[0] << s3[0] <<endl;
  ret 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int first = 0;
        if (n >= k) {
            first = n - k + 1;
        }
        long dp[] = new long[300000];
        for (int i = 0; i < 300000; i++) {
            dp[i] = 1;
        }
        double ans = 0;
        for (int i = 1; i <= n; i++) {
            int tmp = i;
            int cnt = 1;
            while (tmp < k) {
                tmp *= 2;
                cnt *= 2;
            }
            ans += 1 / (1.0 * cnt);
        }
        System.out.println(ans / n);

        sc.close();
    }
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<ll,ll> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=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{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};


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

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,c,ans=0;
int main(){
    cin>>a>>b>>c>>n;
    for(int i=0;i<=a;i++)
        for(int j=0;j<=b;j++)
            for(int z=0;z<=c;z++){
                if(i*500+j*100+z*50==n) ans++;
                if(i*500+j*100+z*50>n) break;
            }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); 
		
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
		}
		
		int[] tmp = new int[n];
		
		for(int i = 0; i < n; i++) {
			tmp[a[i]-1] = i+1;
			
		}
		for(int i = 0; i < n; i++) {
			System.out.print(tmp[i]+" ");
		}
		
	}
}


Measured memory_bytes: 61216
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
	int a, b, c;
	while(cin >> a >> b >> c, a+b+c){
		if(a > b){
			swap(a, b);
		}
		if(b > c){
			swap(b, c);
		}
		int n;
		cin >> n;
		int size_sq = a*a+b*b;
		while(n--){
			int r;
			cin >> r; 
			if(4*r*r > size_sq){
				cout << "OK" << endl;
			}else{
				cout << "NA" << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1156
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {


            int n = in.nextInt();
            int m = in.nextInt();

            int[][] a = new int[n][m];

            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    a[i][j] = in.nextInt();
                }
            }

            int bst = n;

            int[] nxt = new int[n];
            int[] sports = new int[m + 1];
            boolean[] blocked = new boolean[m + 1];

            for (int k = 0; k < m; ++k) {

                int mx_sport = 0;

                for (int i = 0; i < n; ++i) {
                    int x = nxt[i];
                    while (x < m && blocked[a[i][x]]) x++;
                    if (x == m) break;
                    nxt[i] = x;
                    mx_sport = Math.max(++sports[a[i][nxt[i]]], mx_sport);
                }

                for (int i = 0; i < n; ++i) {
                    if (sports[a[i][nxt[i]]] == mx_sport) {
                        blocked[a[i][nxt[i]]] = true;
                    }
                }

                Arrays.fill(sports, 0);

                if (mx_sport > 0)
                    bst = Math.min(mx_sport, bst);
            }

            out.println(bst);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main() {
	int list[10]={};
	
	for(int i=0;i<10;i++){
		cin >> list[i];
		}
	
	for(int x=0;x<10;x++){
		for(int y=0;y<10;y++){
			
			if(list[x]>list[y]){
				int a=list[y];
				list[y]=list[x];
				list[x]=a;
			}
			
		}	
	}
	
	for(int i=0;i<3;i++){
	cout << list[i]<<endl;
	}
	
	
	return 0;
}

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

int N;

int main() {
  cin >> N;

  double p = double((N + 1) / 2) / N;
  printf("%.10lf\n", p);
  return 0;
}


Measured memory_bytes: 256
#pragma region template
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define vint vector<int>
#define vll vector<ll>
#define vstr vector<string>
#define vbl vector<bool>
#define pb push_back
using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> inline T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}template<class T> inline T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}
#pragma endregion template

void solve(ll N, ll T, ll A, vector<ll> H) {
  ll ans = 0;
  double min_diff = DBL_MAX;
  rep(i, N) {
    if (chmin(min_diff, abs(T - H.at(i) * 0.006 - A))) ans = i + 1;
  }

  cout << ans << endl;
}

int main() {
  ll N;
  ignore_ret(scanf("%lld",&N));
  ll T;
  ignore_ret(scanf("%lld",&T));
  ll A;
  ignore_ret(scanf("%lld",&A));
  vector<ll> H(N);
  for(int i = 0 ; i < N ; i++){
    ignore_ret(scanf("%lld",&H[i]));
  }
  solve(N, T, A, move(H));
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,a,f=0;
	cin>>N;
	while(N--)
	{
		cin>>a;
		if(a%2==0&&a%3!=0&&a%5!=0)f=1;
	}
	if(f)cout<<"DENIED";
	else cout<<"APPROVED";
	return 0;
}

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

int main(){
   int N,j;
   vector<int> A(200001,0);
   cin >> N;

   for(int i=1;i<N;i++){
       cin >> j;
       A[j]++;
   }

   for(int i=1;i<=N;i++){
       cout << A[i] << endl;
   }
} 

Measured memory_bytes: 3888
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    h, w = MI()
    c = [input().split() for _ in range(h)]

    for line in c:
        print(line[0])
        print(line[0])

    pass


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
A, B, C = [list(input()) for _ in range(3)]
x = 'a'
while True:
    if x == 'a':
        if len(A) == 0:
            print('A')
            exit()
        x = A[0]
        A.remove(x)
    elif x == 'b':
        if len(B) == 0:
            print('B')
            exit()
        x = B[0]
        B.remove(x)   
    elif x == 'c':
        if len(C) == 0:
            print('C')
            exit()
        x = C[0]
        C.remove(x)   


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[420+69][420+69], pre[420+69];
ll recur(ll l, ll r) {
    if(l == r)return 0;
    if(dp[l][r] != 0)return dp[l][r];
    dp[l][r] = LLONG_MAX;
    for(int i = l; i < r; i++){
        dp[l][r] = min(dp[l][r], recur(l, i) + recur(i+1, r) + pre[r] - pre[l-1]);
    }
    return dp[l][r];
}
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)cin >> pre[i], pre[i] += pre[i-1];
    // cout << pre[n] - pre[n-1] << endl;
    cout << recur(1, n);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int h, w, n, num[1100000], mp[1100][1100], cnt = 1;
int main() {
    cin >> h >> w >> n;
    for(int i = 1; i <= n; i++) {
        cin >> num[i];
    }
    for(int i = 1; i <= h; i++) {
        int from = (i & 1) ? 1 : w;
        int to = (i & 1) ? w + 1 : 0;
        int delta = (i & 1) ? 1 : -1;
        for(int j = from; j != to; j += delta) {
            mp[i][j] = cnt;
            num[cnt]--;
            if(num[cnt] == 0) cnt++;
        }
    }
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j < w; j++) {
            cout << mp[i][j] << " ";
        }
        cout << mp[i][w] <<endl;
    }
    return 0;
}



Measured memory_bytes: 2816
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
         // for declaring
        int n , weight;
        int[] w,v;

        public void solve(int testNumber, InputReader in, PrintWriter out) {

                n = in.nextInt();
                weight = in.nextInt();
                long[] dp = new long[weight+1];
                w = new int[n];
                v = new int[n];
                for(int i = 0 ; i < n ; i++ ){
                    w[i] = in.nextInt();
                    v[i] = in.nextInt();
                    for(int j = weight ; j>=w[i] ; j--){
                        dp[j]= Math.max(dp[j],dp[j-w[i]]+v[i]);
                    }
                }/*
                for(int i = 0 ; i < weight+1 ; i++ ){
                    out.println(dp[i]);
                }*/
                out.println(dp[weight]);
            }
        }


    }

    class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }




Measured memory_bytes: 21716
#include <stdio.h>

void sort(int *ary,int size){
  int tmp;
  for (int i = 0; i < size; i++) {
    for (int j = size - 1; j > i; j--) {
     if (ary[j] > ary[j - 1]) {
        tmp =  ary[j];
        ary[j] = ary[j - 1];
        ary[j - 1] = tmp;
      }
    }
  }
}

int main(){
  int i1[4] = {};
  int i2[2] = {};

  for(int i = 0; i < 4; i++) scanf("%d",&i1[i]);
  sort(i1,sizeof(i1) / sizeof(int));

  for(int i = 0; i < 2; i++) scanf("%d",&i2[i]);
  sort(i2,sizeof(i2) / sizeof(int));

  for(int i = 1; i < 3; i++) i1[0] += i1[i];

  printf("%d\n",i1[0]+i2[0]); 
}    

Measured memory_bytes: 2688
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // abc176_a();
    // abc176_b();
    abc176_c();
  }

  private static void abc176_a() {
    try (Scanner sc = new Scanner(System.in)) {
      double nAll = sc.nextInt();
      double xOneTime = sc.nextInt();
      int tMinute = sc.nextInt();

      System.out.println((int) Math.ceil(nAll / xOneTime) * tMinute);

    } catch (Exception e) {
      System.out.println("エラー" + e);
    }
  }

  private static void abc176_b() {
    try (Scanner sc = new Scanner(System.in)) {
      String nValue = sc.next();
      List<Integer> numList = new ArrayList<Integer>();

      for (int i = 1; i <= nValue.length(); i++) {
        numList.add(parseI(nValue.substring(i - 1, i)));
      }

      int sum = 0;

      for (int num : numList) {
        sum += num;
      }

      if (sum % 9 == 0) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }

    } catch (Exception e) {
      System.out.println("エラー" + e);
    }
  }

  private static void abc176_c() {
    try (Scanner sc = new Scanner(System.in)) {
      int nPeopleCount = sc.nextInt();
      int[] aTallList = new int[2 * 100000];

      long totalAdd = 0;
      int tall = 0;

      aTallList[0] = parseI(sc.next());
      for (int i = 1; i < nPeopleCount; i++) {
        tall = parseI(sc.next());
        if (0 < aTallList[i - 1] - tall) {
          totalAdd += aTallList[i - 1] - tall;
          tall = aTallList[i - 1];
        }
        aTallList[i] = tall;
      }
      System.out.println(totalAdd);

    } catch (Exception e) {
      System.out.println("エラー" + e);
    }
  }

  // int 2147483648 [ 2 * 10(9)]
  // long 9223372036854775808 [ 9 * 10(18)]

  public static int parseI(String value) {
    return Integer.parseInt(value);
  }

  public static long parseL(String value) {
    return Long.parseLong(value);
  }

  public static double parseD(String value) {
    return Double.parseDouble(value);
  }

  public static <T> String parseS(T value) {
    return String.valueOf(value);
  }

  public static BigDecimal parseBigD(String value) {
    return new BigDecimal(value);
  }

  public static BigInteger parseBigI(String value) {
    return new BigInteger(value);
  }

}


Measured memory_bytes: 61452