akhauriyash/Code-Regression huggingface dataset:
// Contest: AtCoder Beginner Contest 154 (https://atcoder.jp/contests/abc154)
// Problem: D: Dice in Line (https://atcoder.jp/contests/abc154/tasks/abc154_d)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cpp_lib_nonmember_container_access >= 201411
#   define sz(x) ((int)size(x))
#else
#   define sz(x) ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define all(a)         (a).begin(),(a).end()
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __has_cpp_attribute(maybe_unused) >= 201603
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18;
//endregion }}}

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

    int n, k; cin >> n >> k;
    vector<ld> p(n);
    trav(pi, p) cin >> pi;
    rep(i, n)
        p[i] = (p[i] / 2) + 0.5;
    reps(i, 1, n)
        p[i] += p[i-1];

    ld mx = 0.0;
    reps(i, k-1, n)
        mx = max(mx, p[i] - (i >= k ? p[i-k] : 0.0));

    cout << setprecision(20) << mx << '\n';
    return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


ll gcd(ll a, ll b) {
    if (a < b) return gcd(b, a);
    ll r;
    while ((r = a%b)) {
        a = b;
        b = r;
    }
    return b;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N, M;
    cin >> N >> M;
    vll A(N);
    rep(i, N) cin >> A[i];

    ll L = A[0];
    REP(i, 1, N) {
        L = lcm(L, A[i]);
        if (M < L / 2) {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, N) {
        if ((L - A[i]) % (2 * A[i]) != 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    if (M < L / 2) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1 + (M - (L / 2)) / L;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import math
a, b, x = map(int, input().split())
water_h = x / (a * a)
rest_b = b - water_h
if x > (a * a * b) / 2:
    ans = math.degrees(math.atan(rest_b/(a / 2)))
else:
    x /= a
    water_h = (2 * x) / b
    ans = math.degrees(math.atan(b / water_h))
print(ans)

Measured memory_bytes: 62292
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

a = A % 10
b = B % 10
c = C % 10
d = D % 10
e = E % 10

t = A + B + C + D + E + (10 - a) % 10 + (10 - b) % 10 + (10 - c) % 10 + (10 - d) % 10 + (10 - e) % 10
m = max([(10 - a) % 10, (10 - b) % 10, (10 - c) % 10, (10 - d) % 10, (10 - e) % 10])
print(t - m)

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

int main() {
  int A,B,count;
  cin >> A >> B;
  
  for(int i = A; i <= B; i++){
    int reverse = 0;
    int N = i;
    int remaind;
    
    while(N != 0){
      remaind = N % 10;
      reverse = reverse * 10 + remaind;
      N /= 10;
    }
    
    if(i == reverse){
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define M 1000000007

int main() {
    int n, k; cin >> n >> k;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    long long dp[100100][101] = {};
    for (int i = 0; i < n; i++) {
        dp[0][i] = 1;
        for (int j = 1; j <= k; j++) {
            if (i > 0) {
                dp[j][i] = dp[j-1][i];
                dp[j][i] += dp[j][i-1];
                if (j >= a[i] + 1) dp[j][i] -= dp[j-a[i]-1][i-1];
                if (dp[j][i] >= M) dp[j][i] -= M;
                else if (dp[j][i] < 0) dp[j][i] += M;
            } else {
                dp[j][i] = (j <= a[i]);
            }
        }
    }
    cout << dp[k][n-1] << endl;
}


Measured memory_bytes: 79232
from math import gcd
a, b, c, d = map(int, input().split())
lcm = c*d//gcd(c, d)
cc = b//c - (a-1)//c
cd = b//d - (a-1)//d
clcm = b//lcm - (a-1)//lcm
print(b-a+1 - (cc + cd - clcm))

Measured memory_bytes: 61508
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int h, w, cnt=0, xflag=0;
    char a[1000][101];
    
    scanf("%d%d", &h, &w);
    rep(i, h){
        scanf("%s", a[i]);
    }
    
    rep(i, h){
        cnt=0;
        rep(j, w){
            if (a[i][j]=='.') {
                cnt++;
            }
        }
        if (cnt==w) {
            rep(j, w){
                a[i][j]='a';
            }
        }
    }
    
    rep(i, w){
        cnt=0;
        rep(j, h){
            if (a[j][i]=='.'||a[j][i]=='a') {
                cnt++;
            }
        }
        if (cnt==h) {
            rep(j, h){
                a[j][i]='a';
            }
        }
    }
    
    rep(i, h){
        xflag=0;
        rep(j, w){
            if (a[i][j]!='a') {
                printf("%c", a[i][j]);
                xflag++;
            }
        }
        if (xflag!=0) {
            printf("\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 1608
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

struct Edge{ int from, to, cost; };

bool comp(const Edge& e1, const Edge& e2){
	return e1.cost < e2.cost;
}

vector<Edge> es;
VI parent;
VI rank;

void init(int n){
	rep(i,n){
		parent.pb(i);
		rank.pb(0);
	}
}

int find(int x){
	if(parent[x] == x){
		return x;
	}
	return parent[x] = find(parent[x]);
}

bool unite(int x, int y){
	x = find(x);
	y = find(y);

	if(x == y)
		return false;

	if(rank[x] < rank[y]){
		parent[x] = y;
	}else{
		parent[y] = x;
		if(rank[x] == rank[y]) rank[x]++;
	}
	return true;
}	

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

	while(1){
		int n, m;
		int ans = 0;

		cin >> n >> m;

		if(n == 0 && m == 0) break;

		rep(i,m){
			Edge e;
			cin >> e.from >> e.to >> e.cost;
			es.pb(e);
		}

		init(n);
		sort(all(es), comp);
		
		rep(i,es.size()){
			Edge e = es[i];
			if(!unite(e.from, e.to)){
				continue;
			}
			ans += e.cost;
		}

		cout << ans << endl;

		parent.clear();
		rank.clear();
		es.clear();
	}
	return 0;
}

Measured memory_bytes: 1224
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>

using namespace std;
const int maxn = 1e5+5;
int mod = 1e9+7;
void up(int &x,int y) { x+=y; if(x>=mod)x-=mod; }
int n;
char ss[maxn];
int sm[maxn],f[maxn],nt[3];
int main() {
	scanf("%s",&ss[1]);
	n = strlen(ss+1);
	bool fl = 0;
	for(int i=1;i<=n;i++) {
		sm[i] = (sm[i-1] + ss[i]-'a'+1)%3;
	}
	for(int i=1;i<n;i++) fl |= (ss[i]==ss[i+1]);
	if(!fl) {
		puts("1"); return 0;
	}
	f[n] = 1;
	for(int i=0;i<3;i++) nt[i] = n+1;
	nt[sm[n]] = n;
	for(int i=n-1;i>=1;i--) {
		if(sm[i]==sm[n]) f[i] = 1;
		up(f[i],f[nt[(sm[i]+1)%3]]);
		up(f[i],f[nt[(sm[i]+2)%3]]);
		nt[sm[i]] = i;
	}
	printf("%d",(f[nt[1]]+f[nt[2]])%mod);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    int ans = 0;

    rep(i,n){
        int x; cin >> x;
        ans += 2*min(x, abs(x-k));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <valarray>
#include <utility>
#include <set>
#include <map>

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP2(i,m,n) for(int i=m+1;i<=(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<=(int)(n);i++)
#define INF 500000000  //
#define INFLL 1000000000000000000  //
#define MOD (1e9)+7

typedef long long int ll;

struct edge {
    int to, cost;
};

// a 0x61  z 0x7a  0 0x30

//------------------------------------------------------

int main() {
    ll k;
    cin >> k;

    cout << 50 << endl;

    ll a[50];
    ll times = k / 50;
    ll plus = k % 50;

    rep(i, 50) a[i] = i + times;
    reverse(a, a + 50);

    rep(i, plus) a[i]++;

    rep(i, 49) cout << a[i] << " ";
    cout << a[49] << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long dp[100009][400];
long long W,n;
long long w[1000];
long long v[1000];
long long solve(long long V, int i) {
    if(i==n){
        if(V==0) return 0;
        else
        return INT_MAX;
    }
   if(dp[V][i]!=-1)
       return dp[V][i];
   long long ans = solve(V,i+1);
   if(v[i]<= V)
       ans = min(ans,w[i] + solve(V-v[i],i+1));

   return dp[V][i] = ans;
}
long long bestValue(long long  max_profit){

    for(long long i=max_profit;i>=0;--i){
        long long temp = solve(i,0);
        if(temp<=W){
            return  i;
        }
    }
    return 0;
}
int main() {
    memset(dp,-1,sizeof dp);
    scanf("%lld%lld",&n,&W);
    long long max_profit = 0;
    for(int i=0;i<n;++i){
        scanf("%lld",w+i);
        scanf("%lld",v+i);
        max_profit+= *(v+i);
    }
    printf("%lld ",bestValue(max_profit));

}

Measured memory_bytes: 316356
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class Main {

	static Scanner sc = new Scanner(System.in);
	
	static int[] dp = new int[1000001];
	static int[] dp2 = new int[1000001];	
	public static void main(String[] args) {
		
		fill(dp, 100000000);
		fill(dp2, 100000000);
		dp[0] = dp2[0] = 0;
		dp[1] = dp2[1] = 1;
		for (int i = 1; i <= 1000000; i++) {
			for (int j = 1; ; j++) {
				int a = f(j);
				int b = i - a;
				if (b < 0) break;
				dp[i] = min(dp[i], 1 + dp[b]);
				if (a % 2 == 1)
					dp2[i] = min(dp2[i], 1 + dp2[b]);
			}
		}
		while (read())
			solve();
	}
	
	static int N;
	static boolean read() {
		N = sc.nextInt();
		if (N == 0) return false;
		return true;
	}

	static void solve() {
		System.out.println(dp[N] + " " + dp2[N]);
	}


	static int f(int n) {
		return n * (n + 1) * (n + 2) / 6;
	}
}

Measured memory_bytes: 20000
n, m = map(int, input().split())
sc = []
for i in range(m):
    sc.append(list(map(int, input().split())))

ans = -1
for i in range(1000):
    if (len(str(i)) == n):
        flag = 1
        for s, c in sc:
            if (str(i)[s - 1] != str(c)):
                flag = 0
        if (flag == 1):
            ans = i
            break
print(ans)


Measured memory_bytes: 3060
import java.util.*;

import static java.lang.Math.*;

class Main {
    final Scanner sc = new Scanner(System.in);

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

    private void run() {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        long[] a = new long[n+1];
        long[] b = new long[m+1];
        long[] aSum = new long[n+1];
        long[] bSum = new long[m+1];

        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
            aSum[i] = a[i] + aSum[i-1];
        }

        for (int i = 1; i <= m; i++) {
            b[i] = sc.nextInt();
            bSum[i] += b[i] + bSum[i-1];
        }

        int ans = 0;
        int bCount = m;
        // Aをi冊読むとき
        for (int aCount = 0; aCount <= n; aCount++) {
            if (aSum[aCount] > k) {
                continue;
            }

            for (; bCount >= 0; bCount--) {
                if (aSum[aCount] + bSum[bCount] <= k) {
                    ans = max(ans, aCount + bCount);
                    break;
                }
            }
        }
        System.out.println(ans);
    }
}


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

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

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

int main() {

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

	int a, b, k;
	cin >> a >> b >> k;

	while (k) {
		if (a & 1) {
			--a;
		}

		b += a / 2;
		a /= 2;
		--k;
		if (!k) {
			break;
		}

		if (b & 1) {
			--b;
		}

		a += b / 2;
		b /= 2;
		--k;
	}

	cout << a << " " << b << "\n";

	return 0;

}

Measured memory_bytes: 256
N,M = map(int,input().split())
H = list(map(int,input().split()))
ans = [0]*N


visited = [0]*N
for i in range(M):
    a,b = map(int,input().split())
    visited[a-1] = 1
    visited[b-1] = 1
    if H[a-1]<H[b-1]:
        ans[a-1] = -1
    elif H[b-1]<H[a-1]:
        ans[b-1] = -1
    else:
        ans[a-1] = -1
        ans[b-1] = -1
        

ans = [i for i in range(N) if ans[i]==0]
print(len(ans))

Measured memory_bytes: 87008
x=int(input())

if 400 <= x <= 599:print(8)
elif 600 <= x <= 799:print(7)
elif 800 <= x <= 999:print(6)
elif 1000 <= x <= 1199:print(5)
elif 1200 <= x <= 1399:print(4)
elif 1400 <= x <= 1599:print(3)
elif 1600 <= x <= 1799:print(2)
else:print(1)


Measured memory_bytes: 9120
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#define N 2002
using namespace std;
long long n,a[N],b[N],c[N];
long long tot,ans,op[N],top;
void work(int l,int r)
{
	if(r<=l)return ;
	for(int i=l+1;i<r;i+=2)op[++tot]=l+1-top;
}
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	long long now=0;
	for(int i=1;i<=n;i+=2)if(a[i]>=0)b[++b[0]]=i,ans+=a[i];
	for(int i=2;i<=n;i+=2)if(a[i]>=0)c[++c[0]]=i,now+=a[i];
	if(!c[0]&&!b[0])
	{
		long long mx=-(1ll<<60),id;
		for(int i=1;i<=n;i++)if(mx<a[i])mx=a[i],id=i;
		ans=mx,tot=0;
		for(int i=1;i<id;i++)op[++tot]=1;
		for(int i=n;i>id;i--)op[++tot]=i-id+1;
	}
	else if(ans>now||!c[0])
	{
		for(int i=1;i<=b[1]-1;i++)op[++tot]=1;top+=b[1]-1;
		for(int i=n;i>b[b[0]];i--)op[++tot]=i-top;
		for(int i=1;i<b[0];i++)work(b[i]+1,b[i+1]-1),top+=(b[i+1]-b[i]-2);
		for(int i=1;i<b[0];i++)op[++tot]=2;
	}
	else
	{
		for(int i=1;i<=c[1]-1;i++)op[++tot]=1;top+=c[1]-1;
		for(int i=n;i>c[c[0]];i--)op[++tot]=i-top;
		for(int i=1;i<c[0];i++)work(c[i]+1,c[i+1]-1),top+=(c[i+1]-c[i]-2);
		for(int i=1;i<c[0];i++)op[++tot]=2;
		ans=now;
	}
	printf("%lld\n",ans);
	printf("%lld\n",tot);
	for(int i=1;i<=tot;i++)printf("%lld\n",op[i]);
}

Measured memory_bytes: 256
n, m, k = gets.split.map(&:to_i)
a_arr = gets.split.map(&:to_i)
b_arr = gets.split.map(&:to_i)

sum = 0
sum_a_arr = [[0, 0]]
a_arr.each_with_index do |num, i|
  sum += num
  sum_a_arr << [sum, i + 1]
end

sum = 0
sum_b_arr = [[0, 0]]
b_arr.each_with_index do |num, i|
  sum += num
  sum_b_arr << [sum, i + 1]
end

max = 0
ind = 0
sum_a_arr.reverse_each do |num, count|
  next if num > k

  c = count
  while ind < b_arr.length + 1
    num2, count2 = sum_b_arr[ind]
    break if num + num2 > k

    ind += 1
    c = count + count2
  end
  
  max = c if max < c
end

p max


Measured memory_bytes: 54528
#include <iostream>


#define endl '\n'
#define pi acos(-1)
#define euler_e 2.71828
#define pii pair<int,int>
#define pb push_back
#define all(a) a.begin(),a.end()
#define ll long long
#define ull unsigned long long
#define io freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
void mycode();
const ll int mod=998244353;
ll int ceil(ll int a,ll int b){return (a+b-1)/b;}
ll int min(ll int a, ll int b){if(a>b)return b;else return a;}
bool bit_check(ll int a,int i){
  if((a & (1LL<<i)))return 1;
  return 0;
}
ll int bit_toggle(ll int a,int i){
  return (a^(1LL<<i));
}
ll int bit_sum(ll int a,int i){
  return a+(1LL<<i);
}
ll int bit_sub(ll int a,int i){
  return a-(1LL<<i);
}
ll int mod_power(ll int x,ll int y){//x^y%p
  ll int p=mod;
  ll int res = 1;
  x = x % p;
  while (y > 0) { 
    if (y & 1)res = (res*x) % p;
    y = y>>1;x = (x*x) % p;
  }
  return res;
}
ll int power_of(ll int a,int b){
  if(a==0)return -1;
  return 1+power_of(a/b,b);
}
ll int power(ll int a, ll int b) {
	if(a==1)return 1;
    ll int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
//__int128
int main(){
	//boost;
	//io;
	//auto start = chrono::high_resolution_clock::now();
	mycode();
	//auto end = chrono::high_resolution_clock::now();cerr << "\nExecution time: "<< chrono::duration_cast<chrono::milliseconds>(end - start).count() << " ms" << endl;
	return 0;
}

void mycode(){
	int t;
	cin>>t;
	ull int arr[100005];
	bool flag1=0,flag2=0;
	for(int i=0;i<t;i++){cin>>arr[i];if(arr[i]==0)flag1=1;}
	if(flag1)cout<<0;
	else{
		__int128 k=1;
		for(int i=0;i<t;i++){
			k*=arr[i];
			//cout<<(ll)k<<endl;
			if(k>1000000000000000000){flag2=1;break;}
		}
		if(flag2)cout<<-1;
		else cout<<(ull)k<<endl;
	}
}

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

int main() {
  long long N,K;
  
  cin>>N>>K;
  
  
  
    if(N%K>K/2){
      cout<<K-(N%K)<<endl;
    }
  else{
    cout<<N%K<<endl;
  }
      
    
  
  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<deque>
#include<iomanip>
#include <math.h>

using namespace std;
typedef long long ll;

int main(void)
{
    int N, D;
    cin >> N >> D;

    int ans = 0;
    if(N % (2 * D + 1) == 0)
    {
        ans = N / (2 * D + 1);
    }
    else
    {
        ans = N / (2 * D + 1) + 1;
    }
    

    cout << ans << endl;
}

Measured memory_bytes: 256
use std::io::Read;
use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    it.next();
    let mut map = std::collections::BTreeMap::new();
    for s in it {
        let s: String = s.chars().collect();
        *map.entry(s).or_insert(0) += 1;
    }
    let mut ans = vec![];
    let mut cnt = 0;
    for (k, v) in map {
        if v > cnt {
            ans.clear();
            cnt = v;
            ans.push(k);
        } else if v == cnt {
            ans.push(k);
        }
    }
    for s in ans {
        writeln!(out, "{}", s).ok();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 28152
N, M = map(int, input().split())
gate = [input().split() for i in range(M)]

MIN = 0
MAX = float('inf')

for i in range(M):
    MIN = max(MIN, int(gate[i][0]))
    MAX = min(MAX, int(gate[i][1]))

print(max(MAX - MIN + 1, 0))

Measured memory_bytes: 32152
n = gets.to_i
h = gets.split.map(&:to_i).reverse
ans = "Yes"
0.upto(n-2) do |i|
  if h[i] < h[i+1]
    h[i+1]-=1
  end
  if h[i] < h[i+1]
    ans = "No"
    break
  end
end
puts ans

Measured memory_bytes: 21608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int MOD = 1e9 + 7;

template <class T>
T ModuloInverse(T a, T m) {
  T b = m, x = 1, y = 0;
  while (b) {
    T t = a / b;
    a -= t * b;
    x -= t * y;
    std::swap(a, b);
    std::swap(x, y);
  }
  return (m + x % m) % m;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto& e : a) cin >> e;

  ll s = 0;
  for (auto e : a) (s += e) %= MOD;

  ll r = 0;
  for (auto e : a) (r += (MOD + s - e) % MOD * e) %= MOD;
  r *= ModuloInverse(2, MOD);
  r %= MOD;
  cout << r << endl;
}


Measured memory_bytes: 4844
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		sc.useDelimiter("\\s");
		while (true) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if (a == 0 && b == 0) {
				break;
			} else {
				if (a < b) {
					System.out.println(a+" "+b);
				} else {
					System.out.println(b+" "+a);
				}
			}
		}
	}

}

Measured memory_bytes: 33736
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    int a, b, c;
    cin >> a >> b >> c;

    int res = a;
    if ( a == b ) {
        res = c;
    } else if ( a == c ) {
        res = b;
    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
import math

a, b, x = map(int, input().split())

# 45度より傾けても大丈夫な場合
if x < a*a*b / 2.0:
  # 底面の水に触れてる長さをhとする
  h = 2.0 * float(x) / (float(b) * float(a))
  rad = math.atan2(b, h)
else:
  # こぼれるぎりぎりの、傾ける反対側の面の水の触れていない長さをhとする
  h = 2.0 * (float(b) - float(x) / float(a*a))
  rad = math.atan2(h, a)

print(math.degrees(rad))


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

#define i64 long long

using namespace std;

const int maxn = (int)1e5+100; //点数
const i64 INF = 0x3f3f3f3f3f3f3f3fLL;
struct node {
    int id;
	i64 w;
    node(){}
    node(int a, int b) : id(a), w(b) {}
    friend bool operator < (node a, node b) {return a.w > b.w;}
};
vector<node> G[maxn];
bool vis[maxn];
i64 dis[maxn], pt[maxn];

void dij(int s, int n) {
    priority_queue<node> q;
	while (!q.empty()) q.pop();
    node cur;
    for (int i = 1; i <= n; ++i) {
		dis[i] = INF;
		vis[i] = 0;
	}
    dis[s] = 0;
    q.push(node(s, dis[s]));
    while (!q.empty()) {
        cur = q.top();
        q.pop();
        if (vis[cur.id]) continue;
        vis[cur.id] = 1;
        for (node to : G[cur.id]) {
            if (!vis[to.id] && dis[to.id] > dis[cur.id]+to.w) {   //dis[to.id] > to.w 就变成了堆优化prim
                dis[to.id] = dis[cur.id]+to.w;
                pt[to.id] = cur.id;
                q.push(node(to.id, dis[to.id]));
            }
        }
    }
}
void init(int n) {
    for (int i = 0; i <= n; ++i) G[i].clear();
}
int n, m;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> n >> m;
    init(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        G[u].emplace_back(node(v, 1));
        G[v].emplace_back(node(u, 1));
    }
    dij(1, n);
    bool flag = true;
    for (int i = 2; i <= n; ++i) {
        flag &= (dis[i] != INF);
    }
    if (!flag) cout << "No" << '\n';
    else {
        cout << "Yes" << '\n';
        for (int i = 2; i <= n; ++i) cout << pt[i] << '\n';
    }

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 19728
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>n>>k;
	ll a[n];
	Ff(i,0,n)
	cin>>a[i];

	sort(a,a+n);
	ll ans=0;
	Ff(i,0,min(k,n))
	ans+=a[i];
	cout<<ans;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 10672
#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>;

const ll MOD = 1000000007;

long long pow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> A(k+1);
    for (int i = k; i > 0; --i) {
        ll t = pow(k/i, n);
        for (int j = i*2; j <= k; j += i) {
            t -= A[j];
        }
        A[i] = (t % MOD + MOD) % MOD;
    }
    ll ans = 0;
    for (int i = 1; i <= k; ++i) {
        ans += (A[i] * i) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4060
n = int(input())
A = [int(i) for i in input().split()]

def f(A, op, acc = 0, cnt = 0):
    for i in range(n):
        acc += A[i]
        
        if i % 2 == 0 and acc * op >= 0:
            cnt += op * acc + 1
            acc = - op
            
        if i % 2 == 1 and acc * op <= 0:
            cnt += - op * acc + 1
            acc = op
            
    if acc == 0:
        cnt += 1
        
    return cnt
        
print(min(f(A, -1), f(A, 1)))

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

const ll MOD = 1000000007;

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

    int ans = 1e8;

    rep(i, n) {
        int tmp_c, tmp_t;
        cin >> tmp_c >> tmp_t;
        if ( tmp_t <= t && tmp_c < ans ) {
            ans = tmp_c;
        }
    }

    if ( ans == 1e8 ) cout << "TLE" << endl;
    else              cout << ans   << endl;

    return 0;
}

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

a.sort(reverse=True)
ans = a[0]
cnt = 1
for i in range(1, n):
    if cnt == n - 1:
        break
    ans += a[i]
    cnt += 1
    if cnt == n - 1:
        break
    ans += a[i]
    cnt += 1
print(ans)


Measured memory_bytes: 105272
package main

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

var sc = bufio.NewScanner((os.Stdin))

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

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	D, G, p, c := nextInt(), nextInt(), []int{}, []int{}
	for i := 0; i < D; i++ {
		p = append(p, nextInt())
		c = append(c, nextInt())
	}

	fmt.Printf("%d\n", ABC104C(G, p, c))
}

// ABC104C ...
func ABC104C(G int, p, c []int) (res int) {
	res = 1000
	for bit := 0; bit < (1 << uint(len(c))); bit++ {
		ans, score, solved := 0, 0, map[int]bool{}
		for i := 0; i < len(c); i++ {
			if bit>>uint(i)&1 == 1 {
				ans += p[i]
				score += c[i] + (i+1)*100*p[i]
				solved[i] = true
			}
		}

		if score < G {
			for i := len(p) - 1; i >= 0; i-- {
				_, ok := solved[i]
				if !ok {
					rest := G - score
					if rest > (i+1)*100*(p[i]-1) {
						ans += p[i] - 1
						score += (i + 1) * 100 * (p[i] - 1)
					} else {
						solvedhrere := rest / ((i + 1) * 100)
						ans += solvedhrere
						score += (i + 1) * 100 * solvedhrere
					}
				}
			}
		}

		if score >= G && ans < res {
			res = ans
		}
	}
  
  	return
}


Measured memory_bytes: 1784
#include<iostream>
using namespace std;
int main(){
int x , y ;
cin >> x>> y;
if (x+y >= x*y && x+y >= x-y)
    cout << x+y;
else if (x-y >= x+y && x-y >= x*y)
    cout << x-y;
else  
    cout << x*y;
return 0;
}


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

namespace Atcoder
{
    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);int m = int.Parse(input[1]);
            Console.WriteLine((n-1)*(m-1));
        }
    }
}


Measured memory_bytes: 13140
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

const long INF = 1123456789012345678;

long n, q;

std::string s;

long sum[100005];

int main(){
	scanf("%ld %ld", &n, &q);
	std::cin >> s;
	for(int i = 0; i < s.length()-1; i++){
		if(s[i] == 'A' && s[i+1] == 'C'){
			sum[i]++;
		}
		if(i > 0){
			sum[i] += sum[i-1];
		}
	}
	/*
	for(int i = 0; i < s.length(); i++){
		printf("%ld ", sum[i]);
	}
	printf("\n");
	//*/
	for(int i = 0; i < q; i++){
		long l, r;
		scanf("%ld %ld", &l, &r);
		l--;
		r--;
		printf("%ld\n", sum[r-1] - ((l>0)?sum[std::max(l-1, 0l)]:0));
	}
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n*n);
    for (int q = 0; q < n*n; q++){
        cin >> a[q];
        a[q]--;
    }
    vector<vector<bool>> used(n, vector<bool>(n, true));
    vector<p> st = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
    vector<vector<int>> d(n, vector<int>(n, 0));
    for (int q = 0; q < n; q++){
        for (int q1 = 0; q1 < n; q1++){
            d[q][q1] = min(min(q, n-q-1), min(q1, n-q1-1));
        }
    }
    int ans = 0;
    for (int q = 0; q < n*n; q++){
        int q1 = a[q]/n, q2 = a[q] % n;
        queue<p> s;
        for (p q3: st) {
            if (q1+q3.first > -1 && q1+q3.first < n && q2+q3.second > -1 && q2+q3.second < n) {
                s.push({q1 + q3.first, q2 + q3.second});
            }
        }
        ans += d[q1][q2], used[q1][q2] = false;
        while (!s.empty()){
            p x = s.front();
            q1 = x.first, q2 = x.second;
            s.pop();
            for (p q3: st){
                if (q1+q3.first > -1 && q1+q3.first < n && q2+q3.second > -1 && q2+q3.second < n && d[q1+q3.first][q2+q3.second]+used[q1+q3.first][q2+q3.second] < d[q1][q2]){
                    d[q1][q2] = d[q1+q3.first][q2+q3.second]+used[q1+q3.first][q2+q3.second];
                    for (p q4: st){
                        if (q1+q4.first > -1 && q1+q4.first < n && q2+q4.second > -1 && q2+q4.second < n) {
                            s.push({q1 + q4.first, q2 + q4.second});
                        }
                    }
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main () {
  int n,k;
  cin >> n >> k;
  vector<int> vec(n);
  
  int d;
  for (int i=0;i<k;++i) {
    cin >> d;
    vector<int> a(d);
    for (int j=0;j<d;++j) {
      cin >> a[j];
      vec[a[j]-1]++;
    }
  }
  int count=0;
  for (int i=0;i<n;++i) {
    if (vec[i]==0) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


// LRUD
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
// const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
// const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


int main(int argc, char**argv){
    int n;
    int a, b;
    cin >> n >> a >> b;
    cout << min(n*a, b) << endl;

    return 0;
}






















Measured memory_bytes: 764
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int L; cin >> L;
    int N;
    FOR(i, 1, 21){
        if((1 << i) > L){
            N = i;
            break;
        }
    }

    mat edge(0, vec(3));
    REP(i, N - 1){
        edge.push_back(vec({i + 1, i + 2, 0}));
    }
    
    REP(i, N - 1){
        edge.push_back(vec({i + 1, i + 2, (1 << (N - i - 2))}));
    }

    REP(i, N - 1){
        if((((L) >> i) & 1) == 1){
            int x = ((L) >> (i + 1)) << (i + 1);
            edge.push_back(vec({1, N - i, x}));
        }
    }

    cout << N << " " << edge.size() << endl;
    REP(i, edge.size()){
        cout << edge[i][0] << " " << edge[i][1] << " " << edge[i][2] << endl;
    }

    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define Q int tt,qq; cin>>tt ;for(qq=1;qq<=tt;qq++)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main()
{
    int n;
    cin>>n,n--;
    int a[n];
    for(auto &it:a)   cin>>it;
    ll ans=a[0];
    for(int i=0;i<n-1;i++){
        ans+=min(a[i],a[i+1]);
    }
    ans+=a[n-1];
    cout<<ans<<endl;
}


Measured memory_bytes: 3628
n = int(input())
a = list(map(int, input().split()))
# nこのlcm 順番に計算するとlog a * n くらいになる？
def my_lcm(a, b):
    cum = a * b
    if a > b:
        a, b = b, a
    while a != 0:
        a, b = b % a, a
    # b がgcd になっている
    return cum // b


res = 1
for i in a:
    res = my_lcm(res, i)
print(res)



Measured memory_bytes: 5600
def ans(s):
    s = list(sorted(s))
    if (s[0] == s[1]) & (s[2] == s[3]) & (s[0] != s[2]):
        return True
    else:
        return False

s = input()
if(ans(s) == True):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
typedef long long ll;
int n;
string s;
ll f(int k){
    ll r=0,d=0,m=0,dm=0;
    for(int i=0;i<n;i++){
        if(i-k>=0){
            if(s[i-k]=='D'){
                d--;
                dm-=m;
            }else if(s[i-k]=='M'){
                m--;
            }
        }
        if(s[i]=='D'){
            d++;
        }else if(s[i]=='M'){
            m++;
            dm+=d;
        }else if(s[i]=='C'){
            r+=dm;
        }


    }
    return r;
}
int main(void){
    int q;
    cin>>n>>s>>q;
    for(int i=0;i<q;i++){
        int k;
        cin>>k;
        ll ans=f(k);
        cout << ans << endl;
    }
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,k;
    cin>>n>>k;
    vector<ld> p(n),a(n-k+1);
    ld ans=0;
    rep(i,n){
        cin>>p[i];
        p[i]=(1+p[i])/2;
        if(i-k<0) a[0]+=p[i];
        else{
            a[i-k+1]=a[i-k]-p[i-k]+p[i];
            ans=max(ans,a[i-k]);
        }
    }
    ans=max(ans,a[n-k]);
    cout<<fixed<<setprecision(10)<<ans;
}

Measured memory_bytes: 9396
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val n = in.readInt
  var b = in.readLine.split(" ").map(_.toInt).toBuffer
  val a = mu.ListBuffer.empty[Int]

  for(i <- 0 until n) {
    var isFind = false
    for(j <- b.size-1 to 0 by -1 if !isFind) {
      if(b(j) == j+1) {
        a += b(j)
        isFind = true
        debug(j, b(j))
      }
    }
    if(isFind && a.nonEmpty && a.last <= b.size) b.remove(a.last-1)
  }

  if(b.isEmpty) {
    println(a.reverse.mkString("\n"))
  }
  else {
    println(-1)
  }

  def debug(any:Any*):Unit = {
    if(this.getClass.toString == "class Main$") return
    println(any.mkString(" "))
  }
}

Measured memory_bytes: 27328
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int n;
  cin >> n;
  for(int i = 0; i <= n / 4; i++) {
    int r = n - i * 4;
    if(r % 7 == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> b(N);
  vector<int> ans;
  for (int i = 0; i < N; i++) cin >> b.at(i);
  for (int i = 0; i < N; i++) {
    bool found = false;
    for (int j = b.size()-1; j >= 0; j--) {
      if (b.at(j) == j+1) {
        ans.push_back(b.at(j));
        b.erase(b.begin() + j);
        found = true;
        break;
      }
    }
    if (!found) {
      cout << -1 << endl;
      return 0;
    }
  }
  reverse(ans.begin(), ans.end());
  for (int v : ans) cout << v << endl;
}

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

#define rep(i, a, b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= int(b); --i)
#define trav(it, v) for(typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define all(v) (v).begin(), (v).end()
#define what_is(x) cerr << #x << " is " << x << endl;

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

int main(){
	ll N;
	cin >> N;
	int Max=0;
	while((2LL << Max)-1 <= N)
		Max++;
	N -= (1LL << Max)-1;
	vector<int> ans;
	rrep(i,Max,0){
		ans.push_back(i+1);
		if((1LL << i) <= N){
			ans.push_back(i+50);
			N -= (1LL<<i);
		}
	}
	rep(i,0,Max){
		ans.push_back(i+50);
	}
	rrep(i,Max,0){
		ans.push_back(i+1);
	}
	cout << ans.size() << endl;
	rep(i,0,ans.size())
		cout << ans[i] << " ";
	cout << endl;
}

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

int main(void)
{
    int H, W;
    while(true) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
        for(int j = 0; j < W; j++) {
            cout << '#';
        }
        cout << endl;
        for(int i = 1; i < H-1; i++) {
            cout << '#';
            for(int j = 1; j < W-1; j++) {
                cout << '.';
            }
            cout << '#' << endl;
        }
        for(int j = 0; j < W; j++) {
            cout << '#';
        }
        cout << endl << endl;
    }
}


Measured memory_bytes: 3108
N=int(input())
A=list(map(int,input().split()))
d=[[0]*(N+1) for i in range(N+1)]
for w in range(1,N+1):
    if w%2==N%2:
        for l in range(N+1-w):
            d[l][l+w]=max(d[l][l+w-1]+A[l+w-1],d[l+1][l+w]+A[l])
    else:
        for l in range(N+1-w):
            d[l][l+w]=min(d[l][l+w-1]-A[l+w-1],d[l+1][l+w]-A[l])
print(d[0][N])

Measured memory_bytes: 113244
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    char[][] m = new char[H][W];
    for (int i = 0; i < H; i++) {
      String s = sc.next();
      for (int j = 0; j < W; j++) {
        m[i][j] = s.charAt(j);
      }
    }
    
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (m[i][j] == '.') {
          System.out.print(count(m, i, j));
        } else {
          System.out.print(m[i][j]);
        }
      }
      System.out.println();
    }
  }
  
  private static int[] di = { -1, -1, -1,  0, 0,  1, 1, 1 };
  private static int[] dj = { -1,  0,  1, -1, 1, -1, 0, 1 };

  private static int count(char[][] m, int i, int j) {

    int ret = 0;
    for (int v = 0; v < 8; v++) {
      int ii = i + di[v];
      int jj = j + dj[v];
      if (0 <= ii && ii < m.length && 0 <= jj && jj < m[i].length
         && m[ii][jj] == '#') {
        ret++;
      }
    }
    return ret;
  }
}

Measured memory_bytes: 22228
#include <stdio.h>

#define INFTY 200000000
#define Max 100
#define White 0
#define Gray 1
#define Black 2

int num,M[Max][Max];

void Dijkstra(){

  int minv,u;
  int d[Max],color[Max];
  int i,v;
  
  for(i=0;i<num;i++){
    d[i]=INFTY;
    color[i]=White;
  }


  d[0]=0;
  color[0]=Gray;
  while(1){
    minv=INFTY;
    u=-1;

    for(i=0;i<num;i++){
      if(minv>d[i]&&color[i]!=Black){
	u=i;
	minv=d[i];
      }
    }

    if(u==-1)break;
    color[u]=Black;
    
    for(v=0;v<num;v++){
      if(color[v]!=Black && M[u][v]!=INFTY){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  
	  color[v]=Gray;
	}
      }
    }
  }

  
  for(i=0;i<num;i++){
   printf("%d %d\n",i,(d[i] == INFTY?-1:d[i]));
  }
  
 
}

int main(){
  int k,c,u,v;
  int i,j;
  scanf("%d",&num);

  for(i=0;i<num;i++){
    for(j=0;j<num;j++){
      M[i][j]= INFTY;
    }
  }
  for(i=0;i<num;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }
  
  Dijkstra();
  

  return 0;
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(){
	string S;
	cin >> S;
	if(S=="zyxwvutsrqponmlkjihgfedcba"){
		cout << -1 << endl;
		return 0;
	}
	vector<ll> count(26, 0);
	REP(i, S.size()) count[S[i]-'a']++;
	REP(i, 26){
		if(count[i]==0){
			cout << S << char('a'+i) << endl;
			return 0;
		}
	}
	vector<ll> perm(26);
	REP(i, S.size()) perm[i] = (S[i]-'a');
	next_permutation(perm.begin(), perm.end());
	REP(i, 26){
		char x = char('a'+perm[i]);
		if(x==S[i]) cout << x;
		else{
			cout << x;
			break;
		}
	}
	cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt(),B=sc.nextInt(),C=sc.nextInt();
		int cnt=Math.abs(A-B)/2;
		if(Math.abs(A-B)%2==1){
			cnt=cnt+1;
			C=C+1;
		}
		int big=A;
		if(big<B)big=B;
		if(C>big){
			cnt=cnt+C-big;
		}else{
			cnt=cnt+(big-C)/2;
			if((big-C)%2==1){
				cnt=cnt+2;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21588
#include <iostream>
#include <algorithm>

using namespace std;

int gcd(int a, int b) {
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

int main() {
	int a, b;
	cin >> a >> b;
	cout << gcd(a, b) << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main(){
    fastio;
    int x,y,z;
    cin >> x >> y>>z;
    cout << z <<" " << x <<" "<<y <<"\n";
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
	char s[10];
	cin>>s;
	if(s[0]=='a'&&s[1]=='b'&&s[2]=='c'){
		cout<<"Yes";
		return 0;
	}
	if(s[0]=='a'&&s[1]=='c'&&s[2]=='b'){
		cout<<"Yes";
		return 0;
	}
	if(s[0]=='b'&&s[1]=='a'&&s[2]=='c'){
		cout<<"Yes";
		return 0;
	}
	if(s[0]=='b'&&s[1]=='c'&&s[2]=='a'){
		cout<<"Yes";
		return 0;
	}
	if(s[0]=='c'&&s[1]=='a'&&s[2]=='b'){
		cout<<"Yes";
		return 0;
	}
	if(s[0]=='c'&&s[1]=='b'&&s[2]=='a'){
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256