akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main()
{
  int year, cost;

  cin >> year >> cost;

  if(year <= 12 && year > 5)
  {
    cout << cost / 2 << endl;
  }

  else if(year <=5)
  {
    cout << 0 << endl;
  }

  else
  cout << cost << endl;
}


Measured memory_bytes: 3632
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n-1,-1,-1):
    if b[i]<=a[i+1]:
        ans+=b[i]
    else:
        ans+=a[i+1]
        b[i]-=a[i+1]
        ans+=min(b[i],a[i])
        a[i]=max(0,a[i]-b[i])
print(ans)

Measured memory_bytes: 18624
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n; cin>>n;
	long a[n+1]={};
	rep(i,n){
		long x; cin>>x;
		a[i+1]=a[i]+x;
	}
	sort(a,a+n+1);
	long cnt=0,sum=0;
	rep(i,n+1){
		if(a[i+1]==a[i]) cnt++;
		else{
			while(cnt>0){
				sum+=cnt; cnt--;
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
#define MINF -1e18
typedef long long ll;

using namespace std;

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

    int n;cin>>n;
    vector<ll>a(n);

    ll sum = 0;
    rep(i,n)
    {
        cin>>a[i];
        int x = 0,y = a[i];
        while(y%2==0)
        {
            x++;
            y/=2;
        }
        sum+=x;
    }

    cout<<sum<<endl;


    return 0;
}


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

using namespace std;

template <typename T>
class BinaryIndexedTree {
 private:
  std::vector<T> data;

 public:
  BinaryIndexedTree(int sz) : data(sz + 1, 0) {}

  T sum(int idx) const {
    T res = 0;
    for (int i = idx + 1; i > 0; i -= i & -i) res += data[i];
    return res;
  }

  void add(int idx, T x) {
    for (int i = idx + 1; i < (int)data.size(); i += i & -i) data[i] += x;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, Q;
  string S;
  cin >> N >> S >> Q;
  vector<BinaryIndexedTree<int>> bits(26, BinaryIndexedTree<int>(N));
  for (int i = 0; i < N; i++) {
    bits[S[i] - 'a'].add(i, 1);
  }
  for (int i = 0; i < Q; i++) {
    int q;
    cin >> q;
    if (q == 1) {
      int i;
      char c;
      cin >> i >> c;
      i--;
      bits[S[i] - 'a'].add(i, -1);
      bits[c - 'a'].add(i, 1);
      S[i] = c;
    } else {
      int l, r;
      cin >> l >> r;
      l--, l--, r--;
      int res = 0;
      for (int i = 0; i < 26; i++) {
        res += (bits[i].sum(r) - bits[i].sum(l) > 0 ? 1 : 0);
      }
      cout << res << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 53660
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define INF 1e9;
#define MOD 1e9 + 7;
int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    deque<int> b;
    rep(i, n) {
        if ((i + 1) % 2 == n % 2)
            b.push_front(a[i]);
        else
            b.push_back(a[i]);
    }
    for (int x : b) cout << x << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
struct node {
	int x,y;
}a[100005];
bool cmp(node a,node b){
	if(a.y<b.y) return true;
	else if(a.y==b.y&&a.x<b.x) return true;
	else return false;
}
int main(){
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		int x,l;
		cin >> x >> l;
		a[i].x=x-l;
		a[i].y=x+l;
	}
	sort(a+1,a+1+n,cmp);
	int en=a[1].y;
	int sum=1;
	for(int i=2;i<=n;i++){
		if(a[i].x>=en){
			en=a[i].y;
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
} 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;//Òç³ö»á±ä³É¸ºÖµ 
typedef long double ldb;
typedef unsigned long long ull;//×Ô¶¯È¡Ä£2^64 
const double pi=acos(-1.0);
const int mod = 1e9+7; // 998244353;
const int inf = 0x7fffffff;//2^31-1
const ll INF = 0x7fffffffffffffff;
const int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
//ll begin_time=clock();    ll end_time=clock();  cout<<"time = "<<end_time-begin_time<<" ms!"<<endl;
//bool operator < (const mmp &a) const{return x<a.x||x==a.x&&y<a.y;}       //map<int,map<int,int> >z;
//map<int,int>::iterator it;for(it=z.begin();it!=z.end();it++)printf("%d %d\n",it->first,it->second);
//ll poww(ll a,ll b){ll s=1;while(b){if(b&1)s=(s*a)%mod;a=(a*a)%mod;b>>=1;}return s%mod;}  //¿ìËÙÃÝÈ¡Ä£ 
//lower_bound(begin,end,num); µÚÒ»¸ö>=numµÄÊý×Ö upper_bound(begin,end,num); µÚÒ»¸ö>numµÄÊý×Ö,·µ»ØµØÖ·
//freopen("input.in","r",stdin);     freopen("output.out","w",stdout);      //ÎÄ¼þ¶ÁÐ´Ìá½» 
//reverse(s.begin(),s.end());   //·­×ª×Ö·û´®        floor(); ÏòÏÂÈ¡Õû  ceil(); ÏòÉÏÈ¡Õû
//ÊýÖáÉÏµÄn¸öµãÒÆ¶¯µ½Í¬Ò»Î»ÖÃ£¬ÒÆ¶¯µ½¸Ã×éÊý×ÖµÄÖÐÎ»ÊýµÄ×Ü¾àÀë×î¶Ì
//bool isPrime(int n){if(n==2||n==3)return 1;if(n%6!=1&&n%6!=5)return 0;
//int t=sqrt(n);for(int i=5;i<=t;i+=6)if(n%i==0||n%(i+2)==0)return 0;return 1;}//ÅÐ¶ÏËØÊý   


int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	ll a,b,c,d,e,f,g,T;   
	cin>>a>>b;
	if(b%2)cout<<"No"<<endl;
	else
	if(a*4>=b&&a*2<=b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
}
	


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound 
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int> 
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
    
	const int N =1e6;
    
     int mod= 1e9+7;
     
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};
   
     void solve(){
        
         int a,b,c;
         cin>>a>>b>>c;
         
         if(a-b>=c){
			  cout<<0<<endl;
			  return;
		 }
		 
		 
		 cout<<(c-(a-b))<<endl;
        
     }
   
   
   
   
      int32_t main() {
	    cool;
	    int t=1;
        //cin>>t;
	    while(t--)
	       solve();
	       
	       
	       return 0;	   
	   }


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

int main(void){
 	int H,N;

	scanf("%d %d\n",&H,&N);

  int a[100000];

  int sum=0;

  for(int i=0;i<N;i++){
    scanf("%d ",&a[i]);
    sum=sum+a[i];
  }


  if(sum>=H){printf("Yes");}else{printf("No");}

  	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
#define ll long long
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int temp = (n%1000);
	if(n>=1000 && n%1000 != 0)
		cout << 1000 - temp;
	else if(n%1000 == 0)
		cout << 0;
	else
		cout << 1000 - n;
}

Measured memory_bytes: 3560
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let k = v[1];
	let mut L:Vec<i32> = procon_read();
	L.sort();
	let mut sum = 0;
	for i in (n-k)..n {
		sum += L[i as usize];
	}
	println!("{}", sum);
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define pri(x) (printf("%d", x))
#define prll(x) (printf("%lld", x))
#define sci(x) (scanf("%d", &x))
#define scll(x) (scanf("%lld", &x))
#define endl printf("\n");
typedef long long ll;

int
main(int argc, char *argv[])
{
  int l, r;
  sci(l); sci(r);

  if(r - l >= 2018) pri(0);
  else{
    int a[2018];
    for(int i = 0; i <= r- l; i++){
      a[i] = (l + i) % 2019;
     
    }
    int n = r- l + 1; int min = 2019;
    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
	min = Min(min, (a[i] * a[j]) % 2019);
      }
    }
    pri(min);
  }
  return 0;
}
	  


Measured memory_bytes: 128
import math
import sys
a, b, c, d = map(int, input().split())

while 1:
    if (c > 0):
        c -= b
    if(c <= 0):
        print("Yes")
        sys.exit()
    if (a > 0):
        a -= d
    if(a <= 0):
        print("No")
        sys.exit()


Measured memory_bytes: 9172
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N; cin >> N;
    N *= 2;
    string S; cin >> S;

    int parity = 1;
    Int ans = 1;
    for (int i = 1; i < N; i++) {
        char crt = S[i];
        if (crt == 'B') {
            if (parity % 2) {
                ans *= parity;
                ans %= MOD;
                parity--;
                if (parity < 0) break;
            }
            else parity++;
        }
        if (crt == 'W') {
            if (parity % 2) parity++;
            else {
                ans *= parity;
                ans %= MOD;
                parity--;
                if (parity < 0) break;
            }
        }
    }

    N /= 2;
    Int weight = 1;
    for (int i = 1; i <= N; i++) {
        weight *= i;
        weight %= MOD;
    }

    if (parity == 0) {
        cout << ans*weight%MOD << endl;
    } else {
        cout << 0 << endl;
    }
    
}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    s.erase(n-1);
    rep(i,n-1) {
        if((int)s.size()%2) {s.erase(s.size()-1); continue;}
        string temp = s.substr(s.size()/2, s.size());
        if(s.substr(0,s.size()/2)==temp) ans = max(ans, (int)s.size());
        s.erase(s.size()-1);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=s[i]-'0';
  }
  cout<<max(ans,9*(n-1)+(s[0]-'0')-1)<<endl;
}


Measured memory_bytes: 256
defmodule Main do
  def main do
    [a,b,h,m]=IO.gets("") |> String.trim |> String.split(" ") |>Enum.map(&String.to_integer(&1)) 
    
    IO.puts(:math.sqrt(a*a+b*b-2*a*b *:math.cos( (h+m/60)*(1-1/12)*2 *:math.pi() )))
  end
end


Measured memory_bytes: 31112
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
string a;
int main()
{
    cin>>a;
    if(a == "SUN")
    {
        printf("7");
    }
    if(a == "MON")
    {
        printf("6");
    }
    if(a == "TUE")
    {
        printf("5");
    }
    if(a == "WED")
    {
        printf("4");
    }
    if(a == "THU")
    {
        printf("3");
    }
    if(a == "FRI")
    {
        printf("2");
    }
    if(a == "SAT")
    {
        printf("1");
    }
    return 0;
}

Measured memory_bytes: 256
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def sankaku(n):
    i = 1

    while not (n < i*(i+1) / 2):
        i += 1
    
    return i - 1

N = int(input())

delist = prime_factorize(N)

counter = collections.Counter(delist)

count = 0

for key, value in counter.items():
    count = count + sankaku(value)

print(count)

Measured memory_bytes: 9492
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;

int main() {
    ll K,N;
    cin >> K >> N;
    vector<ll> A(N);
    vector<ll> diff(N);
    ll sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        sum += A[i];
    }
    for (int i = 0; i < N - 1; ++i) {
        diff[i] = A[i + 1] - A[i];
    }
    diff[N-1] = K - A[N-1] + A[0];
    ll m = 1ll << 50;
    for (int i = 0; i < N; ++i) {
        m = min(m,K- diff[i]);
    }
    cout << m << endl;
}


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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

const ll inf = 1e18;
const int nax = 1e5 + 5;

// ll fact[nax], invfact[nax];

// void pre()
// {
// 	fact[0] = 1;
// 	forn(i, 1, nax)
// 	{
// 		fact[i] = mult(fact[i - 1], i);
// 	}

// 	invfact[nax - 1] = mypow(fact[nax - 1], mod - 2);

// 	ford(i, nax, 1)
// 	{
// 		invfact[i - 1] = mult(invfact[i], i);
// 	}
// }

// ll ncr(ll n, ll r)
// {
// 	if (r > n)
// 		return 0;

// 	ll ans = mult(fact[n], mult(invfact[n - r], invfact[r]));

// 	return ans;
// }

int main()
{
	speedup_IO;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		ll n,r;
		ll ans;
		cin>>n>>r;

		if(n>=10)
		{
			ans = r;
		}
		else
		{
			ans = r + (100)*(10-n);
		}

		cout<<ans;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back      
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define M 1000000007
#define N 211111

#define TASK "1"

using namespace std;

int main(){
	#ifdef home
		freopen(TASK".in","r",stdin);	
		freopen(TASK".out","w",stdout);
	#endif		
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	s.insert(s.begin() + 4, ' ');
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
N = int(input())
A = [None]*N
mx = -1
mx2 = -1
for i in range(N):
	A[i] = int(input())
	if mx <= A[i]:
		mx2 = mx
		mx = A[i]
	elif mx2 < A[i]:
		mx2 = A[i]


for i in range(N):
	if A[i] == mx:
		print(mx2)
	else:
		print(mx)


Measured memory_bytes: 13496
n,m=map(int,input().split())

limax=0
rimin=n
for i in range(m):
    li,ri=map(int,input().split())
    if li>limax:
        limax=li
    if ri<rimin:
        rimin=ri
if rimin<limax:
    print(0)
else:
    print(rimin-limax+1)    

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
         //値の取得
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] h = new int[N];
        
        int count = 0;
        
        for (int i = 0; i < N; ++i){
            h[i] = sc.nextInt();
            if (h[i] >= K){
                ++count;
            }
        }
        
        System.out.println(count);
        
    }
}

Measured memory_bytes: 58340
#include <stdio.h>
int A[2000001],B[2000001],C[10001];
int main()
{
  int i,j,n=0;
  int k=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      scanf("%d",&A[i]);
      C[A[i]]++;
      if(k<A[i]) k=A[i];
      // printf("%d ",A[i]);
    }
  for(i=0;i<=k;i++)
    {
      C[i]=C[i]+C[i-1];
    }
  for(j=n;j>=0;j--)
    {    
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }
  for(i=1;i<n+1;i++)
    {
      if(i!=n)printf("%d ",B[i]);
      else  printf("%d\n",B[i]);
    }
  return 0;
}

Measured memory_bytes: 16264
#include <bits/stdc++.h>
#include <algorithm>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long 
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define endl "\n"
using namespace std;

ll gcd(ll a, ll b){
    return __gcd(a,b);
}

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

bool isPrime(ll n){
    if(n <= 1) return false;
    for(ll i=2; i<=sqrt(n); i++){
        if(n%i == 0){
            return false;
        }
    }
    return true;
}

void solve(){
  ll n,d,count=0;
  cin >> n >> d;
  while(n--){
      ll x,y;
      cin >> x >> y;
      x=abs(x),y=abs(y);
      long double ans = (double)(sqrt(pow(x,2)+pow(y,2)));
      if(ans <= d) count++;
  }
  cout << count ;
}

int main() {
    fast;
    solve();
	//ll t; cin >> t; while(t--){ solve(); }
	return 0;
}


Measured memory_bytes: 3672
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine().trim.toInt
  val a = StdIn.readLine().trim.split(' ').map(_.toInt)

  val last = a(n - 1)

  @inline private def swap(from: Int, to: Int): Unit = {
    //println(s"from: $from  to: $to")
    val temp = a(from)
    a(from) = a(to)
    a(to)   = temp
  }
  
  def partition(arr: Array[Int], p: Int, r: Int): Int = {
    var i = p - 1
    (p until r).foreach{ j =>
      if(arr(j) <= last){
        i += 1
        swap(i, j)
        //println(a.toList.mkString(" "))
      }
    }
    swap(i+1, r)
    //println("last:" + a.toList.mkString(" "))
    i + 1
  }
  
  val partitionIndex = partition(a, 0, n-1)
  //println(s"num: $partitionIndex")
  
  println(a.slice(0, partitionIndex).mkString(" ") +
  " [" + a(partitionIndex) + "] " + 
    a.slice(partitionIndex + 1, n).mkString(" "))
  
}


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

//#define fin cin
//#define fout cout

#define leftSon (node << 1)
#define rightSon ((node << 1) | 1)

#define pii pair < int , int >
#define F first
#define S second

using namespace std;

typedef long long ll;

const int inf = 0x3f3f3f3f;
const long long infL = LLONG_MAX;

const int nmax = 1e5 + 10;
const int mod = 1e9 + 7;

int sum(int a, int b) {
    a += b; if (a >= mod) a -= mod; return a;
}

void no_solution() {
    printf("0\n");
    exit(0);
}

int n, p;

long long A, B;
long long a[nmax];

int dp[nmax][2], lst[nmax];

int main()
{

    /*
    ifstream fin("input.in");
    ofstream fout("output.out");
    */

    scanf("%d %lld %lld", &n, &A, &B);
    for (int i = 1; i <= n; ++i)
        scanf("%lld", &a[i]);

    if (A > B) swap(A, B);

    lst[1] = 1;
    for (int i = 2; i <= n; ++i)
        if (a[i] - a[i-1] >= A) lst[i] = lst[i-1];
        else lst[i] = i;

    dp[1][0] = dp[1][1] = 1; p = 1;
    for (int i = 2; i <= n; ++i) {
        if (a[i] - a[i-1] >= A)
            dp[i][0] = sum(dp[i-1][0], dp[i-1][1]);
        else {
            if (i > 2 && a[i] - a[i-2] < A) {
                no_solution();
            }

            dp[i][0] = dp[i-1][1];
        }

        while (a[i] - a[p] >= B) p++;
        if (p == i) dp[i][1] = sum(dp[i-1][0], dp[i-1][1]);
        else if (lst[i-1] <= p) dp[i][1] = dp[p][0];
    }

    printf("%d\n", sum(dp[n][0], dp[n][1]));

    return 0;
}


Measured memory_bytes: 2304
from collections import Counter
N, M = map(int, input().split())
X = list(map(int, input().split()))
S = [0] * M
MM = [0] * M
for x, n in Counter(X).items():
    MM[x%M] += n//2
    S[x%M] += n
ans = 0
ans += S[0] // 2
if M%2 == 0:
    ans += S[M//2] // 2
for i1 in range(1, 1000000):
    i2 = M-i1
    if i1 >= i2:
        break
    s1, s2 = S[i1], S[i2]
    if s1 < s2:
        ans += s1 + min((s2-s1)//2, MM[i2])
    else:
        ans += s2 + min((s1-s2)//2, MM[i1])
print(ans)


Measured memory_bytes: 21216
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here
    
    string S;

    cin >> S;

    if(S.at(2)==S.at(3)&&S.at(4)==S.at(5)){
        printf("Yes");
    }else{
        printf("No");
    }

    
}

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

int main() {
  int n;
  cin >> n;
  
  string s;
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  rep(i, n){
    cin >> s;
    if(s == "AC"){
      ac++;
    }
    else if(s == "WA"){
      wa++;
    }
    else if(s == "TLE"){
      tle++;
    }
    else if(s == "RE"){
      re++;
    }
  }
  
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define repi(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
using namespace std;
typedef long long ll;

int main() {
  int N; cin >> N;
  if(N <= 2) cout << 2;
  else cout << (N % 2 == 0 ? N : N * 2) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int main(){

  int M[N][N];
  int n,u,k,v,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--; //0 origin
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--; // 0 orign
      M[u][v]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
  
}//main end



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;

int main() {
	string N;
	cin >>N;
	for (size_t i = 0; i < 3; i++)
	{
		if (N.at(i) == '7') {
			cout << "Yes";
			return 0;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 3628
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};


int cakesize(int x1,int y1, int x2, int y2){
	return abs(x1-x2)*abs(y1-y2);
}

struct cake{
	int x[4];	//左上、右上、右下、左下
	int y[4];
	bool operator==(const cake& c1){
		rep(i,4){
			if(x[i] != c1.x[i]){
				return false;
			}
			if(y[i] != c1.y[i]){
				return false;
			}
		}
		return true;
	}
};


bool cakesort(const cake& c1, const cake& c2){
	return cakesize(c1.x[0],c1.y[0],c1.x[2],c1.y[2]) < cakesize(c2.x[0],c2.y[0],c2.x[2],c2.y[2]); 
}


int main(){
	int n,w,d;
	while(true){
		cin >> n >> w >> d;
		if(n+w+d == 0){
			break;
		}
		vector<cake> data;
		cake s;
		s.x[0] = 0; s.x[1] = w; s.x[2] = w; s.x[3] = 0;
		s.y[0] = d; s.y[1] = d; s.y[2] = 0; s.y[3] = 0;
		data.pb(s);

		int a,b;
		rep(i,n){
			cin >> a >> b;
			a--;
			cake buf = data[a];
			auto del = remove(all(data),data[a]);
			data.erase(del, data.end());

			int mx = buf.x[1] - buf.x[0];
			int my = buf.y[1] - buf.y[2];
			int mv = 0;
			while(true){
				if(b / mx == 0){
					break;
				}
				b -= mx;
				mv++;

				if(b / my == 0){
					break;
				}
				b -= my;
				mv++;
			}
			mv %= 4;

			cake add1,add2;
			rep(i,4){
				add1.x[i] = buf.x[i]; add2.x[i] = buf.x[i];
				add1.y[i] = buf.y[i]; add2.y[i] = buf.y[i];
			}

			if(mv&1){
				int ny;
				if(mv == 1){
					ny = (my-b) + buf.y[2];
				}else{
					ny = b + buf.y[2];
				}
				add1.y[2] = ny; add1.y[3] = ny;
				add2.y[0] = ny; add2.y[1] = ny;
			}else{
				int nx;
				if(mv == 2){
					nx = (mx-b) + buf.x[0];
				}else{
					nx = b + buf.x[0];
				}
				add1.x[1] = nx; add1.x[2] = nx;
				add2.x[0] = nx; add2.x[3] = nx;
			}

			if(cakesize(add1.x[0],add1.y[0],add1.x[2],add1.y[2]) < cakesize(add2.x[0],add2.y[0],add2.x[2],add2.y[2])){
				data.pb(add1);
				data.pb(add2);
			}else{
				data.pb(add2);
				data.pb(add1);
			}
		}

		sort(all(data), cakesort);

		rep(i,data.size()){
			cout << cakesize(data[i].x[0],data[i].y[0],data[i].x[2],data[i].y[2]) << (i+1==data.size() ? "\n" : " ");
		}
	}
}

Measured memory_bytes: 1220
N = int(input())
A = list(map(int, input().split()))
M = 1000
min_ai = A[0]
max_ai = A[0]
for i in range(1, N):
    ai = A[i]
    if max_ai > ai:
        M = M % min_ai + (M // min_ai) * max_ai
        min_ai = ai
        max_ai = ai
    else:
        max_ai = ai

M = M % min_ai + (M // min_ai) * max_ai
print(M)

Measured memory_bytes: 61828
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] nums = new int[3];
		for(int i=0;i<3;i++) {
			nums[i]= sc.nextInt();
		}
		int k=sc.nextInt();

		Arrays.sort(nums);
		for(int i=0; i<k;i++) {
			nums[2]*=2;
		}
		System.out.println(nums[0]+nums[1]+nums[2]);

	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define MAX 10000
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
struct Node{int p,l,r;};
Node T[MAX];
int D[MAX],H[MAX];
void setDepth(int u,int d){
    if(u==-1)return;
    D[u]=d;
    setDepth(T[u].l,d+1);
    setDepth(T[u].r,d+1);
}
int setHeight(int u){
    int h1=0,h2=0;
    if(T[u].l!=-1)
    h1=setHeight(T[u].l)+1;
    if(T[u].r!=-1)
    h2=setHeight(T[u].r)+1;
    H[u]=(h1>h2?h1:h2);
    return H[u];
}
int getsibling(int u){
    if(T[u].p==-1)return -1;
    if(T[T[u].p].l!=-1&&T[T[u].p].l!=u)
        return T[T[u].p].l;
    if(T[T[u].p].r!=-1&&T[T[u].p].r!=u)
        return T[T[u].p].r;
    return -1;
}
void print(int u){
    cout<<"node "<<u;
    cout<<": parent = "<<T[u].p;
    cout<<", sibling = "<<getsibling(u);
    int deg=0;
    if(T[u].l!=-1)deg++;
    if(T[u].r!=-1)deg++;
    cout<<", degree = "<<deg;
    cout<<", depth = "<<D[u];
    cout<<", height = "<<H[u]<<", ";
    if(T[u].p==-1)cout<<"root";
    else if(deg==0)cout<<"leaf";
    else cout<<"internal node";
    cout<<endl;
}
int main(){
    int root,n,a,b,c;
    cin>>n;
    r(i,n)T[i].p=-1;
    r(i,n){
      cin>>a>>b>>c;
      T[a].l=b;
      T[a].r=c;
      if(b!=-1)T[b].p=a;
      if(c!=-1)T[c].p=a;
    }
    r(i,n)if(T[i].p==-1)root=i;
    setDepth(root,0);
    setHeight(root);
    r(i,n)print(i);
}


Measured memory_bytes: 3088
import java.util.Scanner;

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

		int count = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] * (4 * m) >= sum) {
				count++;
			}
		}

		System.out.println(count >= m ? "Yes" : "No");
	}
}

Measured memory_bytes: 22996
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine.toInt
  val seq = Iterator.continually(StdIn.readLine)
    .take(2)
    .map(_.split(" ").map(_.toInt))
    .toArray
  val seq1 = seq(0).scanLeft(0)( (acc, e) => acc + e).tail
  val seq2 = seq(1).scanRight(0)( (e,acc) => acc + e).init
  val ans = (0 until n).map(i => seq1(i) + seq2(i)).max

  println(ans)
}

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

int main() {
    long long N, C, K;
    cin >> N >> C >> K;
    long long ppl[N];
    for (int i=0; i<N; i++) cin >>ppl[i];
    sort(ppl, ppl+N);
    int cap=0, limit=-1, ans=0;
    for (int i=0; i<N; i++){
        if (cap==C || ppl[i]> limit){
            ans++;
            limit=ppl[i]+K;
            cap=0;
        }
        cap++;
    }
    cout << ans << endl;
}


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

int main(){
  int A,B,C,X;//500,100,50,合計
  cin >> A >> B >> C >> X;
  
  int n=0;
  
  for(int i=0;i<A+1;i++){
    for(int j=0;j<B+1;j++){
      for(int k=0;k<C+1;k++){
        if(500*i+100*j+50*k==X){
          n++;
        }
      }
    }
  }
  
  cout << n << endl;
  
}

Measured memory_bytes: 256
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_A&lang=jp
  * String - Finding a Word
  */
object Main {
  def main(args: Array[String]): Unit = {
    val word = io.StdIn.readLine().toLowerCase
    val words = Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null)
      .takeWhile(_ != "END_OF_TEXT")
      .flatMap(_.toLowerCase.split("[ \\n]"))
    println(words.count(_ == word))
  }
}

Measured memory_bytes: 43912
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
LL n, k;
int main() {
	cin >> n >> k;
	db ans = 0;
	for (LL i = 1; i <= n; ++i) {
		if (i == k - 1) {
			ans += 1.0 / 2.0;
			continue ;
		} 
		LL tms = 1;
		for (LL j = i; j < k; j *= 2) tms *= 2;
		ans += (1.0 / tms);
	}
	printf("%.10f", ans * (1.0 / n));
	return 0;
}

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())
if a <= c:
    if b < c:
        answer = 0
    elif b < d:
        answer = b - c
    else:
        answer = d - c
else:
    if d < a:
        answer = 0
    elif d < b:
        answer = d - a
    else:
        answer = b - a
print(answer)

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

typedef long long ll;

const int N=1e6 + 5;
ll arr[N];
ll n,cnt,su,x;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i)
        scanf("%d",arr+i);
    su=x=0;
    for(int i=0,j=0;i < n; ++i){
        su+=arr[i];
        x^=arr[i];
        while(su != x)
            su-=arr[j],x^=arr[j],++j;
        cnt+=i-j+1;
    }
    printf("%lld",cnt);




}



Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	int n, m;
	int a, b;
	int student[501][501];
	int i, j;
	int invite;
	int friends[501];
	
	while (scanf("%d %d", &n, &m)){
		invite = 0;
		for (i = 0; i < 501; i++){
			friends[i] = 0;
			for (j = 0; j < 501; j++){
				student[i][j] = 0;
			}
		}
		
		if (n == 0 && m == 0) break;
		
		for (i = 1; i <= m; i++){
			scanf("%d %d", &a, &b);
			student[a][b]++;
			student[b][a]++;
			if (a == 1){
				friends[b] = 1;
			}
		}
		for (i = 1; i <= n; i++){
			for (j = 2; j <= n; j++){
				if (student[1][i] == 1 && student[i][j] == 1){
					friends[j] = 1;
				}
			}
		}
		for (i = 2; i <= n; i++){
			if (friends[i] == 1){
				invite++;
			}
		}
		printf("%d\n", invite);
	}
	return (0);
}

Measured memory_bytes: 1580
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
typedef vector<pii> vpii;
#define reps(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define all(g) (g).begin(),(g).end()
#define pb push_back
const int mod = 1e9 + 7;
#define INF 1<<25
/*
input case
output case
*/

int N;
int a[120];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i,N) cin >> a[i];

    int mean = 0;
    int ans = 1<<25;
    reps(i,-100,101){
        mean = 0;
        rep(j,N){
            mean += pow((i-a[j]),2);
        }
        ans = min(ans,mean);
    }
    cout << ans << endl;
}

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<ll> p(n);
  for(int i = 0; i< n; i++) cin >> p[i];
 int sum= 0;
  for(int i = 0; i< k; i++) sum += p[i];
 int ans = sum;
  for(int i = 0; i< n-k; i++){
        sum = sum+p[k+i]-p[i];
        ans = max(ans, sum);
    }
double ans2 = (ans+k)*0.5;
printf("%.10f\n",ans2);
 return 0;
}

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

string getResult(vector<string> &strs, const int strCount, const int strLen){
  for(int i = 0; i < strCount - 1; i++){
    for(int j = strCount - 1; j > i; j--){
      for(int k = 0; k < strLen; k++){
        if(strs[i][k] < strs[j][k]){
          break;
        }
        if(strs[i][k] > strs[j][k]){
          string tmp = strs[i];
          strs[i] = strs[j];
          strs[j] = tmp;
          break;
        }
      }
    }
  }

  string result = "";
  for(string str : strs){
    result += str;
  }
  return result;
}

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

  vector<string> S(N);
  for(int i = 0; i < N; i++){
    cin >> S[i];
  }

  string result = getResult(S, N, L);
  cout << result;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
int main(){
	while (1) {
		int w,h,xs,ys,xg,yg,n;
		cin>>w>>h;
		if(!w) break;
		cin>>xs>>ys>>xg>>yg>>n;
		int board[w][h];
		bool visited[w][h];
		memset(board,0,sizeof board);
		memset(visited,0,sizeof visited);
		queue<pair<int,int>> que;
		que.emplace(--xs,--ys);
		visited[xs][ys] = true;
		xg--;yg--;
		int area[2][2][8] = {{{-1,0,1,2,-1,0,1,2},{-1,-1,-1,-1,0,0,0,0}},
		    {{-1,-1,-1,-1,0,0,0,0},{-1,0,1,2,-1,0,1,2}}};
		for (int i = 0; i < n; i++) {
			int c,d,x,y;
			cin>>c>>d>>x>>y;
			for (int i = 0; i < 8; i++)
				board[area[d][0][i]+x][area[d][1][i]+y] = c;
		}
		constexpr int dx[]={0,-1,1,0},dy[]={1,0,0,-1};
		while (!que.empty()) {
			auto now = que.front(); que.pop();
			for (int i = 0; i < 4; i++) {
				int nx = now.first+dx[i],ny = now.second+dy[i];
				if(nx >= 0 && nx < w && ny >= 0 && ny < h && board[nx][ny] == board[xs][ys] && !visited[nx][ny]){
					visited[nx][ny] = true;
					que.emplace(nx,ny);
				}
			}
		}
		puts((visited[xg][yg]) ? "OK" : "NG");
	}
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
int main(){
  int ans;
  vector<int> x(5);
  for(int i=0;i<5;i++){
    cin>>x.at(i);
    if(x.at(i)==0)ans=i+1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <math.h>
int n;
int ary[20];
int min(int a,int b){
	if(a<b)return a;
	else return b;
	}
int solve(int a,int b,int k){
	if(n==k){
		return abs(a-b);
		}
	return min(solve(a+ary[k],b,k+1),solve(a,b+ary[k],k+1));

	}
int main(){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		int i;
		for(i=0;i<n;i++){
			scanf("%d",&ary[i]);
			}
		printf("%d\n",solve(0,0,0));
		}
	return 0;
	}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#pragma GCC optimize ("trapv")
using namespace std;

#define pii pair<int, int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define DEBUG 1
#define cerr if (DEBUG) cerr
#define test cerr << "hi\n";

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l, r) uniform_int_distribution<long long>(l, r)(rng)
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;

#define INF 0x3f3f3f3f3f3f3f3f
#define MAXN 1000006
//#define MOD 998244353LL
#define MOD 1000000007LL

int p[MAXN];
int h, l;
long long ans = 0;
long long sum[MAXN];
vector<int> changed;
long long root;

void dfs2(int x, long long acc = 1) {
    if (x >= l) {
//        cerr << "transition " << x << '\n';
        (acc *= x) %= MOD;
        x = p[x];
        while (x > 1) {
            (acc *= x) %= MOD;
            (ans += root * acc % MOD * sum[x^1] % MOD * (x/2) % MOD) %= MOD;
            x /= 2;
        }
    }
    else {
        dfs2(x<<1, acc*x%MOD);
        dfs2(x<<1|1, acc*x%MOD);
    }
}

void dfs1(int x, long long acc = 1) {
    if (x >= l) {
//        cerr << "transition " << x << '\n';
        (acc *= x) %= MOD;
        x = p[x];
        while (x > 1) {
            (acc *= x) %= MOD;
            changed.pb(x);
            (sum[x] += acc) %= MOD;
            x /= 2;
        }
    }
    else {
        dfs1(x<<1, acc*x%MOD);
        dfs1(x<<1|1, acc*x%MOD);
    }
}

void work(int x) {
    root = x;
    dfs1(x<<1, 1);
    dfs2(x<<1|1, 1);

    for (int x : changed)
        sum[x] = 0;
    changed.clear();
}

void solve() {
    cin >> h;
    l = 1<<(h-1);
    for (int i = l; i < l*2; i++) {
        cin >> p[i];
        p[i] = l + p[i] - 1;
    }
    for (int i = 1; i < l; i++)
        work(i);
    cout << ans << '\n';
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    auto start_time = clock();
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
//    cin >> t;
    for (int no = 1; no <= t; no++) {
//        cout << "Case #" << no << ": ";
        solve();
    }

#ifdef LOCAL
    cerr << "TIME ELAPSED: " << double(clock() - start_time) / CLOCKS_PER_SEC << '\n';
#endif
}

Measured memory_bytes: 14204
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            if(n == 0){
                break;
            }
            int[] s;
            s = new int[n];
            int Sum = 0;
            for(int i = 0; i < n; i++){
                s[i] = sc.nextInt();
                Sum += s[i];
            } 
            double Average = (double)Sum/n;
            double a = 0.0;
            for(int i = 0; i < n; i++){
                a += (s[i] -Average)*(s[i] -Average);
            }
            a /= n;
            System.out.println(Math.sqrt(a));
        }
    }    
}


Measured memory_bytes: 31732
#include<iostream>
#include<vector>
#include<cstdio>

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

using namespace std;

int s[20];
int e[20];
int d[20];

int use[20];
int c;
int f;
int n, m;
vector<int> p;

bool dfs(int pos){
  // printf("pos: %d  cnt: %d\n", pos, c);
  if(c == 0){
    p.push_back(pos);
    return true;
  }

  REP(i,m) if(use[i] && (s[i] == pos || e[i] == pos)){
    int next = (s[i] == pos ? e[i] : s[i]);

    c--;
    use[i] = false;

    if(dfs(next)){
      p.push_back(pos);
      return true;
    }

    use[i] = true;
    c++;
  }

  return false;
}

int main(){
  while(scanf("%d%d", &n, &m), n + m){
    pair<int,int> ans = make_pair(0,0);
    
    REP(i,m) scanf("%d%d%d",s+i,e+i,d+i);
    REP(i,m){ s[i]--; e[i]--; }
    
    REP(i,1<<m){
      int cnt[10] = { 0 };
      int dist = 0;
      int bad  = 0;
      
      REP(j,m) if(i & (1 << j)){
	cnt[s[j]]++;
	cnt[e[j]]++;
	dist += d[j];
      }
      
      REP(j,n) if(cnt[j] % 2 == 1) bad++;
      
      if(bad <= 2)
	ans = max(ans, make_pair(dist, i));
    }
    
    int cnt[10] = { 0 };
    int bad  = 0;
    REP(i,m) if(ans.second & (1 << i)){
      cnt[s[i]]++;
      cnt[e[i]]++;
      use[i] = (ans.second & (1 << i)) != 0;
    }
    REP(j,n) if(cnt[j] % 2 == 1) bad++;
    c = 0; REP(i,m) if(use[i]) c++;
    p = vector<int>();

    // printf("%d %d %d\n", ans.second, c, bad);
    if(bad == 0){
      REP(i,n) if(cnt[i] > 0){
	if(!dfs(f = i)) puts("error");
	break;
      }
    }else{
      REP(i,n) if(cnt[i] % 2 == 1){
	if(!dfs(f = i)) puts("error");
	break;
      }
    }

    printf("%d\n", ans.first);

    for(int i = p.size() - 1; i >= 0; i--)
      printf("%d%c", p[i] + 1, i == 0 ? '\n' : ' ');
  }

  return 0;
}

Measured memory_bytes: 0
N = int(input())

l = []
for i in range(N):
    S,P=input().split()
    l.append((S, int(P), i))
l_s = sorted(l, key=lambda x:x[1], reverse=True)
l_s2 = sorted(l_s, key=lambda x:x[0])
for i in range(N):
    print(l_s2[i][2] + 1)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int n,a,b,c;
  cin >> n;
  for(int i=0;i<n;i++){
    int ans=0;
    cin >> a >> b >> c;
    while(1){
      if(a<=0 || b<=0 || c<=0){
	break;
      }
      a--;
      b--;
      c--;
      ans++;
    }
    while(1){
      if(a<=1 || b<=0){
	break;
      }
      a-=2;
      b--;
      ans++;
    }
    while(1){
      if(a<=2){
	break;
      }
      a-=3;
      ans++;
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1164
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        if (n == 25) return "Christmas";
        if (n == 24) return "Christmas Eve";
        if (n == 23) return "Christmas Eve Eve";
        if (n == 22) return "Christmas Eve Eve Eve";

        return null;
    }
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



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

	vi p(n + 1, 1);
	p[0] = 0; p[1] = 0;
	vi a;
	REP(i, p.size()) {
		if (p[i]) {
			a.push_back(i);
			for (int j = 2; i*j < p.size(); ++j)p[i*j] = 0;
		}
	}
	vi cnt(a.size());
	REP(i, a.size()) {
		int t = a[i];
		int tmp = 0;
		while (t <= n) {
			tmp += n / t;
			t *= a[i];
		}
		cnt[i] = tmp;
	}

	vvi v = { {74},{2,24}, {5,15},{3,5,5} };
	int ans = 0;
	REP(i, a.size()) {
		if (cnt[i] >= 74)ans++;
	}
	REP(i, a.size()) {
		if (cnt[i] >= 2) {
			REP(j, a.size()) {
				if (i == j)continue;
				if (cnt[j] >= 24)ans++;
			}
		}
	}
	REP(i, a.size()) {
		if (cnt[i] >= 4) {
			REP(j, a.size()) {
				if (i == j)continue;
				if (cnt[j] >= 14)ans++;
			}
		}
	}

	REP(i, a.size()) {
		if (cnt[i] >= 2) {
			REP(j, a.size()) {
				if (i == j)continue;
				if (cnt[j] >= 4) {
					FOR(k, j + 1, a.size()) {
						if (i == k)continue;
						if (cnt[k] >= 4)ans++;
					}
				}


			}
		}

	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

"""
# 文字列（数値変換も含む）
n = readline().rstrip() # １行に１文字列のみ
lis = readline().rstrip().split() # # １行に複数の文字列

# 数値（文字変換も含む）
n = int(readline().rstrip()) # １行に数値１個のみ
a, b, c = map(int,readline().rstrip().split()) # １行に複数の数値
A = list(map(int,readline().rstrip().split()))  # １行に複数の数値（リスト受け取り）
lis = [readline().rstrip().split() for _ in range(n)] # １行に複数の数値(m個)かつ、n行続く場合（出力は二次元リスト：[['1', '2'], ['4', '5']]）

# 一行に文字列が一個 * n行
s_lis=[readline().rstrip().decode() for _ in range(n)] # .decodeはバイト列から文字列へ変換
# 一行に文字列が一個 * n行で文字列をアルファベット順に変換
s_lis=["".join(sorted(readline().rstrip().decode())) for _ in range(n)]
# 一行に文字列が複数個 * n行
s_lis=[readline().rstrip().split().decode() for _ in range(n)] # .decodeはバイト列から文字列へ変換

# 一行に数値が一個 * n行
s_lis=[int(readline().rstrip()) for _ in range(n)] 
# 一行に数値が複数個 * n行
s_lis=[int(readline().rstrip().split()) for _ in range(n)]

# dとAの行が交互に並んでいる場合
s = sys.stdin.readlines()
n, k=map(int, s[0].split())
d=[]
A=[]
for i in s[1:2*k:2]:
    d.append(int(i))
for i in s[2:2*k+1:2]:
    A.append(list(map(int, i.split())))
"""

a,b,c,k=map(int,input().split())

if k<=a:
    print(k)

elif a<k<=a+b:
    print(a)

else:
    print(2*a+b-k)

Measured memory_bytes: 9188
N,K=[int(x) for x in input().split()]
S=input()
bg=S[0]
t=0
A=[]
for i in range(N):
    if S[i]==bg:
        t+=1
    else:
        A.append(t)
        bg=S[i]
        t=1
A.append(t)
ans=N - max( (len(A)-2*K) , 1)
print(ans)

Measured memory_bytes: 3956