akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int [] input = new int[n];
		for (int i = 0; i < n; i++) {
			input[i] = sc.nextInt();
		}
		sc.close();
		
		bubbleSort(input, n);

	}

	private static void bubbleSort(int[] A, int N) {

		boolean flag = true;
		int count = 0;
		while(flag) {
			
			flag = false;
			for (int j = N-1 ; j >= 1; j--) {
				if(A[j] < A[j-1]) {
					int wk = A[j-1];
					A[j-1] = A[j];
					A[j] = wk;
					
					flag = true;
					count++;
				}
			}
		}
		show(A, " ");
		System.out.println(count);
	}

	private static void show(int[] a, String joiner) {

		String line = Arrays.stream(a)
				.mapToObj(String::valueOf)
				.collect(Collectors.joining(joiner));
		
		System.out.println(line);
		
	}
}

Measured memory_bytes: 32524
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf3(a,b,c) printf("%d %d %d",a,b,c)
#define sfl(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld %lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pfl(a) printf("%lld",a)
#define pfl2(a,b) printf("%lld %lld",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
#define tz 100000
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
ll br[200005];
main()
{
    timesave;
    ll n;
    while(cin>>n)
    {
        ll i,ar[200005]={0};
        map<ll,ll>mp,mp1;
        for(i=0;i<n;i++)
        {
            cin>>ar[i];
            br[i]=ar[i];
        }
        sort(br,br+n);
        ll sum=0,cnt=1;
        br[n]=10000000;
        for(i=1;i<=n;i++)
        {
            if(br[i]!=br[i-1])
            {
                mp[br[i-1]]=(cnt*(cnt-1))/2;
                mp1[br[i-1]]=cnt;
                sum+=mp[br[i-1]];
                cnt=1;
            }
            else
                cnt++;
        }
     //   cout<<sum<<endl;
        for(i=0;i<n;i++)
        {
            //cout<<ar[i]<<" "<<mp[ar[i]]<<endl;
            ll x=mp[ar[i]];
            ll ans=sum-x;
            ll xx=mp1[ar[i]]-1;
            if(xx<0)
                xx=0;
            ans=ans+(((xx-1)*xx)/2);
            cout<<ans<<endl;
        }
    }
}




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

int main() {
  int n; cin >> n;
  vector<string> ss(n);
  for (int i = 0; i < n; i++) cin >> ss.at(i);
  
  int m; cin >> m;
  vector<string> st(m);
  for (int i = 0; i < m; i++) cin >> st.at(i);
  
  int answer = 0;
  for (int i = 0; i < n; i++) {
    int score = 0;
    for (int j = 0; j < n; j++) if (ss.at(i) == ss.at(j)) score++;
    for (int j = 0; j < m; j++) if (ss.at(i) == st.at(j)) score--;
    answer = max(answer, score);
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    vi a;
    int n;
    cin>>n;
    a.resize(n);
    double ans=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ans=ans+1.0/a[i];
    }
    ans=1.0/ans;
    printf("%0.9lf\n",ans);


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
int main()
{
    optimize();
    int n,i;
    double p,t=0.0;
    string st;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>p>>st;
        if(st=="BTC")
            p=380000.0*p;
        t+=p;
    }
    cout<<t<<"\n";
    return 0;

}


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


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair
#define snd second
#define fst first
#define debug printf("--%d--\n",__LINE__)
#define ll long long int

int R, C, N;
static ll a[131072], r[131072], c[131072];
static int par[131072];
static ll diff[131072];
static vector<pair<pair<int, int> , ll> > v;

ll tmp;
int parent(int x){
	while(1){
		int p = par[x];
		if (p == x) return p;
		tmp += diff[x];
		x = p;
	}
}

int main(void){
	srand(time(NULL));
	cin >> R >> C >> N;
	for(int i=0;i<N;i++) cin >> r[i] >> c[i] >> a[i];
	
	for(int i=0;i<N;i++) v.pb(mp(mp(r[i]-1,c[i]-1),a[i]));
	sort(v.begin(), v.end());
	
	for(int i=0;i<C;i++) {par[i] = i;}
	for(int i=0;i+1<N;i++){
		if (v[i].first.first==v[i+1].first.first){
			tmp = v[i].second;
			int p1 = parent(v[i].first.second);
			par[v[i].first.second] = p1;
			diff[v[i].first.second] = tmp - v[i].second;
			
			ll tmp2 = tmp;
			
			tmp = v[i+1].second;
			int p2 = parent(v[i+1].first.second);
			par[v[i+1].first.second] = p2;
			diff[v[i+1].first.second] = tmp - v[i+1].second;			
			
			
			if (p1==p2){
				if (tmp!=tmp2){
					cout << "No" << endl;
					return 0;
				}
			}else{
				if (rand()%2){
					par[p1] = p2;
					diff[p1] = tmp - tmp2;
				}else{
					par[p2] = p1;
					diff[p2] = tmp2 - tmp;
				}
			}
		}
	}
	
	ll lb[C] = {0};
	for(int i=0;i<C;i++){
		tmp = 0;
		int p = parent(i);
		//cout << "i=" << i << " " << p << " " << tmp << endl;
		lb[p] = max(lb[p], tmp);
	}
	//cout << endl;
	//for(int i=0;i<C;i++) cout << lb[i] << " ";
	//cout << endl;
	
	for(int i=0;i<N;i++){
		tmp = v[i].second;
		int p = parent(v[i].first.second);
		//cout << "i=" << i << " " << tmp << " " << lb[p] << endl;
		if (tmp < lb[p]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	
	return 0;
}


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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace

#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);	
    ll n;
    cin >> n;
    vll nums(n);
    FOR(i, n) cin >> nums[i];
    sort(nums.begin(), nums.end());
    ll tot = 0;
    FOR(i, n - 2)
    {
        ll a = nums[i];
        FORN(j, i + 1, n - 1)
        {
            ll b = nums[j];
            ll diff = b - a;
            ll sum = a + b;
            auto start = upper_bound(nums.begin() + j + 1, nums.end(), diff);
            auto end = lower_bound(nums.begin() + j + 1, nums.end(), sum);
            tot += end - start;
        }
    }
    cout << tot << '\n';
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
   	
int main() {
	int flag = 0;
	string s;
	cin >> s;

	for (int i = 0; i < 3; i++)
	{
		if (s[i] == s[i+1])
		{
			flag = 1;
		}
	}

	if (flag == 1)
	{
		cout << "Bad";
	}
	else
	{
		cout << "Good";
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = boost::multiprecision::int128_t;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;


map<ll, ll> memo;
map<ll, bool> done;

ll n, a, b, c, d;

ll dp(ll x) {
  if (done[x]) return memo[x];
  if (x == 0) return 0;
  if (x == 1) return d;

  ll res = d * x;
  chmin(res, dp(x/2) + (x%2)*d + a);
  chmin(res, dp(x/3) + (x%3)*d + b);
  chmin(res, dp(x/5) + (x%5)*d + c);
  chmin(res, dp((x+1)/2) + (2-x%2)*d + a);
  chmin(res, dp((x+2)/3) + (3-x%3)*d + b);
  chmin(res, dp((x+4)/5) + (5-x%5)*d + c);

  done[x] = true;
  memo[x] = res;
  return res;
}


int main() {
  int t; cin >> t;
  rep(_, t) {
    done.clear();
    memo.clear();
    cin >> n >> a >> b >> c >> d;
    cout << dp(n) << "\n";
  }
  return 0;
}


Measured memory_bytes: 6416
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    int N;
    Set<String> set;

    AtCoder(FastScanner sc) {
        N = sc.nextInt();
        set = new HashSet<>();
        for (int i = 0; i < N; i++) {
            set.add(sc.next());
        }
    }

    void solve(PrintWriter out) {
        out.println(set.size() == 3 ? "Three" : "Four");
    }

}

class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22100
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


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









Measured memory_bytes: 384
n,p=map(int,input().split())
s=input()
ans=0
if(p==2 or p==5):
    kensa=["0","2","4","6","8"]
    if(p==5):
        kensa=["0","5"]
    for i in range(n):
        if(s[i] in kensa):
            ans+=i+1
else:
    amari=0
    ju=1

    cnt=[0]*p
    cnt[0]=1

    for i in range(n):
        amari+=int(s[n-i-1])*ju
        amari%=p
        ju=(ju*10)%p
        cnt[amari]+=1
    for c in cnt:
        if(c==0 or c==1):
            continue
        ans+=c*(c-1)//2
print(ans)

Measured memory_bytes: 41180
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    double l; cin>>l;
    l /= 3;

    printf("%.10f\n", l * l * l);

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
l = sorted(map(int, input().split()))
q = sorted(list(map(int, input().split()))[::-1] for _ in range(m))
q.reverse()
curr = sum(l)
i = j = 0

while j < m and i < n and q[j][0] >= l[i]:
    curr += q[j][0] - l[i]
    # print(i, j, curr, q[j], l[i])
    q[j][1] -= 1
    if q[j][1] == 0: j += 1
    i += 1
        
print(curr)

Measured memory_bytes: 24652
#include <bits/stdc++.h>
#define For(i, l, r) for(int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
    int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}

void File() {
#ifdef zjp_shadow
	freopen ("C.in", "r", stdin);
	freopen ("C.out", "w", stdout);
#endif
}

#define pow2(x) ((x) * (x))
int n, a[110];

int main () {
	File();
	n = read();
	For (i, 1, n)
		a[i] = read();

	int ans = 0x7f7f7f7f;
	For (i, -100, 100) {
		int now = 0;
		For (j, 1, n)
			now += pow2(a[j] - i);
		chkmin(ans, now);
	}
	printf ("%d\n", ans);
    return 0;
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N, a, b;
pii pt[100010];
ll ret;
bool rm[100010];
vector<pii> vx, vy;
set<pii> sx, sy;
map<pii, int> id;

int main() {
	scanf("%d %d %d", &N, &a, &b), --a, --b;

	rep(i, N) {
		int x, y;
		scanf("%d %d", &x, &y);
		pt[i] = mp(x-y, x+y);
		sx.insert(mp(x-y, x+y));
		sy.insert(mp(x+y, x-y));
		vx.pb(mp(x-y, x+y));
		vy.pb(mp(x+y, x-y));		
		id[pt[i]] = i;
	}

	sort(ALL(vx));
	sort(ALL(vy));

	int d = max(abs(pt[a].fi-pt[b].fi), abs(pt[a].se-pt[b].se));

	queue<int> que;
	que.push(a);
	que.push(b);

	while (!que.empty()) {
		int v = que.front(); que.pop();
		if (rm[v]) continue;
		rm[v] = true;

		int x = pt[v].fi, y = pt[v].se;

		auto it = sx.lower_bound(mp(x-d, y-d));

		while (it != sx.end()) {
			if (it->fi != x-d || it->se > y+d) break;
			que.push(id[*it]);
			sx.erase(it++);
		}

		it = sx.lower_bound(mp(x+d, y-d));
		while (it != sx.end()) {
			if (it->fi != x+d || it->se > y+d) break;
			que.push(id[*it]);
			sx.erase(it++);
		}

		it = sy.lower_bound(mp(y-d, x-d));

		while (it != sy.end()) {
			if (it->fi != y-d || it->se > x+d) break;
			que.push(id[mp(it->se, it->fi)]);
			sy.erase(it++);
		}

		it = sy.lower_bound(mp(y+d, x-d));
		while (it != sy.end()) {
			if (it->fi != y+d || it->se > x+d) break;
			que.push(id[mp(it->se, it->fi)]);
			sy.erase(it++);
		}
	}

	rep(i, N) if (rm[i]) {
		int x = pt[i].fi, y = pt[i].se;

		int rr = ret;
		auto it = lower_bound(ALL(vx), mp(x-d, y-d));
		auto it2 = upper_bound(ALL(vx), mp(x-d, y+d));
		ret += it2 - it;

		it = lower_bound(ALL(vx), mp(x+d, y-d));
		it2 = upper_bound(ALL(vx), mp(x+d, y+d));
		ret += it2 - it;

		it = lower_bound(ALL(vy), mp(y-d, x-d));
		it2 = upper_bound(ALL(vy), mp(y-d, x+d));
		ret += it2 - it;

		it = lower_bound(ALL(vy), mp(y+d, x-d));
		it2 = upper_bound(ALL(vy), mp(y+d, x+d));
		ret += it2 - it;

		if (id.count(mp(x-d, y-d))) --ret;
		if (id.count(mp(x-d, y+d))) --ret;		
		if (id.count(mp(x+d, y-d))) --ret;		
		if (id.count(mp(x+d, y+d))) --ret;	
	}

	printf("%lld\n", ret / 2);

	return 0;
}

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

inline void ioThings() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#define debug(x) cerr << #x << ": <" << (x) << ">\n"
#else
#define debug(x)
#endif
}

#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp(x, y)  make_pair(x, y);
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second
#define mod       1000000007

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int main() {
  ioThings();

  int n, m;
  cin >> n >> m;

  vi a(n);
  rep(i, n) cin >> a[i];

  vvi adj(n);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    adj[x].pb(y);
    adj[y].pb(x);
  }

  vi v(n);
  rep(i, n) {
    if (v[i]) continue;

    for (int j : adj[i]) {
      if (a[j] <= a[i]) v[j] = -1;
      if (a[j] >= a[i]) {
        v[i] = -1;
        break;
      }
    }

    if (!v[i]) v[i] = 1;
  }

  int cnt = 0;
  for (int i : v) if (i == 1) cnt++;

  cout << cnt;

  return 0;
}


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

using namespace std;

#define ll long long
#define PI 3.14159265358979323846264338327950L

struct Node;


struct way{
    Node* to;
    ll cost;
    ll time;
};

struct Node{

    int num;
    int exCost;
    int extime;
    ll minTime = -1;
    set<way*> reachabl;

};


struct compareWay {
    bool operator() (const way* a, const way* b) const{
        return a->time > b->time;
    }
};


const int numNodes = 51;
const int maxSilv = 2500;
int n,m,s;
int u,v,aa,bb;

Node a[numNodes];
ll dp[numNodes][maxSilv];

void solve(){

    cin >> n >> m >> s;

    for (int i = 0; i < m; i++)
    {
        cin >> u >> v >> aa >> bb;
        u--;
        v--;

        way* k = new way();
        k->to = &a[u];
        k->cost = aa;
        k->time = bb;
        a[v].reachabl.insert(k);

        way* f = new way();
        f->to = &a[v];
        f->cost = aa;
        f->time = bb;
        a[u].reachabl.insert(f);
        

    }

    for (int i = 0; i < n; i++)
    {
        cin >> u >> v;

        a[i].num = i;
        a[i].exCost = u;
        a[i].extime = v;


    }
    m = n;

    for (int i = 0; i < numNodes; i++)
    {
        for (int j = 0; j < maxSilv; j++)
        {
            dp[i][j] = -1;
        }
        
    }
    
    
    //dp[0][s] = 0;
    if(s > maxSilv) s = maxSilv;
    
    way* t = new way();
    t->to = &a[0];
    t->cost = s;
    t->time = 0;
    
    priority_queue<way*, vector<way*>, compareWay> next;

    next.push(t);


    while (!next.empty() && n > 0 )
    {
        way* k =  next.top();
        next.pop();
        
        if(dp[k->to->num][k->cost] == -1 || k->time < dp[k->to->num][k->cost]){
            dp[k->to->num][k->cost] = k->time;

            if(k->to->minTime == -1){
                k->to->minTime = k->time;
                n--;
            }

            for (auto o : k->to->reachabl)
            {
                
                if(o->cost <= k->cost){
                    way* t = new way();
                    t->to = o->to;
                    t->cost = k->cost - o->cost;
                    t->time = k->time + o->time;
                    next.push(t);
                }
            }

            
            way* t = new way();
            t->to = k->to;
            t->cost = k->cost + t->to->exCost;
            if(t->cost > maxSilv) t->cost = maxSilv; 
            t->time = k->time + k->to->extime;
            next.push(t);
           
              
        }
        //free(k);
    }


    for (int i = 1; i < m; i++ )
    {
        cout << a[i].minTime << endl;
    }
    

}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

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

using namespace std;

int main() {
  int n, a = 0;
  cin >> n;
  char s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == 'Y') {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
  return 0;
}


Measured memory_bytes: 256
def solve(i, m):
    if m == 0:
        return True
    elif m < 0:
        return False
    if i >= n:
        return False
    return solve(i + 1, m) or solve(i + 1, m - A[i])
    
if __name__ == '__main__':
    yes = set()
    no = set()
    n = int(input())
    A = list(map(int,input().split()))
    q = int(input())
    m = list(map(int,input().split()))
    s = sum(A)
    for i in range(q):
        if s < m[i]:
            print('no')
            no.add(m[i])
        elif m[i] in yes:
            print('yes')
        elif m[i] in no:
            print('no')
        elif solve(0, m[i]):
            print('yes')
            yes.add(m[i])
        else :
            print('no')
            no.add(m[i])


Measured memory_bytes: 5640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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 ll MAX=1000010;
ll fac[MAX];
ll inv[MAX];

ll pow_mod(ll n, ll p) {
     ll ret = 1;
     while (p > 0) {
         if (p & 1) ret = (ret * n) % MOD;
         n = (n * n) % MOD;
         p >>= 1;
     }
     return ret;
 }

 void setup() {
     fac[0] = fac[1] = 1;
     inv[0] = inv[1] = 1;
     for (int i = 2; i <= MAX - 2; i++) {
         fac[i] = (fac[i - 1] * i) % MOD;
         inv[i] = pow_mod(fac[i], MOD - 2);
     }
 }

 ll nPk(ll n, ll k) {
     if (n < k) return 0;
     return fac[n] * inv[n - k] % MOD;
 }

vector<int> G[MAX];

ll dfs(int v, int p ,ll k){
  if(p==-1){
    ll ret=k;
    int child=G[v].size();//頂点vから出る子の数
    ret*=nPk(k-1,child);
    ret%=MOD;
    rep(i,sz(G[v])){
      int to=G[v][i];
      ret*=dfs(to,v,k);
      ret%=MOD;
    }
    return ret;
  }else{
    ll ret=1;
    if(sz(G[v])==1) return ret;
    int child=G[v].size()-1;//頂点vから出る子の数
    ret*=nPk(k-2,child);
    ret%=MOD;
    rep(i,sz(G[v])){
      int to=G[v][i];
      if(to==p) continue;
      ret*=dfs(to,v,k);
      ret%=MOD;
    }
    return ret;
  }
}

int main(int argc, char const *argv[]) {
  setup();
  ll n,k;
  cin >> n >> k;
  
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--,b--;
    G[a].pb(b);
    G[b].pb(a);
  }

  ll ans=dfs(0,-1,k);
  cout << ans << endl;
  return 0;
}


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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

#define int int64_t
int32_t  main(){
	IOS;
  int k,a,b;cin>>k>>a>>b;
  int cnt=1;
  if(b-a>2){
    //try to reach first a biscuits then do exchanging
    if(k>=a-1){
      k-=a-1;
      cnt+=a-1;
      if(k%2==0)cout<<cnt+(k/2)*(b-a)<<endl;
      else cout<<cnt+(k/2)*(b-a)+1<<endl;
    }else{
      cout<<1+k<<endl;
    }
  }else{
    cout<<1+k<<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 inf 1000000007

int main() {
	int n;
	cin >> n;
	int all = 0;
	int mi = inf;
	rep(i, n) {
		int w;
		cin >> w;
		if(w % 2 == 1) {
			mi = min(mi, w);
		}
		all += w;
	}
	if(all % 2 == 0) {
		cout << all / 2 << endl;
	}
	else {
		cout << (all - mi) / 2 << endl;
	}
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long J, K, L, N;
  cin >> N;
  J = -1; //def L_-1
  K = 2; //def L_0
  
  for ( int i = 0; i < N; i++){
    L = J + K; // L_(n+2) = L_n + L_(n+1)
    //             ^L        ^J        ^K
    J = K;
    K = L;
  }
  cout << L << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int A[200005];
int main()
{
    int N;
    cin>>N;

    for(int i=1;i<=N;i++)
    {
        cin>>A[i];
    }
    ll sum=0;
    for(int i=2;i<=N;i++)
    {
        if(A[i-1]>A[i])
        {
             sum+=A[i-1]-A[i];
             A[i]=A[i-1];
        }

    }

    cout << sum << endl;
    return 0;
}


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

typedef long long ll;

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;

ll dp[MAXV];
int N,W,V,wi[MAXN],vi[MAXN];

int main(){

	cin >> N >> W;
	for(int i = 1;i<=N;i++){
		cin >> wi[i] >> vi[i];
		V += vi[i];
	}

	for(int i = 1;i<=V;i++) dp[i] = INF;
	dp[0] = 0;
	
	for(int it = 1;it<=N;it++){
		
		for(int i = V;i>=vi[it];i--){
			dp[i] = min(dp[i],dp[i - vi[it]] + wi[it]);
		}
	}

	for(int i = V;i>=0;i--){
		if(dp[i] <= W){
			cout << i << endl;
			break;
		}
	}

	return 0;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; 
//order_of_key(k)= # of items strictly smaller than 'k'  //find_by_order(x)= iterator to x'th largest element (counting from ZERO) //erase("iterator") [log(n)] //end(<name>)
//os.find_by_order(os.order_of_key(x)=iterator to 'x' in the rb tree
template<class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target ("avx2")
//#pragma GCC optimize ("O3")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef priority_queue<ll> pq;                                        //min-heap-> multiply the values by '-1'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define forr(i,a,b) for (ll i = a; i < b; i++)
#define test ll t;cin>>t;while(t--)
#define summ(a,n) accumulate(a,a+n,0)
#define bsrch(v,n) lower_bound(v.begin(), v.end(), n)
#define minindex(v) distance(v.begin(),min_element(v.begin(),v.end()))         //returns index of minimum(/max) element in the vector
#define bp(x) _builtin_popcount(x)
#define inf 1000000000000
#define PI = 3.1415926535897932384626
#define mod 1000000007

int main()
{
    ll n,k; cin>>n>>k;
  	ll a[n], dp[n];
  	forr(i,0,n) cin>>a[i];
  
  	dp[0]=0, dp[1]=abs(a[0]-a[1]);
  	forr(i,2,n) 
  	{
  	    dp[i]=abs(a[i]-a[i-1])+dp[i-1];
  	    for(ll j=2;j<=(min(i,k));j++) 
  	        dp[i]=min(dp[i], abs(a[i]-a[i-j])+dp[i-j]);
  	}
  	cout<<dp[n-1];
}

Measured memory_bytes: 5196
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<math.h>

#define ALL(a) (a).begin(),(a).end()
#define ll long long
#define vi vector<int>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,k,n) for(int (i)=(k);(i)<(n);(i)++)

using namespace std;
  
int main(){
  int N;cin>>N;
  int t[N]; string s[N];
  REP(i,N)cin>>s[i]>>t[i];
  string X;cin>>X;

  int n=0;int k=0;
  REP(i,N){
    
    if(s[i]==X){/*
      cout << "i:"<<i;
      cout << s[i]<<":"<<X<<endl;*/
      n=i;//cout<<"n:"<<n;
      break;
    }else if(n<1&&i==N-1)n=-1;
    
  }
  n++;
  //cout<<s[n]<<k<<endl;
  if(n!=-1)FOR(i,n,N){
      /*cout << t[i] << "+";*/k+=t[i];
    }
  else k=-1;
  cout << k << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD_CONST 1000000007
typedef long long int lli;

int main(){
    int r;
    cin >> r;
    int ans = 3 * r * r;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll A[200005];
int main() {
    ll A, B, V, W, T;
    
    cin >> A >> V >> B >> W >> T;
    
    if (V <= W){
        cout << "NO";
        return 0;
    }
    if (abs(B - A) <= (V - W) * T){
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 H, W, N;
  cin >> H >> W >> N;
  vi A(N);
  cin >> A;

  i64 cur = 0;
  vvi C(H, vi(W));
  rep(h, H) rep(w, W){
    if(h&1) C[h][W-1-w] = cur + 1;
    else C[h][w] = cur + 1;
    A[cur]--;
    if(!A[cur]) cur++;
  }
  rep(h, H) cout << C[h] << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

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


int main() {
	int n;
	cin>>n;
	
	vector<int> sub(n+1, 0);
	for(int i=1; i<n; i++) {
		int x;
		cin>>x;
		sub[x]++;
	}
	
	for(int i=1; i<=n; i++) {
		cout<<sub[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 4048
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

//===
template<class SemiGroup, class OP = function<SemiGroup(SemiGroup, SemiGroup)> >
struct SlidingWindow {
    using Stack = stack<SemiGroup>;
    const OP merge;
    Stack front_st, back_st;
    Stack front_sum, back_sum;
    size_t sz;

    SlidingWindow(const OP &f):merge(f) {
        sz = 0;
    };

    SemiGroup fold() {
        assert(sz > 0);
        
        if (front_sum.empty()) return back_sum.top();
        else if (back_sum.empty()) return front_sum.top();
        else return merge(front_sum.top(), back_sum.top());
    };

    void push(SemiGroup d) {
        sz++;
        back_st.push(d);
        if (back_sum.empty()) back_sum.push(d);
        else back_sum.push(merge(back_sum.top(), d));
    };

    void pop() {
        assert(sz > 0);

        sz--;
        if (front_st.empty()) {
            front_st.push(back_st.top());
            front_sum.push(back_st.top());
            back_st.pop();
            back_sum.pop();
            
            while (!back_st.empty()) {
                front_st.push(back_st.top());
                front_sum.push(merge(front_sum.top(), back_st.top()));
                back_st.pop();
                back_sum.pop();
            }
        }
        
        front_st.pop();
        front_sum.pop();
    };

    bool empty() {
        return sz == 0;
    };

    size_t size() {
        return sz;
    };
};
//===

llong n, q;
llong a[100005];
llong x;
auto f = [](auto l, auto r){return l + r;};

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

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

    for (int i = 0; i < q; i++) {
        cin >> x;

        llong ans = 0;
        SlidingWindow<llong, decltype(f)> sum(f);
        for (int i = 0; i < n; i++) {
            sum.push(a[i]);

            while (!sum.empty() && sum.fold() > x) {
                sum.pop();
            }

            ans += sum.size();
        }

        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 5260
#include<stdio.h>
int main()
{
int a,b,c;
int temp;
scanf("%d %d %d", &a, &b, &c);
if(a>b){
temp=a;
a=b;
b=temp;
}
if(b>c){
temp=c;
c=b;
b=temp;
}
if(a>b){
temp=a;
a=b;
b=temp;
}
printf("%d %d %d\n",a,b,c);
return 0;
}


Measured memory_bytes: 2736
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define MAX 1005
const ll MOD=1e9+7;
using namespace std;
ll gcd(ll a, ll b) {
  if(a==0) return b;
  if(a>b) return gcd(a%b, b);
  else return gcd(b%a, a);
}
ll lcm(ll a, ll b) {
  ll tmp=gcd(a,b);
  return (a/tmp)*(b/tmp)*tmp;
}

int main() {
  int N;
  cin >> N;
  int ans=0;
  vector<int> s(N);
  rep(i,N){
    cin >> s[i];
    ans+=s[i];
  }
  sort(All(s));
  while(1){
    if(ans%10!=0){
      cout << ans << endl;
      return 0;
    }
    for(int t : s){
      if(t%10!=0){
        ans-=t;
        cout << ans << endl;
        return 0;
      }
    }
    //すべて10の倍数のとき
    cout << 0 << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=5e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const double PI = acos(-1);

void solve(){
    ll n,k;
    cin>>n>>k;
    int arr[n];
    loop(n,i,0)
        cin>>arr[i];
    ll res=0;
    loop(n,i,0){
        loop(n,j,i+1){
            if(arr[j]<arr[i])
                res=(res+(k*(k+1)/2)%MOD)%MOD;
        }
        loopR(i,j,0)
            if(arr[j]<arr[i])
                res=(res+(k*(k-1)/2)%MOD)%MOD;
    }
    cout<<res%MOD<<Endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,cnt=0,f=1;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i] ;
  sort(a,a+n);
  for(int i=n-1;i>=0;i--){
    cnt += a[i]*f;
    if(f==1)f= (-1);
    else f=1;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
A.sort()
X=A[-1]
m=X
p=A[0]
for a in A[:-1]:
  if abs(a-X/2)<m:
    m=abs(a-X/2)
    p=a
  else:
    break
print(X,p)

Measured memory_bytes: 14052
/// In The Name Of God

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

using namespace std;

int n;
int a[N], b[N];

vector <int> st;
ll ans;
int get(int l, int r) {
	return upper_bound(all(st), r) - lower_bound(all(st), l);
}
void solve(int k) {
	int m1 = (1 << k), m2 = m1 << 1;
	for (int i = 1; i <= n; i++) {
		st[i - 1] = a[i] & (m2 - 1);
	}
	sort(all(st));
	ll cnt = 0;
	for (int i = 1; i <= n; i++) {
		int cur = b[i] & (m2 - 1);
		cnt += get(m1 - cur, m2 - cur - 1);
		cnt += get(m1 + m2 - cur, m2 << 1);
	}
	if (cnt & 1) ans += m1;
}
int main() {
	#ifdef IOI2018
		freopen ("in.txt", "r", stdin);
	#endif
	Kazakhstan
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}
	st.resize(n);
	for (int i = 0; i < 29; i++) {
		solve(i);
	}
	cout << ans;
	ioi
}


Measured memory_bytes: 2560