akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int fun(int n)
{
      int sum=0;
      while(n>0)
      {
         sum++;
         n/=10;
      }
      return sum;
}
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     int n;
     cin>>n;
     int res=0;
     for(int i=1;i<=n;i++)
     {
          if(fun(i)&1)
            ++res;
     }
     cout<<res<<endl;
     return 0;
}

Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	nn := n % 10
	if nn == 3 {
		fmt.Fprintln(wr, "bon")
	} else if nn == 0 || nn == 1 || nn == 6 || nn == 8 {
		fmt.Fprintln(wr, "pon")
	} else {
		fmt.Fprintln(wr, "hon")
	}
}


Measured memory_bytes: 1760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	//79502884197169399375105820974944
  int r;
   cin>>r;
   long double pi=3.141592653;
long  double ans = 2*r*pi;
std::cout<<std::fixed;
std::cout<<std::setprecision(10);
cout<<ans;

  return 0;
}

Measured memory_bytes: 3764
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,{chars :$base :expr } ) =>{read_value !($iter ,String ) .chars () .map (|c |(c as u8 -$base as u8 ) as usize ) .collect ::<Vec <usize >>() } ;($iter :expr ,{char :$base :expr } ) =>{read_value !($iter ,{chars :$base } ) [0 ] } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,char ) =>{read_value !($iter ,chars ) [0 ] } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut $iter =s .split_whitespace () ;input_inner !{$iter ,$($r ) *} } ;($($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
pub fn prime_factors(n: usize) -> std::collections::HashMap<usize, usize> {
    let mut factors = std::collections::HashMap::new();
    let mut n = n;
    for i in 2..(n as f32).sqrt() as usize + 1 {
        while n % i == 0 {
            n /= i;
            *factors.entry(i).or_insert(0) += 1;
        }
    }
    if n > 1 {
        *factors.entry(n).or_insert(0) += 1;
    }
    factors
}
fn main() {
    input!(n);
    let mp = prime_factors(n);
    let mut ans = 0;
    for &v in mp.values() {
        let mut v = v;
        let mut i = 1;
        while v >= i {
            v -= i;
            ans += 1;
            i += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2136
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;

  ll cc,dd,cd;
  cc=b/c-(a-1)/c;
  dd=b/d-(a-1)/d;
  cd=b/lcm(c,d)-(a-1)/lcm(c,d);

  cout<<(b-a+1)-(cc+dd-cd)<<endl;
  //cout<<lcm(c,d);
}

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

int n, a, b, c, d;
char s[200010];

inline void wa() {
	puts("No");
	exit(0);
}

int main()
{
	register bool flag = false;
	scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
	scanf("%s", s + 1);
	for (register int i = a + 1; i <= c; ++i) {
		if (s[i] == '#' && s[i - 1] == '#') wa();
	}
	for (register int i = b + 1; i <= d; ++i) {
		if (s[i] == '#' && s[i - 1] == '#') wa();
	}
	if (c > d) {
		for (register int i = b; i <= d; ++i) {
			if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') flag = true;
		}
	} else flag = true;
	if (flag == true) puts("Yes");
	else puts("No");
	return 0;
}

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

using namespace std;

int main() {
    long long int K, tmp;
    cin >> K;
    queue<long long int> q;

    if (K <= 9) {
        cout << K;
        return 0;
    }

    for (int i = 1; i < 10; ++i) {
        q.push(i);
    }

    while (true) {
        tmp = q.front();
        K -= 1;
        if (K == 0) {
            cout << tmp;
            return 0;
        }
        q.pop();
        if (tmp % 10 != 0) {
            q.push(10 * tmp + tmp % 10 - 1);
        }
        q.push(10 * tmp + tmp % 10);
        if (tmp % 10 != 9) {
            q.push(10 * tmp + tmp % 10 + 1);
        }
    }
}


Measured memory_bytes: 1792
n, k = map(int, input().split())
a = list(map(int, input().split()))

# 部分和の作成
l = []
for i in range(n):
    t=0
    for j in range(i, n):
        t += a[j]
        l.append(t)
ans = 0
for i in range(40, -1, -1):
    x = 2 ** i
    s = []
    for ll in l:
        if (ans + x) & ll == (ans + x):
            s.append(ll)
    if len(s) >= k:
        ans += x
print(ans)



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

const int maxn(2e5 + 5);

int n, k, a[maxn], b[maxn], ql[maxn], qr[maxn], o[maxn], len, cov[maxn << 2];
ll f[maxn], ans = 1e18, sum;

void Modify(int x, int l, int r, int ql, int qr, int cv) {
	if (ql > qr) return;
	if (ql <= l && qr >= r) cov[x] = cv;
	else {
		int mid = (l + r) >> 1;
		if (cov[x]) cov[x << 1] = cov[x << 1 | 1] = cov[x], cov[x] = 0;
		if (ql <= mid) Modify(x << 1, l, mid, ql, qr, cv);
		if (qr > mid) Modify(x << 1 | 1, mid + 1, r, ql, qr, cv);
	}
}

int Query(int x, int l, int r, int p) {
	if (l == r) return cov[x];
	int mid = (l + r) >> 1;
	if (cov[x]) cov[x << 1] = cov[x << 1 | 1] = cov[x], cov[x] = 0;
	return p <= mid ? Query(x << 1, l, mid, p) : Query(x << 1 | 1, mid + 1, r, p);
}

inline int Cost(int p1, int p2) {
	return p1 <= p2 ? p2 - p1 : p2 + k - p1;
}

int main() {
	int i, v;
	scanf("%d%d", &n, &k);
	for (i = 1; i <= n; ++i) {
		scanf("%d%d", &a[i], &b[i]);
		if (b[i] == 1 && (a[i] << 1) > k) return puts("-1"), 0;
		sum += a[i], a[i] = (a[i] + a[i - 1]) % k;
	}
	o[++len] = 0, o[++len] = k - 1;
	for (i = 1; i <= n; ++i) {
		if (b[i] == 1) {
			ql[i] = ((-2 * a[i - 1]) % k + k) % k;
			qr[i] = ((-2 * a[i]) % k + k) % k;
		}
		else ql[i] = 0, qr[i] = k - 1;
		o[++len] = ql[i], o[++len] = qr[i];
	}
	sort(o + 1, o + len + 1), len = unique(o + 1, o + len + 1) - o - 1;
	for (i = 1; i <= n; ++i) {
		ql[i] = lower_bound(o + 1, o + len + 1, ql[i]) - o;
		qr[i] = lower_bound(o + 1, o + len + 1, qr[i]) - o;
	}
	Modify(1, 1, len, 1, len, n + 1);
	for (i = n; i; --i) {
		v = Query(1, 1, len, ql[i]), f[i] = f[v] + (v <= n ? Cost(o[ql[i]], o[ql[v]]) : 0);
		if (ql[i] <= qr[i]) Modify(1, 1, len, 1, ql[i] - 1, i), Modify(1, 1, len, qr[i] + 1, len, i);
		else Modify(1, 1, len, qr[i] + 1, ql[i] - 1, i);
	}
	for (i = 1; i <= len; ++i) v = Query(1, 1, len, i), ans = min(ans, f[v] + (v <= n ? Cost(o[i], o[ql[v]]) : 0));
	ans += sum + sum, printf("%lld\n", ans);
	return 0;
}
//orz fdf

Measured memory_bytes: 7680
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T119b
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int K = int.Parse(Console.ReadLine());

            List<char> cl = new List<char>(S);

            char C = cl[K-1];

            for(int i = 0; i < cl.Count; i++)
            {
                if(cl[i] != C)
                {
                    Console.Write('*');
                }
                else
                {
                    Console.Write(C);
                }
            }

            Console.WriteLine();

        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define drep(i, n) for (long long i = n - 1; i > 0; i--)
#define pb push_back
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    if ((h + w) % 2 == 1)
        cout << (h + w + 1) / 2 << endl;
    else
        cout << (h + w) / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
package main
import . "fmt"
func main() {
  var k,s,x,y,z,n,t int
  Scan(&k,&s)
  n = 0
  for z=0;z<=k;z++ {
    t = s - z
    if t < 0 { break }
    for y=0;y<=k;y++ {
      x = t - y
      if x < 0 { break }
      if x <= k { n++ }
    }
  }
  Println(n)
}
func min(x int,y int) int {
  if x < y {
    return x
  } else {
    return y
  }
}

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

int main(){
    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7'){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

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

int main() {
    int N,ans = 0;
    double D,x,y;
 
    cin >> N >> D; 

    for(int i= 0;i < N ;i++){
      cin >> x >> y;

      if(x*x + y*y <= D*D)
          ans++;
}
cout << ans;
}
    


Measured memory_bytes: 3744
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {a[i]=sc.nextInt();}
        long d[]=new long [1000];

        ArrayList<P> lis = new ArrayList<P>();
        long a=9,b=10;
        for(int i=1; i<10; i++) {
            lis.add(new P(i, -11+i));
        }
            lis.add(new P(19, -1));

        for(int i=1; i<15; i++) {
            for (long w=1; w<1000 ;w++ ){
                long x=w*b+a, y=x;
                int e=0;
                while(x>0){e+=x%10; x/=10; }
                lis.add(new P(y,(double)y/e));
            }
            b*=10; a*=10; a+=9;
        }
        sort(lis);
        long max=0;
        for (int w=0; w<lis.size() ;w++ ){
            if(max<lis.get(w).x){
            // db(lis.get(w).x,lis.get(w).d);
            max=lis.get(w).x;
            out.println(max);
            n--;
            if(n==0)break;
            }
        }

        // db(d);

        // for (int w=0; w<n ;w++ )
        // out.println(d[w]);
        out.flush();
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
     
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class P implements Comparable<P>{
    long x;
    double d;
    P(long x, double d) {
        this.x=x;
        this.d=d;
    } 
      
    public int compareTo(P p){
        return (d - p.d)>0?1:-1;//des
    } 
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 22228
#include <stdio.h>
#include <math.h>

int main(){
    int card[4][14];
    int num;
    char mark;
    int id;

    scanf("%d", &num);

    for(int m=0; m<4; m++){
        for(int i=1; i<=13; i++){
            card[m][i] = 0;
        }
    }

    for(int i=0;i<num;i++){
        scanf("%*c%c %d", &mark, &id);
        //printf("%c\n", mark);
        if(mark == 'S'){
            card[0][id] = 1;
            //printf("%c %d %d\n", mark, id, card[0][id]);
        }
        else if(mark == 'H'){
            card[1][id] = 1;
        }
        else if(mark == 'C'){
            card[2][id] = 1;
        }
        else if(mark == 'D'){
            card[3][id] = 1;
        }
    }

    for(int m=0; m<4; m++){
        for(int i=1; i<=13; i++){
            if(card[m][i]==0){
                //printf("%d %d %d\n", m, i, card[m][i]);
                if(m==0){
                    printf("S %d\n", i);
                }
                else if(m==1){
                    printf("H %d\n", i);
                }
                else if(m==2){
                    printf("C %d\n", i);
                }
                else if(m==3){
                    printf("D %d\n", i);
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 2064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, 0, n)
    cin >> a[i];
    ll nim = 0;
    REP(i, 2, n)
    nim ^= a[i];

    if ((nim ^ a[0] ^ a[1]) == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    ll rem = a[0] + a[1] - nim;
    ll a0 = 0, a1 = 0;
    REPR(i, 40, -1)
    if ((1LL << (i + 1)) & rem)
    {
        if ((1LL << i) & nim)
        {
            cout << -1 << endl;
            return 0;
        }

        a0 += (1LL << i);
        a1 += (1LL << i);
        rem -= (1LL << (i + 1));
    }
    REPR(i, 40, -1)
    if ((1LL << i) & nim)
    {
        ll y = (1LL << i);
        if (a0 + y <= a[0])
            a0 += y;
        else
            a1 += y;
    }

    if (rem > 0 || a0 == 0 || a0 > a[0])
    {
        cout << -1 << endl;
        return 0;
    }

    assert((a0 ^ a1 ^ nim) == 0);

    cout << a[0] - a0 << endl;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
using namespace std;

typedef unsigned int U;
#define L 1<<21
bool HA[L];
char T[256];

int main() {
    register U n, s, t;
    char c;
    T['A'] = 1, T['C'] = 2, T['G'] = 3, T['T'] = 4;
    scanf("%d", &n);
    getchar();
    while (n--) {
        s = 0;
        t = 1;
        bool flag = ( c = getchar() ) == 'i';
        while ( ( c = getchar() ) != ' ' );
        while ( ( c = T[getchar()] ) != 0 ) {
            s += c * t;
            t *= 4;
        }
        if ( flag ) {
            HA[s] = true;
        } else {
            puts( HA[s] ? "yes" : "no" );
        }
    }
    return 0;
}

Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t n, k; cin >> n >> k;
	int64_t sum = 1;
	int64_t ans = 0;
	for(int i = 0; ; ++i) {
		if(n >= sum) {
			ans = i + 1;
		} else {
			break;
		}
		sum *= k;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

bool solved;
int inputs[20];

// recursive check if sum can be made by picking / not picking
// each index of inputs array
void check(int index, int sum, int max_index) {
  if (solved) return; // early termination
  int new_sum = sum - inputs[index];
  if (new_sum == 0) {
    solved = true;
    return;
  }
  if (index < max_index) {
    if (new_sum > 0) check(index + 1, new_sum, max_index); // pick cur index
    check(index + 1, sum, max_index); // don't pick cur index
  }
}
  

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &inputs[i]);
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int sum;
    scanf("%d", &sum);
    solved = false;
    check(0, sum, n-1);
    solved ? printf("yes\n") : printf("no\n");
  }
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/combine.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> x(n);
    for (auto&& xx : x) {
        cin >> xx;
    }

    constexpr auto M = 1000000007L;

    int64_t ans = 1;
    int64_t k = 0, p = -1L;
    for (auto i : irange(0L, n)) {
        ans = ans * (k + 1) % M;
        if (p + 1 < x[i]) {
            p += 2;
            ++k;
        }
    }

    cout << ans << endl;
}

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

using namespace std;
#define MX 1e5+1
#define pb push_back
#define prr pair<int,int> 
#define int long long


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
    int n,x,y;
    cin>>n>>x>>y;
    int arr[n+1][n+1];
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j++){
            arr[i][j]=j-i;
            arr[j][i]=j-i;
        }
    }
    unordered_map<int,int> m1;
    arr[x][y]=1;
    arr[y][x]=1;
    
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j++){
            int a1=arr[i][x]+arr[x][j];
            a1=min(a1,arr[i][j]);
            arr[i][j]=a1;
            arr[j][i]=a1;
        }
    }
    
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j++){
            int a1=arr[i][y]+arr[y][j];
            a1=min(a1,arr[i][j]);
            arr[i][j]=a1;
            arr[j][i]=a1;
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j++){
            m1[arr[i][j]]++;
        }
    }
    // for(auto x:m1){
    //     cout<<x.first<<" "<<x.second<<"\n";
    // }

    for(int i=1;i<=n-1;i++){
        cout<<m1[i]<<"\n";
    }

    
}



















Measured memory_bytes: 31616
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    ll n,m;cin >> n >> m;
    ll sum = 0;
    vl a(n);rep(i,n)cin >> a[i];
    rep(i,n)sum+=a[i];
    sort(all(a));reverse(all(a));
    if(a[m-1]*4LL*m >= sum){
        cout << "Yes" << '\n';
    }else{
        cout << "No" << '\n';
    }
    return 0;
}
/*
 *!!CHECK!! 
 * 制約をよく読め：まず最も愚直な解法を考えろ
 * intの掛け算をしてる場合：overflowは大丈夫？
 * 制約の下限・上限は大丈夫？
 * 木構造は一直線にした時TLEしない？
 * */


Measured memory_bytes: 256
def number():
    return int(input())


def space():
    return list(map(int, input().split()))


N, K = space()
H = space()

inf = 10**4+1

dp = [0] * N
dp[0] = 0

for i in range(1, N):
    v = []
    for j in range(max(0, i - K), i):
        v.append(dp[j] + abs(H[j] - H[i]))
        # dp[i] = min(dp[i], dp[j] + abs(H[j] - H[i]))
    dp[i] = min(v)
print(dp[-1])



Measured memory_bytes: 52448
let () =
  Scanf.scanf "%d %d" @@ fun n c ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y)) in
  Array.sort compare a;

  (* (sum_v, score_f, score_fb *)
  let sa = Array.make (n+1) (0,0,0) in
  let (x0,v0) = a.(0) in
  sa.(1) <- (v0, max 0 (v0-x0), max 0 (v0-2*x0));
  for i = 2 to n do
    let (pv,py,pz), (x,v) = sa.(i-1), a.(i-1) in
    sa.(i) <- (pv+v, max py (pv+v - x), max pz (pv+v - 2*x))
  done;

  let sb = Array.make (n+1) (0,0,0) in
  let (x0,v0) = a.(n-1) in
  sb.(n-1) <- (v0, max 0 (v0 - (c-x0)), max 0 (v0 - 2*(c-x0)));
  for i = n-2 downto 0 do
    let (pv,py,pz), (x,v) = sb.(i+1), a.(i) in
    sb.(i) <- (pv+v, max py (pv+v - (c-x)), max pz (pv+v - 2*(c-x)))
  done;

  Array.init (n+1) (fun i ->
    let (_,pa,qa) = sa.(i) in
    let (_,pb,qb) = sb.(i) in
    max (pa+qb) (pb+qa))
  |> Array.fold_left max 0 |> Printf.printf "%d\n"

Measured memory_bytes: 15360
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ans = -1;

  rep(i, n) {
    for(int j = i; j<n; j++) {
      int tmp = abs(a[i] - a[j]);
      ans = max(tmp, ans);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const ll MOD = 1e9 + 7;
const double eps = 1e-9;
ll f[N];
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) r = r % MOD * a % MOD;
		a = a % MOD * a % MOD;
		n >>= 1;
	}
	return r % MOD;
}
ll ff(ll n,ll a){
    ll res = 1;
    for(ll i = n - a + 1; i <= n; ++i){
        res *= i;
        res %= MOD;
    }
    return res; 
}
ll C(ll n,int k) {
    return (ff(n,k)*(bp(f[k],MOD - 2))) % MOD;
}
void solve(){
    ll n,a,b;
    cin >> n >> a >> b; 
    ll ans = bp(2,n);
    ans += 3ll *MOD;
    ans --;
    ans -= C(n,a);
    ans -= C(n,b);
    cout << ans % MOD;
}
 
int main(){
    speed();
    int t = 1;
    f[0] = 1;
    for(ll i = 1; i < N; ++i){
        f[int(i)] = (f[int(i) - 1] * i) % MOD;
    }
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int f[] = new int[M];
        for(int i=0; i<N; i++) {
            int count = sc.nextInt();
            for(int k=0; k<count; k++) {
                int t = sc.nextInt();
                f[t-1]++;
            }
        }
        int result = 0;
        for(int t=0; t<M; t++) {
            if(f[t]==N) result++;
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 24660
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> g(h);

  vector<int> cnt(256);
  for (int i = 0; i < h; i++) {
    cin >> g[i];
    for (int j = 0; j < w; j++) {
      cnt[g[i][j]]++;
    }
  }

  int one = h % 2 == 1 && w % 2 == 1;
  int two = (h % 2 == 1 ? w / 2: 0) + (w % 2 == 1 ? h / 2 : 0);
  int four = (h / 2) * (w / 2);
  for (int i = 0; i < 256; i++) {
    while (four > 0 && cnt[i] > 0 && cnt[i] >= 4) {
      cnt[i] -= 4;
      four--;
    }
  }
  for (int i = 0; i < 256; i++) {
    while (two > 0 && cnt[i] > 0 && cnt[i] >= 2) {
      cnt[i] -= 2;
      two--;
    }
  }
  for (int i = 0; i < 256; i++) {
    while (one > 0 && cnt[i] > 0 && cnt[i] >= 1) {
      cnt[i]--;
      one--;
    }
  }

  if (one == 0 && two == 0 && four == 0) {
    puts("Yes");
  } else {
    puts("No");
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <queue>

using namespace std;
typedef long long LL;

const int maxn = 200005;
int n,m,a[maxn],f[maxn],c[maxn],t[maxn],ans;
int main()
{
	#ifdef LOCAL_JUDGE
		freopen("snuke.in","r",stdin);
		//freopen("snuke.out","w",stdout);
	#endif
	scanf("%d %d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),c[a[i]]++;
	for (int i=1;i<=n;i++)
	for (int j=i;j&&j>i-c[i];j--) t[j]++;
	for (int i=1;i<=n;i++) ans+=t[i]>0;
	for (int x,y,i=1;i<=m;i++)
	{
		scanf("%d %d",&x,&y);
		int o=a[x];a[x]=y;
		if (int w=o-c[o]+1) {
			if (w>0)
			if (!--t[w]) --ans;
		}
		c[o]--;c[y]++;
		if (int w=y-c[y]+1) {
			if (w>0)
			if (!t[w]++) ++ans;
		}
		printf("%d\n",n-ans);
	}
	return 0;
}

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

const int maxn = 1e5 + 5;
bool done[maxn];
int penalty[maxn];

int main() {
#ifdef LOCAL_EXEC
//    freopen("sample.in", "r", stdin);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#endif

  int n, m;
  cin >> n >> m;
  int score = 0, totpenalty = 0;
  while (m--) {
    int p;
    string s;
    cin >> p >> s;
    if (s == "AC") {
      if (!done[p]) {
        score++;
        done[p] = true;
        totpenalty += penalty[p];
      }
    } else {
      penalty[p]++;
    }
  }

  cout << score << ' ' << totpenalty << '\n';

	return 0;
}

Measured memory_bytes: 768
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;

int n,m;
int main(){
	cin>>n>>m;
	for(int i=0;i<=n;i++){
		for(int j=0;i+j<=n;j++){
			int k=n-(i+j);
			if(i+j+k==n && i*10000+j*5000+k*1000==m){
				cout<<i<<" "<<j<<" "<<k<<endl;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sf(n) scanf("%lld",&n)
#define sff(n,m) scanf("%lld %lld",&n,&m)
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PLL pair<ll,ll>
#define mod 998244353
#define mx 300002
#define FILE freopen("input.txt","r",stdin)

ll n;
ll ar[10];
ll ma,mb,mc;

ll F(ll i,ll a,ll b,ll c)
{
  if(i>n){
     if(a==0||b==0||c==0) return 1e17;
     else return abs(ma-a)+abs(mb-b)+abs(mc-c);
  }

  ll ret = (a>0?10:0)+F(i+1,a+ar[i],b,c);
  ret = min(ret,(b>0?10:0)+F(i+1,a,b+ar[i],c));
  ret = min(ret,(c>0?10:0)+F(i+1,a,b,c+ar[i]));
  ret = min(ret,F(i+1,a,b,c));

  return ret;
}

int main()
{
fastio
cin>>n>>ma>>mb>>mc;

for(ll i = 1;i<=n;i++)
{
  cin>>ar[i];
}

cout<<F(1,0,0,0)<<endl;

return 0;
}


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

using namespace std;

vector<string> s = {"SUN","MON","TUE","WED","THU","FRI","SAT"};


int main(){
	long n,ac=0;
	string ss;
	cin >> ss;

	for (auto x : s){
		if (ac != 0) ac++;
		if (x == ss) ac=1;
	}

	cout << ac << endl;

	cin >> n;
	return 0;

	
}

//abc145-c

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

using namespace std;

string smax(string A, string B) {
    if (A.length() < B.length()) {
        return B;
    } else if (A.length() > B.length()) {
        return A;
    } else {
        return (A > B ? A : B);
    }
}

string S;

string expr(int l, int r);

// fill [l, r) with digits
string number(int l, int r) {
    static vector<vector<string>> dp(S.length(), vector<string>(S.length(), "hoge"));
    string& ret = dp[l][r];
    if (ret != "hoge") return ret;

    ret = "";
    for (int i = l; i <= r; ++i) {
        if (S[i] != '?' && !isdigit(S[i])) return ret = "";
        ret.push_back(S[i] == '?' ? '9' : S[i]);
    }
    if (ret[0] == '0' && ret.length() > 1) return ret = "";
    return ret;
}

string left(int l, int r) {
    static vector<vector<string>> dp(S.length(), vector<string>(S.length(), "hoge"));
    string& ret = dp[l][r];
    if (ret != "hoge") return ret;

    ret = "";
    if (r <= l + 1 ||
        !(S[l] == 'L' || S[l] == '?') ||
        !(S[l + 1] == '(' || S[l + 1] == '?') ||
        !(S[r] == ')' || S[r] == '?')) return ret;
    l += 2;
    r -= 1;

    for (int i = l + 1; i <= r - 1; ++i) {
        if (S[i] != ',' && S[i] != '?') continue;
        string L = expr(l, i - 1);
        string R = expr(i + 1, r);
        if (L.empty() || R.empty()) continue;
        ret = smax(ret, L);
    }
    return ret;
}

string right(int l, int r) {
    static vector<vector<string>> dp(S.length(), vector<string>(S.length(), "hoge"));
    string& ret = dp[l][r];
    if (ret != "hoge") return ret;

    ret = "";
    if (r <= l + 1 ||
        !(S[l] == 'R' || S[l] == '?') ||
        !(S[l + 1] == '(' || S[l + 1] == '?') ||
        !(S[r] == ')' || S[r] == '?')) return ret;
    l += 2;
    r -= 1;

    for (int i = l + 1; i <= r - 1; ++i) {
        if (S[i] != ',' && S[i] != '?') continue;
        string L = expr(l, i - 1);
        string R = expr(i + 1, r);
        if (L.empty() || R.empty()) continue;
        ret = smax(ret, R);
    }
    return ret;
}

string expr(int l, int r) {
    static vector<vector<string>> dp(S.length(), vector<string>(S.length(), "hoge"));
    string& ret = dp[l][r];
    if (ret != "hoge") return ret;

    ret = number(l, r);
    ret = smax(ret, left(l, r));
    ret = smax(ret, right(l, r));
    return ret;
}

int main() {
    cin >> S;
    string ans = expr(0, S.length() - 1);
    cout << (ans.empty() ? "invalid" : ans) << endl;
    return 0;
}



Measured memory_bytes: 3432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,K;
    cin >>N>>K;
    if(N%K==0){
        cout<<0<<endl;
    }else{
        cout<<1<<endl;
    }



    return 0;
    

}

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

int main(void){
    int N, W; cin >> N >> W;
    int v[100], w[100];
    for(int i = 0; i < N; i++) cin >> v[i] >> w[i];

    int dp[10001] = {0};
    for(int i = 0; i < N; i++){
        for(int j = w[i]; j <= W; j++){
            dp[j] = max(dp[j-w[i]] + v[i], dp[j]);
        }
    }

    cout << dp[W] << '\n';
    return 0;
}



Measured memory_bytes: 3132
function main(lines) {
    const input = lines.split('\n').map(Number)[0]
    var count = 0
    for(var i=1; i<=input; i++){
        if(i.toString().split('').length % 2 === 1){
            count++
        }
    }
    console.log(count)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int main() {
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if (0 <= x - r && x + r <= w
        && 0 <= y - r && y + r <= h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int a;
    cin >> a;
    int ans = a+a*a+a*a*a;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.next();
			int k = sc.nextInt();
			String[] arr = new String[k];
			int len = s.length();
			for (int i = 0; i < len; i++) {
				for (int j = i + 1; j <= len; j++) {
					String next = s.substring(i, j);
					for (int at = 0; at < k; at++) {
						if (arr[at] == null) {
							arr[at] = next;
							break;
						}
						if (next.compareTo(arr[at]) > 0) {
							continue;
						} else if (next.compareTo(arr[at]) == 0) {
							break;
						} else {
							for (int mv = k - 1; mv > at; mv--) {
								arr[mv] = arr[mv - 1];
							}
							arr[at] = next;
							break;
						}
					}
				}
			}
			System.out.println(arr[k - 1]);
		}
	}
}

Measured memory_bytes: 55568
# coding: utf-8
# Your code here!

# 3問目

n = int(input())
a = list(map(int,input().split()))
count = i = 0

while True:
    hantei = True
    
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] = a[i] / 2
        else :
            hantei = False
            break

    if hantei:
        count += 1
    else:
        break

print(count)

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

int main(){
    int A,B,ans=0;
    cin >> A;
    cin >> B;

    for(int i=0;i<2;i++){
        if(A<B){
            ans += B;
            B--;
        }else{
            ans += A;
            A--;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

const lint mod = 998244353;

lint powmod(lint x, lint n){
  lint ret = 1;
  while(n > 0){
    if(n&1) ret *= x, ret %= mod, n -= 1;
    else x *= x, x %= mod, n >>= 1;
  }
  return ret;
}

template<class T> struct SegTree{
  int n;
  vector<T> node;
  
  SegTree(int n_){
    n = 1;
    while(n < n_) n *= 2;
    node.resize(n*2-1, 0);
  }
  
  void update(int i, T val){
    i += n - 1;
    node[i] += val;
    while(i > 0){
        i = (i-1) / 2;
        node[i] = node[i*2+1] + node[i*2+2];
    }
  }
  
  T getsum(int a, int b, int i, int l, int r){
    if(r<=a || b<=l) return 0;
    if(a<=l && r<=b) return node[i];
    T vl = getsum(a, b, i*2+1, l, (l+r)/2);
    T vr = getsum(a, b, i*2+2, (l+r)/2, r);
    return vl + vr;
  }
};

int main(){
    int n;
    scanf("%d", &n);
    pii p[n];
    vector<int> y(n);
    rep(i, n){
        int tx, ty;
        scanf("%d%d", &tx, &ty);
        p[i] = pii(tx, ty);
        y[i] = ty;
    }
    sort(y.begin(), y.end());
    sort(p, p+n);
    SegTree<lint> st1(n), st2(n);
    rep(i, n) st2.update(i, 1);
    lint ans = 0;
    rep(i, n){
        ans = (ans + powmod(2, n-1)) % mod;
        int id = lower_bound(y.begin(), y.end(), p[i].se) - y.begin();
        lint lu = st1.getsum(id+1, n, 0, 0, st1.n);
        lint ld = st1.getsum(0, id, 0, 0, st1.n);
        lint ru = st2.getsum(id+1, n, 0, 0, st2.n);
        lint rd = st2.getsum(0, id, 0, 0, st2.n);
        lint a = (powmod(2, lu)-1+mod)%mod * (powmod(2, rd)-1+mod)%mod * powmod(2, ld+ru)%mod;
        lint b = (powmod(2, ld)-1+mod)%mod * (powmod(2, ru)-1+mod)%mod * powmod(2, lu+rd)%mod;
        lint c = (powmod(2, lu)-1+mod)%mod * (powmod(2, rd)-1+mod)%mod * (powmod(2, ld)-1+mod)%mod * (powmod(2, ru)-1+mod)%mod;
        ans = (ans + a+b-c+mod)%mod;
        st1.update(id, 1);
        st2.update(id, -1);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 10752
from sys import maxsize as INF

def main():
    N,K = map(int, input().split())
    h = list(map(int, input().split()))
    cost = [INF]*N
    cost[0] = 0

    for j in range(1,N):
        for i in range(1,min(j,K)+1):
            cp = cost[j-i] + abs(h[j]-h[j-i])
            if cost[j] > cp : cost[j] = cp
        
    print(cost[-1])

    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 52448
function Main(input: string) {
  const lines = input.split('\n');
  const params = lines[0].split(' ').map(x => parseInt(x));

  const x = params[0];
  const y = params[1];
  const z = params[2];

  const s = `${z} ${x} ${y}`;

  console.log(s);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i];
    }

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

    double len_path = 0.0;
    do
    {
        for (int i = 0; i < n - 1; i++)
        {
            int sqdx = (x[p[i + 1]] - x[p[i]]) * (x[p[i + 1]] - x[p[i]]);
            int sqdy = (y[p[i + 1]] - y[p[i]]) * (y[p[i + 1]] - y[p[i]]);

            len_path += sqrt(static_cast<double>(sqdx + sqdy));
        }

    } while (next_permutation(p.begin(), p.end()));

    for (int i = 2; i <= n; i++)
    {
        len_path /= static_cast<double>(i);
    }

    cout << setprecision(numeric_limits<double>::digits10 + 1) << len_path << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
max_a = 0
next_a = 0
max_loc = 0
for i in range(n):
    ai = int(input())
    if ai > max_a:
        max_a =ai
        max_loc = i
    elif ai > next_a:
        next_a = ai
if next_a == 0:
    for i in range(n):
        print(max_a)
else:
    for i in range(max_loc):
        print(max_a)
    print(next_a)
    for i in range(n-max_loc-1):
        print(max_a)

Measured memory_bytes: 9132
k, n = list(map(int, input().split()))
aa = list(map(int, input().split()))

max_space = 0

for i in range(n):
    if i == 0:
        max_space = k - aa[n - 1] + aa[0]
    else:
        max_space = max(max_space, aa[i] - aa[i - 1])
print(k - max_space)


Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  sort(ALL(v));
  double ans = v[0];
  rep(i,n-1) ans = (ans + v[i+1]) / 2;
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3700
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut jobs: Vec<(usize, usize)> =
        (0..n)
            .map(|_| {
                (
                    iterator.next().unwrap().parse().unwrap(),
                    iterator.next().unwrap().parse().unwrap(),
                )
            })
            .collect();

    jobs.sort_by(|a, b| a.1.cmp(&b.1));

    let mut ans = "Yes";

    let mut time = 0;
    for (need, limit) in jobs {
        time += need;
        if time > limit {
            ans = "No";
            break;
        }
    }

    return ans.to_string();
}


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

int main(){
	char ss[90];
	int i,j,number,k,t;
	number=0;
	while(~scanf(" %s ",ss)){
		for(i=0;;i++){
			if(ss[i]=='\0')break;
			
			if(ss[i]>'0' && ss[i]<='9'){
				t=i;
				for(j=i;;j++){
					if(ss[j]<'0' || ss[j]>'9')break;
				}
				--j;
				t=j;
				k=1;
				for(j;j>=i;j--){
					number+=(ss[j]-'0')*k;
					k*=10;
				}
				i=t;
			}
		}
	}
	
	printf("%d\n",number);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }

int main() {
    double n;
    cin >> n;
    cout << fixed << setprecision(10);
    vector<double> x(n);
    rep(i,n)cin >> x.at(i);
    vector<double> y(n);
    rep(i,n)cin >> y.at(i);
    for(double i =1;i<=3;i++){
        double dist = 0;
        double sum = 0;
        rep(j,n)sum += pow(abs(x.at(j) - y.at(j)),i);
        dist = pow(sum,1.0/i);
        cout << dist << "\n";
    }
    double Chebyshev_dist = 0;
    rep(i,n)Chebyshev_dist = max(abs(x.at(i) - y.at(i)),Chebyshev_dist);
    cout << Chebyshev_dist << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


Measured memory_bytes: 3488
#include<iostream>
#include <cmath>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
typedef long long llong;

int main()
{
	char a[100];
	int sizeofa, b[100];
	cin >> a;
	for (int i = 0;;i++)
	{
		b[i] = a[i] - '0';
		if (a[i] == '\0') 
		{
			sizeofa = i;
			break;
		}
	}
	int ans = 10000;
	
	for (int i = 0; i < sizeofa - 2; i++)
	{
		if (abs(b[i] * 100 + b[i + 1] * 10 + b[i + 2] - 753) < ans) ans = abs(b[i] * 100 + b[i + 1] * 10 + b[i + 2] - 753);
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <queue>
#include <string>
#include <map>
#include <vector>

using namespace std;

bool cmp(pair<string, int> a, pair<string, int> b) {
  return a.second > b.second || (a.second == b.second && a.first < b.first);
}

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    string s, l;
    getline(cin, l);
    for (int i = 0; i < n; i++) {
      getline(cin, l);
      s += l;
      s += ' ';
    }
    char k;
    cin >> k;
    int c = 0;
    char w[21];
    map<string, int> freq;
    for (int i = 0; i < s.length(); i++)
      if (s[i] == ' ' && c) {
        w[c] = '\0';
        if (w[0] == k) freq[w]++;
        c = 0;
      } else
        w[c++] = s[i];
    vector<pair<string, int> > v;
    for (map<string, int>::iterator p = freq.begin(); p != freq.end(); ++p)
      v.push_back(*p);
    if (v.empty())
      cout << "NA" << endl;
    else {
      sort(v.begin(), v.end(), cmp);
      cout << v[0].first;
      for (int i = 1; i < min(v.size(), (vector<pair<string, int> >::size_type)5); i++)
        cout << ' ' << v[i].first;
      cout << endl;
    }
  }
}

Measured memory_bytes: 1252
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        
        int tens = 1;
        for (int i = 0; i < N; i++) {
            tens = mul(tens, 10);
        }
        int nines = 1;
        for (int i = 0; i < N; i++) {
            nines = mul(nines, 9);
        }
        int eights = 1;
        for (int i = 0; i < N; i++) {
            eights = mul(eights,8);
        }
        int ans = add(tens, eights);
        ans = sub(ans,nines);
        ans = sub(ans,nines);
        out.println(ans);
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);

    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 33172