akhauriyash/Code-Regression huggingface dataset:
def isCLKWISE(ph):
    return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P):
    P.sort()
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            if isCLKWISE(phU) : break
            else :
                del phU[-2]
                if len(phU) == 2 : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            if isCLKWISE(phL) : break
            else :
                del phL[-2]
                if len(phL) == 2 : break
    ph = phU + phL[1:-1]
    return ph
  
n = range(int(input()))
P = []
for i in n:
    P.append([int(x) for x in input().split()])
      
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R : print(r[0],r[1])

Measured memory_bytes: 33920
S = input()

while len(S) != 0:
    if S[-2:] == 'er':
        S = S[:-2]
        if S[-5:] == 'dream':
            S = S[:-5]
        elif S[-4:] == 'eras':
            S = S[:-4]
        else:
            print('NO')
            exit()
    else:
        if S[-5:] == 'dream' or S[-5:] == 'erase':
            S = S[:-5]
        else:
            print('NO')
            exit()

print('YES')

Measured memory_bytes: 9136
INF = float('inf')
N, C = map(int, input().split())
D = list() #D[i][j]:=iからjに変える時の違和感
graph = list()
for i in range(C):
  D.append(list(map(int, input().split())))
for i in range(N):
  graph.append(list(map(int, input().split())))
E = [[0] * C for _ in range(3)] #E[i][j]:=mod3でiの場所を全て色jにしたときの違和感
for c in range(C):
  for x in range(N):
    for y in range(N):
      p = (x+y+2)%3
      cxy = graph[x][y]-1
      E[p][c] += D[cxy][c]
F = [[[INF]*2 for _ in range(3)] for _ in range(3)] 
#F[i][j][k]:=mod3でiの場所の違和感の最小値第j+1位。k=0色番号, k=1最小値]
for i in range(3):
  for j in range(C):
    if(E[i][j] < F[i][0][1]):
      F[i][2] = F[i][1]
      F[i][1] = F[i][0]
      F[i][0] = [j, E[i][j]]
    elif(E[i][j] < F[i][1][1]):
      F[i][2] = F[i][1]
      F[i][1] = [j, E[i][j]]
    elif(E[i][j] < F[i][2][1]):
      F[i][2] = [j, E[i][j]]
      
ans = INF
for i in range(3):
  for j in range(3):
    for k in range(3):
      c0 = F[0][i][0]
      c1 = F[1][j][0]
      c2 = F[2][k][0]
      if(c0 != c1 and c1 != c2 and c2 != c0):
        ans = min(ans, F[0][i][1]+F[1][j][1]+F[2][k][1])
print(ans)

Measured memory_bytes: 43484
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int m,n,y,x,i;
 cin>>n>>m;
 x=min(n,m);
 y=max(m,n);
 for(i=1;i<=y;i++)
 {
     cout<<x;
 }

    return 0;

}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> v(N);
	for(int i = 0; i < N; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	int M = 0, t1 = 0, t2 = 0, t3 = 0, k = 0;
	for(int i = 0; i < N; i++) {
		if(v[i] != k) {
			if(M < t1 + t2 + t3) M = t1 + t2 + t3;
			int d = v[i] - k;
			if(d == 1) t3 = t2, t2 = t1;
			if(d == 2) t3 = t1, t2 =  0;
			if(d >= 3) t3 = t2 = 0;
			t1 = 0;
			k = v[i];
		}
		t1++;
	}
	if(M < t1 + t2 + t3) M = t1 + t2 + t3;
	cout << M << endl;
	return 0;
}

Measured memory_bytes: 640
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric,std.math;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split();foreach(i,ref arg; args){ if (i >= line.length) return;arg = line[i].to!(typeof(arg));}};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
void times(int n,void delegate() stmt){foreach(i;iota(n))stmt();}

auto sieve(){
	const primeMax = 120000;
	bool[primeMax] notPrime;
	notPrime[0] = notPrime[1] = true; 
	for(int i = 2; i * i < primeMax; i++){
		if (notPrime[i]) continue;
		for(int j = i; i * j < primeMax; j++){
			notPrime[i * j] = true;
		}
	}
	return notPrime;
}
void main(){
	int[] primes_;
	foreach(int i,np;sieve()){if(!np)primes_ ~= i;}
	auto primes = primes_.assumeSorted;
	int n,p;
	while(read(n,p),n!=-1 && p != -1){
		auto starts = primes.upperBound(n)[0..p].array;
		int[] m ;
		foreach(i,s1;starts){
			foreach(s2;starts[i..$]){
				m ~= s1 + s2;
			}
		}
		m.sort[p-1].writeln;
	}
}

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

int main(){
    string s1,s2,s3;
    char a,b,c;
    int i;
    cin >> s1 >> s2 >> s3;

    a = s1.at(0) -32;
    b = s2.at(0) -32;
    c = s3.at(0) -32;

    cout << a << b << c << endl;

    return 0;
}

Measured memory_bytes: 256
S = input()
d = S[0]
c = 1
runlength = []
for i in range(1,len(S)):
    if d == S[i]:
        c += 1
    else:
        runlength.append([d,c])
        d = S[i]
        c = 1
    if i == len(S)-1:
        runlength.append([d,c])
ans = [0]*len(S)
ind = -1
for rl in runlength:
    if rl[0] == "R":
        ind += rl[1]
        ans[ind] += rl[1] - rl[1]//2
        ans[ind+1] += rl[1]//2
    else:
        ans[ind] += rl[1]//2
        ans[ind+1] += rl[1] - rl[1]//2
        ind += rl[1]
print(*ans)

Measured memory_bytes: 16624
#include <iostream>
#include <cstdio>

using namespace std;

int n, w, mx;
int a0;
int a, b;
int d[105][305];

int main()
{
    scanf("%d%d", &n, &w);
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= 3 * n; j++)
        {
            d[i][j] = -1;
        }
    }
    d[0][0] = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d%d", &a, &b);
        if(i == 1) a0 = a;
        for(int j = i; j >= 1; j--)
        {
            for(int k = a - a0; j * a0 + k <= w && k <= n * 3; k++)
            {
                if(d[j - 1][k - a + a0] != -1) d[j][k] = max(d[j][k], d[j - 1][k - a + a0] + b);
                mx = max(mx, d[j][k]);
            }
        }
    }
    printf("%d", mx);
    return 0;
}


Measured memory_bytes: 384
def main():
    s = int(input())
    n = s
    A = []
    i = 0
    while True:
        for ele in A:
            if ele == n:
                print(i+1)
                return
        A.append(n)
        if n%2 == 0:
            n = n // 2
        else:
            n = 3*n + 1
        
        i += 1
        
main()

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

int main(){
	int s, d, m;
	int k[101], w[101][51], p[101][51], f[101];
	
	while( cin >> s >> d >> m ){
		for(int i=0 ; i < s ; i++ ){
			cin >> k[i];
			for(int j=0 ; j < k[i] ; j++ ){
				cin >> w[i][j] >> p[i][j];
			}
		}
		for(int i=0 ; i < d ; i++ ){
			cin >> f[i];
		}
		
		// dp[i][x] := i 日目に予算を x 使ったときの体重に与える最大の影響値
		int dp[101][301] = {0};
		for(int i=0 ; i < d ; i++ ){
			// i 日目について v[l] := 予算を l 使ったときの体重に与える影響の最大値
			vector<int> v(m+1);
			for(int j=0 ; j < k[f[i]] ; j++ ){
				for(int l = m - p[f[i]][j] ; l >= 0 ; l-- ){
					v[l + p[f[i]][j]] = max( v[l + p[f[i]][j]] , v[l] + w[f[i]][j] );
				}
			}
			
			for(int j=0 ; j < m+1 ; j++ ){
				for(int l=0 ; l < j+1 ; l++ ){
					dp[i+1][j-l] = max( dp[i+1][j-l] , dp[i][j] + v[l] );
				}
			}
		}
		int ans = -1, money = -1;
		for(int i = m ; i >= 0 ; i-- ){
			if( ans < dp[d][i] ){
				ans = dp[d][i];
				money = m - i;
			}
		}
		cout << ans << " " << money << endl;
	}
}

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

int main()
{
  int n;
  ll k;
  cin >> n >> k;
  
  vector<int> a(n);
  rep(i,n) cin >> a[i], a[i]--;
  
  vector<vector<int>> d(61, vector<int>(n)); //d[2^i個先][jから]
  rep(i,n) d[0][i] = a[i];
  rep(i,60) rep(j,n)
  {
    d[i+1][j] = d[i][d[i][j]];
  }
  
  int p = 0;
  for(int i = 0; (1LL<<i) <= k; i++)
  {
    if((1LL<<i)&k) p = d[i][p];
  }
  cout << p+1 << endl;
  
  return 0;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



int main(){
    string s;
    cin >> s;

    int ans = (s.size()-1)*9;

    int f = ctoi(s[0]);

    ans+=f;

    string x ="";

    for(int i=0;i<s.size();i++){
        x+='9';
    }

    x[0]=s[0];

    if(x>s){
        ans--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int d[11][11],n,m,tot,now,sum;
int pa[110],pb[110];
bool vis[11][11];
struct edge{
    int a,b,c;
}ans[310];
int numn,numm;
void print(){
    for(int i=1;i<=sum;i++){
        numm+=ans[i].a+ans[i].b+1;
        numn+=ans[i].a+ans[i].b;
    }
    numn+=2;
    /*if (numn>300){
        puts("Impossible");
        return ;
    }*/
    puts("Possible");
    //printf("Possible\n");
    printf("%d %d\n",numn,numm);
    int t=1,pre=1;
    for (int i=1;i<=sum;i++){
        pre=1;
        printf("%d %d %d\n",pre,++t,ans[i].c),pre=t;
        for (int j=1;j<=ans[i].a;j++){
            printf("%d %d %c\n",pre,(j==ans[i].a&&ans[i].b==0)?numn:++t,'X'),pre=t;
        }
        for (int j=1;j<=ans[i].b;j++)
            printf("%d %d %c\n",pre,(j==ans[i].b)?numn:++t,'Y'),pre=t;

    }
    printf("%d %d\n",1,numn);
}

int a,b,c;
bool p,q;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&d[i][j]);
    for(int s=0;s<=300;s++)
        for(a=0;a<=s&&a<=100;a++)
            for(b=0;b<=s-a&&b<=100;b++){
                    c=s-a-b;
                    p=false;
                    q=false;
                    int now=0;
                    for(int i=1;i<=n;i++){
                        for(int j=1;j<=m;j++){
                            if(a*i+b*j+c==d[i][j]&&!vis[i][j]){
                                q=true;
                                pa[++now]=i;
                                pb[now]=j;
                            }
                            else{
                                if(a*i+b*j+c<d[i][j]){
                                    p=true;
                                    break;
                                }
                            }
                        }
                        if(p==1) break;
                    }
                    if((!p)&&q){
                        for(int i=1;i<=now;i++)
                            vis[pa[i]][pb[i]]=1;
                        tot+=now;
                        ans[++sum]=(edge){a,b,c};
                        if(tot==n*m){
                            print();
                            return 0;
                        }
                    }
                }
    puts("Impossible");
    //printf("\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main() {
  LL N, C;
  cin >> N >> C;
  vector<pii> sushi(N);

  REP(i,N){
    LL x, v;
    cin >> x >> v;
    sushi[i] = make_pair(x, v);
  }

  vector<LL> ruiseki(N+1);

  ruiseki[0] = 0;

  REP(i,N){
    ruiseki[i + 1] = ruiseki[i] + sushi[i].second;
  }

  vector<LL> saiteki_f(N+1);
  vector<LL> saiteki_f_2(N+1);

  saiteki_f[0] = 0;
  saiteki_f_2[0] = 0;

  REP(i,N){
    saiteki_f[i + 1] = max(saiteki_f[i], ruiseki[i + 1] - sushi[i].first);
    saiteki_f_2[i + 1] = max(saiteki_f_2[i], ruiseki[i + 1] - sushi[i].first*2);
  }

  vector<LL> saiteki_b(N+1);
  vector<LL> saiteki_b_2(N+1);

  saiteki_b[N] = 0;
  saiteki_b_2[N] = 0;

  for (int i = N-1; i >= 0;--i){
    saiteki_b[i] = max(saiteki_b[i+1], (ruiseki[N]-ruiseki[i]) - (C-sushi[i].first));
    saiteki_b_2[i] = max(saiteki_b_2[i+1], (ruiseki[N]-ruiseki[i]) - (C-sushi[i].first)*2);
  }

  LL max_eiyou = 0;

  REP(i,N+1){
    LL eiyou1 = saiteki_f[i] + saiteki_b_2[i];
    if(eiyou1>max_eiyou){
      max_eiyou = eiyou1;
    }
    LL eiyou2 = saiteki_f_2[i] + saiteki_b[i];
    if(eiyou2>max_eiyou){
      max_eiyou = eiyou2;
    }
  }

  cout << max_eiyou << endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int

int main(){
   ll a,b,c,d,e,k;
   cin>>a>>b>>c>>d>>e>>k;
   if((e-a)>k){
     cout<<":("<<endl;
   }
   else
     cout<<"Yay!"<<endl;

   return 0;
}


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

#define ll             long long
#define LL             long long
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define sz(x)          (int)x.size()
#define TN             typename
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof(a))
#define endl           '\n'

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> T lcm(T a, T b) {return a * (b / gcd(a, b));}
template <TN T> T sqr(T a) {return a * a;}
template <TN T> T cube(T a) {return a * a * a;}
template <TN T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void smax(T &a, T b) {a = a > b ? a : b;}

template <TN T> inline void Int(T &n) {
	n = 0; int f = 1; register int ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
	for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
	n = n * f;
}

#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
	vector <string> v;
	stringstream ss(s); string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
	cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
	err(++it, args...);
}

inline int in() {int n; scanf("%d", &n); return n;}
inline ll Lin() {ll n; scanf("%lld", &n); return n;}
inline double Din() {double n; scanf("%lf", &n); return n;}

inline int add(int a, int b, int mod) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b, int mod) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b, int mod) {return (ll)a * b % mod;}

const int N          = 2e5 + 5;
const ll  Mod        = (ll)1e9 + 7;
const int inf        = (int)2e9;
const ll  Inf        = (ll)1e18;
const int mod        = (int)1e9 + 7;

ll tree[N];

void update(int n, int x, ll val) {
	while (x <= n) {
		tree[x] = max(tree[x], val);
		x += (x & -x);
	}
}

ll query(int x) {
	ll mx = 0;
	while (x > 0) {
		mx = max(mx, tree[x]);
		x -= (x & -x);
	}
	return mx;
}


int solve() {
	int n = in();
	vi h(n), a(n);
	for (int i = 0; i < n; i++) {
		h[i] = in();
	}
	for (int i = 0; i < n; i++) {
		a[i] = in();
	}
	for (int i = 0; i < n; i++) {
		update(n, h[i], query(h[i] - 1) + a[i]);
	}
	ll ans = query(n);
	printf("%lld\n", ans);
	return 0;
}

int main() {
	int test = 1, tc = 0;
	//scanf("%d", &test);
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
	return 0;
}





Measured memory_bytes: 3328
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }




int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	int s = 1;
	while (1) {
		if (s >= b) {
			cout << ans << endl;
			return 0;
		}
		else {
			ans++;
			s += a - 1;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int counter = 0;
  for(int a = 0; a <= A; a++){
    for(int b = 0;b <= B; b++){
      for(int c = 0; c <= C; c++){
        int d = a * 500 + b * 100 + c * 50;
        if(X == d) counter++;
      }
    }
  }
  cout << counter << endl;
  return 0;
}

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

class Main {
    static Scanner scanner = new Scanner();
    static PrintWriter out = new PrintWriter(System.out);
    static long mod = 1000000007;

    void solve() {
        String l = scanner.next();
        int n = l.length();
        long[] dp1 = new long[n + 1];
        long[] dp2 = new long[n + 1];
        dp2[0] = 1;
        for (int i = 1; i <= n; i++) {
            if (l.charAt(i - 1) == '0') {
                dp1[i] = dp1[i - 1] * 3 % mod;
                dp2[i] = dp2[i - 1] % mod;
            } else {
                dp1[i] = (dp1[i - 1] * 3 + dp2[i - 1]) % mod;
                dp2[i] = dp2[i - 1] * 2 % mod;
            }
        }
        out.println((dp1[n] + dp2[n]) % mod);
    }

    public static void main(String[]$) {
        new Main().solve();
        out.close();
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 32768);
        StringTokenizer tokenizer;

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

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=998244353;
const double EPS=1e-14;
const bool DEBUG=false;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////
void answer(ll N, vector<ll> A){
    ll answer = 0;
    for(auto &a : A){
        if(a >= 3){
            if(a % 2 == 0){
                answer += (a - 2) / 2;
                a = 2;
            }else{
                answer += a / 2;
                a = 1;
            }
        }
    }

    for(int i=0; i<A.size()-1; ++i){
        if(A[i] == 2){
            A[i] == 0;
            answer++;
        }else if(A[i]==1 && A[i+1]>=1){
            A[i] = 0;
            A[i+1] -= 1;
            answer++;
        }
    }
    if(A[A.size()-1]>=2){
        A[A.size()-1] = 0;
        answer++;
    }

    cout<<answer<<endl;

    return;
}

/////

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(16);

    ll N;
    cin>>N;
    vector<ll> A(N);
    for(auto &a : A){
        cin>>a;
    }
    answer(N, A);

    return 0;
}


Measured memory_bytes: 4752
#include <cstdio>

const int mod=924844033;

const int N=2005;

int n,k,vis[N],a[N],a_cnt,fac[N],ans;

long long f[N][N][2][2];

int main(){
	scanf("%d%d",&n,&k); a[0]=a[n+1]=1e9;
	for(int i=1;i<=n;++i) if(!vis[i]) for(int j=i;j<=n;j+=k) vis[j]=1,a[++a_cnt]=j;
	for(int i=0;i<=n;++i){
		f[i][0][0][0]=1;
		for(int j=1;j<=i;++j){
			f[i][j][0][0]=(f[i-1][j][0][0]+f[i-1][j][1][0]+(a[i]-a[i-1]==k)*f[i-1][j-1][0][0])%mod;
			f[i][j][0][1]=(a[i+1]-a[i]==k)*(f[i-1][j-1][0][0]+f[i-1][j-1][1][0])%mod;
			f[i][j][1][0]=(f[i-1][j][0][1]+f[i-1][j][1][1]+(a[i]-a[i-1]==k)*f[i-1][j-1][0][1])%mod;
			f[i][j][1][1]=(a[i+1]-a[i]==k)*(f[i-1][j-1][0][1]+f[i-1][j-1][1][1])%mod;
		}
	}
	fac[0]=1; for(int i=1;i<=n;++i) fac[i]=1ll*fac[i-1]*i%mod;
	for(int i=0,t=1;i<=n;++i,t=mod-t){
		int res=0;
		for(int p=0;p<2;++p) for(int q=0;q<2;++q) res=(res+f[n][i][p][q])%mod;
		ans=(ans+1ll*t*res%mod*fac[n-i]%mod)%mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 123648
#ifdef Dhiraj
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
    #define cerr if(0) cerr
#endif

// Macro --------------------------------------------------------------------

#define ll                  long long int
#define FOR(i, a, b, s)     for(ll i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define FOR1(b)             FOR(i, 0, b, 1)
#define FOR2(i, b)          FOR(i, 0, b, 1)
#define FOR3(i, a, b)       FOR(i, a, b, (a) <= (b) ? 1 :-1)
#define FOR4(i, a, b, s)    FOR(i, a, b, s)
#define GET5(a, b, c, d, e, ...) e
#define FORC(...)           GET5(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)
#define loop(...)           FORC(__VA_ARGS__)(__VA_ARGS__)
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define endl                '\n'

// Template -----------------------------------------------------------------

// multiple input
template <typename... T> 
inline void inp(T&... args) {
    ((cin >> args), ...);
}
// scan vector
template <typename T> 
inline istream& operator >>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream& operator >>(istream &in, pair<T, U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

const ll mx = 4000;
ll dp[mx][mx];

ll n;
vector<ll> a;

ll f(ll i, ll j)
{
    if(i > j || i < 0 || j < 0 || i >= n || j >= n) return 0;    
    if(dp[i][j] != -1) return dp[i][j];

    ll& ans = dp[i][j];
    ans = max(a[i] - f(i + 1, j), a[j] - f(i, j - 1));
    return ans;
}

void solve(int &T)
{
    cin >> n;
    a.resize(n);
    cin >> a;

    memset(dp, -1, sizeof(dp));
    cout << f(0, n - 1) << endl;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt", "r", stdin);
        freopen("D:/dhiraj/Programming/o1.txt", "w", stdout);
        // freopen("D:/dhiraj/Programming/e1.txt", "w", stderr);
    #endif

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

    int t = 1;
    for(int i = 1; i <= t; i++) {
        cerr << "Case #" << i << "\n";
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 128920
from collections import deque
d = deque()
s = input()
d.append(s)
rev = 0

Q = int(input())

for q in range(Q):
    ls = input().split()
    #print (ls)
    if ls[0] == '1':
        rev = (rev + 1) % 2
    else:
        if (int(ls[1]) + rev) % 2 == 0:
            d.append(ls[2])
        else:
            d.appendleft(ls[2])

ans = ''.join(list(d))
if rev == 1:
    ans = ans[::-1]
print (ans)


Measured memory_bytes: 6900
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    // rep(i, n) cout << s[i] << endl;
    sort(s.begin(), s.end());
    // rep(i, n) cout << s[i] << endl;
    int ans =0;
    string temp = "";
    rep(i,n){
        if(temp != s[i]) {temp=s[i]; ans++;}
    }
    cout << ans << endl;

    return 0;
}

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


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

    string s;
    int sol = 0;
    bool rained = false;
    cin >> s;
    for (int i = 0; i < 3; i++)
    {
        if(s[i] == 'R')
        {
            rained = true;
            if(s[i + 1] == s[i] && i != 3)
            {
                sol++;
            }
        }
    }
    cout << sol + rained << '\n';
    return 0;

}

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

int main()
{
    int a, b;
    cin >> a >> b;

    int n = 100;
    bool gt[50][100] = {}, gf[50][100] = {};
    for (int i = 0; i < n / 2; i += 2) {
        for (int j = 0; j < n; j += 2) {
                if (--a > 0) gt[i][j] = true;
                if (--b > 0) gf[n / 2 - i - 1][j] = true;
        }
    }

    cout << n << " " << n << endl;
    for (int i = 0; i < n / 2; i++) {
        for (int j = 0; j < n; j++) cout << (gt[i][j] ? '.' : '#');
        cout << endl;
    }
    for (int i = 0; i < n / 2; i++) {
        for (int j = 0; j < n; j++) cout << (gf[i][j] ? '#' : '.');
        cout << endl;
    }

    return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int l[n];
    for(int i = 0; i < n; i++)
        cin >> l[i];

    int ans = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            for(int k = 0; k < n; k++)
                if((l[i]-l[j]) != 0 && (l[i]-l[k]) != 0 && (l[j]-l[k]) != 0 && l[i]+l[j] > l[k] && l[j]+l[k] > l[i] && l[i]+l[k] > l[j])
                    ans++;

    cout << ans/6;
    return 0;
}


Measured memory_bytes: 3596
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void rd(string &x){
  char *buf = (char *)wmem;
  rd(buf);
  x = buf;
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
inline void wt_L(string &x){
  int i=0;
  for(i=0;x[i]!='\0';i++){
    my_putchar_unlocked(x[i]);
  }
}
string S;
string str[4] = {"AC", "WA", "TLE", "RE"};
int res[4];
int main(){
  int Lj4PdHRW, i;
  wmem = memarr;
  int KL2GvlyY = rd_int();
  for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){
    int i;
    rd(S);
    for(i=(0);i<(4);i++){
      if(S==str[i]){
        res[i]++;
      }
    }
  }
  for(i=(0);i<(4);i++){
    wt_L(str[i]);
    wt_L(" x ");
    wt_L(res[i]);
    wt_L("\n");
  }
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// string S;
// string str[4] = {"AC", "WA", "TLE", "RE"};
// int res[4];
// {
//   REP(rd_int()){
//     rd(S);
//     rep(i,4) if(S==str[i]) res[i]++;
//   }
//   rep(i,4) wtF("{str[i]} x {res[i]}\n");
// }


Measured memory_bytes: 3988
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int ans=n%10;
	if(ans==2||ans==4||ans==5||ans==7||ans==9){
		cout<<"hon"<<'\n';
	}
	else if(ans==0||ans==1||ans==6||ans==8){
		cout<<"pon"<<'\n';
	}
	else{
		cout<<"bon"<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f(x,n) for (int i=x;i<n;i++)

int count(int a[], int n)
{
  
 int ab,b,c;
  ab=0;
  b=abs(a[2]-a[1]);
  if(n==1)
  return ab;
 if (n==2)
  return b;
  for (int i=3;i<=n;i++)
  {
    
    c=min(ab+abs(a[i]-a[i-2]),b+abs(a[i]-a[i-1]));
    ab=b;
    b=c;
  }

  return c;

}

int main()
{
  int n;
  cin>>n;
  int a[n+1];
 
   for(int i=1;i<=n;i++)
    cin>>a[i];
  int ans=count(a,n);
  cout<<ans;

  return 0;
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
#define lson root<<1,l,midd
#define rson root<<1|1,midd+1,r
#define pb push_back
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	vector<int> x(1<<n),r(1<<n),m(1<<n);
	for(auto &e:x)scanf("%d",&e);
	for(int i=0;i<1<<n;i++){
		for(int j=i;j<1<<n;j=(j+1)|i){
			r[j]=max(r[j],x[i]+m[j]);
			m[j]=max(m[j],x[i]);
		}
	}
	for(int i=1;i<1<<n;i++){
		r[i]=max(r[i],r[i-1]);
		printf("%d\n",r[i]);
	}
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
int N;
int sum[MAXN],dp[MAXN];
void Solve() {
    read(N);
    dp[0] = 1;
    sum[0] = 1;
    int ans = 0;
    for(int i = 1 ; i <= N ; ++i) {
        update(dp[i],dp[i - 1]);
        if(i >= 3) update(dp[i],sum[i - 3]);
        sum[i] = inc(sum[i - 1],dp[i]);
    }
    for(int i = 0 ; i <= N ; ++i) {
        if(i == N - 1) {
            update(ans,mul(dp[i],N - 1));
        }
        else if(i == N) {
            update(ans,dp[i]);
        }
        else {
            update(ans,mul(dp[i],mul(N - 1,N - 1)));
        }
        if(i < N - 1) {
            int t = N - i - 1;
            update(ans,mul(dp[i],N - t));
        }
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


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

int main(){
	int n, k;
	cin >> n >> k;
	for(int i=0 ; i < k ; i++ ){
		int x, y, c;
		cin >> x >> y;
		if( x <= y && x+y <= n+1 ){
			 c = (x-1) % 3;
		}else if( x <= y && x+y > n+1 ){
			c = (n-y) % 3;
		}else if( x > y && x+y <= n+1 ){
			c = (y-1) % 3;
		}else if( x > y && x+y > n+1 ){
			c = (n-x) % 3;
		}
		cout << c+1 << endl;
	}
}

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int N = 100000;
const int K = 100000;
int n, k;
int w[N], c[K];

bool check(int lmt) {
  int i, j;

  for (i=0; i<n; i++)
    if (lmt < w[i]) return false;

  memset(c, 0, sizeof(c));
  int full = -1;
  for (i=0; i<n; i++) {
    bool is_put = false;
    for (j=full+1; j<k; j++) {
      if (lmt < c[j] + w[i])
        full++; 
      else {
        c[j] += w[i];
        if (c[j] == lmt) full++;
        is_put = true;
        break;
      }
    }
    if (!is_put) return false;
  }

  return true;
}

int main() {
  int i;
  scanf("%d%d ", &n, &k);
  for (i=0; i<n; i++)
    scanf("%d ", w+i);
  memset(c, 0, sizeof(c));

  //?±?????????????(l, u]????????????????????¨??????????????¢?´¢
  int l = 0, u = 0;
  for (i=0; i<n; i++) u += w[i];
  while (u-l > 1) {
    int m = (l+u)/2;
    if (check(m))
      u = m;
    else
      l = m;
  }

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

  return 0;
}

Measured memory_bytes: 1980
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
list<int> L;
stack<int> S;
queue<int> Q;
deque<int> dq;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=1e5;
static const int NMAX=50;
static const int MMAX=50;
int N,a[MAX];
ll cunt2,cunt1,sum;
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    
        sum=0ll;
    //偶数が正
        for(int i=0;i<N;i++){
            if(i%2==0&&sum+a[i]<=0){//sumは負
                cunt1+=(-1)*sum+1-a[i];
                sum=1;
            }else if(i%2!=0&&sum+a[i]>=0){
                cunt1+=a[i]+sum+1;
                sum=-1;
            }else sum+=a[i]; //操作必要なし
            
        }
    //奇数が正
    sum=0ll;
    for(int i=0;i<N;i++){
        if(i%2!=0&&sum+a[i]<=0){
            cunt2+=(-1)*sum+1-a[i];;
            sum=1;
        }else if(i%2==0&&sum+a[i]>=0){
            cunt2+=a[i]+sum+1;
            sum=-1;
        }else sum+=a[i]; //操作必要なし

    }
    
    cout<<min(cunt1,cunt2)<<"\n";
    
    
    return 0;
}


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

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

bool isValid(int r, int c, int x, int y){
    if(x>=0 && x<r && y>=0 && y<c)
        return true;
    return false;
}

int main(){
    int h,w;

    while(scanf("%d%d",&h,&w)!=EOF){
        bool grid[h][w];
        int dist[h][w];
        char ch;
        int white=0;

        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                scanf(" %c",&ch);
                if(ch=='.')
                    grid[i][j] = true, white++;
                else
                    grid[i][j] = false;
            }
        }

        if(!grid[0][0]){
            puts("-1");
            continue;
        }

        memset(dist, -1, sizeof dist);
        queue<pair<int, int> >q;
        q.push(make_pair(0,0));
        dist[0][0] = 1;

        while(!q.empty()){
            int sx = q.front().first, sy = q.front().second;
            q.pop();

            for(int i=0; i<4; i++){
                int x = sx + dx[i];
                int y = sy + dy[i];

                if(isValid(h,w,x,y) && grid[x][y] && dist[x][y]==-1){
                    dist[x][y] = dist[sx][sy] + 1;
                    q.push(make_pair(x,y));
                }
            }
        }

        if(dist[h-1][w-1] == -1)
            puts("-1");

        else
            printf("%d\n",white - dist[h-1][w-1]);
    }

    return 0;
}


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

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}


int main(void) {

	int n;
	cin >> n;

	double sum = 0;
	for (int i = 0; i < n; i++) {
		double a;
		cin >> a;
		a = 1 / a;
		sum += a;
	}

	COUT(setprecision(10) << 1 / sum);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N;
map<int, int> mp1, mp2;

int main(void){
    
    scanf("%d", &N);
    for(int i = 0; i < N; ++i){
        int a; scanf("%d", &a);
        if(i % 2 == 0) ++mp1[a];
        else ++mp2[a];
    }
    
    vector<P> v, w;
    for(auto i : mp1) v.push_back(make_pair(i.second, i.first));
    for(auto i : mp2) w.push_back(make_pair(i.second, i.first));
    v.push_back(make_pair(0, 0)), w.push_back(make_pair(0, 0));
    sort(v.begin(), v.end(), greater<P>());
    sort(w.begin(), w.end(), greater<P>());
    
    int a = v[0].first, b = v[1].first;
    int c = w[0].first, d = w[1].first;
    
    if(v[0].second == w[0].second) printf("%d\n", min(N - a - d, N - c - b));
    else printf("%d\n", N - a - c);
    
    return 0;
}


Measured memory_bytes: 6136
n=int(input())

tb = 0
xb = 0
yb = 0
count = 0

for i in range(n):
  t,x,y=map(int,input().split())
  if (x-xb+y-yb)<=t-tb and (t-tb+x-xb+y-yb)%2==0:
    tb = t
    xb = x
    yb = y
    count += 1

print("Yes" if count == n else "No")

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int i,n;
  int c = 0;
  char s[200];
  scanf("%d%s",&n,s);
  if(n%2 == 1) printf("No");
  else {
    for(i=0;i<n/2;i++){if(s[i] == s[i+n/2]) c++;}
  	if(c == n/2) printf("Yes");
  	else printf("No");
  }
}


Measured memory_bytes: 128
H,W,K=map(int,raw_input().split())

fibo=[1,1,2]
for i in range(W):
    fibo.append(fibo[-1]+fibo[-2])

mod=1000000007
    
f=[[1 if i==1 else 0 for i in range(W+2)]]
for i in range(H):
    for j in range(W):
        f.append([(f[-1][j]*fibo[j-1]*fibo[W-j]+f[-1][j-1]*fibo[j-2]*fibo[W-j]\
                  +f[-1][j+1]*fibo[j-1]*fibo[W-j-1])% mod\
                     if (j>=1 and j<=W) else 0 for j in range(W+2)])     

print f[H][K]

Measured memory_bytes: 2948
#include <iostream>
#include <cmath>
//#include <string>
using namespace std;
int main(){

    while(true){
    int n,x;
    cin>>n>>x;
    int ans=0;
        if(n==0&&x==0)break;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            for(int u=j+1;u<=n;u++){
                if(i+j+u==x)ans++;
            }
        }
    }
    cout<<ans<<endl;
    
    }
    
    return 0;
}


Measured memory_bytes: 3136
t_hp, t_at, a_hp, a_at = map(int, input().split())

count = 0
while t_hp*a_hp>0:
  if count % 2 == 0:
    a_hp -= t_at
  else:
    t_hp -= a_at
  count += 1

if t_hp <= 0:
  print('No')
else:
  print('Yes')
  

Measured memory_bytes: 9168
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    long double a,b,h,m;
    cin>>a>>b>>h>>m;
    long double c=h/12.0+(m/60.0)/12.0,d=m/60.0;
    long double e=M_PI*2*(c-d);
    cout<<sqrtl(a*a+b*b-2*a*b*cosl(e))<<endl;
}

Measured memory_bytes: 4132
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define present(container, element) (container.find(element) != container.end())
#define ss  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cpresent(container, element) (find(all(container),element) != container.end())
#define all(c) c.begin(), c.end()
#define mod 1000000007 
#define MOD 998244353
#define PI 3.141592654
typedef long long ll;
using namespace std;
int main(){
  ss
  ll n;
  cin>>n;
cout<<(n*(n-1))/2;
return 0; 

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i, j, k, l, n, cnt;
    while (scanf("%d", &n) != EOF) {
        cnt = 0;
        for (i = 0; i <= 9; i++)
            for (j = 0; j <= 9; j++)
                for (k = 0; k <= 9; k++)
                    for (l = 0; l <= 9; l++)
                        if (i + j + k + l == n)
                            cnt++;
        printf("%d\n", cnt);
    }

    return 0;
}


Measured memory_bytes: 2044
class Node
    attr_accessor :length, :child
    def initialize(length)
        @length = length
        @child = {}
    end
end

N, L = gets.split.map(&:to_i)

root = Node.new(0)

N.times do
    s = gets.chomp
    node = root
    s.length.times do |i|
        if node.child[s[i]]
            node = node.child[s[i]]
        else
            node.child[s[i]] = Node.new(i+1)
            node = node.child[s[i]]
        end
    end
end

grundy = 0
queue = [root]
while queue.length > 0
    node = queue.pop
    if node.child.length > 0
        ['0', '1'].each do |c|
            if node.child[c]
                queue.push(node.child[c])
            else
                len = L - node.length
                k = 1
                while len % 2 == 0
                    len /= 2
                    k *= 2
                end
                grundy ^= k
            end
        end
    end
end

puts grundy == 0 ? 'Bob' : 'Alice'

Measured memory_bytes: 46460
n = int(input())

def soinsu(n):
    a = []
    while n % 2 ==0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return [str(_) for _ in a]
ans = str(n) + ': ' + ' '.join(soinsu(n))
print(ans)


Measured memory_bytes: 5604
package main

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

func max(nums []int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func min(nums []int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m, x, y := nextInt(), nextInt(), nextInt(), nextInt()
	maxX := max(nextInts(n))
	minY := min(nextInts(m))
	ok := false
	for z := maxX + 1; z <= minY; z++ {
		if x < z && z <= y {
			ok = true
			break
		}
	}
	if ok {
		puts("No War")
	} else {
		puts("War")
	}
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();

    Map<Integer, Long> memo = new HashMap<>();
    Set<Integer> broken = new HashSet<>();
    int[] a = new int[M];
    for (int i = 0; i < M; i++) {
      broken.add(sc.nextInt());
    }
    
    long ans = func(0, N, broken, memo);
    
    System.out.println(ans);
  }
  
  private static long func(int n, int N, Set<Integer> broken,
                          Map<Integer, Long> memo) {

    if (broken.contains(n) || N < n) {
      return 0;
    }
    if (n == N) {
      return 1;
    }
    Long cache = memo.get(n);
    if (cache != null) {
      return cache;
    }
    
    long value = func(n+1, N, broken, memo) % 1000000007
      + func(n+2, N, broken, memo) % 1000000007;
    memo.put(n, value % 1000000007);

    return value % 1000000007;
  }
}

Measured memory_bytes: 66848