akhauriyash/Code-Regression huggingface dataset:
n=int(raw_input())
a=[int(raw_input()) for _ in xrange(n)]*3

dp=[[0]*(3*n) for _ in xrange(3*n)]
for i in xrange(3*n):
    if (n-1)%2==0:
        dp[i][i]=a[i]
    else:break

for d in xrange(1,n):
    for l in xrange(2*n):
        r=l+d
        if (r-l)%2==(n-1)%2:
            dp[l][r]=max(dp[l+1][r]+a[l],dp[l][r-1]+a[r])
        else:
            if a[l]>a[r]:
                dp[l][r]=dp[l+1][r]
            else:
                dp[l][r]=dp[l][r-1]

ans=0
for i in xrange(n):
    ans=max(ans,dp[i][i+n-1])
print(ans)

Measured memory_bytes: 384192
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
	ios;
	string s;
	cin>>s;
	ll sm=0,l=s.length(),i;
	for(i=0;i<l;i++)
	sm=sm+(ll)(s[i]-'0');
	if(sm%9==0) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3740
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, p = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    ls = [0] * 5001
    ls[0] += 1
    for v in a:
        for i in range(5000 - v, -1, -1):
            ls[i+v] += ls[i]
    t = 0
    for i in range(p, 5001, 2):
        t += ls[i]
    print(t)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38768
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    long long a, b,c; cin >> a >> b>>c;
    cout << (c % gcd(a, b) == 0 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3608
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main(){
	int n, l; cin >> n >> l;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	int ma =0 ,idx=0;
	rep(i, 0, n - 1) ma = max(ma, a[i + 1] + a[i]);
	if (ma< l) printf("Impossible\n");
	else {
		printf("Possible\n");
		rep(i, 0, n - 1) if (ma== a[i + 1] + a[i]) idx = i+1;
		rep(i, 1, idx) printf("%d\n", i);
		rep(i, idx + 1, n) printf("%d\n", n - 1 -i+ idx + 1);
		printf("%d\n", idx);
	}
	return 0;
}


Measured memory_bytes: 1152
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int t = sc.nextInt();
		int[] aa = new int[n];
		int[] bb = new int[n];
		for (int i = 0; i < n; i++) {
			aa[i] = sc.nextInt();
			bb[i] = sc.nextInt();
		}
		int[][] dp = new int[n][t];
		int[][] dq = new int[n][t];
		for (int i = 0; i < n - 1; i++) {
			int a = aa[i];
			int b = bb[i];
			for (int x = t - 1; x >= 0; x--) {
				dp[i + 1][x] = dp[i][x];
				if (x + a < t)
					dp[i + 1][x + a] = Math.max(dp[i + 1][x + a], dp[i][x] + b);
			}
		}
		for (int i = 0; i < n - 1; i++) {
			int a = aa[n - 1 - i];
			int b = bb[n - 1 - i];
			for (int x = t - 1; x >= 0; x--) {
				dq[i + 1][x] = dq[i][x];
				if (x + a < t)
					dq[i + 1][x + a] = Math.max(dq[i + 1][x + a], dq[i][x] + b);
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int p = i, q = n - 1 - i;
			for (int x = 0, y = t - 1; x < t; x++, y--)
				ans = Math.max(ans, dp[p][x] + bb[i] + dq[q][y]);
		}
		println(ans);
	}
}


Measured memory_bytes: 134448
n = int(raw_input())
cs = [i + 1 for i in range(n * 2)]
for i in range(int(raw_input())):
    k = int(raw_input())
    if k == 0:
        cs = reduce(lambda x, y: x + list(y), zip(cs[:n], cs[n:]), [])
    else:
        cs = cs[k:] + cs[:k]
print '\n'.join(map(str, cs))

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[11111];
signed main(){
    int n;
    cin>>n;
    for(int j=0;j<n;j++){
        cin>>a[j];
    }
    int sum=0;
    for(int i=0;i<n;i++){
        for(int k=0;k<30;k++){
            if(a[i]%2==0){
                a[i]=a[i]/2;
                sum++;
            }
            else{
            }
        }
    }
    cout<<sum<<endl;
}

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

int main(){
    int k,n;
    cin >> k >> n;
    vector<int> a(n+1);
    for(auto&& x:a){
        cin >> x;
    }
    a.at(n) = a.at(0) + k;
    vector<int> delta(n);
    for (int i = 0; i < n; i++)
    {
        delta.at(i) = a.at(i+1) - a.at(i);
    }
    int ans = k - *max_element(delta.begin(),delta.end());
    cout << ans << endl;
}

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

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	string A[n];
	string B[m];
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		A[i] = s;
	}
	for (int i = 0; i < m; i++) {
		string s;
		cin >> s;
		B[i] = s;
	}
	bool res = false;
	for (int i = 0; i <= n - m; i++) {
		for (int j = 0; j <= n - m; j++) {
			bool all = true;
			for (int k = 0; k < m; k++) {
				for (int l = 0; l < m; l++) {
					all = (A[i + k][j + l] == B[k][l]);
					if (!all)
						break;
				}
				if (!all)
					break;
 			}
 			if (all) {
 				res = all;
 			}
 			if (res)
 				break;
		}
		if (res)
			break;
	}
	cout << (res?"Yes":"No") << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

#define INF 100000000;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;

int main(){
    string S[2];
    cin >> S[0] >> S[1];
    if(S[0] > S[1]) cout << ">" << endl;
    else if (S[1] > S[0]) cout << "<" << endl;
    else cout << "=" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 long long int plu(long long int a){
   long long int sum=0;for(int i=0;i<a;i++)sum+=i;
   return sum;
 }
 
int main() {unordered_map<int, int> mp;
long long int n,a,l,sum=0;cin>>n;long long int k[n],A[n+1]={0};
            
for(long long int i=0;i<n;i++){
  cin>>k[i];l=k[i];
  //cout<<k[i]<<" "<<l<<endl;
  A[l]++;
}
  
for(long long int i=0;i<n+1;i++){sum+=plu(A[i]);}
  //cout<<sum;
//cout<<A[1]<<A[2]<<A[3];            
for(long long int i=0;i<n;i++)cout<<sum-A[k[i]]+1<<endl;
           }
  


Measured memory_bytes: 5760
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("xyz");
            WillReturn.Add("abc");
            //xaybzc
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("atcoderbeginnercontest");
            WillReturn.Add("atcoderregularcontest");
            //aattccooddeerrbreeggiunlnaerrccoonntteesstt
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string O = InputList[0];
        string E = InputList[1];

        var sb = new System.Text.StringBuilder();
        for (int I = 0; I <= O.Length + E.Length - 1; I++) {
            sb.Append((I % 2 == 0) ? O[I / 2] : E[I / 2]);
        }
        Console.WriteLine(sb.ToString());
    }
}


Measured memory_bytes: 13140
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, E, F, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >> N;
  ll v[N], c[N];
  ans = 0;
  rep(i, N){
    cin >> v[i];
  }
  rep(i, N){
    cin >> c[i];
    ans += max(v[i]-c[i], (ll)0);
  }

  cout << ans << endl;

}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    string S, partS;
    cin >> S;
    int max_length = 0;
    bool flag;
    for (int i = 1; i < S.size(); i++)
    {
        flag = false;
        partS = S.substr(i-max_length, max_length + 1);
        for (int j = 0; j < i - 2*max_length; j++)
        {
            if (S.compare(j, max_length + 1, partS) == 0){
                flag = true;
                break;
            }
        }
        if (flag)
            ++max_length;
    }

    cout << max_length << endl;
}

Measured memory_bytes: 384
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, m = na()
x = na()

x.sort()
d = [x[i] - x[i - 1] for i in range(1, m)]
d.sort()
if n >= m:
    print(0)
else:
    print(sum(d[:m - n]))

Measured memory_bytes: 13316
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<int>> A(H, vector<int>(W));
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> A[i][j];
	vector<vector<int>> Ans;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A[i][j] % 2 == 1) {
				if (i < H - 1) {
					Ans.push_back({ i + 1, j + 1, i + 2, j + 1 });
					A[i + 1][j]++;
				}
				else {
					if (j < W - 1) {
						Ans.push_back({ i + 1, j + 1, i + 1, j + 2 });
						A[i][j + 1]++;
					}
				}
			}
		}
	}
	cout << Ans.size() << endl;
	for (int i = 0; i < Ans.size(); i++) cout << Ans[i][0] << " " << Ans[i][1] << " " << Ans[i][2] << " " << Ans[i][3] << endl;
}

Measured memory_bytes: 9904
/*
        |___________________________Arshit Mangukiya_____________________________|
        |_______________________________DA-IICT__________________________________|
        |_____________________________201801173__________________________________|
*/
        /*______________________WRITE  YOUR  CODE  HERE_________________________*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;            
typedef long double ld;
#define ff first
#define ss second
#define pi acos(-1)
#define mr_ad_0501 ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define all(a)      a.begin(),a.end()
#define F(i,n) for(ll i=0;i<n;i++)
#define MOD 1000000007
#define MAX 200007
#define LM LLONG_MAX
#define sz size()
#define p(x) 		cout<< x << " ";
#define pe(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
const int N=2e5+5;
    	/*	bool fun(pair<int,int>a , pair<int,int>b)
			{
				if(a.ff == b.ff)	return a.ss < b.ss;
				else			return a.ff > b.ff;
			}*/
 /*void bfs(ll x)
 {
 	queue<ll> q;
	q.push(x);
    while(!q.empty())
    {
        ll k=q.front();
        q.pop();
        for(auto X:v[k])
        {
            if(!vis[X])
            {
            	l[X]=l[k]+1;
                vis[X]=1;
                q.push(X);
            }
        }
    }
 }*/

void solve()
{
	   ll n,m,q;

    ll x;
    cin>>x;
    ll cnt=0;
    ld rate=1.01;
    ld p=100;
    ll sum=100;
    while(1)
    {
        ll inte=p*rate;
        p=inte;
        
        if(inte>=x)
            break;
        cnt++;    
    }
    cout<<cnt+1<<endl;
}
int32_t main(){
	mr_ad_0501;
	ll t=1;
	//cin >> t;
	while(t--)
	{
		solve();
	}
}

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

using namespace std;

const int N = 3005;

double dp[N][N], p[N];
int n;

int main() {
  scanf("%d", &n);

  for (int i = 1; i <= n; i++)
    scanf("%lf", &p[i]);
  
  for (int i = 0; i <= n; i++)
    dp[0][i] = 0;
  dp[0][0] = 1;

  for (int i = 1; i <= n; i++)
    dp[i][0] = dp[i-1][0] * (1.0-p[i]);

  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      dp[i][j] = dp[i-1][j] * (1.0 - p[i]) + dp[i-1][j-1] * p[i];

  double answer = 0;

  for (int i = n/2+1; i <= n; i++)
    answer += dp[n][i];

  printf("%.10lf", answer);
  
  return 0;
}


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

using namespace std;

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

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int N = 1e5 + 1;
bool prime[N];
int cnt[N];
void sieve(){
	memset(prime,1,sizeof(prime));
	prime[0] = 0, prime[1] = 0;
	for(int i = 2; i < N; i++)
		if(prime[i])
			for(int j = 2*i; j < N; j += i)
				prime[j] = 0;
}
signed main(){
    int t = 1; //cin >> t;
    while(t--){
    	sieve();
    	for(int i = 3; i < N; i+=2)
    		if(prime[i] and prime[(i+1)/2])
    			cnt[i]++;
    	for(int i = 3; i < N; i++)
    		cnt[i] += cnt[i-1];
    	int q; cin >> q;
    	while(q--)
    	{
    		int l,r; cin >> l >> r;
    		cout << cnt[r] - cnt[l-1] << endl;
    	}
    }    
}

Measured memory_bytes: 4436
Module Program
  Sub Main
    Dim s = GetInts()
    Dim a=s(0),b=s(1)
    Dim ans=If(a Mod b=0,0,1)
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

Measured memory_bytes: 22352
use proconio::input;
fn main() {    
    input!{
        n: i32,
        m: i32,
        c: i32,
        b: [i32; m],
        a: [[i32; m]; n]
    }
    let ans = a.iter().filter(|x| {
        x.iter()
        .zip(b.iter())
        //.inspect(|(&y, &z)| println!("{}", y*z ))
        .fold(0, |acc, (y, z)|  y*z + acc) + c > 0 })
        .count();

    println!("{}", ans);

}


Measured memory_bytes: 2108
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)

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

// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;
// const double PI = M_PI;

int N;
vector<ll> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  A.resize(N);
  rep(i, N) { cin >> A[i]; }
  sort(A.begin(), A.end(), greater<ll>());

  ll ans = A[0];
  ll idx = 1;
  ll cnt = 0;
  for (int i = 1; i < N - 1; i++) {
    ans += A[idx];
    cnt++;
    if (cnt == 2) {
      idx++;
      cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4368
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3,unroll-loops")

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

int T[101];
int v[40001];
int main(void){
	int n=nextint();
	for(int i=1; i<=n; i++){
		T[i]=T[i-1]+nextint()*2;
	}
	for(int i=1; i<=n; i++){
		int V=nextint()*2;
		for(int t=T[i-1]; t<T[i]; t++){
			v[t]=V;
		}
	}
	v[0]=1;
	for(int t=0; t<T[n]; t++){
		if(v[t+1]>v[t]+1) v[t+1]=v[t]+1;
	}
	for(int t=T[n]; t>0; t--){
		if(v[t-1]>v[t]+1) v[t-1]=v[t]+1;
	}
	int ans=0;
	for(int t=0; t<T[n]; t++){
		ans += (v[t]<v[t+1]?v[t]:v[t+1]);
	}
	printf("%.2lf\n", (double)ans/4);
}


Measured memory_bytes: 1820
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if (s == u) { cout << a - 1 << " " << b << "\n"; }
	else{ cout << a << " " << b - 1 << "\n"; }
	return 0;
}


Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<pair<string,pair<int,int>>> box;
  string s;
  int p;
  map<string,int> map;
  rep(i,n){
    cin >> s >> p;
    box.push_back(make_pair(s,make_pair(p,i+1)));
    map[s]++;
  }
  sort(box.begin(),box.end());
  int cnt;
  rep(i,n){
    cnt = map[box[i].first];
    if(cnt == 1){
      printf("%d\n", box[i].second.second);
    }else{
      vector<pair<int,int>> cheak;
      rep(j,cnt){
        cheak.push_back(make_pair(-box[i+j].second.first,box[i+j].second.second));
      }
      sort(cheak.begin(),cheak.end());
      rep(j,cnt){
        printf("%d\n",cheak[j].second);
      }
      i += cnt-1;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

const int MAX_V = 100010;

vector<vector<int>> G(MAX_V);
vector<pair<int, int>> bridge;
vector<int> articulation;
int ord[MAX_V], low[MAX_V];
bool visited[MAX_V];

void dfs(int cv, int pv, int &k){
    visited[cv] = true;

    ord[cv] = k++;
    low[cv] = ord[cv];

    bool isArticulation = false;
    int cnt = 0;

    for(int i=0; i<G[cv].size(); i++){
        int nv = G[cv][i];

        if(!visited[nv]){
            cnt++;
            dfs(nv, cv, k);
            low[cv] = min(low[cv], low[nv]);
            if(~pv && ord[cv] <= low[nv]) isArticulation = true;
            if(ord[cv] < low[nv]) bridge.emplace_back(minmax(cv, nv));
        }
        else if(nv != pv){
            low[cv] = min(low[cv], ord[nv]);
        }
    }

    if(pv == -1 && 1 < cnt) isArticulation = true;
    if(isArticulation) articulation.emplace_back(cv);
}

int main(){
    int n, m; cin>>n>>m;
    for(int i=0; i<m; i++){
        int s, t; cin>>s>>t;
        G[s].emplace_back(t);
        G[t].emplace_back(s);
    }

    int k = 0;
    for(int i=0; i<n; i++){
        if(!visited[i]) dfs(i, -1, k);
    }

    sort(articulation.begin(), articulation.end());
    sort(bridge.begin(), bridge.end());

    /*
    for(auto i:articulation){
        cout << i << endl;
    }
    */
    for(auto i:bridge){
        cout << i.first << " " << i.second << endl;
    }
}


Measured memory_bytes: 6616
N = int(input())
list = list(map(int, input().split()))
ans = 1

dict = {}
for i in range(N):
    if list[i] in dict.keys():
        dict[list[i]] += 1
    else:
        dict.setdefault(list[i], 1)

max = max(dict)

try:
    for i in range(1,max+1):
        ans = (ans * (dict[i-1] ** dict[i])) % 998244353
    if dict[0] != 1:
        ans = 0
    if list[0] != 0:
        ans = 0
except KeyError:
    ans = 0

print(ans)

Measured memory_bytes: 19552
#include<iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n[4], h[2], i, l, g = 0;
    for (i = 0; i < 4; i++)
    {
        cin >> n[i];
    }
    for (i = 0; i<2; i++)
    {
        cin >> h[i];
    }
    for (i = 3; i >= 0; i--)
    {
        sort(n, n + 4);
    }
    l = n[3] + n[2] + n[1];
    if (h[0] > h[1])
        cout << l + h[0] << endl;
    else
        cout << l + h[1] << endl;
    return 0;
}

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

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(int N, int M, vector<int>& S, vector<int>& T) {
    vector<vector<int> > dp(N, vector<int>(M, 0));
    vector<vector<int> > dpSum(N, vector<int>(M, 0));

    REP(i,0,N) {
        REP(j,0,M) {
            if (S[i] == T[j]) {
                if (i>0 && j>0) dp[i][j] = (dpSum[i-1][j-1] + 1) % MOD;
                else dp[i][j] = 1;
            }

            if (i>0) dpSum[i][j] = dpSum[i-1][j];
            if (j>0) dpSum[i][j] = (dpSum[i][j] + dpSum[i][j-1]) % MOD;
            if (i>0 && j>0) dpSum[i][j] = (MOD + dpSum[i][j] - dpSum[i-1][j-1]) % MOD;
            dpSum[i][j] = (dpSum[i][j] + dp[i][j]) % MOD;
        }
    }
	stringstream ss;
	ss << dpSum[N-1][M-1] + 1;

	cout << ss.str() << '\n';

    return;
}

signed main() {
    int N, M;
    cin >> N >> M;

    vector<int> S(N), T(M);
    REP(i,0,N) cin >> S[i];
    REP(i,0,M) cin >> T[i];

    solve(N, M, S, T);
    
    return 0;
}



Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0,m;cin>>n;
  lvector v(n+1,1);
  for(ll i=2;i<=n;++i) for(ll j=i;j<=n;j+=i) v[j]++;
  rep(i,n+1) ans+=i*v[i];
  print(ans);
  return 0;
}

Measured memory_bytes: 81324
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String su = sc.next();
        String[] s = su.split("",0);
        
        if(s.length<=k){
            System.out.println(su);
        }else{
            for(int i = 0;i < k;i++){
                System.out.print(s[i]);
            }
            System.out.println("...");
        }
    }
}

Measured memory_bytes: 35708
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  ll a[n];
  rep(i,n)cin >> a[i];
  int cnt=0;
  rep(i,n){
   if(a[i]<0)cnt++;
  }
  ll ans=0;
  rep(i,n){
    if(a[i]<0)a[i]*=-1;
  }
  sort(a,a+n);
  if(cnt%2==0){
    rep(i,n){
      ans+=abs(a[i]);
    }
  }
  else{
    ans-=a[0];
    for(int i=1;i<n;i++)ans+=a[i];
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 1024
N,T = map(int,input().split())
c_t = []
for i in range(N):
  c_t.append(list(map(int,input().split())))
c_min = []
for i in c_t:
  if i[1] <= T:
    c_min.append(i[0])
print(min(c_min) if len(c_min)>0 else "TLE")

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

int main()
{
    int n; cin>>n;
    auto a=to_string(n);
    long res=0;
    for(int i=1; i<=n; ++i) if (i%10>0) {
        auto s=to_string(i);
        int m=s.size();
        res+=s[0]==s[m-1];
        //int c=s[0]==s[m-1];
        for(int j=0, p=1; j<5; ++j, p*=10) {
            string t;
            t+=s[m-1];
            t+=string(j, '0');
            t+=s[0];

            auto x=stol(t);
            if (x>n) break;
            string u;
            u+=s[m-1];
            u+=string(j, '9');
            u+=s[0];

            auto y=stol(u);
            if (y<=n) {
                res+=p;
                //c+=p;
            }
            else {
                for(; x<=n; x+=10) ++res;
            }
        }
        //cout<<i<<": "<<c<<endl;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
import bisect
INF=10**11
A,B,q=map(int,input().split())
a=[-INF]+[int(input()) for _ in range(A)]+[INF]
b=[-INF]+[int(input()) for _ in range(B)]+[INF]
for _ in range(q):
  x=int(input())
  i=bisect.bisect_left(a,x)
  j=bisect.bisect_left(b,x)
  ans=min(max(a[i],b[j])-x,x-min(a[i-1],b[j-1]),a[i]-b[j-1]+min(a[i]-x,x-b[j-1]),b[j]-a[i-1]+min(b[j]-x,x-a[i-1]))
  print(ans)

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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n-1; i++) {
            x *= y;
        }
        return x;
    }
}


int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
	int ans=0,mn=0;
	for(int i=1;i<=5;i++)
	{
		int x;
		cin >> x;
		int t=((x-1)/10+1)*10;
		ans+=t;
		mn=max(mn,t-x);
	}
	cout << ans-mn;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
p = gets.chomp.split(' ').join
q = gets.chomp.split(' ').join
arr = []
n.times { |i| arr << (i + 1) }
def rec(arr1, arr2)
  return [arr2.join('')] if arr1.length == 0
  res = []
  arr1.each do |i|
    copied_arr1 = arr1.dup
    copied_arr1.delete(i)
    copied_arr2 = arr2.dup
    copied_arr2 << i
    res += rec(copied_arr1, copied_arr2)
  end
  return res
end
list = rec(arr, [])
a, b = 0, 0
list.each_with_index do |x, i|
  a = i + 1 if x == p
  b = i + 1 if x == q
end
puts (a - b).abs

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	string s;
	cin >> s;

	int res = 0;
	rep (i, 0, s.size() / 2) {
		if (s[i] != s[s.size() - (i + 1)])
			res++;
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextStr()
	maxr := 0
	run := 0

	for i := 0; i < len(s); i++ {
		if s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T' {
			run++
			maxr = max(maxr, run)
		} else {
			run = 0
		}
	}

	fmt.Println(maxr)

}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int H, N;
int A[MAX_N];

signed main()
{
  cin >> H >> N; 
  REP(n,N) {
    cin >> A[n];
    H -= A[n];
  }

  cout << (H <= 0 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,min=1000000;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++){
        int sum1=0,sum2=0;
        for(int j=0;j<i;j++){
            sum1+=a[j];
        }
        for(int j=i;j<n;j++){
            sum2+=a[j];
        }
        if(min>abs(sum1-sum2)) min=abs(sum1-sum2);
    }
    cout<<min;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,r,x,y;
	ll		ans = 0;
	string	s;
	cin >> n >> s;
	if ( (n & 1) == 1) {
		cout << "No" << endl;
		return 0;
	}
	bool f = true;
	for(i=0;i<n/2;i++) {
		if (s[i] != s[i+n/2]) f = false;
	}

	if (f) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	//if (ans<0) ans = 0;
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];
	//vector<ll>	dp(n+1,INFL);
	//vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));

	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int INF=1e9;



int main(){
	int H,W;
	cin>>H>>W;
	char A[1005][1005];
	int d[1005][1005];
	rep(i,H)rep(j,W){
		cin>>A[i][j];
		if(A[i][j]=='#')d[i][j]=0;
		else d[i][j]=INF;
	}
	
	rep(i,H){
		int now=d[i][0];
		rep1(j,W-1){
			now++;
			d[i][j]=min(now,d[i][j]);
			now=d[i][j];
		}
		now=d[i][W-1];
		for(int j=W-2;j>=0;j--){
			now++;
			d[i][j]=min(now,d[i][j]);
			now=d[i][j];
		}
	}

	rep(i,W){
		int now=d[0][i];
		rep1(j,H-1){
			now++;
			d[j][i]=min(now,d[j][i]);
			now=d[j][i];
		}
		now=d[H-1][i];
		for(int j=H-2;j>=0;j--){
			now++;
			d[j][i]=min(now,d[j][i]);
			now=d[j][i];
		}
	}
//	rep(i,H){
  //  	rep(j,W){
  //      	cout<<d[i][j]<<" ";
  //      }
 //     cout<<endl;
//    }	
  
	int ans=0;
	rep(i,H)rep(j,W)ans=max(ans,d[i][j]);
	cout<<ans<<endl;

	
}

Measured memory_bytes: 5120
N,M = map(int,input().split())
vertex = [[0 for j in range(N+1)] for i in range(N+1)]

for i in range(M):
    a,b = map(int,input().split())
    vertex[a][b] = 1
    vertex[b][a] = 1

from itertools import permutations

ans = 0
for v in permutations([i+2 for i in range(N-1)], N-1):
    v = [1] + list(v)
    canmake = 1
    for j in range(N-1):
        if not vertex[v[j]][v[j+1]]:
            canmake = 0
            break
    if canmake:
        ans += 1
print(ans)

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N);
  vector< ll > a(N);
  REP(i, N) {
    cin >> a[i];
  }
  vector< ll > b(N);
  REP(i, N) {
    cin >> b[i];
  }
  // sort(ALL(a));
  // sort(ALL(b));

  ll tmp = 0ll;
  REP(i, N) {
    ll tmp2 = b[i] - a[i];
    if (tmp2 < 0) {
      tmp += tmp2;
    } else {
      if (tmp2 > 1) {
	tmp += tmp2 / 2ll;
      }
    }
  }
  debug(tmp);
  // cout << (-1 / 2) << endl;

  OK(tmp >= 0);

  return 0;
}



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

int GetCommon(int a, int b, int c)
{
    int m = min(a,b);
        m = min(m,c);

    for(int i = m; i >0; --i)
    {
        if(a%i ==0 && b%i ==0 && c%i ==0)
        {
            return i;
        }
    }
    return 1;
}

int main(void) 
{
    int k;
    cin >> k;
    ll ans =0;

    for(int a = 1; a <=k ; ++a)
    for(int b = 1; b <=k ; ++b)
    for(int c = 1; c <= k; ++c)
    ans += GetCommon(a,b,c);

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vec vector
#define vi vec<int>
#define vvi vec<vec<int>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define UNIQUE(a) a.erase(unique(ALL(a)), end(a))
#define lambda(i) [](auto& i)
#define compare(i, j) [](auto& i, auto& j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(a) (int)(a).size()
#define REP(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i != a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

const int INF = 1e18;
const int MOD = 1e9 + 7;

struct union_find {
  vi data;
  union_find(int size) : data(size, -1) { }
  bool union_set(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find_set(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

vi cum(vi V) {
  vi U(SZ(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  int n;
  int ans = 0;

  cin >> n;
  vi a(n), b(n), c(n), b_a(n + 1);
  REP(i, n) {
    cin >> a[i];
  }
  REP(i, n) {
    cin >> b[i];
  }
  REP(i, n) {
    cin >> c[i];
  }
  SORT(a);
  SORT(b);
  SORT(c);
  REP(i, n) {
    int index = lower_bound(ALL(a), b[i]) - begin(a);
    b_a[i] += index;
    b_a[i + 1] = b_a[i];
  }
  REP(i, n) {
    int index = lower_bound(ALL(b), c[i]) - begin(b);
    if (index < 1) continue;
    ans += b_a[index - 1];
  }

  cout << ans << endl;
  // REP(i, n) {
  //   cout << v[i];
  // }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <algorithm>
#include <vector>
#include <queue>
#define int long long
using namespace std;
 
signed main(){
    int n;
    int max=0;
    int min=0;
    cin>> n;
    int N=3*n;
    int a[N];
 
    priority_queue<int> PQ1;
    priority_queue<int, vector<int>, greater<int> >PQ2;
 
    int max_arr[n+1]={0};
    int min_arr[n+1]={0};
    
    for(int i=0;i<3*n;i++){
        cin>>a[i];
        
    }
 
    for(int i=0;i<n;i++){
        max+=a[i];
        min+=a[i+2*n];
    }
 
    // cout<<max<<" "<<min<<endl;
 
    max_arr[0]=max;
    
    for(int i=0;i<n;i++){
        PQ2.push(a[i]);
    }
 
    for(int i=n;i<2*n+1;i++){
        PQ2.push(a[i]);
        max+=a[i];
        max-=PQ2.top();
        PQ2.pop();
        max_arr[i-n+1]=max;
 
    }
 
    // for(int i=0;i<n+1;i++){
    //     cout<<max_arr[i]<<" ";
    // }
 
    min_arr[n]=min;
    for(int i=2*n;i<3*n;i++){
        PQ1.push(a[i]);
    }
    for(int i=3*n;i>2*n;i--){
        // cout<<i-n-1<<endl;
        PQ1.push(a[i-n-1]);
        min+=a[i-n-1];
        min-=PQ1.top();
 
        // cout<<PQ1.top()<<endl;
        PQ1.pop();
        min_arr[(i-2*n)-1]=min;
    }
    // cout<<count<<endl;
 
 
    // for(int i=0;i<n+1;i++){
    //     cout<<min_arr[i]<<" ";
    // }
 
 
    // for(int i=0;i<n+1;i++){
    //     max[i]=
    // }
 
    int ans=-1e19;
    for(int i=0;i<n+1;i++){
        if(ans<max_arr[i]-min_arr[i]){
            ans=max_arr[i]-min_arr[i];
        }
        // ans=max(ans,);
    }
    cout<<ans<<endl;
 
}

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

void insertionSort(int *A, int N){
    int v, j;
    for(int i=1; i<N; i++){
        for(int i=0; i<N; i++) {
            cout << A[i];
            if(i != N-1) cout << " ";
        }
        cout << endl;
        v = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
            A[j+1] = v;
        }
    }
}

int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i=0; i<N; i++) cin >> A[i];
    
    insertionSort(A, N);
    for(int i=0; i<N; i++) {
        cout << A[i];
        if(i != N-1) cout << " ";
    }
    cout << endl;
}



Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_081
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int[] array = ReadInts();
            var cntArray = new int[200000];
            for (int i = 0; i < nk[0]; i++)
            {
                cntArray[array[i] - 1]++;
            }
            Array.Sort(cntArray);
            int changeCnt = 0;
            int iterator = 0;
            while (nk[1] < 200000 - iterator)
            {
                changeCnt += cntArray[iterator];
                iterator++;
            }
            Console.WriteLine(changeCnt);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

char a[10];
int main(){
	cin >> a;

	for(int i = 0;i < 4;i++) {
		a[i] -= '0';//aを文字コードから数字に変換する処理を書く
	}

	for(int i = 0;i < (1 << 3)/* +か-かを3回選ぶ時何回繰り返すのか？ */;i++) {

		int s = a[0];//計算結果を入れる変数を用意して、適切な値で初期化しよう。

		for(int j = 0;j < 3/*計算する回数はいくらかな? */;j++) {
			if(i & (1 << j)/*演算子が+だったら*/) {
				s += a[j + 1];//14行目で宣言した変数に値を加算代入
			}else {
				s -= a[j + 1];//14行目で宣言した変数に値を減算代入
			}
		}

		if(s == 7/*計算結果が7だったら*/) {
			printf("%d",a[0]);//第一項を出力
			for(int j = 0;j < 3/*演算子を出力する回数はいくつか？*/;j++) {
				if(i & (1 << j)/*演算子が+だったら*/) {
					printf("+");// +を出力
				}else {
					printf("-");// -を出力
				}
				printf("%d",a[j + 1]);//演算子の右の数字を出力
			}
			printf("=7\n");//=7改行 を出力
			break;//見つかったので終了する。
		}
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
D = list(map(int, input().split()))
ans = 0
lb, ub = -1, min(D) + 1
while ub - lb > 1:
    m = (lb + ub) // 2
    group = [0] * N
    for k in range(N):
        if group[k] != 0:
            continue
        group[k] = 1
        stack = [k]
        while stack:
            i = stack.pop()
            for j in range(N):
                if i == j or group[j] != 0:
                    continue
                diff = abs(D[i]-D[j])
                if min(diff, 24-diff) < m:
                    group[j] = group[i] * -1
                    stack.append(j)
    ok = True
    for i in range(N):
        for j in range(i):
            diff = abs(D[i]*group[i]-D[j]*group[j])
            if min(diff, 24-diff) < m:
                ok = False
                break
        if not ok:
            break
    if not ok:
        ub = m
    else:
        lb = m
print(lb)

Measured memory_bytes: 39664
#include <stdio.h>

int main(void)
{
  char t[1000000];
  scanf("%s", t);
  for(long int i=0;t[i]!='\0';i++){
    if(t[i]=='?'){
      t[i]='D';
    }
  }
  printf("%s\n", t);
  return 0;
}


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

using namespace std;
using ll = long long;

int main(){
    int n;
    while( cin >> n ){
        vector<int>v(n);
        for( int i = 0; i < n; i++ ){
            cin >> v[i];
        }
        sort( v.begin(), v.end() );
        int res = INT_MAX;
        for( int i = 1; i <= 100; i++ ){
            int sum = 0;
            for( int j = 0; j < n; j++ ){
                sum += (v[j]-i)*(v[j]-i);
            }
            res = min( res, sum );
        }
        cout << res<< endl;
    }
}


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

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int n;cin>>n;
  int pt=0, px=0, py=0;
  bool ans=true;
  for(int i=0;i<n;i++){
  	int t, x, y;cin>>t>>x>>y;
    int d = abs(x-px)+abs(y-py);
    if(d>t || (t-d)%2)ans=false;
  }
  cout<<(ans?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[str]"):
    ans = 0
    for i in range(60):
        z = 0
        o = 0
        for a in A:
            if i + 1 > len(a):
                z += 1
            else:
                if a[len(a) - i - 1] == '0':
                    z += 1
                else:
                    o += 1
        ans += (z * o) * (2 ** i)
        ans %= MOD
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [bin(int(next(tokens)))[2:] for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 174644