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

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n; cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	if (n % 3) {
		for (int i = 0; i < n; ++i) {
			if (a[i] != 0) {
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}
	else {
		map<ll, int> m;
		for (auto ai : a)
			m[ai] = 0;
		for (auto ai : a)
			++m[ai];
		if (m.size() > 3) {
			cout << "No" << endl;
		}
		else if (m.size() == 1) {
			if (a[0] == 0)
				cout << "Yes" << endl;
			else
				cout << "No" << endl;
		}
		else if (m.size() == 2) {
			for (auto& mi : m) {
				if (mi.second != (n / 3) && mi.second != (2 * n / 3)) {
					cout << "No" << endl;
					return 0;
				}
				if (mi.second == (n / 3) && mi.first != 0LL) {
					cout << "No" << endl;
					return 0;
				}
			}
			cout << "Yes" << endl;
		}
		else {
			ll tmp = 0LL;
			for (auto& mi : m) {
				tmp ^= mi.first;
				if (mi.second != (n / 3)) {
					cout << "No" << endl;
					return 0;
				}
			}
			if (tmp == 0LL)
				cout << "Yes" << endl;
			else
				cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 5632
var lines = [];
var match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6];

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {

    var N = Number(lines[0].split(" ")[0]);
    var M = Number(lines[0].split(" ")[1]);

    var A = lines[1].split(" ").map(value => Number(value));

    // 文字数
    // dpに入るモノは最大の文字列
    var dp = Array(N + 1).fill("");

    // dp配列初期化
    for (var i = 0; i < M; i++) {
        // 本数match[A[i]]使える時，A[i]は作れる
        if (dp[match[A[i]]] === "" || dp[match[A[i]]] < A[i].toString()) { dp[match[A[i]]] = A[i].toString(); }
    }

    for (var i = 1; i <= N; i++) {
        for (var j = 0; j < M; j++) {

            // 数字を作るためにマッチをi本よりも多く使うなら，その数字は作れない
            if (i - match[A[j]] < 0) { continue; }

            if (dp[i - match[A[j]]] === "") { continue; }

            else {
                // A[j]を追加したxを作成
                var x = dp[i - match[A[j]]] + A[j];
                // 現在最大値のdp[i]とxを比較して，xの方が大きければdp[i]=xとする
                if (dp[i].length < x.length || (dp[i].length === x.length && dp[i] < x)) { dp[i] = x; }
            }
        }
    }

    console.log(dp[N]);
});


Measured memory_bytes: 48460
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        a: [usize; n],
    }
    let s = a.iter().sum();
    let c = a.into_iter().filter(|ai| ai * 4 * m >= s).count();
    println!("{}", if c >= m { "Yes" } else { "No" });
}


Measured memory_bytes: 2128
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &in, vector<T> &vec) {
    for (auto &e : vec) in >> e;
    return in;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int N;
    read(N);
    vector<int> x(N), y(N), idx(N);
    rep(i, N) {
        read(x[i], y[i]);
        idx[i] = i;
    }

    long double sum = 0;
    i64 cnt = 0;
    do {
        rep(i, N - 1) {
            sum += hypot(x[idx[i+1]] - x[idx[i]], y[idx[i+1]] - y[idx[i]]);
        }
        ++cnt;
    } while (next_permutation(all(idx)));
    cout << fixed << setprecision(12);
    print(sum / cnt);

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		int c = parseInt(sc.next());
		int x = parseInt(sc.next());
		int y = parseInt(sc.next());
		sc.close();
		int mn=(x+y)*Math.max(a, Math.max(b, c));
		int mx=Math.max(x, y);
		int tmp=0; 
		for (i = 0; i <= mx; i++) {
			int tmpx=x-i; 
			int tmpy=y-i;
			tmpx=tmpx<0?0:tmpx;
			tmpy=tmpy<0?0:tmpy;
			tmp=tmpx*a+tmpy*b+i*c*2;
//			out.printf("%d:%d%n", i, tmp);
			if(tmp<mn)mn=tmp;
		}
		out.println(mn);
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


int main() {
  
  long long S;
  cin >> S;

  int e = 1000000000;
  int c = (e - S % e) % e;
  int d = (S + c) / e;

  cout << 0 << " " << 0 << " " << 1000000000 << " " << 1 << " " << c << " " << d << endl;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())
#print(N,S)

# reader position 0
leftSide = 0
rigthSide = S[1:].count("E")

#print(rigthSide)

minChange = rigthSide
crntCnt = rigthSide
for i in range(1, len(S)):
  if S[i-1] == "W":
    crntCnt += 1
  if S[i] == "E":
    crntCnt -= 1
  if crntCnt < minChange:
    minChange = crntCnt
print(minChange)

Measured memory_bytes: 8012
import java.util.Map;
import java.util.Scanner;

public class Main {

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        Scanner sc = new Scanner(System.in);

        int n = nextInt(sc);
        int[] a = nextInts(sc, n);
        boolean[] isEven = new boolean[n];

        for (int i = 0; i < n; i++) {
            isEven[i] = (a[i] % 2 == 0);

            if (!isEven[i]) {
                out(0);

                return;
            }
        }

        int count = 1;

        while (true) {
            for(int i = 0; i < n ; i++) {
                a[i] = a[i] / 2;

                if (a[i] % 2 == 1) {
                    out(count);

                    return;
                }
            }

            count++;
        }
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt(Scanner sc) {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString(Scanner sc) {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(Scanner sc, int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt(sc);
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }

    public static void putCountMap(Map<Integer, Integer> map, int value) {
        if (map.containsKey(value)) {
            map.put(value, map.get(value) + 1);
        } else {
            map.put(value, 1);
        }
    }
}


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


int func(int N){// 例: 11221213312, 12,  432,  8
  if (N < 10) return N;
  return func(N/10) + N % 10;
}

int main()
{
  int n; 
  cin >> n;
  int s = func(n);
  if (n % s == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;

}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9+7;
const int maxn = 250005;

void go() {
   	int n, w;
   	cin >> n >> w;
   	int dp[100005];
   	memset(dp, 0x3f, sizeof(dp));
   	dp[0] = 0;
   	f(n) {
   		int x, y;
   		cin >> x >> y;
   		for (int j = 100000 ; j >= y ; j--) {
   			dp[j] = min(dp[j] , dp[j - y] + x);
   		}
   	}
   	for (int i = 100000 ; i >= 0 ; i--) {
   		if (dp[i] <= w) {
   			cout << i << '\n';
   			return;
   		}
   	}
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
    
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define int  long long int
#define mod 1000000000000007
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(i) i.begin(),i.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define set_bit __builtin_popcount //gives number of set_bits
#define ff first
#define ss second
#define cases(t) int t;cin>>t; rep(casn,1,t+1)
#define el cout<<"\n";
#define deci(n) int n; scanf("%lld",&n);
#define decs(n) string n; cin>>n;
#define sz(v) v.size()
#define repit(m) for(auto it=m.begin();it!=m.end();it++)
// #define find(m,i) (m.find(i)!=m.end())
// #define find(m,i) (m.find(i)==m.end())
#define cYES cout<<"YES\n";
#define cNO cout<<"NO\n";
#define ins insert
#define imax 1000000000000000000
#define imin -1000000000000000000
// #define NP 50000
//  cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
 
//  IIITA
//SUNEET KUMAR -->  ਸੁਨੀਤ
 
// scanning numbers extremely fast/////////
void fs(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
// ========================================
int power(int a,int x)
{
        a%=mod;
    int res=1;
    while(x>0)
    {
        if(x&1)
        res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}
int max(int a,int b)
{
    if(a>b)
    {
        return a;
    }
    else
    {
        return b;
    }
}
int min(int a,int b)
{
    if(a>b)
    {
        return b;
    }
    else
    {
        return a;
    }
}
int madd(int a,int b)
{
    int ans;
    ans=(a%mod+b%mod)%mod;
    return ans;
}
int mmult(int a,int b)
{
    int ans=1;
    ans=((a%mod)*(b%mod))%mod;
    return ans%mod;
}
int modinverse(int a)
{
    return power(a,mod-2);
}
 
void nhi_degi()
{
    double r;cin>>r;
    cout<<2*r*(3.14);el
}
signed main()
{
    // cases(t)
    // {
        nhi_degi();
    // }
}

Measured memory_bytes: 3812
fun calc143C(s: String): Int = s.fold((0 to  '0')) { acc, c ->
    when (c) {
        acc.second -> acc.first to c
        else -> acc.first + 1 to c
    }
}.first

fun main(args: Array<String>) {
    val N = readLine()!!
    val s = readLine()!!
    println(calc143C(s))
}


Measured memory_bytes: 37308
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  int a[100002]={};
  // int b[100000]={};
  int flag=0;
  ll ans=1;
  REP(i,n){
    cin>>a[i];
    // b[i]=1;
  }
  sort(a,a+n);
  reverse(a,a+n);
  for(int i=0;i<=n-2;i++){
    if(a[i]==a[i+1]){
      flag++;
      if(flag<=2)ans*=a[i];
      if(i!=n-2)i++;
      if(flag==2)break;
    }
    if(i==n-2 && a[i]!=a[i-2])ans=0;
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<limits>
#include<algorithm>
#include<numeric>
#include<utility>

using ull = unsigned long long int;
using ll = long long int; 

using namespace std;

int main(){
    ll n;
    ll tmp=-1;

    cin >> n;

    for(int i=9;i>=1;i--){
        if(n%i==0){
            tmp=n/i;
            break;
        }
    }
    if(tmp==-1||tmp>9) cout << "No" << endl;
    else cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	h := iScan()
	_ = iScan()
	for i := 0; i < h; i++ {
		x := Scan()
		fmt.Println(x)
		fmt.Println(x)
	}
}


Measured memory_bytes: 1780
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, w, n) for(int i = w; i < n; i++)
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))

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;}
const long long INF = 1LL << 60;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(15);
    
    int a, b; cin >> a >> b;

    cout << a / b << ' ' << a % b << ' ' << a / (double)b << endl;

    return 0;
}



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

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

    vector<int> A(N);
    for (int i=0;i<N;i++) {
        cin >> A.at(i);
    }

    set<int> set_A;
    for(int i=0;i<N;i++) {
        set_A.insert(A.at(i));
    }

    cout << set_A.size() << endl;
    return 0;
}

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

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

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

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


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

int N, M;

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

  cin >> N >> M;
  VI xs(N);
  REP(i,N){
	cin >> xs[i];
	--xs[i];
  }

  VL del(M+10);
  LL sum = 0;
  REP(i,N-1){
	LL d;
	if(xs[i] < xs[i+1]){
	  d = xs[i+1] - xs[i];
	  sum += min(d, 1LL + xs[i+1]);
	}
	else{
	  d = M - xs[i] + xs[i+1];
	  sum += min(d, 1LL + xs[i+1]);
	}

	int l = xs[i+1] - d + 1;
	if(0 <= l){
	  del[l]--;
	  del[xs[i+1]]++;
	  del[xs[i+1]] += d-1;
	  del[xs[i+1]+1] -= d-1;
	}
	else{
	  l = xs[i+1] + 1;
	  del[0]--;
	  del[xs[i+1]]++;
	  del[xs[i+1]] += d-1;
	  del[xs[i+1]+1] -= d-1;
	  del[M-d+l]--;
	}
  }

  REP(i,M) del[i+1] += del[i];

  LL ans = sum;
  REP(i,M){
	mini(ans, sum);
	sum += del[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	s := make([]int, n)

	for i := range s {
		s[i] = nextInt()
	}
	sort.Ints(s)

	ceiling := n / 2
	floor := n/2 - 1
	diff := s[ceiling] - s[floor]

	_, _ = fmt.Fprintf(writer, "%d", diff)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
#define MOD (1000000000+7)
 
int main()
{
	int N, K;
 
	cin >> N >> K;

	vector<int> num;
	for( int i = 1; i * i <= N; i++ ) {
		num.push_back( i );
		if( N / i != i ) {
			num.push_back( N / i );
		}
	}
	sort( num.begin(), num.end() );
	int it = num.size();
	for( int i = it - 1; i > 0; i-- ) {
		num[i] = num[i] - num[i - 1];
	}
	vector<vector<long long>> dp( K + 1, vector<long long>( it ) );
	vector<long long> sdp( it + 1 );
	dp[0][0] = 1;
	for( int i = 0; i < K; i++ ) {
		fill( sdp.begin(), sdp.end(), 0 );
		for( int j = 0; j < it; j++ ) {
			sdp[j + 1] = sdp[j] + dp[i][j];
			sdp[j + 1] %= MOD;
		}
		for( int j = 0; j < it; j++ ) {
			dp[i + 1][j] = sdp[it - j] * num[j] % MOD;
		}
	}
	long long ans = 0;
	for( int i = 0; i < it; i++ ) {
		ans += dp[K][i];
		ans %= MOD;
	}

	cout << ans << endl;
}


Measured memory_bytes: 51196
#include <iostream>
using namespace std;
int main()
{
  int n,m,c,s,i,j;
  while(cin >> m >> n){
    s = 0;
    while(m--){
      c = 0;
      for(i=0;i<n;i++){
	cin >> j;
	if(j==1)c++;
      }
      if(s<c) s = c;
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#define N 2000000
int a[N],b[N],c[N];
int main(){
  int i,j,k=0,n;
   
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    c[a[i]]++;
     
    if(k<a[i])k=a[i];
  }
  for(i=1;i<=k;i++){
    c[i]+=c[i-1];
  }
 
  for(i=0;i<n;i++){
    b[c[a[i]]-1]=a[i];
    c[a[i]]--;
  }
  for(i=0;i<n;i++){
    if(i!=n-1)
      printf("%d ",b[i]);
    else printf("%d\n",b[i]);
     
  }
   
   
  return 0;
}

Measured memory_bytes: 17892
#include<cstdio>
int main()
{
  int n,a,b,c,o,p,q,i,x;
  scanf("%d",&n);
  if(n%3!=0)
  {
    for(i=0;i<n;i++)if(scanf("%d",&x),x!=0)return puts("No"),0;
    puts("Yes");return 0;
  }
  a=b=c=-1,o=p=q=0;
  for(i=0;i<n;i++)
  {
    scanf("%d",&x);
    if(a==-1)a=x,o=1;
    else if(a==x)o++;
    else if(b==-1)b=x,p=1;
    else if(b==x)p++;
    else if(c==-1)c=x,q=1;
    else if(c==x)q++;
    else return puts("No"),0;
  }
  puts(o==p&&p==q&&(a^b)==c||c==-1&&(p==o*2&&a==0||o==p*2&&b==0)||b==-1&&a==0?"Yes":"No");
}

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

int main()
{
  int K, S;
  cin >> K >> S;

  int n = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int s = S - x - y;
      if (0 <= s && s <= K) n++;
    }
  }

  cout << n << endl;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
x = I()
ans = 2*(x//11)+1
x %= 11
if x == 0:
    ans -= 1
if x > 6:
    ans += 1
print(ans)
"""

#D
n = I()
a = LI()
d = defaultdict(int)
for i in a:
    d[i] += 1
l = list(d.keys())
k = 0
for i in l:
    k ^= ~(d[i]%2)
    d[i] = 1
ans = sum(list(d.values()))
ans -= 1 if k%2 else 0
print(ans)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 18848
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int H, W, D;
  cin>>H>>W>>D;
  map<int, pair<int, int> > amap;
  int A;
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      cin>>A;
      amap[A] = mp(i, j);
    }
  }
  vector<vector<int> >arr(D+1);
  int j;
  for(int i=1;i<=D;++i) {
    arr[i].push_back(0);
    j = 1;
    while(i+j*D<=H*W) {
      arr[i].push_back(arr[i][j-1]+abs(amap[i+j*D].fi-amap[i+(j-1)*D].fi)+abs(amap[i+j*D].se-amap[i+(j-1)*D].se));
      j++;
    }
  }
  int Q;
  cin>>Q;
  int L, R;
  int index;
  for(int i=0;i<Q;++i) {
    cin>>L>>R;
    index = L%D;
    if(index==0) index = D;
    cout<<arr[index][(R-index)/D] - arr[index][(L-index)/D]<<endl;
  }
}


Measured memory_bytes: 13752
# 最小金額を求める
# 一番高い商品に割引を適用して半額（小数点以下切り捨て）にする作業の繰り返し
# 問題詳細：https://atcoder.jp/contests/abc141/tasks/abc141_d
# 優先度付きキューを利用する
import heapq

def main():
  n, m = map(int, input().split())
  a = list(map(int, input().split()))
  pq = to_priorityqueue(a)
  pq = use_ticket(pq, m)
  print(-sum(pq))


# 優先度付きキューを作成
# heapqモジュールを利用
# pythonのheapqの場合、pop(取り出し)を行った際に最小のものから取り出される
# 今回は大きい順に取り出して利用したいため、-1を掛けてpushする（最大の値が最小になる）
def to_priorityqueue(list):
  rtn = []
  for el in list:
    heapq.heappush(rtn, -el)
  return rtn

# チケットの利用（割引の適用）
# チケットがなくなるまで、その時点で最も価格が高い商品にわりびきを適用する
# 最大まで割引を適用した結果できたキューを返す
def use_ticket(pq, t_num):
  while t_num and pq:
    el = -(heapq.heappop(pq))
    el //= 2
    heapq.heappush(pq, -el)
    t_num -= 1
  return pq

if __name__ == "__main__":
  main()

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

using namespace std;






int main() {

	
	int nsize;
	int ksize;
	int a[100000];


	while (true) {
		cin >> nsize >> ksize;
		if (nsize == 0 && ksize == 0)break;
		for (int i = 0; i < nsize; i++) {
			cin >> a[i];
		}
		int maxval;
		int val = 0;
		for (int i = 0; i < ksize; i++) {
			val += a[i];
		}
		maxval = val;

		for (int i = ksize; i < nsize; i++) {
			val -= a[i - ksize];
			val += a[i];
			if (maxval < val) {
				maxval = val;
			}
		}
		cout << maxval << endl;
	}
	






	
	
	//system("pause");
	return 0;
}


Measured memory_bytes: 3376
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;

void main()
{
	auto n = readln.chomp.to!int;

	foreach (_; 0..n) {
		bool[int] f;
		auto x = readln.chomp.to!int;
		int cnt;
		while (x > 9) {
			if (f.get(x, 0)) {
				cnt = -1;
				break;
			}
			f[x] = 1;
			int next;
			auto str = x.to!string;
			foreach (i; 1..str.length) {
				foreach (j; i..str.length) {
					next = max(next, str[0..i].to!int * str[i..$].to!int);
				}
			}
			x = next;
			cnt++;
		}
		cnt.writeln;
	}
}

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

int main() {
	// your code goes here
	long long n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){
	    cin>>a[i];
	}
	sort(a,a+n);
    long long sum=0;
    for(int i=0;i<k;i++){
        sum+=a[i];
    }
    cout<<sum<<endl;    
        
	return 0;
}


Measured memory_bytes: 3624
<?php

list($n, $m, $k) = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));
$b = explode(' ', trim(fgets(STDIN)));

$t = 0;
for ($i=0; $i < $m; $i++) {
  $t += $b[$i];
}

$j = $m;
$ans = 0;
for ($i=0; $i < $n+1; $i++) {
  while ($j > 0 && $t > $k) {
    $j--;
    $t -= $b[$j];
  }

  if ($t > $k) {
    break;
  }

  $ans = max($ans, $i + $j);

  if ($i == $n) {
    break;
  }

  $t += $a[$i];
}

echo $ans;


Measured memory_bytes: 46184
def g;gets.split.map &:to_i;end
while(x,y,z=g;x>0)
v=g
e=[]
r=(0..y).map{Hash.new{0}}
r[s=0][0]=1.0
z.times{n,*a=g;e[n]=a}
y.times{|i|o=d=0
t,u=e[i]
t&&(t<2?(o=u):(d=t<3?u:-u))
r[i].map{|k,w|k+=d;v.map{|j|r[[y,i+j+o].min][k<0?0:k]+=w/x}}}
r[y].map{|k,w|s+=k*w}
p s.to_i
end

Measured memory_bytes: 7784
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		var A = GetLongs(N);
		var dp = new long[N + 1, N + 1];
		dp[0, N] = 1000;
		for(long i = 0; i < N; i++)
		{
			dp[i + 1, i] = dp[i, N];
			dp[i + 1, N] = dp[i, N];
			for(long j = 0; j < i; j++)
			{
				dp[i + 1, j] = dp[i, j];

				long q = dp[i, j] / A[j];
				chmax(ref dp[i + 1, N], dp[i, j] + q * (A[i] - A[j]));
			}
		}
		WriteLine(dp[N, N]);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 28444
n = int(input())
str_list = [input() for _ in range(n)]


a=0
b=0
c=0                
d=0                
                
for i in range(n):
    if str_list[i] == 'AC':
    	a += 1
    elif str_list[i] == 'WA':
    	b += 1
    elif str_list[i] == 'TLE':
    	c +=1
    else :
    	d +=1

print('AC x '+ str(a))
print('WA x '+ str(b))
print('TLE x '+ str(c))
print('RE x '+ str(d))




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

int main() {

	string s;	//文字列
	long long k;	//繰り返す回数

	cin >> s >> k;

	//string t="";

	//for (int i = 0; i < s; i++) {
	//	t += n;
	//}
	int array[100] = {0};
	int j = 0;

	// 文字列がどれだけ連続しているか計s難して、arrayに入れる
	char c = s[0]; //現在の文字
	int count = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == c) {
			count++;
		}
		else {
			//cout << t[i] << "=" << count << endl;
			array[j] = count;
			count = 1;
			c = s[i];
			j++;
		}
	}
	array[j] = count;
	j++;
	//cout << "j =" << j << endl;
	//for (int i = 0; i < j; i++)cout << array[i] << endl;
	//cout << "-----------" << endl;

	long long sum = 0;
	int array2[100] = { 0 };
	int j2;
	/*j <= 1 ? j2 = 1 : */ j2 = j - 1;

	if (s.size() != 1) { //文字列が2つ以上の場合
		if (s[0] != s[s.size() - 1]) { //最初と最後の文字が異なる場合

			for (int i = 0; i < j; i++) {
				sum += array[i] / 2;
			}
			sum = sum * k;
		}
		else { //最初と最後の文字が同じ場合

			for (int i = 0; i < j2; i++) {
				array2[i] = array[i + 1];
			}
			

			if (j >= 1 && j2 >=1)array2[j2-1] = array[0] + array[j-1];
			//cout << "-----------" << endl;
			//cout << "j2 =" << j2 << endl;
			//for (int i = 0; i < j2; i++)cout << array2[i] << endl;
			//cout << "-----------" << endl;
			//for (int i = 0; i < j; i++) cout << array[i] << endl;
			if (j2 >= 1) {
				for (int i = 0; i < j2; i++) {
					int tmp = array2[i] / 2;
					if (tmp >= 1)sum += tmp;
				}

				sum = sum * (k - 1);

				for (int i = 0; i < j; i++) {
					int tmp = array[i] / 2;
					if (tmp >= 1)sum += tmp;
				}
			}
			else if(j2 == 0){
				sum = s.size() * k / 2;
			}
		}
	}
	else {
		sum = k / 2;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
d = readl()

s = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        s += d[i] * d[j]
print(s)

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

string S;

int main() {
    cin >> S;

    int lmax = 0;
    for (int i = 0; i < S.length(); ++i) {

        int l = 0;
        for (int j = i; j < S.length(); ++j) {
            if (S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T') {
                ++l;
            } else {
                break;
            }
        }
        lmax = max(lmax, l);
    }

    cout << lmax << endl;
    return 0;
}

Measured memory_bytes: 888
from collections import defaultdict

N, M = map(int, input().split())
friend = defaultdict(set)
leader = []
for i in range(M):
    Ai, Bi = map(int, input().split())
    friend[Ai].add(Bi)
    friend[Bi].add(Ai)
already = {}
answer = 0
for i in range(1, N + 1):
    if i in already:
        continue
    if i not in friend:
        continue

    queue = []
    for f in friend[i]:
        already[f] = True
        queue.append(f)
    already[i] = True
    size = 0
    while len(queue) > size:
        item = queue[size]
        size += 1
        if item in friend:
            for f in friend[item]:
                if f not in already:
                    already[f] = True
                    queue.append(f)
    if size > answer:
        answer = size
print(answer + 1)

Measured memory_bytes: 100492
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);CIN(X);
    I vec;
    REP(a,N){
        CIN(b);
        vec.pb(b);
    }
    X -= accumulate(ALL(vec),0);
    int m = *min_element(ALL(vec));
    COUT(X/m+N);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<set>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

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

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
static const int N=114514;

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=1e9+7;
#define ll long long

int main(){
  cin.tie(0); ios::sync_with_stdio(false);
  ll n,k;
  cin>>n>>k;
  vector<int>a(n);
  rep(i,n){
    cin>>a[i];
  }
  ll cnt1=0;
  ll cnt2=0;
  rep(i,n-1){
    for(int j=i+1;j<n;j++){
      if(a[i]>a[j])cnt1++;
      if(a[i]<a[j])cnt2++;
    }
  }
  ll ans=0,num1=0,num2=0;
  num1=k*(k+1)/2%mod;
  num1*=cnt1;
  num1%=mod;
  if(k>=2){
  num2=(k-1)*(k)/2%mod;
  }
  num2*=cnt2;
  num2%=mod;
  ans=(num1+num2)%mod;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch)
{
	if (ch == 'A')
		return 1;
	else if (ch == 'C')
		return 2;
	else if (ch == 'G')
		return 3;
	else if (ch == 'T')
		return 4;
	else
		return 0;
}

long long getKey(char str[])
{
	long long sum = 0, p = 1;
	for (int i = 0; i < strlen(str); i++)
	{
		sum += p * (getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key)
{
	return key % M;
}

int h2(int key)
{
	return 1 + (key % (M - 1));
}

int find(char str[])
{
	long long key, h;
	key = getKey(str);
	for (int i = 0; ; i++)
	{
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0)
			return 1;
		else if (strlen(H[h]) == 0)
			return 0;
	}
	return 0;
}

int insert(char str[])
{
	long long key, i, h;
	key = getKey(str);
	for (i = 0; ; i++)
	{
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0)
			return 1;
		else if (strlen(H[h]) == 0)
		{
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int main()
{
	int n, h;
	char str[L], com[9];
	for (int i = 0; i < M; i++)
		H[i][0] = '\0';
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%s %s", com, str);

		if (com[0] == 'i')
		{
			insert(str);
		}
		else
		{
			if (find(str))
			{
				printf("yes\n");
			}
			else
			{
				printf("no\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 16956
#include <bits/stdc++.h>
using  namespace std ;
#define fi first
#define se second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define ALL(x) (x).begin(),(x).end() 
#define UNQ(x) (x).erase( unique(ALL(x)) , (x).end() ) 
#define lwb( x , y ) lower_bound(ALL(x) , (y) ) - (x).begin() 
#define upb( x , y ) upper_bound(ALL(x) , (y) ) - (x).begin() 
#define sz(x) (int)(x).size() 
#define pb push_back
typedef long long ll ;


int n , m , arr[200010] ;
ii st[800010] ;

struct ev{
	int val , x , y , ok ;
	bool operator<(const ev &a) const{
		if(a.ok != ok) return a.ok < ok ;
		return arr[a.val] < arr[val] ;
	}
} ;

priority_queue<ev> djk ; 
 
void build(int node , int f , int l){
	if(f == l){
		if(f&1) st[node] = { n + 1 , f } ;
		else st[node] = { l , n + 1 } ;
		return  ;
	}
	build(2*node , f , (f+l)/2) ;
	build(2*node +1 , (f+l)/2 + 1 , l );
	if(arr[st[2*node + 1].fi] < arr[st[2*node].fi]) st[node].fi = st[2*node + 1].fi ;
	else st[node].fi = st[2*node].fi ;
	if(arr[st[2*node + 1].se] < arr[st[2*node].se] ) st[node].se = st[2*node + 1].se ;
	else st[node].se = st[2*node].se ; 
}
 
ii qr(int node,  int f , int l , int x , int y){
	if(f > y || l < x) return {n+1 , n+1} ;
	if(x<=f && l<=y) return st[node] ;
	ii r1 = qr(2*node , f , (f+l)/2 , x , y) , r2 = qr(2*node + 1 , (f+l)/2 + 1 , l , x, y)  , res ; 
 
	if(arr[r1.fi] < arr[r2.fi]) res.fi = r1.fi ;
	else res.fi = r2.fi ;
	if(arr[r1.se] < arr[r2.se]) res.se = r1.se ;
	else res.se = r2.se ;
	return res ; 
}
 
void find_ans(vii &srt){
	djk.push( {0 , 1 , n , 0} ) ;  
	int f , l , mrk , par ; 
	set<ev>::iterator it ; 
	ev tmp  ;
	while(!djk.empty()){
	
		tmp = djk.top();
		djk.pop() ;
		
		f = tmp.x ; 
		l = tmp.y ; 
		mrk = tmp.ok ; 
		par = tmp.val ; 
		if(f > l) continue ; 
		// printf("%d %d %d %d\n" , f , l , mrk , par) ;
		ii rs ; 
		rs = qr(1 , 1 , n , f , l ) ;
		int use , p ;
		if(mrk) {
			if(f&1) use =  rs.se ;
			else use = rs.fi ;
			srt.push_back( ii(arr[par] , arr[use]) ) ;
			// printf("%d %d\n" , arr[par] , arr[use] ) ;
			djk.push( { 0 , f , use - 1 , 0 } ) ;
			djk.push( { 0 , use + 1 , l , 0 } ) ;
		}
		else{
			if(f&1) use = rs.se ;
			else use = rs.fi ; 
			p = use ;
			djk.push( { 0 , f , use - 1 , 0 } ) ;
			djk.push( { p , use + 1 , l , 1 } ) ;
		}
	}
}

int main(){
	// freopen("in.txt" , "r" , stdin);
	// freopen("out.txt" , "w" , stdout) ;
	scanf("%d" , &n) ;
	arr[n + 1] = 1e9 ; 
	for( int i=1 ; i<=n ; i++ ){
		scanf("%d" , arr + i ) ;
	}
	build(1 , 1 , n) ;
	vii res ;
	res.clear() ;
	find_ans(res) ;
	for(ii v : res) printf("%d %d " , v.fi , v.se ) ; 
	return  0 ;
}


Measured memory_bytes: 11760
S = input()
Q = int(input())
hanten = 1
front = []
back = []
for _ in range(Q):
    q = list(map(str, input().split()))
    if q[0]=='1':
        hanten *= -1
    else:
        if hanten==1:
            if q[1]=='1':
                front.append(q[2])
            else:
                back.append(q[2])
        else:
            if q[1]=='1':
                back.append(q[2])
            else:
                front.append(q[2])


if hanten==1:
    print(''.join(list(reversed(front)) + list(S) + back))
else:
    print(''.join(list(reversed(list(S)+back))+front))

Measured memory_bytes: 9440
package main

import "fmt"

func main() {
	var o, e string
	fmt.Scan(&o, &e)
	b := make([]byte, 0, len(o)+len(e))
	for i := 0; i < len(o)-1; i++ {
		b = append(b, o[i])
		b = append(b, e[i])
	}
	if len(o) == len(e)+1 {
		b = append(b, o[len(o)-1])
	} else {
		b = append(b, o[len(o)-1])
		b = append(b, e[len(o)-1])
	}
	fmt.Println(string(b))
}


Measured memory_bytes: 512
from math import sqrt
n=int(input())
a=n
flag=False
for i in range(2,int(sqrt(n))+2):
    if n%i==0:
        b=(i-1)+(n//i-1)
        if a>b:
            a=b
            flag=True
if flag:
    print(a)
else:
    print(n-1)
        


Measured memory_bytes: 3060
S = input()
L = len(S)
for i in range((L-1)//2):
    if S[i] != S[L-1-i]:
        print("No")
        exit()

for i in range((L-1)//4):
    if S[i] != S[(L-1)//2-1-i]:
        print("No")
        exit()

for i in range(L-1, L - (L-1)//4, -1):
    if S[i] != S[i - (L-1)//2-1]:
        print("No")
        exit()

print("Yes")

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        double a=sc.nextDouble();
        double b=sc.nextDouble();
        double C=sc.nextDouble();
        double S=a*b/2*Math.sin(C*Math.PI/180);
        double d=Math.sqrt(a*a+b*b-2*a*b*Math.cos(C*Math.PI/180));
        double L=a+b+d;
        double h=S*2/a;
        System.out.println(S);
        System.out.println(L);
        System.out.println(h);
    }
}



Measured memory_bytes: 27852
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{

    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

//----------------------------------------------------------------

int main()
{
    ll n, k;
    cin >> n >> k;
    ll a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
    }
    if ((n - 1) % (k - 1) > 0)
    {
        cout << (n - 1) / (k - 1) + 1 << endl;
    }
    else
    {
        cout << (n - 1) / (k - 1) << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<stdio.h>
inline int read(void)
{
    int x=0;
    char c=getchar_unlocked();
    while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar_unlocked();}
    return x;
}
int main(void)
{
    long ans = read();
    long n = ans + 1;
    int u, v, i = 1;
    while(++i < n)
    {
        u = read();
        v = read();
        switch(u > v)
        {
            case 1: ans += i * (n - i) - v * (n - u); break;
            default: ans += i * (n - i) - u * (n - v);
        }
    }
    printf("%ld", ans);
    return 0;
}


Measured memory_bytes: 1604
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:

};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> A(n);
    long long sum = 0;
    long long res = 0;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
        res += sum * A[i];
        sum += A[i];
    }

    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
struct LS {
	ll num, cost;
	//値、遅延配列
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%p;
		x = x * x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n;
	int a[100];
	cin >> n;
	double b=0, c = inf;
	int k = 0;
	for (int i = 0;i < n; i++) {
		cin >> a[i];
		b += a[i];
	}
	b /= n;
	for (int i = 1; i < n; i++) {
		if (abs(a[k] - b) > abs(a[i] - b)) {
			k = i;
		}
	}
	cout << k << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include <queue>
#include <cmath>
#define read(X) scanf("%d",&X);
#define readLL(X) cin>>X;
#define readN(N,a) for(int i=0;i<N;i++)scanf("%lld",&a[i]);
#define LL long long
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define pii pair<int,int>
#define INF 3000000
using namespace std;

int main(){
	long long N,A,B;
	cin>>N>>A>>B;
	long long kecil = N*A - A + B;
	long long gede = N*B - B + A;
	cout<<max(0LL,gede-kecil+1LL)<<endl;
}

Measured memory_bytes: 256