akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> A(N);
  double sum=0;
  for(int i=0;i<N;i++)
    cin>>A.at(i).first>>A.at(i).second;
  sort(A.begin(),A.end());
  do{
    pair<int,int> y;
    int i=0;
    for(pair<int,int> x:A){
      if(i!=0){
      sum+=sqrt((x.first-y.first)*(x.first-y.first)+(x.second-y.second)*(x.second-y.second));
      //cout<<sum<<endl;
      }
        y.first=x.first;
      y.second=x.second;
      i++;
    }
  }while(next_permutation(A.begin(),A.end()));
  int n=1;
  for(int i=2;i<=N;i++)
    n*=i;
  printf("%.7f\n",sum/n);
}

Measured memory_bytes: 256
from collections import deque


S = input()
Q = int(input())

d = deque(list(S))

left_head = True

for i in range(Q):
    inp = input()

    if inp == '1':
        left_head = not left_head
    else:
        T, F, c = inp.split()

        # 戦闘
        if F == '1':
            if left_head:
                d.appendleft(c)
            else:
                d.append(c)
        else:
            if left_head:
                d.append(c)
            else:
                d.appendleft(c)


if left_head:
    print(''.join(d))
else:
    print(''.join(d)[::-1])


Measured memory_bytes: 8548
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)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 dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


ll n;
ll a[100100];
ll b[100100];
ll sum=0;

int main(){
	cin>>n;
	REP(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	ll nls=n*(n+1)/2;
	if(sum%nls!=0){
		cout<<"NO"<<endl;
		return 0;
	}
	nls=sum/nls;
	b[0]=a[0]-a[n-1];
	for(int i=0;i<n-1;i++){
		b[i+1]=a[i+1]-a[i];
	}
	for(int i=0;i<n;i++){
		b[i]-=nls;
		if(b[i]%n!=0){
			cout<<"NO"<<endl;
			return 0;
		}
		b[i]/=n;
		b[i]*=(-1);
		if(b[i]<0){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	for(int i=0;i<n;i++){
		nls-=b[i];
	}
	if(nls==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

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

int first[100003], next[200003], node[200003], n, len, ans[3], m;
char fs[100003];
bool vis[100003];

inline void readin(int n)
{
    int p = 1;
    for (int i = 1; i < n; ++i)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        next[p] = first[u];
        first[u] = p;
        node[p] = v;
        ++p;
        next[p] = first[v];
        first[v] = p;
        node[p] = u;
        ++p;
    }
}

bool dfs(int x, int deep)
{
    vis[x] = true;
    if (x == n)
    {
        len = deep >> 1;
        fs[n] = 2;
        ++ans[2];
        return true;
    }
    int t = first[x];
    while (t)
    {
        if (!vis[node[t]])
        {
            if (dfs(node[t], deep + 1))
            {
                if (deep > len)
                {
                    fs[x] = 2;
                    ++ans[2];
                }
                else
                {
                    fs[x] = 1;
                    ++ans[1];
                }
                return true;
            }
        }
        t = next[t];
    }
    return false;
}

void ddfs(int x)
{
    int t = first[x];
    while (t)
    {
        if (fs[node[t]] == 0)
        {
            ++ans[m];
            fs[node[t]] = m;
            ddfs(node[t]);
        }
        t = next[t];
    }
}

void init()
{
    memset(first, 0, sizeof first);
    memset(ans, 0, sizeof ans);
    memset(fs, 0, sizeof fs);
    memset(vis, false, sizeof vis);
}

int main()
{
    while (scanf("%d", &n) != EOF)
    {
        readin(n);
        dfs(1, 0);
        for (int i = 1; i <= n; ++i)
        {
            if (fs[i])
            {
                m = fs[i];
                ddfs(i);
            }
        }
        printf("%s\n", ans[1] > ans[2] ? "Fennec" : "Snuke");
        init();
    }
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
int ans=0,k=0,n,l=0,a[12],num[3]={3,5,7};
void tui(){
	cout<<ans;
	exit(0);
}
void suan(){
	int sum=0,t1=0,t2=0,t3=0;
	for(int i=0;i<l;i++){
//		cout<<a[i]<<" ";
		if(a[i]==3){
			t1++;
		}else if(a[i]==5){
			t2++;
		}else{
			t3++;
		}
		sum=sum*10+a[i];
	}
//	cout<<" "<<sum<<' '<<l;
	if(t1<1||t2<1||t3<1){
//		cout<<"###"<<endl;
		return;
	}
//	cout<<endl;
	if(sum<=n){
		ans++;
	}else{
		tui();
	}
}
void dfs(int j){
	if(j==0){
		suan();
		return;
	}
	for(int i=0;i<3;i++){
		a[l-j]=num[i];
		dfs(j-1);
	}
}
int main(){
	cin>>n;
	if(n<357){
		cout<<0;
		return 0;
	}
	while(true){
		if(n<pow(10,k)){
			break;
		}
		k++;
	}
	for(int i=3;i<=k;i++){
		l=i;
		dfs(i);
	}
	cout<<ans;
	return 0;
}

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

using namespace std;
using ll = long long;

int main()
{
   int n, a;
   cin>>n;
   for (int i = n; i < 1000; i++)
   {
       if (i/100 == i%10 && i/100 == i/10%10)
       {
           cout<<i;
           break;
       }
       
   }
   
   return 0;
}


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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

string S;
signed main() {
    cin >> S;
    int cur = 0, ans = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            cur++;
            chmax(ans, cur);
        } else { cur = 0; }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
N = int(input())
A = list(map(int, input().split()))
A.sort()

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if len(A) == 2:
    print(A[1])
    print(A[0])

half = A[-1] / 2
for i in range(N-2):
    if abs(A[i]-half) >= abs(A[i+1]-half) <= abs(A[i+2]-half):
            print(A[-1])
            print(A[i+1])
            exit()

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


#define fast_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define pb push_back
#define F first
#define S second
#define int long long int
#define ll long long
#define ld long double

bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}

ll lcm(ll x,ll y){
    return (x*y)/(__gcd(x,y));
}

ll nod(ll n){
    while(n%10==0){
        n/=10;
    }
    return n;
}


signed main(){
    fast_IO;
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a.begin(),a.end());
        int cnt=0;
        for(int i=0;i<n-2;i++){
            for(int j=i+1;j<n-1;j++){
                for(int k=j+1;k<n;k++){
                    if(a[i]!=a[j] && a[k]!=a[j] && a[i]!=a[k]){
                        if(a[i]+a[j]>a[k] && a[j]-a[i]<a[k]){
                            cnt++;
                        }
                    }
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}



Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        char[][] arr = new char[55][55];
        for(int i = 1; i <= H; i++) {
            String tmp = sc.next();
            for(int j = 1; j <= W; j++) {
                char c = tmp.charAt(j-1);
                arr[i][j] = c;
            }
        }
        int cnt = 0;
        for(int i = 1; i <= H; i++) {
            for(int j = 1; j <= W; j++) {
                if(arr[i][j] == '#' && arr[i][j-1] == '.' && arr[i][j+1] == '.' && arr[i-1][j] == '.' && arr[i+1][j] == '.') cnt++;
            }
        }
        if(cnt == 0) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 35668
#include "iostream"
#include "vector"
#include "string"

using namespace std;

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

	if (S.size() <= K) {
		cout << S;
	}
	else {
		
		cout << S.substr(0, K) + "..." ;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        if((N&(N-1)) == 0){
            cout << "No" << endl;
            continue;
        }
        cout << "Yes" << endl;
        vector<int> l(1, 1);
        vector<int> r(1, 1);
        vector<int> checked(N+1, 0);
        bool checkN = (N%2 == 1);
        for(int i=2;i+1<=N;i+=2){
            if(checked[i]) continue;
            l.push_back(i);
            l.push_back(i+1);
            r.push_back(N+i+1);
            r.push_back(N+i);
            if(!checkN && N%2 == 0 && (N^i) < N){
                int b = (N^i);
                checked[b] = 1;
                checkN = true;
                l.push_back(b+1);
                l.push_back(b);
                r.push_back(N+b);
                r.push_back(N+b+1);
                cout << N << " " << N+i << endl;
                cout << 2*N << " " << N+b << endl;
            }
        }
        for(int i=0;i+1<l.size();i++) cout << l[i] << " " << l[i+1] << endl;
        for(int i=0;i+1<r.size();i++) cout << r[i] << " " << r[i+1] << endl;
        cout << 3 << " " << N+1 << endl;
    }
}

Measured memory_bytes: 4212
line1 = input()

aryLine1 = line1.split()

N = int(aryLine1[0]);
D = float(aryLine1[1]);

X = []
Y = []
ans = 0

for i in range(0, N):
    line2 = input()
    aryLine2 = line2.split()
    X = float(aryLine2[0])
    Y = float(aryLine2[1])
    if X*X + Y*Y <= D*D:
        ans = ans + 1

print(ans)

Measured memory_bytes: 9204
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string O, E;
	std::cin >> O >> E;

	for (int i = 0; i < O.size(); ++i) {
		std::cout << O[i];
		if (i < E.size())
			std::cout << E[i];
	}
	std::cout << "\n";
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;

class MyClass
{
    public static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var name = Console.ReadLine();
        var count = 0;
        for (int _i = 0; _i < N; _i++)
        {
            var s = Console.ReadLine();
            var L = s.Length;
            for (int i = 0; i < L; i++)
            {
                if (s[i] == name[0])
                {
                    for (int j = i + 1; j < L; j++)
                    {
                        if (s[j] == name[1])
                        {
                            var b = true;
                            int d = j - i;
                            for (int k = 2; k < name.Length; k++)
                            {
                                if (i + k * d >= L || s[i + k * d] != name[k])
                                {
                                    b = false;
                                    break;
                                }
                            }
                            if (b)
                            {
                                count++;
                                goto LOOPEND;
                            }
                        }
                    }
                }
            }
        LOOPEND:
            ;
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 15912
from collections import deque


n, m = map(int, input().split())
p = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(m)]

graph = [[] for i in range(n)]
for a, b in info:
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

def dfs(s):
    res = 0
    set_ = set()
    q = deque([s])
    visited[s] = True
    set_.add(s)
    while q:
        v = q.pop()
        for nxt_v in graph[v]:
            if visited[nxt_v]:
                continue
            visited[nxt_v] = True
            q.append(nxt_v)
            set_.add(nxt_v)
    set_2 = set()
    for i in set_:
        set_2.add(p[i] - 1)
    for i in set_:
        if i in set_2:
            res += 1
    return res

ans = 0
visited = [False] * n
for i in range(n):
    if visited[i]:
        continue
    else:
        ans += dfs(i)
        
print(ans)

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

ll n,q;
vector<vector<ll>>V;
ll ans[200010];

void dfs(ll num,ll parent){
  for(auto k:V[num]){
    if(k==parent)continue;
    ans[k]+=ans[num];
    dfs(k,num);
  }
}


int main(){

  cin>>n>>q;
  V.resize(n);

  rep(i,0,n-1){
    ll a,b;cin>>a>>b;
    --a,--b;
    V[a].push_back(b);
    V[b].push_back(a);
  }

  rep(i,0,q){
    ll p,x;cin>>p>>x;
    --p;
    ans[p]+=x;
  }

  dfs(0,0);
  rep(i,0,n)cout<<ans[i]<<" ";



  return 0;
}


Measured memory_bytes: 24320
#include<bits/stdc++.h>
#define slowanddetermined ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

const long long mod=1e9+7;
long long inverseMod(long long x,long long mod);
long long nCr(long long n,long long r,long long mod){
    //when r is lesser and is greater
    long long res=1;
    if(r>n-r)r=n-r;
    long long div=1;
    for(long long  i=0;i<r;i++){
        res=(res*(n-i))%mod;
    }

    for(long long i=1;i<=r;i++){
        div=(div*i)%mod;
    }
    return (res*inverseMod(div,mod))%mod;
}


long long power(long long x,long long n,long long mod){
//(x^n)%mod
long long result=1;

    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

long long inverseMod(long long x,long long mod){

return power(x,mod-2,mod);
}


int main()
{
    slowanddetermined

    int n,p;
    cin>>n>>p;
    string s;
    cin>>s;
    long long ans=0;
    if(p==2){
        for(int i=0;i<n;i++){
            if((s[i]-'0')%2==0)ans+=i+1;
        }
    }
    else if(p==5){
        for(int i=0;i<n;i++){
            if(((s[i]-'0')%5)==0)ans+=i+1;
        }
    }
    else{

        map<long long ,long long >mp;
        mp[0]=1;
       long long a;
        long long last=0;
        long long  cur=0;
        long long val;
        for(int i=0;i<n;i++){
            cur*=10;cur+=s[i]-'0';cur%=p;
            val=power(10,n-i-1,p)*cur;
            val%=p;
            mp[val]++;
        }
        for(auto i:mp){
            ans+=(i.second*(i.second-1))/2;
        }
        //ans+=mp[0];



    }
    cout<<ans;





    return 0;

}


Measured memory_bytes: 1044
n = gets.chomp.to_i
hash = Hash.new(0)
sentou = Hash.new(0)
count = 0
n.times do |i|
    s = gets.chomp
    if s[0] == "M" || s[0] == "A" || s[0] == "R" || s[0] == "C" || s[0] == "H"
    hash[s] += 1
    sentou[s[0]] += 1
    count += 1
    end
end
arr = []
hash.each do |i|
    arr << i[0][0]
end
arr = arr.uniq.sort
ans = 0
ar = []
arr.permutation (3) do |i|
    ar << i.sort
    ans += 1
end
ar =  ar.uniq
all = 0
ar.each do |j|
    count = 1
    j.each do |k|
        count *= sentou[k]
    end
    all += count
end
puts all

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

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main() {
  int N;
  cin >> N;
  
  cout << N*N << endl;

}


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

using namespace std;

typedef long long ll;

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

    for (int i = 0; i < n; ) {
        ll tmp = 0;
        int j = i;
        while (j < n && a[j] > 0) {
            tmp += a[j];
            j++;
        }

        ans += tmp / 2;
        i = j+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define sz size()
#define endl "\n"
#define print(X) cout << (X) << "\n"
// // #define input(X) getline(cin,X)
static const ll  INF = 1e9+7;
static const ll INFL = 1e18+7;
ll n,m,l, p;
string s,t;
ll d[200010],e[200010],dp[1001][1001];
char field[202][202];

int main(){
  cin >> n;
  ll ans = 0;
  int count = 0;
  ll mn = INF;
  rep(i,0,n){
    cin >> d[i];
    if(d[i] < 0)count++;
    mn = min(mn, abs(d[i]));
    ans += abs(d[i]);
  }
  if(count % 2)print(ans-2*mn);
  else print(ans);
  return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define REP(i,n) for(int i=0;i<n;++i)
#define INF (2<<30)
using namespace std;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  double x, sum;
  string u;
  int n;
  cin >> n;
  REP(i, n) {
    cin >> x >> u;
    if(u.compare("JPY") == 0) {
      sum += x;
    } else {
      sum += x * 380000;
    }
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	int dp[10][10] = {0};
	for(register int i = 1; i <= n; ++i) {
		if(!(i % 10)) continue;
		int high = i;
		while(high >= 10) high /= 10;
		dp[high][i % 10]++;
	}
	long long ans = 0;
	for(register int i = 1; i <= 9; ++i)
		for(register int j = 1; j <= 9; ++j)
			ans += 1ll * dp[i][j] * dp[j][i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <cmath>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
 
using namespace std;
 
int main() {
    string s, result;
    //vector<char> vec;
    cin >> s;
    for (unsigned int i = 0; i < s.length(); i++)
    {
        if (s[i] == 'B' && !result.empty())
        {
            result.pop_back();
        }
        else if (s[i] != 'B')
        {
            result.push_back(s[i]);
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
import sys


class Dice(object):
    def __init__(self, faces: list):
        self.list_sn = [faces[5], faces[4], faces[0], faces[1]]  # 6,5,1,2
        self.list_we = [faces[5], faces[2], faces[0], faces[3]]  # 6,5,1,2

    def _roll_positive(self, list_a: list, list_b: list) -> list:
        list_a = list_a[1:] + list_a[0:1]  # Roll one unit in the positive direction.
        list_b[0] = list_a[0]  # Change the bottom face.
        list_b[2] = list_a[2]  # Change the top face.
        return [list_a, list_b]

    def _roll_negative(self, list_a: list, list_b: list) -> list:
        list_a = list_a[3:] + list_a[0:3]
        list_b[0] = list_a[0]  # Change the bottom face.
        list_b[2] = list_a[2]  # Change the top face.
        return [list_a, list_b]

    def roll(self, direction: str):
        if "N" == direction:
            self.list_sn, self.list_we = self._roll_positive(self.list_sn, self.list_we)
        elif "S" == direction:
            self.list_sn, self.list_we = self._roll_negative(self.list_sn, self.list_we)
        elif "E" == direction:
            self.list_we, self.list_sn = self._roll_positive(self.list_we, self.list_sn)
        else:
            self.list_we, self.list_sn = self._roll_negative(self.list_we, self.list_sn)


if __name__ == "__main__":
    faces_dice_a = list(map(lambda x: int(x), input().split()))
    faces_dice_b = list(map(lambda x: int(x), input().split()))
    Dice_a = Dice(faces_dice_a)
    Dice_b = Dice(faces_dice_b)

    for command in "NNNNWNNNWNNNENNNENNNWNNN":  # Check all patterns.
        Dice_b.roll(command)
        if Dice_a.list_sn == Dice_b.list_sn and Dice_a.list_we == Dice_b.list_we:
            print("Yes")
            sys.exit()    
    print("No")



Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
vector<int> a(100001),b(100001);

int main(){
  int n;
  cin >> n;
  vector<int> A(n/2),B(n/2);
  for(int i=0;i<n/2;i++){cin >> A[i] >> B[i];}
  for(int i=0;i<=100000;i++){a[i]=0; b[i]=0;}
  for(int i=0;i<n/2;i++){a[A[i]]++; b[B[i]]++;}
  vector<pair<int,int>> q(100000),w(100000);
  for(int i=1;i<100000;i++){q[i]=make_pair(a[i],i); w[i]=make_pair(b[i],i);}
  sort(q.begin(),q.end()); sort(w.begin(),w.end());
  reverse(q.begin(),q.end()); reverse(w.begin(),w.end());
  int ans=0;
  if(q[0].second!=w[0].second){ans=n-(q[0].first+w[0].first);}
  else{
    int m=n-(q[1].first+w[0].first);
    int l=n-(q[0].first+w[1].first);
    ans=min(m,l);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2944
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<complex>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
#define EPS (long double) 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> a(n);
	REP(i, n) cin>>a[i];
	vector<int> dp(n + 1);
	dp[0] = -1;
	FOR(i, 1, n + 1) {
		dp[i] = INF;
	}
	FOR(i, 1, n + 1) {
		vector<int>::iterator ite = lower_bound(ALL(dp), a[i - 1]);
		if(ite != a.end()) *ite = a[i - 1];
	}
	int res = 0;
	REP(i, n + 1) {
		if(dp[i] != INF) res = i;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 3572
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
const int MR=1e6+10;

bool check(char* s,int b,int len){
	for(int i=0;i<b;i++){
		if(i+b>=len) return false;
		if(s[i]!=s[i+b]) return false;
	}
	return true;
}

int main(){
	char s[205];
	cin.getline(s,205);
	int len=strlen(s);
	len--;
	for(int b=len/2;b>=1;b--){
		if(check(s,b,len)){
			printf("%d\n",2*b);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int a,b;
  int s;
  scanf("%d %d",&a,&b);
  s=a*b;
  
  if(s%2==0){
    printf("Even\n");
  }
  else{
    printf("Odd\n");
  }
  
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    deque<int> deq;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(i%2 == (n-1)%2) deq.push_front(a);
        else deq.push_back(a);
    }
    for(int i=0; i<n; i++){
        if(i == n-1) cout << deq.at(i) << endl;
        else cout << deq.at(i) << " ";
    }
    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	ll n;
	cin>>n;
	for(int tt=0;tt<n;tt++){
		ll f[14] = {};
		for(int i=0;i<14;i++){
			f[i] = -1;	
		}
		for(int j=0;j<6;j++){
			ll t;
			cin>>t;
			f[t] = 1;
		}
		int  l = 6,r = 8;
		int t = 1;
		if(f[1] == f[13] ) {
			if(f[1]==-1){
				cout<<"yes"<<endl;
			}else{
				cout<<"no"<<endl;
			}
			continue;
		}
		int tu[2] ;
		if(f[1] == 1){
			tu[0] = -1;
			tu[1] = 1;
		}else{
			tu[0] = 1;
			tu[1] = -1;
		}
		int se = 0,go = 0;
		while(se!=6 && go!= 6){
			if(t==1){
				if(tu[0] == -1 ){
					if(l!=0 && f[l] ==1){
						l--;

						se++;
					}else{
						if(r!=14&&f[r] == 1){
						    	r++;
							se++;
						}
					}
				}else{
				    	if(r!=14 && f[r] == 1){
						r++;
						se++;
					}else{
						if(l!=0&&f[l] == 1){
							l--;
							se++;
						}
					}

				}

			}else{

				if(tu[1] == -1 ){
					if(l!=0 && f[l] ==-1){
						l--;
						go++;

					}else{
						if(r!=14&&f[r] == -1){
						    	r++;
							go++;
						}
					}
				}else{
				    	if(r!=14 && f[r] == -1){
						r++;
						go++;
					}else{
						if(l!=0&&f[l] == -1){
							l--;
							go++;
						}
					}

				}
			}
			t*=-1;
		}
		
		if(se==6){

			cout<<"yes"<<endl;
		}else{
			cout<<"no"<<endl;
		}

		
		
	
	}


	return 0;
}



Measured memory_bytes: 3104
n,m = map(int,input().split())
a = list(map(int,input().split()))


total = 0
for num in a:
    total += num

pjn =  1/(4*m)
x = total * pjn
count = 0
for each_n in a:
    if each_n < x:
        continue;
    else:
        count += 1
if count >= m:
    print("Yes")
else:
    print("No")


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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    string S; cin>>S;
    string dm="dream",dmer="dreamer",es="erase",eser="eraser";

    reverse(ToEnd(S));
    reverse(ToEnd(dm));
    reverse(ToEnd(dmer));
    reverse(ToEnd(es));
    reverse(ToEnd(eser));

    while(S.find(eser)!=string::npos){
        int i=S.find(eser);
        S.erase(i,eser.size());
    }
    while(S.find(es)!=string::npos){
        int i=S.find(es);
        S.erase(i,es.size());
    }
    while(S.find(dmer)!=string::npos){
        int i=S.find(dmer);
        S.erase(i,dmer.size());
    }
    while(S.find(dm)!=string::npos){
        int i=S.find(dm);
        S.erase(i,dm.size());
    }

    string ans="YES";
    if(S.size()) ans="NO";
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define r(i, n) for (int i=0;i<n;i++)
using namespace std;
int main() {
  int n;
  cin >> n;
  double a[n];
  double b=0;
  r(i, n) {
    cin >> a[i];
    b=b+1/a[i];
  }
  cout << 1/b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
     
using namespace std;
     
int main()
{
    int K,A,B;
    cin >> K >> A >>B;
    if (A/K != B/K || A%K == 0)
    {
        cout << "OK";
    }else
    {
        cout << "NG";
    }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin >> k;
    if(k%2 == 0 || k%5 == 0)
        cout << "-1" << endl;
    else
    {
        int cnt = -1, cur = 0;
        vector<bool>visit(k);
        for(int i = 1;; i++)
        {
            cur = (cur*10 + 7)%k;
            if(visit[cur])
                break;
            visit[cur] = true;
            if(cur == 0)
            {
                cnt = i;
                break;
            }
        }
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3644
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private String S;

    public Main() {
	S = scan.next();
	scan.close();
    }

    public final void answer() {
	long count = IntStream.range(0, S.length())
	    .filter(i -> S.charAt(i) == '1')
	    .count();
	System.out.println(count);
    }
}


Measured memory_bytes: 27092
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	char a[50]={'H'};
	int b[50];
	scanf("%s",&a);
	int cnt=0,ans=0;
	int m=strlen(a);
	for(int i=0;i<m+1;i++){
		if(a[i]=='A'||a[i]=='G'||a[i]=='C'||a[i]=='T'){
			cnt++;
		}
		else{
			b[ans]=cnt;
			cnt=0;
			ans++;
		}
	}

	if(ans==0){
		printf("%d",cnt);
	}
	else{
	sort(b,b+ans);
	printf("%d",b[ans-1]);		
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n, a, b;
    cin >> n >> a >> b;
    
    auto digitsum = [](int a) {
        int n = 0;
        while (a > 0) {
            n += (a % 10);
            a /= 10;
        }
        return n;
    };
    
    int ans = 0;
    repeat_from_to (i, 1, n) {
        int n = digitsum(i);
        if (a <= n and n <= b) {
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }

signed main(void)
{
  int num;
  int a, b, c, d; cin >> a >> b >> c >> d;

  if (c > d) {
    swap(c, d);
  }

  num = b - max(a - 1, 0ll);
  if (c == d) {
    num -= b / c;
    num += max(a - 1, 0ll) / c;
  } else if (lcm(c, d) == d) {
    num -= b / c;
    num += max(a - 1, 0ll) / c;
  } else {
    num -= b / c + b / d - b / lcm(c, d);
    num += max(a - 1, 0ll) / c + max(a - 1, 0ll) / d - max(a - 1, 0ll) / lcm(c, d);
  }

  cout << num << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();
		String answer = a * b + " " + (2 * a + 2 * b);
		System.out.println(answer);
	}
}

Measured memory_bytes: 17360
n,q = map(int,input().split())
s = input()
lr = [0] * (n+1)

for i in range(n):
    lr[i+1] = lr[i]+(1 if s[i:i+2] == "AC" else 0)

for i in range(q):
    st,fn = map(int,input().split())
    print(lr[fn-1] - lr[st-1])

Measured memory_bytes: 77416
#!/usr/bin/env python3
import sys, math, fractions, itertools

MOD = 1000000007  # type: int


def solve(S: str):
    dp = [[0 for _ in range(4)] for _ in range(len(S)+1)]
    for i in reversed(range(len(S)+1)):
        for j in reversed(range(4)):
            if i == len(S) and j == 3:
                dp[i][j] = 1
            if j < 3 and i == len(S):
                dp[i][j] = 0
            if i < len(S):
                if j == 3:
                    if S[i] == '?':
                        m = 3
                    else:
                        m = 1
                    dp[i][3] = m * dp[i+1][3]
                if j < 3:
                    if S[i] == '?':
                        m1 = 3
                    else:
                        m1 = 1
                    if S[i] == '?' or S[i] == list('ABC')[j]:
                        m2 = 1
                    else:
                        m2 = 0
                    dp[i][j] = m1 * dp[i+1][j] + m2 * dp[i+1][j+1]
            dp[i][j] %= MOD
    print(dp[0][0])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 29692
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int k = saori.saori_hayami();
		int[] h = new int[n];
		for(int i = 0;i < n;i++){
			h[i] = saori.saori_hayami();
		}
		Arrays.sort(h);
		int ans = MAX;
		for(int i = 0;i <= n-k;i++){
			ans = Math.min(ans, Math.abs(h[i]-h[i+k-1]));
		}
		System.out.println(ans);
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 23044
/*
  AUTHOR:SOURABH
  CREATED:10:01:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

ll modex(ll x,ll y)
{
    x=x%mod;
    ll r=1;
    while(y>0)
    {
        if(y%2==1)
            r=(r*x)%mod;
        y/=2;
        x=(x*x)%mod;
    }
    return r;
}

ll mm(ll x,ll y)
{
    x=(x+mod)%mod;
    y=(y+mod)%mod;
    return (x*y)%mod;
}

ll fact[100001];
ll inv_fact[100001];

void build(void)
{
    fact[0]=1;
    ll i;
    fs(i,1,100001)
    {
        fact[i]=mm(fact[i-1],i);
    }
    inv_fact[100000]=modex(fact[100000],mod-2);
    fr(i,99999)
    {
        inv_fact[i]=mm(inv_fact[i+1],i+1);
    }
}

ll C(ll n,ll r)
{
    if(n<r)
        return 0;
    ll res;
    res=fact[n];
    res=mm(res,inv_fact[n-r]);
    return mm(res,inv_fact[r]);
}

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

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll n,k,i,sum=0,ans=0;
    cin>>n>>k;
    vll a(n);
    fn(i,n)
    cin>>a[i];
    sort(a.begin(),a.end());
    build();
    fn(i,n-k+1)
    {
        sum=(sum+mm(a[i],C(n-i-1,k-1)))%mod;
    }
    sum=mm(sum,mod-1);
    for(i=n-1;i>=k-1;i--)
    {
        ans=(ans+mm(a[i],C(i,k-1)))%mod;
    }
    ans=(sum+ans)%mod;
    cout<<ans;
    return 0;
}










Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  for(Int i=0;i<n;i++) assert(a[i]>0);

  vector<Int> dp1(n,0),dp2(n,0);
  {
    vector<Int> b(a);
    stack<Int> st;
    for(Int i=0;i<n;i++){
      if(i>0) dp1[i]=dp1[i-1];
      dp1[i]++;
      a[i]*=-2;
      if(i==0){
        st.emplace(i);
        continue;
      }
      while(a[i-1]>a[i]){
        a[i-1]*=4;
        Int j=st.top();st.pop();
        if(j!=i-1) a[j]*=4;        
        dp1[i]+=(i-j)*2;
        if(j==0||a[j-1]<=a[j]*4) st.emplace(j);
      }
      if(a[i-1]<=a[i]*4) st.emplace(i);
    }
    a=b;
  }
  
  {
    vector<Int> b(a);
    stack<Int> st;
    for(Int i=n-1;i>=0;i--){
      if(i<n-1) dp2[i]=dp2[i+1];
      if(i==n-1){
        st.emplace(i);
        continue;
      }      
      while(a[i+1]<a[i]){
        a[i+1]*=4;
        Int j=st.top();st.pop();
        if(j!=i+1) a[j]*=4;        
        dp2[i]+=(j-i)*2;
        if(j==n-1||a[j]*4<=a[j+1]) st.emplace(j);
      }
      if(a[i]*4<=a[i+1]) st.emplace(i);
    }
    a=b;
  }
  //for(Int i=0;i<n;i++) cout<<dp1[i]<<" "<<dp2[i]<<endl;
 
  Int ans=min(dp1[n-1],dp2[0]);
  for(Int i=0;i+1<n;i++) chmin(ans,dp1[i]+dp2[i+1]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6528
package main
import(
  "fmt"
  "bufio"
  "os"
  "strconv"
)
var sc=bufio.NewScanner(os.Stdin)
func nextInt() int64{
  sc.Scan()
  i, e :=strconv.ParseInt(sc.Text(), 10, 64)
  if e!=nil{
    panic(e)
  }
  return i
}
func min (a *int64, b int64) bool{
  if *a>b{
    *a=b
    return true
  }
  return false
}
func abs(a int64) int64{
  if a<0{
    return a*-1
  }else{
    return a
  }
}
func main(){
  var i int64
  dp:=make([]int64, 100010)
  sc.Split(bufio.ScanWords)
  n:=nextInt()
  a:=make([]int64, 100010)
  for i=0;i<n;i++{
    a[i]=nextInt()
  }
  for i=0;i<100010;i++{
    dp[i]=1000000001
  }
  dp[0]=0
  for i=0;i<n;i++{
    min(&dp[i+1], dp[i]+abs(a[i]-a[i+1]))
    min(&dp[i+2], dp[i]+abs(a[i]-a[i+2]))

  }
  fmt.Println(dp[n-1])
}


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

using namespace std;

int main(){
  int X;
  cin >> X;
  
  vector<bool> prime(1000000, true);
  
  for(int i = 2; i < 1000000; i++){
    if(prime[i]){
      for(int j = 2; i * j < 1000000; j++){
        prime[i * j] = false;
      }
    }
  }
  
  int p = 0;
  for(int i = X;;i++){
    if(prime[i]){
      p = i;
      break;
    }
  }
  
  cout << p << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll a[200001];

int main()
{
    fast_io;
    ll n, i, x = 0;
    cin >> n;
    for (i = 1; i <= n; i++) cin >> a[i], x ^= a[i];
    for (i = 1; i <= n; i++) cout << (x ^ a[i]) << ' ';
    return 0;
}

Measured memory_bytes: 5080
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
#define all(v) (v).begin(),(v).end()
typedef pair<ll,ll> P;
#define fi first
#define se second
set<string> c;
map<ll,ll> mp;
const ll inf=100000000000000000;
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}

int main(){
int n;
cin>>n;
multiset<int,greater<int>> ans;
for(int i=0;i<n;i++){
    int a;
    cin>>a;
    auto ite=ans.upper_bound(a);
    if(ite!=ans.end()) ans.erase(ite);
    ans.insert(a);
}
cout<<ans.size()<<endl;
}

Measured memory_bytes: 4992
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n;
        double ave=0,sum=0,sum2=0;
        double[] data = new double[1001];
        double[] data2 = new double[1001];
        
        
        while(true) {
            n = sc.nextInt();
            if(n==0)break;
            for(int i = 0;i<n;i++) {
            	data[i]=sc.nextInt();
            	sum +=data[i];
            }
            ave = sum/n;
        	
            for(int i = 0;i<n;i++) {
            	data2[i]=Math.pow(data[i]-ave, 2);
            	sum2 +=data2[i];
            	}
            double ans = sum2/n;
            System.out.printf("%f\n", Math.sqrt(ans));
            
            
            
            sum =0 ;
            sum2=0;
        }
        
        
        
        
        sc.close();
	}


}



Measured memory_bytes: 31276
n = int(input())
d = dict()
a = [int(i) for i in input().split()]
for i in a:
    if i not in d.keys():
        d[i] = 0
    d[i] += 1
m = int(input())
for i in [int(j) for j in input().split()]:
    if i not in d.keys():
        print("NO")
        break
    d[i] -= 1
    if d[i] < 0:
        print("NO")
        break
else:
    print("YES")

Measured memory_bytes: 46176
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    import fractions
    a,b,c,d=map(int, input().split())
    e=c*d//fractions.gcd(c,d)
    ckosu=b//c-(a-1)//c
    dkosu=b//d-(a-1)//d
    ekosu=b//e-(a-1)//e
    print(b-a+1-(ckosu+dkosu-ekosu))
resolve()

Measured memory_bytes: 5048
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] data = new int[N];
		for (int i = 0; i < N; i++) {
			data[i] = sc.nextInt();
		}
		Arrays.sort(data);
		int c = 0;
		int cnt = 0;
		int ans = 0;
		for (int i = 0; i < N; i++) {
			if (data[i] != c) {
				if (cnt < c) {
					ans += cnt;
				} else {
					ans += (cnt - c);
				}
				c = data[i];
				cnt = 0;
			}
			cnt++;
			if (i == (N - 1)) {
				if (cnt < c) {
					ans += cnt;
				} else {
					ans += (cnt - c);
				}
			} 

		}
		System.out.println(ans);
		sc.close();
	}

}

Measured memory_bytes: 48932
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
#define LL long long
const int N = 2e5+55;
char s[N];
int main()
{
	scanf("%s",s+1);
	int n=(int)strlen(s+1);
	if(s[n]=='1'||s[1]=='0'||s[n-1]=='0'){
		printf("-1\n");
		return 0;
	}
	int now = 2;
	while(now<=n-now){
		if(s[now]!=s[n-now]) {
			printf("-1\n");
			return 0;
		}
		now++;
	}
	int root=2,num=1;
	now=2;
	printf("2 1\n");
	while(now<=n-now){
		if(s[now]=='1'){
			printf("%d %d\n",++now,root);
			root=now;
		}else{
			printf("%d %d\n",++now,root);
		}
		num++;
	}
	for(int i=num+1;i<n;i++){
		printf("%d %d\n",root,++now);
	}

}


Measured memory_bytes: 1536