akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class  Main{
    public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();
        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=sc.nextInt();
        int ans=0;
        for(int i=1;i<n-1;i++) {
        	if((in[i]>in[i-1] && in[i]<in[i+1]) || (in[i]<in[i-1] && in[i]>in[i+1])) {
        		ans++;
        	}
        }
        pw.println(ans);
        pw.flush();
    }
    static StringBuilder tosb(int[]in) {
    	StringBuilder s=new StringBuilder();
    	for(int i=0;i<in.length;i++) {
    		s.append(in[i]+" ");
    	}
    	return s;
    }
    static StringBuilder tosb(long[]in) {
    	StringBuilder s=new StringBuilder();
    	for(int i=0;i<in.length;i++) {
    		s.append(in[i]+" ");
    	}
    	return s;
    }
    
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 24660
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>
#include <stack>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;
vector<ll> p(1300001);

void era(){
    for (int i=2; i<1300001; i++) {
        if(p[i]==0)continue;
        int j=i;
        while (j<1300001) {
            j+=i;
            if(j>=1300001)break;
            p[j]=0;
        }
    }
}

int main(){
    rep(i, 1300001) p[i]=i;
    era();
    for(;;){
        ll n;
        cin >>n;
        if(!n) break;
        ll ans = 0;
        ll i=n,j=n;
        while (p[i]==0) {
            i++;
        }
        while (p[j]==0) {
            j--;
        }
        ans = p[i]-p[j];
        cout << ans <<endl;
    }
}

Measured memory_bytes: 11288
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000


int main(){
	
	int N;
	cin>>N;
	
	vector<int> a(N);
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	
	int mini = 0;
	int ind = 0;
	
	for(int i=0;i<N;i++){
		if(abs(mini)<abs(a[i])){
			mini = a[i];
			ind = i;
		}
	}
	
	cout<<N-1+N-1<<endl;
	
	for(int i=0;i<N;i++){
		if(i==ind)continue;
		cout<<ind+1<<' '<<i+1<<endl;
	}
	
	if(mini>=0){
		for(int i=0;i<N-1;i++){
			cout<<i+1<<' '<<i+2<<endl;
		}
	}
	else{
		for(int i=N-1;i>=1;i--){
			cout<<i+1<<' '<<i<<endl;
		}
	}
	
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>

#define ll long long

using namespace std;

void solve() {
    int n, m, t;
    cin >> n >> m >> t;
    vector<ll> a(n), b(m);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(i > 0) {
            a[i] += a[i - 1];
        }
    }
    for(int i = 0; i < m; i++) {
        cin >> b[i];
        if(i > 0) {
            b[i] += b[i - 1];
        }
    }
    
    int res = upper_bound(b.begin(), b.end(), t) - b.begin();
    for(int i = 0; i < n; i++) {
        if(t < a[i]) {
            break;
        }
        if(b[0] > t - a[i]) {
            res = max(res, i + 1);
            continue;
        }
        // cout << t - a[i] << endl;
        int c = upper_bound(b.begin(), b.end(), t - a[i]) - b.begin();
        res = max(res, c + i + 1);
    }
    
    cout << res <<endl;
}

int main() {
    
    // int T;
    // cin >> T;
    // while(T--) {
        // solve();
    // }
    solve();
    
    return 0;
};


Measured memory_bytes: 6424
/*  union_find_tree_size.cpp
    素集合系を union-find tree で管理するライブラリ
    併合時の工夫：union by size

    verified: AtCoder ABC157 D - Friend Suggestions
        https://atcoder.jp/contests/abc157/tasks/abc157_d
*/

#include <bits/stdc++.h>
using namespace std;

/* UnionFind：素集合系管理の構造体(union by size)
    isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
    unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
    treeSize(x): x を含む集合の要素数。
*/
struct UnionFind {
    vector<int> size, parents;
    UnionFind() {}
    UnionFind(int n) {  // make n trees.
        size.resize(n, 0);
        parents.resize(n, 0);
        for (int i = 0; i < n; i++) {
            makeTree(i);
        }
    }
    void makeTree(int x) {
        parents[x] = x;  // the parent of x is x
        size[x] = 1;
    }
    bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }
    bool unite(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y) return false;
        if (size[x] > size[y]) {
            parents[y] = x;
            size[x] += size[y];
        } else {
            parents[x] = y;
            size[y] += size[x];
        }
        return true;
    }
    int findRoot(int x) {
        if (x != parents[x]) {
            parents[x] = findRoot(parents[x]);
        }
        return parents[x];
    }
    int treeSize(int x) { return size[findRoot(x)]; }
};
using ll = long long;
int main() {
    int N;
    cin >> N;
    const int MAX = 110000;
    UnionFind uf(MAX * 2);
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y + MAX);
    }

    map<int, ll> mx, my;
    for (int i = 0; i < MAX; i++) {
        mx[uf.findRoot(i)]++;
    }
    for (int i = MAX; i < MAX * 2; i++) {
        my[uf.findRoot(i)]++;
    }

    ll ans = 0;
    for (int i = 0; i < 2 * MAX; i++) {
        ans += mx[i] * my[i];
    }
    cout << ans - N << endl;

    return 0;
}


Measured memory_bytes: 29440
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,K;
int A[100010];

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

signed main(){
	cin>>N>>K;
	int M=0;
	REP(i,N){
		cin>>A[i];
		M=max(M,A[i]);
	}
	int G=A[0];
	for(int i=1;i<N;i++){
		G=gcd(G,A[i]);
	}
	if(K<=M&&K%G==0){
		cout<<"POSSIBLE"<<endl;
	}
	else{
		cout<<"IMPOSSIBLE"<<endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
const int N = 205 ;
string s[N] ;
int n ,vis[N] ,lvl[N] ;
vector<int> adj[N] ;

int bfs (ll n) {
    vis[n] = 1 ;
    int res = 1 ;
    vector<int> ans[N] ;
    ans[0].pb(n) ;
    queue<int>q ;
    q.push(n) ;int x = 0 ;
    while(!q.empty()) {
        ll f = q.front() ;
        q.pop() ;
        for (auto it  : adj[f] ) {
            if (!vis[it]) {
                vis[it] =1 ;
                lvl[it] = lvl[f]+1 ;
                x = max( x,lvl[it] ) ;
                q.push(it) ;
                ans[lvl[it]].pb(it) ;
            }
        }
    }
    int i ,j ;
    for (auto it : ans) {
        for (i = 0 ; i<it.size();i++) {
            for (j = 0 ; j<it.size();j++) {
                if (i!=j) {
                     //   cout << n << ' ' << i << ' ' << j << endl ;
                    if ( s[it[i]][it[j]]=='1' ) res = 0 ;
                }
            }
        }
    }
    return (res==0 ? 0 : x+1 ) ;


}

int main() {
   cin >> n ;
   ll j , i ;
   for ( i = 0 ; i< n ;i++) cin >> s[i] ;
   for (i = 0 ; i< n ;i++) {
    for ( j = 0 ; j< n ;j++)  if (s[i][j]=='1' ) adj[i].pb(j) ;
   }
   int ans = 0 ;

   for ( i = 0 ; i< n ;i++) {
    memset(vis,0,sizeof(vis)) ;
    memset(lvl,0,sizeof(lvl)) ;
    int x = bfs(i) ;
    ans = max(ans,x ) ;
   // cout << i << ' ' << x << endl ;
   }
   cout << (ans == 0 ? -1 : ans ) << endl ;




}


Measured memory_bytes: 512
L=input()
N=len(L)
dp=[[0,0]for _ in range(N)]
dp[0][0]=1 #以下が確定（0）
dp[0][1]=2 #以下が確定してない（1,0）と逆
mod=10**9+7
for i in range(1,N):
  #以下モードは3倍に配給パターンが増える
  dp[i][0]+=3*dp[i-1][0]
  dp[i][0]%=mod
  if L[i]=='0':
    #(0,0)を配給し、そのまま
    dp[i][1]+=dp[i-1][1]
  else:
    #(0,0)を配給すれば、以下モードに移る
    dp[i][0]+=dp[i-1][1]
    #(1,0)(0,1)を配給する
    dp[i][1]+=dp[i-1][1]*2
  dp[i][0]%=mod
  dp[i][1]%=mod
print(sum(dp[-1])%mod)

Measured memory_bytes: 23984
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong




int num[10] = {0,2,5,5,4,5,6,3,7,6};


signed main(){
	int n,m;
	cin >> n >> m;
	int A[20] = {};
	REP(i,m){
		cin >> A[i];

	}
	sort(A,A+m);
    reverse(A,A+m);
    int dp[MAX];
    dp[0] = 0;
    FOR(i,1,n+1){
        dp[i] = -1000000;
        REP(j,m){
            if(i - num[A[j]] >= 0) dp[i] = max(dp[i], dp[i-num[A[j]]] + 1);
        }
    }
    int keta = dp[n];
    int ind = n;
    while(keta){
        REP(i,m){
            if(ind - num[A[i]] >= 0 and dp[ind - num[A[i]]] == dp[ind] - 1){
                cout << A[i];
                ind -= num[A[i]];
                break;
            }
        }
        keta --;
    }


}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int X;
	cin >> X;
	int R = 0, i = 0;
	while (1)
	{
		R += i;
		if (R >= X)
			break ;
		i++;
	}
	cout << i << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long A,B,K,a=0;
    cin>>A>>B>>K;
    a=A;
    if(A>=K){
        A=A-K;
    }
    else{
        A=0;
        K=K-a;
        if(B>=K){
            B=B-K;
        }
        else{
            B=0;
        }
    }
    cout<<A<<" "<<B<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

void mkwall(int x, int y, int h, int w);

int main()
{
	for (;;) {
		int h, w, x, y;
		scanf("%d %d", &h, &w);
		if (h == 0 & w == 0) {
			return 0;
		}
		for (y = 0; y < h; y++) {
			for (x = 0; x < w; x++) {
				mkwall(x + 1, y + 1, h, w);
			}
			printf("\n");
		}
		printf("\n");
	}
}

void mkwall(int x, int y, int h, int w)
{
	if (x == 1 | x == w | y == 1 | y == h) {
		printf("#");
	} else {
		printf(".");
	}
}

Measured memory_bytes: 572
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;

void updatemin(ll& a, ll b) { if (b < a) a = b; }

ll n=0, wmax=0;
vector<ll> w, v;

int main() {
    cin >> n >> wmax;
    w.resize(n);
    v.resize(n);
    rep(i,n) cin >> w[i] >> v[i];

    const ll maxsumv = 100*1000+1;
    vector<ll> dp(maxsumv, Inf); // minimum weight
    dp[0] = 0;
    rep(i,n) {
        for (ll j=maxsumv-v[i]; j >= 0; --j) {
            updatemin(dp[j+v[i]], dp[j] + w[i]);
        }
    }

    ll ans = 0;
    rep(i,maxsumv) {
        if (dp[i] <= wmax)
            ans = i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3676
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

float t, x, ans;

int main() {
    scanf("%f %f", &t, &x);
    ans = t / x;
    printf("%f", ans);
    return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

newUF n = VUM.replicate n (-1 :: Int)

root uf x = do
    p <- VUM.read uf x
    if p < 0
        then return x
        else do
            r <- root uf p
            VUM.write uf x r
            return r

same uf x y = liftM2 (==) (root uf x) (root uf y)

unite uf x y = do
    px <- root uf x
    py <- root uf y
    when (px /= py) $ do
        sx <- VUM.read uf px
        sy <- VUM.read uf py
        let (par, chld) = if sx < sy then (px, py)　else (py, px)
        VUM.write uf chld par
        VUM.write uf par (sx + sy) 

size uf x = do
    px <- root uf x
    s <- VUM.read uf px
    return $ abs s

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m] <- getIntList
    ps <- zip [0..] . map pred <$> getIntList
    xy <- replicateM m $ do
        [x,y] <- getIntList
        return (x-1,y-1)
    uf <- newUF n
    forM_ xy $ \(x,y) -> do
        unite uf x y
    ans <- sum <$> mapM (\(i,p) -> do
                       b <- same uf i p
                       return (if b then 1 else 0)) ps
    print ans

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

using namespace std;

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

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

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

int a, l;

string changes(int i, int l){
	string res;
	stringstream ss;
	ss << i;
	ss >> res;
	reverse(ALL(res));
	int k = res.size();
	REP(i, l - k){
		res += "0";
	}
	reverse(ALL(res));
	return res;
}

int changei(string s){
	int res;
	stringstream ss;
	ss << s;
	ss >> res;
	return res;
}

int main(){
	while (cin >> a >> l&&a + l){
		vector<string> vs;
		string s = changes(a, l);
		while (find(ALL(vs), s) == vs.end()){
			vs.push_back(s);
			sort(ALL(s));
			int MIN = changei(s);
			sort(ALL(s), greater<int>());
			int MAX = changei(s);
			s = changes(MAX - MIN, l);
		}
		int ans = 0;
		REP(i, vs.size()){
			if (s == vs[i])ans = i;
		}
		cout << ans << " " << changei(s) << " " << vs.size() - ans << endl;
	}
}

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

int compare(const void *a,const void *b){
  return strcmp(a,b);
}

int main(){
  int N;
  char s[200001][11];
  scanf("%d",&N);
  int i;
  for(i=0;i<N;i++){
    scanf("%s",s[i]);
  }
  int count=1;
  qsort(s,N,sizeof(*s),compare);
  for(i=0;i<N-1;i++){
    if(strcmp(s[i],s[i+1])!=0){
      count++;
    }
  }
  printf("%d",count);
}



Measured memory_bytes: 5744
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

R, G, B, N = MAP()
cnt = 0
for r in range(N // R + 1):
    for g in range((N - r * R) // G + 1):
        tmp = (N - r * R - g * G)
        if tmp >= 0 and tmp % B == 0:
            cnt += 1
print(cnt)


Measured memory_bytes: 27132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

int main()
{
        string s;
        cin >> s;
        ll ans = 0;
        if (s[0] == '1') ans++;
        if (s[1] == '1') ans++;
        if (s[2] == '1') ans++;
        cout << ans << endl;


}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a;i < b; i++)

int main() {

	int a, b;
	cin >> a >> b;

	if (b == 1) {
		cout << 0 << endl;
		return 0;
	}

	int count = 1;

	while (b - a > 0) {
		count++;
		b = b - a + 1;
	}

	cout << count << endl;

	return 0;
}

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

int main() {
    // input
    int k; scanf("%d", &k);
    vector<int> a(k); REP (i, k) scanf("%d", &a[i]);
    // solve
    reverse(ALL(a));
    ll l = 2, r = 3;
    for (int a_i : a) {
        l = (l + a_i - 1) / a_i * a_i;
        r = (r + a_i - 1) / a_i * a_i;
    }
    // output
    if (l == r) {
        printf("-1\n");
    } else {
        printf("%lld %lld\n", l, r - 1);
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    int n;
    cin >> n;
    int ans = INF;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            double a = log10(i) + 1;
            double b = log10(n / i) + 1;
            int f = max(floor(a), floor(b));
            ans = min(ans, f);
        }
    }
    cout << ans << "\n";
}

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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i=0;i<n;i++){
    cin >> p[i];
  }
  int ans = 0;
  for (int i=1;i<n-1;i++){
    if (p[i-1] < p[i] && p[i] < p[i+1]) ans++;
    if (p[i-1] > p[i] && p[i] > p[i+1]) ans++;
  }
  cout << ans << endl;

  return 0;
}

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

int main(void){

    std::string s; std::cin >> s;
    int lastlength = 1, answer = 1;
    char lastletter = s[0];
    for(int i=1; i<s.length();){

        if(i == s.length() - 1 && lastlength == 1 && lastletter == s[i]) break;

        bool go_one = false;
        if(lastlength == 2) go_one = true;
        else if(lastletter != s[i]) go_one = true;
        answer++;
        if(go_one){
            lastlength = 1;
            lastletter = s[i];
            i++;
        }
        else{
            lastlength = 2;
            lastletter = -1;
            i += 2;
        }
    }
    std::cout << answer << std::endl;
    //while(1);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <list>
#include <string>
using namespace std;
struct Trie
{
	struct Node
	{
		Node() :isEnd(false) {}
		Node(char _v) : v(_v), isEnd(false) {}
		~Node()
		{
			for (list<Node*>::iterator it = nodes.begin();
				it != nodes.end();
				++it)
			{
				delete *it;
			}
		}
		Node* FindChild(char c){
			for (list<Node*>::iterator it = nodes.begin();
				it != nodes.end();
				++it)
			{
				if ((*it)->v == c)
					return *it;
			}
			return 0;
		}

		bool isEnd;
		char v;
		list<Node*> nodes;
	};

	void Add(const string& str){
		Node* n = &root;
		Node* cn = 0;
		int s = str.size();
		std::string::size_type p = 0;
		for (; p < s; ++p){
			char c = str[p];
			cn = n->FindChild(c);
			if (cn)
				n = cn;
			else{
				cn = new Node(c);
				n->nodes.push_back(cn);
				n = cn;
			}
		}
		n->isEnd = true;
	}
	bool Find(const string& str){
		Node* n = &root;
		Node* cn = 0;
		int s = str.size();
		std::string::size_type p = 0;
		for (; p < s; ++p){
			char c = str[p];
			cn = n->FindChild(c);
			if (!cn)
				return false;
			n = cn;
			if (p == s - 1)
				return n->isEnd;
		}
	}
	Node root;
};

int main()
{
	int n, i;
	cin >> n;
	string com, str;
	Trie trie;
	for (i = 0; i < n; ++i){
		cin >> com >> str;
		if (com == "insert") trie.Add(str);
		if (com == "find")
			cout << (trie.Find(str) ? "yes\n" : "no\n");
	}

	return 0;
}

Measured memory_bytes: 22940
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	ll a,b,c,d;
	
	cin >> a >> b >> c >> d;
	cout << max(a*b,c*d) << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
point_list = list(map(int, input().split()))
hp_list = []
for p in range(1, max(point_list) + 1):
    hp = 0
    for i in range(len(point_list)):
        hp += (point_list[i] - p) ** 2
    hp_list.append(hp)
print(min(hp_list))


Measured memory_bytes: 2940
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N = int(readline())
A = np.zeros(N+2,np.int32)
A[1:-1] = np.array(read().split(),np.int32)

left_max = np.maximum.accumulate(A[:-2])
right_max = np.maximum.accumulate(A[::-1])[::-1][2:]
answer = np.maximum(left_max, right_max)
print('\n'.join(answer.astype(str)))


Measured memory_bytes: 50844
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()


s,k,d = Ri()
flag = False
if s < 0:
    flag = True

totk=  k
s = abs(s)
times = s//d

minn = s-k*d
if minn >= 0:
    print(s-k*d)
else:
    pos1 = s-times*d
    pos2 = INF
    k-=times
    if pos1 == 0:
        if k %2 == 1:
            print(d)
        else:
            print(0)
        exit()
    pos2 = abs(pos1 - d)
    if k == 1:
        print(pos2)
    elif k % 2 == 0:
        print(pos1)
    else:
        print(pos2)




        


Measured memory_bytes: 63056
N, M=map(int,input().split())
ret = [-1]*N
fg = True
for i in range(M):
  s, c=map(int,input().split())
  if ret[s-1]==-1:
    ret[s-1]=c
  elif ret[s-1]!=c:
    fg = False
    break
if fg:
  for i in range(N):
    if ret[i]==-1:
      if i==0 and N>1:
        ret[i]=1
      else:
        ret[i]=0
  ans=int(''.join(map(str,ret)))
  if len(str(ans))==N:
    print(ans)
  else:
    print(-1)
else:
  print(-1)

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

struct edge{
	int a, b, w;
	bool operator< (const edge &e) const{
		return w < e.w;
	}
};

int par[101];
void init(int n){
	for(int i = 1; i <= n; ++i){
		par[i] = i;
	}
}

int find(int x){
	return x != par[x] ? par[x] = find(par[x]) : x;
}

int main(){
	int n, m;
	const int INF = 1 << 30;

	while(scanf("%d%d", &n, &m), n != 0){
		int ans = INF;

		vector<edge> e(m);
		for(int i = 0; i < m; ++i){
			scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].w);
		}
		sort(e.begin(), e.end());
		for(int i = 0; i < m; ++i){
			int g = n;

			init(n);
			for(int j = i; j < m; ++j){
				int x = find(e[j].a), y = find(e[j].b);
				if(x != y){
					par[x] = y;
					
					if(--g == 1){
						ans = min(ans, e[j].w - e[i].w);
						break;
					}
				}
			}
		}

		printf("%d\n", ans < INF ? ans : -1);
	}
}

Measured memory_bytes: 1108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		String ans = "Three";
		for (int i = 0; i < N; i++) {
			char ch = reader.next().charAt(0);
			if (ch == 'Y') {
				ans = "Four";
			}

		}



		System.out.print(ans);
		reader.close();
	}
}


Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector<int> G[100005]; // child list
vector<int> H[100005]; // parent list
int nH[100005];
int T[100005];
int main() {
  ios::sync_with_stdio(false);
  int N, M, A, B;
  cin >> N >> M;
  for (int i=0; i<N-1+M; i++) {
    cin >> A >> B;
    G[A].push_back(B);
    H[B].push_back(A);
    nH[B]++;
  }
  int root;
  for (int i=1; i<=N; i++) {
    if (H[i].size() == 0) {
      root = i;
      break;
    }
  }
  queue<int> Q;
  Q.push(root);
  int c = 1;
  while (!Q.empty()) {
    int p = Q.front(); Q.pop();
    T[p] = c++;
    for (int i=0; i<G[p].size(); i++) {
      int m = G[p][i];
      nH[m]--;
      if (nH[m] == 0) {
        Q.push(m);
      }
    }
  }
  for (int i=1; i<=N; i++) {
    if (H[i].size() == 0) {
      cout << 0 << '\n';
    } else {
      int p = H[i][0];
      int d = T[p];
      for (int j=1; j<H[i].size(); j++) {
        if (T[H[i][j]] > d) {
          p = H[i][j];
          d = T[p];
        }
      }
      cout << p << '\n';
    }
  }
  cout << flush;
}

Measured memory_bytes: 12544
n,k=io.read("*n","*n","*l")
h={}
for i=1,n do
    h[i]=io.read("*n")
end
table.sort(h)

minth=10^9+1
for i=1,n-k+1 do
    minth=math.min(minth,h[i+k-1]-h[i])
end
print(minth)

Measured memory_bytes: 2424
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <cstdlib>
using namespace std;

int main(){
    int n;
    while(cin>>n&&n!=0){
        set<int> schedules[101];
        for(int i = 0; i < n; i++){
            int t;
            cin>>t;
            for(int j = 0; j < t; j++){
                int p;
                cin>>p;
                schedules[i].insert(p);
            }
        }
        // ツつサツづェツつシツづェツつェツつ「ツづ慊づづ個地ツ図ツづーツ篠敖づづつ「ツづゥツつゥ
        bool m[51][51];
        memset(m,0,sizeof(m));
        for(int i = 0; i < n; i++)
            m[i][i]=true;
        int idx=31;
        for(int i = 1; i <= 30; i++){
            vector<int> v;
            set<int> s;
            for(int j = 0; j < n; j++){
                if(schedules[j].find(i)!=schedules[j].end()){
                    v.push_back(j);
                    for(int k = 0; k < n; k++){
                        if(m[j][k])
                            s.insert(k);
                    }
                }
            }
            if(s.size()==n){
                idx=i;
                break;
            }
            for(set<int>::iterator it = s.begin(); it!=s.end(); it++)
                for(int j = 0; j < v.size(); j++)
                    m[v[j]][*it]=true;
        }
        if(idx==31)
            cout<<-1<<endl;
        else
            cout<<idx<<endl;
    }

    return 0;
}

Measured memory_bytes: 956
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long swappings[70][100001];
long long final_swappings[100001];

int main(){
#define int long long
	int n;
	cin >> n;
	vector<long long> inputs;
	REP(i, n) {
		int a;
		cin >> a;
		inputs.push_back(a);
		swappings[0][i] = i;
		final_swappings[i] = i;
	}
	long long m, k;
	cin >> m >> k;
	REP(i, m) {
		int a;
		cin >> a;
		a--;
		swap(swappings[0][a], swappings[0][a - 1]);
	}
	for (int q = 1; q <= 64; ++q) {
		REP(i, n) {
			swappings[q][i] = swappings[q - 1][swappings[q - 1][i]];
		}
	}
	for (long long q = 0; q <= 62; ++q) {
		if (((1LL << q) & k) != 0) {
			REP(i, n) {
				final_swappings[i] = swappings[q][final_swappings[i]];
			}
		}
	}
	cout << inputs[0] << endl;
	long long now = inputs[0];
	REP(i,n-1) {
		int a = final_swappings[i];
		int diff = inputs[a + 1] - inputs[a];
		now += diff;
		cout << now << endl;
	}
}

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

using namespace std;

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

    return gcd(b, a%b);
}

int main(){
    int n,X;
    cin >> n >> X; 
    vector<int> x(n);
    vector<int> tmp(n);
    for(int i = 0; i < n; i++){
        cin >> x[i];
        tmp[i] = abs(X-x[i]);
    }

    if(n == 1){
        cout << tmp[0] << endl;
        return 0;
    }
    else{
        int ans = gcd(tmp[0],tmp[1]);
        for(int i = 2; i < n; i++){
            ans = gcd(ans, tmp[i]);
        }
        cout << ans << endl;
        return 0;
    }


}


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

const int N=30;
typedef long long LL;
int num[N];

int main(){
    LL n;
    int cnt=0;
    cin>>n;
    while(n){
        num[cnt++]=n%10;
        n/=10;
    }
    int mx=0,ans=0;
    for(int i=0;i<cnt;i++) mx+=num[i];
    ans=max(ans,mx);
    for(int i=cnt-1;i>=1;i--){
        mx=num[i]-1;
        for(int j=i-1;j>=0;j--) mx+=9;
        ans=max(ans,mx);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream> 
#include<vector> 
#include<algorithm> 
using namespace std; 
#define lld long long int
#define X 1000000007
#define fast();  ios_base::sync_with_stdio(false); cin.tie(0);
# define rec(i,n) for(int i=0;i<n;i++) 
#define w(t) int t; cin>>t; while(t--)
int main()
{
    fast(); 

    int n; 
    lld sum=0; 
    cin>>n; 
    rec(i,n+1)
     if(i%3!=0 && i%5!=0) 
        sum+=i; 
    cout<<sum<<endl; 
    
	return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
#include <cmath>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int a[20];
int n;

bool DFS(int k, int m, double r){
	int s=ceil(a[k]-a[k]*r);
	if(s==0)s=1;
	int e=ceil(a[k]+a[k]*r);
	for(int p=((s-1)/m+1)*m;p<e;p+=m)
		if(k==n-1)return true;
		else if(DFS(k+1,p,r))return true;
	return false;
}

bool C(double r){
	return DFS(0,1,r);
}

int main(){
	scanf("%d",&n);
	REP(i,n)scanf("%d",&a[i]);
	double u=1.0, l=0.0;
	while(u-l>1e-9){
		double mid=(u+l)*0.5;
		if(C(mid))u=mid;
		else l=mid;
	}
	printf("%.10f\n",u);
	return 0;
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	if( n >= 2*k-1 ){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,C;
LL ANS=2e18;
LL V[31][31],W[3][505],COST[3][505];
int main() {
	scanf("%d%d\n",&n,&C);
	for(int i=1;i<=C;i++)
		for(int j=1;j<=C;j++) scanf("%d",&V[i][j]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++) {
			int v; scanf("%d",&v);
			W[(i+j)%3][v]++;
		}
	for(int i=0;i<3;i++)
		for(int j=1;j<=C;j++) 
			for(int k=1;k<=C;k++) 
				COST[i][j]+=W[i][k]*V[k][j];
	for(int i=1;i<=C;i++)
		for(int j=1;j<=C;j++) if(i!=j) 
			for(int k=1;k<=C;k++) if(i!=k&&j!=k) 
				ANS=min(ANS,COST[0][i]+COST[1][j]+COST[2][k]);
	printf("%lld\n",ANS);
	return 0;
}

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

// a < b
bool within( int a, int b, int c ) {
	
	return ( a <= c && c <= b );
}

int main() {
	
	int W, a, b;
	
	cin >> W;
	cin >> a;
	cin >> b;
	
	// すでに連結
	if ( within(a,a+W,b) || within(a,a+W,b+W) ) {
		cout << 0 << endl;
	}
	else {
		cout << ( (a+W < b) ? b-(a+W) : a-(b+W) ) << endl;
	}
	
	
	
	return 0;
}

Measured memory_bytes: 256
//Problem C
#include<bits/stdc++.h>
using namespace std;
const int N=200007;
void rd(int &a){
    char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))a=(a<<1)+(a<<3)+(ch^48),ch=getchar();
}
int n,k,c[N],s;
int main(){
    rd(n);rd(k);
    for(int i=1;i<=n;i++){
        int a=0;rd(a);
        ++c[a];
    }
    sort(c+1,c+n+1);
    for(int i=1;i<=n-k;i++)s+=c[i];
    printf("%d",s);
    return 0;
}

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

int main() {
  string a;
  cin >> a;
  
  long long l = a.size();
  map<char, long long> cnt;
  for(int i = 0; i < l; i++){
    char c = a.at(i);
    cnt[c]++;
  }
  
  long long ans = l * (l-1) / 2 + 1;
  for(auto now : cnt){
    ans -= now.second * (now.second-1) / 2;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3768
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
	while(1){
		int h; cin>>h;
		if(!h) break;
		int ans=0, table[10][5];
		for(int i=0; i<h; i++){
			for(int j=0; j<5; j++)
				cin >>table[i][j];{
			}
		}

		int hoge = 0;
		while(1){
			for(int i=0; i<h; i++){
				int count=0;
				bool b[5];
				fill(b, b+5, false);

				if(table[i][2] == 0) continue;
				if(table[i][2] == table[i][1]){
					b[1]=true;
					count++;
					if(table[i][2] == table[i][0]){
						b[0]=true;
						count++;
					}
				}
				if(table[i][2] == table[i][3]){
					b[3]=true;
					count++;
					if(table[i][2] ==table[i][4]){
						b[4]=true;
						count++;
					}
				}

				if(count>=2){
					b[2] = true;
					count++;
					ans += (table[i][2]*count);

					for(int j=0; j<5; j++){
						if(b[j]==true){
							table[i][j]=0;
						}
					}
				}
			}//endfor

			if(hoge == ans) break;
			hoge = ans;

			for(int i=0; i<h; i++){
				for(int j=0; j<5; j++){
					if(table[i][j] == 0){
						for(int k=i; k>0; k--){
							swap(table[k][j], table[k-1][j]);
						}
					}
				}
			}
		}//endwhile
		cout << ans << endl;
	}//endwhile
	return 0;
}


Measured memory_bytes: 3068
def check_palindrome(s):
    line = list(s)
    l = len(line)
    for i in range(l//2):
        if line[i] != line[l-i-1]:
            return False
    return True

s = input()
length = len(s)
if check_palindrome(s) and check_palindrome(s[0:length//2]) and check_palindrome(s[length//2+1:length]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include <cstdio>
 #include <algorithm>
using namespace std;
 
 int main(){
 	int array[50];
 	int w,n,a,b;
 
 	for(int i=0 ; i<50 ; i++){
 		array[i] = i;
 	}
 	
 	scanf("%d", &w);
 	scanf("%d", &n);
 	for(int i=0 ; i<n ; i++){
 		scanf("%d,%d", &a, &b);
 		swap( array[a] , array[b] );
 	}
 	for(int i=1 ; i<=w ; i++){
 		printf("%d\n", array[i]);
 	}
 }

Measured memory_bytes: 0
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, A[112345], B[112345], C[112345];
LL resA[112345], resB[112345];
LL ans;
LL minC[112345];

int main()
{
	in >> N;
	rep(i, N) { in >> A[i]; }
	rep(i, N) { in >> B[i]; }
	rep(i, N) { in >> C[i]; }

	std::sort(A, A + N);
	std::sort(B, B + N);
	std::sort(C, C + N);
	rep(i, N)
	{
		auto it = std::upper_bound(B, B + N, A[i]);
		resA[i] = (it - B) - 1;
	}
	rep(i, N)
	{
		auto it = std::upper_bound(C, C + N, B[i]);
		resB[i + 1] += N - (it - C);
		resB[i + 2] += resB[i + 1];
	}
	rep(i, N)
	{
		LL res = 0;
		res = resB[N] - resB[resA[i] + 1];
		ans += res;
	}

	out << ans << std::endl;
	return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(args...) do { cout << "\033[32;1m" << #args << " -> "; err(args); } while (0)
#else
#define dbg(...)
#endif
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); }
template<typename T, typename... Args>
void err(T a, Args... args) { cout << a << ' '; err(args...); }

LL bin(LL x, LL n, LL MOD) {
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1) ret = ret * x % MOD;
    return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
////////////////////////////////////////////////////////////////////////////////////

const int N = 1E5 + 100;
map<int, int> a, b;
vector<pair<int, int>> X, Y;

int main() {
    int n; cin >> n;
    FOR (i, 0, n) {
        int x; cin >> x;
        if (i % 2) b[x]++;
        else a[x]++;
    }
    X.push_back({0, -1});
    Y.push_back({0, -2});
    for (auto& r: a) X.push_back({r.second, r.first});
    for (auto& r: b) Y.push_back({r.second, r.first});
    sort(X.rbegin(), X.rend());
    sort(Y.rbegin(), Y.rend());
    int ans = n;
    FOR (i, 0, 2) {
        FOR (j, 0, 2) {
            if (X[i].second != Y[j].second)
                ans = min(ans, n - X[i].first - Y[j].first);
        }
    }
    cout << ans << endl;
}


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

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N = 1e5+7;

int32_t main() {
    IOS;
	int n, m;
	cin >> n >> m;
	vector<int> a[n+1];
	while (m--) {
		int u, v;
		cin >> u >> v;
		a[u].push_back(v);
		a[v].push_back(u);
	}
	int parent[n+1];
	memset(parent, -1, sizeof(parent));
	queue<int> q;
	vector<bool> visited(n+1, false);
	q.push(1);
	visited[1] = true;
	while (not q.empty()) {
		int front = q.front();
		q.pop();
		for (auto i : a[front]) {
			if (not visited[i]) {
				visited[i] = true;
				parent[i] = front;
				q.push(i);
			}
		}
	}
	bool check = false;
	for (int i = 2; i <= n; i++) if (parent[i] == -1) check = true;
	if (check) cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		for (int i = 2; i <= n; i++) cout << parent[i] << endl;
	}

    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

#define INF 100000000

int main()
{
	int H, W, K;
	cin >> H >> W >> K;
	
	vector<string> grid(H);
	for (int h = 0; h < H; h++)
		cin >> grid[h];

	int count = 0;
	for (int i = 0; i < (1 << H+W); i++)
	{
		vector<string> temp(grid);
		for (int n = 0; n < H+W; n++)
			if ((i >> n) & 1)
			{
				if (n < H)
					for (int c = 0; c < W; c++)
						temp[n][c] = 'R';
				else
					for (int r = 0; r < H; r++)
						temp[r][n-H] = 'R';
			}
		int blacks = 0;
		for (int r = 0; r < H; r++)
			for (int c = 0; c < W; c++)
				if (temp[r][c] == '#')
					blacks++;
		if (blacks == K)
			count += 1;
	}
	cout << count << endl;
}



Measured memory_bytes: 3640
// #include<bits/stdc++.h>
// using namespace std;
// #define F first
// #define S second
// #define PB push_back
// #define MP make_pair
// #define REP(i,a,b) for (int i = a; i <= b; i++)

// typedef long long ll;
// typedef vector<int> vi;
// typedef pair<int,int> pii;

// int main() {
//   ios::sync_with_stdio(0);
//   cin.tie(0);
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
//   //(a + b) mod m = (a mod m + b mod m) mod m;
//   //(a - b) mod m = (a mod m - b mod m) mod m;
//   //(a * b) mod m = (a mod m * b mod m) mod m;
//   // x = x % m;
//   // if (x < 0) x += m;
// }

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	//freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

    //int T; cin >> T;
    //while(T--) {
      map<string, int> m;
      int n;
      cin >> n;
      FOR(i,0,n){
        string x;
        cin >> x;
        m[x]++;
      }

      cout << "AC x " << m["AC"];
      cout << nl;
      cout << "WA x " << m["WA"];
      cout << nl;
      cout << "TLE x " << m["TLE"];
      cout << nl;
      cout << "RE x " << m["RE"];
      cout << nl;
      //}

      return 0;
}

// read the question correctly (ll vs int)
// template by bqi343




Measured memory_bytes: 3652