akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

typedef long long ll;

using namespace std;

ll powmod(ll x, ll k, ll m)
{
    ll ret = 1;
    for (ll i = 0; i < k; i++)
    {
        ret = (ret * x) % m;
    }
    return ret;
}

int main(void)
{
    ll N, X, M;
    cin >> N >> X >> M;

    ll A = X;
    ll ans = X;
    ll array[M];
    for (int i = 1; i < N; i++)
    {
        A = powmod(A, 2, M);
        for (int j = 1; j < i; j++)
        {
            if (array[j] == A)
            {
                ll sum = 0;
                for (int k = j; k < i; k++)
                {
                    sum = sum + array[k];
                }
                ans = ans + (sum * ll((N - i) / (i - j)));
                for (int k = 0; k < ((N - i) % (i - j)); k++)
                {
                    ans = ans + array[j + k];
                }
                A = 0;
                break;
            }
            else
            {
                array[i] = A;
            }
        }
        if (A == 0)
        {
            break;
        }
        ans = ans + A;
    }

    cout << ans << "\n";
}


Measured memory_bytes: 3480
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
#define REP(i,a,n) for(register int i(a);i<=(n);++i)
#define FEC(i,x,y) for(register int i=head[x],y=g[i].to;i;i=g[i].ne,y=g[i].to)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define lc t[o].ch[0]
#define rc t[o].ch[1]
const int SZ=(1<<21)+1;char ibuf[SZ],*iS,*iT,obuf[SZ+128],*oS=obuf,*oT=obuf+SZ-1;
#ifdef ONLINE_JUDGE
#define gc() (iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,SZ,stdin),(iS==iT?EOF:*iS++)):*iS++)
#else
#define gc() getchar()
#endif
template<typename I>inline void read(I&x){char c=gc();int f=0;for(;c<'0'||c>'9';c=gc())c=='-'?f=1:0;for(x=0;c>='0'&&c<='9';c=gc())x=(x<<1)+(x<<3)+(c&15);f?x=-x:0;}
inline void flush(){fwrite(obuf,1,oS-obuf,stdout);oS=obuf;}
#define printf(...) (oS>oT&&(flush(),1),oS+=sprintf(oS,__VA_ARGS__))
template<typename A,typename B>inline char SMAX(A&a,const B&b){return a<b?a=b,1:0;}
template<typename A,typename B>inline char SMIN(A&a,const B&b){return a>b?a=b,1:0;}
typedef long long ll;typedef unsigned long long ull;typedef std::pair<int,int>pii;

const int N=2e5+7;
int n,a[N],ans,tot,RT;

struct Node{int v,p,ch[2],s,c;}t[N];
void maintain(int o){t[o].s=t[o].c+t[lc].s+t[rc].s;}
void rotate(int &o,int d){int k=t[o].ch[d^1];t[o].ch[d^1]=t[k].ch[d];t[k].ch[d]=o;maintain(o);maintain(k);o=k;}
void Insert(int &o,int x){
    if(!o){o=++tot;t[tot].v=x;t[tot].p=rand();t[tot].s=t[tot].c=1;}else if(t[o].v==x)++t[o].c;
    else{bool d=x>t[o].v;Insert(t[o].ch[d],x);if(t[t[o].ch[d]].p<t[o].p)rotate(o,d^1);}maintain(o);
}
void Delete(int &o,int x){
    if(!o)return;if(t[o].v!=x)Delete(t[o].ch[x>t[o].v],x);else if(t[o].c>1)--t[o].c;
    else if(!lc||!rc)o=lc+rc;else{int d=t[lc].p<t[rc].p;rotate(o,d);Delete(t[o].ch[d],x);}if(o)maintain(o);
}
int Find(int o,int x){while(o){if(x==t[o].v)return t[o].c;if(x>t[o].v)o=rc;else o=lc;}return 0;}

multiset<int>s;
int main(){
	read(n);REP(i,1,n)read(a[i]),Insert(RT,a[i]);
	int hkk=1073741824;
	while(hkk>1){
		REP(i,1,n)if(Find(RT,a[i])&&(hkk-a[i]!=a[i]?Find(RT,hkk-a[i]):(Find(RT,a[i])>1)))Delete(RT,a[i]),Delete(RT,hkk-a[i]),++ans;
		hkk>>=1;
	}printf("%d\n",ans);return flush(),0;
}

Measured memory_bytes: 6400
import collections
N = int(input())
S = input()
c = collections.Counter([s for s in S])
RGB = c.most_common()
if len(RGB) != 3:
  result = 0
else:
  rgb = set(["R", "G", "B"])
  result = RGB[0][1] * RGB[1][1] * RGB[2][1]
  for i in range(1, N//2+1):
    for j in range(N-i*2):
      if set([S[j], S[j+i], S[j+i*2]]) == rgb:
        result -= 1
print(result)

Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    string a = "AAA";
    string b = "BBB";
    if(s == a || s == b){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  vector<int> data(26);
  for(int i = 0; i < S.size(); i++) {
    data.at(S.at(i) - 'a')++;
  }
  for(int i = 0; i < 26; i++) {
    if(data.at(i) == 0) {
      cout <<(char) (i + 'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = 0;
		for (int i = 1; i <= n; i++) {
			a += i;
		}
		System.out.println(a);
	}
}


Measured memory_bytes: 9428
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a[64]={},b[64]={},c=0;
    cin>>n;
    for(int i=0; i<n; i++){
      cin>>a[i];
      b[i]=a[i];  
    }
    sort(b,b+n);
    for(int i=0; i<n; i++){
     if(a[i]!=b[i]){
       c++;
     }else{
     }
    }
    if(c>=3){
      cout<<"NO"<<'\n';
    }else{
      cout<<"YES"<<'\n';
    }
    return(0);
}

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

int main() {
	int cnt=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s.substr(i,1)=="1")cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}



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

int main() {
  ll a;
  double b;
  cin >> a >> b;
  ll ib = b*100+0.5;//表示桁数範囲の整数として代入。暗黙の変換に対応して切り捨てが起こってもいいように0.5足している

  a *= ib;
  a /= 100;//小数第2位まで表示なので、100倍して計算後に100で割る
  printf("%lld\n",a);
}


Measured memory_bytes: 3772
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<random>
#include<unordered_set>

using namespace std;

/*

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

tree<pair<long long, long long>, null_type, less<pair<long long, long long>>, rb_tree_tag, tree_order_statistics_node_update> st;

*/
/*

st.find_by_order();
st.order_of_key();

*/

#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#define pb push_back
#define ld long double
#define int long long

mt19937 rnd(51);

const int N = 1e7 + 10;
vector<int> cnt(N);

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    for (int i = 1; i < N; i++){
        for (int j = i; j < N; j += i){
            cnt[j]++;
        }
    }
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++){
        ans += i * cnt[i];
    }
    cout << ans << endl;
    return 0;
}


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

int asc(const void *a, const void *b)
{
	return *(int*)a - *(int *)b;
}
int	main(void)
{
	long long int N;
	scanf("%lld",&N);
	long long int index =0;
	long long int X[N];
	long long int p = 0;
	long long int q = 0;
	if(N ==1)
	{
		printf("0\n");
		return(0);
	}
	long long int sum = 0;
	while (index < N)
	{
		scanf("%lld", &X[index]);
		sum = sum + X[index];
		index++;
	}
	p = sum/N;
	q = (sum/N) + 1;
	long long int sump = 0;
	long long int sumq = 0;
	index =0;
	while (index <N)
	{
		sump = sump + ((X[index]-p)*(X[index]-p));
		sumq = sumq + ((X[index]-q)*(X[index]-q));
		index++;
	}
	if (sump > sumq)
		printf("%lld\n", sumq);
	else
		printf("%lld\n", sump);
	return(0);
}


Measured memory_bytes: 128
#include<vector>
#include<set>
#include<algorithm>
#include<queue>

class BipartiteGraph {
public:
    BipartiteGraph(const int x, const int y) :size_x_(x), size_y_(y), edge_(x + y) {}

    void add_xy(const int vx, const int vy) {edge_[vx].insert(size_x_ + vy);}

    int matching() const {
        std::vector<int> match_to(edge_.size(), -1);
        int count = 0;
        for(int i = 0; i < size_x_; ++i) {
            std::vector<bool> visited(edge_.size(), false);
            if(FordFullkerson(i, match_to, visited)) ++count;
        }
        return count;
    }

private:
    bool FordFullkerson(int from, std::vector<int>& match_to, std::vector<bool>& visited) const {
        if(from == -1) return true;
        if(visited[from]) return false;
        visited[from] = true;
        for(const auto& to: edge_[from]) {
            if(!FordFullkerson(match_to[to], match_to, visited)) continue;
            match_to[from] = to;
            match_to[to] = from;
            return true;
        }
        return false;
    }

    std::vector<std::set<int>> edge_;
    int size_x_, size_y_;
};

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

#include<iostream>
using namespace std;

int main() {
    int x, y, e;
    cin >> x >> y >> e;
    BipartiteGraph g(x, y);
    for(int i = 0; i < e; ++i) {
        int vx, vy;
        cin >> vx >> vy;
        g.add_xy(vx, vy);
    }
    cout << g.matching() << endl;
}

Measured memory_bytes: 1672
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *
from heapq import *
import copy


#int(input())
#map(int,input().split())
N=int(input())
S=Counter([input() for i in range(N)]).most_common()
S=[i[0] for i in S if i[1]==S[0][1]]
for i in sorted(S):
    print(i)


Measured memory_bytes: 45252
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, (int)vec.size() - 1)std::cout << vec[i] << " ";
	if(!vec.empty())std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int n,a[200010];
int main(){
	std::cin>>n;
	int cnt=1;
	rep(i,n){
		std::cin>>a[i];
		if(a[i]==cnt)cnt++;
	}
	if(cnt==1)puts("-1");
	else std::cout<<n-cnt+1<<std::endl;
	return 0;
}


Measured memory_bytes: 4400
#include <stdio.h>

int n, dp[40];

int main(void){
    int x;
    dp[0] = 1;
    while(1){
        scanf("%d", &n);
        if(n == 0) break;
        for(x = 1; x <= n; x++){
            dp[x] = 0;
        }
        for(x = 1; x <= n; x++){
            if(x >= 1) dp[x] += dp[x-1];
            if(x >= 2) dp[x] += dp[x-2];
            if(x >= 3) dp[x] += dp[x-3];
        }
        printf("%d\n", (dp[n]-1)/3650+1);
    }
    return 0;
}

Measured memory_bytes: 600
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    List<String> w = new ArrayList<String>();
    w.add("Sunny");
    w.add("Cloudy");
    w.add("Rainy");
    w.add("Sunny");
    System.out.println(w.get(w.indexOf(s)+1));
  }
}


Measured memory_bytes: 35440
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long q = long.Parse(input[0]);
		long h = long.Parse(input[1]);
    long s = long.Parse(input[2]);
		long d = long.Parse(input[3]);
		long n = long.Parse(Console.ReadLine());
    long answer = 0;
    long memo = 0;

    long memoQ = q*8;
    long memoH = h*4;
    long memoS = s*2;
    n *= 4;

    if(d > memoS) d = memoS;
    if(d > memoH) d = memoH;
    if(d > memoQ) d = memoQ;
    if(s > h*2) s = h*2;
    if(s > q*4) s = q*4;
    if(h > q*2) h = q*2;

    answer += n/8*d;
    n %= 8;
    //Console.WriteLine(answer);
    answer += n/4*s;
    n %= 4;
    //Console.WriteLine(answer);
    answer += n/2*h;
    n %= 2;
    //Console.WriteLine(answer);
    answer += n*q;
    
		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
ll h,w;
string s[12];
vector<pair<ll,ll> >p;
bool judge(ll alone){
    bool used[12];
    for(int i=0;i<w;i++)used[i]=0;
    for(int i=0;i<w;i++)if(used[i]==0){
        for(int j=0;j<i;j++)if(used[j]==0){
            bool ok=1;
            for(auto pp:p){
                ok&=(s[pp.first][i]==s[pp.second][j]);
                ok&=(s[pp.first][j]==s[pp.second][i]);
            }
            if(~alone)ok&=(s[alone][i]==s[alone][j]);
            if(ok){
                used[i]=used[j]=1;
                break;
            }
        }
    }
    ll pnt=-1;
    for(int i=0;i<w;i++){
        if(used[i]==0){
            if(~pnt)return 0;
            pnt=i;
        }
    }
    if(~pnt){
        for(auto pp:p){
            if(s[pp.first][pnt]!=s[pp.second][pnt])return 0;
        }
    }
    return 1;
}
bool used[12];
bool dfs(ll alone){
    ll cnt=0;
    for(int i=0;i<h;i++)cnt+=used[i];
    if(cnt+1>=h){
        return judge(alone);
    }
    ll fi=-1;
    for(int i=0;i<h;i++)if(used[i]==0){
        fi=i;
        break;
    }
    for(int i=fi+1;i<h;i++)if(used[i]==0){
        p.push_back(make_pair(fi,i));
        used[fi]=used[i]=1;
        if(dfs(alone)==1)return 1;
        used[fi]=used[i]=0;
        p.pop_back();
    }
    return 0;
}
int main(){
  cin>>h>>w;
  for(int i=0;i<h;i++)cin>>s[i];
  bool ans=0;
  if(h%2==0)ans=dfs(-1);
  else{
      for(int i=0;i<h;i++){
          for(int j=0;j<h;j++)used[j]=0;
          used[i]=1;
          ans|=dfs(i);
          if(ans==1)break;
      }
  }
  if(ans){
      cout<<"YES"<<endl;
  }
  else cout<<"NO"<<endl;
  return 0;
}



Measured memory_bytes: 256
// Problem : E - Simple String Queries
// Contest : AtCoder Beginner Contest 157
// URL : https://atcoder.jp/contests/abc157/tasks/abc157_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define DEBUG(...) cerr << #__VA_ARGS__ << ": ", debug(__VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator << (ostream &os, const vector<T> &v) {os << "["; for (int i=0; i<(int)v.size(); i++) {if (i) os << ", "; os << v[i];} return os << "]";}
void debug() {cerr << "\n";} template<typename T, typename... Args> void debug(T x, Args... args) {cerr << x << "; "; debug(args...);}

#define MAXN 500000

template<int SZ>
struct SegmentTree {
    int n, st[2*SZ];

    SegmentTree() {
        memset(st, 0, sizeof(st));
    }

    void init(int _n) {
        n = _n;
    }

    int query(int l, int r) {
        int ret = 0;
        for (l+=n, r+=n; l<r; l>>=1, r>>=1) {
            if (l&1) ret += st[l++];
            if (r&1) ret += st[--r];
        }
        return ret;
    }

    void update(int p, int val) {
        for (st[p+=n]=val; p>1; p>>=1)
            st[p>>1] = st[p] + st[p^1];
    }
};

SegmentTree<MAXN> st[26];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    int n, q;
    string s;
    cin >> n >> s >> q;
    
    for (int i=0; i<26; i++)
        st[i].init(n);
    for (int i=0; i<n; i++)
        st[s[i]-'a'].update(i, 1);
    
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            if (s[i] != c) {
                st[s[i]-'a'].update(i, 0);
                s[i] = c;
                st[s[i]-'a'].update(i, 1);
            }
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            
            int ret = 0;
            for (int i=0; i<26; i++)
                ret += (st[i].query(l, r) > 0);
            cout << ret << "\n";
        }
    }

    return 0;
}


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

import itertools


def count_paths(n, adj_list):
    res = 0
    for vs in itertools.permutations(range(n)):
        if vs[0] != 0:
            continue
        for i in range(n - 1):
            if vs[i] not in adj_list[vs[i + 1]]:
                break
        else:
            res += 1
    return res


def main():
    n, m = (int(x) for x in input().split())
    adj_list = [set() for _ in range(n)]
    for _ in range(m):
        a, b = (int(y) - 1 for y in input().split())
        adj_list[a].add(b)
        adj_list[b].add(a)
    print(count_paths(n, adj_list))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;
int vis[1000];

int main(){
	
	int n,x;
	cin>>x>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		vis[a[i]] = 1;
	}
	int z = x;
	while(vis[z]){
		z++;
	}
	int z1 = x;
	while(vis[z1]){
		z1--;
	}

	if(abs(x - z1)>abs(z-x)){
		cout<<z<<endl;
	}else{
		cout<<z1<<endl;
	}




	

	return 0;
}

Measured memory_bytes: 3608
// #include <iostream>
// #include <string>
// #include <math.h>
// #include <map>
// #include <vector>
// #include <tuple>
// #include <algorithm>
// #include <queue>
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;
int main(){
  int N;
  cin >> N;
  lli a[N];
  lli b[N-1];
  lli sum = 0;
  F(i, N){
    cin >> b[i];
  }
  if(N==2){
    sum = 2*b[0];
  }
  else{
    F(i, N-1){
      lli tmp = b[i];
      if(i == 0){
        if(b[i] < b[i+1]){
          a[i] = b[i];
          a[i+1] = b[i];
        }
        else{
          a[i] = b[i];
          a[i+1] = b[i+1];
        }
      }
      else if (i == N-2){
        a[i+1] = b[i];
      }
      else{
        if(b[i] < b[i+1]){
          a[i+1] = b[i];
        }
        else{
          a[i+1] = b[i+1];
        }
      }
    }
    F(i, N){
      sum += a[i];
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    int n;
    cin >> n;
    int a[n];
    int count=0;
    rep(i, n)
            cin >>
        a[i];
    sort(a, a + n, greater<int>());
    int old=0;
    rep(i, n)
    {
        if(a[i]!=old){
            count++;
            old = a[i];
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <utility>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

// 基本的な演算
namespace BasicMath {
    // 絶対値を求める
    static UInt Abs(const Int a);
    // 二つの値の最小値を求める関数
    static Int Min(const Int a, const Int b);
    // 絶対値を求める
    UInt Abs(const Int a) {
        return a > 0 ? a : -a;
    }
    // 二つの値の最小値を求める関数
    Int Min(const Int a, const Int b) {
        if (a <= b) {
            return a;
        } else {
            return b;
        }
    }
}
using namespace BasicMath;

int main(void) {
    Int n, a, b, c;
    cin >> n >> a >> b >> c;
    VI l(n);
    for (Int i = 0; i < n; ++i) {
        cin >> l[i];
    }
    Int size = pow(2, n);
    VI bamboo(size);
    VI cost(size);
    for (Int i = 0; i < size; ++i) {
        bamboo[i] = 0;
        cost[i] = 0;
        for (Int j = 0; j < n; ++j) {
            if ((i & (1 << j)) != 0) {
                bamboo[i] += l[j];
                cost[i]++;
            }
        }
    }
    VI da(size);
    VI db(size);
    VI dc(size);
    for (Int i = 1; i < size; ++i) {
        da[i] = Abs(bamboo[i] - a) + 10 * (cost[i] - 1);
        db[i] = Abs(bamboo[i] - b) + 10 * (cost[i] - 1);
        dc[i] = Abs(bamboo[i] - c) + 10 * (cost[i] - 1);
    }
    Int answer = INT_MAX;
    for (Int i = 1; i < size; ++i) {
        for (Int j = 1; j < size; ++j) {
            for (Int k = 1; k < size; ++k) {
                bool flag = true;
                for (Int x = 0; x < n; ++x) {
                    int xa = ((i & (1 << x)));
                    int xb = ((j & (1 << x)));
                    int xc = ((k & (1 << x)));
                    if (xa > 0 && xb > 0) {
                        flag = false;
                    }
                    if (xb > 0 && xc > 0) {
                        flag = false;
                    }
                    if (xc > 0 && xa > 0) {
                        flag = false;
                    }
                }
                if (flag) {
                    answer = Min(answer, da[i] + db[j] + dc[k]);
                }
            }
        }
    }
    cout << answer << endl;
    return 0;
}



Measured memory_bytes: 4116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,Y;cin >> N >> Y;
  Y/=1000;
  rep(x,N+1){
    rep(y,N-x+1){
      if(Y==x*10+y*5+N-x-y){
        cout << x SP y SP N-x-y << endl;
        return 0;
      }
    }
  }
  cout << -1 SP -1 SP -1 << endl;
  return 0;
}


Measured memory_bytes: 256
import math

n = int(raw_input())

for i in range(0, n):
	xa,ya,ra,xb,yb,rb = map(float,raw_input().split())
	
	distance = math.hypot(xa - xb, ya - yb)
	
	if distance + rb < ra:
		print 2
	elif distance + ra < rb:
		print -2
	elif ra + rb >= distance:
		print 1
	elif ra + rb < distance:
		print 0

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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP(A,B) make_pair(A,B)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<ll> a(4);
    rep(i,0,4) cin >> a[i];
    ll ans=-INFLL;
    // ans=(abs(a*c),min(abs(a*d),min(abs(b*c),abs(b*d))));
    // if(ans==abs(a*c)) {cout << a*c ENDL; return 0 }
    // if(ans==abs(a*d)) cout << a*d ENDL;
    // if(ans==abs(b*c)) cout << b*c ENDL;
    // if(ans==abs(b*d)) cout << b*d ENDL;

    rep(i,0,2){
        rep(j,2,4){
            if(ans<a[i]*a[j]) ans=a[i]*a[j];
            //ans=max(ans,a[i]*a[j]);
        }
    }
    
    cout << ans ENDL;
    
    return 0;
}

Measured memory_bytes: 5996
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, m = gi()
s = list(input())
ans = 0
for k in range(1, n):
	if s[k] == s[k - 1]:
		ans += 1
ss = [s[0]]
k = 1
l = [1, 0]
cur = 1
while k < n:
	while k < n and s[k] == s[k - 1]:
		k += 1
	if k == n:
		break;
	l[cur % 2] += 1
	cur += 1
	ss.append(s[k])
	k += 1
x, y = l
x *= 2
y *= 2
x -= 1
if ss[-1] == ss[0]:
	x -= 1
else:
	y -= 1
ans += min(min(x, y), m * 2)
print(ans)

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

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;
int l[2000];

int div2(int j, int n, int chk) {
	int ok = j, ng = n;
	while (ng - ok > 1) {
		int med = (ok + ng) / 2;
		if (l[med] < chk) ok = med;
		else ng = med;
	}
	return ok;
}
int main(void)
{
	int n;
	cin >> n;
	ll ans = 0;
	rep(i, n) cin >> l[i];
	sort(l, l + n);
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			// cout << l[i] << " " << l[j] << " " << div2(j, n, l[i] + l[j]) << endl;
			ans += div2(j, n, l[i] + l[j]) - j;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def d_we_like_agc(N, MOD=10**9 + 7):
    from itertools import product

    # dp[i][j][k][l]: Sの先頭i文字目を見ているとき、i-3, i-2, i-1番目の文字が
    # j, k, lだ(ACGT↔0123と対応させる)として、そのような文字列が何通り存在するか
    dp = [[[[0 for k in range(4)] for k in range(4)] for j in range(4)] for i in range(N + 1)]
    # 文字の制約にTは関係ないので、調べる文字列は 'TTT' + S だとしていい。
    dp[0][3][3][3] = 1

    for k in range(N):
        for c0, c1, c2, c3 in product(range(4), repeat=4):
            # 数字列c0c1c2c3をACGT文字列に変換したときに許されない文字列をはじく
            strings = ''.join(map(lambda x: 'ACGT'[x], (c0, c1, c2, c3)))
            for s in (strings[:i] + '*' + strings[i + 1:] for i in range(3)):
                if s in ('*AGC', '*GAC', '*ACG', 'A*GC', 'AG*C'):
                    break
            else:
                # 文字列 TTT...c0c1c2(TTTを除く長さk) の末尾にc3を加えることが許される
                # 次回は新しい文字列 TTT...c1c2c3(長さk+1)に対して同じことを行う
                dp[k + 1][c1][c2][c3] += dp[k][c0][c1][c2]
                dp[k + 1][c1][c2][c3] %= MOD
    return sum([dp[N][c0][c1][c2] for c0, c1, c2 in product(range(4), repeat=3)]) % MOD

N = int(input())
print(d_we_like_agc(N))

Measured memory_bytes: 3440
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String path = r.readLine();
		int p = 0;
		for (int j = 0; j < path.length(); j++)
			p |= (path.charAt(j) == 'S' ? 1 : path.charAt(j) == 'N' ? 2 : path.charAt(j) == 'W' ? 4 : 8);
		System.out.println(p == 3 || p == 12 || p == 15 ? "Yes" : "No");
	}

}

Measured memory_bytes: 7636
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <typeinfo>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;  // check the limits, dummy

typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
void print(const vector<T> v) {
  cout << "[ ";
  F0R(i, v.size()) { cout << v[i] << ' '; }
  cout << "]" << '\n';
}

int mod(int i, int j) {
  return (i % j) < 0 ? (i % j) + 0 + (j < 0 ? -j : j) : (i % j + 0);
}

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if (a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

// --------------------------------------------------------
// This is tool
// --------------------------------------------------------
void Main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int N, M, sum, d;
  // string mojiretu[N];
  vector<string> mojiretu;
  string s;
  cin >> N;
  // vi A(N + 1);
  // cout << A.size() << endl;
  // cin >> M;
  // cin >> sum;
  // cout << sum << endl;
  // sum = 0;
  // d = 0;
  FOR(i, 0, N) {
    cin >> s;
    // cout << s << endl;
    mojiretu.push_back(s);
    // A.push_back(d);
    // cout << mojiretu[0] << endl;
  }
  set<string> setm(mojiretu.begin(), mojiretu.end());
  cout << setm.size() << endl;

  // FOR(i, 1, N + 1) { cout << A.at(i) << endl; }
  // cout << sum << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

Measured memory_bytes: 24888
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,cnt,i,j,k,l,flg1,flg2,sa,len1,len2,k1;
	char s[101],name[26];
	scanf("%d",&n);
	scanf("%s",name);
	len1=strlen(name);
	cnt=0;
	for(i=0;i<n;i++){
		flg1=0;
		scanf("%s",s);
		len2=strlen(s);
		for(j=0;j<len2-1;j++){
			for(k=j+1;k<len2;k++){
				if(s[j]==name[0]&&s[k]==name[1]){
					sa=k-j;
				    flg2=0;
					k1=k+sa;
				    for(l=2;l<len1;l++){
						if(k1>len2){
							flg2=1;
							break;
						}
					    if(s[k1]!=name[l]){
						   flg2=1;
						   break;
					    }
						if(s[k1]==name[l]){
							k1+=sa;
						}
				     }
				    if(flg2==0){
					   flg1=1;
				    }
				}
			}
		}
		if(flg1==1){
			cnt++; 
			}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2104
N = int(input())
AB = [list(map(int, input().split(" "))) for _ in range(N)]
CD = [list(map(int, input().split(" "))) for _ in range(N)]

CD.sort()
AB.sort(key=lambda x: (x[1], x[0]), reverse=True)

count = 0
for c, d in CD:
    for j, (a, b) in enumerate(AB):
        if a < c and b < d:
            count += 1
            AB.pop(j)
            break

print(count)

Measured memory_bytes: 3064
N = gets.to_i
XYs = readlines.map{|l| l.split.map(&:to_i)}
M = 998244353

sub = ->(a, b){(a % M + M - b % M) % M}
t = 1
dd = [t]
N.times do
  t = 2*t % M
  dd << t
end
xs, ys = XYs.transpose
ini = N.times.sort_by{|n| xs[n]}
N.times.sort_by{|n| ys[n]}.each_with_index{|yi, i| ys[yi] = i}
nys = ini.map{|i| ys[i]}
tree = [0]*(N + 1)
r = 0
nys.each_with_index do |y, i|
  j = y + 1
  while j <= N
    tree[j] += 1
    j += j & -j
  end
  d = 0
  j = y
  while j > 0
    d += tree[j]
    j -= j & -j
  end
  c = i - d
  b = (N - 1) - y - c
  a = (N - 1) - b - c - d
  r = (r + sub[dd[b + c] + dd[c + d] + dd[d + a] + dd[a + b], dd[a] + dd[b] + dd[c] + dd[d]]) % M
end
puts sub[dd[N]*N % M, (r + N) % M]

Measured memory_bytes: 43372
def main():
    N, K = map(int, input().split())
    ans = [0] * (10 ** 5 + 1) 
    for i in range(N):
        a, b = map(int, input().split())
        ans[a] += b
    for i in range(10 ** 5 + 1):
        if K <= ans[i]:
            print(i)
            exit()
        else:
            K -= ans[i]
    
main()

    

Measured memory_bytes: 5736
#include <stdio.h>

int h, w;
int G[50][50];

void visit(int i, int j){
  int di[8] = { 0, -1, -1, -1, 0, 1, 1, 1};
  int dj[8] = { 1, 1, 0, -1, -1, -1, 0, 1};
  int r;
  int ni, nj;

  G[i][j]=0;

  for( r=0; r<8; r++){
    ni = i+di[r];
    nj = j+dj[r];

  if(-1<ni && ni<h && -1<nj && nj<w && G[ni][nj]==1)
    visit(ni, nj);
  }
}

main(void){
  
  int count=0;
  int i, j;

  while(1){
    scanf("%d %d", &w, &h);
    if ( h == 0 && w == 0 ) break;

    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        scanf("%d", &G[i][j]);
      }
    }

    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        if(G[i][j]==1){
          count++;
          visit(i, j);
        }
      }
    }
    printf("%d\n", count);
    count=0;
  }
  return 0;
}

Measured memory_bytes: 0
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

N,X = list(map(int,input().split()))
data = list(map(lambda x:abs(int(x)-X),input().split()))


ans = data[0]
for i in range(1,N):
    ans = gcd(ans,data[i])

print(ans)

Measured memory_bytes: 14252
mod = int(1e9 + 7)

def inv(x):
    return pow(x, mod - 2, mod)

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

def lcm(a, b):
    return a * b // gcd(a, b)

def mod_lcm(a, b):
    return a * b % mod * inv(gcd(a, b)) % mod


while True:
    try:
        n = int(input())
        a = list(map(int, input().split()))
    except:
        break

    l = a[0]
    for i in range(1, n):
        l = lcm(l, a[i])
    l %= mod

    ans = 0
    for i in range(n):
        ans = (ans + l * inv(a[i])) % mod
    print(ans)

Measured memory_bytes: 4084
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define LL long long
const int MAXN = 500+50;
const int MAXM = 8*15+50;
const int MOD = 1e9+7;
const double PI = acos(-1);
inline char getc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
    int x=0,f=1; char ch=getc();
    while(!isdigit(ch)){ if(ch=='-') f=-1; ch=getc(); }
    while(isdigit(ch)) x=x*10+ch-48,ch=getc();
    return x*f;
}
map<string,int> mp;
signed main(){
#ifndef ONLINE_JUDGE
    //freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
#endif // ONLINE_JUDGE
    int n,mx=0; scanf("%d",&n);
    for(int i=1;i<=n;i++){
        string ss; cin>>ss; mp[ss]++; mx=max(mx,mp[ss]);
    }
    for(auto i:mp) if(i.second==mx) cout<<(i.first)<<'\n';
    return 0;
}


Measured memory_bytes: 25216
#include <stdio.h>
 
void mkwall(int x, int y, int h, int w);
 
int main()
{
    for (;;) {
        int h, w, x, y;
        scanf("%d %d", &h, &w);
        if (h == 0 & w == 0) {
            return 0;
        }
        for (y = 0; y < h; y++) {
            for (x = 0; x < w; x++) {
                mkwall(x + 1, y + 1, h, w);
            }
            printf("\n");
        }
        printf("\n");
    }
}
 
void mkwall(int x, int y, int h, int w)
{
    if (x == 1 | x == w | y == 1 | y == h) {
        printf("#");
    } else {
        printf(".");
    }
}

Measured memory_bytes: 572
N=int(input())
S=input()
cntR,cntG,cntB=S.count('R'),S.count('G'),S.count('B')

ans=cntR*cntG*cntB

for i in range(N-2):
    for j in range(i+1,N-1):
        if S[i]!=S[j]:
            k=2*j-i
            if k<N and S[k]!=S[i] and S[k]!=S[j]:
                ans-=1

print(ans)

Measured memory_bytes: 9192
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i,n) cin >> v[i];
    
    double ans = 0;
    sort(all(v),greater<int>());
    while(v.size()>1) {
        double minv1 = v.back();
        v.pop_back();
        double minv2 = v.back();
        v.pop_back();
        double newv = (double)(minv1+minv2) / 2;
        v.push_back(newv);
    }
    cout << printf("%.8f",v[0]);
    return 0;
}




























Measured memory_bytes: 256
h = int(input())

import math

if h == 1:
    print(1)

else:
    n_attacks = 0
    while h / 2 >= 1:
        n_attacks += 1
        h = math.floor(h/2)

    gsum = 1

    for x in range(n_attacks):
        gsum += 2 ** (x + 1)
        
    print(gsum)

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

int main() {
	string s;
	int ns = 0, np = 0;
	cin >> s;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'S') ns++;
		if(s[i] == 'T') {
			if(ns > 0) {
				ns--;
				np++;
			}
		}
	}
	cout << (s.size() - 2 * np) << endl;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n, m; cin >> n >> m;
    if(n == m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3604
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BC = []

for i in range(M):
    b,c = map(int,input().split())
    BC.append([b,c])

BC.sort(key=lambda x:x[1],reverse=True)

ind = 0
ans = 0
for b,c in BC:
    if c > A[min(ind+b,N-1)]:
        ans += c * min(b,N-ind)
        ind += b
    else:
        while c > A[ind]:
            ans += c
            ind += 1
    if ind >= N:
        print(ans)
        exit()
print(ans + sum(A[ind:]))



Measured memory_bytes: 25664
import collections
s = list(input())
sset = set(s)
if len(sset) != 26:
    for i in range(97,123):
        if chr(i) in sset:
            continue
        else:
            tmp = chr(i)
            s.append(tmp)
            break

    print(''.join(s))
    exit()
else:
    tmp = []
    flg = False
    # 昇順のインデックス見つける
    for i in range(1,26):
        if s[i-1] < s[i]:
            tmp.append(i-1)
            continue
    # ０なら-1
    if len(tmp) == 0:
        print(-1)
        exit()
    # 末尾の昇順のとこかえる
    change_i = max(tmp)
    ans = s[:change_i]
    for i in range(97,123):
        if chr(i) in ans:
            continue
        else:
            if ord(s[change_i]) < i:
                ans.append(chr(i))
                break
    print(''.join(ans))


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

int  parent(int k) {
  return (k / 2);
}
int left(int k) {
  return (2 * k);
}
int right(int k ) {
  return (2 * k + 1);
}

int main(){


  int h;
  cin >> h;
  int *a = (int *)malloc(sizeof(int) * (h + 1));
  for(int i = 1;i <= h;i++) cin >> a[i];

  for(int i = 1;i <=h;i++){

    cout << "node " << i << ": " << "key = " << a[i] << ", ";
    if(parent(i) >= 1) cout << "parent key = " << a[parent(i)] << ", ";
    if(left(i) <= h) cout << "left key = " << a[left(i)] << ", ";
    if(right(i) <= h) cout << "right key = " << a[right(i)] << ", ";
    cout << endl;
  }
}

Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int N, M;
    cin >> N >> M;
    vector <int> K(N);
    vector <vector<int>> A(N, vector<int>(M));
    int count[M] = {0};
    rep(i, N){
        cin >> K[i];
        rep(j, K[i]){
            cin >> A[i][j];
            count[A[i][j] - 1]++;
        }
    }
    int num = 0;
    rep(i, M){
        if(count[i] == N) num++;
    }

    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;


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

  if(N%10 == 3){
    cout<<"bon"<<endl;
  }else if(N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8){
    cout<<"pon"<<endl;
  }else{
    cout<<"hon"<<endl;
  }
  return 0;

}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-15;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  ld a, b, c;
  cin >> a >> b >> c;
  cout << ((2 * sqrt(a * b) + EPS < c - a - b) ? "Yes" : "No") << endl;
}


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

using namespace std;

typedef long long ll;

int main() {
  int N; scanf("%d", &N);
  ll maxMargin = -10000000000;
  ll minR; scanf("%lld", &minR);
  for (int i=1; i<N; i++) {
    ll R; scanf("%lld", &R);
    maxMargin = max(maxMargin, R-minR);
    minR = min(minR, R);
  }
  printf("%lld\n", maxMargin);
  return 0;
}

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__);
#else
#define dbg(...) 
#endif

int main() {
	ios_base::sync_with_stdio(false);
	int k; cin >> k;
	string s; cin >> s;
	if(s.size()<=k){
		cout << s << endl;
	} else {
		cout << s.substr(0, k) << "..." << endl;
	}
	return 0;
}


Measured memory_bytes: 3656
#!/usr/bin/env python3
#ABC137 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b = LI()
print(max(a+b,a-b,a*b))


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

int main() {
	// your code goes here
	long long n,w;
	long long ans=0;
	cin>>n>>w;
	vector<long long> wei (n , 0);
	vector<long long> val (n , 0);
	for(int i=0;i<n;i++){
		cin>>wei[i]>>val[i];
	}
	vector<vector<long long>> dp (n + 1, vector<long long> (w + 1 , 0));
	
	for(int i=1;i<=n;i++){
		
		for(int j=w;j>=0;j--){
			dp[i][j]=dp[i-1][j];
			if(j>=wei[i-1]){
			dp[i][j]=max(dp[i][j], val[i-1] + dp[i-1][j-wei[i-1]]);
			}
		}
	}
	
	cout<<dp[n][w]<<endl;
	return 0;
}

Measured memory_bytes: 83212
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M;
vector<P> G[1500];
int D[1500][1500];
void dijkstra(int s) {
  int *dist = D[s];
  priority_queue<P, vector<P>, greater<P> > q;
  dist[s] = 0;
  q.push(P(0, s));
  while (!q.empty()) {
    int x = q.top()._2,
        r = q.top()._1;
    q.pop();
    if (dist[x] < r) continue;

    for (P p : G[x]) {
      int t = p._1, l = p._2;
      if (dist[t] > r+l) {
        dist[t] = r+l;
        q.push(P(r+l, t));
      }
    }
  }
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  rep(i, M) {
    int s, t, d;
    cin >> s >> t >> d;
    s--, t--;
    G[s].pb(P(t, d));
    G[t].pb(P(s, d));
  }
  rep(i, N) rep(j, N) D[i][j] = INF;
  rep(i, N) dijkstra(i);
  int R = 0;
  rep(i, N) rep(j, N) R = max(R, D[i][j]);

  vector<int> ans;
  rep(i, N) {
    vector<int> rs;
    map<int, vector<int > > vs;
    rep(j, N) rs.pb(D[i][j]), vs[D[i][j]].pb(j);
    sort(all(rs)); uniq(rs);
    //for (int x:rs)cout<<x<<",";cout<<" i="<<i<<"\n";
    bool ok = true;
    for (int x : rs) {
      if (binary_search(all(rs), R-x)) {
        for (int s : vs[x]) {
          for (int t : vs[R-x]) {
            if (D[s][t] == R) {
              ok = false;
              break;
            }
          }
        }
      }
    }
    if (ok) ans.pb(i);
  }
  cout << ans.size() << "\n";
  for (int x : ans) cout << x+1 << "\n";
  return 0;
}

Measured memory_bytes: 12180