akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
  int n;
  int a[4][13];
  int kazu;
  char alf;
  for(int i=0;i<4;i++){
    for(int k=0;k<13;k++){
      a[i][k]=false;
    }
  }
  cin>>n;
  for(int i=0;i<n;i++){
    cin >>alf>>kazu;
    if(alf=='S'){
      a[0][kazu-1]=true;
    }else if(alf=='H'){
      a[1][kazu-1]=true;
    }else if(alf=='C'){
      a[2][kazu-1]=true;
    }else{
      a[3][kazu-1]=true;
    }
  }
  for(int i=0;i<4;i++){
    for(int k=0;k<13;k++){
      if(a[i][k]==false){
        if(i==0){
          cout <<"S"<<" "<<k+1<<endl;
        }else if(i==1){
          cout <<"H"<<" "<<k+1<<endl;
        }else if(i==2){
          cout <<"C"<<" "<<k+1<<endl;
        }else if(i==3){
          cout <<"D"<<" "<<k+1<<endl;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)

int main() {
  long long N, M, x, ans = 1;
  cin >> N >> M;
  x = M * 1900 + (N - M ) * 100;
  REP(i,M) x *= 2;
  cout << x << endl;
  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 ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const ll INF = 1LL<<60;

int main(){
    int n; cin >> n;
    vector<vector<int>> f(n, vector<int>(10));
    rep(i,n)rep(j,10) cin >> f[i][j];
    vector<vector<int>> p(n, vector<int>(11));
    rep(i,n)rep(j,11) cin >> p[i][j];
    ll ans = -INF;
    for(int bit = 1; bit < (1 << 10); ++bit){
        vector<int> cnt(n,0);
        for(int i = 0; i < 10; ++i){
            if(bit & (1 << i)){
                for(int j = 0; j < n; ++j){
                    if(f[j][i]) cnt[j]++;
                }
            }
        }
        ll tmp = 0;
        for(int i = 0; i < n; i++){
            tmp += p[i][cnt[i]];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N = int(input())
    B = list(map(int, input().split()))

    ans = []

    for time in range(N):
        for i in range(N - time)[:: -1]:
            if B[i] == i + 1:
                ans.append(B.pop(i))
                break

    if B:
        print(-1)
    else:
        for a in reversed(ans):
            print(a)

sol()

Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;


int main(void) {
	int n, m;
	cin >> n >> m;
	int sum = 0;
	for (int i = 0; i < m; i++) {
		int x;
		cin >> x;
		sum += x;
	}
	if (n - sum < 0)
		cout << -1;
	else
		cout << n - sum;
	cout << '\n';
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;


int main() {
	
	int n;
	cin >> n;
	int mini  = IINF;
	int ans;
	
	rep(i, n){
		int a, b;
		cin >> a >> b;
		if(mini > b){
			ans = a;
			mini = b;
		}
	}
	
	cout << ans + mini << endl;
	
	return 0;
}

Measured memory_bytes: 384
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
    n <- getInt
    let o = length $ filter odd [1..n]
    print $ fromIntegral o / fromIntegral n

Measured memory_bytes: 508
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) for(auto x:obj)cout<<x<<' ';cout<<endl;
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	string s;
	cin>>s;
	reverse(all(s));
	ll ans = 0LL;
	ll cnt_b = 0LL;
	rep(i,s.size()){
		if(s[i] == 'B'){
			ans += i-cnt_b;
			++cnt_b;
		}
	}
	cout<<ans<<endl;
	return 0;
}



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

namespace Atcoder178
{
    class Program
    {
        const long Mod = 1000000007;

        static void Main(string[] args)
        {

            var n = long.Parse(Console.ReadLine());

            var ans = powMod(10, n) % Mod;
            ans -= powMod(9, n) * 2 % Mod;
            ans += powMod(8, n) % Mod;

                      while (ans < 0) ans += Mod;

            Console.WriteLine(ans % Mod);

            // これだとnの桁数が大きいとNaNになってしまう
            //var ans = Math.Pow(10, n) % Mod;
            //ans -= Math.Pow(9, n) % Mod * 2;
            //ans += Math.Pow(8, n);
        }

        private static long powMod(long x, long y)
        {
            var ans = 1L;
            for(var i = 0L; i < y; i++)
            {
                ans *= x;
                ans %= Mod;
            }

            return ans;
        }
    }
}


Measured memory_bytes: 27464
#include<stdio.h>
int main(void){
int ai,n,i,min,max;
long sum;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&ai);
if(i==0){
min=ai;
max=ai;
sum=ai;}
else{
sum=sum+ai;
if(min>ai){
min=ai;}
if(max<ai){
max=ai;}}}
printf("%d %d %ld\n",min,max,sum);
return 0;}

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

using namespace std;

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

	unsigned long long  cur_max = 0;
	
	unsigned long long  total = 0;

	for (int i = 0; i < n; ++i) {
		if (v[i] > cur_max) {
			cur_max = v[i];
		} else if (v[i] < cur_max) {
			total += (cur_max - v[i]);
		}
	}

	cout << total << endl;
	return 0;
}


Measured memory_bytes: 4040
n = input()
friendliness = [int(item) for item in input().split()]
friendliness.sort()
def of_ans():
    sum_ = 0
    idx = 1
    while idx < len(friendliness):
        sum_ += friendliness[len(friendliness) - (idx // 2) - 1]
        idx += 1
    return sum_
print(of_ans())

Measured memory_bytes: 31364
s = str(input())
Odd = s[::2]
Even = s[1::2]
Ocount =0
Ecount =0
for i in range(len(Odd)):
  if Odd[i] == "R" or Odd[i] == "U" or Odd[i] == "D":
     Ocount +=1
     if len(Even)==0:
        print("Yes")
        quit()      
for i in range(len(Even)):
  if Even[i] == "L" or Even[i] == "U" or Even[i] == "D":
    Ecount +=1
  if Ecount == len(Even) and Ocount == len(Odd):
    print("Yes")
    quit()
print("No")

Measured memory_bytes: 3064
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

map<int, bool> cache;
bool check(int n){
	if(n == 2)return true;
	for(int i = 2; i * i <= n; i++){
		if(n % i == 0)return false;
	}
	return true;
}

int main(){
	FIO
	

	int n, ans = 0;
	cin >> n;
	while(n--){
		int el;
		cin >> el;
		if(check(el))ans++;
	}
	cout << ans << '\n';
	return 0;
}



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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<ll> &s, ll a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

int main() {
    int n;
    cin >> n;
    vector<ll> hps(n);
    rep(i, n) cin >> hps[i];
    sort(hps.begin(), hps.end());

    for (int i = 0; i < n - 1; i++) {

        if (hps[i + 1] % hps[i] == 0) {
            ll now = hps[i];
            hps[i + 1] = now;

        } else {
            ll now = hps[i + 1] % hps[i];
            hps[i + 1] = now;
            swap(hps[i + 1], hps[i]);
            i--;
        }
    }

    cout << hps.back() << endl;
}



Measured memory_bytes: 1024
# coding: utf-8


def solve(*args: str) -> str:
    s = args[0]
    hug = 0
    for i in range(len(s)//2):
        if s[i] != s[-i-1]:
            hug += 1

    return str(hug)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

typedef long long llong;
typedef pair<int, int> pii;

void solve(){

	string s;
	cin >> s;

	//E W
	set<char> x_axis;
	//N S
	set<char> y_axis;

	for(char c : s){

		if(c == 'E' || c == 'W') x_axis.insert(c);
		else y_axis.insert(c);

	}

	bool valid_x = x_axis.size() != 1;
	bool valid_y = y_axis.size() != 1;

	if(valid_x && valid_y) cout << "Yes";
	else cout << "No";

}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif

	solve();

	return 0;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return [init]*size1
  else
    return [[init]*size2]*size1
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
h=get_i
dp=array(N,INF)
dp[0]=0
(N-1).times do|i|
    dp[i+1]=min(dp[i]+(h[i]-h[i+1]).abs,dp[i+1])
    dp[i+2]=min(dp[i]+(h[i]-h[i+2]).abs,dp[i+2]) if i+2<N
end
puts dp[N-1]

Measured memory_bytes: 9228
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  vector<ll> a(N);
  for(int i = 0;i < N;i++)cin >> a[i];

  int cnt_2 = 0;
  int cnt_4 = 0;
  for(int i = 0;i < N;i++){
    if(a[i] % 4 == 0)cnt_4++;
    else if(a[i] % 2 == 0)cnt_2++;
  }

  int nn = N - cnt_2 - cnt_4;

  if(nn > cnt_4 + 1 || (nn == cnt_4 + 1 && cnt_2 != 0))cout << "No" << endl;
  else cout << "Yes" << endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e14;
using Graph = vector<vector<int>>;

signed main(){
  int X;
  cin >> X;
  int a = 1;
  while( true ){
    if( (X*a)%360 == 0 ){
      cout << a << endl;
      return 0;
    }
    a++;
  }


}


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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

void solve() {
    Int n;
    cin >> n;
    vector<Int> a(3 * n);
    for (Int i = 0; i < 3 * n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    Int res = 0;
    for (Int i = n; i < 3 * n; i += 2) {
        res += a[i];
    }
    print(res);
}

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


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

int solve0(long long n, long long x) {
    if (x) cout << n+1 << endl;
    else cout << 1 << endl;
    return 0;
}

int main() {
    long long n, x, d; cin >> n >> x >> d;
    if (d == 0) return solve0(n, x);
    if (d < 0) {
        x = x + d * (n-1); d = -d;
    }
    map<long long, vector<pair<long long, long long>>> m;
    long long l = 0, r = 0;
    m[0].emplace_back(l, r);
    for (long long i = 0; i < n; i++) {
        l += i; r += n-i-1;
        long long c = (i+1) * x;
        long long add = c / d; c %= d;
        m[c].emplace_back(l+add, r+add);
    }
    long long ans = 0;
    for (auto &iter: m) {
        auto &v = iter.second;
        sort(v.begin(), v.end());
        long long left = v.front().first;
        long long right = v.front().second;
        for (int i = 0; i < v.size(); i++) {
            auto &curr = v[i];
            if (right < curr.first) {
                ans += right - left + 1;
                left = v[i].first;
                right = v[i].second;
            } else {
                right = max(right, curr.second);
            }
        }
        ans += right - left + 1;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int n;

	while (scanf("%d", &n), n != 0){
		int b, r, t;
		int y;
		double max = 0, money;
		int max_n;

		scanf("%d", &y);

		for (int i = 0; i < n; i++){
			scanf("%d%d%d", &b, &r, &t);
			if (t == 1){
				money = 1 + y * r / 100.0;
			}
			else {
				money = 1;
				for (int j = 0; j < y; j++){
					money *= (1 + r / 100.0);
				}
			}

			if (money > max){
				max = money;
				max_n = b;
			}
		}

		cout << max_n << endl;
	}

	return (0);
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
int n;
int d[510][510];bool del[510][510];int p[250010]; 
inline void dfs(int x,int y,int k){
	rep(i,0,3){
		int tx=x+dir[i][0];int ty=y+dir[i][1];
		if(tx<1||ty<1||tx>n||ty>n||k>=d[tx][ty])continue;
		d[tx][ty]=k;
		dfs(tx,ty,k+(del[tx][ty]==0));
	}
	return;
}

int main(){
	read(n);
	rep(i,1,n*n)read(p[i]);
	rep(i,1,n){
		rep(j,1,n)d[i][j]=min(min(i,n+1-i),min(j,n+1-j))-1;
	}
	
	int ans=0; 
	rep(i,1,n*n){
		int n1=(p[i]/n)+(p[i]%n!=0);int n2=p[i]-n*(n1-1);
		ans+=d[n1][n2];del[n1][n2]=1;dfs(n1,n2,d[n1][n2]);
	}
	write(ans);
	return 0;
}


Measured memory_bytes: 21168
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void process();

int main(){
    int N,X,Y;
    bool update;
    int i,j;
    cin >> N;
    int dis[N][N];
    int dis_num[N];
    for(i = 0;i<N;i++){
        dis_num[i] = 0;
    }
    for(i=0;i<N-1;i++){
        for(j=i;j<N;j++){
            dis[i][j] = j - i;
        }
    }
    cin >> X >> Y;
    X--;
    Y--;
    /**/
    for(i=0;i<=X;i++){
        for(j=Y;j<N;j++){
            dis[i][j] = X - i + j - Y + 1;
        }
        for(j=Y-1;j>=X;j--){
            if( dis[i][j] > X - i + 1 + Y - j){
                dis[i][j] = X - i + 1 + Y - j;
            }else{
                break;
            }
        }
    }
    for(i=X;i<=Y;i++){
        for(j=Y;j<N;j++){
            if( dis[i][j] > i - X + 1 + j - Y){
                dis[i][j] = i - X + 1 + j - Y;
            }else{
                break;
            }
        }
        for(j=Y-1;j>=i;j--){
            if( dis[i][j] > i - X + 1 + Y-j){
                dis[i][j] = i - X + 1 + Y-j;
            }else{
                break;
            }
        }
        
    }
    for(i=0;i<N-1;i++){
        for(j=i+1;j<N;j++){
            dis_num[dis[i][j]]++;
        }
    }
    for(i=1;i<N;i++){
        cout << dis_num[i] << endl;
    }
    
    return 0;
}

void process(){
    
}

Measured memory_bytes: 15360
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// 2文字以上の回分が出現しないものは、abcabcabc...と続く形しか無い（a,b,cの出現順序は問わない。）
// したがって、各文字の出現回数をカウントし上記の文字列が作成可能かどうかをチェックする。
// より具体的には、全ての文字はn/3回以上出現し、かつn%3個だけab...が続く

int main(){
    Init();
    string s; cin >> s;
    ll n = s.size();
    vi cnt(3, 0), req(3, (ll)(n/3));
    rep(i, n) cnt[(ll)(s[i]-'a')]++;
    sort(all(cnt));
    n %= 3;
    for(ll i=0; i<n; i++) req[2-i]++;
    bool ans = true;
    rep(i, 3) if(req[i] != cnt[i]) ans = false;
    ans ? YES() : NO();
}

Measured memory_bytes: 3700
'use strict';

function Main(input) {
  const N = Number(input.split("\n")[0]);
  const T = Number(input.split("\n")[1].split(" ")[0]);
  const A = Number(input.split("\n")[1].split(" ")[1]);
  const Hs = input.split("\n")[2].split(" ").map(x => Number(x));
  let Temps = [];

  for(let val of Hs) {
    Temps.push(Math.abs(A - (T - val*0.006)));
  }

  const min = Math.min.apply(null, Temps);

  console.log(Temps.indexOf(min) + 1);

};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 21296
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX = 405;
int n;
ll a[MAX], sum[MAX], dp[MAX][MAX]; // dp[i][j] := a[i] ~ a[j] までの最小コスト

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n) sum[i+1] = sum[i] + a[i];

    rep(i, MAX) {
        rep(j, MAX) {
            if (i == j) dp[i][j] = 0;
            else dp[i][j] = LLINF;
        }
    }

    for (int l = 2; l <= n; l++) {
        for (int i = 0; i <= n - l; i++) {
            int j = i + l - 1;
            for (int k = i; k < min(j, n); k++) {
                chmin(dp[i][j], dp[i][k] + dp[k+1][j] + sum[j+1] - sum[i]);
            }
        }
    }
    cout << dp[0][n-1] << endl;

}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define f(i,a,b) for(int i=a; i<b; i++)
#define pb push_back
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
using namespace std;

int main()
{
    IOS
    int n, m;
    cin>>n>>m;
    cout<<(n*(n-1))/2 + (m*(m-1))/2;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next());
    String x = sc.next();
    int b = Integer.parseInt(sc.next());
    if(x.equals("+")){
      System.out.println(a + b);
    }else{
      System.out.println(a - b);
    }
  }
}

Measured memory_bytes: 21972
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
#define eps 1e-10
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll x;
ll d[400005];
ll a[200005];
ll sum[200005];

int main(void){
	scanf("%d%lld%lld",&n,&d[0],&x);
	for(int i=1;i<n*2;i++){
		d[i]=d[i-1]+x;
	}
	for(int i=0;i<n;i++){
		a[i]=d[i*2]+d[i*2+1];
	}
	for(int i=0;i<n;i++){
		sum[i+1]=sum[i]+a[i];
	}
	long double res=sum[n]*0.5;
	for(int i=1;i<n;i++){
		res+=(sum[n]-sum[i])*0.25/(i+1);
		res+=(sum[n-i]-sum[0])*0.25/(i+1);
	}
	printf("%.9f\n",(double)res);
	return 0;
}


Measured memory_bytes: 6528
// https: //onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/10/ITP1_10_D

#include <iostream>
#include <cmath>
#include <iomanip>

int main()
{
    int n;
    std::cin >> n;

    double x[n] = {};
    double y[n] = {};
    double D[4] = {};

    for (int i = 0; i < n; i++)
    {
        std::cin >> x[i];
    }

    for (int i = 0; i < n; i++)
    {
        std::cin >> y[i];
    }
    for (int i = 0; i < 4; i++)
    {
        double tmp = 0;
        if (i < 3)
        {
            for (int j = 0; j < n; j++)
            {
                tmp += pow(abs(x[j] - y[j]), (double)(i + 1.));
            }
            D[i] = pow(tmp, 1. / (double)(i + 1));
        }
        else if (i == 3)
        {
            for (int j = 0; j < n; j++)
            {
                if (tmp < abs(x[j] - y[j]))
                    tmp = abs(x[j] - y[j]);
            }
            D[i] = tmp;
        }
    }

    for (auto &x : D)
    {
        std::cout << std::fixed << std::setprecision(5) << x << std::endl;
    }
}


Measured memory_bytes: 3456
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Point[] reds = new Point[n];
    Point[] blues = new Point[n];
    for(int i = 0; i < n; i++) reds[i] = new Point(sc.nextInt(), sc.nextInt());
    for(int i = 0; i < n; i++) blues[i] = new Point(sc.nextInt(), sc.nextInt());
    Arrays.sort(reds, (r1, r2) -> r2.getY() - r1.getY());
    Arrays.sort(blues, (b1, b2) -> b1.getX() - b2.getX());
    int count = 0;
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        if(blues[i] == null || reds[j] == null) continue;
        if(reds[j].getX() < blues[i].getX() && reds[j].getY() < blues[i].getY()) {
          count++;
          reds[j] = null;
          blues[i] = null;
          break;
        }
      }
    }
    System.out.println(count);
  }
  static class Point {
    int x;
    int y;
    public Point(int x, int y) {
      this.x = x;
      this.y = y;
    }
    public int getX() {
      return this.x;
    }
    public int getY() {
      return this.y;
    }
  }
}

Measured memory_bytes: 27092
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,M; cin>>N>>M;
    ll ans=0;
    priority_queue<ll> que;
    rep(i,N){
        ll tmp;
        cin>>tmp;
        que.push(tmp);
    }
    rep(i,M){
        ll tmp=que.top(); que.pop();
        que.push(tmp/2);
    }
    while(!que.empty()){
        ans+=que.top(); que.pop();
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4320
object Scanner {
  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}

object Main extends App {

  def devidablity(x:Int) = {
    var num = x
    var count = 0
    while (num%2==0){
      count = count + 1
      num = num / 2
    }
    count
  }

  val n = Scanner.nextInt()
  val a = Array.fill(n)(Scanner.nextInt())
  val result = a.map(ai=>{
    devidablity(ai)
  }).sum
  println(result)
}

Measured memory_bytes: 27708
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
/*
░░░░░░░░░░░░░░░░░░░░░░░░░
░░█▀▀▄░░░░░░░░░░░▄▀▀█░░░░
░░█░░░▀▄░▄▄▄▄▄░▄▀░░░█░░░░
░░░▀▄░░░▀░░░░░▀░░░▄▀░░░░░
░░░░░▌░▄▄░░░▄▄░▐▀▀░░░░░░░
░░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█░
░░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█░
░▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█░
░█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀░
░░▀▄░░▀░░▀▀▀░░▀░░░▄█▀░░░░
░░░░█░░░░░░░░░░░▄▀▄░▀▄░░░
░░░░█░░░░░░░░░▄▀█░░█░░█░░
░░░░█░░░░░░░░░░░█▄█░░▄▀░░
░░░░█░░░░░░░░░░░████▀░░░░
░░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░
*/
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 2e5 + 10;
ll l[MAXN],r[MAXN];
const ll MOD = 1e9 + 7;
ll fact[MAXN];

void solve(){
    fact[0] = 1;

    FOR(i,1,MAXN-1) fact[i] = (fact[i-1]*i)%MOD;

    ll n; cin>>n;
    string s; cin>>s;

    if(s.front() == 'W' || s.back() == 'W'){
        cout<<0<<endl;
        return;
    }

    l[0] = 1,r[0] = 0;
    ll prev = 1;
    FOR(i,1,2*n-1){
        l[i] = l[i-1],r[i] = r[i-1];
        if(s[i] == s[i-1]){
            if(prev == 1) r[i]++,prev = 0;
            else l[i]++,prev = 1;
        }else {
            if(prev == 1) l[i]++,prev = 1;
            else r[i]++,prev = 0;
        }
    }

    if(l[2*n-1] != r[2*n-1]){
        cout<<0<<endl;      
        return;
    }

    ll ans = 1;

    FOR(i,0,2*n-1){
        if(r[i] > r[i-1]){
            ll left = l[i] - r[i-1];
            ans = (ans * left)%MOD;
        } 
    }

    ans = (ans * fact[n])%MOD;
    cout<<ans<<endl;
} 
 
signed main(){
 
   FastRead;    
 
 
    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 5268
#include <iostream>
#include <string>

bool f(std::string ret, const std::string& s, const long long n) {
    for (auto i = 1ll; i < n - 1; i++) {
        ret += ((s[i] == 'x') ^ (ret[i] == 'S')) ? ret[i - 1] : (ret[i - 1] == 'S' ? 'W' : 'S');
    }
    if (((s[n - 1] == 'x') ^ (ret[n - 1] == 'S') ? ret[n - 2] : (ret[n - 2] == 'S' ? 'W' : 'S')) == ret[0]
        && ((s[0] == 'x') ^ (ret[0] == 'S') ? ret[n - 1] : (ret[n - 1] == 'S' ? 'W' : 'S')) == ret[1]) {
            std::cout << ret << std::endl;
            return true;
        }

    return false;
}

int main() {
    long long n;
    std::string s;
    std::cin >> n >> s;
    std::string ret;

    ret = "SS";
    if (f(ret, s, n)) return 0;

    ret = "SW";
    if (f(ret, s, n)) return 0;

    ret = "WS";
    if (f(ret, s, n)) return 0;

    ret = "WW";
    if (f(ret, s, n)) return 0;

    std::cout << -1 << std::endl;

    return 0;
}

Measured memory_bytes: 776
use text_io::*;
use std::collections::*;
use std::process::exit;

fn main() {
    let mut n:usize = read!();
    let mut k:usize = read!();
    let mut ans:usize = 0;
    for i in 0..n {
        let a:usize = read!();
        if k<=a {
            ans += 1;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 2148
// ABC_094_A
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define forn(i, n) for(int i = 0; i < (int)n; ++i)

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

	if(a <= x && a+b >= x) cout << "YES" << "\n"; 
	else cout << "NO" << "\n";

	return 0;
}

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

using namespace std;

int main(){
	vector<long> A;
	vector<long> B;

	long a;
	long b;


	long N;
	long kutiku;
	long kutiku_sum=0;
	cin >> N;

	for(long i=0; i < N+1; i++){
		cin >> a;
		A.push_back(a);
	}
	for(long i=0; i < N; i++){
		cin >> b;
		B.push_back(b);
	}

	for(long i=0; i < N; i++){
		kutiku = 0;
		if(A[i]+A[i+1]-B[i] <= 0){
			kutiku_sum = kutiku_sum + A[i]+A[i+1];
			A[i+1] =0;
		}
		else if(A[i]-B[i] <= 0){
			kutiku_sum = kutiku_sum + B[i];
			A[i+1] = A[i+1] + A[i] -B[i];

		}else if(A[i]-B[i] >= 0){
			kutiku_sum = kutiku_sum + B[i];
		}

	
	}
		
	cout << kutiku_sum << endl;

	return 0;

}

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

int main(){

int a;
bool b=false;
cin >> a;
for(int i=1;i<10;i++){
    if(a%i==0&&a/i<=9){
        b=true;
        break;
    }
}
if(b==true){
    cout << "Yes" << endl;
}
else{
    cout << "No" << endl;
}
}


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

int main() {
  int A,P;
  int ans = 0;

  cin >> A >> P;

  if (A > 0) {
    P = P + (A * 3);
  }

  if (P > 1) {
    ans = P / 2;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> p;
typedef priority_queue<ll, vector<ll>, greater<ll> > pque;

constexpr ll MAX_N = 1e5;

vector<vector<ll> > cost_table;
ll table_id = 0;

vector<ll> node_cost;

vector<ll> G[MAX_N];
vector<bool> used;
ll N, M;

ll ans = 0;

void dfs(ll node, ll table_id) {
    used[node] = true;
    if (cost_table.size() == table_id) {
        cost_table.push_back(vector<ll>());
    }

    cost_table[table_id].push_back(node_cost[node]);

    for (auto&& g : G[node]) {
        if (!used[g]) {
            dfs(g, table_id);
        }
    }
}

int main(void) {
    cin >> N >> M;
    used = vector<bool>(N, false);
    node_cost = vector<ll>(N);

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

    for (ll i = 0; i < M; i++) {
        ll a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    if (N - 1 == M) {
        cout << 0 << endl;
        return 0;
    }

    if (N < 2 * (N - M - 1)) {
        cout << "Impossible" << endl;
        return 0;
    }

    for (ll i = 0; i < N; i++) {
        if (!used[i]) {
            dfs(i, table_id);
            sort(cost_table[table_id].begin(), cost_table[table_id].end());
            table_id++;
        }
    }

    ll cost = 0;
    ll numnode = 0;
    ll need = 2 * (N - M - 1);

    for (auto&& ct : cost_table) {
        cost += ct[0];
        numnode++;
    }

    vector<ll> nodes;
    for (auto&& ct : cost_table) {
        for (ll i = 1; i < ct.size(); i++) {
            nodes.push_back(ct[i]);
        }
    }

    sort(nodes.begin(), nodes.end());

    for (ll i = 0; i < need - numnode; i++) {
        cost += nodes[i];
    }

    cout << cost << endl;
    return 0;
}



Measured memory_bytes: 9840
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, D;
  cin >> N >> D;
  vector< vector< int > > X(N, vector< int >(D));
  REP(i, N) {
    REP(j, D) { cin >> X[i][j]; }
  }
  int count = 0;
  REP(i, N) {
    FOR(j, i + 1, N) {
      double sum = 0;
      REP(k, D) { sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]); }
      // cout << i << " " << j << " " << sum << endl;
      if (sqrt(sum) == floor(sqrt(sum))) {
        count++;
      }
    }
  }
  cout << count << "\n";
}

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

namespace CompetitiveProgCsLib
{
	class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void OutLine<T>(IEnumerable<T> obj, string separateChar) => Out(String.Join(separateChar, obj));
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES" : "NO");
		static bool IsIn(int y, int x, int h, int w) => 0 <= x && x < w && 0 <= y && y < h;

		static void Main(string[] args)
		{
			var n = RI;
			var a = RIs;
			int max = 0;
			for(int i = 0;i < a.Length;i++)
			{
				int count = 0;
				while(true)
				{
					if (a[i] % 2 == 0)
					{
						count++;
						a[i] /= 2;
					}
					else break;
				}
				max += count;
			}
			Out(max);
		}
	}
}


Measured memory_bytes: 14176
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
  string s;
  cin >> s;

  int n = s.length(); int mini = 10000;
  rep(i, n-2) {
      int digits = stoi(s.substr(i, 3));
      mini = min(mini, abs(digits-753));
    //   cout << s[i] << endl;
  }
  cout << mini << endl;
}

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

string query(int i) {
    cout << i << endl;
    string result;
    cin >> result;
    return result;
};

int main() {
    int n;
    cin >> n;
    int begin = 0, end = n;
    string head = query(begin);
    if (head != "Vacant") {
        while (true) {
            auto mid = (begin + end) / 2;
            auto current = query(mid);
            if (current == "Vacant") {
                break;
            }
            if ((current == head) != (begin % 2 == mid % 2)) {
                end = mid;
            } else {
                begin = mid;
                swap(head, current);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 852
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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;}

const ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  int N, M; cin >> N >> M;
  vector<int> a(M);
  rep(i, M) cin >> a[i];
  int tmp = accumulate(a.begin(), a.end(), 0);
  if (N - tmp >= 0) cout << N - tmp << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;


int main(){
    int N; cin >> N; 
    vector<int> A(N), B(N);
    for(int i = 0; i < N; i++) cin >> A[i] >> B[i];
    ll cnt=0;
    for(int i = N-1; i >= 0; i--){
        //cout << B[i]+cnt << " " << A[i] << endl;
        if((A[i] + cnt)% B[i] == 0) continue;
        cnt += B[i] - ((A[i]+cnt) % B[i]);
        //cout << cnt << endl;
        
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
//https://atcoder.jp/contests/abc116/tasks/abc116_c

import java.util.Scanner;
import java.util.ArrayList;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i=0;i<N;i++){
            h[i] = sc.nextInt();
        }
        sc.close();
        int area = 0;
        int ans = 0;
        for (int i=0;i<N;i++){
            if (h[i]==0){
                ans += area;
                area = 0;
            }
            if (h[i]>= area){
                area = h[i];
            } else {
                ans += area - h[i];
                area = h[i];
            }
        }
        ans += area;
        System.out.println(ans);
    }
}

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

void solve() {
	int n; cin >> n;
	vector<long long> a(n);
	rep(i, n) scanf("%lld", &a[i]);

	vector<long long> s(n + 1, 0);
	map<long long, long long> nums;
	for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];
	for (int i = 0; i <= n; i++) nums[s[i]]++;

	long long res = 0;
	long long num;
	for (auto it : nums) {
		num = it.second;
		res += num * (num - 1) / 2;
	}

	cout << res << endl;
}

int main(void) {
	solve();

	return 0;
}

Measured memory_bytes: 15872
n = int(input())

import math
m = int(math.sqrt(n))

ans = 100000000000

for i in range(1,m+1):
	if n%i == 0:
		a = int(n/i)
		b = i
		c = max(a,b)
		#print(a,b,c)
		if len(str(c)) < ans:
			ans = len(str(c))

print(ans)
		



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Crossing | diff Crossing.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Crossing.cpp && ./a.out

/*
 
 5/2/2020
 
 15:13-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

void solve() {
  for(int k=1; k*(k-1)/2<=N; ++k) if(k*(k-1)==2*N) {
    VV<int> res(k);
    int x=1;
    REP(i,k) FOR(j,i+1,k) {
      res[i].push_back(x);
      res[j].push_back(x);
      ++x;
    }
    cout<<"Yes"<<endl;
    cout<<k<<endl;
    REP(i,k) {
      cout<<SZ(res[i])<<" ";
      FORR(a,res[i]) cout<<a<<" ";
      cout<<endl;
    }
    return;
  }
  cout<<"No"<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 2304
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define debug(x) cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  string s;
  cin >> s;

  int l, r;
  l = s.size()+2;

  FOR(i, 0, s.size()){
    if (s[i]=='A') l=min(l, i);
    if (s[i]=='Z') r=i;
  }

  cout << r-l+1 << endl;

  return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
 
using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
 
int main(){
  string s, t;
  cin >> s >> t;
  int ssize=s.size();
  int tsize=t.size();
  if(ssize<tsize){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for(int i=ssize-tsize; i>=0; i--){
    bool flag=false;
    for(int j=i; j<i+tsize; j++){
      if(s[j]!=t[j-i] && s[j]!='?'){
        flag=true;
      }
    }
    if(!flag){
      for(int j=i; j<i+tsize; j++){
        s[j]=t[j-i];
      }
      break;
    }
    if(i==0){
      cout << "UNRESTORABLE" << endl;
      return 0;
    }
  }
  rep(i, ssize){
    if(s[i]=='?'){
      s[i]='a';
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 10000000005
#define NIL -1
int main(){
    ll n; cin >> n;
    ll a[n+1], b[n+1];
    for(ll i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    ll cnt = 0;
    for(ll i = n-1; i >= 0; i--){
        if(a[i] == 0) continue;
        a[i] += cnt;
        if(a[i] <= b[i]) cnt += b[i] - a[i];
        else {
            if(a[i]%b[i] != 0){
                cnt += b[i]*(a[i]/b[i] +1) - a[i];
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A, B;
    cin >> N;
    if (N == 1) cout << "Hello World" << endl;
    else {
        cin >> A >> B;
        cout << A + B << endl;
    }
    return 0;
}

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

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = Read();
            if (r.Substring(2, 1) == r.Substring(3, 1)
                && r.Substring(4, 1) == r.Substring(5, 1))
            {
                Write("Yes");
            }
            else
            {
                Write("No");
            }
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
            Read();
        }
    }
}


public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }
}



Measured memory_bytes: 13140
#include <stdio.h>
#include <string.h>

int main(void)
{
	char S[3];

	scanf("%s", S);

	if (strcmp(S, "abc") == 0) printf("Yes");
	else if (strcmp(S, "acb") == 0) printf("Yes");
	else if (strcmp(S, "bca") == 0) printf("Yes");
	else if (strcmp(S, "bac") == 0) printf("Yes");
	else if (strcmp(S, "cab") == 0) printf("Yes");
	else if (strcmp(S, "cba") == 0) printf("Yes");
	else printf("No");

	return 0;
}



Measured memory_bytes: 128