akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a[100001],s[100002],ans,L=1;
int main(void){
    cin>>n;
    for(int i=0;i<=n;i++){
        cin>>a[i];
    }
    for(int i=n;i>=0;i--){
        s[i]=s[i+1]+a[i];
    }
    for(int i=0;i<=n;i++){
        ans+=L;
        L-=a[i];
        if(L<0){cout<<"-1"<<endl;return 0;}
        L=min(2*L,s[i+1]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5156
#include <bits/stdc++.h>
#define ff(x,a,b) for(int x=a;x<=b;++x)
#define fff(x,a,b) for(int x=a;x>=b;--x)
using namespace std;
typedef long long ll;
void rd(int &v){char ch;for(ch='*';ch<'0'||ch>'9';ch=getchar());for(v=0;ch>='0'&&ch<='9';ch=getchar()) v=v*10+ch-'0';}
int n,dl[100005],len,a[100005];
int main()
{
	cin>>n;
	ff(i,1,n) rd(a[i]);
	len=1;dl[1]=a[n];
	fff(i,n-1,1)
	{
		int k=upper_bound(dl+1,dl+1+len,a[i])-dl;
		if(k>len) dl[++len]=a[i];
		if(dl[k]>a[i]) dl[k]=a[i];
	}
	cout<<len;
}

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int count = 1;
    for (int i = 1; i < N; i++) {
        if (S[i] != S[i-1]) count ++;
    }

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,m;
	int cou = 0;
	int x;
	cin>>n>>x;
	int l[n];
	int now = 0;
	rep(i, n){
		int pp;cin>>pp;
		if(now <= x){
			cou++;
			
		}else{
			
		}
		now += pp;
	}
	if(now <= x)cou++;
	cout << cou << endl;
	return 0;
}


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


int main(void)
{
	//変数の宣言
	char s[200010];
	char t[200010];
	int tchar[30];
	int len;
	int stemp,ttemp;
	int ans=0;
	int i,j;
	
	//データの読み込み
	scanf("%s\n%s",&s,&t);
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	len=strlen(s);
	
	for(i=0;i<30;i++){
		tchar[i]=-1;
	}
	
	for(i=0;i<len;i++){
		stemp=s[i];
		ttemp=t[i];
		if(tchar[stemp-'a']==-1){
			for(j=0;j<26;j++){
				if(ttemp==tchar[j]){
					ans=-1;
//					printf("%cは他の文字にもうあてられています",ttemp);
				}
			}
			tchar[stemp-'a']=ttemp;
//			printf("%cは%cに変換\n",s[i],t[i]);
		}else{
			if(tchar[stemp-'a']!=ttemp){
				ans=-1;
//				printf("%d文字目が変換不可\n",i+1);
			}
		}
	}
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	if(ans==0){
		printf("Yes");
	}else{
		printf("No");
	}
	
//	printf("結果の出力終了\n");
	
	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define nl cout<<"\n"
#define fr(n) for(int i = 0; i<n; i++)
#define frr(j, n) for(int i = j; i<n; i++)
using namespace std;
typedef long long int lli;
int main(){
    int n;
    cin>>n;
    lli a[n];
    fr(n)cin>>a[i];
    lli sum = 0;
    frr(1,n){
        sum += max(0ll,a[i-1]-a[i]);
        a[i] = max(a[i],a[i-1]);
    }
    cout<<sum;
}

Measured memory_bytes: 5180
#include <iostream>
#include <string>
#include <limits.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
int n, v, l, r;
int m[300010] = {};
string s;
int main()
{
	cin >> n >> s;
	l = 0;
	r = 0;
	rep(i, n) {
		if ('E' == s.at(i)) {
			m[i] = 1;
			if( i != 0)
				++r;
		}
	}
	v = INT_MAX;
	rep(i, n) {
		if (i != 0) {
			if (m[i - 1] == 0) ++l;
			if (m[i] == 1) --r;
		}
		int t = l + r;
		if (v > t)
			v = t;
	}
	cout << v << endl;
	return 0;
}

Measured memory_bytes: 1796
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
#include<map>
#include <cstdio>
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;
map<int, int>pp;

ll ddd(ll n)
{
    return n * (n - 1) / 2;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n;
    while (cin >> n)
    {
        int* p = new int[n + 5]; ll ans = 0;
        for (int i = 0; i < n; i++)
        {
            cin >> p[i]; pp[p[i]]++;
            if (pp[p[i]] >= 2)ans += (pp[p[i]]-1);
        }
        
        for (int i = 0; i < n; i++)
        {
            ll temp = ans;
            temp -= (pp[p[i]] - 1);
            cout << temp << '\n';
        }
        




        pp.clear();
    }

}



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

int main()
{
    string c1, c2;

    cin >> c1;
    cin >> c2;
    
    if (c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

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

#define ll long long
const int maxn = 2e3 + 5;
ll dp[maxn][maxn];

struct Node {
    int seq, val;
}a[maxn];

int cmp(Node a, Node b) {
    return a.val < b.val;
}

int main() {
    int len, n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i].val);
        a[i].seq = i;
    }
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 1; i <= n; ++i) {
        dp[i][i] = (ll)a[1].val * abs(a[1].seq - i);
    }

    int j;
    for (int len = 2; len <= n; ++len) {
        for (int i = 1; i + len - 1 <= n; ++i) {
            j = i + len - 1;
            dp[i][j] = max(dp[i + 1][j] + (ll)a[len].val * abs(a[len].seq - i), dp[i][j - 1] + (ll)a[len].val * abs(a[len].seq - j));
        }
    }
    printf("%lld\n", dp[1][n]);
    return 0;
}

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

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

  int d[N];
  for (int i = 0; i < N; i++) cin >> d[i];

  map<int, int> values;
  for (int i = 0; i < N; i++) {
    values[d[i]] = 1;
  }

  cout << values.size() << endl;
}

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

using namespace std;

const int N = 2e5+7;

int n, res;
int a[N], f[N];

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    f[0] = 1;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        if (f[a[i]-1]) f[a[i]] = 1;
    }
    for (int i = 1; i <= n; ++i) {
        if (f[i]) res = max(res, i);
    }
    cout << (res ? n-res : -1) << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <functional>
#include <array>
#include <cmath>

using namespace std;

int N, a[100]{};

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

	sort(a, end(a), std::greater<decltype(a[0])>());

	int ans = 0;
	for (int i = 0; i < 50; ++i) {
		ans += (a[i * 2] - a[i * 2 + 1]);
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

int field[92][92] = { };
int vx[4] = { 1, -1, 0, 0 };
int vy[4] = { 0, 0, 1, -1 };
int ans=0,ANSW=0;

int dfs(int X, int Y, int n){
	if (field[X][Y]==0)return n;
	field[X][Y] = 0;
	for (int i = 0; i < 4; i++){
		ans = max(ans, dfs(X + vx[i], Y + vy[i], n + 1));
	}
	field[X][Y] = 1;
	return ans;
}

int main(){
	while (1){
		ans = 0, ANSW = 0;
		int l, m;
		scanf("%d%d", &l, &m);
		if (l == 0 && m == 0)return 0;
		for (int i = 0; i < l; i++){
			for (int j = 0; j < m; j++){
				cin>> field[i + 1][j + 1];
			}
		}
		for (int i = 0; i < l; i++){
			for (int j = 0; j < m; j++){
				if (field[i + 1][j + 1])ANSW = max(ANSW, dfs(i + 1, j + 1, 0));
			}
		}
		printf("%d\n", ANSW);
	}
}

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

int main(int argc, char **argv)
{
    int N, M;
    std::cin >> N >> M;
    std::vector<long long> H(N);
    std::vector<int> A(M);
    std::vector<int> B(M);

    std::vector<bool> R(N, true);

    for(int i = 0; i < N; i++){
        std::cin >> H.at(i);
    }
    for(int i = 0; i < M; i++){
        std::cin >> A.at(i) >> B.at(i);
    }
    
    for(int i = 0; i < M; i++){
        long long a = H.at(A.at(i)-1);
        long long b = H.at(B.at(i)-1);
        if(a <= b){
            R.at(A.at(i)-1) = false;
        }
        if(b <= a){
            R.at(B.at(i)-1) = false;
        }
    }

    int sum = 0;
    for(int i = 0; i < N; i++){
        if(R.at(i)) sum++;
    }

    std::cout << sum << std::endl;
    
    
}


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

long long n, ans = 0;

int main()
{
    cin >> n;
    for (int i = 1; 1LL * i * i <= 2 * n; i++)
        if ((n - i) % i == 0)
        {
            long long cur = (n - i) / i;
            if (cur > i)
                ans += cur;
        }
    cout << ans;
}


Measured memory_bytes: 256
map[10][10],d,w=100;X,Y,s;D(x,y){x+=X,y+=Y;x>=0&x<10&y>=0&y<10&&(w-=map[x][y]++==0,d=map[x][y]>d?map[x][y]:d);}main(){for(;~scanf("%d,%d,%d",&X,&Y,&s);D(0,0)+D(1,0)+D(-1,0)+D(0,1)+D(0,-1))s>2&&D(-2,0)+D(2,0)+D(0,-2)+D(0,2),s>1&&D(-1,-1)+D(1,-1)+D(-1,1)+D(1,1);exit(!printf("%d\n%d\n",w,d));}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N], total[N], suffix[N];

int32_t main(){_
   
   cin>>n;

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

   total[0] = 1;
   for (int i = n; i >= 0; --i)
   {
      suffix[i] = suffix[i+1] + a[i];
   }

   int ans = 1;
   for (int i = 1; i <= n; ++i)
   {
      total[i] = min((total[i-1] - a[i-1]) * 2, suffix[i]);
      if (total[i] < a[i]){
         cout<<-1;
         exit(0);
      }
      ans += total[i];
   }

   if (total[0] < a[0]){
      cout<<-1;
      exit(0);
   }
      
   cout<<ans;

   return 0;
}

Measured memory_bytes: 5960
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int x = sc.nextInt();
		int min = 100000;
		int sum = 0;

		for (int i = 0; i < n; i++) {
			int m = sc.nextInt();
			sum += m;
			if (m < min) {
				min = m;
			}
		}

		System.out.println(n + (x - sum) / min);

		sc.close();
	}
}


Measured memory_bytes: 23380
/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
int main()
{
	int ah,as,bh,bs;
	cin>>ah>>as>>bh>>bs;
	for (int i=1;i<=1000000;i++)
	{
		if (i%2==1)  bh-=as;
		else ah-=bs;
		if (ah<=0){
			cout<<"No"<<endl;return 0;
		}
		if (bh<=0){
			cout<<"Yes"<<endl;return 0;
		}
	}
}


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

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>


int n, m, q;
V a(q), b(q), c(q), d(q);
V A(n+1);
ll func(int pos);

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    cin >> n >> m >> q;
    a.resize(q); b.resize(q); c.resize(q); d.resize(q); A.resize(n+1);
 
    REP(i, q)    cin >> a[i] >> b[i] >> c[i] >> d[i];
    
    fill(ALL(A), 0);  A[0] = 1;
    
    cout << func(1) << endl;
	return 0;
}

ll func(int pos){

  if(pos == n+1){
    ll res = 0;
    for(int i = 0 ; i < q ; i++)
      if(A[b[i]] - A[a[i]] == c[i])  res += d[i];

    return res;
  }

  ll res = -1;
  for(int i = A[pos-1] ; i <= m ; i++){
    A[pos] = i;
    res = max(res, func(pos+1));
  }
  return res;
}


Measured memory_bytes: 3660
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, M;
  while (cin >> N >> M) {
    int res = N * (N - 1) / 2 + M * (M - 1) / 2; 
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 764
s=input()
ce=co=0
for i in range(len(s)):
    if i%2==0 and s[i]=='0':
        ce+=1 
    elif i%2==1 and s[i]=='1':
        ce+=1 
for i in range(len(s)):
    if i%2==1 and s[i]=='0':
        co+=1 
    elif i%2==0 and s[i]=='1':
        co+=1
if ce<co:
    print(ce)
else:
    print(co)

Measured memory_bytes: 3188
from collections import deque


x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p = sorted(p)
q = sorted(q)
baseline = p[-x:] + q[-y:]

r = deque(sorted(r))
baseline = deque(sorted(baseline))

while len(r) != 0:
    v = r.pop()
    if v > baseline[0]:
        baseline.popleft()
        baseline.append(v)
    else:
        break

print(sum(baseline))


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

using namespace std;

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> vec(102, 0);
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    vec[tmp] = 1;
  }

  int ans = 0;
  int vmin = x;
  for (int i = 1; i <= 101; ++i) {
    if (vec[i] != 0 || vmin <= abs(x-i))
      continue;
    ans = i;
    vmin = abs(x - i);
  }

  cout << ans << endl;
}

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

int main(){
  int N; cin >> N;
  vector<int> h(N,0); for(int i = 0; i < N; i++) cin >> h.at(i);
  
  int ans = h.at(0);
  for(int i = 0; i < N - 1; i++){
    if(h.at(i+1) > h.at(i)) ans += h.at(i+1) - h.at(i);
  }
  cout << ans << endl;
}



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

int main(){
  string A,B,C;
  cin >> A >> B >> C;
  
  if((A.back()==B.front())&&(B.back()==C.front())){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }

}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 21;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 62;

ll n;
ll a[e5];

int main(){
  cin >> n;
  for(ll i = 0;i < n;i++) cin >> a[i];
  for(ll i = 0;i < n;i++){
    if(a[i]%2 == 1){
      cout << "first" << endl;
      return 0;
    }
  }
  cout << "second" << endl;
}


Measured memory_bytes: 1024
var soroban=[
"* = ****".split(""),
"* =* ***".split(""),
"* =** **".split(""),
"* =*** *".split(""),
"* =**** ".split(""),
" *= ****".split(""),
" *=* ***".split(""),
" *=** **".split(""),
" *=*** *".split(""),
" *=**** ".split("")
];
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.replace(/\n$/,"")).split("\n").map(Number);
Arr.forEach(function(v,i){
   if(i!==0)console.log("");
   var str=("00000"+v).slice(-5);
   var arr=["","","","","","","",""];
   for(var i=0;i<5;i++){
      var s=soroban[(str[i]-0)];
      s.forEach(function(v,index){arr[index]+=v;});
   }
   console.log(arr.join("\n"));
});

Measured memory_bytes: 10620
import math
dishes = [int(input()) for _ in range(5)]
lead_times = [int(math.ceil(t/10))*10 - t for t in dishes]
max_idx = lead_times.index(max(lead_times))
result = 0
for i in range(5):
  result += dishes[i]
  if i != max_idx:
    result += lead_times[i]
print(result)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i, n) cin >> a[i+1];
    int now = 1;
    rep(i, 100010)
    {
        now = a[now];
        if(now==2){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

bool Prime(ll a){
  if(a == 1 || a ==  0){
    return false;
  }
  for(int i = 2;i <= pow(a,0.5);i++){
    if(a % i == 0){
      return false;
    }
  }
  return true;
}

int main(){
  int N;cin >> N;
  vector<ll> P;
  for(int i = 2;i <= 55555;i++){
    if(Prime(i) && i % 5 == 1){
      P.push_back(i);
    }
  }
  for(int i = 0;i < N;i++){
    cout << P[i] << ' ';
  }
  cout << endl;
}


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

#define int long long
#define INF ((int)(1e17))
#define EPS 1e6

signed main(){
  cout<<fixed<<setprecision(6);
  int N;
  int sum = 0;
  vector<int> t, v, maxs, maxs2;

  int  V = 0, bV = 0;
  double ans = 0;
  cin>>N;

  t.resize(N+10,0);
  v.resize(N+10,0);
  maxs.resize(N*210,0);
  
  maxs2.resize(N*210,0);
  
  for(int i = 0; i < N; i++){
    cin>>t[i];
  }
  for(int i = 0; i < N; i++){
    cin>>v[i];
    for(int j = 0; j < t[i]; j++){
      maxs[sum+j] = v[i];
    }
    for(int j = 1; j <= t[i]; j++){
      maxs2[sum+j] = v[i];
    }
    sum += t[i];
  }

  for(int i = sum+1; i >= 1; i--){
    maxs[i-1] = min(maxs[i-1], maxs[i]+1);
    
  }

  for(int i = 0, j = 0; i <= sum; i++){
    //cout<<i<<" "<<V<<" "<<maxs[i]<<" "<<maxs2[i]<<endl;
    if(maxs[i] == maxs[i+1]){
      if(V < maxs[i]){
	ans += V+0.5;
	V++;
      } else if(V == maxs[i]){
	ans += V;
	
      }
    } else if(maxs[i] < maxs[i+1]){
      if(maxs2[i+1] >= V+1){
	ans += V + 0.5;
	V++;
      } else {
	ans += V;
      }
    } else if(maxs[i] > maxs[i+1]){
      if(V == maxs[i+1]){
	ans += V + 0.25;
	
      } else if(V == maxs[i]){
	ans += V - 0.5;
	V--;
      } else  if(maxs[i+1] >= V+1){
	ans += V+ 0.5;
	V++;
      } 
    }
  }

  cout<<ans<<endl;
  
}


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

int main() {
  double N, A;
  cin >> N >> A;
  if( N < 1 ){ 
  	cout << "error: N under 1" << endl;
    return 1;
  }
  else if( N > 100 ){ 
  	cout << "error: N over 100" << endl;
    return 1;
  }
  if( A < 0 ){
  	cout << "error: A under 0" << endl;
    return 1;
  }
  else if( A > N*N){
  	cout << "error: A over N * N" << endl;
    return 1;
  }
  cout << (N*N) - A << endl;
}

Measured memory_bytes: 256
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let solve n q =
  let s = Array.init n (fun i -> i) in
  let rec find u =
    if u = s.(u) then u
    else begin
      s.(u) <- find s.(u);
      s.(u)
    end in
  let rec doit i =
    if i < q then begin
      begin match List.map int_of_string (split_on_char ' ' (read_line ())) with
      | 0 :: x :: y :: _ -> s.(find x) <- find y
      | 1 :: x :: y :: _ -> print_endline (if find x = find y then "1" else "0")
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split_on_char ' ' (read_line ())) with
  | [n; q] -> solve n q
  | _ -> ()

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

using namespace std;


int main(){
    int64_t n, x, m;
    cin >> n >> x >> m;
    int64_t S = 0;
    int64_t y = x;
    int cnt = 0;
    vector<bool> used(m + 1);
    int64_t s;
    while (true){
        if (used[y]){
            s = y;
            break;
        }
        used[y] = true;
        y = (y * y) % m;
    }

    y = s;
    while (true){
        S += y;
        y = (y * y) % m;
        cnt++;
        if (y == s)
            break;
    }

    int64_t ans = 0;
    y = x;
    while (true){
        ans += y;
        y = (y * y) % m;
        n--;
        if (y == s)
            break;
    }
    
    ans += n / cnt * S;
    y = s;
    for (int64_t i = n / cnt * cnt; i < n; i++){
        ans += y;
        y = (y * y) % m;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(long long*)a > *(long long*)b){
        return -1;
    }else if (*(long long*)a == *(long long*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

/*
int struct_ascending_compare(const void *p, const void *q) {
return ((struct_name*)p)->member_name - ((struct_name*)q)->member_name;
}*/

/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]);
        }
    }
}*/
int head[1005];
int next[2005];
int to[2005];
int weight[2005];
long long v[1005] = {0};
int vb[1005] = {0};
int n, m;
int vton[1005] = {0};
int first_to_v[1005] = {0};
int closed[1005] = {0};
int start;

int dfs(int crt){
    int edge = head[crt];
    while (edge != -1){
        if (vb[to[edge]] != 1 && v[to[edge]] < v[crt] + weight[edge]){
            v[to[edge]] = v[crt] + weight[edge];
            vb[to[edge]] = 1;
            dfs(to[edge]);
        }
        edge = next[edge];
    }
    vb[crt] = 0;
    return 0;
}


int check_closed(int crt){
    int edge = head[crt];
    while (edge != -1){
        if ((to[edge] == start || vb[to[edge]] != 1) && v[to[edge]] < v[crt] + weight[edge]){
            v[to[edge]] = v[crt] + weight[edge];
            vb[to[edge]]++;
            check_closed(to[edge]);
        }
        edge = next[edge];  
    }
    vb[crt]--;
    return 0;
}


int main(void){
    int input[3];
    int total = 0;
    for (int i = 0; i < 3; i++){
        scanf("%d", &input[i]);
        total += input[i];
    }
    for (int i = 0; i < 3; i++){
        if (total%2 == 0 && input[i] == total/2){
            printf("Yes\n");
            return 0;
        }
    }

    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

def Lgcd(i):
    if i == 0:
        return 0
    if i == 1:
        return a_s[0]
    if i in Lmemo:
        return Lmemo[i]
    re = gcd(Lgcd(i - 1), a_s[i - 1])
    Lmemo[i] = re
    return re


def Rgcd(i):
    if i == n - 1:
        return 0
    if i == n - 2:
        return a_s[-1]
    if i in Rmemo:
        return Rmemo[i]
    re = gcd(Rgcd(i + 1), a_s[i + 1])
    Rmemo[i] = re
    return re


def gcd(a, b):
    if a * b == 0:
        return a + b
    while 1:
        a, b = b, a % b
        if b == 0:
            return a


Lmemo = {}
Rmemo = {}
n = int(input())
a_s = list(map(int, input().split()))
mx = 0
for i in range(n):
    g = gcd(Lgcd(i),Rgcd(i))
    if g > mx:
        mx = g
print(mx)


Measured memory_bytes: 111964
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
accumuration = [A[0]]
for i in range(1,N):
	accumuration.append(accumuration[i-1]+A[i])
for i in range(N):
	if accumuration[N-i-2]*2 < A[N-1-i]:
		print(i+1)
		exit()
print(N)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		
		ll n,k;
			cin>>n>>k;

			vector<ll> a(n);
			for(ll& x:a) {
				cin>>x;
			}

			vector<bool> dp(k+1);

			for(ll stones = 0; stones<=k; stones++) {
				for(ll x:a) {
					if(stones>=x && !dp[stones-x]) {
						dp[stones] = true;
					}
				}
			}

			if(dp[k]) {
				cout<<"First"<<endl;
			}
			else {
				cout<<"Second"<<endl;
			}		

		return 0;
	}


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

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



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

    int T=1;
    //cin >> T;
    while(T--){
        int n,m;
        cin>>n>>m;
        cout<<(n*n-n+m*m-m)/2<<el;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

dp = [dict() for _ in range(n)]

dp[0][0] = 0
dp[0][1] = a[0]
dp[1][0] = 0
dp[1][1] = max(a[0], a[1])

import math
for i in range(2, n):
    k1 = int(math.ceil((i + 1) / 2))
    k2 = k1 - 1

    if i % 2 == 0:
        dp[i][k1] = dp[i-2][k1-1] + a[i]
    else:
        dp[i][k1] = max(dp[i-1][k1], dp[i-2][k1-1] + a[i])

    dp[i][k2] = max(dp[i-1][k2], dp[i-2][k2-1] + a[i])

print(dp[-1][n // 2])


Measured memory_bytes: 139968
(defun solve (l r &optional (result 0))
  (if (null l)
      result
      (progn
        (when (not (eql (car l) (car r)))
          (incf result))
        (solve (cdr l) (cdr r) result))))

(princ (solve (coerce (read-line) 'list) (coerce (read-line) 'list)))

Measured memory_bytes: 35708
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++) cin >> v[i];
    vector<int> tmp(v.begin(), v.end());
    sort(v.begin(), v.end());
    int ml = v[N / 2 - 1], mr = v[N / 2];
    for (int i = 0; i < N; i++) {
        if (tmp[i] <= ml) cout << mr << '\n';
        else cout << ml << '\n';
    }
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    string S;
    cin >> S;
    int N = S.size();
    S = '0' + S;
    if(N == 1){
        cout << 1 << endl;
        return 0;
    }else if(N == 2){
        cout << (S[0] == S[1] ? 1:2) << endl;
        return 0;
    }
    //vectorの初期化
    //vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));
    vector<vector<int>> dp(N+2, vector<int>(3, -1));
    dp[N][1] = 1;
    dp[N-1][2] = 1;
    for(int i=N;i>=1;i--){
        if(i+1<=N && S[i] != S[i+1]) dp[i][1] = max(dp[i][1], dp[i+1][1]+1);
        if(i+2<=N){
            dp[i][1] = max(dp[i][1], dp[i+1][2]+1);
            dp[i][2] = max(dp[i][2], dp[i+2][1]+1);
        }
        if(i+3<=N && S.substr(i, 2) != S.substr(i+2, 2))
            dp[i][2] = max(dp[i][2], dp[i+2][2]+1);
    }
    cout << max(dp[1][1], dp[1][2]) << endl;
}

Measured memory_bytes: 11328
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>

using namespace std;

// #define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

int N, M;
vector<vector<int>> G;
vector<int> con, used;
map<pair<int,int>,int> mp;

void solve(int node = 1, int per = -1){
	if(used[node]) return ;
	used[node] = true;
	// cout<<node<<endl;
	for(int y : G[node]){
		if(y == per) continue;
		if(used[y]){
			if(!mp[make_pair(node,y)]){
				con[node]++;
				cout<<node<<" "<<y<<endl;
				mp[make_pair(node,y)] = true;
				mp[make_pair(y,node)] = true;
			}
			
		} else {
			solve(y , node);
		}
	}
	
	if(per == -1) return;
	
	if(con[node]%2){
		cout<<node<<" "<<per<<endl;
		con[node]++;
	} else {
		cout<<per<<" "<<node<<endl;
		con[per]++;
	}
}
signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	
	int a, b;

	cin>>N>>M;
	
	G.resize(N+10);
	con.resize(N+10);
	used.resize(N+10);
	
	for(int i = 0; i < M; i++){
		cin>>a>>b;
		
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	if(M%2){
		cout<<-1<<endl;
		return 0;
	}
	
	solve();
	
	
	return 0;
}

Measured memory_bytes: 21760
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
  int n, k; cin>>n>>k;
  string s; cin>>s;
  char c=*min_element(s.begin(), s.end());
  if(k>=14){
    string ans;
    for(int i=0; i<n; i++) ans+=c;
    cout<<ans<<endl;
    return 0;
  }
  vector<string> v;
  for(int i=0; i<n; ){
    if(s[i]!=c){
      i++; continue;
    }
    string t;
    int r=i;
    for(; r<n; r++){
      if(s[r]!=c) break;
    }
    if(r==n){
      if((1<<k)*(r-i)>=n){
        string ans;
        for(int j=0; j<n; j++) ans+=c;
        cout<<ans<<endl;
        return 0;
      }
      int l=(1<<k)*(r-i);
      for(int j=0; j<l; j++) t+=c;
      int p=i-1;
      for(int j=0; j<n-l; j++){
        t+=s[p];
        p--;
      }
      v.push_back(t);
      break;
    }
    if((1<<(k-1))*(r-i)>=n){
      string ans;
      for(int j=0; j<n; j++) ans+=c;
      cout<<ans<<endl;
      return 0;
    }
    int l=(1<<(k-1))*(r-i);
    for(int j=0; j<l; j++) t+=c;
    bool nuo=0;
    int p=r;
    for(int j=0; j<n-l; j++){
      if(p==n){
        nuo=1;
        p--;
      }
      t+=s[p];
      if(nuo) p--;
      else p++;
    }
    v.push_back(t);
    i=r;
  }
  cout<<*min_element(v.begin(), v.end())<<endl;
	return 0;
}

Measured memory_bytes: 11904
#include <cstdio>

const int N=41;
int a[N],mx=-1,t;
long long n;

int main(){
	scanf("%lld",&n);
	for(int i=40;~i;--i)
		if((n>>i)&1)
			if(~mx)a[i]=mx+(++t);
			else mx=i;
	printf("%d\n",mx+mx+2+t+t);
	if(a[0])printf("%d ",a[0]);
	for(int i=1;i<=mx;++i){
		printf("%d ",i);
		if(a[i])printf("%d ",a[i]);
	}
	for(int i=1;i<=mx+t;++i)printf("%d ",i);
	printf("%d %d\n",mx+t+1,mx+t+1);
}

Measured memory_bytes: 256
def CountingSort(A, B, k):
    C = [0] * (k + 1)

    for j in range(n):
        C[A[j]] += 1

    for i in range(1, k + 1):
        C[i] += C[i - 1]

    for j in range(n - 1, -1, -1):
        B[C[A[j]] - 1] = A[j]
        C[A[j]] -= 1

n = int(input())
A = [int(a) for a in input().split()]
B = [0] * n

CountingSort(A, B, 10000)

print(*B)

Measured memory_bytes: 234260
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

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

  bool a = s[0] == 'R';
  bool b = s[1] == 'R';
  bool c = s[2] == 'R';

  if(a & b & c) cout << "3" << endl;
  else if(a&b | b&c) cout << "2" << endl;
  else if(a | b | c) cout << "1" << endl;
  else cout << "0" << endl;
  
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

int main()
{
    using namespace std;
    
    int d,t,s;
    cin >> d >> t >> s;
    
    auto solver = [&](){
        return (d <= t * s)? "Yes" : "No";
    };
    
    cout << solver() << endl;

    return 0;
}


Measured memory_bytes: 3512
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }

using namespace std;

void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }

}

int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    REP(i, 2, sqrt(N-1)+1) {
        if ((N-1) % i == 0) {
            ans+=1;
            if (i != sqrt(N-1)) {
                ans++;
            }
        }
    }
    REP(i, 2, sqrt(N)+1) {
        if (N % i == 0) {
            ll tmp = N;
            ll d = i;
            while(tmp % d == 0) {
                tmp /= d;
                d *= d;
            }
            while(tmp % i == 0) {
                tmp /= i;
            }
            if (tmp % i == 1) {
                ans++;
            }
        }
    }


//    cout << ans + 2 << endl;
    if (N == 2) {
        cout << 1 << endl;
    } else {
        cout << ans + 2 << endl;
    }


}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string s,t; cin >> s >> t;
  reverse(t.begin(),t.end());

  if(s==t) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<cmath>

using namespace std;

int main() {
  long long X;
  cin >> X;
  int a = 0;
  double b = 0;
  while(true) {
    b = pow(abs(X-(long long)pow(a,5.)),0.2);
    if(abs(b-floor(b))<0.000000001){
      if(pow(a,5)-pow(floor(b),5)==X || pow(a,5)+pow(floor(b),5)==X)
        break;
    }
    a++;
  }

  if(pow(a,5)-pow(floor(b),5)==X)
    cout << a << " " << floor(b) << endl;
  else
    cout << a << " -" << floor(b) << endl;
}


Measured memory_bytes: 4192
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	line := nextLine()
	words := strings.Split(line, " ")
	res := ""
	for _, word := range words {
		res += string(word[0])
	}
	fmt.Println(strings.ToUpper(res))
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MOD 1e9+7
#define MAX_V 305

typedef pair<int, int> P;

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

    ll idx = 1, kosu = 1;
    ll tmp = 0, kaisu = 0;
    while(1) {
        tmp += kosu;
        if(tmp >= h) break;
        kosu*=2, idx++;
    }

    ll ans = 1;
    REP(i, idx-1) {
        ans = 2*ans+1;
    }

    cout << ans << endl;

    return 0;
}

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

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

 ll sum=0;

  for(int i=0;i<n;i++){
    auto itra=lower_bound(ALL(a),b[i]);
    ll ai=itra-a.begin();//b[i]より小さく、aのなかで一番大きい数のindex+1
    auto itrc=upper_bound(ALL(c),b[i]);
    ll ci=itrc-c.begin();//b[i]より大きく、Cのなかで一番小さい数のindex
    ll cii=n-ci;
    sum+=ai*cii;
  }

 cout << sum << endl;
}


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

int VtoI(const vector<int>& v) {
  int num = 0;
  for (auto i : v) {
    num *= 10;
    num += i;
  }
  return num;
}

void ItoV(int num, int n, vector<int>& v) {
  v = vector<int> (n);
  int i = n - 1;
  while(i >= 0) {
    v[i] = num % 10;
    num /= 10;
    i--;
  }
}

int next(int i, int n) {
  vector<int> v;
  ItoV(i, n, v);
  sort(v.begin(), v.end());
  auto min = VtoI(v);
  reverse(v.begin(), v.end());
  auto max = VtoI(v);
  return max - min;
}

void solve(int a,int n) {
  map<int, int> mp;
  int i = 0;
  while(true) {
    if (mp.find(a) != mp.end()) {
      break;
    }
    
    mp[a] = i;
    a = next(a, n);
    i++;
  }

  cout << mp[a] << " " << a << " " << i - mp[a] << endl;
  return;
}

int main() {
  int a, n;
  while(cin >> a >> n, a | n) {
    solve(a, n);
  }

  return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define sec second
#define fir first
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}

int main(){
	ll n,d;cin>>n>>d;
	ll ans = 0;
	rep(i,0,n){
		ll u,v;
		cin>>u>>v;
		if(u*u + v*v<=d*d) ans++;
	}
	cout<<ans;

}
		 

Measured memory_bytes: 3600
def nxt(arr)
	arr.each do |val|
		unless $grp[val]
			return val
		end
	end
	return nil
end

def dfs_src(s,id)
	stk = [s]
	$grp[s] = id
	while stk != []
		u = nxt($l[stk.last])
		if u
			stk.push(u)
			$grp[u] = id
		else
			stk.pop
		end
	end
end
$grp = []

result = []
$l=[]
n, m = gets.chomp.split(" ").map(&:to_i)
m.times do
	s,t = gets.chomp.split(" ").map(&:to_i)
	if $l[s]
		$l[s].push(t)
	else
		$l[s] = [t]
	end
	if $l[t]
		$l[t].push(s)
	else
		$l[t] = [s]
	end
end
q = gets.chomp.to_i

list = []
i = 0
while i <= n
	unless $grp[i]
		if $l[i]
			dfs_src(i, i)
		end
	end
	i += 1
end

q.times do
	res = "no"
	s, t = gets.chomp.split.map(&:to_i)
	if $grp[s] == $grp[t] && $grp[s] != nil
		result.push("yes")
	else
		result.push("no")
	end
end

result.each do |r|
	puts r
end


Measured memory_bytes: 16472
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const ll mod = 1e9 + 7;

int main() {
    ll dp[13] = { 1 };
    string S;
    cin >> S;

    for(char c : S) {
        ll cdp[13] = {};
        for(ll i = 0; i < 10; i++) {
            if(!(c == '?' || (c - '0') == i)) continue;
            for(ll j = 0; j < 13; j++) (cdp[(j * 10 + i) % 13] += dp[j]) %= mod;
        }
        for(ll i = 0; i < 13; i++) dp[i] = cdp[i];
    }
    cout << dp[5] << endl;
    return 0;
}


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

const int M = 1000005;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end());

  vector<int> cnt(M);
  for (int x : A) {
    if (cnt[x] != 0) {
      cnt[x]++;
      continue;
    }

    for (int i = x; i < M; i += x) {
      cnt[i]++;
    }
  }

  int ans = 0;
  for (int x : A) {
    if (cnt[x] == 1) {
      ans++;
    }
  }

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


Measured memory_bytes: 8016
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
   int n;
   cin>>n;
   vector<int>a(n);

   for(int i=0;i<n;i++){
       cin>>a[i];
   }
   sort(a.begin(),a.end());
   int count=1;
   for(int i=1;i<n;i++){
       if(a[i]!= a[i-1]){
           count++;
       }
   }
   cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,q,a,t,x;
	cin >> n >> q;
	stack<int> st[n+1];
	for(int i=0;i<q;i++){
		cin >> a;
		if(a==0){
			cin >> t >> x;
			st[t].push(x);
		}else if(a==1){
			cin >> t;
			if(!st[t].empty()){
				cout << st[t].top() << endl;
			}
		}else{
			cin >> t;
			if(!st[t].empty()){
				st[t].pop();
			}
		}
	}

}


Measured memory_bytes: 4364
#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 1e6+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
int n;
string s;
vector<pii_> Pa,Pb;
int main()
{
    fastio();
    cin>>n;
    rep(i,1,n){
        cin>>s;
        int l=0,r=0;
        for(auto x:s){
            if(x=='(') l++;
            else{
                if(l) l--;
                else r++;
            }
        }
        if(l<=r) Pa.pb(mp_(l,r));
        else Pb.pb(mp_(l,r));
    }
    sort(Pa.begin(),Pa.end());
    sort(Pb.begin(),Pb.end(),[](pii_ a,pii_ b){return a.se>b.se;});
    int sum = 0;
    int flag = 1;
    int sza = Pa.size(),szb=Pb.size();
    rep(i,0,sza-1){
        sum -= Pa[i].fi;
        if(sum<0) flag=0;
        sum += Pa[i].se;
    }
    rep(i,0,szb-1){
        sum -= Pb[i].fi;
        if(sum<0) flag=0;
        sum += Pb[i].se;
    }
    if(sum) flag=0;
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 11192
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  n--;
  ll b[n];
  rep(i,n) R b[i];
  ll ans=0;
  rep(i,n-1) ans+=min(b[i],b[i+1]);
  pr(ans+b[0]+b[n-1]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

N,M,L=map(int,input().split())
d=[[0 for i in range(0,N)] for i in range(0,N)]
for i in range(0,M):
    a,b,c=map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c

csr1=csr_matrix(d)

a=floyd_warshall(csr1)

d=[[0 for i in range(0,N)] for j in range(0,N)]
for i in range(0,N):
    for j in range(0,N):
        if L>=a[i][j]:
            d[i][j]=1


csr2=csr_matrix(d)

data=floyd_warshall(csr2)
ans=[]
Q=int(input())
for i in range(0,Q):
    s,t=map(int,input().split())
    if data[s-1][t-1]!=float('inf'):
        ans.append(int(data[s-1][t-1])-1)
    else:
        ans.append(-1)

for i in range(Q):
    print(ans[i])

Measured memory_bytes: 20880