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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll mx;
ll fac[1000010],finv[1000010];

ll comb(ll n,ll r){
  maxch(mx,n); maxch(mx,r);
  if(n<0||r<0||n<r)return 0;
  else return ((fac[n]*finv[n-r])%mod)*finv[r]%mod;
}

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

ll calc(ll S,ll N){
  if(S<0)return 0;
  return comb(S+N,N);
}

ll calc2(ll S,ll N,ll M,ll X,ll Y){
  ll c=comb(N,M);
  S-=(N-M)*Y;
  if(S<0)return 0;
  ll res=0;
  rep(i,M+1){
    if(S<0)break;
    ll add=comb(M,i)*c%mod;
    (add*=calc(S,N))%=mod;
    if(i%2==0) (res+=add)%=mod;
    else (res+=(mod-add))%=mod;
    S-=X+1;
  }
  return res;
}

ll N,M,L,R;

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

  fac[0]=1;
  rep(i,1000000)fac[i+1]=fac[i]*(i+1)%mod;
  rep(i,1000001)finv[i]=mod_pow(fac[i],mod-2);

  cin>>N>>M>>L>>R;
  M=N-M;
  ll tot=(calc(R,N)-calc(L-1,N)+mod)%mod;
  rep(X,R){
    ll Y=X+1;
    ll sub=((calc2(R,N,M,X,Y)-calc2(R,N,M,X,Y+1)+mod)%mod-(calc2(L-1,N,M,X,Y)-calc2(L-1,N,M,X,Y+1)+mod)%mod+mod)%mod;
    tot=(tot-sub+mod)%mod;
  }
  cout<<tot<<endl;

  return 0;
}


Measured memory_bytes: 15872
import java.util.*;

class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int count = 0;
        while (a > 0 && c > 0) {
            if (count % 2 == 0) {
                c -= b;
            } else {
                a -= d;
            }
            count++;
        }
        if (c <= 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}


Measured memory_bytes: 35740
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;

int const N = 1e5;
int u,v,w;
bool tr[N+1],res[N+1];
vector<pair<int,int>> e[N+1];

queue<int> q;

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

	
	for(int i=1;i<=n;i++){
		cin>>u>>v>>w;
		e[u].push_back({v,w});
		e[v].push_back({u,w});
	}
	res[1] = 1;
	q.push(1);
	
	while(!q.empty()){
		int r = q.front();
		tr[r] = true; 
		q.pop();
		for(int i=0;i<e[r].size();i++){
			pair<int,int> p = e[r][i];
			int a = p.first;
			int b = p.second;
			if(!tr[a]){
				if(b%2==0) res[a] = res[r];
				else res[a] = !res[r];
				q.push(a);
			}
		}
	}
	
	for(int i=1;i<=n;i++) cout<<res[i]<<endl;
 	return 0;
}

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

int main()
{
    int i,j,m,n,k;
    char a[27],c[26];
    bool b[26];
    cin>>a;
    memset(b,false,sizeof(b));
    for(i=0;i<strlen(a);i++)
    {
        b[a[i]-'a']=true;
        c[i]=a[i];
    }
    if(strlen(a)==26)
    {

        if(next_permutation(a,a+26))
        {
            for(i=0;i<strlen(a);i++)
            {
                if(a[i]!=c[i])
                {
                    cout<<char(a[i])<<endl;break;
                }
                cout<<a[i];
            }
        }
        else
        {
            cout<<-1<<endl;
        }
        return 0;
    }
    cout<<a;
    for(i=0;i<26;i++)
        if(!b[i]) {cout<<char('a'+i)<<endl;break;}
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define INF (1<<21)

int main(void)
{
int i,j,n,m,ans=0,min,a[101][101],b[101],c[101];

scanf("%d",&n);

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

scanf("%d",&a[i][j]);
if(a[i][j]==-1) a[i][j]=INF;

}
}

for(i=0;i<101;i++){
b[i]=0;
c[i]=INF;
}

c[0]=0;

while(1){

min=INF;
m=-1;

for(i=0;i<n;i++){
if(b[i]) continue;
if(c[i]<min){
min=c[i];
m=i;
}
}

if(m==-1) break;

b[m]=1;
ans+=c[m];

for(i=0;i<n;i++){
if(b[i]) continue;
if(a[m][i]<c[i]){
c[i]=a[m][i];
}
}
}

printf("%d\n",ans);

return 0;
}



Measured memory_bytes: 2144
n = gets.chomp.to_i
xs = []
us = []
n.times.map.with_index(0) do |i|
  x, u = gets.chomp.split(' ')
  xs[i] = x
  us[i] = u
end

sum = 0.0
0.upto(n - 1).each do |i|
  if us[i] == 'BTC'
    yen = xs[i].to_f * 380000.0
  else
    yen = xs[i].to_f
  end
  sum += yen
end
puts sum


Measured memory_bytes: 1788
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

aa = inputs[0][0]
bb = inputs[0][1]
tt = inputs[0][2]

# body
if $debugFlag
  p aa
  p bb
  p tt
end

puts bb * ((tt.to_f + 0.5) / aa).floor

Measured memory_bytes: 1788
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        List<Integer>[] adj;
        int[] color;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();

            adj = (List<Integer>[]) new LinkedList[N];
            for (int i = 0; i < N; i++) adj[i] = new LinkedList<>();
            for (int i = 0; i < M; i++) {
                int v = in.nextInt() - 1;
                int w = in.nextInt() - 1;
                adj[v].add(w);
                adj[w].add(v);
            }
            long ans = 0L;
            color = new int[N];
            Arrays.fill(color, -1);
            if (bipartite(0, 0)) {
                int b = 0;
                for (int i = 0; i < N; i++) {
                    if (color[i] == 0) b++;
                }
                ans = 1L * b * (N - b) - M;
            } else {
                ans = 1L * N * (N - 1) / 2 - M;
            }
            out.println(ans);
        }

        private boolean bipartite(int v, int c) {
            if (color[v] != -1) {
                return c == color[v];
            }
            color[v] = c;
            boolean ans = true;
            for (int w : adj[v]) {
                ans &= bipartite(w, c ^ 1);
            }
            return ans;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 56724
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int N;
    cin >> N;
    int64_t pw = 1;
    rep2(i, 1, N + 1)
    {
        pw = (pw * i) % BG;
    }
    cout << pw << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int mo = 1e9 + 7, sz = 1e5 + 100;
typedef long long ll;
ll a, ans, arr[sz];

void solve()
{
    for (int i = 1; i <= a; i++)
        if (arr[i] == i)
        {
            swap(arr[i + 1], arr[i]);
            ans++;
        }
}
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    ans = 0;
    scanf("%lld", &a);
    for (int i = 1; i <= a; i++)
        scanf("%lld", arr + i);
    solve();
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1024
A, B = map(int, input().split())

def f(c):
  p =  (c + 1) // 2
  if p % 2 == 0:
    s = 0
  else:
    s = 1
  if c % 2 == 0:
    s = s ^ c
  return s

print(f(A - 1) ^ f(B))

Measured memory_bytes: 38384
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

const int MAX = 510000;
const int MOD = 1000000007;
const long long INF = 1LL << 60;

const ll MAXINDx = 100001;
const ll MAXINDy = 3001;


ll dp[MAXINDx] = {0};

vector<vector<int>> edges;

int rec(int v){
    int res = 0;

    if(dp[v] > -1)return dp[v];

    for(auto nv: edges[v]){
        res = max(res, rec(nv) + 1);
    }
    return dp[v] = res;
}

int main(){

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

    int N,M;

    cin >>N>>M;

    edges.assign(N,vector<int>());

    for(int i = 0; i < M;i++){
        int from, to;
        cin >>from>>to;
        edges[from-1].push_back(to-1);
    }

    for(int i = 0 ; i < N;i++){
        rec(i);
    }

    ll ans = -1;
    for(int i = 0; i < N;i++){
        ans = max(ans, dp[i]);
    }

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

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;

bool comp(const pair<int,int> a, const pair<int,int> b) {
    return a.second < b.second;
}

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


*/


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int N_MAX=200000;

template<class T>
class Fenwick_tree{
	int n;
	T a[N_MAX];

public:
	void build(int n){
		this->n=n;
		rep(i,n) a[i]=0;
	}

	void add(int i,T v){
		for(;i<n;i|=i+1) a[i]+=v;
	}

	T sum(int i,int j){
		if(i==0){
			T s=0;
			for(;j>=0;j=(j&(j+1))-1) s+=a[j];
			return s;
		}
		return sum(0,j)-sum(0,i-1);
	}
};

int main(){
	int q; cin>>q;
	vector<int> id(q),a(q),b(q);
	rep(i,q){
		cin>>id[i];
		if(id[i]==1) cin>>a[i]>>b[i];
	}

	vector<int> X;
	rep(i,q) if(id[i]==1) X.emplace_back(a[i]);
	sort(X.begin(),X.end());
	X.erase(unique(X.begin(),X.end()),X.end());
	int n=X.size();
	rep(i,q) if(id[i]==1) a[i]=lower_bound(X.begin(),X.end(),a[i])-X.begin();

	Fenwick_tree<int> F;
	Fenwick_tree<long long> L,R;
	F.build(n);
	L.build(n);
	R.build(n);

	int m=0;
	long long bsum=0;
	rep(i,q){
		if(id[i]==1){
			m++;
			F.add(a[i],1);
			L.add(a[i],X[ n-1]-X[a[i]]);
			R.add(a[i],X[a[i]]-X[  0 ]);
			bsum+=b[i];
		}
		else{
			int lo=0,hi=n;
			while(lo<hi){
				int mi=(lo+hi)/2;
				if(F.sum(0,mi)<(m+1)/2) lo=mi+1;
				else                    hi=mi;
			}

			long long ans=bsum,lnum=F.sum(0,lo-1),rnum=F.sum(lo+1,n-1);
			ans+=L.sum(  0 ,lo-1)-lnum*(X[n-1]-X[lo]);
			ans+=R.sum(lo+1, n-1)-rnum*(X[ lo]-X[ 0]);
			printf("%d %lld\n",X[lo],ans);
		}
	}

	return 0;
}


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a, b;
    cin >> a >> b;
    for(int i=0;i<=20000;++i){
        if(i*8/100 == a && i*10/100 == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<utility>
#include<deque>
#include<algorithm>

using namespace std;

typedef pair<int,int> P;

int N,W;
int x[50500];
int sum[50500];

P get(int id,int s){
	P res;
	int lb=id,ub=N;
	while(ub-lb>1){
		int mid=(ub+lb)/2;
		int n=mid-id+1;
		long long tmp=(long long)(sum[mid]-sum[id-1])+(long long)s*(n-1);
		if(tmp<W) lb=mid;
		else ub=mid;
	}
	res.first=ub+1;
	lb=id+1,ub=N+1;
	while(ub-lb>1){
		int mid=(ub+lb)/2;
		int n=mid-id+1;
		long long tmp=(long long)(sum[mid]-sum[id-1])+(n-1);
		if(tmp>W) ub=mid;
		else lb=mid;
	}
	res.second=lb+1;
	return res;
}

bool check2(int i,int s){
	int x=sum[N]-sum[i-1]+(N-i+1);
	if(x<=W) return true;
	return false;
}

bool ok[50500];

bool check(int s){
	deque<P> deq;
	deq.push_back(P(1,1));
	bool flg=false;
	for(int i=1;i<=N;i++) ok[i]=false;
	while(!deq.empty()){
		P p=deq.front();
		int id=p.first;
		if(id==N+1) return true;
		ok[id]=true;
		if(p.first==p.second) deq.pop_front();
		else deq[0].first++;
		P nxt=get(id,s);
		if(nxt.first>nxt.second) continue;
		if(deq.empty()||deq.back().second<nxt.first-1) deq.push_back(nxt);
		else deq.back().second=nxt.second;
	}
	for(int i=1;i<=N;i++) if(ok[i]){
		if(check2(i,s)) return true;
	}
	return false;
}

int main(){
	while(true){
		scanf("%d%d",&W,&N);
		if(N==0&&W==0) break;
		for(int i=1;i<=N;i++) scanf("%d",x+i);
		sum[0]=0;
		for(int i=1;i<=N;i++) sum[i]=sum[i-1]+x[i];
		int lb=0,ub=W;
		while(ub-lb>1){
			int mid=(ub+lb)/2;
			if(check(mid)) ub=mid;
			else lb=mid;
		}
		printf("%d\n",ub);
	}
	return 0;
}

Measured memory_bytes: 1492
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] C = sc.next().toCharArray();
        char before = '0';
        int answer = 0;

        for (int i = 0; i < C.length; i++) {
            if (i == 0) {
                before = C[i];
            } else if (before == '0' && before == C[i]) {
                answer++;
                before = '1';
            } else if (before == '1' && before == C[i]) {
                answer++;
                before = '0';
            } else {
                before = C[i];
            }
        }
        System.out.println(answer);
        sc.close();
    }
}

Measured memory_bytes: 39548
my($N,$Q)=split$",<>;
my@fenwicktree=(0)x$N;
sub add{
	my($p,$x)=@_;
	$p++;
	while($p<=$N){
		$fenwicktree[$p-1]+=$x;
		$p+=$p&-$p;
	}
}
sub sum{
	return prefixsum($_[1])-prefixsum($_[0]);
}
sub prefixsum{
	my$r=shift;
	my$s=0;
	while($r>0){
		$s+=$fenwicktree[$r-1];
		$r-=$r&-$r;
	}
	return$s;
}
my@a=split$",<>;
for$i(0..$#a){
	add($i,$a[$i]);
}
for(1..$Q){
	my($t,$a,$b)=split$",<>;
	if($t==0){
		add($a,$b);
	}
	else{
		print sum($a,$b),$/;
	}
}


Measured memory_bytes: 72848
#include <stdio.h>

int main(){
	int count=0,counter;
	int a,b,c;
	int i,j,k;
	int x,y[8];
	int cter;
	
	scanf("%d",&counter);
	while(counter>count){
		scanf("%d",&x);
		cter=10;
		c=0;
		printf("Case %d:\n",count+1);
		while(c<cter){
			
			x*=x;
			x/=100;
			x%=10000;
			c++;
			printf("%d\n",x);
		}
		count++;
	}
	return 0;
}

Measured memory_bytes: 592
import numpy as np
h,w=map(int,input().split())
graph=[[0 if i=='#' else float('inf') for i in list(input())] for _ in range(h)]
graph=np.array(graph)
for x in range(w-1):
    graph[:,x+1]=np.minimum(graph[:,x]+1,graph[:,x+1])
for x in range(w-1,0,-1):
    graph[:,x-1]=np.minimum(graph[:,x]+1,graph[:,x-1])
for y in range(h-1):
    graph[y+1,:]=np.minimum(graph[y,:]+1,graph[y+1,:])
for y in range(h-1,0,-1):
    graph[y-1,:]=np.minimum(graph[y,:]+1,graph[y-1,:])

print(int(np.max(graph)))


Measured memory_bytes: 52456
N = int(input())
a = [0]*10050
for i in range(1,105):
    for j in range(1,105):
        for k in range(1,105):
            v = i*i+j*j+k*k+i*j+i*k+j*k
            if v < 10050:
                a[v-1] += 1

for i in range(N):
    print(a[i])


Measured memory_bytes: 9384
#include<stdio.h>

int main(){

int a,b,c,on,tw,th;

scanf("%d %d %d",&a,&b,&c);

if(a <= b && b <= c){

on = a;  tw = b;  th = c;

}

else if(a <= c && c <= b){

on = a;  tw = c;  th = b;

}

else if(b <= a && a <= c){

on = b;  tw = a;  th = c;

}

else if(b <= c && c <= a){

on = b;  tw = c;  th = a;

}

else if(c <= a && a <= b){

on = c;  tw = a;  th = b;

}

else if(c <= b && b <= a){

on = c;  tw = b;  th = a;

}

printf("%d %d %d\n",on,tw,th);

return 0;

}

Measured memory_bytes: 1848
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

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

	int ops = 0;
	while (true) {
		int i = 0; 
		while (i < n && h[i] == 0) {
			++i;
		}

		if (i == n) {
			break;
		}

		while (i < n && h[i] != 0) {
			--h[i];
			++i;
		}

		++ops;
	}

	cout << ops << "\n";

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
//#include<cstdlib>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<iterator>
#include<deque>

using namespace std;
#define PI          acos(-1)
#define INF         10000000000000000ll
#define sc(n)       scanf("%d",&n);
#define lsc(n)      scanf("%lld",&n);
#define dsc(n)      scanf("%lf",&n);
#define LL          long long int
#define UI          unsigned int
#define ULL         unsigned long long int
#define DB          double
#define pii         pair<int,int>
#define PB          push_back
#define MP          make_pair
#define M(mx,a)     mx=max(mx,a)
#define IT          ::iterator
#define all(a)      a.begin(),a.end()
#define mems(a,b)   memset(a,b,sizeof(a))
#define ARC(n)      for(i=0;i<n;i++)
#define ASC(n,aa)   for(i=0;i<n;i++)scanf("%lld",&aa[i]);
#define PNT(n,aa)   for(i=0;i<n;i++)printf("%lld ",aa[i]);
#define mod         1000000007
#define NUM         200010
#define NUM2        1000000000



int main()
{
    int T=1,QQ=0;
    //cin >> T ;
    while(T--)
    {
        int n,k,i,j,l,r=0,sm=0,ans=0,zero=0;
        cin >> n >> k;
        string ss;
        cin >> ss;
        vector<int> vv,vvv;
        for(i=0,j=0;i<ss.size();i=j)
        {
            while(j<ss.size()&&ss[i]==ss[j])j++;
            vv.PB(ss[i]-'0');
            vvv.PB(j-i);
        }
        for(l=0;l<vvv.size();l++)
        {
            if(l>r)r=l;
            while(zero<=k&&r<vvv.size())
            {
                if(vv[r]==0&&zero==k)break;
                if(vv[r] == 0)zero++;
                sm+=vvv[r];
                r++;
            }
            ans=max(sm,ans);
            sm-=vvv[l];
            if(vv[l]==0)zero--;
        }
        cout << ans ;
    }
}


Measured memory_bytes: 1404
n=int(input())
from collections import deque
a=list(map(int,input().split()))
a.sort()
a.reverse()
c=0
d=0
e=0
b=deque(a)
c+=b.popleft()
f=(n-2)//2
for i in range(f):
  e=b.popleft()
  c+=2*e
if n%2==1:
  e=b.popleft()
  c+=e
print(c)

Measured memory_bytes: 32436
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
d = {}
for i in range(n):
    s = input()
    if s not in d.keys():
        d[s] = 1
    else:
        d[s] += 1
m = max(d.values())
ans = []
for k, v in d.items():
    if v == m:
        ans.append(k)
print(*sorted(ans))

Measured memory_bytes: 34012
import datetime
import string
import re
import math

inp = list(map(int, input().split()))
N=int(inp[0])
D=int(inp[1])
alist = [input().split() for i in range(N)]

count = 0
for i in range(N):
    if int(alist[i][0])**2 + int(alist[i][1])**2 <= D**2: count += 1

print(count)

Measured memory_bytes: 68528
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <list>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

struct point{ double x; double y; };

void Koch(point a, point b, int n) {
	if(n == 0) return;
	point s, t, u;
	double th = M_PI * 60.0 / 180.0; 

	s.x = (2.0*a.x + b.x)/3.0;
	s.y = (2.0*a.y + b.y)/3.0;
	t.x = (a.x + 2.0*b.x) / 3.0;
	t.y = (a.y + 2.0*b.y) / 3.0;
	u.x = (t.x-s.x) * cos(th) - (t.y-s.y) * sin(th) + s.x;
	u.y = (t.x-s.x) * sin(th) + (t.y-s.y) * cos(th) + s.y;

	Koch(a, s, n-1);
	printf("%.8f %.8f\n", s.x, s.y);
	Koch(s, u, n-1);
	printf("%.8f %.8f\n", u.x, u.y);
	Koch(u, t, n-1);
	printf("%.8f %.8f\n", t.x, t.y);
	Koch(t, b, n-1);
}

int main() {
	int n;
	cin >> n;
	point a, b;
	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;
	printf("%.8f %.8f\n", a.x, a.y);
	Koch(a, b, n);
	printf("%.8f %.8f\n", b.x, b.y);
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n,m,k;
    cin>>n>>m>>k;
    vector<int> a(n),b(m);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<m;i++) cin>>b[i];
    long long pref_a[n+1];
    long long pref_b[m+1];
    pref_a[0]=0;
    pref_b[0]=0;
    for(int i=1;i<=n;i++)
        pref_a[i]=pref_a[i-1]+a[i-1];
    for(int j=1;j<=m;j++)
        pref_b[j]=pref_b[j-1]+b[j-1];
    /*for(int i=0;i<=n;i++)
       cout<<pref_a[i]<<" ";
    cout<<endl;
    for(int i=0;i<=m;i++)
        cout<<pref_b[i]<<" ";*/
    int i=0,j=m;
    int ans=0;
    while(true)
    {
        //cout<<i<<" "<<j<<endl;
        if(i==n and j==0) 
        {
            if(pref_a[i]+pref_b[j]<=k)
                ans=max(ans,i+j);
            break;
        }
        if(pref_a[i]+pref_b[j]<=k)
            ans=max(ans,i+j);
        if((pref_a[i]+pref_b[j]<=k and i<n) or j==0)
            i++;
        else
            j--;
    }
    
    cout<<ans;
    return 0;
}



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

using namespace std;

int a,b,c;
multiset<string> se;

int main(){
	scanf("%d%d%d",&a,&b,&c);
	for (int i=1;i<=a;++i) se.insert("a");
	for (int i=1;i<=b;++i) se.insert("b");
	for (int i=1;i<=c;++i) se.insert("c");
	while (se.size()>1){
		string x=*se.begin(),y=*se.rbegin();
		se.erase(se.begin()); se.erase(--se.end());
		se.insert(x+y);
	}
	puts(se.begin()->c_str());
	
	return 0;
}
			

Measured memory_bytes: 256
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;

const int Mod = (int)1e9 + 7;
const int MAXN = 100005;
string str;
int p[MAXN];
int memo[MAXN][13];

int solve(int idx, int rem) {
    if (idx == str.size())
        return rem == 5;
    int &ret = memo[idx][rem];
    if (~ret)
        return ret;
    ret = 0;
    if (str[idx] == '?') {
        for (int i = 0; i < 10; ++i) {
            ret += solve(idx + 1, (rem + i * p[idx] % 13) % 13);
            ret %= Mod;
        }
    } else {
        ret = solve(idx + 1, (rem + (str[idx] - '0') * p[idx] % 13) % 13);
        ret %= Mod;
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;


    cin >> str;
    p[str.size() - 1] = 1;
    for (int i = str.size() - 2; ~i; --i) {
        p[i] = p[i + 1] * 10 % 13;
    }
    memset(memo, -1, sizeof memo);
    cout << solve(0, 0) << '\n';

    return 0;
}

Measured memory_bytes: 10604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  string A, B, C;
  cin >> N >> A >> B >> C;
  int ans = 0;
  rep(i, N)
  {
    if (A[i] != B[i] && B[i] != C[i] && C[i] != A[i])
      ans += 2;
    else if (A[i] == B[i] && B[i] == C[i])
      continue;
    else
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    if N == 1:
        if K == A[0]: return "POSSIBLE"
        else: return "IMPOSSIBLE"
    if max(A) < K:
        return "IMPOSSIBLE"
    if K in A:
        return "POSSIBLE"

    ref = A[0]
    for i in range(1, N):
        ref = gcd(ref, A[i])
    for i in range(N):
        if A[i] > K and (A[i]-K) % ref == 0:
            return "POSSIBLE"
    return "IMPOSSIBLE"

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0: return b
    else: return gcd(b%a, a)

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 14232
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<57;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

ll n,D,q;
vl d;

int main(){
	cin>>n>>D;
	d=vl(n);
	for(int i=0;i<n;i++) cin>>d[i];
	vl a(n+1);
	for(int i=0;i<n;i++){
		a[i]=D;
		if(d[i]<D) D-=d[i];
		else D=min(D,d[i]-D);
	}
	a[n]=D;
	D=1;
	vl b(n+1);
	for(int i=n-1;i>=0;i--){
		b[i+1]=D;
		if(D>d[i]/2) D+=d[i];
	}
	b[0]=D;
	cin>>q;
	for(int i=0;i<q;i++){
		ll t;
		cin>>t;
		if(a[t-1]>=b[t]) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 15232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int N,K,C; 
char s[200001];
int l[200001],r[200001];

int main(){
  cin>>N>>K>>C;
  for(int i=1;i<=N;++i){
    cin>>s[i];
  }
  int count = 1;
  for(int i=1;i<=N;++i){
    if(s[i]=='o'){
      l[count] = i;
      ++count;
      if(count==K+1){break;}
      else{i+=C;}
    }
  }
  count = K;
  for(int i=N;i>=1;--i){
    if(s[i]=='o'){
      r[count] = i;
      --count;
      if(count==0){break;}
      else{i-=C;}
    }
  }
  for(int i=1;i<=K;++i){
    if(l[i]==r[i]){cout<<l[i]<<"\n";}
  }
  
}

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

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  int cnt(0);
  for (int i(0);i<=n;i++){
    int sum(0);
    string s=to_string(i);
    for (int j(0);j<s.size();j++){
      sum+=(s[j]-'0');
    }
    if (sum>=a&&sum<=b) cnt+=i;
  }
  cout << cnt << endl;
}


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

#define ll long long
#define MOD 1000000007


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

    vector<double> p(n+1,0);
    vector<double> sum(n+1);


    cin>>p.at(1);
    sum.at(1) = (p.at(1)*(p.at(1)+1)/2)/p.at(1);
    for(int i=2;i<=n;i++){
        cin>>p.at(i);
        sum.at(i) = (p.at(i)*(p.at(i)+1)/2)/p.at(i) + sum.at(i-1);
    }

    double ans = 0;
    for(int i=0;i+k<=n;i++){
        ans = max(ans,sum.at(i+k)-sum.at(i));
    }

    cout<<fixed<<setprecision(6)<<ans<<endl;

}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(x) for(auto it=(x).begin();it!=(x).end();it++) 
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
 
using namespace std;

int main(){
    int n;
    cin>>n;
    rep(i,0,n){
        int m; cin>>m;
        int ma=0,mi=0;
        int past;
        rep(j,0,m){
            if(j==0)cin>>past;
            else {
                int x; cin>>x;
                if(x-past>0)ma=max(ma,x-past);
                else mi=max(mi,past-x);
                
                past=x;
                
            }
            
        }
    cout<<ma<<" "<<((mi==INF)?0:mi)<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

void Main()
{
	int A, B;
	cin >> A >> B;
	
	if (B == 1) {
		cout << 0;
		return;
	}
	int ret = 0;
	ret = (B - 1) / (A - 1);
	if ((B - 1) % (A - 1) != 0) {
		ret++;
	}
	cout << ret;
}
 
int main()
{
	Main();
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3

from collections import defaultdict
from heapq import heappush, heappop
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x)


def solve1(N, K, heights):
    heights += [INF] * K
    costs = [INF] * (N + K)
    costs[0] = 0
    for i in range(N - 1):
        for k in range(1, K + 1):
            newcost = costs[i] + abs(heights[i + k] - heights[i])
            if newcost < costs[i + k]:
                costs[i + k] = newcost
    return costs[N - 1]


def solve(N, K, heights):
    costs = [0] * N
    costs[0] = 0
    for i in range(1, N):
        costs[i] = min(
            costs[j] + abs(heights[i] - heights[j])
            for j in range(max(i - K, 0), i)
        )

    return costs[-1]


def solve3(N, K, heights):
    costs = [None] * N
    costs[0] = 0

    def get_cost(i):
        if costs[i] != None:
            return costs[i]

        c = min(
            get_cost(j) + abs(heights[i] - heights[j])
            for j in range(max(i - K, 0), i)
        )
        costs[i] = c
        return c

    return get_cost(N - 1)


def main():
    N, K = map(int, input().split())
    heights = list(map(int, input().split()))
    print(solve(N, K, heights))


def _test():
    """
    >>> solve(5, 3, [10, 30, 40, 50, 20])
    30
    >>> solve(3, 1, [10, 20, 10])
    20
    >>> solve(2, 100, [10, 10])
    0
    >>> solve(10, 4, [40, 10, 20, 70, 80, 10, 20, 70, 80, 60])
    40
    """
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 83496
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        
        if (s.contains("RRR"))
            System.out.println(3);
        else if (s.contains("RR"))
            System.out.println(2);
        else if (s.contains("R"))
            System.out.println(1);
        else
            System.out.println(0);


    }
}


Measured memory_bytes: 35692
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))


int main(void)
{
long N, M, index;
long A[10000];

  scanf("%ld %ld", &N, &M);
  for (index = 0; index < M; ++index) {
    scanf("%ld", &A[index]);
    N -= A[index];
  }
  if (N < 0) {
    printf("-1\n");
  } else {
    printf("%ld\n", N);
  }
  
  return 0;
}


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

using namespace std;

int gcd(int a, int b){ //a>b
	int c =1;
	while(c!=0){
		c=a%b;
		a=b;
		b=c;
	}
	return a;
}

int main(){
	int A,B,K;
	cin >> A >>B >>K;

	std::vector<int> CD;

	int GCD = gcd(A,B);
	int d = GCD;
	while(d!=0){
		if (GCD%d ==0){
			CD.push_back(d);
		}
		d -= 1; 
	}

	cout << CD[K-1] << endl;
	return 0;
}

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

class Program
{
    void Run()
    {
        var sc = new Scanner();
        int a = sc.NextInt();
        int b = sc.NextInt();
        Console.WriteLine(a <= 5 ? 0 : a <= 12 ? b / 2 : b);
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
constexpr int INF = (numeric_limits<int>::max() == INT_MAX ? (int)1e9 : (long long)1e18);
constexpr long double eps = 1e-6;
const string el = "\n";
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;using pii = pair<int,int>;using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void fast_io(){ios::sync_with_stdio(false); cin.tie(nullptr);}
int out(int a){cout << a << el; return 0;}
int out(string s = "NO"){cout << s << el; return 0;}
template <class T>
inline int out(vector<T>&v,string c = " "){
    for(int i = 0; i < v.size(); ++i){
        if(i) cout << c; cout << v[i];
    } cout << el;return 0;
}
int solve(bool isLarge, deque<int>input){
    deque<int>u;
    if(isLarge){
        u.push_front(input.back());
        input.pop_back();
    } else {
        u.push_back(input.front());
        input.pop_front();
    }
    isLarge = !isLarge;
    int N = input.size();
    rep(i,N){
        if(isLarge){
            isLarge = false;
            int l = input.back();
            input.pop_back();
            bool is_l = false;
            if(abs(u.front() - l) > abs(u.back() - l)){
                u.push_front(l);
                is_l = true;
            }else{
                u.push_back(l);
            }
           // i += 1;
            if(input.empty()) continue;
            l = input.back();
            input.pop_back();
            if(not is_l)
                u.push_front(l);
            else
                u.push_back(l);
            i += 1;
            
        } else {
            isLarge = true;
            int l = input.front();
            input.pop_front();
            bool is_l = false;
            if(abs(u.front() - l) > abs(u.back() - l)){
                u.push_front(l);
                is_l = true;
            }else
                u.push_back(l);
            //i += 1;
            if(input.empty()) continue;
            l = input.front();
            input.pop_front();
            if(not is_l)
                u.push_front(l);
            else
                u.push_back(l);
            i += 1;
        }
    }
    int res = 0;
    for(int i = 0; i + 1 < u.size(); ++i)
        res += abs(u[i + 1] - u[i]);
    return res;
}
signed main(){
    fast_io();
    int N; cin >> N;
    deque<int>input;
    rep(_,N){
        int e; cin >> e;
        input.emplace_back(e);
    }
    sort(input.begin(),input.end());
    out(max(solve(true,input),solve(false,input)));
    
}




Measured memory_bytes: 1988
#include<bits/stdc++.h>
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
#define ll long long int
const ll mod = 1000000007;
int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string s;
  cin >> s;
  ll n = s.length();
  ll dp[n][13];
  memset(dp,0,sizeof(dp));
  if(s[0] == '?')
    for (int i = 0; i < 10; ++i)
    {
      dp[0][i] = 1;
    }
  else
    dp[0][s[0]-'0'] = 1;
 
  for (int i = 1; i < n ; ++i)
  {
    ll t = s[i]-'0';
    if(s[i] == '?')
    {
      for (int j = 0; j < 10; ++j)
      {
        t = j;
        for (int k = 0; k < 13; ++k)
        {
          dp[i][(k*10+t)%13] += dp[i-1][k];
          dp[i][(k*10+t)%13] %= mod;
        }
      }
    }
    else
    {
      for (int j = 0; j < 13; ++j)
      {
        dp[i][(j*10+t)%13] += dp[i-1][j];
        dp[i][(j*10+t)%13] %= mod;
      }
    }
    
  }
  
  cout << dp[n-1][5] << endl;
  return 0;
}

Measured memory_bytes: 10704
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[][] map = new int[n][2];
			for (int i = 0; i < n; i++) {
				map[i][0] = scanner.nextInt();
			}
			for (int i = 0; i < n; i++) {
				map[i][1] = scanner.nextInt();
			}

			int[] ans = new int[2];
			for (int i = 0; i < 2; i++) {
				int x = i;
				int y = 0;
				int count = 0;
				boolean[][] b = new boolean[n][2];
				while (true) {
					if (b[y][x]) {
						ans[i] = Integer.MAX_VALUE;
						break;
					}
					if (y == n - 1 && map[y][x] != 2) {
						ans[i] = count;
						break;
					}
					b[y][x] = true;
					if ( map[y][x] == 1 && map[y + 1][x] == 1)
						y++;
					else if (map[y][x] == 2)
						y--;
					else {
						if (x == 0)
							x = 1;
						else
							x = 0;
						if (y == n - 2)
							y += 1;
						else
							y += 2;
						count++;
					}
				}
			}
			if (ans[0] == Integer.MAX_VALUE && ans[1] == Integer.MAX_VALUE)
				System.out.println("NA");
			else
				System.out.println(ans[0] < ans[1] ? ans[0] : ans[1]);
		}
	}
}

Measured memory_bytes: 26520
import sys
sys.setrecursionlimit(100000)

V,E = map(int, input().split())
#???£??\??????????????????
A = [[] for i in range(V)]
for i in range(E):
    s,t = map(int, input().split())
    A[s].append(t)
    A[t].append(s)
     
#??????????????¨???????
prenum = [None for i in range(V)]
#DFS???????????????????????????
parent = [None for i in range(V)]
#?????????????????°??????????
lowest = [None for i in range(V)]
#??¨?????????????°??????
visited = [False for i in range(V)]
 
def DFS(u = 0, prev = -1, timer = 0):
    prenum[u] = timer
    lowest[u] = timer
    timer += 1
    visited[u] = True
     
    for v in A[u]:
        if not visited[v]:
            parent[v] = u
            DFS(v, u, timer)
            lowest[u] = min(lowest[u], lowest[v])
        elif v != prev:
            lowest[u] = min(lowest[u], prenum[v])
DFS()
 
ans = set()
  
for u in range(1, V):
    p = parent[u]
    if prenum[p] <= lowest[u]:
        ans.add(p)
  
if parent.count(0) >= 2:
    ans.add(0)
else:
    ans.discard(0)
  
ans = list(ans)
ans.sort()
  
if ans:
    print(*ans, sep = '\n')

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


int main()
{
    double a,b,C,PI=acos(-1),S,L,h;
    cin >> a >> b >> C; 

    double C_r=C*PI/180;

    S = a*b*sin(C_r)/2;

    L= a+b+ sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(C_r));

    h =2*S/a;   


    printf("%.7f\n%.7f\n%.7f\n",S,L,h);

    return 0;

}


Measured memory_bytes: 3524
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <ctime>
#include <deque>
#include <ctime>
#include <string>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cassert>
#include <cstring>
#include <queue>
#include <random>

#define fi first
#define se second
#define ll long long
#define pii pair<int, int>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pll pair<long long, long long>
#define mp(x, y) make_pair((x), (y))

using namespace std;

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

    int n, k;
    cin >> n >> k;
    vector<int> vec(n);
    int cnt=  0;
    for (int i = 0; i < n; ++i) {
        cin >> vec[i];
        if (vec[i] >= k) {
            cnt++;
        }
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B ;
  if(A > B){
    cout << 2*A-1 << endl;
  }else if(A < B){
    cout << 2*B-1 <<endl;
  }else{
  cout << A+B << endl;
  }
  }

Measured memory_bytes: 256
n, k = map(int, input().split())
s = input()
m = min(s)
for p in range(k):
    u = s + s[::-1]
    l = []
    cnt = 0
    idx = 0
    for i in range(n * 2):
        if u[i] == m:
            if cnt == 0:
                idx = i
            cnt += 1
        else:
            if cnt > 0:
                l.append((cnt, idx))
                cnt = 0
    if cnt > 0:
        l.append((cnt, idx))
    a, j = max(l)
    if a >= n:
        print(m * n)
        exit(0)
    for c, i in l:
        if i <= n and c == a:
            s = min(s, u[i:i + n])
    s = s[::-1]
print(s[::-1])


Measured memory_bytes: 42608
#include<stdio.h>
int Euclidean(int,int);
int main(){
  int a,b,result;
  scanf("%d %d",&a,&b);
  if(a<=b) result=Euclidean(b,a);
  else result=Euclidean(a,b);
  printf("%d\n",result);
  return 0;
}
int Euclidean(int x,int y){
  int r=0;
  r=x%y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }
  return y;
}

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

int main(int argc, char const *argv[])
{
	int a,b,c;

	cin >> a;
	cin >> b;
	cin >> c;

	if (a<b && b<c)
	{
	cout << "Yes" << endl;
	}else{
	cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 3088
N,K = map(int,input().split())
ans = 0
num = [0]*(K+1)
MOD = 10**9+7
for i in range(K,0,-1):
  num[i] = pow(K//i, N, MOD)
  for j in range(2*i,K+1,i):
    num[i]-=num[j]
  num[i]=num[i]%MOD
  ans+=num[i]*i
  ans%=MOD

print(ans%MOD)

Measured memory_bytes: 68908
#include <stdio.h>
int main(){
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    if(((A<C)&&(C<B))||((A>C)&&(C>B))){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128