akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    maximumDifference()
}

fun maximumDifference() {
    val n = readLine()!!.toInt()
    val numList = readLine()!!.split(" ").filter { it != "" }.map { it.toInt() }

    if (n != numList.size) return

    println(numList.max()!!.minus(numList.min()!!))
}

Measured memory_bytes: 37976
N = int(input())
min = 10**10
for i in range(1, int(N**0.5+1)):
    if N % i == 0:
        b = N // i
        if i <= b and len(list(map(int, str(b)))) < min:
            min = len(list(map(int, str(b))))
        elif i > b:
            break

print(min)


Measured memory_bytes: 39280
def agc011_b():
    N = int(input())
    A = sorted([0] + list(map(int, input().split())))

    cumsum = [0]
    for i in range(1, N+1):
        cumsum.append(cumsum[-1] + A[i])

    ans = 1
    for i in range(N-1, 0, -1):
        if cumsum[i] * 2 < A[i+1]:
            break  # 2倍しても次に小さい個体を吸収できないので、これ以下は生き残れない
        else:
            ans += 1
    print(ans)

agc011_b()

Measured memory_bytes: 14304
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def judge(W, H, x, y, r):
    if (x - r) >= 0 and (y - r) >= 0 and\
       (x + r) <= W and (y + r) <= H:
        print "Yes"
    else:
        print "No"

W, H, x, y, r = map(int, raw_input().split())

if -100 <= x <= 100 and -100 <= y <= 100 and \
   0 < W <= 100 and 0 < H <= 100 and 0 < r <= 100:
    judge(W, H, x, y, r)
else:
    print "error!!"
    sys.exit(0)

Measured memory_bytes: 4220
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000010;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	set<string> st;
	rep(i, n) {
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << st.size() << '\n';
}

Measured memory_bytes: 19272
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int max = a[n - 1];
		int min = max + 1;
		int mini = -1;
		for (int i = 0; i < n - 1; i++) {
			if (Math.min(Math.abs(a[i] - max / 2), Math.abs(a[i] - (max + 1) / 2)) < min) {
				min = Math.min(Math.abs(a[i] - max / 2), Math.abs(a[i] - (max + 1) / 2));
				mini = i;
			}
		}
		System.out.println(max + " " + a[mini]);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 23396
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;


int main(void){
    int N;
    cin >> N;
    int ans = -INF;
    vector<int> V(N), C(N);
    for(int i = 0; i < N; i++){
        cin >> V.at(i);
    }
    for(int i = 0; i < N; i++){
        cin >> C.at(i);
    }
    for(int i = 0; i < pow(2, N); i++){
        int x = 0,y = 0;
        vector<bool> X(N);
        int I = i;
        for(int j = 0; j < N; j++){
            X.at(j) = I % 2;
            I /= 2;
        }
        for(int j = 0; j < N; j++){
            if(X.at(j)){
                x += V.at(j);
                y += C.at(j);
            }
        }
        ans = max(ans, x-y);
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    long long N,i,A,B,C,D;
    A=0;B=0;C=0;D=0;
    for(i=0;i<4;i++){
        cin>>N;
        if(N==1){
            A=1;
        }else if(N==9){
            B=1;
        }else if(N==7){
            C=1;
        }else if(N==4){
            D=1;
        }
    }
    if(A*B*C*D){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}


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

int main() {
  int N,K;
  string S;
  cin >> N >> K;
  cin >> S;
  string S_new;
  for(int i=0; i<N; i++){
    if(i != K-1){
      S_new.push_back(S[i]);
    }
    else{
      if(S[i] == 'A') S_new.push_back('a');
      if(S[i] == 'B') S_new.push_back('b');
      if(S[i] == 'C') S_new.push_back('c');
    }
  }

  for(int i=0; i<N; i++){
    cout << S_new[i] << flush;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define ps(x,y) fixed<<setprecision(y)<<x
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out <<  "(" << a.F << ", " << a.S << ")";
}
 
template<class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out << "[";
	for (auto it = a.begin(); it != a.end(); ++it) {
		if (it != a.begin())
			out << ", ";
		out << *it;
	}
	return out << "]";
}
ll n;
vector<ll>adj[2005];
vector<vector<ll>>d(2005,vector<ll>(2005,100000));
void bfs(ll v){
	queue<ll>q;
	q.push(v);
	d[v][v]=0;
	while(!q.empty()){
		ll x=q.front();
		q.pop();
		for(auto p:adj[x]){
			if(d[v][p]>d[v][x]+1){
				d[v][p]=d[v][x]+1;
				q.push(p);
			}
		}
	}
}
int main()
{
    boost;
    ll i,j,x,t,y;
	cin>>n>>x>>y;
	for(i=1;i<n;i++) {
		adj[i].pb(i+1);
		adj[i+1].pb(i);
	}
	adj[x].pb(y);
	adj[y].pb(x);
	for(i=1;i<=n;i++){
		bfs(i);
	}
	vector<ll>ans(n+1,0);
	for(i=1;i<n;i++){
		for(j=i+1;j<=n;j++) ans[d[i][j]]++;
	}
	for(i=1;i<n;i++) cout<<ans[i]<<"\n";
}

Measured memory_bytes: 31872
#include <stdio.h>
 
int main(){
  int H,W,i,j;
  while(1){
    scanf("%d %d",&H,&W);
    if(H==0&&W==0){
      break;
    }
    for(i=0; i<H; i++){
      for(j=0; j<W; j++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    int a[N], b[N];
    ll e[51];
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];
    e[0] = 1;
    rep2(i, 1, 50) e[i] = 2*e[i-1];
    rep(i, N){
        if(a[i] != b[i] && a[i] <= 2*b[i]){
            cout << -1 << endl;
            exit(0);
        }
    }
    set<int> s[N];
    rep(i, N) s[i].insert(a[i]);
    int m[51][51];
    rep(i, 51){
        rep(j, 51){
            if(i == j) m[i][j] = 0;
            elif(i <= 2*j) m[i][j] = -1;
            else{
                rep2(k, 1, 50){
                    if(i%k == j || i%k > 2*j) {m[i][j] = k; break;}
                }
            }
            
        }
    }
    ll ans = 0;
    while(true){
        int use = 0;
        rep(i, N){
            int tmp = 50;
            set<int>::iterator ite = s[i].begin();;
            rep(j, s[i].size()){
                if(m[*ite][b[i]] >= 0) tmp = min(tmp, m[*ite][b[i]]);
                ite++;
            }
            use = max(use, tmp);
        }
        if(use == 0) break;
        ans += e[use];
        rep(i, N){
            set<int>::iterator ite = s[i].begin();;
            int n = s[i].size();
            int k[n];
            rep(j, n){
                k[j] = *ite % use;
                ite++;
            }
            rep(j, n){
                s[i].insert(k[j]);
            }
        }
    }
    cout << ans << endl;
}

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

int main()
{
    int a[1000],i,n;
    n=10;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }

    sort(a,a+n);

    int j;
    for(j=i-1;j>=7;j--)
    {
        printf("%d\n",a[j]);
    }


    return 0;
}

Measured memory_bytes: 1048
fun main(args: Array<String>) {
    var nsm = mapOf<Int, String>()
    var ism = mapOf<Int, Int>()
    for (i in 0 until readLine()!!.toInt()){
        var (x, y) = readLine()!!.split(" ")
        nsm = nsm.plus(y.toInt() to x)
        ism = ism.plus(y.toInt() to i)
    }
    var am = nsm.toList().sortedBy { it.first * -1 }.sortedBy { it.second }
    am.forEach {
        println(ism[it.first]!! + 1)
    }
}

Measured memory_bytes: 38488
import itertools

N, K = map(int, input().split())
X = []; Y = []
xy = []
for i in range(N):
  x, y= map(int, input().split())
  xy.append((x, y))
  X.append(x); Y.append(y)

ans = 10**20
x2 = list(itertools.combinations(X, 2))
y2 = list(itertools.combinations(Y, 2))

for xi, xj in x2:
  if xj < xi:
    xi, xj = xj, xi
  for yi, yj in y2:
    if yj < yi:
      yi, yj = yj, yi
    n = 0
    for x, y in xy:
      if xi<=x<=xj and yi<=y<=yj:
        n += 1
    if n >= K:
      ans = min(ans, (xj-xi)*(yj-yi))

print(ans)

Measured memory_bytes: 46940
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int a[] = new int[m];
            int b[] = new int[m];
            for (int i = 0; i < m; i++) {
                // 0-indexed
                a[i] = Integer.parseInt(in.next()) - 1;
                b[i] = Integer.parseInt(in.next()) - 1;
            }
            int ans[][] = new int[n][2];
            for (int i = 0; i < n; i++) {
                ans[i][0] = i;
                ans[i][1] = 0;
            }

            for (int i = 0; i < m; i++) {
                ans[a[i]][1]++;
                ans[b[i]][1]++;
            }

            // 出力
            for (int i = 0; i < n; i++) {
                out.println(ans[i][1]);
            }

        }

    }
}



Measured memory_bytes: 21840
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    string S;
    cin>>S;
    int64 N=S.length();
    int64 tmpR=0,tmpL=0,tmp=0,tmpodd=0,tmpeven=0;
    vector<int64> ans(N);

    for(int64 i=0;i<N;i++){
        
        if(S[i]=='R'){
            tmpR++;
            if(tmpR%2){
                tmpodd++;
            }else{
                tmpeven++;
            }
        }else{
            tmp=i;
            while(S[i]=='L'&&i<N){
                tmpL++;
                if(tmpL%2){
                    tmpeven++;
                }else{
                    tmpodd++;
                }
                i++;
            }
            i--;
            ans[tmp]=tmpeven;
            ans[tmp-1]=tmpodd;
            tmpR=0,tmpL=0,tmp=0,tmpodd=0,tmpeven=0;
        }
        
    }
    for(int64 i=0;i<N;i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node {
    int key;
    struct Node *right, *left, *parent;
};
typedef struct Node Node;

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key   = k;
    z->left  = NIL;
    z->right = NIL;
    
    while(x != NIL) {
        y = x;
        if(z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y == NIL) {
        root = z;
    } else {
        if( z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u) {
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
    
int main(void) {
    int n, i, x;
    char com[16];
    scanf("%d",&n);
    
    for(i=0;i<n;i++) {
        scanf("%s",com);
        if(!strcmp(com,"insert")) {
            scanf("%d",&x);
            insert(x);
        } else if(!strcmp(com,"print")) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


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

const int mxN = 2e5 + 5;
int N, h[mxN], a[mxN];
ll tree[4 * mxN];

ll query(int s, int e, int ql, int qr, int node) {
	if (ql <= s && qr >= e) {
		return tree[node];
	}
	if (qr < s || ql > e) {
		return 0;
	}
	int mid = s + (e - s) / 2;
	return max(query(s, mid, ql, qr, 2 * node), query(mid + 1, e, ql, qr, 2 * node + 1));
}

void update(int l, int r, int idx, ll val, int node) {
	if (l == r) {
		tree[node] = val;
	} else {
		int mid = l + (r - l) / 2;
		if (idx >= l && idx <= mid) {
			update(l, mid, idx, val, 2 * node);
		} else if (idx >= mid + 1 && idx <= r) {
			update(mid + 1, r, idx, val, 2 * node + 1);
		}
		tree[node] = max(tree[2 * node], tree[2 * node + 1]);
	}
}

int main() {
	ios_base::sync_with_stdio(false);

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	ll answer = 0;
	for (int i = 0; i < N; i++) {
		ll val = a[i] + query(1, N, 1, h[i] - 1, 1);
		answer = max(answer, val);
		update(1, N, h[i], val, 1);
	}
	cout << answer;

	return 0;
}

Measured memory_bytes: 9284
#include<cstdio>
#include<sstream>
#define MAX(x,y) ((x>y)?x:y)
using namespace std;

int main(){
	int i,j,x,sum,f,ans;
	char s[512];
	
	while(fgets(s,512,stdin)!=NULL){
		istringstream ss(s);
		f=sum=0;
		while(ss>>x){
			if(x==0)goto fin;
			if(x==1)f++;
			else if(x>9)sum+=10;
			else sum+=x;
		}
		ans=0;
		for(i=0;i<=f;i++){
			x=sum+i+11*(f-i);
			if(x>21)x=0;
			ans=MAX(ans,x);
		}
		printf("%d\n",ans);
	}
	fin:
	
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

int n,A,B,C;
vi l;

int dfs(int cnt, int a, int b, int c){
  if(cnt == n){
    if(a*b*c == 0) return 1e9;
    return abs(A-a) + abs(B-b) + abs(C-c) - 30;
  }

  int ret = 1e9;
  chmin(ret, dfs(cnt+1, a+l[cnt], b, c) + 10);
  chmin(ret, dfs(cnt+1, a, b+l[cnt], c) + 10);
  chmin(ret, dfs(cnt+1, a, b, c+l[cnt]) + 10);
  chmin(ret, dfs(cnt+1, a, b, c));

  return ret;
}

int main(){
  cin >> n >> A >> B >> C;
  l.resize(n);
  rep(i,n) cin >> l[i];

  cout << dfs(0,0,0,0) << endl;
}

Measured memory_bytes: 256
s = list(map(str, input().rstrip()))


def solve(s, d):
    arr = [0] * len(s)

    if d == "L":
        s = s[::-1]

    cnt = 0
    for i in range(len(s)):
        if s[i] == d:
            cnt += 1
        elif cnt > 0:
            arr[i - 1] += cnt // 2 + cnt % 2
            arr[i] += cnt // 2
            cnt = 0

    if d == "L":
        arr = arr[::-1]

    return arr


ans = [x + y for x, y in zip(solve(s, "R"), solve(s, "L"))]

print(*ans)

Measured memory_bytes: 7072
A=[]
for _ in range(3):
    A.append(list(map(int,input().split())))
n=int(input())
for _ in range(n):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                A[i][j]=-1
ans="No"
for i in range(3):
    if A[i]==[-1,-1,-1]:
        ans="Yes"
for i in range(3):
    if A[0][i]==-1 and A[1][i]==-1 and A[2][i]==-1:
        ans="Yes"
if A[0][0]==-1 and A[1][1]==-1 and A[2][2]==-1:
    ans="Yes"
if A[0][2]==-1 and A[1][1]==-1 and A[2][0]==-1:
    ans="Yes"
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

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

    int ans=0;
    for(int x=0; x<=N; x++){
        for(int y=0; y<=N-x; y++){
            for(int z=0; z<=N-x-y; z++){
                if(x+y+z != N) continue;
                if(10000*x + 5000*y + 1000*z ==  Y){
                    cout << x <<" " << y << " " << z << endl;
                    return 0;
                }
            }
        }
    }

    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include <cmath>
#define max 1000000
#define ll long long int
using namespace std;

int main() 
{
	ll n;
	cin>>n;
	
	vector<ll>v(n);
	
	for(ll i=0;i<n;i++)
	{
		cin>>v[i];
	}
	
	vector<ll>dp(n,max);
	
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	
	for(ll i=2;i<n;i++)
	{
		dp[i]=min((dp[i-1]+(abs(v[i]-v[i-1]))),(dp[i-2]+abs((v[i]-v[i-2]))));
	}
	
	cout<<dp[n-1]<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
package main

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

func main() {
	var a, i int
	var list []int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for scanner.Scan() {
		num, _ := strconv.Atoi(scanner.Text())
		if i == 0 {
			a = num
			i++
			continue
		}
		list = append(list, num)
		if i == a {
			break
		}
		i++
	}
	list, _, _ = insertSort(list, a)
}

func insertSort(array []int, n int) ([]int, int, int) {
	printArray(array)
	count := 0
	loop := 0
	// 1から
	for i := 1; i < n; i++ {
		// ループ時の値を保存
		v := array[i]
		// 前のindexを保存
		j := i - 1
		for {
			loop++
			// indexの例外を外す vとそれ以降の値を順番に比べていって、どんどん入れ替えていく。そして入れ替われなくなったらループを一つ抜ける。
			if j < 0 || array[j] <= v {
				break
			}
			// v と array[j]を比べて 左と右を入れ替える。
			array[j+1] = array[j]
			count++
			// 右から見ていく
			j--
		}
		array[j+1] = v
		printArray(array)
	}
	return array, count, loop
}

func printArray(ar []int) {
	str := ""
	for i, a := range ar {
		str += fmt.Sprintf("%d", a)
		if i < len(ar)-1 {
			str += " "
		}
	}
	fmt.Println(str)
}


Measured memory_bytes: 5368
data class Point(val x: Int, val y: Int)

fun distance(a: Point, b: Point) = Math.abs(a.x - b.x) + Math.abs(a.y - b.y)

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    val st = Array(n) {
        val (a, b) = readLine()!!.split(' ').map(String::toInt)
        Point(a, b)
    }
    val cp = Array(m) {
        val (c, d) = readLine()!!.split(' ').map(String::toInt)
        Point(c, d)
    }
    for (s in st) {
        var nearestDst = Int.MAX_VALUE
        var nearestIdx = -1
        for ((i, c) in cp.withIndex()) {
            val d = distance(s, c)
            if (d < nearestDst) {
                nearestDst = d
                nearestIdx = i
                if (d == 0) break
            }
        }
        println(nearestIdx + 1)
    }
}


Measured memory_bytes: 38128
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int n, x;
	cin >> n >> x;
	int l[105];
	for (int i = 1; i <= n; i++)
		cin >> l[i];
	int d = 0, ans = 1;
	for (int i = 1; i <= n; i++)
	{
		d += l[i];
		if (d <= x)ans++;
		else break;
	}
	cout << ans << endl;
	return 0;
}

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

int main(void){
  int N;
  cin>>N;
  int a;
  int temp=1;
  int ans=0;
  for (int i=0;i<N;i++){
    cin>>a;
    if(a!=temp){
      ans++;
      continue;
    }
    else temp++;
  }
  if(temp==1){
    cout<<-1<<endl;
    return 0;
  }
 
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  auto v = vector<vector<int>>(2, vector<int>(N));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> v[i][j];
    }
  }

  int ANS = 0;
  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = 0; j <= i; j++) {
      sum += v[0][j];
    }
    for (int j = i; j < N; j++) {
      sum += v[1][j];
    }
    ANS = max(ANS, sum);
  }
  cout << ANS << endl;
}


Measured memory_bytes: 3160
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX (1 << 29)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s)
    ret += to_string(x);
  return ret + "}";
}
template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  FOR(i, N) {
    int h;
    cin >> h;
    if (h >= K)
      ans++;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int x,t;
    cin >> x >> t;
    cout << max(0,x-t) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#define S 0
#define H 1
#define C 2
#define D 3


int main(int argc, const char * argv[]) {
    
    int card[4][13] = {};//4種類、１〜１３
    int n, num, i, j;
    
    char m;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf(" %c %d", &m, &num);
        switch(m){
            case 'S': card[S][num] = -1;
                break;
            case 'H': card[H][num] = -1;
                break;
            case 'C': card[C][num] = -1;
                break;
            case 'D': card[D][num] = -1;
                break;
        }
    }
    for(i = 0; i < 4; i++){
        for(j = 1; j < 14; j++){
            if(card[i][j] != -1){
                switch(i){
                    case S: putchar('S');
                        break;
                    case H: putchar('H');
                        break;
                    case C: putchar('C');
                        break;
                    case D: putchar('D');
                        break;
                }
                printf(" %d\n", j);
            }
        }
    }
        return 0;
    }


Measured memory_bytes: 2044
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.StringBuilder;
public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] st = sc.readLine().split(" ");
		int n = Integer.parseInt(st[0]);
		int m = Integer.parseInt(st[1]);
		int l = Integer.parseInt(st[2]);
		long[][] a = new long[n][m];
		long[][] b = new long[m][l];
		long t = 0;
		for(int i = 0;i < n;i++){
			st = sc.readLine().split(" ");
			for(int k = 0;k < m;k++){
				a[i][k] = Long.parseLong(st[k]);
			}
		}
		for(int i = 0;i < m;i++){
			st = sc.readLine().split(" ");
			for(int k = 0;k < l;k++){
				b[i][k] = Long.parseLong(st[k]);
			}
		}
		for(int i = 0;i < n;i++){
			for(int k = 0;k < l;k++){
				for(int j = 0;j < m;j++){
					t += a[i][j]*b[j][k];
				}
				sb.append(t);
				t = 0;
				if(k!=l-1)
					sb.append(" ");
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 32672
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int MAXN = 10 + 1e6;
const ll oo = 1 + 1e18;
const ll mod = 7 + 1e9;

int x, y;

int main()
{
    #define TASK "ABC"
    #ifndef ONLINE_JUDGE
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
    #endif ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> x >> y;

    for (int i = 0; i <= x; i++)
    {
        for (int j = 0; j <= x; j++)
        {
            if (i * 2 + j * 4 == y && i + j == x) {
                cout << "Yes";
                return 0;
            }
        }
    }

    cout << "No";


    return 0;
}




















































































Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>

typedef long long int ll;

using namespace std;

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

    vector<int> a(n), b(m);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];

    vector<ll> as(n+1), bs(m+1);
    for (int i = 1; i < n+1; i++) as[i] = as[i - 1] + a[i - 1];
    for (int i = 1; i < m+1; i++) bs[i] = bs[i - 1] + b[i - 1];

    int val = 0;
    for (int i = 0; i < n+1; i++) {
        if (k < as[i]) break;
        int j = lower_bound(bs.begin(), bs.end(), k - as[i] + 1) - bs.begin() - 1;
//      int j = 0;
//      for (j = 0; j < m; j++) {
//          if (bs[j + 1] > k - as[i]) break;
//      }

        val = max(val, i + j);
    }

    cout << val << endl;

    return 0;
}

Measured memory_bytes: 8024
use proconio::input;

fn main() {
    input! {
        k: usize,
    }
    let mut all: Vec<i64> = Vec::new();
    for i in 1..=9 {
        dfs(1, i, i, &mut all);
    }
    all.sort();
    println!("{}", all[k - 1]);
}

fn dfs(d: usize, prev: i64, n: i64, all: &mut Vec<i64>) {
    all.push(n);
    if d == 10 {
        return;
    }

    for i in prev - 1..=prev + 1 {
        if i < 0 || i > 9 {
            continue;
        }
        let next = n * 10 + i;
        dfs(d + 1, i, next, all);
    }
}


Measured memory_bytes: 4344
import sys
from collections import deque
import bisect

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()

    yaku = [0] * (N + 1)

    for i in range(1, N + 1):
        for j in range(i, N + 1, i):
            yaku[j] += 1

    ans = 0
    for i in range(1, N + 1):
        ans += i * yaku[i]

    print(ans)


if __name__ == '__main__':
    main()


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    string S;
    ll abc[3] = {};
    ll maxi = 0;
    ll mini = numeric_limits<ll>::max();
    cin >> S;
    iter(c, S) abc[c - 'a']++;
    iter(i, abc) {
        maxi = max(maxi, i);
        mini = min(mini, i);
    }
    cout << (S.size() == 1 || maxi - mini <= 1 ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n; cin >> n;
  vector<int> p(n);
  REP(i, n) {
    cin >> p[i]; --p[i];
  }
  int ans = 0;
  REP(i, n - 1) {
    if (p[i] == i) {
      swap(p[i], p[i + 1]);
      ++ans;
    }
  }
  if (p[n - 1] == n - 1) ++ans;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
#define INF 1e15
#define MOD 1000000007

#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
typedef pair<int, int> P;
#define END system("PAUSE");return 0
int a, b;
int t[45];
int cnt[45];
signed main() {
	cin >> a >> b;
	t[0] = 1;
	for (int i = 1; i < 45; i++)t[i] = t[i - 1] * 2;
	rep(i, 44) {
		cnt[i] += ((b / t[i + 1])*t[i]) + max(0ll,( b%t[i + 1]) - t[i] + 1);
	}
	a--;
	rep(i, 44) {
		cnt[i] -= ((a / t[i + 1])*t[i]) + max(0ll, (a%t[i + 1]) - t[i] + 1);
	}
	int ans = 0;
	rep(i, 44) {
		if (cnt[i] % 2)ans += t[i];
	}
	cout << ans << endl;
	END;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  sum+=2*(N/11);
  N%=11;
  if(N>6)sum+=2;
  else if(N>0)sum++;
  Out(sum);
}

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

int main() {
	int N, subans, ans;
	cin >> N;
	int H[N+1];
	for(int k = 0; k < N; k++){
		cin >> H[k];
	}
	H[N] = 1000000002;
	subans = 0;
	ans = 0;
	for(int i = 0; i < N; i++){
		if(H[i+1] <= H[i]){
			subans++;
		}else{
			if(ans < subans){
				ans = subans;
			}
			subans = 0;
		}

	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3884
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,i,d,c,j,ans;
    
    cin>>n>>k;
    ans=n;
    int a[n+1]={0};
    while(k--){
        cin>>d;
        for(i=0;i<d;i++){cin>>c;
            if(!a[c])ans--;
            a[c]=1;
        }
    }cout<<ans;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  string S;
  cin>>S;
  ll ans=0;
  ll red=0;
  for(ll i=0;i<N;i++) {
    if(S[i]=='W') {
for(ll j=red;j<N-i-1;j++) {
 if( S[N-1-j]=='R') {
ans++;
   red=j+1;
   break;
 }
  if(j==N-i-2) {
red=j+1;
  }
}
      if(red==N-i-1) {
break;
      }
     
    
    }
  }
  
  cout<<ans<<endl;
}
   
  
  
  
  
  
  
  
  
  
  
  


Measured memory_bytes: 3688
from collections import defaultdict
s=input()
cnt=defaultdict(lambda :0)

for i in s:
    cnt[i]+=1

if cnt['N']*cnt['S']==0 and (cnt['N']+cnt['S'])>0:
    print('No')
elif cnt['E']*cnt['W']==0 and (cnt['E']+cnt['W'])>0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3316
#include <iostream>
#include <queue>
#include <assert.h>   
#include <vector>
#include <algorithm>
#include <time.h>
#include <numeric>
#include <string>
#include <cstring>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <numeric>
#include <deque>
#include <iomanip>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <cstdio>
using namespace std;


//#define double long double
//#define int long long
//#define int unsigned long long

#define ll long long
#define ld long double 
#define pi pair<int, int> 
#define pl pair<ll,ll>  
#define pd pair<ld,ld> 
#define str string  
#define mp make_pair
#define vi vector<int> 
#define vl vector<ll> 
#define vd vector<ld> 
#define vs vector<str> 
#define vpi vector<pi> 
#define vpl vector<pl> 
#define vpd vector<pd> 
#define si set<int> 
#define FF(i,j,n) for(signed i=j;i<=n;i++)  
#define DD(i,j,n) for(signed i=j;i>=n;i--) 
#define F(i,j,n) for(signed i=j;i<n;i++)   
#define D(i,j,n) for(signed i=j;i>n;i--) 
#define mem(a,b) memset(a,b,sizeof(a))
#define ndl cout << endl
#define ull unsigned long long 

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;


#define sz(x) (signed)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() 
#define rsz resize
#define ins insert 
#define ft front() 
#define bk back() 
#define fi first
#define se second
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define lb lower_bound 
#define ub upper_bound 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

//math


const int mod = 1e9 + 7;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int pct(int x) { return __builtin_popcount(x); } 
int bit(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) 
int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0 


//DEBUG, compile with -DLOCAL
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
  cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
  DBG(t...); }
#ifdef LOCAL 
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#define HERE cout << "===GOTHERE===" << endl
#else
#define dbg(...) 42
#define HERE 42
#endif


 /* ============== END OF HEADER ============== */





const int maxn = 1e5*3+20;

int n,_,q,k;
int a[maxn];

void solve(){
	cin >> n >> k;
	FF(i,1,n){
		cin >> a[i];
	}
	double ans = 0.0;
	double sum = 0.0;
	F(j,1,1+k){
		sum += ((1.0/a[j]) * ((a[j] * (a[j]+1))/2));
		ans = max(ans, sum);
	}
	FF(j,k+1,n){
		sum -= ((1.0/a[j-k]) * ((a[j-k] * (a[j-k]+1))/2));
		sum += ((1.0/a[j]) * ((a[j] * (a[j]+1))/2));
		ans = max(ans, sum);
	}

	cout << fixed << setprecision(10) << ans << endl;
}

signed main(){
  //clock_t t1 = clock();  
	IOS
	solve();
  
  //cout << "THE ALGORITHM TOOK: " << (clock() - t1) * 1.0 / CLOCKS_PER_SEC * 1000 << "ms"<< endl;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5 + 5;

struct Segment_Tree
{
	int mx[MAXN<<2], tag[MAXN<<2];
	#define ls(u) ((u)<<1)
	#define rs(u) ((u)<<1|1)
	#define lson(u) ls(u),l,mid
	#define rson(u) rs(u),mid+1,r
	inline void push_up(int u){ mx[u] = max(mx[ls(u)], mx[rs(u)]);}
	inline void push_down(int u)
	{
		if(~tag[u])
		{
			mx[ls(u)] = tag[ls(u)] = tag[u];
			mx[rs(u)] = tag[rs(u)] = tag[u];
			tag[u] = -1;
		}
	}
	void build(int u,int l,int r,int k)
	{
		mx[u]=k; tag[u]=-1;
		if(l==r) return;
		int mid = (l+r)>>1;
		build(lson(u),k); build(rson(u),k);
	}
	void update(int u,int l,int r,int ql,int qr,int k)
	{
		if(ql<=l && r<=qr){ mx[u]=tag[u]=k; return;}
		push_down(u);
		int mid = (l+r)>>1;
		if(ql<=mid) update(lson(u),ql,qr,k);
		if(mid<qr) update(rson(u),ql,qr,k);
		push_up(u);
	}
	int query(int u,int l,int r,int q)
	{
		if(l==r) return mx[u];
		push_down(u);
		int mid = (l+r)>>1;
		if(q<=mid) return query(lson(u),q);
		else return query(rson(u),q);
	}
	int find_greater(int u,int l,int r,int k)
	{
		if(mx[u] <= k) return r+1;
		if(l==r) return l;
		push_down(u);
		int mid = (l+r)>>1;
		if(mx[ls(u)] > k) return find_greater(lson(u),k);
		else return find_greater(rson(u),k);
	}
};

int main(void)
{
	int n,Q;
	scanf("%d%d",&n,&Q);
	
	ll ans = (ll)(n-2) * (n-2);
	
	static Segment_Tree up,lef;
	up.build(1,1,n,n-1); lef.build(1,1,n,n-1);
	
	while(Q--)
	{
		int oper,x;
		scanf("%d%d",&oper,&x);
		if(oper == 1)
		{
			int to = lef.query(1,1,n, x);
			ans -= to-1;
			int pos = up.find_greater(1,1,n, x-1);
			if(pos <= to) up.update(1,1,n, pos,to,x-1);
		}
		else
		{
			int to = up.query(1,1,n, x);
			ans -= to-1;
			int pos = lef.find_greater(1,1,n, x-1);
			if(pos <= to) lef.update(1,1,n, pos,to,x-1);
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 9940
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    int n,m;
    cin >> n >> m;

    if(m==0){
        if(n==1){
            cout << 0 << endl;
            return 0;
        }else{
            string s(n,'0');
            s[0]='1';
            cout << s << endl;
            return 0;
        }
    }

    map<int,int> sc;
    for(int i=0;i<m;i++){
        int s,c;
        cin >> s >> c;
        if(sc.find(s)!=sc.end() && sc.at(s)!=c){
            cout << -1 << endl;
            return 0;
        }else{
            sc.insert(make_pair(s,c));
        }
    }

    string ans(n,'0');
    auto it=sc.begin();
    for(int i=1;i<=n;i++){
        if(it==sc.end())break;
        if(it->first!=i){
            if(i==1)ans[i-1]='1';
            continue;
        }else{
            if(i==1 && it->second==0){
                if(n==1)ans[i-1]='0';
                else{
                    cout << -1 << endl;
                    return 0;
                }
            }else{
                ans[i-1]=it->second+'0';
            }
        }
        it++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <utility>
#include <stack>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int,int> pii;
int dp[100][100];
bool dfs(int x,int y){
    if(dp[x][y]!=-1){
        return dp[x][y] == 1;
    }
    if(x<=1 and y<=1)return dp[x][y] = 0;
    for(int i = 1; i <= x/2; i++){
        if(dfs(x-2*i,y+i)==0){
            return dp[x][y] = 1;
        }
    }
    for(int i = 1; i <= y/2; i++){
        if(dfs(x+i,y-2*i)==0){
            return dp[x][y] = 1;
        }
    }
    return dp[x][y] = 0;
}
int main(){
    // rep(i,100)rep(j,100)dp[i][j] = -1;
    // rep(i,10){
    //     rep(j,10){
    //         cout << dfs(i,j);
    //     }
    //     cout << endl;
    // }
    ll x,y;
    cin >> x >> y;
    if(abs(x-y)<=1){
        cout << "Brown" << endl;
    }else{
        cout << "Alice" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class set{
public:
    bool white;
    int length;
    set(bool w,int l):white(w),length(l){}
    set(bool w):white(w),length(1){}
};
int main(){
    int time;
    while(cin>>time&&time){
        vector<set> line;
        for(int i=0;i<time;++i){
            int color;
            cin>>color;
            if(i%2==0){
                if(line.empty()){
                    line.push_back(set(color==0));
                }else{
                    if((color==0)==line.back().white){
                        ++line.back().length;
                    }else{
                        line.push_back(set(color==0));
                    }
                }
            }else{
                if((color==0)==line.back().white){
                    ++line.back().length;
                }else{
                    int num = line.back().length+1;
                    line.pop_back();
                    if(line.empty()){
                        line.push_back(set(color==0,num));
                    }else{
                        line.back().length+=num;
                    }
                }
            }
        }
        int num = 0;
        for(int i=0;i<line.size();++i){
            if(line[i].white){
                num+=line[i].length;
            }
        }
        cout<<num<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084