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

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int n = sc.nextInt();

        Map<Long, Long> map = new HashMap<>();
        for (int i = 1; i <= n; ++i) {
            map = d(i, map);
        }
        long ans = 1;
        for (Map.Entry<Long, Long> entry : map.entrySet()) {
            ans *= entry.getValue() + 1;
            ans %= 1_000_000_007;
        }
        _out.println(ans % 1_000_000_007);
    }
    private Map<Long, Long> d(long n, Map<Long, Long> map) {
        for (long i = 2; i <= n; ++i) {
            if (n % i == 0) {
                long cnt = 0;
                while (n % i == 0) {
                    n /= i;
                    ++cnt;
                }
                Long l = map.get(i);
                if (l == null) {
                    map.put(i, cnt);
                } else {
                    map.put(i, cnt + l);
                }
            }
        }
        return map;
    }
    private long C(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        for (long i = r; i > 1; --i) {
            res /= i;
        }
        return res;
    }
    private long P(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

typedef long long ll;

const int INF = 1<<29;

const int MAX_N = 5020;

int p[MAX_N];
int c[MAX_N];

int smallerOrEq[MAX_N][MAX_N][2];
int indexOf[MAX_N][2];

int dp[MAX_N][MAX_N];

int getIndex(int val, int c, int white, int black) {
    int idx = indexOf[val][c];
    int res = idx;
    res += smallerOrEq[idx][white][0];
    res += smallerOrEq[idx][black][1];
    return res;
}

int getRes(int white, int black, int n) {
    if(white + black == 2 * n) {
        return 0;
    }
    if(dp[white][black] != -1) {
        return dp[white][black];
    }

    int res = INF;

    //cout<<"State\tw: "<<white<<"\tb: "<<black<<endl;

    if(white < n) {
        int idx = getIndex(white+1, 0, white, black);
        int cost = idx - (white+black+1);
        //cout<<"w idx: "<<idx<<endl;
        res = min(res, getRes(white+1, black, n) + cost);
    }

    if(black < n) {
        int idx = getIndex(black+1, 1, white, black);
        int cost = idx - (white+black+1);
        //cout<<"b idx: "<<idx<<endl;
        res = min(res, getRes(white, black+1, n) + cost);
    }

    return dp[white][black] = res;
}

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin>>n;

    for(int i = 1;i<=2*n;++i) {
        char ci;
        cin>>ci;
        c[i] = ci == 'B';
        cin>>p[i];

        indexOf[p[i]][c[i]] = i;
    }

    for(int i = 2*n;i >= 1;--i) {
        for(int j = n;j>=1;--j) {
            for(int k = 0;k<2;++k) {
                smallerOrEq[i][j][k] = 0;

                if(i+1 <= 2*n) {
                    smallerOrEq[i][j][k] += smallerOrEq[i+1][j][k];

                    if(p[i+1] <= j && c[i+1] == k) {
                        smallerOrEq[i][j][k]++;
                    }
                }
            }
        }
    }

    for(int i = 0;i<MAX_N;++i) {
        for(int j = 0;j<MAX_N;++j) {
            dp[i][j] = -1;
        }
    }

    int res = getRes(0, 0, n);

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 256640
n = int(input())
A = list(map(int,input().split()))
a = 0
b = 0
for i in range(n):
    if A[i] %2 == 0:
        a +=1
        if A[i] %3== 0 or A[i]%5==0:
            b +=1
if a == b:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int dp[111][4][4][4];

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

    dp[0][3][3][3] = 1;

    REP(len,n) REP(newc,4) REP(oldc1,4) REP(oldc2,4) REP(oldc3,4) {
        if (dp[len][oldc1][oldc2][oldc3] == 0) continue;

        if (oldc2 == 0 && oldc1 == 2 && newc == 1) continue;
        if (oldc2 == 2 && oldc1 == 0 && newc == 1) continue;
        if (oldc2 == 0 && oldc1 == 1 && newc == 2) continue;
        if (oldc3 == 0 && oldc1 == 2 && newc == 1) continue;
        if (oldc3 == 0 && oldc2 == 2 && newc == 1) continue;

        dp[len+1][newc][oldc1][oldc2] += dp[len][oldc1][oldc2][oldc3];
        dp[len+1][newc][oldc1][oldc2] %= MOD;
    }

    int ans = 0;
    REP(c1,4) REP(c2,4) REP(c3,4) {
        ans += dp[n][c1][c2][c3];
        ans %= MOD;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
# Problem C - 755

from collections import deque

# input
N = input()
n_keta = len(N)
N = int(N)

# initialization
class Search:
    def __init__(self, n, keta):
        self.ans = 0
        self.n = n
        self.keta = keta

    def get_ans(self):
        return self.ans

    def check_str(self, check_num, check_str):
        return check_num<=self.n and '3' in check_str and '5' in check_str and '7' in check_str

    # dfs search
    # num_str is deque
    def dfs(self, num_str):
        if len(num_str)==self.keta:
            check_num = int("".join(num_str))
            if self.check_str(check_num, num_str):
                self.ans += 1
        else:
            for s in ['3', '5', '7']:
                num_str.append(s)
                check_num = int("".join(num_str))
                if len(num_str)<self.keta:
                    if self.check_str(check_num, num_str):
                        self.ans += 1
                self.dfs(num_str)
                num_str.pop()

# calc
dfs_search = Search(N, n_keta)
num_str = deque([])
dfs_search.dfs(num_str)

# output
print(dfs_search.get_ans())


Measured memory_bytes: 3316
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int left = a + b;
		int right = c + d;
		
		if(left > right) {
		 System.out.println("Left");
		} else if(left == right) {
		 System.out.println("Balanced");
		} else {
		 System.out.println("Right");
		}
	}
}

Measured memory_bytes: 21332
import java.util.Scanner;

public class Main{
    private static int n,maxWeight;
    private static int weights[] = new int[101];
    private static long values[] = new long[101];
    private static long dp[][] = new long[101][(int) (1e5 + 1)];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        maxWeight = sc.nextInt();
        for (int i = 0;i < n;i++){
            weights[i] = sc.nextInt();
            values[i] = sc.nextLong();
        }
        for (int i = 0;i < n;i++){
            for (int j = 0;j <= maxWeight;j++){
                dp[i][j] = -1;
            }
        }
        System.out.println(dp(0,maxWeight));
    }
    private static long dp(int idx,int rem){
        if(idx == n)
            return 0;
        if(dp[idx][rem] != -1)
            return dp[idx][rem];
        dp[idx][rem] = dp(idx + 1,rem);
       if(rem - weights[idx] >= 0)
           dp[idx][rem] = Math.max(dp[idx][rem], values[idx] + dp(idx + 1,rem - weights[idx]));
        return dp[idx][rem];
    }
}

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

const int N=2e5+100;
const int mod=1e9+7;
typedef long long ll;

int l[N],r[N];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n,k;cin>>n>>k;
    int nl=0,nr=0;
    for(int i=1;i<=n;i++){
         int x;cin>>x;
         if(x<0) l[++nl]=-x;
         else   r[++nr]=x;
    }

    reverse(l+1,l+1+nl);


    int ans=1e9;
    for(int i=0;i<=nl;i++){
            if(k-i>nr ||  k-i<0) continue;
        ans=min(ans,l[i]+r[k-i]*2);
    }
    for(int i=0;i<=nr;i++){
         if(k-i>nl || k-i<0 ) continue;
        ans=min(ans,l[k-i]*2+r[i]);
    }

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


Measured memory_bytes: 3980
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    ll a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];
    ll ans = 0;
    while(true){
        bool upd = false;
        ll sum = 0;
        ll b[n];
        for(int i = 0; i < n; i++){
            sum += a[i]/n;
            b[i] = a[i]/n;
            a[i] %= n;
        }
        if(sum == 0)    break;
        for(int i = 0; i < n; i++){
            a[i] += sum-b[i];
        }
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string S;
  	cin>>S;
  	int ans=0;
  	for(int i=0;i<3;i++)
    {
      if(S[i]=='R')
      {
	      int cnt =1;
    	  for(int j=i+1;j<3;j++)
      		{
        		if(S[i]==S[j])cnt++;
        		else
          		break;
      		}
      		ans=max(ans,cnt);
	  }
    }
  cout<<ans;
}

Measured memory_bytes: 3628
N, u, v = map(int, input().split())
L = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    L[a - 1].append(b - 1)
    L[b - 1].append(a - 1)

Leaf = []  # 葉かどうかを記録する
for i in range(N):
    c = 0
    for j in L[i]:
        c = c + 1
    if c == 1:
        Leaf.append(True)
    else:
        Leaf.append(False)

UD = [0 for i in range(N)]  # 各頂点のuからの距離
UD[u - 1] = -1  # 0でないなら訪問済みとする
M = L[u - 1]  # 次に訪れるノードのリスト
d = 1  # uからの距離
while True:
    new_M = []
    for i in M:
        if UD[i] == 0:  # 0 ならiに隣接するノードをnew_Mに追加
            UD[i] = d
            for j in L[i]:
                new_M.append(j)
        else:
            pass
    M = new_M
    if len(M) == 0:
        break
    d = d + 1
UD[u-1] = 0

VD = [0 for i in range(N)]
VD[v-1] = -1
M = L[v-1]
d = 1

while True:
    new_M = []
    for i in M:
        if VD[i] == 0:  # 0 ならiに隣接するノードをnew_Mに追加
            VD[i] = d
            for j in L[i]:
                new_M.append(j)
        else:
            pass
    M = new_M
    if len(M) == 0:
        break
    d = d + 1
VD[v-1] = 0




d = -1
index = u-1
# vよりもuの方が近く,最もvから離れている葉を見つける
for i in range(N):
    if Leaf[i]:
        if UD[i] < VD[i]:
            if d < VD[i]:
                d = VD[i]

print(d-1)









Measured memory_bytes: 28268
m,d = gets.chomp.split(" ").map(&:to_i)
M,D = gets.chomp.split(" ").map(&:to_i)

if m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12
  if d == 31
    p 1
  else
    p 0
  end
elsif m == 4 || m == 6 || m == 9 || m == 11
  if d == 30
    p 1
  else
    p 0
  end
elsif m == 2
  if d == 28
    p 1
  else
    p 0
  end
else
  p 0
end

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c;
	long long k;
	scanf("%d%d%d%lld",&a,&b,&c,&k);
	if(k&1)
		printf("%d",b-a);
	else
		printf("%d",a-b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  vector<double> guzai(N);
  for(int i=0; i<N; i++){
    double d;
    cin>>d;
    guzai.at(i)=d;
  }
  sort(guzai.begin(), guzai.end());
  double last = (guzai.at(0) + guzai.at(1))/2;
  if(N>2){
  for(int k=2; k<N; k++){
    last = (last+guzai.at(k))/2;
  }
  }
  cout << fixed << setprecision(10);
  cout << last <<endl;
}


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

int taro, hanako;

void score(char *tstr, char *hstr) {
  if (strcmp(tstr, hstr) > 0)
    taro += 3;
  else if (strcmp(tstr, hstr) < 0)
    hanako += 3;
  else {
    taro++;
    hanako++;
  }
  return;
}

int main(void)
{
  int n, i;
  char tstr[101], hstr[101];
  taro = 0;
  hanako = 0;
  scanf(" %d", &n);
  for (i = 0; i < n; i++) {
    scanf(" %s %s", tstr, hstr);
    score(tstr, hstr);
  }
  printf("%d %d\n", taro, hanako);
  return 0;
}



Measured memory_bytes: 2076
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := makeWordScanner()
	k := eGetInt(scanner)
	a := eGetInt(scanner)
	b := eGetInt(scanner)
	for i := a; i <= b; i++ {
		if i%k == 0 {
			fmt.Println("OK")
			return
		}
	}
	fmt.Println("NG")
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
const (
	TooLarge = math.MaxInt64
	TooSmall = math.MinInt64
)

func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func pow(a, n int) int {
	if n == 0 {
		return 1
	}
	if n == 1 {
		return a
	}
	if n%2 == 1 {
		return pow((a*a), n/2) * a
	}
	return pow((a * a), n/2)
}
func powMod(a, n, mod int) int {
	if n == 0 {
		return 1 % mod
	}
	if n == 1 {
		return a % mod
	}
	if n%2 == 1 {
		return powMod((a*a)%mod, n/2, mod) * a % mod
	}
	return powMod((a*a)%mod, n/2, mod)
}

func factoricalMod(n, count, mod int) int {
	if count == 1 {
		return n % mod
	}
	return (n % mod) * (factoricalMod(n-1, count-1, mod)) % mod
}

func combinationMod(n, a, mod int) int {
	x := factoricalMod(n, a, mod)
	y := factoricalMod(a, a, mod)
	y = powMod(y, mod-2, mod)
	return ((x % mod) * (y % mod)) % mod
}
func countBitOfOn(i, numbits int) int {
	count := 0
	var bit uint64
	for bit = 0; bit < uint64(numbits); bit++ {
		t := 1 << bit
		if i&t > 0 {
			count++
		}
	}
	return count
}

type ints []int

func ToString(slice []int) string {
	format := fmt.Sprint(slice)
	return fmt.Sprint(format[1 : len(format)-1])
}


Measured memory_bytes: 1816
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scanner = new Scanner(System.in);
		String input = scanner.next();
		
		if(input.equals("SSS"))
			System.out.println(0);
			
		if(input.equals("RRR"))
			System.out.println(3);
			
		if(input.equals("RRS") || input.equals("SRR"))
			System.out.println(2);
			
		if(input.equals("RSR") || input.equals("SRS") || input.equals("SSR") || input.equals("RSS"))
			System.out.println(1);
	}
}

Measured memory_bytes: 35696
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  cin >> n;
  int p[n];
  for(int i = 0; i < n; i++) cin >> p[i];

  int count = 0;
  for(int i = 1; i + 1 < n; i++){
    if((p[i - 1] < p[i] && p[i] < p[i + 1]) ||
        (p[i - 1] > p[i] && p[i] > p[i + 1])) ++count;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
template<typename T> using Graph = vector<vector<T>>;

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

    int N, M, A, B;
    cin >> N >> M >> A >> B;
    vi D(N);
    rep(i, N) cin >> D[i];

    int i;
    for (i = 0; i < N && D[i] >= A; i++) {
        ;
    }

    if (N - i < M) {
        for (i = i - 1 ; i >= 0 && D[i] <= B; i--) {
            ;
        }
        cout << i + 1 << endl;
    } else {
        cout << i << endl;
    }

}

Measured memory_bytes: 3172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(int N, int[] A)
        {
            var q = new Queue<int>[20];
            for (int i = 0; i < 20; ++i) { q[i] = new Queue<int>(); }
            for (int i = 0; i < N; ++i)
            {
                for (int j = 0; j < 20; ++j)
                {
                    if ((A[i] & (1 << j)) != 0) { q[j].Enqueue(i); }
                }
            }
            long sum = 0;
            for (int i = 0; i < N; ++i)
            {
                int min = N;
                for (int j = 0; j < 20; ++j)
                {
                    if (q[j].Count >= 2) { min = Math.Min(q[j].ElementAt(1), min); }
                    if (q[j].Count > 0 && q[j].First() == i) { q[j].Dequeue(); }
                }
                sum += min - i;
            }
            return sum;
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            int[] A = ReadInts();
            Console.WriteLine(Solve(N, A));
        }
    }
}


Measured memory_bytes: 44372
#include<stdio.h>
#include<stdlib.h>
#define MAXLEN 20000001
#define VMAX 10000

void CountingSoat(int *, int *, int, int);

int *A, *B;

int main(){
  int i, j, max=0;
  
  int n;

  scanf("%d", &n);

  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);
  for(i=0; i<n; i++){
    scanf("%hd", &A[i+1]);
    if(A[i+1] > max) max = A[i+1];
  }
  
  CountingSoat(A, B, max, n);
  for(i=1; i<n; i++){
    printf("%d ", B[i]);
  } printf("%d\n", B[i]);

  free(A);
  free(B);
  return 0;
}

void CountingSoat(int *A,int *B, int max, int n){
  int i, j;
  int *C;

  C = malloc(sizeof(int)*max+1);
  for(i=0; i<=max; i++){
    C[i] = 0;
  }

  for(j=0; j<n; j++){
    C[A[j+1]]++;
  }
  
  for(i=1; i<=max; i++){
    C[i] = C[i] + C[i-1];
  }

  for(j=1; j<=n; j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  free(C);
}



Measured memory_bytes: 17196
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
        // code
        int h, w;
        cin >> h >> w;
        int a[h][w];
        REP(i, h) REP(j, w) cin >> a[i][j];

        vector< tuple<int, int, int, int> > tt;
        for (int i = h - 1; i >= 0; i--) {
                if (i % 2 == 0) {
                        for (int j = 0; j < w; j++) {
                                if (a[i][j] % 2 == 1) {
                                        a[i][j]--;
                                        if (j + 1 == w) {
                                                if (i > 0) {
                                                        tt.emplace_back(
                                                            i, j, i - 1, j);
                                                        a[i - 1][j]++;
                                                }
                                        } else {
                                                tt.emplace_back(i, j, i, j + 1);
                                                a[i][j + 1]++;
                                        }
                                }
                        }
                } else {
                        for (int j = w - 1; j >= 0; j--) {
                                if (a[i][j] % 2 == 1) {
                                        a[i][j]--;
                                        if (j == 0) {
                                                if (i > 0) {
                                                        tt.emplace_back(
                                                            i, j, i - 1, j);
                                                        a[i - 1][j]++;
                                                }
                                        } else {
                                                tt.emplace_back(i, j, i, j - 1);
                                                a[i][j - 1]++;
                                        }
                                }
                        }
                }
        }

        cout << tt.size() << endl;
        for (auto &p : tt) {
                int a, b, c, d;
                tie(a, b, c, d) = p;
                cout << a + 1 << " " << b + 1 << " " << c + 1 << " " << d + 1
                     << endl;
        }

        return 0;
}

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

int N, K;
int x[MAX_N];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  cin >> K;
  rep(i, N) cin >> x[i];

  int total = 0;
  rep(i, N){
      total += min( abs(x[i] - K), abs(x[i]) ) * 2;
  }

  cout << total << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

list<pair<int, int> > L;

void Write(){

    int l, s; cin >> l >> s;
    for(auto itr = L.begin();;itr++){
        if(itr->first != -1) continue;

        if(itr->second <= s){
            itr->first = l;
            s -= itr->second;
            if(s == 0) return;
        }else{
            itr->second -= s;
            itr = L.insert(itr, {l, s});
            return;
        }
    }

}

void Read(){
    int p; cin >> p;
    p++;
    for(auto itr : L){
        p -= itr.second;
        if(p <= 0){
            cout << itr.first << endl;
            break;
        }
    }



}

void Delete(){

    int l; cin >> l;
    for(auto &itr : L){
        if(itr.first == l){
            itr.first = -1;
        }
    }

}


signed main(){

    while(1){
        int n; cin >> n;
        if(!n) break;
        L.clear();
        L.push_back({-1, 10000000000});

        for(int i = 0; i < n; i++){
            char op; cin >> op;
            if(op == 'W') Write();
            else if(op == 'R') Read();
            else Delete();
                
            //for(auto x : L) cerr << "(" << x.first << ", " << x.second << ") ";
            //cerr << endl;


        }
        cout << endl;
    }
    return 0;
}




Measured memory_bytes: 3300
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<vector>
#include<functional>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)


int main()
{
	int N;
	cin >> N;
	int pt=0, px = 0, py = 0;
	REP(i, N)
	{
		int t, x, y;
		cin >> t >> x >> y;
		int dt = t - pt;
		int dx = abs(x - px);
		int dy = abs(y - py);
		dt = dt - dx;
		if (dt < 0 || dt <dy)
		{
			cout << "No" << endl;
			return 0;
		}
		if (dt % 2 == 0)
		{
			if (dy % 2 == 0)
			{
				pt = t;
				px = x;
				py = y;
			}
			else
			{
				cout << "No" << endl;
				return 0;
			}
		}
		else
		{
			if (dy % 2 == 0)
			{
				cout << "No" << endl;
				return 0;
			}
			else
			{
				pt = t;
				px = x;
				py = y;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import bisect as bisect
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A = sorted(A)
B = sorted(B)
C = sorted(C)
ans = 0
for b in B:
    ans += bisect.bisect_left(A,b) * (N - bisect.bisect_right(C,b))
print(ans)

Measured memory_bytes: 23360
#include <bits/stdc++.h>
#define ii pair < int , int >
#define fi first
#define se second

using namespace std;
const int N=3e3+33;
int dp[N][N];
ii p[N][N];
string a,b;

int main()
{
	memset(dp,-1,sizeof dp);
	memset(p,-1,sizeof p);
	cin>>a>>b;
	int n=a.size();
	int m=b.size();
	for(int i=n-1;i>=0;i--)
	{
		for(int j=m-1;j>=0;j--)
		{
			if(a[i]==b[j])
			{
				p[i][j]={i+1,j+1};
				dp[i][j]=1+dp[i+1][j+1];
			}
			if(dp[i][j]<dp[i+1][j])
			{
				p[i][j]={i+1,j};
				dp[i][j]=dp[i+1][j];
			}
			if(dp[i][j]<dp[i][j+1])
			{
				p[i][j]={i,j+1};
				dp[i][j]=dp[i][j+1];
			}
		}
	}
	int x=0,y=0,i,j;
	while(x!=-1&&y!=-1)
	{
		i=x;
		j=y;
		x=p[i][j].fi;
		y=p[i][j].se;
		if(x>i&&y>j)
			cout<<a[i];
	}
	return 0;
}


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

namespace AtCoder.ABC094.C
{
    class Program
    {
        static void Main ()
        {
            var sc = new Scanner ();
            int n = sc.NextInt ();
            var x = sc.ArrayLong (n);
            int centerIndex = n / 2 - 1;
            var x2 = x.OrderByDescending (val => val).ToArray ();
            var centerValue1 = x2[centerIndex];
            var centerValue2 = x2[centerIndex + 1];
            for (int i = 0; i < n; i++)
            {
                var currentValue = x[i];
                if (currentValue < centerValue1) Console.WriteLine (centerValue1);
                else Console.WriteLine (centerValue2);
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner ()
        {
            s = new string[0];
            i = 0;
        }

        public string Next ()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine ();
            while (st == "") st = Console.ReadLine ();
            s = st.Split (cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next ();
            i = 0;
            return s[i++];
        }

        public int NextInt ()
        {
            return int.Parse (Next ());
        }
        public int[] ArrayInt (int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt () + add;
            }
            return Array;
        }

        public long NextLong ()
        {
            return long.Parse (Next ());
        }

        public long[] ArrayLong (int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong () + add;
            }
            return Array;
        }

        public double NextDouble ()
        {
            return double.Parse (Next ());
        }

        public double[] ArrayDouble (int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble () + add;
            }
            return Array;
        }

        public decimal NextDecimal ()
        {
            return decimal.Parse (Next ());
        }

        public decimal[] ArrayDecimal (int N, decimal add = 0)
        {
            decimal[] Array = new decimal[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDecimal ();
            }
            return Array;
        }
    }
}

Measured memory_bytes: 45936
a,b = list(input() for i in range(2))
str = ''
num = max(len(a),len(b))
if len(a) < num:
  a = a + ' '
if len(b) < num:
  b = b + ' '
for i in range(num):
  str = str + a[i] + b[i]
print(str.replace(' ', ''))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long INF = 1LL<<60;
typedef long long ll;

int main() {
    string S; cin >> S;
    int N = S.size();
    vector<int> ans(N);
    bool flag = true; // L -> R に切り替わる時
    float cnt_r = 0;
    float cnt_l = 0;
    ll idx = 0;     // R -> L に切り替わる位置
    for (int i = 0; i < N; ++i){
        ans[i] = 0;
        if (S[i] == 'R'){
            if (!flag){
                ans[idx-1] = ceil(cnt_r/2) + floor(cnt_l/2);     // R 側
                ans[idx] = floor(cnt_r/2) + ceil(cnt_l/2);       // L 側
                cnt_r = 1;
                cnt_l = 0;
                flag = true;
            }else{
                cnt_r += 1;
            }
        }else{
            if (flag){
                flag = false;
                idx = i;
            }
            cnt_l += 1;

        }
    }
    ans[idx-1] = ceil(cnt_r/2) + floor(cnt_l/2);     // R 側
    ans[idx] = floor(cnt_r/2) + ceil(cnt_l/2);       // L 側   
    for (int i = 0; i < N; ++i){
        cout << ans[i] << " ";
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 1024
S = input()
l = len(S)
if l != 26:
    colors = [0]*26
    for i in range(l):
        colors[ ord(S[i]) - ord('a')] = 1
    for i in range(26):
        if colors[i] == 0:
            ans = S + chr( i + ord('a'))
            break
    print(ans)
elif S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for i in range(25,0,-1):
        if S[i] > S[i-1]:
            now = i
            break
    colors = [0]*26
    for i in range(now-1):
        colors[ ord(S[i]) - ord('a')] = 1
    c = 'z'
    for i in range(now-1,26):
        if S[now-1] < S[i]:
            c = min(c, S[i])
    print(S[:now-1]+c)


Measured memory_bytes: 3064
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>


using namespace std;




int main() {
	int a[100];
	int n;
	cin >> n;
	int sum = 0;
	float s=101.0;
	int id = -1;
	float heikin = 0;

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

	for (int i = 0;i < n;i++) {
		sum += a[i];
	}
	heikin = (float)sum / n;

	for (int i = 0;i < 100;i++) {
		if (s > fabs((float)a[i]-heikin)) {
			id = i;
			s = fabs((float)a[i]-heikin);



		}
	}

	cout << id << endl;



}









Measured memory_bytes: 256
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
#include <algorithm>
// #include "./Debug.h"

namespace AtCoder {
	using Input = std::vector<std::string>;
	using Num = std::vector<int>;

	Input input(void) {
		Input result;
		{
			std::string buf = "", row = "";
			std::getline(std::cin, buf);
			for (unsigned int i = 0; i < buf.size(); i++) {
				if (' ' == buf[i]) {
					result.push_back(row);
					row = "";
				} else {
					row += buf[i];
				}
			}
			result.push_back(row);
		}
		return result;
	}

	Num replaceToInteger(Input original = { "" }) {
		Num result;
		for (unsigned int i = 0; i < original.size(); i++) {
			result.push_back(atoi(original[i].c_str()));
		}
		return result;
	}
}

namespace AtCoder {
	std::vector<int> sort(std::vector<int> vec = { 0 }) {
		std::sort(vec.begin(), vec.end());
		return vec;
	}
}

int main(void) {

	AtCoder::Num s = AtCoder::replaceToInteger(AtCoder::input());

	const int n = s[0];

	AtCoder::Num p = AtCoder::replaceToInteger(AtCoder::input());
	AtCoder::Num ps = AtCoder::sort(p);

	int fc = 0;
	for (int i = 0; i < p.size(); i++) {
		if (p[i] != ps[i]) {
			fc++;
			if (2 < fc) {
				break;
			}
		}
	}

	if (2 < fc) {
		printf("NO\n");
	} else {
		printf("YES\n");
	}

	return 0;
}


Measured memory_bytes: 256
def main():
    import heapq
    n, m = map(int, input().split(' '))
    df = []
    for _ in range(n):
        x, y = map(int, input().split(' '))
        df.append([x, y])
    df.sort()
    h = []
    result = 0
    counter = 0
    for i in range(1, m+1):
        while counter < len(df) and df[counter][0] <= i:
            heapq.heappush(h, (-1)*df[counter][1])
            counter += 1
        if len(h) == 0:
            continue
        else:
            result -= heapq.heappop(h)
    print(result)
if __name__ == '__main__':
    main()

Measured memory_bytes: 23880
#include <iostream>
#include <math.h>
using namespace std;

int n, sum = 0, ans;
int grid[3][101];

int main() {
    cin>>n;
    for(int i = 1; i <= 2; i++)
        for(int j = 1; j <= n; j++) 
            cin>>grid[i][j];
    for(int i = 1; i <= n; i++) {
        sum += grid[1][i];
    }
    sum += grid[2][n];
    ans = sum;
    for(int i = n; i >= 2; i--) {
        sum -= grid[1][i];
        sum += grid[2][i-1];
        if(sum > ans)
            ans = sum;
    }
    cout<<ans;
}

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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

int N, K;
vector<ll> h;
vector<ll> dp;

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

    cin >> N >> K;
    h.resize(N + K + 10, 0);
    dp.resize(N + K + 10, INF);

    REP(i, N) cin >> h.at(i);

    dp[0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    cout << dp[N - 1] << endl;
    
    return 0;
}

Measured memory_bytes: 1792
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort
F = gets.split.map(&:to_i).sort_by{|v|-v}

T = A.zip(F).map{|a,f|[a*f,a,f]}.sort_by{|v|-v[0]}

def query(n)
    k = 0
    T.each do |t|
        break if t[0] <= n
        k += -(-(t[0] - n)/t[2])
        return false if k > K
    end
    true
end

puts (0..10**12).bsearch{ |n|
    query(n)
}

Measured memory_bytes: 46048
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first first
#define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> x(m), y(m);
    rep(i, 0, m){
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
    }
    vector<int> a(n, 1), f(n, 0);
    f[0] = 1;
    rep(i, 0, m){
        if(f[x[i]]){
            if(a[x[i]] == 1){
                f[x[i]] = 0;
            }
            f[y[i]] = 1;
        }
        a[x[i]]--;
        a[y[i]]++;
    }
    int ans = 0;
    rep(i, 0, n){
        ans += f[i];
    }
    o(ans);
}

Measured memory_bytes: 3328
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void){

   int k,s;
   cin>>k>>s;

   int sum = 0;

   for(int i=0;i<=k;i++){
       if(i > s) break;
       for(int j=i;j<=k;j++){
           if(i+j > s)break;
           int start;
           if(j > s-i-j) start = j;
           else start = s-i-j;
           for(int l=start;l<=k;l++){
               if(i+j+l == s){
                   if(i == j && j == l) sum++;
                   if(i == j && j != l) sum+=3;
                   if(i != j && j == l) sum+=3;
                   if(i == l && j != i) sum+=3;
                   if(i!=j && j!= l && i!= l) sum+=6;
                   //cout<<i<<" "<<j<<" "<<l<<":"<<sum<<endl;
               }
               if(i+j+l > s) break;
           }
       }
   }
   cout<<sum<<endl;
   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>S;
    N = S.size();
    mat left(N+1,vec(2,0)), right(N+1,vec(2,0));
    reps(i,1,N+1){
        left[i][0] = left[i-1][0] + (S[i-1] == 'A');
        left[i][1] = left[i-1][1] + (S[i-1] == '?');
        right[i][0] = right[i-1][0] + (S[N-i] == 'C');
        right[i][1] = right[i-1][1] + (S[N-i] == '?');
    }
    ll ans = 0;
    vec bit3(100010,1);
    reps(i,1,100010) (bit3[i] *= bit3[i-1]*3)%=MOD;
    reps(i,1,N-1){
        if(S[i] == 'B' || S[i] == '?'){
            vec l = left[i], r = right[N-1-i];
            L = (l[0] * bit3[l[1]])%MOD;
            if(l[1] > 0) (L += (l[1] * bit3[l[1] - 1])%MOD)%=MOD;
            R = (r[0] * bit3[r[1]])%MOD;
            if(r[1] > 0) (R += (r[1] * bit3[r[1] - 1])%MOD)%=MOD;
            (L *= R)%=MOD;
            (ans += L)%=MOD;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod=1e9+7,n;

map<ll,ll> mp;

void dfs(vector<ll> v[],ll idx,ll parent)
{

  for(auto a:v[idx])
  {
    if(a!=parent) dfs(v,a,idx);
  }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b;cin>>n;
    ll arr[n];for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n,greater<ll>());
    ll ans=arr[0];
    for(int i=2;i<n;i++)
      ans+=arr[i/2];
    cout<<ans;
}

Measured memory_bytes: 5188
from collections import deque

class Node:
    def __init__(self, idx):
        self.idx = idx
        self.a = []


n, x, y = map(int, input().split())
nodes = []

for i in range(n):
    node = Node(i+1)
    nodes.append(node)

for i in range(n-1):
    cur = nodes[i]
    next = nodes[i+1]

    cur.a.append(next)
    next.a.append(cur)

X = nodes[x-1]
Y = nodes[y-1]
X.a.append(Y)
Y.a.append(X)
dp = [[None] * (n+1) for _ in range(n+1)]

for i in range(n):
    node = nodes[i]
    q = deque()
    q.append((node, 0))
    done = set()

    while q:
        t = q.popleft()
        node, d = t[0], t[1]

        if node.idx not in done:
            dp[i + 1][node.idx] = d
            done.add(node.idx)
            for adj in node.a:
                q.append((adj, d + 1))

# for i in range(1, n+1):
#     print(dp[i])

m = {}

for i in range(1, n + 1):
    for j in range(1, n + 1):
        dis = dp[i][j]
        if dis in m:
            m[dis] += 1
        else:
            m[dis] = 1

for k in range(1, n):
    if k in m:
        print(m[k] // 2)
    else:
        print(0)

Measured memory_bytes: 131464
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

int right[300001] = {};
int left[300001] = {};

int main(void) {

	int N;
	string S;
	cin >> N >> S;

	for (int i = 0; i < N; i++) {
		if (S[i] == 'W') {
			::right[i + 1] = 1;
		}
		::right[i + 1] += ::right[i];
	}

	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == 'E') {
			::left[i] = 1;
		}
		::left[i] += ::left[i + 1];
	}

	int result = N;

	for (int i = 0; i < N; i++) {
		cerr << ::right[i] + ::left[i + 1] << endl;
		CHMIN(result, ::right[i] + ::left[i + 1]);
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int f(int n) {
  if (n % 2 == 0) return n / 2;
  return 3 * n + 1;
}

int main() {
  int s, c = 1;
  set<int> ss;
  cin >> s;
  while (true) {
    ss.insert(s);
    s = f(s);
    ++c;
    if (ss.find(s) != ss.end()) {
      cout << c << endl;
      return 0;
    }
  }
  return 0;
}

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

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


    int last =0;
    int same =0;
    for(int i=0;i<N-1;i++){
        if(S[i].at(S[i].length()-1) != S[i+1].at(0)) last++;
    }
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            if(S[i]== S[j]) same++;
        }
    }
    //cout << last <<" "<< same << endl;

    if(last==0 && same==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import bisect

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

ans = 0
for i in range(N):
    b=B[i]
    a=bisect.bisect_left(A,b)
    c=bisect.bisect_right(C,b)
    ans+= a*(N-c)

print(ans)


Measured memory_bytes: 29576
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

template<typename T> struct UnionFind {
    std::vector<T> par;
    std::vector<T> rank;

    // n要素で初期化
    UnionFind(T n) {
        par = std::vector<T>(n);
        for (T i = 0; i < n; i++) par[i] = i;
        rank = std::vector<T>(n, 0);
    }

    // 木の根を求める
    T find(T x) {
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    // xとyの属する集合を併合
    void unite(T x, T y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
        }
        else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    // xとyが同じ集合に属するかどうか
    bool same(T x, T y) {
        return find(x) == find(y);
    }
};

signed main() {
	int n, m, k;
	cin >> n >> m >> k;
    UnionFind<int> sns(n);
    V<int> friends(n, 0);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        sns.unite(a, b);
        friends[a]++;
        friends[b]++;
    }

    V<int> block(n, 0);
    REP(i, k) {
        int c, d;
        cin >> c >> d;
        c--; d--;
        if (sns.same(c, d)) {
            block[c]++;
            block[d]++;
        }
    }

    V<int> group(n, 0);
    REP(i, n) {
        group[sns.find(i)]++;
    }
	
    REP(i, n) {
        int ans = group[sns.find(i)] - 1 - friends[i] - block[i];
        cout << ans << ' ';
    }
    cout << endl;
	return 0;
}


Measured memory_bytes: 5272