akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;

int main(int argc,char* argv[]){
  std::ios_base::sync_with_stdio(false);
  
  int n,M=0;
  int *pi,*tmp;
  cin>>n;

  pi=new int[n];
  for(int i=0;i<n;i++){
    cin>>pi[i];
    M=max(M,pi[i]);
  }

  tmp=new int[M+1];
  for(int i=0;i<n;i++){
    tmp[pi[i]]++;
  }

  bool flag=true;
  for(int i=0;i<=M;i++){
    if(tmp[i]>0 && flag){
      flag=false;
      cout<<i;
      tmp[i]--;
    }
    while(tmp[i]>0){
      cout<<" "<<i;
      tmp[i]--;
    }
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 9060
def robot_arms(N: int, XY: list) -> tuple:
    odd, even = 0, 0
    max_dist = 0
    for x, y in XY:
        ax, ay = abs(x), abs(y)
        if (ax + ay) % 2 == 0:
            even += 1
        else:
            odd += 1

        if max_dist < ax + ay:
            max_dist = ax + ay

    if odd == 0:
        # 偶数のみの場合は長さ 1 のアームが余計に必要
        arms = [1]
    elif even == 0:
        # 奇数のみの場合は 2 のべき乗の長さのアームだけで OK
        arms = []
    else:
        # 偶奇ごちゃ混ぜの場合は不成立
        return [], []

    # アームの準備
    tmp, sum_tmp = 1, sum(arms)
    while sum_tmp < max_dist:
        arms.append(tmp)
        sum_tmp += tmp
        tmp <<= 1

    # 各点へ腕を伸ばすための操作方法を決めていく
    ops = []
    for x, y in XY:
        op = ''
        # 決定操作
        # 長さが 2^m までの腕を使って届く範囲は綺麗な菱形になっている。
        # 点(x,y)から原点に向かって考える。
        # 腕の長い物から使っていき、使っていない腕で届く範囲に入っていく様に
        # 腕の方向を決定していく。
        # ただし、逆順に決定していくので、決定過程での方向と実際に出力すべき
        # 方向は逆になっていることに注意
        left_len = sum(arms)
        nx, ny = x, y
        for arm in reversed(arms):
            left_len -= arm
            if abs(nx + arm) + abs(ny) <= left_len:
                op = 'L' + op
                nx, ny = nx + arm, ny
            elif abs(nx - arm) + abs(ny) <= left_len:
                op = 'R' + op
                nx, ny = nx - arm, ny
            elif abs(nx) + abs(ny + arm) <= left_len:
                op = 'D' + op
                nx, ny = nx, ny + arm
            elif abs(nx) + abs(ny - arm) <= left_len:
                op = 'U' + op
                nx, ny = nx, ny - arm
        ops.append(op)

    return arms, ops


if __name__ == "__main__":
    N = int(input())
    XY = [tuple(map(int, input().split())) for _ in range(N)]
    ans = robot_arms(N, XY)

    if len(ans[0]) == 0:
        print(-1)
    else:
        d, w = ans
        print(len(d))
        print(' '.join(map(str, d)))
        for ww in w:
            print(ww)


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

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

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

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

 vector<int> l(N);
  vector<int> r(N);
  int sum=0;
  
  for(int i=0;i<N;i++){
  cin >> l.at(i) >> r.at(i) ;
    sum+=(r.at(i)-l.at(i)+1);
  }
  
  cout << sum ;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>

#define lson (idx << 1)
#define rson (idx << 1 | 1)
#define INF 1000000000000LL
#define MAXN 200010

using namespace std;
typedef long long ll;
// `lo` is the current minimum of the segment.
// `lh` is the current value of the left endpoint.
// `lazy` is the lazy tag for addition.
struct Node {
	int l, r;
	ll lo;
	bool flag = false;
} s[MAXN << 2];
int h, w;
// Push up
void calc(int idx) {
	s[idx].lo = min(s[lson].lo, s[rson].lo);
}
void build(int idx, int l, int r) {
	s[idx].l = l, s[idx].r = r;
	if (l == r)	return;
	int mid = (l + r) >> 1;
	build(lson, l, mid);
	build(rson, mid + 1, r);
}
// Lazy propagation
void pushdown(int idx) {
	if (s[idx].flag) {
		ll L = s[idx].lo;
		int l = s[idx].l;
		for (int i = lson; i <= rson; ++i) {
			s[i].lo = L + s[i].l - l;
			s[i].flag = true;
		}
	}
	s[idx].flag = false;
}
// Assign segment [l, r] according to f[l-1] = L
void update(int idx, int l, int r, ll L) {
  if (s[idx].l >= l && s[idx].r <= r) {
    s[idx].lo = L + s[idx].l - l + 1;
    s[idx].flag = true;
    return;
  }
  pushdown(idx);
  int mid = (s[idx].l + s[idx].r) >> 1;
  if (l <= mid)
    update(lson, l, r, L);
  if (mid + 1 <= r)
    update(rson, l, r, L);
  calc(idx);
}
// Range minimum query
ll query(int idx, int l, int r) {
	if (r < 1 || l > w)
		return INF;
	if (s[idx].l >= l && s[idx].r <= r)
		return s[idx].lo;
	pushdown(idx);
	ll ans = INF;
	int mid = (s[idx].l + s[idx].r) >> 1;
	if (l <= mid)
		ans = min(ans, query(lson, l, r));
	if (mid + 1 <= r)
		ans = min(ans, query(rson, l, r));
	return ans;
}
void solve() {
	scanf("%d%d",&h,&w);
	vector<int> l(h), r(h);
	for (int i = 0; i < h; ++i)
		scanf("%d%d",&l[i],&r[i]);
	vector<ll> ans(h, INF);
	build(1, 1, w);
	for (int i = 0; i < h; ++i) {
		ll L = query(1, l[i] - 1, l[i] - 1);
		update(1, l[i], r[i], L);
		ans[i] = min(ans[i], query(1, 1, w))+i+1;
		if (ans[i] == INF)	break;
	}
	for (ll i : ans)	cout << (i >= INF ? -1 : i) << endl;
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	solve();
}

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

int main(){
    int n;
    cin >> n;
    vector<int> S(n);
    for(int i = 0; i < n; i++){
        cin >> S.at(i);
    }
    sort(S.begin(),S.end());
    int q;
    cin >> q;
    vector<int> T(q);
    for(int i = 0; i < q; i++){
        cin >> T.at(i);
    }
    int c = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<q;j++){
            if(i == 0){
               if(S.at(i) == T.at(j)) {
                c++;
                break;
            } 

            }
            else{
                if(S.at(i)>S.at(i-1)){
                    if(S.at(i) == T.at(j)) {
                c++;
                break;
                }
            }
        }
    }
    }
    cout << c << endl;
}




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

int main() {
    int n, k;
    int m = 1;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        if (m*2 < m+k) m *= 2;
        else m += k;
    }
    cout << m << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N,K = map(int, readline().split())
A = np.array(read().split(), np.int64)
MOD = 10 ** 9 + 7
 
def cumprod(A, MOD = MOD):
    L = len(A); Lsq = int(L**.5+1)
    A = np.resize(A, Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        A[:,n] *= A[:,n-1]; A[:,n] %= MOD
    for n in range(1,Lsq):
        A[n] *= A[n-1,-1]; A[n] %= MOD
    return A.ravel()[:L]

def make_fact(U, MOD = MOD):
    x = np.arange(U, dtype = np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact,fact_inv
 
fact, fact_inv = make_fact(10 ** 5 + 100)
 
A.sort()
coef = (fact[K-1:N] * fact_inv[K-1] % MOD * fact_inv[0:N-K+1] % MOD)[::-1]
 
answer = ((A[::-1][:N-K+1] - A[:N-K+1]) * coef % MOD).sum() % MOD
print(answer)

Measured memory_bytes: 33624
#include <stdio.h>

int main(void)
{
	int N;
	int D;
	int X;
	int A[100];
	
	int i;
	int j;
	int choco = 0;
	
	scanf("%d", &N);
	scanf("%d %d", &D, &X);
	
	for (i = 0; i < N; i++){
		scanf("%d", &A[i]);
	} 
	
	for (i = 0; i < N; i++){
		for (j = 0; j * A[i] < D; j++){
			choco++;
		}
	}
	
	choco += X;
	
	printf("%d\n", choco);
	
	return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
 
 
int main(){
  int64_t N,M;
  cin>>N>>M;
  
  vector<int64_t> X(M);
  for(int i=0;i<M;i++){
    cin>>X.at(i);
  }
  sort(X.begin(),X.end());
  vector<int64_t> dis(M-1);
  for(int i=1;i<M;i++){
    dis.at(i-1)=X.at(i)-X.at(i-1);
  }
  sort(dis.begin(),dis.end());
 
  int64_t sum=0;
  for(int i=0;i<M-N;i++){
    sum+=dis.at(i);
  }
  cout<<sum<<endl;
}

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

typedef unsigned long int64;

int leader[100001];
int size[100001];

int root(int A)
{
    if (leader[A] == A)
    {
        return A;
    }
    else
    {
        return leader[A] = root(leader[A]);
    }
}

int main()
{
    int64 n, m, s, t;
    cin >> n >> m;
    vector<int64> a(m), b(m), ans(m + 1);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    for (int i = 0; i < n; i++)
    {
        leader[i] = i;
        size[i] = 1;
    }

    ans[m] = n * (n - 1) / 2;

    for (int i = m - 1; i >= 1; i--)
    {
        s = root(a[i]);
        t = root(b[i]);

        if (s == t)
        {
            ans[i] = ans[i + 1];
            continue;
        }

        ans[i] = ans[i + 1] - size[s] * size[t];

        if (size[s] < size[t])
            swap(s, t);
        // s < t
        // size[s] > size[t]
        // leadet[j] = t -> s
        leader[t] = s;
        size[s] += size[t];
        size[t] = 0;
    }
    for (int i = 1; i <= m; i++)
        cout << ans[i] << endl;
}


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

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

  int all= 1;
  int ng= 1;
  for(int i=0; i<N; i++){
    cin >> buf;
    all*= 3;

    if(buf%2==0){ ng*= 2; }
    else        { ng*= 1; }
  }

  int ans= all- ng;

  cout << ans << endl;
}

Measured memory_bytes: 256
#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, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
*/
int main()
{
    int N, M;
    cin >> N >> M;
    cout << (N == M ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a[101][101],b[101][101];
	long long int c[101][101];
	int i,j,k;
	int n,m,l,sum;

	for(i=0;i<101;i++)
	{
		for(j=0;j<101;j++)
		{
			a[i][j]=0;b[i][j]=0;c[i][j]=0;
		}
	}
	
	scanf("%d %d %d",&n,&m,&l);

	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	
	for(i=0;i<m;i++)
	{
		for(j=0;j<l;j++)
		{
			scanf("%d",&b[i][j]);
		}
	}

	for(i=0;i<n;i++)
	{
		for(j=0;j<l;j++)
		{
			c[i][j]=0;
			for(k=0;k<m;k++)
			{
				c[i][j]+=a[i][k]*b[k][j];
			}
		}
	}
	
	for(i=0;i<n;i++)
	{
		for(k=0;k<l;k++)
			{
				printf("%lld",c[i][k]);
			if(k<l-1) {printf(" ");
			}else{ printf("\n");}
		}
	}  
	return 0;
}


Measured memory_bytes: 2924
N = int(input())
A = list(map(int,input().split(" ")))
over2 = []
num = {}

for length in A:
	if length in num:
		num.pop(length)
		over2.append(length)
	else:
		num[length] = 1


over2.sort()

if len(over2) >= 2:
	print(over2[-1]*over2[-2])
else:
	print(0)



Measured memory_bytes: 18060
#include <iostream>

using namespace std;

int main() {
    int h, w;

    cin >> h >> w;
    for (int j = 0; j < w + 2; j++) cout << "#";
    cout << "\n";
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        cout << "#" << s << "#" << endl;
    }
    for (int j = 0; j < w + 2; j++) cout << "#";
    cout << "\n";
}

Measured memory_bytes: 256
from functools import reduce
from collections import Counter

N = int(input())

A = tuple(map(int, input().split()))

sum = []

for i in range(N):
    if i == 0:
        sum.append(A[i])
    else:
        sum.append(sum[i-1] + A[i])
        
counter = Counter(sum)

res = 0
for k, v in counter.most_common(N):
    if k == 0:
        res += v*(v+1)//2
    elif v >= 2:
        res += v*(v-1)//2

print(res)


Measured memory_bytes: 48852
#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 - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
	ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vll res0, res1;
    ll i = 0, len0 = 0, len1 = 0;
    while(1){
        while(s[i] == '0'){
            if(len1) res1.push_back(len1);
            len1 = 0;
            len0++;
            i++;
            if(i == n) break;
        }
        if(i == n) break;
        while(s[i] == '1'){
            if(len0) res0.push_back(len0);
            len0 = 0;
            len1++;
            i++;
            if(i == n) break;
        }
        if(i == n) break;
    }
    if(len0) res0.push_back(len0);
    if(len1) res1.push_back(len1);
    ll a = res0.size(), b = res1.size();

    k = min(k, a);
    
    if(a == b && s[0] == '0'){
        res1.push_back(0);
        REPR(i, b) res1[i + 1] = res1[i];
        res1[0] = 0;
        b++;
    }
    if(a == b && s[0] == '1'){
        res1.push_back(0);
        b++;
    }
    if(a > b){
        res1.push_back(0);
        REPR(i, b) res1[i + 1] = res1[i];
        res1[0] = 0;
        res1.push_back(0);
        b += 2;
    }

    vll s0(a + 1, 0), s1(b + 1, 0);
    REP(i, a){
        s0[i + 1] = s0[i] + res0[i];
    }
    REP(i, b){
        s1[i + 1] = s1[i] + res1[i];
    }
    ll x = a - k + 1, ans = 0;
    REP(i, x){
        ll res = s1[k + i + 1] - s1[i] + s0[k + i] - s0[i];
        ans = max(ans, res);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    long long n, a, b, sum1, sum2;
    cin>>n>>a>>b;
//    scanf("%d%d%d", &n, &a, &b);
//    if((n<2 && a!=b) || a>b){
//        printf("%d", 0);
//    }else if(n==1 && a==b){
//        printf("%d", 1);
//    }else{
//        sum1 = a*(n-1) + b;
//        sum2 = a + (n-1)*b;
//        printf("%d", sum2-sum1+1);
//    }

    sum1 = a*(n-1) + b;
    sum2 = a + (n-1)*b;
    if(a>b){
        cout<<'0';
    }else if(a==b){
        cout<<'1';
    }else{
        if(n==1)
            cout<<'0';
        else{
            cout<<sum2-sum1+1;
        }
    }

    return 0;
}



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

int main()
{
  int n, m, i=0, j=0;
  int a[1000], b[1000];

  cin >>n;
  while (i<n) {
    cin >> a[i];
    i++;
  }

  m = n-1;
  while(j<n-1){
    cout <<a[m] << " ";
    j++;
    m = m-1;
  }
  cout <<a[0] <<endl;
}

Measured memory_bytes: 1164
program contest
implicit none
integer :: x, y, c
integer :: money(205)

money(1) = 300000
money(2) = 200000
money(3) = 100000
money(4:205) = 0

read(*,*) x, y
if (x>4 .and. y>4) then
write(*,*) 0
stop
end if

c = money(x)+money(y)

if(x==1 .and. y==1) then
c = c + 400000
end if
write(*,*) c

end program contest

Measured memory_bytes: 2828
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
total_distance = 0
for i in range(n):
    for j in range(i+1,n):
        total_distance += ((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)**0.5
print(total_distance*2/n)

Measured memory_bytes: 3188
#include <iostream>
#include <complex>

int main()
{
	int n;
	long long int z, w, a[2010];
	
	std::cin >> n >> z >> w;
	
	for (int i = 0; i < n; ++i)
		std::cin >> a[i];
	
	if (n > 1)
		std::cout << std::max(abs(w - a[n - 1]), abs(a[n - 1] - a[n - 2]));
	else
		std::cout << abs(w - a[n - 1]);
}

Measured memory_bytes: 256
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

s = ns()
k = ni()

w = s[0]
a = []
count = 1
for i in s[1:]:
    if w == i:
        count += 1
    else:
        a.append(count)
        count = 1
        w = i
if s.count(s[0]) == len(s):
    ans = (len(s) * k) // 2
elif w != s[0]:
    a.append(count)
    ans = 0
    for i in a:
        ans += i // 2
    ans = ans * k
else:
    al = a[0]
    ar = count
    ans = 0
    for i in a[1:]:
        ans += i // 2
    ans = ans * k
    ans += al //2 + ar //2
    ans += ((al + ar)//2) * (k -1)
print(ans)

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

int main(){
    ll n;
    string r;
    cin >> n;
    n;
    do{
        --n;
        r += n % 26 + 'a';
        n /= 26;
    }while(n);
    reverse(r.begin(), r.end());
    cout(r);
}


Measured memory_bytes: 3544
package main

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

func main() {
	io, flush := NewIO()
	defer flush()

	n := io.ScanInt()
	a := io.ScanInts(n)
	numCountMap := map[int]int{}

	for _, num := range a {
		numCountMap[num] += 1
	}

	var minDeleteCount int
	for num, count := range numCountMap {
		if num == count {
			continue
		}
		if count > num {
			minDeleteCount += count - num
			continue
		}
		minDeleteCount += count
	}
	fmt.Println(minDeleteCount)
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInt2() (int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt3() (int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt4() (int, int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}



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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;  typedef pair<int,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	
	VL a(3*n);
	for(auto& ia: a) cin >>ia;
	
	VL hdr(3*n), mig(3*n);
	priority_queue<ll> qa, qb;
	ll sm =0;
	rep(i, 3*n){
		sm += a[i];
		qa.push(-a[i]);
		if(sz(qa)> n){
			sm += qa.top();
			qa.pop();
		}
		hdr[i] = sm;
	}
	sm =0;
	repr(i, 3*n-1, 0){
		sm +=a[i];
		qb.push(a[i]);
		if(sz(qb)> n){
			sm -= qb.top();
			qb.pop();
		}
		mig[i] = sm;
		
	}
	
	//for(auto x :hdr) printf("%2d ",x); puts("");
	//for(auto x :mig) printf("%2d ",x); puts("");
	ll ans = -1 * 1LL<<60;
	
	rep2(i, n-1, 2*n) ans = max(ans , hdr[i] - mig[i+1]);
	cout << ans <<"\n";
	return 0;
}

Measured memory_bytes: 9588
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main() 
{
  string s, t; cin >> s >> t;
  if(s > t) cout << ">" << endl;
  else if(s < t)cout << "<" << endl;
  else cout << "=" << endl;
  system("pause");
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
vector<int> v(0);
int main(){
    int a,b,k; cin >> a >> b >> k;
    for(int i = 1; i <= 100; i++){
        if(a % i == 0 && b % i == 0){
            v.push_back(i);
        }
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    cout << v[k-1] << endl;
}



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

int main() {
 	int n, k;
  	cin >> n >> k;
  	int a[n + 1];
  	for(int i = 1; i <= n; i++) {
     	cin >> a[i]; 
    }
  	sort(a + 1, a + 1 + n);
  	int sum = 0;
  	for(int i = 1; i <= k; i++) {
      	sum += a[i];
    }	
  	cout << sum << "\n";
}

Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

struct mint {
    lint x; // typedef long long ll;
    mint(lint x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(lint t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

lint cnt[1000050]={};
lint savediv[1000050]={};

lint powmod(lint a,lint b){
  return b?powmod(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}

int main(void){
    int N;
    cin >> N;
    lint A[N];
    rep(i,N) cin >> A[i];
    mint ans=accumulate(A,A+N,0LL);
    ans=ans*ans;
    rep(i,N) ans-=A[i]*A[i];
    ans/=2;
    rep(i,N) cnt[A[i]]++;
    for(lint i=2;i<=1000000;i++){
        savediv[i]=(savediv[i]+i-1)%MOD;
        lint nsum=0;
        lint div2=powmod(i,MOD-2);
        for(lint j=i;j<=1000000;j+=i){
            lint minus=(nsum*((j*cnt[j])%MOD))%MOD;
            minus=(minus*savediv[i])%MOD;
            minus=(minus*div2)%MOD;
            ans-=minus;
            nsum=(nsum+cnt[j]*j)%MOD;
            if(j!=i) savediv[j]=(savediv[j]-(savediv[i]*(j/i))%MOD+MOD)%MOD;
        }
        if(cnt[i]>=2){
            ans-=((cnt[i]*(cnt[i]-1)/2)%MOD)*((i*i-i)%MOD);
        }
    }
    cout << ans << endl;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  rep(i, s.length()){
    if(t.at(i) != s.at(i)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
    
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>
int main(void){
  int N;
  int D;
  int i;
  int s=0;
  scanf("%d %d",&N,&D);
  for(i=0;i<N;i++){
    int x,y;
    double a,b;
    scanf("%d %d",&x,&y);
    a=pow(x,2.0)+pow(y,2.0);
    b=sqrt(a);
    if(b<=D){
      s=s+1;
    }
  }
  
  printf("%d\n",s);
  return 0;
}

Measured memory_bytes: 2128
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<vector>


using namespace std;



int main() {


	string s;
	cin >> s;
	
	int count = 0;


	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'o')
			count++;
	}



	if (15-s.size() >= 8-count)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}



Measured memory_bytes: 256
s = input()

if s.count("N")==0 and s.count("S")>=1:
  print("No")
elif s.count("N")>=1 and s.count("S")==0:
  print("No")
elif s.count("E")==0 and s.count("W")>=1:
  print("No")
elif s.count("E")>=1 and s.count("W")==0:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rep(i, a, b) for(ll i = a; i < b; ++i)
using namespace std;
typedef long long ll;
typedef vector<ll> vll;

int main()
{
	FIO;
    ll n;
    cin >> n;
    string ans = "";
    while(n > 0) {
        n--;
        ans += char('a' + (n % 26));
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans ;
	return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
int main(void)
{
    int n,i;
    long long int s=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        if(((i%3)!=0)&&((i%5)!=0))
        s+=i;
    }
    printf("%lld\n",s);
    return 0;
}

Measured memory_bytes: 1732
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()

typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    vector <pair<int, int> > v[n];
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        while (x--) {
            int y, z;
            cin >> y >> z;
            y--;
            v[i].pb({y, z});
        }
    }
    int k = (1 << n);
    int ans = 0;
    for (int mask = 0; mask < k; mask++) {
        int kek = mask;
        int sum = 0;
        vector <bool> flex(n, false);
        for (int i = 0; i < n; i++) {
            flex[i] = kek % 2;
            sum += kek % 2;
            kek /= 2;
        }
        bool ok = true;
        for (int i = 0; i < n; i++) {
            for (auto it : v[i]) {
                if (flex[i]) {
                    ok &= (flex[it.first] == it.second);
                }
            }
        }
        if (ok) {
            ans = max(ans, sum);
        }
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
    int N;
    string s, t;
    cin >> N;
    cin >> s >> t;
    int flag = 1;
    int arg = 2*N;
    for(int i=0; i<N; i++){
        for(int j=0; j<N-i; j++){
            if(s.at(j+i) != t.at(j)){
                flag = 0;
            }
        }
        if(flag == 1){
            arg = i;
            break;
        }
        flag = 1;
    }
    if(arg == 2*N){
        cout << arg << endl;
        return 0;
    }
    cout << N + arg << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int cup[3]={1,0,0};
	char x,y;
	while(scanf("%c,%c",&x,&y)!=EOF){
		int t,num1,num2;
		num1 = x-'A';
		num2 = y-'A';
		t=cup[num1];
		cup[num1]=cup[num2];
		cup[num2]=t;
	}
	int i;
	for(i=0;i<3;i++){
		if(cup[i]==1)
			printf("%c\n",'A'+i);
	}
	return 0;
}

Measured memory_bytes: 544
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  startupcpp();
  ll i,N;
  map<string,int> mp;
  cin>>N;
  vector<string> v(N);
  rep(i,N)cin>>v[i];
  mp[v[0]]++;
  rep1(i,N){
    if(mp[v[i]]||v[i][0]!=v[i-1][v[i-1].size()-1]){
      printno;
      return 0;
    }
    mp[v[i]]++;
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int n, m;
int c[26];
int s[400][26];
int t[400], ssc[400];
void input() {
    cin >> n;
    m = 26;
    for (int i = 0; i < m; i++) cin >> c[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> s[i][j];
        }
    }
}
void output() {
    for (int i = 0; i < n; i++) {
        cout << t[i] + 1 << newl;
    }
}
int pl = 0, mi = 0;
int score() {
    V<int> last(m, -1);
    int res = 0;
    for (int i = 0; i < n; i++) {
        res += s[i][t[i]];
        last[t[i]] = i;
        for (int j = 0; j < m; j++) {
            res -= c[j] * (i - last[j]);
        }
    }
    return res;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    input();
    int lim = 100000;
    random_device rd;
    mt19937 mt(rd());
    uniform_int_distribution<> rn(0, n - 1), rc(0, m - 1);
    uniform_real_distribution<> r1(0, 1);
    int mid = *max_element(c, c + 26);
    for (int i = 0; i < n; i++) {
        t[i] = mid;
    }
    int now = score();
    cerr << now << newl;
    double tmp = 30;
    for (int co = 0; co < lim; co++) {
        int d = rn(mt), i = rc(mt);
        int be = t[d];
        t[d] = i;
        int sc = score();
        if (sc > now || exp(-(now - sc) / tmp) > r1(mt)) {
            now = sc;
        } else {
            t[d] = be;
        }
        tmp -= 30.0 / double(lim);
    }
    output();
    cerr << pl << " " << mi << newl;
    cerr << now << newl;
}


Measured memory_bytes: 4280
from itertools import accumulate


def binary(N, T):  # 二分探索 # N:探索要素数
    l, r = -1, N
    while r - l > 1:
        if T < b[(l + r) // 2]:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return r - 1


n, m, k = map(int, input().split())
a = [0] + list(accumulate(map(int, input().split())))
b = [0] + list(accumulate(map(int, input().split())))

ans = 0
for i, ai in enumerate(a):
    t = k - ai
    if t >= 0:
        j = binary(m + 1, t)
        ans = max(ans, i + j)
print(ans)


Measured memory_bytes: 45848
n, m = gets.split.map(&:to_i)
as = []
bs = []
cs = []
INF = 2 ** 50
ds = Array.new(n){ INF }
ds[0] = 0
m.times do
  a, b, c = gets.split.map(&:to_i)
  as << a
  bs << b
  cs << -c
end

(n-1).times do
  m.times do |i|
    s = as[i] - 1
    d = bs[i] - 1
    next if ds[s] == INF
    if ds[d] > ds[s] + cs[i]
      ds[d] = ds[s] + cs[i]
    end
  end
end

tmp = ds[n-1]
m.times do |i|
  s = as[i] - 1
  d = bs[i] - 1
  next if ds[s] == INF
  if ds[d] > ds[s] + cs[i]
    ds[d] = ds[s] + cs[i]
  end
end

if ds[n-1] < tmp
  puts "inf"
else
  puts -tmp
end


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		bool ok = true;
		rep(i, N) {
			UL a; cin >> a;
			if ((a & 1) == 0)
				if (a % 3 != 0)
					if (a % 5 != 0) { ok = false; }
		}
		cout << (ok ? "APPROVED" : "DENIED") << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N;
string S;

inline bool check() {
    if(S[N-1] == '1') return true;
    bool all_zero = true;
    REP(i, N/2) {
        if(S[i] != S[N-2-i]) return true;
        if(S[i] == '1') all_zero = false;
    }
    return all_zero;
}

int main() {
    fastio();
    cin >> S;
    N = S.size();
    if(check()) {
        cout << -1 << "\n";
        return 0;
    }
    int p = 1, c;
    for(int i = 2; i <= N; i++) {
        cout << p << " " << i << "\n";
        if(S[N-i] == '1') p = i;
    }
	return 0;
}

Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

long long calc(ll A){
    if(A<=0) return 0;
    ll ans=0;
    A+=1;
    for(int i=0;i<50;i++){

        ll loop=(1LL<<(i+1));
        ll cnt=(A/loop)*(loop/2);
        cnt+=max(0LL,(A%loop)-(loop/2));
    if(cnt%2==1){
        ans+=1LL<<i;
    }
}
        return ans;
}

int main(){
    
    ll A,B;
    cin>>A>>B;
    ll ans=calc(B)^calc(A-1);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]


N = int(input())
A, B = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]

a = b = c = 0
for p in P:
    if p <= A:
        a += 1
    elif p <= B:
        b += 1
    else:
        c += 1

print(min(a, b, c))


Measured memory_bytes: 3060
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p=p[:x]
q=q[:y]
p[len(p):len(p)]=q
p[len(p):len(p)]=r
p.sort(reverse=True)
print(sum(p[:x+y]))

Measured memory_bytes: 23328
//
//  main.cpp
//  Tenka1PBC2019
//
//  Created by hiroaki on 2019/04/21.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main() {
//    int a,b,c;
//    cin >>a>>b>>c;
//    if (a<c&&c<b) {
//        cout<<"Yes"<<endl;
//    }else if(b<c&&c<a){
//        cout<<"Yes"<<endl;
//    }else{
//        cout<<"No"<<endl;
//    }
    
    int n,k;
    string s;
    cin >>n>>s>>k;
    char c = s[k-1];
    string r;
    for (int i=0; i<n; i++) {
        if (s[i]==c) {
            r.push_back(c);
        }
        else{
            r.push_back('*');
        }
    }
    cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();int m=in();
	map<int,bool> o,e;
	int u,v;
	for(int i=0;i<m;i++)
	{
		u=in();v=in();
		if(u==1)o[v]=1;
		else if(u==n)e[v]=1;
		if(v==1)o[u]=1;
		else if(v==n)e[u]=1;
	}
	
	bool ok=0;
	for(auto i:o)
	{
		if(e[i.first])ok=1;
	}
	if(ok)puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;


int main() {

    ll H;
    cin >> H;
    ll ans = 0;
    ll i = 1;

    while(H > 0){
        H /= 2;
        ans += i;
        i *= 2;
    }

    cout << ans << endl;
    
    
    
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    std::cin >> s;
    if(s[0]=='S'){
        std::cout << "Cloudy" << std::endl;
    }else if(s[0]=='C'){
        std::cout << "Rainy" << std::endl;
    }else{
        std::cout << "Sunny" << std::endl;
    }
}


Measured memory_bytes: 256
#pragma GCC optimize("O2")
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <ctime>
#include <set>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 * 2 + 10;

vector<ll> vec;
ll q;

int main() {
    fastInp;

    string s, t;
    cin >> s;
    cin >> t;

    for (int i = 0; i < 26; i++) {
        s.push_back('a' + i);
        if (s == t) {
            cout << "Yes";
            return 0;
        }
        s.pop_back();
    }

    cout << "No";
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    int N; cin >> N;
    int tmp = N;
    int sum = 0;
    while (tmp >= 1) {
        sum += tmp % 10;
        tmp /= 10;
    }
    N % sum == 0 ? cout << "Yes" << endl : cout << "No" << endl;

}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int i=0;
    int c,ans=0;
    while (i<3)
    {
        if (s[i]=='R')
        {
            c=0;
            while (s[i]=='R')
            {
                i++;
                c++;
            }
        }
        else
        i++;
        
        ans=max(ans,c);
    }
    cout<<ans;
}

Measured memory_bytes: 3504
S = input()


str12=int(S[0:2])
str34=int(S[2:4])

str12_enableMM = False
if 1 <= str12 and str12 <= 12:
    str12_enableMM = True

str34_enableMM = False
if 1 <= str34 and str34 <= 12:
    str34_enableMM = True



ans="NA"

if str12_enableMM is False:
    if str34_enableMM is False:
        pass
    else:
        ans = "YYMM"
else:
    if str34_enableMM is False:
        ans = "MMYY"
    else:
        ans = "AMBIGUOUS"

print(ans)

Measured memory_bytes: 38384
from itertools import product

N,a,b,c = map(int,input().split())
L = list(int(input()) for i in range(N))

ans = float("inf")

for prod in product(range(4), repeat=N) :
    A = []
    B = []
    C = []
    for i in range(len(prod)) :
        if prod[i] == 1 :
            A.append(L[i])
        elif prod[i] == 2 :
            B.append(L[i])
        elif prod[i] == 3 :
            C.append(L[i])
    
    if len(A) * len(B) * len(C) == 0 :
        continue
    cost = 0
    for li in [A,B,C] :
        cost += (len(li)-1)*10
    cost += abs(a-sum(A)) + abs(b-sum(B)) + abs(c-sum(C))
    ans = min(ans,cost)
print(ans)


Measured memory_bytes: 3064