akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	vector <int> A(n);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		if (i > 0) {
			if (1LL * (A[i] - A[i - 1]) * a < b) {
				ans += 1LL * (A[i] - A[i - 1]) * a;
			}
			else {
				ans += b;
			}
		}
	}
	cout << ans;
		
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;
long long second[21];
long long second_sum[21][200010]={};
//status unsolved


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

    
    long long a[n+1];
    rep2(i,n){
        cin>>a[i];
    }
    long long ans=0;
    int r=1;
    long long sum=0;
    for(int l=1;l<=n;l++){
        while(r<n+1 &&(sum^a[r])==(sum+a[r])){
            sum+=a[r];
            r++;
        }
        ans+=r-l;
        if(r==l)r++;
        else{
            sum-=a[l];
        }
    }
    cout<<ans<<endl;

    
    return 0;
}
/*


*/


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
vector<int> v[101010];
int n,k,a,y,i=1;
int s(int x,int p=0){
    int r=0;
    for(auto to:v[x])r=max(r,s(to,x));
    if(++r>=k&&p)a++,r=0;
    return r;
}
int main(){
    cin>>n>>k>>y;
    if(y!=1)a++;
    for(;i<n;i++){
        cin>>y;
        v[y-1].push_back(i);
    }
    s(0);
    cout<<a;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int n;
  cin >> n;
  int h[100000];
  REP(i, n)
  {
    cin >> h[i];
  }

  REP(i, n - 1)
  {
    if (h[i] - h[i + 1] >= 2)
    {
      cout << "No" << endl;
      return 0;
    }
    if (h[i] - h[i + 1] == 1)
    {

      h[i + 1]++;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()


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

	rep(i, N)
	{
		int a;
		cin >> a;

		if (a % 2 != 0) continue;

		if (a % 3 != 0 && a % 5 != 0)
		{
			cout << "DENIED" << endl;
			return 0;
		}
	}

	cout << "APPROVED" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int a , b , result ;
    char op ;
    while( true ) {
        std::cin >> a >> op >> b ;
        if( op == '?' ) {
            break ;
        } else {
            switch( op ) {
                case '+' :
                    result = a + b ;
                    break ;
                case '-' :
                    result = a - b ;
                    break ;
                case '*' :
                    result = a * b ;
                    break ;
                case '/' :
                    result = a / b ;
                    break ;
            }
        }
        std::cout << result << std::endl ;
    }
}


Measured memory_bytes: 3088
#include <stdio.h>

int main(void) {
	int n,a[10], i, max = 0;
	
	scanf("%d", &n);
	
	for(i = 0; n > i; i++){
		scanf("%d", &a[i]);
		if(max < a[i]) max = a[i];
	}
	
	for(i = 1; ; i++){
		long int buf = max*i;
		int c, f = 0;
		
		for(c = 0; n > c; c++){
			if(buf % a[c]){
				f = 1;
				break;
			}
		}
		
		if(!f){
			printf("%ld\n", buf);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
lst=[]
for i in range(20):
    n=int(input())
    lst.append(n)

lst1=lst[0:10]
lst2=lst[10:20]
lst1.sort(reverse=True)
lst2.sort(reverse=True)
lst3=lst1[0:3]
lst4=lst2[0:3]

print(sum(lst3),sum(lst4))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 3e5 + 10;
int cnt1[MAXN], cnt2[MAXN];
void solve() {
    int h, w, n;
    cin >> h >> w >> n;
    set <pii> a;
    for(int i = 1; i <= n; ++i) {
        int x, y;
        cin >> x >> y;
        cnt1[x]++;
        cnt2[y]++;
        a.insert(mp(x, y));
    }
    int mx = *max_element(cnt1 + 1, cnt1 + h + 1);
    int mx2 = *max_element(cnt2 + 1, cnt2 + w + 1);
    veci x, y;
    for(int i = 1; i <= h; ++i) if(cnt1[i] == mx) x.pb(i);
    for(int i = 1; i <= w; ++i) if(cnt2[i] == mx2) y.pb(i);
    int ans = 0;
    for(auto v : x)
        for(auto u : y) {
            int ch = a.count(mp(v, u));
            ans = max(ans, cnt1[v] + cnt2[u] - ch);
            if(!ch) break;
        }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}


Measured memory_bytes: 23820
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
	int n,cnt=0;
	while(cin >> n){
		for(int a=0;a<10;a++){
			for(int b=0;b<10;b++){
				for(int c=0;c<10;c++){
					for(int d=0;d<10;d++){
						if(a + b + c + d == n){
							cnt++;
						}
					}
				}
			}
		}
	cout << cnt << endl;
	cnt=0;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  vector<int> vec(3);
  cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
  sort(vec.begin(), vec.end());
  cout << vec.at(0) << " " << vec.at(1) << " " << vec.at(2) << endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	long long ans=0;
	for(int i=0;i<n-k;i++)
	{
		ans+=a[i];
	}
	cout<<ans;

    return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int N=Integer.parseInt(br.readLine());
		String s=br.readLine();
		int num;
		if(N>1){
	        num=Integer.parseInt(s.substring(0, s.indexOf(" ")));
		}else{
			num=Integer.parseInt(s.substring(0));
		}
        int min=num,max=num;
        long sum=num;
		if(N>1){
	        List<String> a=Arrays.asList(s.substring(s.indexOf(" ")+1).split(" "));
	        for(String n:a){
	        	num=Integer.parseInt(n);
	            if(num<min) min=num;
	            if(num>max) max=num;
	            sum+=num;
	        }
		}
        System.out.println(min+" "+max+" "+sum);
	}
}

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

ll N;

ll f(ll x){
  ll res=0;
  while(x>0){
    res++;
    x/=10LL;
  }
  return res;
}

int main(){
  ll ans=1e9;
  cin>>N;
  for(ll i=1;i*i<=N;i++){
    if(N%i>0)continue;
    ll A=i;
    ll B=N/i;
    ans=min( ans, max( f(A) , f(B) ) );
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() 
{
	long long n;
    cin >> n;
    long long ans = LLONG_MAX;

    for(long long i=1;i<=sqrt(n);i++) {
        long long comp = n / i;
        if(comp * i == n) {
            ans = min(ans, i + comp - 2);
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


struct Node
{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k)
{
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while (x != NIL)
	{
		y = x;
		if (z->key < x->key)
		{
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if (y == NIL)
	{
		root = z;
	} else {
		if (z->key < y->key)
		{
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u)
{
	if (u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u)
{
	if (u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}


int main()
{
	int n, i, x;
	string com;
	
	cin >> n;
	REP(n)
	{
		cin >> com;
		if (com == "insert")
		{
			cin >> x;
			insert(x);
		} else if (com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			cout << endl;
		}
	}
	
	return 0;
}


void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}


double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

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

int w , h , a , b , dp[105][105];
char s[105][105];

signed main(){
  cin >> h >> w;
  for(int i=0 ;i<h ;i++ ){
    for(int j=0 ;j<w ;j++ ){  
      cin >> s[i][j];
    }
  }
  
  if(s[0][0] == '#'){
    dp[0][0] = 1;
  } else {
    dp[0][0] = 0;
  }
  
  for(int i=1 ;i<h ;i++){
    a = dp[i-1][0];
    if(s[i][0] == '#' && s[i-1][0] == '.'){
      a++;
    }
    dp[i][0] = a;
  }
  for(int j=1 ;j<w ;j++){
    b = dp[0][j-1];
    if(s[0][j] == '#' && s[0][j-1] == '.'){
      b++;
    }
    dp[0][j] = b;
  }
  
  for(int i=1 ;i<h ;i++){
    for(int j=1 ;j<w ;j++){
      a = dp[i-1][j] , b = dp[i][j-1];
      if(s[i][j] == '#' && s[i-1][j] == '.'){
        a++;
      }
      if(s[i][j] == '#' && s[i][j-1] == '.'){
        b++;
      }
      dp[i][j] = min(a,b);
    }
  }
  
  cout << dp[h-1][w-1] << endl;
  return(0);
}

Measured memory_bytes: 256
H,W=map(int,input().split())
C=[]
for i in range(10):
    c=list(map(int,input().split()))
    C.append(c)
decide=set()
INF=10**9
cost=[INF]*10
def check(cost):
    for i in cost:
        if i==INF:
            return True
    return False
while(check(cost)):
    l=-1
    m=INF
    for j in range(10):
        for i in range(10):
            if i in decide:
                continue
            c=min(C[i][1],C[i][j]+cost[j])
            if c<m:
                m=c
                l=i
    cost[l]=m
    decide.add(l)
ans=0
for i in range(H):
    A=list(map(int,input().split()))
    for j in A:
        if j==-1:
            continue
        ans+=cost[j]
print(ans)


Measured memory_bytes: 41452
x,y,a,b,c=map(int,input().split())
pt=sorted(list(map(int,input().split())),reverse=True)
qt=sorted(list(map(int,input().split())),reverse=True)
r=sorted(list(map(int,input().split())),reverse=True)
p=pt[:x]
q=qt[:y]

prev=sorted(p)
qrev=sorted(q)

#print(p,q,r,prev,qrev)

saisho=[0]*(x+y)

pgen=0
qgen=0
genzai=0
gokei=0
powari=False
for i in range(a+b):
    if(prev[pgen]<qrev[qgen]):
        genzai+=prev[pgen]
        pgen+=1
    else:
        genzai+=qrev[qgen]
        qgen+=1
    saisho[i]=genzai
    if(pgen==x):
        powari=True
        gokei=i+1
        break
    if(qgen==y):
        gokei=i+1
        break

if(powari):
    for i in range(y-qgen):
        genzai+=qrev[qgen+i]
        saisho[gokei+i]=genzai
else:
    for i in range(x-pgen):
        genzai+=prev[pgen+i]
        saisho[gokei+i]=genzai


zenbu=saisho[x+y-1]
#print(saisho)
#print(zenbu)

sikokaisu=min(c,x+y)

ans=[0]*sikokaisu

genc=0
for i in range(sikokaisu):
    genc+=r[i]
    ans[i]=zenbu-saisho[i]+genc

#print(ans)

print(max(zenbu,max(ans)))

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

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

#define rep(i,n) for(int i=(0);i<(n);i++)

int main(){
    // A:0, G:1, C:2, T:3
    // 部分文字列として AGC, GAC, ACG, A?GC, AG?C のいずれも含まない (? は何らかの 1 文字)
    // 012, 102, 021, 0?12, 01?2
    int N;
    cin >> N;

    long long MOD = 1e9 + 7;
    auto dp = make_vec<long long>(N+1, 4, 4, 4); // nまでの実現可能な文字列の通り
    // fill_v(dp, 0); // make_vecで作った多次元vectorを任意の値で初期化する
    
    // 初期化
    rep(n,N+1) rep(i,4) rep(j,4) rep(k,4) dp[n][i][j][k] = 0;
    rep(i,4) rep(j,4) rep(k,4){
        if(i==0 && j==1 && k==2) continue;
        if(i==1 && j==0 && k==2) continue;
        if(i==0 && j==2 && k==1) continue;
        else dp[3][i][j][k] = 1;
    }

    // dp
    for(int n = 4; n < N+1; n++){
        rep(i,4) rep(j,4) rep(k,4) rep(l,4){
            if(        j==0 && k==1 && l==2) continue;
            if(        j==1 && k==0 && l==2) continue;
            if(        j==0 && k==2 && l==1) continue;
            if(i==0         && k==1 && l==2) continue;
            if(i==0 && j==1 &&         l==2) continue;
            dp[n][j][k][l] += dp[n-1][i][j][k] % MOD;
        }
    }

    // sum
    long long res = 0;
    rep(i,4) rep(j,4) rep(k,4){
        res += dp[N][i][j][k];
        res %= MOD;
    }
    
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
    int a[10],i,j,l;
    for(i=0;i<10;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<9;i++){
        for(j=i;j<10;j++){
            if(a[i]<a[j]){
                a[i] = a[i] ^ a[j];
                a[j] = a[i] ^ a[j];
                a[i] = a[i] ^ a[j];
            }
        }
    }
    printf("%d\n%d\n%d\n",a[0],a[1],a[2]);

    return 0;
}

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

int main() {
  string s1 ;
  cin >> s1 ;
  
  int x =s1.size();
  string s2 ;
  string s3 ;
  
  for(int i=0;i<(x-1)/2;i++){
    s2+=s1.at(i);
  }
  
  for(int j=(x+3)/2-1;j<x;j++){
    s3+=s1.at(j);
  }
  
  string s4=s1;
  string s5=s2;
  string s6=s3;
  
  reverse(s4.begin(),s4.end());
  reverse(s5.begin(),s5.end());
  reverse(s6.begin(),s6.end());
  
  if(s1==s4&&s2==s5&&s3==s6){
    cout <<"Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }

}

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

#define ll long long int

ll n,k;
ll h[100002];

ll memo[100002];

ll fil(ll s)
{
    if(s==n)return 0;
    if(memo[s]!=-1)return memo[s];

    ll ans=INT_MAX;
    for(ll i=s+1;i<=n && i<=s+k;i++)
    {
        ans=min(ans,fil(i)+abs(h[i]-h[s]));
    }
    memo[s]=ans;
    return ans;
}
int main()
{
    cin>>n>>k;
    for(ll i=1;i<=n;i++)cin>>h[i];
    memset(memo,-1,sizeof(memo));

    cout<<fil(1);
}


Measured memory_bytes: 6528
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1),i=new(n(2))(r.readFileSync("/dev/stdin","utf8").trim().split(/\s+/g));n(4)(i)},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3);t.exports=class{constructor(t){this.inp=new r(t)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}add(t){this.inp.enq(t)}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}}},function(t,e,n){"use strict";t.exports=function(t){var e=[t.in(),t.in(),t.in()];e.sort(function(t,e){return t-e}),console.log(e[0]+e[1])}}]);

Measured memory_bytes: 22964
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char a = s.charAt(0);
        int c = 1;
        char b ='a';
        int d = 0;
        boolean ans = true;
        for (int i = 1; i < 4; i++) {
            if(a != s.charAt(i) && d == 0){
                b = s.charAt(i);
                d++;
            }else if(a == s.charAt(i)){
                c++;
            }else if(b == s.charAt(i)){
                d++;
            }else{
                ans = false;
            }
        }
        if(c != 2 || d != 2) ans = false;
        System.out.println(ans ? "Yes" : "No");
        sc.close();
    }

}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, Q;
  cin >> N >> Q;
  vector<PII> xs(N);
  REP(i,N){
	cin >> xs[i].FF;
	xs[i].SS = i;
  }
  SORT(xs);

  VI tab(N);
  REP(i,N) tab[xs[i].SS] = i;
  set<int> leader;
  while(Q--){
	int x;
	string S;
	cin >> S >> x;
	if(S[0] == 'A'){
	  leader.insert(x-1);
	}
	else if(S[0] == 'R'){
	  leader.erase(x-1);
	}
	else{
	  if(leader.empty()){
		if(x < N) cout << "NA" << endl;
		else cout << 0 << endl;
		continue;
	  }
	  vector<int> sc;
	  for(int x: leader)
		sc.PB(xs[tab[x]].FF);
	  SORT(sc);
	  
	  int lb = -1, ub = 1e9+10;
	  while(ub-lb>1){
		int m = (lb + ub) / 2;

		int l = 0, sum = 0;
		for(int s: sc){
		  int lx = lower_bound(ALL(xs), MP(s-m,-1)) - begin(xs);
		  int rx = lower_bound(ALL(xs), MP(s+1,-1)) - begin(xs);
		  sum += rx - max(l, lx);
		  l = rx;
		}
		if(N-sum <= x) ub = m;
		else lb = m;
	  }

	  if(ub == 1e9+10)
		cout << "NA" << endl;
	  else
		cout << ub << endl;
	}
  }

  return 0;
}



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

int main(){
  long long N;
  cin >> N;
  vector<long long> L(N+1);
  L.at(0)=2;
  L.at(1)=1;
  for(int i=2; i<=N; i++){
    L.at(i)=L.at(i-1)+L.at(i-2);
  }
  cout << L.at(N) << endl;
}

Measured memory_bytes: 256
using System;

public class Hello{
	public static void Main(){
      int[] array = new int [100];
      int N = int.Parse(Console.ReadLine());
      int Sum = 0;
      int Sum_2a=0;
      int Sum_2b=0;
      int Avg;
      string[] s = Console.ReadLine().Split(' ');
      for(int i=0;i<N;i++){
        array[i]=int.Parse(s[i]);
        Sum = Sum +array[i];
      }
      Avg=Sum/N;
      for(int i=0;i<N;i++){
        Sum_2a=Sum_2a+(array[i]-Avg)*(array[i]-Avg);
        Sum_2b=Sum_2b+(array[i]-(Avg+1))*(array[i]-(Avg+1));
      }
      if(Sum_2a<Sum_2b){
        Console.WriteLine(Sum_2a);
      }
      else Console.WriteLine(Sum_2b);
	}
}



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

#define loop(n, i) for(int i=0;i<n;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using vec = vector<T>;

const ll INF = 1LL << 50;

int sig(int k) {
    return (k % 2) * 2 - 1;
}

ll x[1010], y[1010], z[1010];
ll dp[1010][1010][8] = {};
int main() {
    int n, m; cin >> n >> m;
    loop (n, i) cin >> x[i] >> y[i] >> z[i];

    loop (m, i) loop (8, j) dp[0][i + 1][j] = -INF;
    loop (n, i) loop (m, j) loop (8, k) {
        dp[i + 1][j + 1][k] = max(
            dp[i][j + 1][k],
            dp[i][j][k] + sig(k) * x[i] + sig(k >> 1) * y[i] + sig(k >> 2) * z[i]
        );
    }

    ll ans = 0;
    loop (8, i) ans = max(ans, dp[n][m][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 63872
#include <iostream>
using namespace std;
#define rep(i, n);for(int i=1;i<=n;++i)
int main(void){
    int n;
    cin >> n;
    rep(kk, n){
        int cnt = 0;
        rep(i, n-2){
            if(i*i+i+i+3>kk) break;
            rep(j, n-i+1){
                if(i*i + j*j + i*j + i + j + 1 > kk) break;
                rep(k, n-i-j+2){
                    int res = i*i + j*j + k*k + i*j + j*k + k*i;
                    if (res==kk){
                        cnt++;
                    } else if(res > kk){
                        break;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3588
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def contains_digit(number, digits):
    while number != 0:
        if number%10 in digits:
            return True
        number //= 10
    return False


def solve():
    N, K = read_ints()
    digits = set(read_ints())
    while contains_digit(N, digits):
        N += 1
    return N


if __name__ == '__main__':
    print(solve())

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

using namespace std;

#define ll long long

int n;
string s;

void solve() {
  cin >> n >> s;
  ll ans = 1;
  for (int i = 0; i < n-1; i++) {
    if (s[i+1]!=s[i]) {
      ans++;
    }
  }
  cout << ans << '\n';
}

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


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

int main()
{
  long long n,x,t;

  cin >> n >> x >> t;

  long long ans = 0;

  for(;;){
    if(n<=0){
      break;
    }

    n -= x;
    ans += t;
  }

  cout << ans;
  
}


Measured memory_bytes: 3620
from itertools import chain
 
n,m,k = map(int,input().split())
 
bff = [list(map(int,input().split())) for i in range(m)]
 
blk = [list(map(int,input().split())) for i in range(k)]
 
 
rank = [0] * (n+1)
par = [i for i in range(n+1)]
demi = [1] * (n+1)
 
 
for i,j in bff:
    x = par[i]
    y = par[j]
    while x != par[x]:
        x = par[x]
    while y != par[y]:
        y = par[y]
    if(x == y):
        continue
    
    if rank[x] < rank[y]:
        par[x] = y
        demi[y] += demi[x]
        
    else:
        par[y] = x
        demi[x] += demi[y]
        
        if rank[x] == rank[y]:
             rank[x] += 1
 
 
for i in range(n):
    x = par[i+1]
    while x!=par[x]:
        x = par[x]
    par[i+1] = x
 
 
for i in range(n):
    x = par[i+1]
    while x!=par[x]:
        x = par[x]
    demi[i+1] = demi[x]
 
 
 
a = list(chain.from_iterable(bff))
b = list(chain.from_iterable(blk))
 
fqua = [0] * n
bqua = [0] * n
 
for i,j in bff:
    if(par[i] == par[j]):
        fqua[i-1] += 1
        fqua[j-1] += 1
 
for i,j in blk:
    if(par[i] == par[j]):
        bqua[i-1] += 1
        bqua[j-1] += 1
 
for i in range(n):
    print(demi[i+1] - fqua[i] - bqua[i] - 1 ,end=" ")

Measured memory_bytes: 110348
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
T,A = MI()
for _ in range(N-1):
    t,a = MI()
    x = (T+t-1)//t
    y = (A+a-1)//a
    if x >= y:
        T,A = t*x,a*x
    else:
        T,A = t*y,a*y

print(T+A)


Measured memory_bytes: 64552
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 2;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  string s, t;
  cin >> s >> t;
  ll n = s.length();
  vector<ll> pos[26];
  rep(i, n)
  {
    pos[s[i] - 'a'].push_back(i);
  }
  ll now_pos = -1;
  ll loop = 0;
  rep(i, t.length())
  {
    int c = t[i] - 'a';
    if (pos[c].empty())
    {
      cout << -1 << endl;
      return 0;
    }
    auto itr = upper_bound(all(pos[c]), now_pos);
    if (itr == pos[c].end())
    {
      loop++;
      now_pos = pos[c][0];
    }
    else
    {
      now_pos = *itr;
    }
  }
  cout << loop * n + now_pos + 1 << endl;
  return 0;
}

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

int main(){
  string st,ans = "yes";
  //int flg = 0;

  cin >> st;

  for(int i = 0; i < st.size(); i++){
    for(int j = 0; j < st.size(); j++){
      if(i != j and st[i] == st[j]) ans = "no";
    }
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
typedef long long ll;
using namespace std;
int main(){
  int n;
  cin>>n;
  cout<<n*n*n<<endl;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
 
time_list = [A, B, C, D, E]
# 最後の一品以外は切り上げ時刻の和を取ることに等しい
time_list_upper = [(((time - 1)//10)+1)*10 for time in time_list]
# 最後の一品は1の位が1～9で最小のやつ。
time_list_ones = [(time - 1) % 10 for time in time_list]
smallest_idx = time_list_ones.index(min(time_list_ones))
smallest = time_list.pop(smallest_idx)
time_list_upper.pop(smallest_idx)
 
print(sum(time_list_upper) + smallest)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define input(array) repi(array##_itr, array) { cin >> *(array##_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	bool ans=true;
	cin >>s;
	set<char> dis;
	rep(i, s.size()) { dis.insert(s[i]); }

	cout<<solve(dis.count('N')==dis.count('S') and dis.count('W')==dis.count('E'))<<endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
using namespace std;
int h1,m1,h2,m2,k;

int main() {
  INCANT;
  cin >> h1>>m1>>h2>>m2>>k;
  int tm = 0;
  tm+=m2-m1;
  tm+=(h2-h1)*60;
  cout << tm -k << endl;
  return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using ll=long long;

const ll INF = pow(10,18)+1;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}
template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}
 
int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if((A < C && C < B) || (A > C && C > B)){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int 
main(){
	char s[4];
	int i;
	char tmp[4];
	int j=0;
	scanf("%s",s);
	static int cnt[4];
	int k;
	int l=0;
	for(i=0;i<4;i++){
		tmp[j]=s[i];
		for(k=i+1;k<4;k++){
			if(tmp[j]==s[k])cnt[l]++;
		}
		if(cnt[l]!=0)l++;
	}
	if(cnt[0]*cnt[1] == 1)printf("Yes\n");
	else printf("No\n");

 return 0;
}

Measured memory_bytes: 128
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1138&lang=ja
// ICPC:	国内予選2005D
// Traveling by Stagecoach

/*
Problem.
m個の都市を繋ぐp個の道があり,
各道について 都市１、都市２、距離が与えられる。
道を移動するためには馬車が必要で、馬車のチケットがn枚
与えられる。
チケットごとに馬の頭数が決められていて、移動時間は
距離/頭数で与えられる。
各チケットは一回ずつのみ使用可能である。
都市aから都市bへの最短移動時間を求めよ

Point.
dp[移動状態(bit)][都市]:移動状態の都市への移動時間の最小値
dp[次の状態(現在 | チケット種類)][次の都市] = min(dp[次の状態][次の都市], dp[今の状態][今の都市] + 距離/頭数)
*/

#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vvd = vector<vector<double> >;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pair<int, int>, int>;

#define INF 1e15

int n, m, p, a, b;
void solve(){
  vd ticket(n);
  for(double &i: ticket) cin >> i;
  vvd road(m, vd(m, INF));
  for(int i = 0; i < p; i++){
    int x, y; double z;
    cin >> x >> y >> z;
    x--, y--;
    road[x][y] = z;
    road[y][x] = z;
  }
  vvd dp(1<<n, vd(m, INF));
  dp[0][a] = 0;
  for(int i = 0; i < (1<<n); i++){
    for(int j = 0; j < m; j++){
      for(int k = 0; k < m; k++){
        if(road[j][k] == INF) continue;
        for(int l = 0; l < n; l++){
          if(i >> l & 1) continue;
          dp[i | 1 << l][k] = min(dp[i | 1 << l][k], dp[i][j]+(double)road[j][k]/ticket[l]);
        }
      }
    }
  }
  double ans = INF;
  for(int i = 0; i < (1<<n); i++) ans = min(ans, dp[i][b]);
  if(ans != INF) cout << fixed << setprecision(10) << ans << endl;
  else cout << "Impossible" << endl;
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  //start-----------------------------------------------
  while(cin >> n >> m >> p >> a >> b && n){
    a--, b--;
    solve();
  }
  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}



Measured memory_bytes: 3416
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);


int N;
int A[100000];
int main() {
	cin >> N;
	rep(i, N) cin >> A[i];

	sort(&A[0], &A[N]);

	set<int> S;
	vector<int> V;
	for(int i = N-1; i >= 0; i--){
		int a = A[i];
		if(S.find(a) != S.end()){
			S.erase(a);
			V.push_back(a);
		}
		else{
			S.insert(a);
		}
	}

	if (V.size() < 2) {
		cout << 0 << endl;
	}
	else{
		ll r1 = V[0];
		ll r2 = V[1];
		cout << r1 * r2 << endl;
	}
}

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

#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace atcoder;
using namespace std;
using namespace boost;
using namespace boost::adaptors;

using Mod = modint998244353;

Mod op(Mod lhs, Mod rhs) { return lhs + rhs; }

Mod e() { return Mod(0); }

Mod mapping(Mod m, Mod v) { return m * v; }

Mod composition(Mod l, Mod r) { return l * r; }

Mod id() { return Mod(1); }

using ST = lazy_segtree<Mod, op, e, Mod, mapping, composition, id>;

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

    vector p(n, 0L);
    for (auto&& pp : p) {
        cin >> pp;
    }

    ST st(n + 1), st1(n + 1);

    Mod half = Mod(1) / 2;
    Mod m = Mod(1) - Mod(1) / k;

    Mod ans = 0;
    for (auto i : irange(0L, k)) {
        ans += st.prod(0, p[i]);
        ans += st1.prod(p[i], n + 1);
        ans -= st.prod(p[i], n + 1);

        st.set(p[i], half);
        st1.set(p[i], Mod(1));
    }

    for (auto i : irange(k, n)) {
        st.apply(0, n + 1, m);

        ans += st.prod(0, p[i]);
        ans += st1.prod(p[i], n + 1);
        ans -= st.prod(p[i], n + 1);

        st.set(p[i], half);
        st1.set(p[i], Mod(1));
    }

    cout << ans.val() << endl;
}

Measured memory_bytes: 11720
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define int long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF 0x3f3f3f3f

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

int a,b,c,k;
signed main() {
  IO;
  cin >> a >> b >> c >> k;
  int ans = 0;
  int z1 = min(a,k);
  ans += z1;
  k -= z1;
  int z2 = min(b,k);
  k -= z2;
  int z3 = min(c,k);
  ans -= z3;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int bins(vector<int>& a,int k){
    int ub = a.size();
    int lb = -1;
    while(ub-lb>1){
        int mid = (ub+lb)/2;
        if(a[mid]<=k){
            lb = mid;
        }else{
            ub = mid;
        }
    }
    return ub;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> b(n+1);
    vector<int> c(n+1);
    REP(i,n){
        cin >> a[i];
    }
    a[n] = INT_MAX;
    REP(i,n){
        cin >> b[i];
    }
    b[n] = INT_MAX;
    REP(i,n){
        cin >> c[i];
    }
    c[n] = INT_MAX;
    ll res = 0;
    SORT(a);
    SORT(b);
    SORT(c);
    vector<vector<ll>> d(3,vector<ll>(n,0));
    vector<vector<ll>> sd(3,vector<ll>(n+1,0));
    REP(i,n){
        int temp = n-bins(c,b[i]);
        d[1][i] = temp;
    }
    reverse(all(d[1]));
    REP(i,n){
        sd[1][i+1] = sd[1][i] + d[1][i];
    }
    REP(i,n){
        int temp =n-bins(b,a[i]);
        res += sd[1][temp];
    }
    put(res);
    return 0;
}


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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;

const int mod = 998244353;
const ll inf = 3e18 + 5;

int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

int main(){
    string s;
    cin >> s;
    int sol = 0;
    for(unsigned int i = 0; i < s.size(); i++){
        int tmp = s[i] - '0';
        sol += tmp;
    }
    if(sol % 9 == 0)
        cout << "Yes";
    else
        cout << "No";
}


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

#define ll long long int
#define hell 1000000007
#define vi vector <ll>
#define pb push_back
#define pii pair<ll,ll>
#define vii vector <pii>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sep(i,a,b)  for(ll i=a-1;i>=b;i--)
#define inf (ll)(1e16)

using namespace std;

void solve()
{
    ll n;
    cin>>n;
    vector < long double> a(n);
    rep(i,0,n)
        cin>>a[i];
    long double ans=0;
    rep(i,0,n)
        ans+=1.0/a[i];
    cout<<fixed<<setprecision(6)<<1.0/ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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

int main() {
	ll n;
	cin >> n;
	cout << (1+(n-1)) * (n-1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
/*
 * AOJ1142_mizo0203.cpp
 *
 *  Created on: 2011/08/18
 *      Author: Satoki
 */
#include <iostream>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

int iM;
string str;
set<string> s;

void init() {
  scanf("%d", &iM);
}

bool input() {
  if (!iM--)
    return false;
  s.clear();
  cin >> str;
  return true;
}

void manage() {
  int i, j;
  string a, b;
  for (i = 1; i < (int) str.length(); i++) {

    for (j = 0; j < 8; j++) {

      string left = str.substr(0, i);
      string right = str.substr(i);

      if (j & 1) {
        reverse(right.begin(), right.end());
      }

      if (j & 2) {
        reverse(left.begin(), left.end());
      }

      if (j & 4) {
        swap(left, right);
      }

      s.insert(left + right);

    }
  }
  printf("%d\n", s.size());
}

int main() {
  init();
  while (true) {
    if (!input())
      break;
    manage();
  }
  return 0;
}

Measured memory_bytes: 1028
N, T = (int(i) for i in input().split())
c_min = 10000
for i in range(N):
    c, t = (int(i) for i in input().split())
    if t <= T:
        if c < c_min:
            c_min = c
print(c_min if c_min != 10000 else 'TLE')

Measured memory_bytes: 38256
#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<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
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;
int N;
ll h[100001];
ll A,B;
ll turnnum(ll turnmin,ll turnmax){
	if(turnmin+1==turnmax) return turnmax;
	ll add=A-B;
	ll addturn=0;
	ll turnmid=(turnmin+turnmax)/2;
	rep(i,N){
		if(h[i]>turnmid*B) addturn+=(h[i]-turnmid*B)/add+((h[i]-turnmid*B)%add ? 1 : 0);
	}
	if(addturn<=turnmid) return turnnum(turnmin,turnmid);
	else return turnnum(turnmid,turnmax);
}
int main(){
	ll hmax=0;
	scan(N);scan(A);scan(B);
	ll add=A-B;
	rep(i,N){
		scan(h[i]);
		hmax=max(hmax,h[i]);
	}
	ll turnmin=0,turnmax=hmax/B+1;
	prin(turnnum(turnmin,turnmax));
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    LL X,Y; cin >> X >> Y;
    LL ans = 1;
    while(1)
    {
        if(X * 2 > Y) break;
        else
        {
            X *= 2;
        }
        ans++;
    }
    cout << ans << endl;

}


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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())
#define din(x) int x; cin >> x

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 450555;
const int M = 1155;

void solve() {
    int n;
    cin >> n;

    ll ans = 1, k = 1e18;
    bool b = false;
    for (int i = 1; i <= n; i++){
        ll x;
        cin >> x;
        if (x == 0){
            cout << 0;
            return;
        }
        if (k/ans < x){
            b = true;
        }
        if (b) continue;
        ans *= x;
    }

    if (!b) cout << ans; else
        cout << -1;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
using namespace std;
char sorw(char c) {
  if (c == 'S') {
    return 'W';
  } else {
    return 'S';
  }
}
string zoo(int n, string s1, string s2) {
  for ( ; n < s1.size(); n++) {
    if ((s1[n] == 'o' && s2[n] == 'S') || (s1[n] == 'x' && s2[n] == 'W')) {
      s2.push_back(s2[n - 1]);
    } else {
      s2.push_back(sorw(s2[n - 1]));
    }
  }
  return s2;
}

bool check(string s) {
  return (s[0] == s[s.size() - 2] && s[1] == s[s.size()  - 1]);
}
int main(void) {
  int n;
  string s;
  cin >> n >> s;
  s.push_back(s[0]);
  string ss = zoo(1, s, "SS");
  string sw = zoo(1, s, "SW");
  string ws = zoo(1, s, "WS");
  string ww = zoo(1, s, "WW");
  if (check(ss)) {
    cout << ss.erase(ss.size() - 2) << endl;
  } else if (check(sw)) {
    cout << sw.erase(sw.size() - 2) << endl;
  } else if (check(ws)) {
    cout << ws.erase(ws.size() - 2) << endl;
  } else if (check(ww)) {
    cout << ww.erase(ww.size() - 2) << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int num[110000];

int main(){
  string S;
  cin>>S;
  S[3]='8';
  cout<<S<<endl;
}


Measured memory_bytes: 256