akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int cnt[10];

int main() {
  int n;
  cin>>n;
  for (int i=0; i<n; i++) {
    int x;
    cin>>x;
    if (x<3200) cnt[x/400]++;
    else cnt[8]++;
  }
  int cnt2=0;
  for (int i=0; i<8; i++) {
    if (cnt[i]) cnt2++;
  }

  if (cnt[8]==n) cout<<1<<" "<<n<<endl;
  else cout<<cnt2<<" "<<cnt2+cnt[8]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
using namespace std;
int main(){
  int n;
  cin >> n;
  int p[n],q[n];
  REP(i,n) cin >> p[i];
  REP(i,n) cin >> q[i];
  vector<int> vp,vq;
  REP(i,n) vp.push_back(i);
  REP(i,n) vq.push_back(i);
  int sum1,sum2,ans;
  
  int sum = 1;
  do{
    bool flag = true;
    for(int i=0; i<n; i++){
      if(vp[i]+1 != p[i]){
        flag = false;
      }
    }
    if(flag){
      sum1 = sum;
      break;
    }
    else sum++;
  }while(next_permutation(vp.begin(),vp.end()));
  
  sum = 1;
  do{
    bool flag = true;
    for(int i=0; i<n; i++){
      if(vq[i]+1 != q[i]){
        flag = false;
      }
    }
    if(flag){
      sum2 = sum;
      break;
    }
    else sum++;
  }while(next_permutation(vq.begin(),vq.end()));
  
  
  ans = abs(sum1 - sum2);
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(ll i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


int N, M;
int a[300], b[300];

vector<int> G[1000000];
vector<pair<int, int> > bridge;
vector<int> articulation;
int ord[1000000], low[1000000];
bool vis[1000000];

void dfs(int v, int p, int &k)
{
	vis[v] = true;
	
	ord[v] = k++;
	low[v] = ord[v];
	
	bool isArticulation = false;
	int ct = 0;
	
	for (int i = 0; i < G[v].size(); i++){
		if (!vis[G[v][i]]){
			ct++;
			dfs(G[v][i], v, k);
			low[v] = min(low[v], low[G[v][i]]);
			if (~p && ord[v] <= low[G[v][i]]) isArticulation = true;
			if (ord[v] < low[G[v][i]]) bridge.push_back(make_pair(min(v, G[v][i]), max(v, G[v][i])));
		}
		else if (G[v][i] != p){
			low[v] = min(low[v], ord[G[v][i]]);
		}
	}
	
	if (p == -1 && ct > 1) isArticulation = true;
	if (isArticulation) articulation.push_back(v);
}



int main(void) {
	cin >> N >> M;
	rep(i, M) cin >> a[i] >> b[i];
	rep(i, M) a[i]--, b[i]--;
	rep(i, M) G[a[i]].pb(b[i]), G[b[i]].pb(a[i]);
	int ans = 0;
	
	int k = 0;
	for (int i = 0; i < N; i++){
		if (!vis[i]) dfs(i, -1, k);
	}

	sort(bridge.begin(), bridge.end());
	sort(articulation.begin(), articulation.end());

	printf("%d\n", bridge.size());
	return 0;
}

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

bool calc(vector<string> const &chars, vector<int> const &hswap, vector<int> const &wswap, vector<vector<int>> const &hgv, vector<vector<int>> const &wgv) {
    for (auto hs: hswap) {
        for (auto ws: wswap) {
            if (hs == -1 || ws == -1) continue;
            assert(hgv[hs].size() == 2);
            assert(wgv[ws].size() == 2);
            int y1 = hgv[hs][0];
            int x1 = wgv[ws][0];
            int y2 = hgv[hs][1];
            int x2 = wgv[ws][1];
            if (chars[y1][x1] != chars[y2][x2]) return false;
        }
    }
    return true;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> chars(h);
    for (int i = 0; i < h; i++) {
        cin >> chars[i];
    }

    vector<map<char,int>> cnth(h);
    vector<map<char,int>> cntw(w);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cnth[i][chars[i][j]]++;
            cntw[j][chars[i][j]]++;
        }
    }

    vector<int> hg(h, -1), wg(w, -1);
    int hgc = 0, wgc = 0;
    {
        int &g = hgc;
        for (int i = 0; i < h; i++) {
            if (hg[i] != -1) continue;
            for (int j = i+1; j < h; j++) {
                if (hg[j] != -1) continue;
                if (cnth[i] == cnth[j]) {
                    hg[i] = hg[j] = g++;
                    break;
                }
            }
        }
        if (g != h/2) { cout << "NO" << endl; return 0; }
    }

    {
        int &g = wgc;
        for (int i = 0; i < w; i++) {
            if (wg[i] != -1) continue;
            for (int j = i+1; j < w; j++) {
                if (wg[j] != -1) continue;
                if (cntw[i] == cntw[j]) {
                    wg[i] = wg[j] = g++;
                    break;
                }
            }
        }
        if (g != w/2) { cout << "NO" << endl; return 0; }
    }

    vector<vector<int>> hgv(h/2), wgv(w/2);
    for (int i = 0; i < h; i++) {
        // cout << hg[i] << endl;
        if (hg[i] != -1) hgv[hg[i]].push_back(i);
    }
    for (int i = 0; i < w; i++) {
        // cout << wg[i] << endl;
        if (wg[i] != -1) wgv[wg[i]].push_back(i);
    }

    vector<int> hswap(hgc), wswap(wgc);
    iota(hswap.begin(), hswap.end(), 0);
    iota(wswap.begin(), wswap.end(), 0);

    do {
        do {
            // cout << "testing [";
            // copy(hswap.begin(), hswap.end(), ostream_iterator<int>(cout, ","));
            // cout << "] and [";
            // copy(wswap.begin(), wswap.end(), ostream_iterator<int>(cout, ","));
            // cout << "]" << endl;
            if (calc(chars, hswap, wswap, hgv, wgv)) {
                cout << "YES" << endl;
                return 0;
            }
        } while (next_permutation(wswap.begin(), wswap.end()));
    } while (next_permutation(hswap.begin(), hswap.end()));

    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a int
	var b int
    fmt.Scan(&a)
	fmt.Scan(&b)
	if (a+b)%2 > 0 {
		fmt.Println("IMPOSSIBLE")
	} else {
		fmt.Println((a+b)/2)
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int H,W,D;
  cin >> H >> W >> D;
  vector<pair<int,int>> A(H*W,make_pair(0,0));
  int tmp;
  for(int y=0;y<H;y++){
    for(int x=0;x<W;x++){
      cin >> tmp;
      A[tmp-1] = make_pair(x,y);
    }
  }
  vector<vector<pair<int,int>>> B(D);
  for(int i=0;i<H*W;i++){
    B[i%D].pb(A[i]);
  }
  vector<vector<ll>> cost(D,vector<ll>((int)B[0].size()));
  rep(i,D){
    cost[i][0]=0;
    for(int j=1;j<(int)cost[i].size();j++){
      cost[i][j] =
        (
          cost[i][j-1]
          + abs(B[i][j].first-B[i][j-1].first)
          + abs(B[i][j].second-B[i][j-1].second)
        );
    }
  }
  int Q;
  cin >> Q;
  ll l,r;
  rep(i,Q){
    cin >> l >> r;
    cout << cost[(r-1)%D][(r-1)/D] - cost[(l-1)%D][(l-1)/D] << endl;
  }

  return 0;
}


Measured memory_bytes: 11008
#include<stdio.h>
#include<string.h>

int main(void){
    int N;
    scanf("%d", &N);
    char S[N+1];
    scanf("%s", S);

    int max = N;
    int ans = max;

    int idx;
    int i;
    int flag = 1;

    for(i = 0; i < N-1; i++){
        if(S[i] != S[i+1]){flag = 0; break;}
    }
    

    //これだと(2*10^5)^2で10^10以上で間に合わなさそうなので
    //累積和を使ってO(n)チックにしたい
    /*for(idx = 1; idx <= N-1; idx++){
        for(i = 0; i < idx; i++){if(S[i] == '#')left++;}
        for(i = idx; i < N; i++){if(S[i] == '.')right++;}
        if(ans > (left+right)){ans = left+right;}
        left = 0;
        right = 0;
    }*/

    int lc[N+1];
    lc[0] = 0;
    for(idx = 0; idx < N; idx++){
        if(S[idx] == '#'){lc[idx+1] = lc[idx] + 1;}
        //これ（真下）がないと、何も代入されてない要素ができてしまう
        else{lc[idx+1] = lc[idx];}
        //printf("idx+1:%d, lc[%d]:%d\n", idx+1, idx+1, lc[idx+1]);
    }
    int rc[N+1];
    rc[N] = 0;
    for(idx = N-1; idx >= 0; idx--){
        if(S[idx] == '.'){rc[idx] = rc[idx+1] + 1;}
        else{rc[idx] = rc[idx+1];}
        //printf("idx1:%d, rc[%d]:%d\n", idx, idx, rc[idx]);
    }

    for(i = 0; i < N+1; i++){
        if(ans > lc[i] + rc[i]){ans = lc[i] + rc[i];}
    }
    
    if(flag == 1){printf("0\n");}
    else{printf("%d\n", ans);}
    return 0;
}

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

using namespace std;
int main(){
  int n;cin>>n;
  vector<pair<int,int>> v;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    v.push_back(make_pair(a,i+1));
  }
  sort(v.begin(),v.end());
  for(int i=0;i<n;i++){
    cout<<v[i].second<<" ";
  }
  
  
  
}

Measured memory_bytes: 1780
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>

using namespace std;

// http://d.hatena.ne.jp/pogin/20121001/1349069143
inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

template<class T> inline string toString(T x) {
	ostringstream sout;
	sout << x;
	return sout.str();
}

int is_same_value(int n, int a[], int max) {
	for (int i = 0; i < max; i++) {
		if(a[i] == n) {
			return i;
		}
	}
	
	return -1;
}

int main() {
	while (true) {
		string tmp;
		int L;
		int a[21];
		int n = 0;
		cin >> tmp >> L;
		if (L == 0) {
			break;
		}

		for (int i = 0; i < 21; i++) {
			a[i] = 0;
		}
		int a0_length = tmp.length();
		if (a0_length < L) {
			for (int i = a0_length; i < L; i++) {
				tmp.insert(0, "0");
			}
		}
		//cout << "a0: " << tmp << endl;
		a[0] = toInt(tmp);
		
		while (true) {
			n++;
			string min = tmp;
			sort(min.begin(), min.end());
			string max = min;
			reverse(max.begin(), max.end());
			//cout << "max: " << max << " min: " << min << endl;
			int next = toInt(max) - toInt(min);
			a[n] = next;
			//cout << "a" << n << ": " << a[n] << endl;
			int j = is_same_value(a[n], a, n);
			if (j != -1) {
				cout << j << " " << a[n] << " " << n - j << endl;
				break;
			}
			tmp = toString<int>(next);
			for (int i = tmp.length(); i < L; i++) {
				tmp.insert(0, "0");
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1252
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

int main() {
	int i, zero = 0, one = 0;
	string S;
	cin >> S;
	REP(i, (int)S.size()) {
		if (i % 2 == 0) {
			if (S[i] == '0')
				zero++;
			else
				one++;
		}
		else {
			if (S[i] == '1')
				zero++;
			else
				one++;
		}

	}
	cout << min(zero,one) << endl;
	return 0;
}

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

int main(){
   string A,B;
   cin>>A>>B;
  
   if(A!="1"&&B!="1"){
      cout<<1<<endl;
   }
   if(A!="2"&&B!="2"){
      cout<<2<<endl;
   }
   if(A!="3"&&B!="3"){
      cout<<3<<endl;
   }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, m = -1;
   string s;
   map<string, int> mp;

   cin >> n;
   FOR(i, 0, n)
   {
      cin >> s;
      mp[s] += 1;
   }

   for (auto x : mp)
   {
      m = max(m, x.second);
   }

   for (auto x : mp)
   {
      if (x.second == m)
         cout << x.first << endl;
   }

   return 0;
}


Measured memory_bytes: 25216
from collections import defaultdict
from functools import reduce
N = int(input())
A = [int(x) for x in input().split()]
def isExist(N, A):
  AD = defaultdict(int)
  for a in A:
    AD[a] += 1
  keys = len(AD.keys())
  xor = reduce(lambda x, y: x^y, A)
  mlen = min([a for a in AD.values()])
  if xor != 0:
    return 'No'
  if keys == 1:
    return 'Yes'
  if keys == 2 and N % 3 == 0 and mlen == N // 3:
    return 'Yes'
  if keys == 3 and N % 3 == 0 and mlen == N // 3:
    return 'Yes'
  return 'No'
print(isExist(N, A))

Measured memory_bytes: 14708
#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 ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	set<int> st;
	st.insert(1);
	st.insert(2);
	st.insert(3);
	int a, b; cin >> a >> b;
	st.erase(a);
	st.erase(b);
	cout << *st.begin() << endl;
}

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


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

ll dp[105][100005];
int weight[105];
int value[105];

int main() {
    int n, w;
    cin >> n >> w;
    rep(i, n) {
        cin >> weight[i] >> value[i];
    }

    rep(i, n) {
        rep(x, w + 1) {
            if (x - weight[i] >= 0)
                dp[i + 1][x] = max(dp[i][x], dp[i][x - weight[i]] + value[i]);
            else
                dp[i + 1][x] = dp[i][x];

            // debug(i);
            // debug(x);
            // debug(dp[i][x]);
        }
    }

    out(dp[n][w]);
    return 0;
}


Measured memory_bytes: 79360
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();   
        int H, W;
        {int[] a = r.ii(); H = a[0]; W = a[1];}
        char[][] a = new char[H][W];
        boolean[] hIs = new boolean[H],
        wIs = new boolean[W];
        for(int i = 0; i < H; i++){
            String s = r.s();
            for(int j = 0; j < W; j++){
                a[i][j] = s.charAt(j);
            }
        }
        for(int i = 0; i < H; i++){
            hIs[i] = false;
            for(int j = 0; j < W; j++){
                if(a[i][j] == '#'){
                    hIs[i] = true;
                    break;
                }
            }
        }
        for(int j = 0; j < W; j++){
            wIs[j] = false;
            for(int i = 0; i < H; i++){
                if(a[i][j] == '#'){
                    wIs[j] = true;
                    break;
                }
            }
        }
        for(int i = 0; i < H; i++){
            if(hIs[i]){
                for(int j = 0; j < W; j++){
                    if(wIs[j]){
                        print(a[i][j]);
                    }
                }
                print("\n");
            }
        }
    }

    static void print(Object o){
        System.out.print(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int Int(String s){
            return Integer.parseInt(s);
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}

Measured memory_bytes: 25428
#include<bits/stdc++.h>
using namespace std;
long long h,w,dp[1005][1005],a[1005][1005];
long long solve(long long i,long long j)
{
    if(i==h+1 || j==w+1)
    return 0;
    if(i==h && j==w)
    return 1;
    if(dp[i][j]!=-1)
    return dp[i][j];
    dp[i][j]=0;
    if(a[i][j+1]==0)
    dp[i][j]=(dp[i][j]+solve(i,j+1)%1000000007)%1000000007;
    if(a[i+1][j]==0)
    dp[i][j]=(dp[i][j]+solve(i+1,j)%1000000007)%1000000007;
    return dp[i][j]%1000000007;
}
int main()
{
    cin>>h>>w;
    for(int i=0;i<=h;i++)
    {
        for(int j=0;j<=w;j++)
        dp[i][j]=-1;
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            char x;
            cin>>x;
            if(x=='.')
            a[i][j]=0;
            else
            a[i][j]=1;
        }
    }
  /*  for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        cout<<a[i][j]<<" ";
        cout<<'\n';
    }*/
    cout<<solve(1,1);
    return 0;
}

Measured memory_bytes: 16128
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 210000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
// long long C(int a,int b){
// 	if(a<b||b<0)return 0;
// 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
// }
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	if(a+b==15)printf("+\n");
	else if(a*b==15)printf("*\n");
	else printf("x\n");
}

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

int main() {
  ll N;
  ll M;
  cin >> N >> M;
  vector<ll> H(N+1);
  vector<int> good(N+1);
  
  for(ll i=1;i<N+1;i++){
    cin >> H.at(i);
  }
  
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    if(H.at(a) > H.at(b)){
      good.at(b) = 1;
    }else if(H.at(a) < H.at(b)){
      good.at(a) = 1;
    }else{
      good.at(a) = 1;
      good.at(b) = 1;
    }
  }
  
  ll cnt = 0;
  for(ll i=1;i<N+1;i++){
    if(good.at(i) == 0){
      cnt++;
    }
  }
  
  cout << cnt << endl;
  
  return(0); 
}


Measured memory_bytes: 4580
from functools import reduce
import math

while True:
    n = int(input())
    if ( n == 0 ):
        break
    l  =  list(map(int,input().split()))
    mean = float(reduce(lambda a,b:a+b,l)) / (len(l))
    t = 0
    for i in l:
        t += pow((i - mean),2)
    bunsan = float(t) / len(l)
    print (math.sqrt(bunsan))


Measured memory_bytes: 6332
#include<stdio.h>

int main(){
      int H,N;
      scanf("%d %d",&H,&N);
      int A[N];
      for(int i=0;i<N;i++){
         scanf("%d",&A[i]);
      }
      
      for(int j=0;j<N;j++){
         H=H-A[j];
      }
      if(H<=0){
         printf("Yes");
      }else{
         printf("No");
      }
      return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int lli;
#define optimize ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define F first
#define S second
#define forn(i,n) for(int i = 0; i<n; i++)
#define forab(i,a,b) for(int i = a; i<b; i++)
#define forll(i,a,b) for(lli i = a; i<b; i++)
#define mp make_pair
#define pb push_back
#define sortv(v) sort(v.begin(), v.end())
#define debug(x) cout<<#x<<" : "<<x<<endl
#define all(x) x.begin(),x.end()
#define printv(v) for(auto it : v) cout<<it<<" ";cout<<endl;
#define prec(n) fixed<<setprecision(n)
const int mod1 = 1000000007;
const int mod2 = 998244353;
const int N = 1e5;

vector<vector<char>>grid;

bool islegal(int tx, int ty, int h, int w)
{
	if(tx<0 || tx >= h || ty<0 || ty >= w || grid[tx][ty] == '#')
		return false;
	return true;
}

int main()
{
	optimize

	#ifndef ONLINE_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
	#endif

	int h,w;
	cin>>h>>w;
	int cx,cy,dx,dy;
	cin>>cx>>cy>>dx>>dy;
	cx--;cy--;dx--;dy--;
	grid = vector<vector<char>>(h, vector<char>(w));
	
	forn(i,h)
	{
		forn(j,w)
			cin>>grid[i][j];
	}

	vector<pii>dir = {{0,1},{1,0},{-1,0},{0,-1}};
	vector<vector<int>>dist(h, vector<int>(w, 1000000));
	dist[cx][cy] = 0;
	deque<int>qx;
	deque<int>qy;
	qx.push_back(cx); qy.push_back(cy);

	while(!qx.empty())
	{
		int x = qx.front(); qx.pop_front();
		int y = qy.front(); qy.pop_front();

		forn(i,4)
		{
			int tx = x+dir[i].F;
			int ty = y+dir[i].S;

			if(!islegal(tx,ty,h,w))
				continue;
			if(dist[tx][ty] > dist[x][y])
			{
				dist[tx][ty] = dist[x][y];
				qx.push_front(tx);
				qy.push_front(ty);	
			}
		}
		for(int i = x-2; i<=x+2; i++)
		{
			for(int j = y-2; j<=y+2; j++)
			{
				if(!islegal(i,j,h,w))
					continue;
				if(dist[i][j] > dist[x][y])
				{
					dist[i][j] = dist[x][y]+1;
					qx.push_back(i);
					qy.push_back(j);	
				}
			}
		}
	}


	if(dist[dx][dy] == 1000000)
		dist[dx][dy] = -1;

	cout<<dist[dx][dy]<<endl;


	return 0;
}

Measured memory_bytes: 9212
/* 
 * Author: Priyadarshini
 */
 
/*
 * Run in Mac using the following command:
 * g++ -std=c++14 <cpp_filename>
 * A binary will be generated. Then run:
 * ./a.out
 */
 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <fstream>
#include <cstring>
 
using namespace std;
typedef long long int ll;
 
// Macro //
#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>
 
// Global //
 
 
// Functions //

// Main //
int main()
{
    ll N;
    string a;
    cin >> N;
    cin >> a;
    string r = "No";
    string p1, p2;
    p1 = a.substr (0, N / 2);
    p2 = a.substr (N / 2, N / 2);
    // cout << p1 + p2 <<endl;
    if(p1 == p2 && p1 + p2 == a) r = "Yes";
    cout << r;
    return 0;
}

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

struct R{
	int w, h;
	R(){}
	R(int w_, int h_){
		w = w_; h = h_;
	}
};
bool operator<(const R &a, const R &b){
	if( a.w * a.w + a.h * a.h == b.w * b.w + b.h * b.h ){
		return a.h < b.h;
	}
	return a.w * a.w + a.h * a.h < b.w * b.w + b.h * b.h;
}

int main(){
	int w, h;
	while( cin >> h >> w , h || w ){
		R r(w, h);
		vector<R> v;
		for(int h_ = 1; h_ <= 150; h_++){
			for(int w_ = 1; w_ <= 150; w_++){
				if( w == w_ && h == h_ ) continue;
				if( w_ > h_ ){
					v.push_back( R(w_, h_) );
				}
			}
		}
		sort(v.begin(), v.end());
		int aw, ah;
		for(int i = 0; i < v.size(); i++){
			if( r < v[i] ){
				aw = v[i].w;
				ah = v[i].h;
				break;
			}
		}
		cout << ah << " " << aw << endl;
	}
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int d2(int n) {
	int res = 0;
	while (n % 2 == 0) {
		n /= 2;
		res++;
	}
	return res;
}

int main() {
	int N; cin >> N;
	int ans = 0;
	rep(i, N) {
		int a; cin >> a;
		ans += d2(a);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, N, x[100002], L;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(x[i]));
	scanf("%d", &L);
	x[0] = x[1] - L - 1;
	x[N+1] = x[N] + L + 1;
	
	int j, skip[2][100001][18] = {};
	for (j = 0; j < 18; j++) {
		skip[0][N][j] = N + 1;
		skip[1][1][j] = 0;
	}
	for (i = N - 1; i >= 1; i--) {
		for (j = i + 2; x[j] <= x[i] + L; j++);
		skip[0][i][0] = --j;
		for (j = 0; skip[0][skip[0][i][j]][j] < N + 1; j++) skip[0][i][j+1] = skip[0][skip[0][i][j]][j];
		for (j++; j < 18; j++) skip[0][i][j] = N + 1;
	}
	for (i = 2; i <= N; i++) {
		for (j = i - 2; x[j] >= x[i] - L; j--);
		skip[1][i][0] = ++j;
		for (j = 0; skip[1][skip[1][i][j]][j] > 0; j++) skip[1][i][j+1] = skip[1][skip[1][i][j]][j];
		for (j++; j < 18; j++) skip[1][i][j] = 0;
	}

	
	const int bit[18] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536};
	int q, Q, l, r, ans;
	scanf("%d", &Q);
	for (q = 1; q <= Q; q++) {
		scanf("%d %d", &l, &r);
		ans = 0;
		if (l < r) {
			while (l < r) {
				for (j = 1; skip[0][l][j] <= r; j++);
				ans += bit[--j];
				l = skip[0][l][j];
			}
		} else {
			l ^= r;
			r ^= l;
			l ^= r;
			while (l < r) {
				for (j = 1; skip[1][r][j] >= l; j++);
				ans += bit[--j];
				r = skip[1][r][j];
			}
		}
		printf("%d\n", ans);
	}
	fflush(stdout);
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  }
  else if ((A + B) < (C + D)) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1000000007;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    int x[N], y[N];
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i];
    }
    double ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(i == j){
                continue;
            }
            ans += sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
        }
    }
    fcout << ans / N << endl;
}


Measured memory_bytes: 256
class Dice:
    def __init__(self):
        self.faces=[]

    def rotate(self, direction):
        tmp = self.faces.copy()

        if direction =="N":
            self.faces[5-1] = tmp[1-1]
            self.faces[1-1] = tmp[2-1]
            self.faces[2-1] = tmp[6-1]
            self.faces[6-1] = tmp[5-1]
        if direction =="S":
            self.faces[5-1] = tmp[6-1]
            self.faces[1-1] = tmp[5-1]
            self.faces[2-1] = tmp[1-1]
            self.faces[6-1] = tmp[2-1]
        if direction =="W":
            self.faces[4-1] = tmp[1-1]
            self.faces[1-1] = tmp[3-1]
            self.faces[3-1] = tmp[6-1]
            self.faces[6-1] = tmp[4-1]
        if direction =="E":
            self.faces[3-1] = tmp[1-1]
            self.faces[1-1] = tmp[4-1]
            self.faces[4-1] = tmp[6-1]
            self.faces[6-1] = tmp[3-1]
        return 0



d1 = Dice()
d1.faces=[int(x) for x in input().split(" ")]
directions=list(input())
for d in directions:
    d1.rotate(d)
print(d1.faces[0])

Measured memory_bytes: 7780
#include <bits/stdc++.h>
using namespace std;
int n,k;
int arr[109];
int dp[100009];
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    for(int i=0;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i-arr[j]>=0 && dp[i-arr[j]]==0){
                dp[i] = 1;
            }
        }
    }
    if(dp[k] == 1)cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void abc_160a();

void abc_161a();

void abc_162a();

void abc_163a();

void abc_164a();

void abc_165a();

void abc_166a();

void abc_167a();

void abc_168a();

int main()
{
  //abc_160a();
  //abc_161a();
  //abc_162a();
  //abc_163a();
  //abc_164a();
  //abc_165a();
  //abc_166a();
  //abc_167a();
  abc_168a();
}

void abc_160a()
{
  string S;
  cin >> S;

  if (S[2] == S[3] && S[4] == S[5]) cout << "Yes\n";
  else cout << "No\n";
}

void swap(int& a, int& b)
{
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

void abc_161a()
{
  int x, y, z;
  cin >> x >> y >> z;

  swap(x, y);
  swap(x, z);

  cout << x << " " << y << " " << z << "\n";
}

void abc_162a()
{
  string s;
  cin >> s;
  for (char c : s)
  {
    if (c == '7')
    {
      cout << "Yes\n";
      return;
    }
  }

  cout << "No\n";
}

void abc_163a()
{
  int R;
  cin >> R;

  cout << (double)(2 * R * M_PI);
}

void abc_164a()
{
  int s, w;
  cin >> s >> w;

  if (s <= w) cout << "unsafe\n";
  else cout << "safe\n";
}

void abc_165a()
{
  int k, a, b;
  cin >> k >> a >> b;

  for (int i = a; i <= b; ++i)
  {
    if (i % k == 0)
    {
      cout << "OK\n";
      return;
    }
  }

  cout << "NG\n";
}

void abc_166a()
{
  string s;
  cin >> s;

  if (s == "ABC") cout << "ARC\n";
  if (s == "ARC") cout << "ABC\n";

}

void abc_167a()
{
  string s, t;
  cin >> s >> t;

  for (int i = 0; i < s.size(); ++i)
  {
    if (s[i] != t[i])
    {
      cout << "No\n";
      return;
    }
  }

  if ('a' <= t[t.size() - 1] && t[t.size() - 1] <= 'z') cout << "Yes\n";
  else cout << "No\n";

}

void abc_168a()
{
  string s;
  cin >> s;

  if (s[s.size() - 1] == '3') cout << "bon\n";
  else if (s[s.size() - 1] == '0' ||
    s[s.size() - 1] == '1' ||
    s[s.size() - 1] == '6' ||
    s[s.size() - 1] == '8') cout << "pon\n";
  else cout << "hon\n";
}



Measured memory_bytes: 3560
from itertools import accumulate, chain, cycle

N = int(input())
A = list(map(int,input().split()))

alt = list(chain((0,), accumulate(a*v for v,a in zip(cycle((1,-1)), A))))
tail = alt.pop()

ans = [abs(tail - 2*v) for v in alt]
print(*ans)

Measured memory_bytes: 17704
#include <stdio.h>
#include <math.h>
int main()
{
    int n,i,a[100];
    float sum=0.0,temp;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        temp=pow(a[i],-1);
        sum=sum+temp;
    }
    printf("%f",(1/sum));
    return 0;
}


Measured memory_bytes: 128
n, g = map(int, input().split())
inps = []
for i in range(1, n + 1):
    inp = list(map(int, input().split()))
    inp.append(inp[0] * i * 100 + inp[1])
    inp.append(i)
    inps.append(inp)
def at(items, goal):
    if goal <= 0:
        return 0
    result = 0
    for t, c, a, i in reversed(items):
        tn = i * 100
        cnt = min(t - 1, (goal + tn - 1) // tn)
        result += cnt
        goal -= cnt * tn
        if goal <= 0:
            return result
    return float("inf")
result = []
for i in range(2 ** n):
    items = []
    other = []
    for item in inps:
        (items if i & 1 else other).append(item)
        i >>= 1
    tcnt = sum(map(lambda x: x[0], items))
    acnt = sum(map(lambda x: x[2], items))
    ncnt = at(other, g - acnt)
    result.append(tcnt + ncnt)
print(min(result))


Measured memory_bytes: 3064
N,M,Q=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(Q)]

A=[1 for _ in range(N)]
ans=0

for i in range(10**9):
    temp=0
    for j in range(Q):
        if A[a[j][1]-1]-A[a[j][0]-1]==a[j][2]:
            temp+=a[j][3]
    ans=max(ans,temp)
    A[-1]+=1
    if A[-1]>M:
        k=1
        while max(A)>M and k<N:
            A[N-k-1]+=1
            A[N-k]=A[N-k-1]
            k+=1
            for l in range(1,k):
                A[N-l]=A[N-k]
    if min(A)>M:
        break
print(ans)


Measured memory_bytes: 9248
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional, std.container;
import std.typecons;

void main() {
  auto S = readln.chomp;
  auto N = S.length;
  Tuple!(int, int)[] arr;
  int i = 0;
  while(i < N) {
    int r,l;
    while(i < N && S[i]=='R') { i++; r++; }
    while(i < N && S[i] == 'L') { i++; l++; }
    arr ~= tuple(r,l);
  }

  foreach(a; arr) {
    int r = a[0], l = a[1];
    foreach(j; 0..(r-1)) {
      write("0 ");
    }
    write((r+1) / 2 + l/ 2, " ");
    write(r / 2 + (l+1)/2, " ");
    foreach(j; 0..(l-1)) {
      write("0 ");
    }
  }
}


Measured memory_bytes: 1048
(defun main ()
  (let* ((n (read))
	 (k (read))
	 (a (make-array (1+ n))))
    (dotimes (i n)
      (setf (aref a (1+ i)) (read)))
    (loop for i
	 from (1+ k)
       below (1+ n)
       if (< (aref a (- i k)) (aref a i))
	 do (format t "Yes~%")
       else
	 do (format t "No~%"))))

(main)


Measured memory_bytes: 77776
def main():
    N, M = map(int, input().split())

    # i = 0
    # cnt = 0
    # while cnt < M:
    #     if (N - i * 2 - 1) * 2 != N:
    #         print(1 + i, N - i)
    #         cnt += 1
    #     i += 1



    i = 0
    j = 0
    cnt = 0
    d = set()
    ans = []
    while cnt < M:
        d1 = N - i * 2 - j - 1
        d2 = N - d1
        if d1 in d or d2 in d or d1 * 2 == N or d2 * 2 == N:
            j += 1
            continue
        ans.append((1 + i + j, N - i))
        d.add(d1)
        d.add(d2)
        cnt += 1
        i += 1

    for row in ans:
        print(*row)

if __name__ == '__main__':
    main()


Measured memory_bytes: 102356
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Thu Jan  3 12:25:13 2019
//
package main

import (
	"fmt"
)

func main() {
	var N, Y int
	fmt.Scan(&N, &Y)

	for i := 0; i <= N; i++ {
		for j := 0; j <= N; j++ {
			k := N - i - j
			if k >= 0 && Y == 1000*i+5000*j+10000*k {
				fmt.Println(k, j, i)
				return
			}
		}
	}

	fmt.Println(-1, -1, -1)
}


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

namespace AtCoder.Abc172
{
    class F
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

            var xor = a.Skip(2).Aggregate(0L, (acc, x) => acc ^= x);
            var sum = a[0] + a[1];
            var and = (sum - xor);
            if (and % 2 != 0)
            {
                Console.WriteLine(-1);
                return;
            }
            and >>= 1;
            if ((and & xor) != 0)
            {
                Console.WriteLine(-1);
                return;
            }
            int bitN = 0;
            var or = and | xor;
            while (or > 0)
            {
                bitN++;
                or >>= 1;
            }
            long a0 = and & ~xor;
            long a1 = a0;
            long bit = 1L << (bitN - 1);
            while (bit > 0)
            {
                var iand = and & bit;
                var ixor = xor & bit;
                if (ixor > 0)
                {
                    if ((a0 | bit) <= a[0])
                        a0 |= bit;
                    else
                        a1 |= bit;
                }
                bit >>= 1;
            }

            if (a0 > a[0] || a0 == 0)
                Console.WriteLine(-1);
            else
                Console.WriteLine(a[0] - a0);
        }
    }
}


Measured memory_bytes: 28344
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
	bool can = false;
	string s;
	cin >> s;
	string t = s;
	reverse(t.begin(), t.end());
	if (s == t) {
		int n = s.size();
		string str1 = s.substr(0, (n - 1) / 2);
		string str2 = str1;
		reverse(str2.begin(), str2.end());
		if (str1 == str2) {
			int num = (n + 3) / 2;
			string str3 = s.substr(num - 1, n - num + 1);
			string str4 = str3;
			reverse(str4.begin(), str4.end());
			if (str3 == str4)can = true;
		}
		else can = false;
	}
	else can = false;
	if (can)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

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

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, y;
    cin >> n >> y;
    int i = -1, j = -1, k = -1;
    bool f = false;
    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= n; j++)
        {
            if (i + j > n)
            {
                continue;
            }
            else
            {
                if (10000 * i + 5000 * j + 1000 * (n - i - j) == y)
                {
                    f = true;
                    k = n - i - j;
                    goto LABEL;
                }
            }
        }
    }
LABEL:
{
}
    if (f)
        cout << i << " " << j << " " << k << endl;
    else
        cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Hello
{
    public static void Main()
    {
        int N = NextInt();
        List<int> t = LineInt().ToList();
        List<int> v = LineInt().ToList();
        //その時の速度
        double[] s = new double[400010];
        int time = 0;
        for (int i = 0; i < N; i++) time += t[i] * 2;
        int _t = 1;
        double a = 0;
        for (int i = 0; i < N; i++)
        {
            for (int d = 0; d < t[i] * 2; d++)
            {
                //とりあえず最高速度になるまで加速させてみる
                s[_t + d] = Math.Min(v[i], a + 0.5);
                a += 0.5;
            }
            a = s[_t + t[i] * 2 - 1];
            _t += t[i] * 2;
        }
        //逆からも構築する
        t.Reverse();
        v.Reverse();
        double[] _s = new double[400010];
        _t = 1;
        a = 0;
        for (int i = 0; i < N; i++)
        {
            for (int d = 0; d < t[i] * 2; d++)
            {
                _s[time - (_t + d)] = Math.Min(v[i], a + 0.5);
                //Console.Write("t : {0:f2}", ((time - (_t + d)) / 2.0));
                //Console.WriteLine(" {0:f2} ",_s[time - (_t + d)]);
                a += 0.5;
            }
            a = _s[time - (_t + t[i] * 2 - 1)];
            _t += t[i] * 2;
        }
        _t = 1;
        double ans = 0;
        for (int i = 0; i < N; i++)
        {
            for (int d = 0; d < t[i] * 2; d++)
            {
                //-0.5sとの台形で取る
                double s0 = Math.Min(_s[(_t + d) - 1], s[(_t + d) - 1]);
                double s1 = Math.Min(_s[(_t + d)], s[(_t + d)]);
                ans += (s0 + s1) * 0.5 / 2.0;
                //Console.Write("time : {0:f2}", ((_t + d) / 2.0));
                //Console.WriteLine("   s : {0:f2}", Math.Min(_s[(_t + d)], s[(_t + d)]));
            }
            _t += t[i] * 2;
        }
        Console.WriteLine(ans);
    }

}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); }
    public static string NextString() { Confirm(); return queue.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 15584
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
 
int main()
{
    int n, i;

    std::cin >> n;

    for(i = 1;i <= n;i = i * 2){}

    std::cout << i / 2;
    return 0;
}

Measured memory_bytes: 256
n=gets.to_i
as=gets.split.map(&:to_i)
movesum=as[0].abs+as[-1].abs
(n-1).times do |i|
  movesum+=(as[i+1]-as[i]).abs
end
n.times do |i|
  prev= i==0 ? 0:as[i-1]
  to= i==n-1 ? 0:as[i+1]
  diff1=(as[i]-prev).abs
  diff2=(to-as[i]).abs
  jump=(to-prev).abs
  puts movesum-(diff1+diff2)+jump
end


Measured memory_bytes: 11660
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long h = sc.nextInt();
		long amax = 0;
		List<Long> b = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			amax = (int) Math.max(amax, sc.nextDouble());
			b.add(sc.nextLong());
		}
		Collections.sort(b);
		Collections.reverse(b);
		long ans = 0;
		for(Long e : b) {
			if(e > amax && h > e) {
				h -= e;
				ans++;
			} else if(e > amax && h <= e) {
				h = 0;
				ans++;
				break;
			} else {
				break;
			}
		}
		ans += h / amax;
		if(h % amax != 0)
			ans++;
		System.out.println(ans);

	}

}


Measured memory_bytes: 123816
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    int n;
    cin >> n;

    ll ans = 1, prev = 2;
    FOR(i, 1, n) {
        ll tmp = ans;
        ans += prev;
        prev = tmp;
    }

    print(ans);

}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;	
	while(T--){
		int a,b,c,k;
		cin >> a >>b >> c >> k ;
		int ans =0 ;
		if(a < k){
			k-=a;
			ans+=a;
		}else{
			ans+=k;
			k=0;
		}
		if(k>0){
			k-=b;

		}
		if(k>0){
			int r = min(k,c);
			ans-=r;
			k-=min(k,c);
		}
		cout << ans;
	
	
	}
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e6+10;
int a[N],n,b;
char c[N];
int main()
{cin>>n;
	scanf("%s",c+1);
	for(int i=1;i<=n;i++)b+=c[i]!=c[i-1];
	cout<<b;return 0;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		b+=a[i]*a[j];
	}cout<<b;
}


Measured memory_bytes: 384