akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-7

typedef long long ll;
typedef pair<ll,ll> P;
double high[66];
int n,r;

//チェック関数
bool check(double mid){
	for(int i = 30-r;i < 30+r;i++){
		if(high[i] < mid)return false;
		double A = sqrt((i-30)*(i-30) + (high[i]-mid)*(high[i]-mid));
		double B = sqrt((i-29)*(i-29) + (high[i]-mid)*(high[i]-mid));
		if(min(A,B) < r + EPS)return false;
	}
	return true;
}

int main(){
	while(cin >> r >> n,r|n){
		//初期
		REP(i,66)high[i] = 0;
		
		
		REP(i,n){
			int a,b;
			double c;
			cin >> a >> b >> c;
			for(int j = a;j < b;j++){
				high[j+30] = max(high[j+30],c);
			}
		}
		
		//ちゃんと余裕をもって値をとる
		double tb = 100;
		double ub = -100;
		DBG(SHOW1d(high,66));
		REP(i,1000){
			double mid = (tb + ub) / 2;
			if(check(mid))ub = mid;
			else tb = mid;
		}
		
		//にぶたんで求めたのは中心の高さなので、半径の分だけ時間を足す
		cout << Decimal << (double)(ub+r) << endl;
	}
	return 0;
}


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

int main() {

    string s; cin >> s;
    ll wa = 0LL;
    while (0 < s.size()) {
        string t = { s.back() };
        ll tmp = stoll(t);
        wa += tmp;
        s.pop_back();
    }
    string ans;
    if (wa % 9 == 0) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3740
N,K=map(int,input().split())
a=list(map(int,input().split()))
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=cum[i]+a[i]
A=[]
for i in range(N+1):
    for j in range(i):
        A.append(cum[i]-cum[j])
L=len(A)
ans=0
for j in reversed(range(46)):
    li=[]
    for i in range(L):
        if A[i]>>j&1:
            li.append(A[i])
    if len(li)<K:
        continue
    ans+=1<<j
    A=li
    L=len(A)
print(ans)

Measured memory_bytes: 116836
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    num_list = i_list()

    tmp_list = [0] * 8
    count = 0

    max_count = 0

    for num in num_list:
        if num // 400 >= 8:
            max_count += 1
            continue
        if tmp_list[num//400] == 0:        
            tmp_list[num//400] = 1

    for i in tmp_list:
        if i == 1:
            count += 1
    
    if count == 0:
        print(1, max_count)
    else:
        print(count, count + max_count)
        

if __name__ == '__main__':
    main()


Measured memory_bytes: 77100
#include<iostream>
#include<vector>
#include<string>

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
template<class T> inline void chmax(T& a, T b) { if(a < b) a = b; }
template<class T> inline void chmin(T& a, T b) { if(a > b) a = b; }

int main(){
	int N;
	std::cin >> N;
	std::vector<ll> A(N);
	rep(i, N) std::cin >> A[i];
	A.push_back(0);

	ll coin = 1000;
	ll kabu = 0;
	rep(i, N){
		if(A[i] < A[i+1] && coin > A[i]){
			kabu = coin / A[i];
			coin -= kabu * A[i];
		}
		if(A[i] > A[i+1] && kabu > 0){
			coin += kabu * A[i];
			kabu = 0;
		}
	}
	std::cout << coin << std::endl;
	return 0;
}

Measured memory_bytes: 3596
N, M  = map(int,input().split())
As = sorted(list(map(int,input().split())))
di = {}
for i in range(M):
    b, c = map(int,input().split())
    di[c] = di.get(c, 0) + b

keys = list(sorted(di.keys(), reverse=True))
ichi = 0
for i in range(N):
    try:
        if keys[ichi] > As[i]:
            As[i] = keys[ichi]
            di[keys[ichi]] -= 1
        else:
            break
        if di[keys[ichi]] == 0:
            ichi += 1
    except:
        pass
print(sum(As))


Measured memory_bytes: 76268
#include <iostream>
#include <algorithm>
#include <string>
#include <limits.h>
#include <vector>
#include <numeric>

using namespace std;



bool gooddis(long long int n) {

	long long int a = 0;

	while (n >= a * a) {
		if (n == a * a)return true;
		a++;
	}

	return false;
}


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

	vector<vector<int>> x;
	

	for (int i = 0; i < n; i++) {
		vector<int> wk(d);

		for (auto& j : wk)cin >> j;

		x.push_back(wk);
	}

	int ans = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			long long int dis = 0;

			for (int k = 0; k < d; k++) {
				dis += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}

			if (gooddis(dis))ans++;



		}
	}
	
	cout << ans << endl;


	return 0;

}




Measured memory_bytes: 256
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

type TrieNode struct {
  depth int
  children []*TrieNode
}
func InitTrieNode(d int) *TrieNode {
  c := make([]*TrieNode, 2)
  t := TrieNode{d, c}
  return &t
}

func Solve() {
  var N, L, _s int
  var t *TrieNode
  NextInt(&N, &L)
  T := make([]*TrieNode, 100001)
  T[0] = InitTrieNode(0)
  pos := 1
  for i := 0; i < N; i++ {
    t = T[0]
    for i, s := range NextLine() {
      _s = int(s) - int('0')
      if (*t).children[_s] == nil {
        T[pos] = InitTrieNode(i + 1)
        (*t).children[_s] = T[pos]
        pos++
      }
      t = (*t).children[_s]
    }
  }
  cnt := 0
  for _, t = range T {
    if t == nil { break }
    if ((*t).children[0] == nil) != ((*t).children[1] == nil) { cnt ^= (L - (*t).depth) & ((*t).depth - L) }
  }
  if cnt > 0 {
    Write("Alice")
  } else {
    Write("Bob")
  }
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main() {
  int n,k;
  cin >> n >> k;
  int a = 1;

  rep(i,1,n+1){
    if(2*a < a+k) a = 2*a;
    else a = a+k;
  }
  printf("%d\n",a);

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int LEN = 0;

	void doIt() {
		int n = sc.nextInt();
		long a[] = new long[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		long ans = 0;
		for(int i = 0; i <= 60; i++) {
			long zero = 0, one = 0;
			for(int j = 0; j < n; j++) {
				if((a[j] >> i & 1) == 1)one++;
				else zero++;
				//System.out.println(one + " " + zero);
			}
			//System.out.println(one + " " + zero);
			long num = zero * one % (long)MOD;
			//System.out.println(num);
			for(int j = 0; j < i; j++) {
				num = (num << 1) % (long)MOD;
			}
			ans = (ans + num) % (long)MOD;
		}
		System.out.println(ans % (long)MOD);
	}

	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 99568
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define NUM 1000000007
#define MAX 100001
#define INF LLONG_MAX
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,a,b;
    cin>>n;
    vector<pair<ll,ll>> v;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        v.pb({a,b});
    }
    int flag=0;
    for(int i=0;i<n-2;i++){
        int aa = v[i].first, bb = v[i].second;
        int rr = v[i+1].first, ss = v[i+1].second;
        int xx = v[i+2].first, yy = v[i+2].second;
        if(aa==bb && rr==ss && xx==yy){
            flag=1;
            cout<<"Yes"<<endl;
            break;
        }
    }
    if(flag==0)
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3640
n, k = gets.chomp.split(' ').map(&:to_i)
a = gets.chomp.split(' ').map(&:to_i)

route = Hash.new(0)
sub = Hash.new(0)
s = []
i = 1
l = 0

k.times do |j|
  i = a[i-1]
  if route.has_key?(i.to_s)
    if sub.has_key?(i.to_s)
      t = (k - l - 1) % s.length
      i = s[t]
      break
    else
      l = j if l == 0
      s << i
      sub[i.to_s] += 1
      route[i.to_s] += 1
    end
  else
    route[i.to_s] += 1
  end
end

print i


Measured memory_bytes: 50184
#include <stdio.h>
#include <float.h>

int main()
{
  int n,a;
  scanf("%d",&n);
  if(n%2==0)printf("0.5\n");
  else{
    a=n - n/2;
    printf("%.10lf\n",(double)a/(double)n);
  }

  return 0;
  
}


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

int main()
{
    long long x;

    cin >> x;
    long long count = 0;
    long long first = 100;
    while (true) {
        
        count++;
        first = floor(first * 1.01);
        if (first >= x)break;
    }
    cout << count << endl;

    return 0;
}




Measured memory_bytes: 3260
use std::io;
use std::str::FromStr;

fn main() {
    loop {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).ok();
        let mut iter = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());
        let (x, y, s) = (
            iter.next().unwrap(),
            iter.next().unwrap(),
            iter.next().unwrap(),
        );
        if x == 0 && y == 0 && s == 0 {
            return;
        }

        let mut yen_max = 0;
        for yen_a in 1..s {
            for yen_b in yen_a..s {
                if yen_a * (100 + x) / 100 + yen_b * (100 + x) / 100 == s {
                    let yen_candidate = yen_a * (100 + y) / 100 + yen_b * (100 + y) / 100;
                    if yen_candidate > yen_max {
                        yen_max = yen_candidate;
                    }
                } else if yen_a * (100 + x) / 100 + yen_b * (100 + x) / 100 > s {
                    break;
                }
            }
        }
        println!("{}", yen_max);
    }
}



Measured memory_bytes: 5024
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::iter::once;
#[cfg(debug_assertions)]
include! {"./debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

macro_rules! read {
    ([$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ([$t:ident]) =>
        (rl().split_whitespace().map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    (_, [$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!(_, [$t])).collect::<Vec<_>>());
    (_, [$t:ident]) =>
        (rl().split_whitespace().skip(1).map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    ($($t:ident),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ($t:ident) => (read_type!(rl(), $t));
    ($($t:ident),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(read_type!(w.next().unwrap(), $t)),*)
    }};
}

macro_rules! read_type {
    ($s:expr, chars) => {
        $s.chars().collect::<Vec<char>>()
    };
    ($s:expr, usize1) => {
        read_type!($s, usize) - 1
    };
    ($s:expr, $t:ty) => {
        $s.parse::<$t>().unwrap()
    };
}

fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

////////////////////////////////////////////////////////////////////////////////

fn main() {
    let (n, a, b) = read!(usize, usize, usize);

    let ans = min(a * n, b);

    println!("{}", ans);
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
N = int(input())

C = list(map(int, input().split()))

C.sort(reverse=True)

color = 0
size  = -1
comp  = 0
c_color = 0
c_update = True
for i in range(0, N):
    # C[i] can eat the bigger one
    if C[i] >= size / 2:
        color += 1
        size = C[i]
        continue
    # need to eat some
    else:
        comp += C[i]
        if c_color == 0 or (c_update and C[i -1] <= C[i] * 2):
            c_color += 1
        else:
            c_update = False
    # some composite creature can eat it
    if comp >= size/2:
        color += c_color
        size = comp
        comp = 0
        c_color = 0
        c_update = True
print(color)

Measured memory_bytes: 14252
#include <iostream>
int main(){
    using namespace std;
    int n,b,f,r,v,i,j;
    cin >> n;
    int a1[10] = {};
    int a2[10] = {};
    int a3[10] = {};
    int a4[10] = {};
    int a5[10] = {};
    int a6[10] = {};
    int a7[10] = {};
    int a8[10] = {};
    int a9[10] = {};
    int a10[10] = {};
    int a11[10] = {};
    int a12[10] = {};
    for(i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        if(b==1){
            if(f==1){
                a1[r-1] += v;
            }else if(f==2){
                a2[r-1] += v;
            }else if(f==3){
                a3[r-1] += v;
            }
        }else if(b==2){
            if(f==1){
                a4[r-1] += v;
            }else if(f==2){
                a5[r-1] += v;
            }else if(f==3){
                a6[r-1] += v;
            }

        }else if(b==3){
            if(f==1){
                a7[r-1] += v;
            }else if(f==2){
                a8[r-1] += v;
            }else if(f==3){
                a9[r-1] += v;
            }
        }else if(b==4){
            if(f==1){
                a10[r-1] += v;
            }else if(f==2){
                a11[r-1] += v;
            }else if(f==3){
                a12[r-1] += v;
            }
        }
    }
    for(i=0;i<10;i++){
        cout << " " << a1[i];
    }
    cout << endl;
    for(i=0;i<10;i++){
        cout << " " << a2[i];
    }
    cout << endl;
    for(i=0;i<10;i++){
        cout << " " << a3[i];
    }
    cout << endl;
    for(i=0;i<20;i++){
        cout << "#";
    }
    cout << endl;
    for(i=0;i<10;i++){
        cout << " " << a4[i];
    }
    cout << endl;
    for(i=0;i<10;i++){
        cout << " " << a5[i];
    }
    cout << endl;
    for(i=0;i<10;i++){
        cout << " " << a6[i];
    }
    cout << endl;
    for(i=0;i<20;i++){
        cout << "#";
    }
    cout << endl;
    for(i=0;i<10;i++){
        cout << " " << a7[i];
    }
    cout << endl;
    for(i=0;i<10;i++){
        cout << " " << a8[i];
    }
    cout << endl;
    for(i=0;i<10;i++){
        cout << " " << a9[i];
    }
    cout << endl;
    for(i=0;i<20;i++){
        cout << "#";
    }
    cout << endl;
    for(i=0;i<10;i++){
        cout << " " << a10[i];
    }
    cout << endl;
    for(i=0;i<10;i++){
        cout << " " << a11[i];
    }
    cout << endl;
    for(i=0;i<10;i++){
        cout << " " <<a12[i];
    }
    cout << endl;
    return 0;
}

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

string a,b,c;

bool in(char z){
  for(int i=0;i<c.length();i++){
    if(c[i]==z)return true;
  }
  return false;
}

int main()
{

  while(1){
    cin>>a;
    if(a[0]=='-')break;
    cin>>b>>c;

    queue<char> A,B;
    string ans="";
    for(int i=0;i<a.length();i++)A.push(a[i]);
    for(int i=0;i<b.length();i++)B.push(b[i]);
 
    char m=B.front();
    B.pop();
    while(!B.empty() || !A.empty()){
      if(in(m)){
	m=A.front();
	A.pop();
      }
      else {
	ans+=m;
	m=B.front();
	B.pop();
      }
    }
    cout<<ans+m<<endl;
  }
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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; }

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  cout << min(n % k, abs((n % k) - k)) << endl;
}


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

int main() {
  int a[]={0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x,y; cin>>x>>y;
  cout<<(a[x]==a[y]?"Yes":"No")<< endl;
}


Measured memory_bytes: 256
N = int(input())
A = [[int(a) for a in input().split()] for _ in range(2)]

LeftSum = [0]
RightSum = [sum(A[1])]
for i in range(N):
    LeftSum.append(LeftSum[-1]+A[0][i])
    RightSum.append(RightSum[-1]-A[1][i])

AddSum = [LeftSum[i+1]+RightSum[i] for i in range(N)]
print(max(AddSum))

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

struct nm{
		int ca;
		int dn;
		int c;
		int n;
};

int compare_intnm(const void *a,const void *b){
		struct nm A=*(struct nm*)a,B=*(struct nm*)b;
		if(A.ca>B.ca)return 1;
		else{
				if(A.ca<B.ca)return -1;
				return A.dn-B.dn;
		}
}
int compare_intnma(const void *a,const void *b){
		struct nm A=*(struct nm*)a,B=*(struct nm*)b;
		return A.n-B.n;
}

struct nm hel[200001];
int par[200000];
int rank[200000];

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

int find(int x){
		if(par[x]==x)return x;
		return par[x]=find(par[x]);
}

void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(rank[x]<rank[y]){
				par[x]=y;
				rank[y]+=rank[x];
		}else{
				par[y]=x;
				rank[x]+=rank[y];
		}
}

int same(int x,int y){
		if(find(x)==find(y))return 1;
		return 0;
}

int main(){
		int n,k,l,i,pq[2],rs[2];
		scanf("%d%d%d",&n,&k,&l);
		init(n);
		for(i=0;i<n;i++)hel[i].n=i;
		for(i=0;i<k;i++){
				scanf("%d%d",&pq[0],&pq[1]);
				pq[0]--,pq[1]--;
				unite(pq[0],pq[1]);
		}
		for(i=0;i<n;i++)hel[i].ca=find(i);
		init(n);
		for(i=0;i<l;i++){
				scanf("%d%d",&rs[0],&rs[1]);
				rs[0]--,rs[1]--;
				unite(rs[0],rs[1]);
		}
		for(i=0;i<n;i++)hel[i].dn=find(i);
		qsort(hel,n,sizeof(struct nm),compare_intnm);
		int tmp=1,cc=0;
		for(i=1;i<=n;i++){
				if((hel[i].ca!=hel[i-1].ca)||(hel[i].dn!=hel[i-1].dn)){
						for(int j=i-1;j>=cc;j--)hel[j].c=tmp;
						tmp=1;
						cc=i;
				}else tmp++;
		}
		qsort(hel,n,sizeof(struct nm),compare_intnma);
		for(i=0;i<n;i++)printf("%d ",hel[i].c);
		puts("");
		return 0;
}


Measured memory_bytes: 8332
#include <iostream>
#include <map>
#include <string>
#include <sstream>

using namespace std;

map< int, map<int, int> > cache;
int index;

string to_s(int n) {
    ostringstream os;
    os << n;
    return os.str();
}

int p, q;
string calc(int n, int d) {
    if (cache[n][d] != 0) {
        string ret;
        ret.push_back('\n');
        for (int i = 0; i < cache[n][d]-1; i++) ret.push_back(' ');
        for (int i = 0; i < index-cache[n][d]; i++) ret.push_back('^');
        ret.push_back('\n');
        return ret;
    }

    if (n % d == 0) return to_s(n/d) + "\n";
    cache[n][d] = index++;
    return to_s(n/d) + calc((n%d)*10, d);
}

int main() {
    while (cin >> p >> q) {
        index = 1; 
        cache.clear();
        cout << calc(p*10, q);
    }
    return 0;
}

Measured memory_bytes: 1276
#include <iostream>
using namespace std;
int main() {
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++)
        for (int j = i; j < s.size(); j++) {
            if (s.substr(0, i) + s.substr(j, s.size()-j) == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
        }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[210];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n*2;i++)cin>>a[i];
	sort(a,a+n*2);
	int cnt=0;
	for(int i=0;i<n*2;i+=2)cnt+=a[i];
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import product
from collections import defaultdict

N = int(input())
M = int(N**(0.5) + 1)

dict = defaultdict(int)

for x, y, z in product(range(1,M+1),repeat=3):
    dict[x**2 + y**2 + z**2 + x*y + y*z + z*x] += 1

for i in range(1,N+1):
    print(dict[i])


Measured memory_bytes: 75392
#include<iostream>
using namespace std;
int main(){
    long long s;
    cin>>s;
  if(s==1||s==2) cout<<4;
  else{
    int ans=0;
    while(s!=4){
        if(s%2==0) s=s/2;
        else s=s*3+1;
        ans++;
    }
    cout<<ans+3+1;
  }
}

Measured memory_bytes: 256
# coding: utf-8

n = int(input())

output = 0
# n = (m+1)*x = y*x (y>=2)
limit = pow(n+0.25, 0.5)-0.5
x = 1
while x < limit:
    if n % x == 0:
        output += n // x - 1
    x += 1

print(output)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
	
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b=sc.nextInt();
		int ans;
		ans = Math.max(a+b, a-b);
		ans = Math.max(ans, a*b);
		
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] d = new int[N];
        for (int i = 0; i < N; i++) {
            d[i] = scan.nextInt();
        }
        Arrays.sort(d);
        System.out.println(d[N/2]-d[N/2-1]);
    }
}


Measured memory_bytes: 51040
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')
YES = "Yes"  # type: str
NO = "No"  # type: str


def is_palindrome(s: str):
    return s[:len(s)//2] == s[::-1][:len(s)//2]


def solve(S: str):
    return [NO, YES][is_palindrome(S) and is_palindrome(S[:(len(S)-1)//2-1+1]) and is_palindrome(S[(len(S)+3)//2-1:])]


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    print(f'{solve(S)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75200
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    for (ll i = 1; i <= n; ++i) {
        if (i * (i+1) / 2 >= n) {
            int k = i * (i+1) / 2 - n;
            for (int j = 1; j <= i; ++j) {
                if (j == k) continue;
                cout << j << endl;
            }
            return 0;
        }
    }
}


Measured memory_bytes: 3616
/*
Miles Morales : When will I know I'm ready?
Peter B. Parker : You won't. It's a leap of faith. That's all it is, Miles. A leap of faith.
*/
//KEEP IT SIMPLE STUPID
/*#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define print(o) for(auto it=(o).begin();it!=(o).end();it++) cout<<*it<<" ";
#define vll vector<ll>
#define pb push_back
#define FOR(n) for(ll i=0;i<=n;i++)
#define FORd(n) for(ll i=n;i>=0;i--)
#define FORrd(a,b) for(ll i=a;i>=b;i--)
#define FORr(a,b) for(ll i=a;i<=b;i++)
#define all(x) (x).begin(),(x).end()
#define FIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define ff first
#define ss second
#define w(t) ll t;cin>>t;while(t--)

int main()
{
    ll k;
    cin>>k;
    ll ans=0;
    for(ll a=1;a<=k;a++)
    {
        for(ll b=1;b<=k;b++)
        {
            for(ll c=1;c<=k;c++)
            {
                ans+=__gcd(a,__gcd(b,c));
            }
        }
    }
    cout<<ans<<'\n';
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 3672
import copy

N = int(input())
a = [0]+list(map(int, input().split()))
b = [0 for _ in range(N+1)]
for j in range(N, 0, -1):
    if j > N//2:
        b[j] = a[j]
    if sum(b[n*j] for n in range(2, (N//j)+1)) % 2 != a[j]:
        b[j] = 1

print(sum(b[1:]))
if sum(b[1:]) != 0:
    print(*[i for i, j in enumerate(b) if j == 1])


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

int main(){
string s[3];
  cin>>s[0]>>s[1]>>s[2];

int turn=0, ans;  
 while(true){
  if(s[turn].size()==0){
   ans=turn; break; }
   
  int n = s[turn][0]-'a'; // 'a'は数字として扱われており、a-a=0,c-a=2になっている
  s[turn]=s[turn].substr(1, s[turn].size()-1);
   turn=n;
 }
  if(ans==0){cout<<"A"<<endl;}
  else if(ans==1){cout<<"B"<<endl;}
  else{cout<<"C"<<endl;}
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String x = sc.nextLine();
            if (x.equals("0"))
                break;
            int sum = 0;
            for (int i = 0; i < x.length(); i++) {
                char c = x.charAt(i);
                sum += c - '0';
            }
            System.out.println(sum);
        }
    }
}


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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

int main(int argc, char const* argv[])
{
  int n, k;
  cin>>n>>k;

  vector<int> ps(k);
  int sum = 0;
  int max_sum = 0;
  REP(i,n) {
    int pos = i%k;
    int p_plus1;
    cin>>p_plus1;
    p_plus1++;
    if(ps[pos]) {
      sum -= ps[pos];
    }
    sum += p_plus1;
    ps[pos] = p_plus1;
    if(max_sum < sum) max_sum = sum;
  }

  printf("%.12f\n", (double)max_sum/2);

  return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	for(int i = 1;i <= k;i++){
		if(a>=b && a>=c){
			a *= 2;
			continue;
		}
		if(b >= a&&b>=c){
			b *= 2;
			continue;
		}
		if(c >= a && c>=b){
			c *= 2;
			continue;
		}
	}
	cout<<a+b+c<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque

H,W = map(int,input().split())
maze = [[] for i in range(H)]
con = 0
inf = 10 ** 6
distance = [[inf] * W for i in range(H)]

for i in range(H):
  m = list(input())
  maze[i] = m
  con += m.count("#")

def bfs(maze, distance, sh, sw):
  queue = deque([[sh, sw]])
  distance[sh][sw] = 0
  while queue:
    h,w = queue.popleft()
    if h == H - 1 and w == W - 1:
      return distance[H - 1][W - 1]
    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
      new_h, new_w = h + j, w + k
      if new_h < 0 or new_h >= H or \
        new_w < 0 or new_w >= W:
          continue
      elif maze[new_h][new_w] != "#" and \
        distance[new_h][new_w] > distance[h][w] + 1:
        distance[new_h][new_w] = distance[h][w] + 1

        queue.append([new_h, new_w])
  
minpath = bfs(maze,distance,0,0)

if minpath == None:
  print(-1)
else:
  print(H * W - minpath - con - 1)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
 #define ll long long int
 using namespace std;
 int main()
 {
    ll n,w;
    cin>>n>>w;
    ll x,y;
    vector<pair<ll,ll>> v;
    for(ll i=0;i<n;i++)
    {
        cin>>x>>y;
        v.push_back({x,y});
    }
    ll dp[n+1][w+1];
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=w;j++)
        {
            if(i==0||j==0)
                dp[i][j]=0;
            else
                if(v[i-1].first<=j)
                    dp[i][j]=max((v[i-1].second+dp[i-1][j-v[i-1].first]),dp[i-1][j]);
                else
                    dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w]<<endl;
 }

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

 using namespace std;
 char var[110];
 int main(){
 int a,b;
   scanf("%d%d",&a,&b);
 for(int i=0;i<b;i++)
   var[i]='0'+a;
 string L=var;
 for(int i=0;i<a;i++)
   var[i]='0'+b;
var[a]=0;
string R=var;
printf("%s\n",min(L,R).c_str());
}

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

const int64_t MOD=1000000007;

int64_t frac(int64_t n){
  if(n==0){return 1;}
  else{
    return (n*frac(n-1))%MOD;
  }
}

int main(){
  int64_t N,M;
  cin>>N>>M;
  
  if(abs(N-M)>1){
    cout<<0<<endl;
  }
  else if(abs(N-M)==1){
    cout<<(frac(N)*frac(M))%MOD<<endl;
  }
  else{
    cout<<(2*frac(N)*frac(M))%MOD<<endl;
  }
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <cinttypes>

#define fi first
#define se second


using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

#define int ll

const int INF = 1e18 + 10;

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

  vector<int> s(n);

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

  int t = s[n - 1];
  int ans = INF;

  for (int i = 0; i < n - 1; i++) {
    int temp = abs(s[i] - (t - s[i]));
    ans = min(ans, temp);
  }


  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;


int H,W,K;
int sx,sy,gx,gy;
vector<char>c[1000005];
vector<int>dis[1000005];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
signed main(){
	cin>>H>>W>>K;
	cin>>sx>>sy>>gx>>gy;
	sx--;sy--;gx--;gy--;
	rep(i,H){
		c[i].resize(W);dis[i].resize(W,inf);
	}
	rep(i,H)rep(j,W)cin>>c[i][j];
	queue<P>que;
	que.push({sx,sy});
	dis[sx][sy]=0;
	while(!que.empty()){
		P q=que.front();que.pop();
		rep(i,4){
			REP(j,K+1){
				int nx=q.first+dx[i]*j;
				int ny=q.second+dy[i]*j;
				if(nx<0||ny<0||nx>=H||ny>=W)break;
				if(c[nx][ny]=='@')break;
				int ne=dis[q.first][q.second]+1;
				if(dis[nx][ny]<ne)break;
				if(dis[nx][ny]>ne){
					dis[nx][ny]=ne;
					que.push({nx,ny});
				}
			}
		}
	}
	/*rep(i,H){
		rep(j,W)cout<<dis[i][j]<<" ";
		cout<<endl;
	}*/
	if(dis[gx][gy]==inf)cout<<-1<<endl;
	else cout<<dis[gx][gy]<<endl;
}


Measured memory_bytes: 60888
#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i=x;i<y;i++)
using namespace std;
int main(){
  string s;
  cin >> s;
  int A=1e9,Z=0;
  FOR(i,0,s.size()){
    if(s[i]=='A')A=min(A,i);
    if(s[i]=='Z')Z=max(Z,i);
  }
  cout << Z-A+1 << endl;
}


Measured memory_bytes: 640
require 'prime'

pri = Array.new(100000,0)
0.upto(100000) do |i|
  if Prime.prime?(i)
    pri[i]+=1
  end
end

rui = Array.new
rui[0]=0
1.upto(100000) do |i|
  if pri[i]==1 && pri[(i+1)/2]==1
    rui[i]=rui[i-1]+1
  else
    rui[i]=rui[i-1]
  end
end

q=gets.to_i
q.times do
  l,r = gets.split.map(&:to_i)
  puts rui[r]-rui[l-1]
end

Measured memory_bytes: 4424
fn solve() {
    let (n, d): (usize, i64) = (read::<usize>(), read::<i64>());
    let mut res = 0;
    for _ in 0..n {
        let (x, y): (i64, i64) = (read::<i64>(), read::<i64>());
        if d * d >= x * x + y * y {
            res += 1;
        }
    }
    println!("{}", res);
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 2264
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()

    for i, value in enumerate([105, 135, 165, 189, 195, 201]):
        if N < value: 
            print(i)
            sys.exit()


if __name__ == '__main__':
    main()

Measured memory_bytes: 38448
#include <bits/stdc++.h>
#define rei register int
#define int long long
using namespace std;
const int maxn = 100010;
int n,m,x;
int f[maxn][40],s[maxn][40];
signed main(){
	cin >> n >> x >> m;
	for(rei i = 0;i <= m - 1;++i)
	f[i][0] = 1ll*i * i % m,s[i][0] = f[i][0];
	for(rei j = 1;j <= 39;++j)
	 for(rei i = 1;i <= m - 1;++i)
	f[i][j] = f[f[i][j - 1]][j - 1],s[i][j] = s[f[i][j - 1]][j - 1] + s[i][j - 1];
	int ans(0),now(x); --n;
	for(rei i = 39;i >= 0;--i) if(((long long)1 << (long long)i) <= n){
		n -= ((long long)1 << (long long)i);
		ans += s[now][i],now = f[now][i];
	} ans += x; cout << ans << endl; return 0;
}

Measured memory_bytes: 66096
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.nextInt();
        var syusseki_no = new List<KeyValuePair<int, int>>();
        for (int i = 0; i < n; i++)
        {
            syusseki_no.Add(new KeyValuePair<int, int>(i + 1, sc.nextInt()));
        }
        syusseki_no.Sort(Comparison);

        for (int i = 0; i < n; i++)
        {
            Console.Write(syusseki_no[i].Key);
            if (i == n - 1) Console.Write("\n");
            else Console.Write(" ");
        }
    }

    static int Comparison(KeyValuePair<int, int> a, KeyValuePair<int, int> b)
    {
        return a.Value - b.Value;
    }
}

// chokudai's Scanner
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;
    }
}


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

int main(){
	int s,g,h,m,t,price;
	bool flag;
	int table[7][7]={
	{0 ,300,500,600,700,1350,1650},
	{6 ,0  ,350,450,600,1150,1500},
	{13,7  ,0  ,250,400,1000,1350},
	{18,12 ,5  ,0  ,250,850 ,1300},
	{23,17 ,10 ,5  ,0  ,600 ,1150},
	{43,37 ,30 ,25 ,20 ,0   ,500 },
	{58,52 ,45 ,40 ,35 ,15  ,0   }
	};
	
	while(cin >> s && s){
		flag = false;
		cin >> h >> m ;
		t = h*60 + m;
		if(t >= 17*60+30 && t <= 19*60+30){
			flag = true;
		}
		
		cin >> g;
		
		cin >> h >> m ;
		t = h*60 + m;
		if(t >= 17*60+30 && t <= 19*60+30){
			flag = true;
		}
		s--;g--;
		if(g>s)swap(s,g);
		
		price = table[g][s];
		
		if(flag && table[s][g]<= 40){
			price /=2;
			if(price%50){
				price = price - price%50 + 50;
			}
		}
		cout << price << endl;
	}
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int count=n-2,cur=n-2;
    long long sum=a[n-1]+0ll;
    while(count>2){
        sum+=2ll*a[cur];
        --cur;
        count-=2;
    }
    sum+=count*a[cur];
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 4388
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<set>

using namespace std;

int main(void){

    int n;
    string str;
    cin >> n >> str;
    int ans = 0;

    for(int i = 1;str[i] != '\0';i++){
        string str1, str2;
        vector<int> s1(26,0), s2(26,0);
        int total = 0;
        str1 = str.substr(0, i);
        str2 = str.substr(i, str.length());

        // cout << "str1:" << str1 << " str2:" << str2 << endl;

        for(int j = 0;str1[j] != '\0';j++){
            if(s1[str1[j]-'a'] == 0) s1[str1[j]-'a'] = 1;
        }

        for(int j = 0;str2[j] != '\0';j++){
            if(s2[str2[j]-'a'] == 0) s2[str2[j]-'a'] = 1;
        }

        for(int j = 0;j < 26;j++){
            if(s1[j] & s2[j] == 1) total++;
        }

        ans = max(ans, total);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main(){
	int a, b;
	string s;
	cin >> a >> s >> b;
	if (s == "+") {
		cout << a + b << endl;
	}
	else {
		cout << a - b << endl;
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool a = 0,b = 0,c = 0,d = 0;
    rep(i,len(s)){
        if(s[i] == 'N'){
            a++;
        }else if(s[i] == 'E'){
            b++;
        }else if(s[i] == 'W'){
            c++;
        }else{
            d++;
        }
    }
    if((a > 0 && d == 0) || (a == 0 && d > 0)){
        cout << "No\n";
    }else{
        a = b,d = c;
        if((a > 0 && d == 0) || (a == 0 && d > 0)){
            cout << "No\n";
        }else{
            cout << "Yes\n";
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

template <typename T>
class CumSum1D
{
public:
    CumSum1D(){};
    ~CumSum1D(){};
    void init(vector<T>& arr) {
        m_cum = arr;
        m_N = arr.size();
        FOR(i, 1, m_N) m_cum[i] += m_cum[i - 1];
    }
    // get sum of [l, r]. 0-based.
    T getSum(int l, int r) {
        T ret = m_cum[r];
        if (l != 0) ret -= m_cum[l - 1];
        return ret;
    }
    size_t m_N;
    vector<T> m_cum;
};

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;
    string S;
    cin >> S;

    vector<int> w(N);
    vector<int> b(N);
    REP(n, N) {
        if (S[n] == '#') b[n] = 1;
        else w[n] = 1;
    }

    CumSum1D<int> W; W.init(w);
    CumSum1D<int> B; B.init(b);

    // for(auto e: W.m_cum) cout << e; cout << endl;
    // for(auto e: B.m_cum) cout << e; cout << endl;

    int ans = N * 2;
    REP(white_num, N + 1) {
        int t = 0;
        if (white_num != 0) t += (white_num - W.getSum(0, white_num - 1));
        int black_num = N - white_num;
        if (black_num != 0) t += (black_num - B.getSum(white_num, N - 1));
        // cout << "white_num, t = " << white_num << "," << t << endl;
        ans = min(ans, t);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  char x[100];
  scanf("%s",x);
  int x0 = x[0]-'0';
  int x1 = x[1]-'0';
  int x2 = x[2]-'0';
  int x3 = x[3]-'0';
  int x4 = x[5]-'0';
  int x5 = x[6]-'0';
  int x6 = x[8]-'0';
  int x7 = x[9]-'0';

  int y = 1000*x0+100*x1+10*x2+x3;
  int m = 10*x4+x5;
  int d = 10*x6+x7;
  int ans = 0;
  if(y<=2018) {
    ans = 0;
  } else {
    if(y>=2020) {
      ans = 1;
    } else {
      if(m<=3) {
        ans = 0;
      } else {
        if(m>=5) {
          ans = 1;
        } else {
          ans = 0;
        }
      }
    }
  }

  if(ans == 0) {
    printf("Heisei\n");
  } else {
    printf("TBD\n");
  }

  return 0;
}


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

using namespace std;

int main() {
    
    string s;
    cin >> s;
    set<char> st;
    for (int i = 0; i < s.size(); ++i)
        st.insert(s[i]);

    if(st.size() == 2) cout << "Yes\n";
    else cout << "No\n";
   return 0;
}


Measured memory_bytes: 256
x,n=list(map(int,input().split()))
if n==0:
  print(x)
  exit()
  
p=sorted(list(map(int,input().split())))

if not x in p:
  print(x)
  exit()

s=p.index(x)
for i in range(1,n+1):
  if p[s-i]!=x-i:
    print(x-i)
    exit()
  elif s+i>n-1:
    print(p[-1]+1)
    exit()
  elif s+i<=n-1:
    if p[s+i]!=x+i:
      print(x+i)
      exit()


Measured memory_bytes: 9208