akhauriyash/Code-Regression huggingface dataset:
# -*-coding:utf-8

import math

def main():

    inputNum = int(input())

    x = list(map(float, input().split()))
    y = list(map(float, input().split()))

    absVec = []
    absVec2 = []
    absVec3 = []
    for i, j in zip(x, y):
        absVec.append(abs(i-j))
        absVec2.append(pow(abs(i-j),2))
        absVec3.append(pow(abs(i-j),3))

    print(sum(absVec))
    print(pow(sum(absVec2),1/2))
    print(pow(sum(absVec3),1/3))
    print(max(absVec))

if __name__ == '__main__':
    main()

Measured memory_bytes: 7912
//***Little by little one travels far***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
vector<ll> g[100002];
ll vis[100002];

void dfs(ll u,ll level,vector<ll> &v){
    //cout<<u<<level<<endl;
    v[u]=level;
    vis[u]=1;
    for(auto x:g[u])
        if(!vis[x]) dfs(x,level+1,v);
}

int main()
{
    ll n,u,v;
    cin>>n>>u>>v;

    forn(i,n-1){
        ll p,q;
        cin>>p>>q;
        g[p].pb(q);
        g[q].pb(p);
    }

    vector<ll> ha(n+1);
    vector<ll> hb(n+1);

    dfs(u,0,ha);
    //
    for1(i,n) vis[i]=0;
    //return 0;
    dfs(v,0,hb);
    //for1(i,n) cout<<hb[i]<<" ";
    ll ma=0;

    for1(i,n){
        if(hb[i]>=ha[i]) ma=max(ma,hb[i]-1);
    }
    cout<<ma;
}

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

using namespace std;
#define int long long
const int N = 666666 ;
int n,m;
int f[N];
int getf(int v){
	if(f[v]==v){
		return f[v];
	}else{
		f[v]=getf(f[v]);
		return  f[v];
	}
}
int merge(int u,int v){
	int t1=getf(u);
	int t2=getf(v);
	if(t1!=t2){
		f[t2]=t1;
		return 1;
	}
	return 0;
}

signed main(){
	cin>>n>>m;
	for(int i=0;i<=n;i++) f[i]=i;
	int u,v,sum=0;
	for(int i=0;i<m;i++){
		cin>>u>>v;
		if(merge(u,v)) sum++;
	}	
	int ans=n-1-sum;
	cout<<ans;
	return 0; 
}


Measured memory_bytes: 4372
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int a,z;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A'){
            a = i;
            break;
        }
    }
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'Z') z = i;
    }
    cout << z + 1 - a << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
ll dp[101][100001];

int main(){
  int N,W;cin>>N>>W;
  ll w[101],v[101];
  for(int i=1;i<=N;i++) cin>>w[i]>>v[i];

  for(int i=1;i<=N;i++) for(int j=1;j<=W;j++){
    if(j-w[i]>=0) dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
    else dp[i][j]=dp[i-1][j];
  }
  cout<<dp[N][W]<<endl;
}

Measured memory_bytes: 81616
import sys
import bisect
from math import ceil
from itertools import accumulate
n, d, a = [int(i) for i in sys.stdin.readline().split()]
monsters = []
max_x = 0
for i in range(n):
    x, h = [int(i) for i in sys.stdin.readline().split()]
    max_x = max(x, max_x)
    monsters.append([x, h])
monsters.sort(key=lambda x:x[0])
x, h = zip(*monsters)
x_ls = []
for i, (_x, _h) in enumerate(zip(x, h)):
    ind = bisect.bisect_right(x, _x + 2 * d)
    x_ls.append([i, ind, _h])

h = list(h) + [0]
ls = [0 for i in range(n+1)]
cur = 0
res = 0
for i, ind, _h in x_ls:
    if h[i] > 0:
        cur -= ls[i]
    h[i] -= cur
    if h[i] > 0:
        hoge = ceil(h[i] / a)
        res += hoge
        cur += hoge * a
        ls[ind] += hoge * a
print(res)


Measured memory_bytes: 123056
/*
 * じょえチャンネル
 * 高評価・チャンネル登録よろしくおねがいします！
 * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
 */
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define mod (int)1000000007
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = DBL_EPSILON;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline int gcd(int a, int b) {
	while (b) {
		int c = a;
		a = b; b = c % b;
	}
	return a;
}
inline int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
bool isprime(int n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
int mypow(int a, int b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int modpow(int a, int b, int m = mod) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	int memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
signed main() {
	int n, r;
	cin >> n >> r;
	if (n >= 10)cout << r << endl;
	else cout << r + 100 * (10 - n) << endl;
	return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int n,k,s;
    cin >>n>>k>>s;
    vector<int> as(n);

    rep(i,k)as[i]=s;
    rep1(i,k,n)as[i]=(s+1)%1000000000;

    rep(i,n)cout<<as[i]<<" ";
    ln;

    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 1664
def bubble_sort(c, n)
  0.upto(n-1) do |i|
    (n-1).downto(i+1) do |j|
      if c[j][1].to_i < c[j-1][1].to_i
        c[j], c[j-1] = c[j-1], c[j]
      end
    end
  end

  puts c.join(' ')

  c
end

def selection_sort(c, n)
  0.upto(n-1) do |i|
    min_j = i
    i.upto(n-1) do |j|
      if c[j][1].to_i < c[min_j][1].to_i
        min_j = j
      end
    end

    c[i], c[min_j] = c[min_j], c[i] if i != min_j
  end

  puts c.join(' ')

  c
end

def check_stable(c, before_order, targets)
  after_order = Hash.new { |h, k| h[k] = [] }

  c.each do |elem|
    if targets.include?(elem[1])
      after_order[elem[1]] << elem[0]
    end
  end

  diff = false
  targets.each do |target|
    if before_order[target] != after_order[target]
      diff = true
      break
    end
  end

  puts diff ? 'Not stable' : 'Stable'
end


N = gets.to_i
C = gets.split

before_order = Hash.new { |h, k| h[k] = [] }
C.each do |elem|
  before_order[elem[1]] << elem[0]
end
before_order.select! { |k, v| v.length >= 2 }
targets = before_order.keys

check_stable(bubble_sort(C.dup, N), before_order, targets)
check_stable(selection_sort(C.dup, N), before_order, targets)

Measured memory_bytes: 8768
K = int(input())
A = [int(x) for x in input().split()]
nmin = 2
nmax = 2
last = 1
for a in A[::-1]:
    nmin = ((nmin-1)//a+1)*a
    if(nmin>nmax):
        print(-1)
        break
    nmax = (nmax//a)*a+a-1
    last = a


else:
    print(nmin,nmax)


Measured memory_bytes: 14252
package main 
import(
  "fmt"
)
func main(){
  var n, k, i, j int 
  ans:=0
  fmt.Scan(&n, &k)
  d:=make([]int, k)
  a:=make([][]int, k)
  x:=make([]int, n)
  for i=0;i<k;i++{
    fmt.Scan(&d[i])
    a[i]=make([]int, d[i])
    for j=0;j<d[i];j++{
      fmt.Scan(&a[i][j])
      x[a[i][j]-1]++
    }
  }
  for i=0;i<len(x);i++{
    if x[i]==0{
      ans++
    }
  }
  fmt.Println(ans)
}

Measured memory_bytes: 2428
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

int isUnder(int T,int A){ // AがT以下で1,それ以外0
    if(A<=T) return 1;
    else return 0;
}

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    unordered_map<int,int> m;
    int sameNotExist = true,ans =0;;
    while(sameNotExist){
        ans++;
        if(m.count(N)==0)m[N]++;
        else sameNotExist = false;
        N = ((N%2==0)? N/2:(3*N+1));
    }
    cout << ans << nn;
    return 0;
}

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

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

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

    ll cost_min = 1e9;

    for(ll i = -100; i <= 100; i++){
        ll cost = 0;
        for(ll j = 0; j < N; j++){
            cost += (A[j] - i) * (A[j] - i);
        }
        if(cost <= cost_min){
            cost_min = cost;
        }
    }

    cout << cost_min << endl;

    return 0;
}


Measured memory_bytes: 3488
#include<iostream>
#include<string>
using namespace std;
int n; string S, dp[320][320];
int dp2[320][320];
inline string LCS(string &a1, string &a2) {
	for (int i = 0; i <= a1.size(); i++) {
		for (int j = 0; j <= a2.size(); j++)dp2[i][j] = -1;
	}
	dp2[0][0] = 0;
	for (int i = 0; i <= a1.size(); i++)dp[i][0] = "";
	for (int i = 0; i <= a2.size(); i++)dp[0][i] = "";
	for (int i = 0; i <= a1.size(); i++) {
		for (int j = 0; j <= a2.size(); j++) {
			if (i < a1.size() && j < a2.size() && a1[i] == a2[j]) {
				if (dp2[i + 1][j + 1] < dp2[i][j] + 1) {
					dp[i + 1][j + 1] = dp[i][j] + a1[i];
					dp2[i + 1][j + 1] = dp2[i][j] + 1;
				}
			}
			if (dp2[i + 1][j] < dp2[i][j]) { dp[i + 1][j] = dp[i][j]; dp2[i + 1][j] = dp2[i][j]; }
			if (dp2[i][j + 1] < dp2[i][j]) { dp[i][j + 1] = dp[i][j]; dp2[i][j + 1] = dp2[i][j]; }
		}
	}
	return dp[a1.size()][a2.size()];
}
int main() {
	while (cin >> S) {
		for (int i = 0; i < 102400; i++)dp[i / 320][i % 320] = "";
		if (S == "#END")break;
		n = S.size(); string V = "";
		for (int i = 1; i < n; i++) {
			string T = S.substr(0, i), U = S.substr(i, n - i);
			string W = LCS(T, U);
			if (V.size() < W.size())V = W;
		}
		cout << V << endl;
	}
	return 0;
}

Measured memory_bytes: 9460
/*
 * 
 * */

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout << #x << ":\t" << x << endl
#define _ << " " <<

#define s_time clock_t time_start = clock()
#define t_time cout << double(clock() - time_start) / 1000 << endl

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int N = 1e5 + 3;
const ll M = 1e9 + 7;

int n;
vector<int> g[N];
ll dp[N][2];

void dfs(int v, int pr = -1) {
	dp[v][0] = dp[v][1] = 1;
	for (auto& u: g[v]) {
		if (u != pr) {
			dfs(u, v);
			dp[v][0] = dp[v][0] * (dp[u][0] + dp[u][1]) % M;
			dp[v][1] = dp[v][1] * dp[u][0] % M;
		}
	}
}

int main(int argc, char** argv) {
//	mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> n;
	while (--n) {
		int x, y; cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}
	
	dfs(1);
	cout << (dp[1][0] + dp[1][1]) % M;
	
	return 0;
}

/*
 * 
 * */


Measured memory_bytes: 10368
//????°???±????\??????????
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define MAX_V 100000

vector<int> G[MAX_V];
vector<int> depth,vs;
int id[MAX_V]={};

template<class T>
class segtree{
private:
    vector<T> dat;
    int _size;
    T _init;
    
public:
    segtree(int __size=0 , T init=numeric_limits<T>::max() ):_size(__size) , _init(init) , dat(4*__size,init){
        if(__size==0)return ;
        int x=1;
        while(x<_size)x*=2;
        _size = x;
    }
    
    int size(){
        return _size;
    }
    
    void update(int m,T x){
        int i = m+_size;
        dat[i] = x;
        while(i!=1){
            dat[i/2] = min(dat[i],dat[i^1]);
            i/=2;
        }
    }
    
    // call find(s,t)
    T find(int s,int t,int num=1,int a=0,int b=-1){
        if(b==-1)b=_size-1; //I couldn't "int b=_size".
        if(b<s||t<a)return _init;
        if(s<=a&&b<=t)return dat[num];
        return min( find(s,t,num*2,a,(a+b)/2) , find(s,t,num*2+1,(a+b)/2+1,b) );
    }
};


void dfs(int d,int num){
    depth.pb(d);
    vs.pb(num);
    rep(i,G[num].size()){
        dfs(d+1,G[num][i]);
        depth.pb(d);
        vs.pb(num);
    }
    return ;
}


void init(){
    dfs(1,0);
    rep(i,vs.size()){
        if(id[ vs[i] ]==0)id[ vs[i] ]=i;
    }
}


int main(){
    int n;
    cin>>n;
    rep(i,n){
        int k;
        cin>>k;
        rep(j,k){
            int b;
            cin>>b;
            G[i].pb(b);
        }
    }
    init();                                                         // aranging depth[] , vs[] and id[]
    segtree<pii> st(depth.size(),pii((1LL<<31)-1,(1LL<<31)-1));         // the number of elements is depth.size()
    rep(i,depth.size()){                                            //initialize
        st.update(i,pii(depth[i],vs[i]));
    }
    int a,b;
    int q;
    cin>>q;
    rep(i,q){
        cin>>a>>b;
        cout<<st.find(min(id[a],id[b]),max(id[a],id[b])).second<<endl;  // is equal to LCA(a,b)
    }
}

Measured memory_bytes: 19604
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()

using LL = long long;
int vis[100005];
vector <int> ans;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
	return getchar();
//    if (ib == ie) {
//        ib = ibuf;
//        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
//    }
//    return ib == ie ? -1 : *ib++;
}

}

#define mp(x,y) make_pair(x,y)

using P = pair<int,int> ;
vector<pair<int,int> > g[100005];
int a[100005];
bool b[100005];
void dfs(int x)
{
	vis[x]=1;
	for(auto u:g[x])
	{
		if(vis[u.first]) continue;
		dfs(u.first);
		if(b[u.first])
		{
			ans.push_back(u.second);
			b[u.first]^=1;
			b[x]^=1;
		}
	}
}

int main() {
    ios_base::sync_with_stdio(false);
    int n,m;
	cin>>n>>m;
	vector <pair<int,int> > psort;
    vector <int> lsh;
    for (int i = 0; i < n; ++i) {
		cin>>a[i]>>b[i];
		psort.push_back(mp(a[i],b[i]));
		lsh.push_back(a[i]);
    }
	sort(all(lsh));
    sort(all(psort));
    for(int i=0;i<n;i++)
    {
    	b[i]=psort[i].second;
	}
	for(int i=n;i>=0;i--)
	{
		b[i]^=(i?b[i-1]:0);
	}
    for (int i = 0; i < m; ++i) {
    	int l,r;
		cin>>l>>r;
		l=lower_bound(all(lsh),l)-lsh.begin();
		r=upper_bound(all(lsh),r)-lsh.begin();
		g[l].push_back(make_pair(r,i));
		g[r].push_back(make_pair(l,i));
    }
	for(int i=0;i<=n;i++)
	{
		if(vis[i]) continue;
		dfs(i);
		if(b[i])
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	sort(all(ans));
	cout<<ans.size()<<endl;
	for(auto x:ans)
	{
		cout<<x+1<<' ';
	}
	cout<<endl;
    return 0;
}


Measured memory_bytes: 15092
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    q = deque()

    for i in range(len(s)):
        if s[i] == "B": 
            if q: q.pop()
        else: q.append(s[i])
    Ans = ""
    while q: Ans += q.popleft()
    print(Ans)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3316
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')

n = int(input())
a = list(map(int,input().split()))
res = 10 ** 100

for i in range(n + 1):
    res = min(res, abs(sum(a[:i]) - sum(a[i:])))
    # print(a[:i], a[i:])
print(res)

Measured memory_bytes: 5712
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MAX 1000000007

using namespace std;

bool cmp(const pair<lli, lli> left, const pair<lli, lli> right) {
	return left.second < right.second;
}

using namespace std;

int main() {
	lli n, m, p, q;
	vector<lli> vec;

	cin >> n;
	cout << (n * n * 3);

}


Measured memory_bytes: 888
#include <iostream>
#include <map>

using namespace std;

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

    map<int, int> num;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;

        if (num[A] == 0) num[A] = 1;
        else if (num[A] == 1) num[A] = 0;
    }

    int ans = 0;
    for (auto i = num.begin(); i != num.end(); i++) {
        ans += i->second;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int h,w,k; cin>>h>>w>>k;
    char c[h][w];
    int black_sum=0;
    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
            if(c[i][j]=='#')black_sum++;
        }
    }
    
    int blackh[h];
    int blackw[w];
    rep(i,h){
        blackh[i]=0;
        rep(j,w){
            if(c[i][j]=='#')blackh[i]++;
        }
    }
   
    rep(j,w){
        blackw[j]=0;
        rep(i,h){
            if(c[i][j]=='#')blackw[j]++;
        }
    }
    
    int ans=0;
    for(int bith = 0 ; bith < (1<<h) ; ++bith){
        int dec=0;
        vector<int>   rememverme;
        for(int i=0 ; i < h ; i++){
            if(bith & (1<<i)){
                dec+=blackh[i];
                rememverme.push_back(i);
            }
            
        }
        int memo=dec;
        for(int bitw = 0 ; bitw < (1<<w) ; ++bitw){
            dec=memo;
            for(int j=0 ; j < w ; j++){
                if(bitw & (1<<j)){
                    dec+=blackw[j];
                    for(auto tmp : rememverme){
                        if(c[tmp][j]=='#')dec--;
                    }
                }
            }
            if(black_sum-dec==k)ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

using P=tuple<int, int, int>;
using T=tuple<long, P>;
const long inf=1L<<60;

int main()
{
    uint H, W, K; cin>>H>>W>>K;
    int sx, sy, gx, gy; cin>>sx>>sy>>gx>>gy;
    --sx, --sy, --gx, --gy;

    vector<string> a(H);
    for(auto& s: a) cin>>s;

    vector d(H, vector(W, vector(4, inf)));
    priority_queue<T, vector<T>, greater<T>> q;
    for(int i=0; i<4; ++i) {
        q.emplace(0L, P(sx, sy, i));
        d[sx][sy][i]=0;
    }

    int dx[4]={-1, 0, 1, 0};
    int dy[4]={0, -1, 0, 1};
    while (!q.empty()) {
        auto [cost, pos]=q.top(); q.pop();
        auto [x, y, z]=pos;

        uint nx=x+dx[z];
        uint ny=y+dy[z];
        auto nc=cost+1;
        P np={nx, ny, z};

        if (!(nx>=H or ny>=W or a[nx][ny]=='@' or d[nx][ny][z]<=nc)) {
            q.emplace(nc, np);
            d[nx][ny][z]=nc;
        }
        for(int i=0; i<4; ++i) if (i!=z) {
            nc=(cost+K-1)/K*K;
            if (d[x][y][i]<=nc) continue;
            q.emplace(nc, P(x, y, i));
            d[x][y][i]=nc;
        }
    }

    long res=inf;
    for(int i=0; i<4; ++i) res=min(res, d[gx][gy][i]);
    cout<<(res<inf ? (res+K-1)/K : -1)<<endl;
}


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

using namespace std;
const int MOD=1e9+7;
map<int,int>mp;
int last[200005],c[200005],prep[200005],dp[200005];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>c[i];
	}
	memset(last,-1,sizeof(last));
	memset(prep,-1,sizeof(prep));
	for(int i=1;i<=n;i++){
		last[i]=prep[c[i]];
		prep[c[i]]=i;
	}
	dp[1]=1;
	for(int i=2;i<=n;i++){
		if(c[i]!=c[i-1]&&last[i]!=-1){
			dp[i]=(dp[i-1]+dp[last[i]])%MOD;
		}
		else {
		    dp[i]=dp[i-1];
		}
	}
	cout<<dp[n];
	return 0;
}

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

int N, mx;
vector<vector<pair<int, int>>> G;
vector<int> ans;

void dfs(int v, int pv, int c) {
  for (auto g : G.at(v)) {
    if (g.first == pv) continue;
    int nc = nc % mx + 1;
    ans.at(g.second) = nc;
    dfs(g.first, v, nc);
  }
}

int main() {
  cin >> N;
  G.resize(N);
  ans.resize(N - 1);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    G.at(--a).push_back({--b, i});
    G.at(b).push_back({a, i});
  }
  for (auto g : G) mx = max(mx, (int) g.size());
  cout << mx << "\n";
  dfs(0, -1, 0);
  for (auto a : ans) cout << a << "\n";
}

Measured memory_bytes: 6912
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

void dfs(vector<vector<ll>> &tree, vector<ll> &points, vector<bool> &visited,
         ll current) {
  visited[current] = true;
  for (auto node : tree[current]) {
    if (visited[node]) continue;

    points[node] += points[current];
    dfs(tree, points, visited, node);
  }
}

int main() {
  ll N, Q;
  cin >> N >> Q;
  vector<vector<ll>> tree(N);
  for (ll i = 0; i < N - 1; i++) {
    ll a, b;
    cin >> a >> b;
    tree[a - 1].push_back(b - 1);
    tree[b - 1].push_back(a - 1);
  }

  vector<ll> points(N, 0);
  for (ll i = 0; i < Q; i++) {
    ll p, x;
    cin >> p >> x;
    points[p - 1] += x;
  }

  vector<bool> visited(N, false);
  dfs(tree, points, visited, 0);
  for (ll i = 0; i < N; i++) {
    cout << points[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 30592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  for(int i=0;i<N;i++){
    string num1,num2;
    cin>>num1>>num2;
    if(num1.size()==num2.size()&&num1.size()>80||num2.size()>80){
      cout<<"overflow"<<endl;
      continue;
    }
    int ma,mi;
    stack<int> sum;
    string lnum,snum;
    if(num1.size()>num2.size()){
      ma=num1.size();lnum=num1;
      mi=num2.size();snum=num2;
    }else{
      ma=num2.size();lnum=num2;
      mi=num1.size();snum=num1;
    }
    int keta=0;
    for(int i=ma-1;i>=0;i--){
      int a,b;
      a=lnum[i]-'0';
      if(mi<=0)
	b=0;
      else{
	b=snum[mi-1]-'0';
	mi--;
      }
      int summ=a+b+keta;
      if(summ>=10){
	sum.push(summ%10);
	keta=1;
      }else if(summ<=9){
	sum.push(summ);
	keta=0;
      }
    }
    if(keta==1)
      sum.push(1);
    if(sum.size()>80)
      cout<<"overflow"<<endl;
    else{
      int k=sum.size();
      for(int i=0;i<k;i++){
	cout<<sum.top();
	sum.pop();
      }
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3080
#include <iostream>
using namespace std;
int main()
{
    string s;
    int sum1, sum2 = 0;
    cin >> s;
    sum1 = (s[0] - '0' - 1) + (s.size() - 1) * 9;
    for(size_t i = 0; i < s.size(); i++){
        sum2 += s[i] - '0';
    }
    cout << (sum1 > sum2 ? sum1 : sum2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k;
    cin>>n>>k;
    int a[n],b[n],mn;
    for(i=0;i<n;i++) cin>>a[i];
    memset(b,1000000099,sizeof(b));
    b[n-1]=0;b[n-2]=abs(a[n-1]-a[n-2]);

    for(i=n-3;i>=0;i--)
    {
        for(j=1; j<=k && i+j<n; j++)
        {
            mn=abs(a[i]-a[i+j])+b[i+j];
            b[i]=min(mn,b[i]);
        }
    }
    cout<<b[0]<<endl;
    return 0;
}




Measured memory_bytes: 1024
#! /usr/bin/env perl
use Data::Dumper;

sub check_distance
{
    my ($d,$arr1,$arr2) = @_;
    my $value = 0;
    for(my $i=0;$i<$d;$i++)
    {
        $value +=  abs($arr1->[$i] - $arr2->[$i]) *abs($arr1->[$i] - $arr2->[$i]);
    }
    return check_srrt($value);
}

sub check_srrt
{ 
    my $val = shift;
    if(sqrt($val) =~ /\d+\.\d+/)
    {
        return 0
    }
    else
    {
        return 1;
    }

}

my $input = <STDIN>;
chomp $input;
my ($n,$d) = split / /,$input;
my $count =0;
my $arr = [];

for(my $i=0;$i<$n;$i++){
    $input = <STDIN>;
    chomp $input;
    my @in = split / /,$input;
    push(@$arr,\@in);
}
for(my $j=0;$j<$n-1;$j++)
{
    for(my $q=$j+1;$q<$n;$q++)
    {
        $count += check_distance($d,$arr->[$j],$arr->[$q]);
    }
}

print $count;


Measured memory_bytes: 1920
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        q: usize,
        v: [(usize, usize); q]
    }
    for &(a, b) in &v {
        let x = min(a, b);
        let y = max(a, b);
        let mut l = 0;
        let mut r = y;
        while l + 1 < r {
            let m = (l + r) / 2;
            if m * m < x * y {
                l = m;
            } else {
                r = m;
            }
        }
        if x == y || x + 1 == y {
            println!("{}", 2 * x - 2);
        } else if l * (l + 1) >= x * y {
            println!("{}", 2 * l - 2);
        } else {
            println!("{}", 2 * l - 1);
        }
    }
}


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

#define f first
#define s second
#define pb push_back

using namespace std;

const int maxk = 17 + 1;
const int maxn = 1 * 1e5 + 17;

int A, B;

int main()
{
    cin >> A >> B;
    if (A + B == 15) return !printf("+");
    if (A * B == 15) return !printf("*");
    return !printf("x");
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>

int main()
{
	float R = 0;
	std::cin >> R;

	std::cout.setf(std::ios::fixed, std::ios::floatfield);
	std::cout.precision(16);
	std::cout << 2 * R * M_PI << "\n";

	return 0;
}

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

int main() {
	int N; cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	long long res = A[0] - 1;
	int ma = 1;
	for (int i = 1; i < N; i++) {
		if (A[i] == ma + 1) ma++;
		if (A[i] <= ma) continue;
		res += (A[i]-1) / (ma+1);
	}
	cout << res << endl;
}

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

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

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt();
            String s = in.next();
            if (s.length() != a + b + 1) {
                out.println("No");
                return;
            }
            for (int i = 0; i < a; ++i) {
                if (s.charAt(i) < '0' || s.charAt(i) > '9') {
                    out.println("No");
                    return;
                }
            }

            for (int i = a + 1; i <= a + b; ++i) {
                if (s.charAt(i) < '0' || s.charAt(i) > '9') {
                    out.println("No");
                    return;
                }
            }

            if (s.charAt(a) == '-') {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }
}



Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=3e3+5;
ll inf=1e15;

ll ar[sz][sz],dp[sz][sz][5],n,m,k;

ll f(int i,int j,int cnt)
{
    if(cnt>3)
        return -inf;
    if(i==n and j==m)
        return 0;
    ll &res=dp[i][j][cnt];
    if(res!=-1)
        return res;
    res=-inf;
    if(i<n)
    {
        res=max(res,f(i+1,j,0));
        if(cnt<3)
        res=max(res,f(i+1,j,0)+ar[i][j]);
    }
    if(j<m)
    {
        if(cnt<3)
        res=max(res,f(i,j+1,cnt+1)+ar[i][j]);
        res=max(res,f(i,j+1,cnt));
    }
    return res;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n>>m>>k;
        while(k--)
        {
            ll x,y,val;
            cin>>x>>y>>val;
            x--;
            y--;
            ar[x][y]=val;
        }
        memset(dp,-1,sizeof(dp));
        cout<<f(0,0,0);
    }

    return 0;
}

Measured memory_bytes: 427196
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int i,l_i,r_i,N;
  int sum=0;
  cin>>N;
    for(i=1;i<=N;i++) {
      cin>>l_i>>r_i;
      sum+=(r_i-l_i+1);
      if(i==N){
        cout<<sum<<endl;
      }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin>>x1>>y1>>x2>>y2;
    x3 = x2 + y1 - y2;
    y3 = y2 - x1 + x2;
    x4 = x3 + y2 - y3;
    y4 = y3 - x2 + x3;
    cout << x3 << " " << y3 << " " << x4 << " " << y4;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, c;
		String s;
		int I[], O[];
		int count;
		
		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			c = sc.nextInt();
			s = sc.next();
			I = new int[c];
			O = new int[c];
			
			if (s.charAt(0) == 'I') {
				I[0] = 1;
			}
			for (int i = 1; i < c; i++) {
				if (s.charAt(i) == 'I') {
					I[i] = O[i - 1] + 1;
				} else {
					O[i] = I[i - 1];
				}
			}
			count = 0;
			for (int i = 0; i < c; i++) {
				if (n <= I[i] - 1) {
					count++;
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 38868
# -*- coding: utf-8 -*-

n, m, c = map(int, input().split())
numB = [int(s) for s in input().split()]
codeA = []
for _ in range(n):
    codeA.append([int(t) for t in input().split()])
    
count = 0
for a in codeA:
    total = 0
    for i in range(m):
        total += a[i]*numB[i]
    if total + c > 0:
        count += 1
            
print(count)

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

int main() {
    int n, x, t;
    cin>>n >>x >>t;
    if(n%x==0) cout<<n/x*t<<endl;
    else cout<<(n/x+1)*t<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
int gcd(int, int);

int main(void) {
  int W, H, C;
  cin >> W >> H >> C;
  int a = gcd(W, H);
  cout << ((W/a)*(H/a))*C << endl;
  return 0;
}

int gcd(int a, int b) {
  if (a < b) {
    swap(a,b);
  }
  int mod = a % b, div = b, temp;
  while (mod != 0) {
    temp = mod;
    mod = div % mod;
    div = temp;
  }
  return div;
}




Measured memory_bytes: 3116
#include <bits/stdc++.h>
//#include "lib/bigint2.h"

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ if(a>b) a=b;}


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int h, n, ans =0;
	cin >>h >>n;
	VI a(n);
	ll sm =0;
	rep(i, n){
	 int a; cin >>a;
		sm +=a;
	}
	cout <<(sm >=h? "Yes": "No") <<"\n";
	return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i,N) cin >> A[i];

  vector<ll> cum(N + 1, 0LL);
  REP(i,N) cum[i + 1] = cum[i] + A[i];
  map<ll, ll> mp;
  REP(i, N + 1) ++mp[cum[i]];

  ll ret = 0LL;
  for(auto x: mp) {
    ret += x.second * (x.second - 1) / 2;
  }
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main () {
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<n;i++)cin>>c[i];
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    long long x=0;
    for(int i=0;i<n;i++){
        x+=(lower_bound(a,a+n,b[i])-a)*(n-(upper_bound(c,c+n,b[i])-c));
    }
    cout<<x<<endl;
    return 0 ;
}

 


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

int main()
{
    int n, count1=0, count2=0;
    cin >> n;
    vector<char> a(n);
    vector<int> c(26);
    vector<int> d(26);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < i;j++){
            int tmp = a.at(j) - 97;
            c.at(tmp)++;
            //cout << tmp << " ";
        }
        for (int k = i; k < n; k++)
        {
            int tmp = a.at(k) - 97;
            d.at(tmp)++;
            //cout << k << " ";
        }
        for (int l = 0; l < 26; l++)
        {
            if (c.at(l) >0 && d.at(l)>0){
                count1++;
            }
            //cout << count1 << " ";
        }
        if(count2<count1){
            count2 = count1;
        }
        count1 = 0;
        for (int i = 0; i < 26;i++){
            c.at(i) = 0;
            d.at(i) = 0;
        }
    }
    cout << count2 << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;

int main(){
    int n;  cin >> n;
    vector<ll> s((1 << n));
    multiset<ll> st;
    for(int i = 0; i < (1 << n); i++){
        cin >> s[i];
        st.insert(s[i]);
    }
    vector<ll> taken;
    auto itr = st.end();
    itr--;
    taken.push_back(*itr);
//    cout << *(itr) << endl;
    st.erase(itr);

    while(st.size() > 0){
        vector<ll> new_taken;
        for(auto v: taken){
            auto itr = st.lower_bound(v);
            if(itr == st.begin()){
                cout << "No" << endl;
                return 0;
            }
            itr--;
            new_taken.push_back(*itr);
            st.erase(itr);
        }

        for(auto v: new_taken){
            taken.push_back(v);
        }
        sort(taken.begin(), taken.end());
    }

    cout << "Yes" << endl;


    return 0;
}


Measured memory_bytes: 17460
#include <stdio.h>
#include <iostream>
using namespace std;

class Matrix{
protected:
	int row;
	int col;
public:
	Matrix(int r, int c){ row = r; col = c; }
	int multiply(Matrix *mat);
	int multiply(Matrix *mat1, Matrix *mat3);
};

int Matrix::multiply(Matrix *mat)
{
	return row * col * mat->col;
}

int Matrix::multiply(Matrix *mat1, Matrix *mat3)
{
	return row * mat1->col * mat3->col;
}

class MatrixChain{
private:
	int len;
	Matrix **chain;
	int mult_num[100][100];
public:
	MatrixChain(int s);
	void addMatrix(Matrix *mat);
	int multiply(int i, int j);
};

MatrixChain::MatrixChain(int s)
{
	len = 0;
	chain = new Matrix*[s];
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			mult_num[i][j] = 0;
		}
	}
}

void MatrixChain::addMatrix(Matrix *mat)
{
	chain[len] = mat;
	len++;
}

int MatrixChain::multiply(int i, int j)
{
	if (i >= j) return 0;

	if (mult_num[i][j] != 0) return mult_num[i][j];
	
	if (i + 1 == j) {
		mult_num[i][j] = chain[i]->multiply(chain[j]);
		return mult_num[i][j];
	}

	int mult_min;
	for (int k = i; k + 1 <= j; k++) {
		int temp = multiply(i, k) + multiply(k + 1, j);
		temp += chain[i]->multiply(chain[k], chain[j]);		
		if (k == i) mult_min = temp;
		else mult_min = min(temp, mult_min);
	}
	mult_num[i][j] = mult_min;
	return mult_num[i][j];
}

int main(void)
{
	int n;
	cin >> n;
	MatrixChain matc(n);
	for (int i = 0; i < n; i++) {
		int r, c;
		cin >> r >> c;
		matc.addMatrix(new Matrix(r, c));
	}

	cout << matc.multiply(0, n - 1) << endl;

	return 0;
}

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

int main() {
	int n, k;
	cin >> n >> k;
	int l[n];
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}

	sort(l, l+n);
	int ans = 0;
	for (int i = n-k; i < n; i++) {
		ans += l[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;


int main() {
  int n, m, c;
  cin >> n >> m >> c;
  int b[m+10], a[n+10][m+10];
  int count=0;
  rep(i,m){
    cin >> b[i];
  }
  rep(i,n){
    rep(j,m){
      cin >> a[i][j];
    }
  }
  rep(i,n){
    int ans=0;
    rep(j,m){
      ans+=a[i][j]*b[j];
    }
    ans+=c;
    if(ans>0){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256