akhauriyash/Code-Regression huggingface dataset:
def lscan; gets.split.map(&:to_i); end

@hh = {}

def solvex(n, d, c)
  (c+@d*(n%d) < @d*(n-n/d)) ?
    solve(n/d)+c+@d*(n%d) :
    solve(n/d)+@d*(n-n/d)
end

def solvey(n, d, c)
  (@d*(d-n%d) > 4e18) ? 4e18 :
    solve((n+d)/d)+c+@d*(d-n%d)
end

def solve(n)
  return 0 if n == 0
  return @d if n == 1
  return @hh[n] if @hh.has_key?(n)
  return @hh[n] = [
    solvex(n, 2, @a),
    solvex(n, 3, @b),
    solvex(n, 5, @c),
    n >= 3 ? solvey(n, 2, @a) : 4e18,
    solvey(n, 3, @b),
    solvey(n, 5, @c),
  ].min
end

gets.to_i.times do
  @hh.clear
  n,@a,@b,@c,@d = lscan
  
  p solve(n)
  
end

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define ui64 unsigned long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define mod 998244353LL

#define maxn 1000005
#define log 20

i64 a[maxn] ;
i64 mn[maxn] , mx[maxn] ;

int main()
{
    int n ;

    scanf("%d",&n) ;

    for(int i=0 ; i<=n ; i++) scanf("%lld",&a[i]) ;

    mn[n] = a[n] ; mx[n] = a[n] ;

    for(int i =n-1 ; i>=0 ; i--)
    {
        mn[i] = (mn[i+1]+1)/2 ;
        mx[i] = mx[i+1] ;
        mn[i] += a[i] ; mx[i] += a[i] ;
    }

    if( mn[0] > 1 )
    {
        printf("-1\n") ;
        return 0 ;
    }

    i64 ans = 1 ;

    i64 last = 1 ;

    for(int i=1 ; i<=n ; i++)
    {
        i64 cur = min( last*2 , mx[i] ) ;
        ans += cur ;
        last = cur - a[i] ;
    }

    printf("%lld\n",ans) ;

    return 0 ;
}


Measured memory_bytes: 6104
n = gets.to_i

if 400<=n&&n<600 
puts 8 
end
if 600<=n&&n<800
puts 7 
end
if 800<=n&&n<1000 
puts 6
end 
if 1000<=n&&n<1200 
puts 5 
end
if 1200<=n&&n<1400 
puts 4 
end
if 1400<=n&&n<1600
puts 3 
end
if 1600<=n&&n<1800
puts 2
end 
if 1800<=n
puts 1 
end


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

sa = set(a)
sb = set(b)

count = [0] * (n + 1)
counta = [0] * (n + 1)
countb = [0] * (n + 1)

for v in a:
    count[v] += 1
    counta[v] += 1
for v in b:
    count[v] += 1
    countb[v] += 1

for v in count:
    if v > n:
        print('No')
        exit()

outA = dict()
for v in a:
    outA[v] = []

import heapq
q = []
for v in range(n + 1):
    if count[v]:
        heapq.heappush(q,(-count[v],v))
    
while q[0][0] < 0:
    c, v = heapq.heappop(q)
    if count[v] + c:
        heapq.heappush(q,(-count[v],v))
        continue
    if counta[v]:
        for v2 in sb:
            if v2 != v:
                break
        else:
            print('No')
            exit()
        outA[v].append(v2)
        count[v] -= 1
        count[v2] -= 1
        counta[v] -= 1
        countb[v2] -= 1
        if counta[v] == 0:
            sa.remove(v)
        if countb[v2] == 0:
            sb.remove(v2)
    else:
        for v2 in sa:
            if v2 != v:
                break
        else:
            print('No')
            exit()
        outA[v2].append(v)
        count[v] -= 1
        count[v2] -= 1
        counta[v2] -= 1
        countb[v] -= 1
        if counta[v2] == 0:
            sa.remove(v2)
        if countb[v] == 0:
            sb.remove(v)
    if count[v]:
        heapq.heappush(q, (-count[v], v))

out = []
for v in a:
    out.append(outA[v].pop())
print('Yes')
print(' '.join(map(str,out)))


Measured memory_bytes: 181128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    double l; cin>>l;
    cout<<fixed<<setprecision(10)<<(l/3)*(l/3)*(l/3)<<endl;
    return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


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

    sort(ALL(v));
    for(int i = 0; i < n - 1; i++){
        double t = (v[i] + v[i + 1]) / 2;
        v[i + 1] = t;
    }
    cout << v[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 3820
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

public class AtCoderE
{
    static void Main()
    {
        int h;
        int w;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            h = int.Parse(words[0]);
            w = int.Parse(words[1]);
        }

        bool[,] map = new bool[h, w];

        for (int i = 0; i < h; i++)
        {
            var line = Console.ReadLine();
            for (int j = 0; j < w; j++)
            {
                map[i, j] = ".".Equals(line.Substring(j, 1));
            }
        }

        int[,] l = new int[h, w];
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (map[i, j])
                {
                    if (j == 0)
                    {
                        l[i, j] = 1;
                    }
                    else
                    {
                        l[i, j] = l[i, j - 1] + 1;
                    }
                }
            }
        }

        int[,] r = new int[h, w];
        for (int i = 0; i < h; i++)
        {
            for (int j = w - 1; j >= 0; j--)
            {
                if (map[i, j])
                {
                    if (j == w - 1)
                    {
                        r[i, j] = 1;
                    }
                    else
                    {
                        r[i, j] = r[i, j + 1] + 1;
                    }
                }
            }
        }

        int[,] u = new int[h, w];
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (map[i, j])
                {
                    if (i == 0)
                    {
                        u[i, j] = 1;
                    }
                    else
                    {
                        u[i, j] = u[i - 1, j] + 1;
                    }
                }
            }
        }

        int[,] d = new int[h, w];
        for (int i = h - 1; i >= 0; i--)
        {
            for (int j = 0; j < w; j++)
            {
                if (map[i, j])
                {
                    if (i == h - 1)
                    {
                        d[i, j] = 1;
                    }
                    else
                    {
                        d[i, j] = d[i + 1, j] + 1;
                    }
                }
            }
        }

        int answer = 0;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                answer = Math.Max(answer, l[i, j] + r[i, j] + u[i, j] + d[i, j] - 3);
            }
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 81636
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
ans = 0

if n%2 == 0:
    ans = 2*(sum(a[n//2:])-sum(a[:n//2]))+a[n//2-1]-a[n//2]
else:
    ans = 2*(sum(a[n//2+1:])-sum(a[:n//2]))
    ans -= min(a[n//2+1]-a[n//2], a[n//2]-a[n//2-1])
print(ans)


Measured memory_bytes: 13380
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//nが大

ll com(ll n,ll m){
	if(n<=0 || m<=0 || n==m){
		return 1;
	}
	if(n<m){
		return 0;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}

////////////////////////////////////////////////////////////////////

int main(){
ll n,k;
cin>>n>>k;

ll hi[n];
for(int i=0;i<=n-1;i++){
	cin>>hi[i];
}

sort(hi,hi+n);

ll ans=1000000005;
for(int i=0;i<=n-k;i++){
ans=min(ans, hi[i+k-1]-hi[i]);

}

cout<<ans<<endl;
return 0;


}





Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

char s[100];
char t[100]="AKIHABARA";

int main()
{
	scanf("%s", s);
	int j=0;
	for(int i=0; s[i]; ++i){
		if(s[i] != t[j] && t[j] == 'A') ++j;
		if(s[i] != t[j]){
			puts("NO"); return 0;
		}
		++j;
	}
	++j;
	if(!t[j]) puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int A,B,C;
    cin >> A >> B >> C ;
    int s = 0;
    int i = 1;
    while(s < C){
        s += A;
        if(i % 7 == 0){
            s += B;

        }
        i ++;
    }
    cout << i - 1 <<endl;
    return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){

  long X,N,A,B,t,s,ans;
  bool can;
  can=false;
  //  string S,A;
  
  cin>>X;
  
  t=(X/500);
  s=X-t*500;
  ans=t*1000+(s/5)*5;
  
  cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
fun main() {
  val n = readLine()!!.toInt()
  val d = 2 * n
  var l = 1
  var r = n + 1
  val a = IntArray(n)
  for (i in 0 until n) {
    a[i] = 1 + i
  }
  println("? " + a.joinToString(" "))
  System.out.flush()
  val f = readLine()!!
  while (r - l > 1) {
    val m = (l + r) / 2
    for (i in 0 until n) {
      a[i] = m + i
    }
    println("? " + a.joinToString(" "))
    System.out.flush()
    if (f == readLine()!!) {
      l = m
    } else {
      r = m
    }
  }
  var c = "! "
  for (i in 1..d) {
    val fi = when {
      i == l -> f
      i == l + n -> if (f == "Red") "Blue" else "Red"
      i in l + 1 until l + n -> {
        a[0] = i
        for (j in 1 until n) {
          a[j] = if (n + l + j > d) -n + l + j else n + l + j
        }
        println("? " + a.joinToString(" "))
        System.out.flush()
        readLine()!!
      }
      else -> {
        a[0] = i
        for (j in 1 until n) {
          a[j] = l + j
        }
        println("? " + a.joinToString(" "))
        System.out.flush()
        readLine()!!
      }
    }
    c += fi[0]
  }
  println(c)
  System.out.flush()
}

Measured memory_bytes: 41784
n,a,b,c = list(map(int,input().split()))
l = []
ans = []
for i in range(n):
    l.append(int(input()))

def f(x,y,z,arr,cnt):
    global a
    global b
    global c
    global ans
    if arr:
        f(x + arr[0], y, z, arr[1:],cnt+1)
        f(x, y + arr[0], z, arr[1:],cnt+1)
        f(x, y, z + arr[0], arr[1:],cnt+1)
        f(x, y, z, arr[1:],cnt)
    else:
        if x > 0 and y > 0 and z > 0:
            ans.append(abs(a-x) + abs(b-y) + abs(c-z) + 10 * (cnt - 3))
f(0,0,0,l,0)
print(min(ans))

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

#define ll long long
#define ull unsigned long long

using namespace std;

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


		vector<ull> H(N, 0);
		for (int i = 0; i < N; ++i){
			cin >> H[i];
		}

	if (K >= N){
		cout << 0 << endl;
	} else {
		sort(H.begin(),H.end(),greater<int>());
		ull sum = 0;
		for (int ii = K; ii < N; ++ii){
			sum += H[ii];
		}

		cout << sum << endl;

	}



	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;




int main()
{int num;
num=0;
	string n;
	cin >> n;
	for (int i = 0; i < 2; i++){
		if (n[i] == n[i + 1] && n[i + 1] == n[i + 2]){
		    cout << "Yes" << endl;
		    break;
		}
		else num++;
	}
	if(num==2)cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

ll N;
vector<ll> A;
vector<ll> acc;
unordered_map<ll, ll> memo;

ll rec(ll from, ll to) {
  ll key = from * 1000 + to;
  if (memo.count(key)) return memo[key];
  ll ans = 0;
  if (from == to) {
    ans = 0;
  } else if (from + 1 == to) {
    ans = A[from] + A[to];
  } else {
    ans = rec(from,  from) + rec(from + 1, to) + acc[to + 1] - acc[from];
    rep (i,  to - from) {
      if (i == 0) continue;
      ll tmp = rec(from,  from + i) + rec(from + i + 1, to) + acc[to + 1] - acc[from];
      ans = min(ans, tmp);
    }
  }
  memo[key] = ans;
  return ans;
}

void solve() {
  cin >> N;
  A = vector<ll>(N);
  rep (i, N) cin >> A[i];
  acc = vector<ll>(N+1);
  rep (i, N) acc[i+1] = acc[i] + A[i];

  cout << rec(0, N-1) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 5540
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
class Main {
    public static void main(String[] args)throws IOException {
        //????????±??°
        int n = Integer.parseInt(new BufferedReader(new InputStreamReader(System.in), 64).readLine()); 
        //?¨??????????
        int result = 100000;
         
        //n??±???????????????????¨????
        //0??±??????????¨????????????¨???
        if (n != 0) {
            for(int i = 0; i < n;i++){
                result =(int)(result + (result * 0.05));
                if((result % 1000) != 0 ){
                    result = ((int)(result / 1000) + 1) * 1000;
                }
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 16988
import sys,collections as cl,bisect as bs,heapq as hq
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""


n = onem()

a = l()

fl = a[:n]
ba = a[2*n:]



ba = list(map(lambda x:-x,ba))

po = cl.deque(a[n:2*n])

hq.heapify(fl)
fll = fl
hq.heapify(ba)
baa = ba
al = [sum(fll),sum(baa)]
best = [[0,0] for i in range(n+1)]
best[0] = [al[0],0]
best[-1] = [0,al[1]]
for i in range(n):
	aaa = hq.heappop(fll)
	bbb = po[i]
	if bbb >= aaa:
		hq.heappush(fll,bbb)
		best[i+1][0] = al[0] - aaa + bbb
		al[0] += -aaa + bbb
	else:
		hq.heappush(fll,aaa)
		best[i+1][0] = al[0]

for i in range(n-1,-1,-1):
	aaa = hq.heappop(baa)
	bbb = -po[i]
	if aaa <= bbb:
		hq.heappush(baa,bbb)
		best[i][1] = al[1] - aaa + bbb
		al[1] += -aaa + bbb
	else:
		hq.heappush(baa,aaa)
		best[i][1] = al[1]

ans = -Max

for i in range(n+1):
	ans = max(ans,best[i][0]+best[i][1])

print(ans)

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

int bubbleSort(int A[], int N) {
	int sw = 0;
	bool flag = true;
	for (int i = 0; i < N; i++) {
		flag = false;
		for (int j = N-1; j >i; j--) {
			if (A[j] < A[j - 1]) {
				swap(A[j], A[j - 1]);
				flag = true;
				sw++;
			}
		}
	}
	return sw;
}

int main()
{
	int A[100], N, sw;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	sw = bubbleSort(A, N);
	for (int i = 0; i < N; i++) {
		if (i)cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
    return 0;
}

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

int main() {
	int ans;
	int a,b,c;
	cin >> a>>b>>c;
	if (a + b > b + c) {
		ans = b + c;
	}
	else {
		ans = a + b;
	}
	if (ans > a + c) {
		ans = a + c;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	string s,a,b;
	cin>>s;

	rep(i, s.size())if (s[i] != 'x')a += s[i];
	b=a;
	reverse(all(b));
	if (a!=b){
		cout<<-1<<endl;
		return 0;
	}

	vector<int> idx;
	rep(i, s.size())if (s[i] != 'x')idx.push_back(i);


	int ans = 0;
	idx.insert(idx.begin(), -1);
	idx.push_back(s.size());

	for (int i=1;;i++){
		int j = idx.size()-i-1;
		if (i > j)break;
		ans += abs((idx[i]- idx[i-1])- (idx[j+1]-idx[j]));
	}
	cout<<ans<<endl;


	return 0;
}

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


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

  int n;
  cin >> n;
  vector<ll> cnt(n+1,2);//1 to 自分
  cnt[1] = 1;
  for(ll j = 2; j<= n; j++){
    for(ll l = j+j; l<=n; l +=j){
      cnt[l]++;
    }
  }
  ll ans = 0;
  rep1(i,n){
    ans += cnt[i]*i;
  }
  cout << ans << endl;

  return 0;
    

}


Measured memory_bytes: 81340
#include <iostream>

using namespace std;

int main()
{
    long long N, K;

    cin >> N >> K;

    long long cnt = 0;

    if (K == 0) {
        cout << N * N;
        return 0;
    }

    for (int i = 2; i <= N; i++) {
        if (i > K) {
            cnt += (N / i) * (i - K);
            long long tmp = (N % i) - K + 1;
            if (tmp > 0) cnt += tmp;
        }
    }

    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
typedef struct Bomb
{
    int map[8][8];
} BOMB;
 
int x_cnt, y_cnt;
 
Input(BOMB *);
BOMB *explode(BOMB *);  /*Recursion*/
 
int main()
{
    int input_times, input_cnt;
    BOMB Bomb[50];
    int x, y;
     
    scanf("%d", &input_times);
    input_cnt = 0;
    while(input_cnt < input_times)
    {
        Input(&Bomb[input_cnt]);
        /*Read first explosion*/
		scanf("%d", &x);
		scanf("%d", &y);
		Bomb[input_cnt].map[x - 1][y - 1] = 2;
        explode(&Bomb[input_cnt]);
        input_cnt++;
    }
     
    /*Output*/
    input_cnt = 0;
    while(input_cnt < input_times)
    {
        printf("Data %d:\n", input_cnt + 1);
        for(y_cnt = 0; y_cnt < 8; y_cnt++)
        {
            for(x_cnt = 0; x_cnt < 8; x_cnt++)
            {
                printf("%d", Bomb[input_cnt].map[x_cnt][y_cnt]);
            }
            printf("\n");
        }
        input_cnt++;
    }
	
    return 0;
}

Input(BOMB *bomb)
{
    /*Read input map*/
    char dump;      /*Get rid of enter*/
    dump = getchar();
    for(y_cnt = 0; y_cnt < 8; y_cnt++)
    {
        dump = getchar();
        for(x_cnt = 0; x_cnt < 8; x_cnt++)
            bomb->map[x_cnt][y_cnt] = getchar() - 48;    /*ASCII table*/
    }
    
}
 
BOMB* explode(BOMB* bomb_map)
{
    int explode_cnt;
    for(y_cnt = 0; y_cnt < 8; y_cnt++)
        for(x_cnt = 0; x_cnt < 8; x_cnt++)
        {
            /*Find exploded bomb and process*/
            if(bomb_map->map[x_cnt][y_cnt] == 2)
            {
                bomb_map->map[x_cnt][y_cnt] = 0;
                /*Left*/
                explode_cnt = 1;
                while((x_cnt - explode_cnt) >= 0 && explode_cnt <= 3)
                {
                    if((bomb_map->map[x_cnt - explode_cnt][y_cnt]) == 1)
                        (bomb_map->map[x_cnt - explode_cnt][y_cnt]) = 2;
                    explode_cnt++;
                }
                /*Right*/
                explode_cnt = 1;
                while((x_cnt + explode_cnt) <= 7 && explode_cnt <= 3)
                {
                    if((bomb_map->map[x_cnt + explode_cnt][y_cnt]) == 1)
                        (bomb_map->map[x_cnt + explode_cnt][y_cnt]) = 2;
                    explode_cnt++;
                }
                /*Down*/
                explode_cnt = 1;
                while((y_cnt - explode_cnt) >= 0 && explode_cnt <= 3)
                {
                    if((bomb_map->map[x_cnt][y_cnt - explode_cnt]) == 1)
                        (bomb_map->map[x_cnt][y_cnt - explode_cnt]) = 2;
                    explode_cnt++;
                }
                /*Up*/
                explode_cnt = 1;
                while((y_cnt + explode_cnt) <= 7 && explode_cnt <= 3)
                {
                    if((bomb_map->map[x_cnt][y_cnt + explode_cnt]) == 1)
                        (bomb_map->map[x_cnt][y_cnt + explode_cnt]) = 2;
                    explode_cnt++;
                }
                return explode(bomb_map);
            }
        }
    return bomb_map;
}

Measured memory_bytes: 612
s = gets().chomp

is_strong = true

is_strong = false unless s == s.reverse
  
s1 = s[0, ((s.length - 1) /2)]
is_strong = false unless s1 == s1.reverse
offset = ((s.length + 3) / 2) - 1
s2 = s[offset, s.length - offset]
is_strong = false unless s2 == s2.reverse
puts is_strong ? 'Yes' : 'No'

Measured memory_bytes: 14204
n = int(input())
a = [int(input()) for _ in range(n)]
b = set(a)
d = {i: 0 for i in b}

for i in a:
    d[i] += 1

ans = 0
for v in d.values():
    if v%2 == 1:
        ans += 1
print(ans)

Measured memory_bytes: 64084
//
//  main.cpp
//  B - Step Step Evolution
//
//  Created by Chlerry on 13-8-7.
//  Copyright (c) 2013年 Chlerry. All rights reserved.
//

#include <cstdio>
#include <cstdlib>
#include <cstring>

char input[101000];
int a[101000];
int len;

//int Pro();
int Left();
int Right();
int Min(int x,int y);

int main(int argc, const char * argv[])
{
    //freopen("/Users/Chlerry/Desktop/in.txt","r",stdin);
    while(1)
    {
        //printf("------------------------\n");
        memset(input,0,sizeof(input));
        scanf("%s",input);
        if(input[0]=='#')
            break;
        len=strlen(input);
        //printf("len=%d\n",len);
        for(int i=1;i<=len;i++)
        {
            a[i]=input[i-1]-48;
            if(a[i]%3==0)
                a[i]=3;
            else
                a[i]%=3;
        }
        /*
        for(int i=1;i<=len;i++)
            printf("%d ",a[i]);
        printf("\n");
        */
        printf("%d\n",Min(Left(),Right()));
    }
    return 0;
}
        int Left()
        {
            int ans=0;
            bool flag=1;
            int left,right;
            left=a[1];
            //printf("l=%d r=%d ans=%d\n",left,right,ans);
            for(int i=2;i<=len;i++)
            {
                if(flag==0)
                    if(a[i]>right)
                    {
                        right=a[i];
                        ans++;
                    }
                    else
                    {
                        left=a[i];
                        flag=!flag;
                    }
                else
                    if(a[i]<left)
                    {
                        left=a[i];
                        ans++;
                    }
                    else
                    {
                        right=a[i];
                        flag=!flag;
                    }
                //printf("l=%d r=%d ans=%d\n",left,right,ans);
            }
            return ans;
        }
int Right()
{
    int ans=0;
    bool flag=0;
    int left,right;
    right=a[1];
    //printf("l=%d r=%d ans=%d\n",left,right,ans);
    for(int i=2;i<=len;i++)
    {
        if(flag==0)
            if(a[i]>right)
            {
                right=a[i];
                ans++;
            }
            else
            {
                left=a[i];
                flag=!flag;
            }
            else
                if(a[i]<left)
                {
                    left=a[i];
                    ans++;
                }
                else
                {
                    right=a[i];
                    flag=!flag;
                }
        //printf("l=%d r=%d ans=%d\n",left,right,ans);
    }
    return ans;
}
int Min(int x,int y)
{
    return x<y?x:y;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >>n;
	int cost[n];
	int min_cost[n];
	for(int i = 0;i<n;++i){
		cin >> cost[i];
	}
	min_cost[0]=0;
	min_cost[1]=abs(cost[1]-cost[0]);
	if(n>=2){
		for(int i = 2;i<n;++i){
			min_cost[i]=min(min_cost[i-1]+abs(cost[i]-cost[i-1]),min_cost[i-2]+abs(cost[i]-cost[i-2]));
		}
	}
	cout << min_cost[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;

#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define Rep(i, a, b) for (int (i) = (a) - 1; (i) < (b); (i)++)
#define REP(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define Sort(a, len, cmp) sort(a + 1, a + len + 1, cmp)
#define ass(a, sum) memset(a, sum, sizeof(a))

#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define ENDL cout << endl
#define SZ(x) ((int)x.size())

typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef pair <ll, ll> pll ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
typedef map <ll, ll> mll ;

const int N = 100010 ;
const double eps = 1e-8 ;
const int iinf = INT_MAX ;
const ll linf = 2e18 ;
const double dinf = 1e30 ;
const int MOD = 1000000007 ;

inline int read(){
    int X = 0, w = 0 ;
	char ch = 0 ;
    while (!isdigit(ch)) { w |= ch == '-' ; ch = getchar() ; }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar() ;
    return w ? - X : X ;
}

void write(int x){
     if (x < 0) putchar('-'), x = - x ;
     if (x > 9) write(x / 10) ;
     putchar(x % 10 + '0') ;
}

void print(int x) {
	cout << x << endl ;
	exit(0) ;
}

void PRINT(string x) {
	cout << x << endl ;
	exit(0) ;
}

void douout(double x){
	 printf("%lf\n", x + 0.0000000001) ;
}

int n, k ;
int a[N] ;
vector <ll> v, v2 ;
ll ans ;

signed main(){
	scanf("%d%d", &n, &k) ;
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]) ;
	for (int i = 1; i <= n; i++) {
		ll sum = 0 ;
		for (int j = i; j <= n; j++) {
			sum += a[j] ;
			v.pb(sum) ;
		}
	}
	for (int i = 40; i >= 0; i--) {
		v2.clear() ;
		ll p = (1ll << i) ;
		for (int i = 0; i < SZ(v); i++) {
			ll c = v[i] ;
			if (c & p) v2.pb(c) ;
		}
		if (SZ(v2) >= k) {
			ans += p ;
			v.clear() ;
			v = v2 ;
		}
	}
	printf("%lld\n", ans) ;
}

/*
写代码时请注意：
	1.是否要开Long Long？数组边界处理好了么？
	2.实数精度有没有处理？
	3.特殊情况处理好了么？
	4.做一些总比不做好。
思考提醒：
	1.最大值和最小值问题可不可以用二分答案？
	2.有没有贪心策略？否则能不能dp？
*/


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

int main(){
    int N;    
    cin >> N;
    vector<int> t(N+1), x(N+1), y(N+1);
    bool flag = true;
    t[0]=0; x[0]=0; y[0]=0; 
    for(int i=1; i<N+1; i++)
	cin >> t[i] >> x[i] >> y[i];
    
    for(int i=0; i<N; i++){
	int xDis = abs(x[i+1]-x[i]);
	int yDis = abs(y[i+1]-y[i]);
	int time = abs(t[i+1]-t[i]);
	int tmp = time-(xDis + yDis);
	
	if(tmp<0 || tmp%2==1)
	    flag=false;
    }
    cout << (flag ? "Yes": "No") << endl;
}



Measured memory_bytes: 1408
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
vpll adj[301];
int main(){
	int N,M;
	ll L;
	ll dis[301][301];
	vint hokyunum[301][301];
	int ans[301][301];
	scan(N>>M>>L);
	fill(dis[0],dis[301],INFl);
	fill(ans[0],ans[301],INF);
	rep(i,N) dis[i][i]=0;
	rep(i,M){
		int A,B;
		ll C;
		scan(A>>B>>C);
		A--; B--;
		adj[A].push_back({B,C});
		adj[B].push_back({A,C});
		dis[A][B]=C;
		dis[B][A]=C;
	}
	rep(k,N){
		rep(i,N){
			rep(j,N){
				if(k==i||k==j) continue;
				if(dis[i][j]>dis[i][k]+dis[k][j]) dis[i][j]=dis[i][k]+dis[k][j];
			}//添字の順番はWikipedia通りにやってまふ
		}
	}
	rep(i,N){
		rep(j,N){
			if(dis[i][j]<=L){
				hokyunum[i][0].push_back(j);
			}
		}
	}
	rep(i,N){
		bool alre[301]={};
		rep(j,hokyunum[i][0].size()){
			alre[hokyunum[i][0][j]]=1;
			ans[i][hokyunum[i][0][j]]=0;
		}
		rep(depth,N){
			int flag=0;
			rep(j,hokyunum[i][depth].size()){
				int v=hokyunum[i][depth][j];
				rep(k,hokyunum[v][0].size()){
					int u=hokyunum[v][0][k];
					if(alre[u]==0){
						flag=1;
						alre[u]=1;
						hokyunum[i][depth+1].push_back(u);
						ans[i][u]=depth+1;
					}
				}
			}
			if(flag==0) break;
		}
	}
	int Q;
	scan(Q);
	rep(i,Q){
		int s,t;
		scan(s>>t);
		s--; t--;
		if(ans[s][t]==INF) prin(-1);
		else prin(ans[s][t]);
	}
	return 0;
}


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

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

ll mpow(ll a,ll b){
    ll res=1;
    a%=mod;
    while(b){
    	if(b%2) res=res*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return res;
}

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

void solve(){
	//code
	int n;
  	cin >> n;
  	vector<int> p(n);
  	vector<int> q(n);
  	
	for (int i=0;i<n;i++) 
		cin >> p[i];
  	for (int i = 0; i < n; i++) 
	  	cin >> q[i];
  	
	vector<int> ans=p;
 
  	sort(ans.begin(),ans.end());
  	int a = 0, b = 0, c = 1;
  	
	do {
    	if (equal(ans.begin(),ans.end(),p.begin()))
			a = c;
    	if (equal(ans.begin(),ans.end(),q.begin())) 
			b = c;
    	if (a && b)
			break;
    	c++;
  	}while (next_permutation(ans.begin(), ans.end()));
  	
	cout << abs(a-b) << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	solve();
 	return 0;
}


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

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

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

int main(){
  int N,M;
  long long x[1000];
  long long y[1000];
  long long z[1000];
  long long ppp[1000];
  long long ppn[1000];
  long long pnp[1000];
  long long pnn[1000];
  long long npp[1000];
  long long npn[1000];
  long long nnp[1000];
  long long nnn[1000];
  long long eight[8];
  long long maximum=0;
  cin >> N >> M;
  for(int i=0;i<N;i++){
    cin >> x[i] >> y[i] >> z[i];
    ppp[i] = x[i] + y[i] + z[i];
    ppn[i] = x[i] + y[i] - z[i];
    pnp[i] = x[i] - y[i] + z[i];
    pnn[i] = x[i] - y[i] - z[i];
    npp[i] = -x[i] + y[i] + z[i];
    npn[i] = -x[i] + y[i] - z[i];
    nnp[i] = -x[i] - y[i] + z[i];
    nnn[i] = -x[i] - y[i] - z[i];
  }
  sort(ppp, ppp+N);
  sort(ppn, ppn+N);
  sort(pnp, pnp+N);
  sort(pnn, pnn+N);
  sort(npp, npp+N);
  sort(npn, npn+N);
  sort(nnp, nnp+N);
  sort(nnn, nnn+N);

  for(int i=0;i<M;i++){
    eight[0]+=ppp[N-i-1];
    eight[1]+=ppn[N-i-1];
    eight[2]+=pnp[N-i-1];
    eight[3]+=pnn[N-i-1];
    eight[4]+=npp[N-i-1];
    eight[5]+=npn[N-i-1];
    eight[6]+=nnp[N-i-1];
    eight[7]+=nnn[N-i-1];
  }
  //cout << eight[0]<< endl;
  for(int i=0;i<8;i++){
    if(maximum <  eight[i]){
      maximum = eight[i];
    }
  }
  cout << maximum << endl;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"log"
)

func main() {
	var n int
	if _, err := fmt.Scanf("%d", &n); err != nil {
		log.Fatalln(err)
	}
	s := make([]int, n)
	for i := 0; i < n; i++ {
		if _, err := fmt.Scanf("%d", &s[i]); err != nil {
			log.Fatalln(err)
		}
	}

	var q int
	if _, err := fmt.Scanf("%d", &q); err != nil {
		log.Fatalln(err)
	}
	t := make([]int, q)
	for i := 0; i < q; i++ {
		if _, err := fmt.Scanf("%d", &t[i]); err != nil {
			log.Fatalln(err)
		}
	}
	fmt.Println(linearSearch(s, t))
}

func linearSearch(array1 []int, array2 []int) int {
	var count int
	for _, n2 := range array2 {
		for _, n1 := range array1 {
			if n1 == n2 {
				count++
				break
			}
		}
	}
	return count
}


Measured memory_bytes: 1716
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int n;
    cin >> n;
    using Graph = vector<vector<int>>;
    Graph G(n);
    rep(i, n){
        string s;
        cin >> s;
        rep(j, n)if(s[j]=='1') G[i].push_back(j);
    }
    queue<int> que;
    vector<int> ts(n, -1);
    ts[0] = 0;
    que.push(0);
    while(!que.empty()){
        int u = que.front(); que.pop();
        int now = ts[u];
        repe(v, G[u]){
            if(ts[v] != -1){
                if(!(ts[v]==now-1 || ts[v]==now+1)){
                    cout << -1 << endl;
                    return 0;
                }
                continue;
            }
            ts[v] = now+1;
            que.push(v);
        }
    }

    int ANS = 0;
    rep(i, n){
        ts.assign(n, -1);
        ts[i] = 0;
        que.push(i);
        int ans = 0;
        while(!que.empty()){
            int u = que.front(); que.pop();
            int now = ts[u];
            chmax(ans, now);
            repe(v, G[u]){
                if(ts[v] != -1){
                    continue;
                }
                ts[v] = now+1;
                que.push(v);
            }
        }
        chmax(ANS, ans+1);
    }
    cout << ANS << endl;


}

Measured memory_bytes: 512
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        aa: [usize; n]
    };
    let mut hm = std::collections::HashMap::new();
    for a in aa {
        *hm.entry(a).or_insert(0) += 1;
    }
    let mut sum = 0;
    for (num, count) in hm {
        if num < count {
            sum += count - num;
        } else if num > count {
            sum += count;
        }
    }
    println!("{}", sum);
}


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

using namespace std;

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

    int count=0;

    for(int i=1;i<=k;i++){

        for(int j=1;j<=k;j++){

            for(int l=1;l<=k;l++){
                count+=gcd(i,gcd(j,l));
            }

        }

    }

    cout<<count<<endl;
}

Measured memory_bytes: 3620
n = int(input())
s = input()

f = "";
b = "";

if n % 2 == 0 :
	for i in range(n):
		if i < n / 2 :
			f += s[i]
		else :
			b += s[i]
	if f == b :
		print("Yes")
	else :
		print("No")
else :
	print("No")


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

#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

using namespace std;
int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int x;
	cin >> x;
	int ar[x+106];
	for(int i=0;i<x+106;i++){
		ar[i]=0;
	}
	ar[0]=1;
	for(int i=0;i<=x;i++){
		if(ar[i]==1){
			for(int j=0;j<=5;j++){
				ar[i+j+100]=1;
			}
		}
	}

	cout << ar[x] << "\n";


}

Measured memory_bytes: 640
K=int(input())
ans=[]
for i in range(1,10):
    ans.append(i)
i=0

while True:
    if ans[i]%10==0:
        ans.append(10*ans[i])
        ans.append(10*ans[i]+1)
    elif ans[i]%10==9:
        ans.append(10*ans[i]+8)
        ans.append(10*ans[i]+9)
    else:
        ans.append(10*ans[i]+(ans[i]%10-1))
        ans.append(10 * ans[i] + (ans[i] % 10 ))
        ans.append(10 * ans[i] + (ans[i] % 10+1))
    if len(ans)>K:
        break
    i+=1

print(ans[K-1])

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

int main(void)
{
  char str[21] = {0};
  int i;

  scanf("%s", str);
  for (i = strlen(str) - 1; i >= 0; i--) {
    printf("%c", str[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 520
#include <iostream>
#include <stdio.h>
#include <strings.h>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
 
int main(){
    double px,py,qx,qy;
    double ax,ay,len;
    scanf("%lf %lf %lf %lf",&px,&py,&qx,&qy);
    ax = (px - qx)*(px - qx);
    ay = (py - qy)*(py - qy);
    len = sqrt(ax + ay);
    printf("%.8lf\n",len);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    int n;cin>>n;
    vector<ll> 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.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll res=0;
    for(int i=0;i<n;i++){
        ll mid=b[i],tmp=1;
        if(upper_bound(c.begin(),c.end(),mid)!=c.end()){
            tmp*=n-(upper_bound(c.begin(),c.end(),mid)-c.begin());
        }
        else continue;

        if(lower_bound(a.begin(),a.end(),mid)!=a.begin()){
            tmp*=lower_bound(a.begin(),a.end(),mid)-a.begin();
        }
        else continue;

        res+=tmp;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3196
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def FI(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline().split())
def S(): return input()

n, a, b = LI()

if a>b:
	print(0)
elif n==1 and a!=b:
	print(0)
else:
	mi = a*(n-1)+b
	ma = a+b*(n-1)
	print(ma-mi+1)

Measured memory_bytes: 7232
class UnionFind():
    # https://qiita.com/hukuhuku11111a1/items/1bbf67d90630552eb512
    def __init__(self, size):
        self.table = [-1] * size

    def find(self, x):
        while 1:
            i = self.table[x]
            if i < 0:
                return x
            x = i

    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 == s2:
            return
        d = self.table[s1] - self.table[s2]
        if d < 0:
            self.table[s2] = s1
        elif d > 0:
            self.table[s1] = s2
        else:
            self.table[s1] += -1
            self.table[s2] = s1

N, M = [int(_) for _ in input().split()]
ab = [[int(_) for _ in input().split()] for _ in range(M)]

result = 0

for a1, b1 in ab:
    uf = UnionFind(N + 1)
    for a, b in ab:
        if (a, b) == (a1, b1):
            continue
        uf.union(a, b)
    rs = set([])
    for i in range(1, N + 1):
        rs.add(uf.find(i))
    if len(rs) > 1:
        result += 1

print(result)
    



Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

struct edge{ 
	int to, cost;
	edge(int to, int cost) :to(to), cost(cost){};
};
vector<edge> G[110];

int n, r, k, t;
int p, s, d, v;

int dis[110];

void dijkstra(int start){
	dis[start] = 0;

	priority_queue<P> que;
	que.push(P(0, start));

	while (!que.empty()){
		P p = que.top(); que.pop();
		int a = p.second;

		if (dis[a] < p.first)continue;

		for (int i = 0; i < G[a].size(); i++){
			edge e = G[a][i];
			if (dis[e.to] > dis[a] + e.cost){
				dis[e.to] = dis[a] + e.cost;
				que.push(P(dis[e.to], e.to));
			}

		}
	}
}

int main(){
	cin >> n;
	REP(i, n){
		cin >> r >> k;
		REP(j, k){
			cin >> t;
			G[r].push_back(edge(t, 1));
		}
	}
	cin >> p;
	REP(i, p){
		REP(j, 110)dis[j] = INF;
		cin >> s >> d >> v;
		dijkstra(s);
		if (dis[d] + 1 <= v)cout << dis[d] + 1 << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 1204
m = {'A':0, 'B':0, 'AB':0, 'O':0}
while True:
    try:
        a,b = list(input().split(','))
    except:
        break
    if b == 'A':    m['A']+=1
    if b == 'B':    m['B']+=1
    if b == 'AB':   m['AB']+=1
    if b == 'O':    m['O']+=1
print(m['A'],m['B'],m['AB'],m['O'], sep = '\n')


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


int main(){
    int n,x;
    cin>>n>>x;

    vector <int> l(n);

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


    int ans = 0;    
    int d = 0;
    ans++;
    for (int i = 0; i < n; i++)
    {
        d = l[i]+d;
        if(d>x){
            break;
        }
        ans++;
    }
    
    
    cout << ans <<endl;
    return 0;
    
}

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

int main() {
  int number_of_student, number_of_checkpoint;
  cin >> number_of_student >> number_of_checkpoint;

  const int NMMAX = 50;
  int A[NMMAX], B[NMMAX], C[NMMAX], D[NMMAX];

  for(int i=0; i < number_of_student; i++) {
    cin >> A[i] >> B[i];
  }
  for(int i=0; i < number_of_checkpoint; i++) {
    cin >> C[i] >> D[i];
  }

  for(int i=0;i<number_of_student; i++) {
    int min_dist = abs(A[i]-C[0])+abs(B[i]-D[0]), checkpoint=1;

    for(int j=1; j<number_of_checkpoint; j++) {
      const int cur_dist = abs(A[i]-C[j])+abs(B[i]-D[j]);
      if(min_dist > cur_dist) {
        min_dist = cur_dist;
        checkpoint = j+1;
      }
    }
    cout << checkpoint << endl;
  }
}

Measured memory_bytes: 3640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();

		if ( (b-a)%2 == 0 ) {
			System.out.println((b-a)/2);
			System.exit(0);
		}

		// 出力
		long d = Math.min(n-b,a-1l) + 1l + (b-a)/2l;
		System.out.println(d);
	}
}

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}



int32_t main()
{
    IOS

    ll n;
    cin>>n;
    if(n<2)
    {
    	cout<<0<<endl;
    	return 0;
    }

    vector<ll> v(n);
    for(int i=0;i<n;i++)
    	cin>>v[i];
    sort(all(v));

    if(n==2)
    {
    	cout<<v[n-1]<<endl;
    	return 0;
    }

    ll ans=v[n-1],temp=n-2;
    for(int i=n-2;i>=0;i--)
    {
    	ans+=(v[i]*2LL);
    	temp-=2;
    	if(temp==0)
    		break;

    	if(temp<0)
    	{
    		ans-=v[i];
    		break;
    	}
    }

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

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

using namespace std;

int main() {
    size_t s;
    cin >> s;
    vector<bool> a(1000000, false);
    long long m = 1;
    a[s] = true;
    long long current = s;
    while (true) {
        current = (current % 2 == 0) ? (current / 2) : (3 * current + 1);
        if (a[current]) {
            break;
        }
        else {
            a[current] = true;
            ++m;
        }
    }
    cout << m + 1 << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int x1, x2;
    cin >> x1 >> x2;
    if(x1 > x2){
        cout << x1-x2 << endl;
    }
    else{
        cout << x2-x1 << endl;
        
    }
    
    
    

    
}




Measured memory_bytes: 3092