akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;

int main() {
   ll n,k;cin >>n>>k;
   vector<ll>a(n);
   vector<ll>b(n);
    for (int i = 0; i < n; ++i) {
        cin >>a[i]>>b[i];
    }
    ll ans=0;
    vector<int>x;
    for (int i =30; i>=0; --i) {
        if(1LL&(k>>i))x.push_back(i);
    }
    ll now=0;
    vector<ll>lis;
    lis.emplace_back(k);
    for (int i =0; i <x.size(); ++i) {
        now=0;
        for (int j = 0; j <=i; ++j) {
            now+=((1LL)<<x[j]);
        }
        now--;
        if(now>0) {
            lis.emplace_back(now);
        }
    }
    now=0;
    for (int l = 0; l < lis.size(); ++l){
        now=0;
        for (int i = 0; i < n; ++i) {
            if(lis[l]>=(lis[l]|a[i]))now+=b[i];
        }
//        cout <<lis[l]<<" "<<now<<endl;
        ans=max(ans,now);
    }
    cout <<ans<<endl;
}


Measured memory_bytes: 4848
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean ok = true;
		for(int i = 0; i < N; i++) {
			int A = sc.nextInt();
			if(A % 2 == 0)
				if(A % 3 != 0 && A % 5 != 0)
					ok = false;
		}
		System.out.println(ok ? "APPROVED" : "DENIED");

	}

}

Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <math.h>
 
using namespace std;
 
int main(){
 double pi=3.14159265358979;
 int N,i,j=0;
 cin >> N;
 int x[N],y[N],min=1000000,mini=0;
 for (i=0; i<N; i++) {
  cin >> x[i];
  cin >> y[i];
  if (x[i]<min) {
   min=x[i];
   mini=i;
  } else if (x[i]==min && y[i]<y[mini]) {
   min=x[i];
   mini=i;
  }
 }
 int minii=mini;
 
 double oldk=-999999999,k[N],s[N],p[N];
 for (i=0; i<N; i++) {
  p[i]=0;
 }
 
 for (j=0;j<N;j++) {
  int kupi=mini,kmini=mini;
  k[mini]=9999999999;
  for (i=0; i<N; i++) {
   if (mini==i) {
    continue;
   } else if (x[mini]-x[i]==0) {
    k[i]=9999999999;
   } else {
    k[i]=(y[mini]-y[i]);
    k[i]=k[i]/(x[mini]-x[i]);
   }
   if (k[i]>oldk && k[kupi]>k[i]) kupi=i;
   if (k[i]>oldk && k[kupi]==k[i] && abs(x[mini]-x[kupi])+abs(y[mini]-y[kupi])<abs(x[mini]-x[i])+abs(y[mini]-y[i])) kupi=i;
   if (k[kmini]>k[i]) kmini=i;
   if (k[kmini]==k[i] && abs(x[mini]-x[kmini])+abs(y[mini]-y[kmini])<abs(x[mini]-x[i])+abs(y[mini]-y[i])) kmini=i;
  }
  if (kupi!=mini) {
   s[j]=atan(k[kupi]);
  } else {
   s[j]=atan(k[kmini]);
  }
  if (j>0) {
   if (s[j]-s[j-1]<=0) {
    p[mini]=(s[j]-s[j-1]+pi)/(2*pi);
   } else {
    p[mini]=(s[j]-s[j-1])/(2*pi);
   }
  }
  if (kupi!=mini) {
   mini = kupi;
  } else {
   mini = kmini;
  }
  oldk=k[mini];
  if (mini==minii) {
   j+=1;
   break;
  }
 }
 
 j-=1;
 
 if (s[0]-s[j]<=0) {
  p[minii]=(s[0]-s[j]+pi)/(2*pi);
 } else {
  p[minii]=(s[0]-s[j])/(2*pi);
 }
 
 for (i=0;i<N;i++) {
  cout << p[i];
  if (i<N-1) cout << endl;
 }
 return 0;
}

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

using namespace std ;

#define IOS ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
#define ll long long int 

#define fr first
#define se second

#define all(v) v.begin(),v.end() 
#define rall(v) v.rbegin(),v.rend()
#define sz(v) v.size() 

#define pb push_back
#define mp make_pair 

#define PI 3.141592653589793238



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


//bool valid(int x, int y){return x > 0 && x < 9 && y > 0 && y < 9;}


int n, s1, s2, mm = INT_MAX;
vector<int>v;

int main(){
  cin >> n;
  v.resize(n);
  for(int i = 0 ; i < n ; i++){
    cin >> v[i];
    s1+= v[i];
  }
  for(int i = 0; i < n ; i++){
    mm = min(mm, abs(s1-s2));
    s1 -= v[i];
    s2 += v[i];
  }
  cout << mm;
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

s = input()
t = input()

tmp = 0
res = "No"

if s == t[:-1]:
    res = "Yes"

print(res)


Measured memory_bytes: 31104
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;
#define pi 3.1415926
 
 int a[100005];
 int b[100005];

int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++)
        b[a[i]] = i;
    for(int i = 1; i <= n; i++)
        cout << b[i] << ' ';

}


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

int main() {
    int a, b;
    int cnt = 0;
    cin >> a >> b;

    for (int i = a; i <= b; i++) {
        string s = to_string(i);
        bool f = false;
        int sz = s.size();
        for (int j = 0; j < sz/2; j++) {
            if (s[j] != s[sz-j-1]) {
                f = true;
            }
        }
        if (f == false) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

int main() {
	string str;
	stack<char>br;
	while (getline(cin, str), str != ".") {
		int flag = false;
		while (br.empty() != true) br.pop();
		for (int i = 0; i < str.size(); i++) {
			if (str[i] == '(' || str[i] == '[') br.push(str[i]);
			else if (str[i] == ')') {
				if (br.empty()) {
					br.push('@');
					break;
				}
				else if ('(' == br.top())br.pop();
				else break;
			}
			else if (str[i] == ']') {
				if (br.empty()) {
					br.push('@');
					break;
				}
				else if ('[' == br.top())br.pop();
				else break; 
			}
		}
		if (br.empty()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, h;
	cin >> n >> h;
	vector<ll> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	ll ans = 0;
	for (auto i : b) {
		if (i <= a[0]) break;
		h -= i;
		ans++;
		if (h <= 0) break;
	}
	if (h > 0) ans += (h + a[0] - 1) / a[0];
	cout << ans << endl;
	return 0;
}


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

int gcd(int x,int y, int z){
  int a = (x % y)? gcd(y, x % y): y;
  return (z % a)? gcd(a, z % a): a;
}
int main() {
  int k;
  cin >> k;
  int ans = 0;
  for(int i = 1; i <= k; i++){
    for(int j = 1; j <= k; j++){
      for(int l = 1; l <= k; l++){
        ans += gcd(i,j,l);
      }
      
    }
    
  }
  cout << ans << endl;
}


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

using namespace std;
int main(){
    int N,a,b;cin >> N;a,b = 0;
    std::vector<int> P(N);for(int i=0;i<N;i++) cin >> P[i];
    a = P[0];
    for(int i=0;i<N;i++){
        if(a>=P[i]){
            b+=1;
        }
        if(a>P[i]){
            a = P[i];
        }
    }
    cout << b << endl;
    return 0;
}


Measured memory_bytes: 1024
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

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

  ll r = 0;
  ll b = 0;
  for (const auto &c : S) {
    (c == '0' ? r : b)++;
  }
  cout << min(r, b) * 2 << endl;
  return 0;
}


Measured memory_bytes: 3752
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            a = list(str(i))
            if a[-1] == '1':
                ass.append(i)
    return ass


def main():
    N = int(input())
    ass = primes(55555)
    ans = []
    for i in range(N):
        ans.append(ass[i])
    print(*ans)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 68784
def main():
    ABCD = input()

    total = 0
    mask = 0
    n = len(ABCD)
    while mask < (1<<(n-1)):
        i = 0
        s = list(ABCD)
        while i < n-1:
            if mask & (1<<i):
                s[i] = s[i] + '+'
            else:
                s[i] = s[i] + '-'
            i += 1
        total = eval(''.join(s))
        if total == 7:
            break
        mask += 1

    print(*s, sep='', end='')
    print('=' + str(total))

main()


Measured memory_bytes: 3064
sa = gets.chomp
sb = gets.chomp
sc = gets.chomp
i = 'a'
a = 0
b = 0
c = 0
len_a = sa.length
len_b = sb.length
len_c = sc.length
while true
  if i == 'a'
    if a >= len_a
      puts "A"
      exit
    end
    i = sa[a]
    a += 1
  elsif i == 'b'
    if b >= len_b
      puts "B"
      exit
    end
    i = sb[b]
    b += 1
  else
    if c >= len_c
      puts "C"
      exit
    end
    i = sc[c]
    c += 1
  end
end

Measured memory_bytes: 14384
#include <bits/stdc++.h>
#define sz(a) ((int)(a.size()))
#define sg sz(ve[g])
using namespace std;

const int N = 200005;
int n, x, y, fp[N];
vector<int> v[N], ve[2];
bool g, gr[N];

void sgd(int dg, int op, bool bo) {
	ve[bo].push_back(dg);
	for(int i = 0; i < v[dg].size(); ++i) {
		if(v[dg][i] != op) {
			sgd(v[dg][i], dg, bo ^ 1);
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 1; i < n; ++i) {
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	sgd(1, 0, 0);
	if(sz(ve[0]) > sz(ve[1])) g = 1;
	if(n / 3 >= sg) {
		int j3 = 3;
		for(int i = 0; i < ve[g].size(); ++i) {
			fp[ve[g][i]] = j3;
			gr[j3] = 1;
			j3 += 3;
		}
	} else {
		int j1 = 1, j2 = 2;
		for(int i = 0; j1 <= n; ++i) {
			fp[ve[0][i]] = j1;
			gr[j1] = 1;
			j1 += 3;
		}
		for(int i = 0; j2 <= n; ++i) {
			fp[ve[1][i]] = j2;
			gr[j2] = 1;
			j2 += 3;
		}
	}
	int dgr = 1;
	for(int i = 1; i <= n; ++i) {
		while(gr[dgr]) ++dgr;
		if(fp[i] == 0) {
			fp[i] = dgr;
			gr[dgr] = 1;
		}
	}
	for(int i = 1; i <= n; ++i) {
		cout << fp[i] << " ";
	}
	return 0;
}


Measured memory_bytes: 19444
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)
 
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define repp(i, a, b) for(int i = a; i <= b; i++)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, b, a) for(int i = b; i >= a; i--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mem(a, b) memset(a, b, sizeof(a));
#define mem0(a) memset(a, 0, sizeof(a));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in_edges(m) repp(i, 1, m){ll a, b; cin >> a >> b; v[a].pb(b), v[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define endl "\n"
ll power(ll x, ll y); 

const ll MOD = 1000000007;
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    ll n;
    cin >> n;

    map<string, ll> m;

    ll mx = 0;

    rep(i, 0, n){
        string s;
        cin >> s;
        m[s]++;
        mx = max(mx, m[s]);
    }

    for(auto i : m){
        if(i.ss == mx) cout << i.ff << endl;
    }
}
 
ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 25216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
        private static class FastScanner {
            private BufferedReader reader = null;
            private StringTokenizer tokenizer = null;

            public FastScanner(InputStream in) {
                reader = new BufferedReader(new InputStreamReader(in));
                tokenizer = null;
            }

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

            public String nextLine() {
                if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    try {
                        return reader.readLine();
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }

                return tokenizer.nextToken("\n");
            }

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

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

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

            public int[] nextIntArray(int n) {
                int[] a = new int[n];
                for (int i = 0; i < n; i++)
                    a[i] = nextInt();
                return a;
            }

            public long[] nextLongArray(int n) {
                long[] a = new long[n];
                for (int i = 0; i < n; i++)
                    a[i] = nextLong();
                return a;
            }
        }

    public static void main(String[] args) {
        Main.FastScanner sc = new Main.FastScanner(System.in);

        int N = 0;
        N = sc.nextInt();
        boolean flag = true;
        int array [] = sc.nextIntArray(N);
        for (int i = 0; i < N; i++) {
            if (array[i] % 2 == 0) {
                if (array[i] % 3 != 0 && array[i] % 5 != 0){
                    flag = false;
                }
                }
            }
        System.out.println(flag == true ? "APPROVED" : "DENIED");

    }

}



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

public class Main {
    static long mod = 998244353;
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out, false);
        int n = scanner.nextInt();
        int[] dists = new int[n];
        for(int i =0; i < n; i++)  {
            dists[i] = scanner.nextInt();
            if ((i == 0 && dists[i] != 0) || (i != 0 && dists[i] == 0)) {
                System.out.println(0);
                return;
            }
        }
        Arrays.sort(dists);
        long ans = 1;
        int p = 1;
        long prev = 1;
        for(int i = 1; i < n; i++) {
            long cnt = 0;
            while(p < n && dists[p] == i) {
                cnt++;
                p++;
            }
            if (cnt == 0) break;
            ans = (ans * modPow(prev, cnt)) % mod;
            prev = cnt;
        }
        if (p < n) out.println(0);
        else out.println(ans);
        out.flush();
    }
    static long modPow(long x, long p) {
        if (p == 0) return 1L;
        long t = modPow(x, p/2);
        t = (t * t) % mod;
        if (p % 2 == 0) return t;
        return (x * t) % mod;
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 33928
#include <stdio.h>

#define MAX 100000

void swap(int*,int*);
void Partition(int,int,int*);

int main(){
  int n,i,A[MAX];
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  Partition(0,n-1,A);
  return 0;
}

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

void Partition(int l,int r,int *A){
  int x = A[r],i = l,j;
  for(j = l ; j < r ; j++){
    if(A[j] <= x){
      swap(&A[i++],&A[j]);
    }
  }
  swap(&A[i],&A[r]);
  for(j = l ; j <= r ; j++){
    if(j > l){ printf(" "); }
    if(j == i){
      printf("[%d]",A[j]);
    }else{
      printf("%d",A[j]);
    }
  }
  printf("\n");
}

Measured memory_bytes: 992
A = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

B = factorization(A)
N = len(B)
ans = 0
for n in range(N):
  m =1
  b = B[n][1]
  while b >= ((m+1)*(m+2)//2):
    m+=1
  ans += m
if A==1:
  print(0)
else:
  print(ans)
  


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

int main(){
 int a,b,c,d;
  cin>>a>>b>>c>>d;
  int tuduku=0;
  while(tuduku==0){
    c=c-b;
    if(c<=0){
      cout<<"Yes"<<endl;
      return 0;
    }
    a=a-d;
    if(a<=0){
      cout<<"No"<<endl;
      return 0;
    }
    
  }
  
}

Measured memory_bytes: 3636
<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}

/*		START		*/
$temp = getq(1);
$N = $temp[0];
$X = $temp[1];
$M=array();
$ans=0;
for ($i=0; $i < $N; $i++){
	$M[$i]=getq();
	$X-=$M[$i];
	$ans++;
}
while($X>=min($M)){
	$X-=min($M);
	$ans++;
}
echo "$ans\n";
?>

Measured memory_bytes: 4856
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    while (cin >> n, n) {
        vector<int> a(n);
        rep(i, n) cin >> a[i];
        double ave = accumulate(all(a), 0.0) / n;
        vector<double> b(n);
        rep(i, n) b[i] = a[i] - ave;
        double ans = 0;
        rep(i, n) ans += b[i] * b[i];
        ans /= n;
        ans = sqrt(ans);
        cout << fixed << setprecision(15) << ans << endl;
    }
}



Measured memory_bytes: 3300
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////



int main() {

	char a, b;
	cin >> a >> b;

	if (a == 'H'&&b == 'H') {cout << 'H';}
	if (a == 'H'&&b == 'D') { cout << 'D'; }
	if (a == 'D'&&b == 'H') { cout << 'D'; }
	if (a == 'D'&&b == 'D') { cout << 'H'; }

	system("PAUSE");
}


Measured memory_bytes: 504
s = raw_input()

ans = len(s)
for c in range(26):
  c = chr(ord("a")+c)
  t = s
  n = 0
  while True:
    if t==c*len(t):
      break
    x = ""
    for i in range(len(t)-1):
      if t[i+1]==c:
        x += t[i+1]
      else:
        x += t[i]
    t = x
    n += 1
  ans = min(ans, n)
print ans


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int n,q;
string s;
vector<char> t(200010),d(200010);

bool left(int x){
  int now=x;
  rep(i,q){
    if(t[i]==s[now]){
      if(d[i]=='L') now--;
      else now++;
    }
    if(now==-1) return true;
    if(now==n) break;
  }
  return false;
} 

bool right(int x){
  int now=x;
  rep(i,q){
    if(t[i]==s[now]){
      if(d[i]=='L') now--;
      else now++;
    }
    if(now==n) return true;
    if(now==-1) break;
  }
  return false;
} 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>q;
  cin>>s;
  rep(i,q) cin>>t[i]>>d[i];
  int high=n,low=0,mid;
  int ans1,ans2;
  while(high-low>1){
    mid=(high+low)/2;
    if(left(mid)) low=mid;
    else high=mid;
  }
  ans1=low;
  high=n,low=0;
  while(high-low>1){
    mid=(high+low)/2;
    if(right(mid)) high=mid;
    else low=mid;
  }
  ans2=high;
  //cout<<ans1<<' '<<ans2<<endl;
  if(ans1>=ans2) cout<<0<<endl;
  else{
    cout<<ans2-ans1-1<<endl;
  }
}

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

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

    return gcd(b,a % b);
}

int main(int argc,char* argv[] ){
    int d;
    cin >> d;
    int answer = 0;
    for(int i = 1;i <= d;i ++){
        for(int l = 1;l <= d; l ++){
            for(int m = 1;m <= d;m ++){
                answer += gcd(gcd(i,l),m);
            }
        }
    }

    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 3616
import java.util.*;

public class Main {
	static int n, v, c;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = Integer.parseInt(sc.nextLine());
		
		String[] vs = sc.nextLine().split(" ");
		String[] cs = sc.nextLine().split(" ");
		
		v = 0;
		c = 0;
		//System.out.println(vs);
		for(int i = 0; i < n; i++) {
			if(Integer.parseInt(vs[i]) - Integer.parseInt(cs[i]) > 0) {
				v+=Integer.parseInt(vs[i]);
				c+=Integer.parseInt(cs[i]);
			}
		}
		//System.out.println(vs);
		System.out.println(v-c);
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

char t[200001] = {}, d[200001] = {};
int n, q;
string s;

int solve(int idx) {
  rep(i, 0, q) {
    if(t[i] == s[idx]) {
      if(d[i] == 'L') idx--;
      else idx++;
    }
    if(idx >= n) return true;
  }
  return false;
}

int solve2(int idx) {
  rep(i, 0, q) {
    if(t[i] == s[idx]) {
      if(d[i] == 'L') idx--;
      else idx++;
    }
    if(idx < 0) return true;
  }
  return false;
}


signed main() {
  cin >> n >> q >> s;
  rep(i, 0, q) cin >> t[i] >> d[i];

  int left = -1, right = n;
  while (right - left > 1) {
    int mid = left + (right - left) / 2;
    if (solve(mid)) right = mid;
    else left = mid;
  }
  int r = left;
  left = -1, right = n;
  while (right - left > 1) {
    int mid = left + (right - left) / 2;
    if (solve2(mid)) left = mid;
    else right = mid;
  }
  int l = right;
  cout << max(r - l + 1, (int)0) << endl;
}


Measured memory_bytes: 976
#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 <<"Balanced"<<endl;
  }
  else{
    cout <<"Right"<<endl;
  }
}

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

int main(){
  long long n, i, ans=0, last=-1;
  cin >> n;
  long long a[21] = {};
  long long b[21] = {};
  long long c[21] = {};
  
  for (i=0; i<n; i++){
    cin >> a[i];
  }
  for (i=0; i<n; i++){
    cin >> b[i];
  }
  for (i=0; i<n-1; i++){
    cin >> c[i];
  }
  
  for (int i=0; i<n; i++){
    ans += b[a[i] - 1];
      if (a[i] - last == 1){
        ans += c[a[i-1] - 1];
      }
    last = a[i];
  }
    
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  if(N<1000) cout<<"ABC"<<endl;
  else cout<<"ABD"<<endl;
}


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

int main()
{
    ll a,b,c,d,x,cnt=0;
     cin>>a>>b>>c;
     if(a%c==0) cnt++;

    d= b/c;
    x= a/c;
    d = d-x;
    cout<<d+cnt<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>


int min(int p,int q)
{
        if(p >= q) {
                return q;
        } else {
                return p;
        }
}

int main(void)
{
        int i,n,a,b;
        scanf("%d",&n);
        scanf("%d %d",&a,&b);

        int counta = 0,countb = 0,countc = 0;
        int p[n];
        for(i = 0;i < n;i++) {
                scanf("%d",&p[i]);

                if(p[i] <= a) {
                        counta++;
                } else if(p[i] > a && p[i] <= b) {
                        countb++;
                } else if(p[i] > b) {
                        countc++;
                }

        }


        printf("%d\n",min(min(counta,countb),countc));

        return 0;
}


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

const int MAXN = 100005;

long long n, a[MAXN], sum, d[MAXN];

int main() {

	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);

		sum += a[i];
	}

	if (sum % (n * (n + 1) / 2) != 0) {
		printf("NO\n");
		return 0;
	}

	int k = sum / (n * (n + 1) / 2);

	for (int i = 0; i < n; i++) {
		d[i] = a[(i+1)%n] - a[i];
	}

	int left = k;
	for (int i = 0; i < n; i++) {
		int tmp = k - d[i];
		if (tmp < 0 || (tmp % n != 0 && left - tmp / n >= 0)) {
			printf("NO\n");
			return 0;
		} else {
			left -= tmp / n;
		}
	}

	printf("YES\n");

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    
    int A, B;
    cin >> A >> B;

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

    if ((A - B) % 2 != 0) cout << "IMPOSSIBLE" << endl;
    else cout << B + (A - B) / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
N = input()
lst = input().split(" ")
lst2 = []
for i in lst:
    int_i = int(i)
    #print(int_i)
    lst2.append(int_i)
#print(lst2)
max  = max(lst2)
#print(max)
sum = sum(lst2)
#print(sum)
if sum - max > max:
    print("Yes")
else:
    print("No")
#input()

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

#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define ff first
#define ss second

typedef long long ll;

using namespace std;

const int N = 1e5+5;

int n,a,b;

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>a>>b;
	cout << min( n*a , b ); 
	return 0;
}


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

int main(){
  long long N,K;
  cin >> N >> K;
  vector<long long> H(N);
  for(int i=0;i<N;i++){
    cin >> H.at(i);
  }
  sort(H.begin(),H.end());
  reverse(H.begin(),H.end());
  if(K>=N){
      cout << 0 << endl;
  }
  else{
      long long a=0;
      for(int i=K;i<N;i++){
          a+=H.at(i);
      }
      cout << a << endl;
  }
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main() {
  ll n , k ; 
  cin >> n >> k ;
  vector<pair<ll,ll>>vec;
  rep(i,n){
    ll a,b; cin>>a>>b;
    vec.push_back(make_pair(a,b));
  }
  sort(vec.begin(),vec.end());
  ll sum=0;
  rep(i,n){
    sum+=vec[i].second;
    if(sum>=k){
      cout<<vec[i].first;
      break;
    }
  }
  
}



Measured memory_bytes: 2420
package main

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

var sc *bufio.Scanner

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

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)
	a := make([]int, 5)
	b := make([]int, 5)
	s := 0
	t := 0
	for i := 0; i < 5; i++ {
		a[i] = nextInt()
		b[i] = 10 - a[i]%10
		if b[i] == 10 {
			b[i] = 0
		}
		s += a[i]
		t += b[i]
	}
	sort.Ints(b)
	fmt.Fprintf(writer, "%d", s+t-b[4])
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    string s;cin>>s;
    ll count = 0;
    ll wcount = 0;
    for(int i =0;i<s.size();++i){
            if(s[i]=='W'){
                count+=i-wcount;
                wcount++;
            }

    }
    cout << count << endl;

}

Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <cmath>

int factorial(int n)
{
  int ret = 1;
  for(int i=0; i<n; i++) {
    ret *= n-i;
  }
  return ret;
}

// num: number created by N!
// digit: digit from left.(0 digit for 4123 is 4)
int get_order(const std::vector<int> &num,
              int digit)
{
  int len = num.size();
  int n = num[digit];
  int used = 0;
  for(int i=0; i<digit; i++) {
    if(num[i] < n) {
      ++used;
    }
  }
  return (n - used - 1) * factorial(len - digit - 1);
}

int main()
{
  int N;
  std::cin >> N;
  std::vector<int> P(N), Q(N);

  for(int i=0; i<N; i++) {
    std::cin >> P[i];
  }
  for(int i=0; i<N; i++) {
    std::cin >> Q[i];
  }

  int order_p = 0, order_q = 0;
  for(int i=0; i<N; i++) {
    order_p += get_order(P, i);
    order_q += get_order(Q, i);
    //    std::cout << "i: " << i
    //              << "order_p: " << order_p
    //              << "order_q: " << order_q
    //              << std::endl;
  }

  std::cout << std::abs(order_p - order_q) << std::endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <fstream>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
typedef long long ll;

ll N,C,K;
vector<ll> T;

int main() {

	cin >> N >> C >> K;
	T.resize(N);
	REP(i,N) cin >> T[i];

	sort(T.begin(),T.end());
	reverse(T.begin(),T.end());

	ll ans = 0;
	ll cnt = 0;
	ll start = -1;
	REP(i,T.size()) {
		if(start == -1) {
			start = T[i];
			cnt++;
		} else if(start - T[i] > K) {
			start = T[i];
			cnt = 1;
			ans++;
		} else {
			cnt++;
		}
		if(cnt == C) {
			cnt = 0;
			start = -1;
			ans++;
		}
	}

	if(cnt > 0) ans++;

	cout << ans << endl;

	return 0;
}



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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    string S;
    cin >> S;
    int n = 0, m = INT32_MAX;
    REP(i, S.length() - 2){
        n = (S[i] - '0') * 100 + (S[i + 1] - '0') * 10 + S[i + 2] - '0';
        m = min(m, abs(n - 753));
    }
    PRINT(m);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  string s;
  cin >> n >> s >> k;
  for(int i=0;i<n;i++){
    if(s[i]!=s[k-1]){
      s[i]='*';
    }
  }
  cout << s << endl;
}


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

long long int n,m,ans[100010],i,x,a,b;
vector<long long int> adj[100010];
bool vis[100010];
queue<long long int> q;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>m;
	for (i=1;i<m+1;i++)
	{
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for (i=2;i<n+1;i++) vis[i]=false;vis[1]=true;
	q.push(1);
	while (!q.empty())
	{
		a=q.front();q.pop();
		for (auto u:adj[a])
		{
			if (vis[u]) continue;
			vis[u]=true;ans[u]=a;
			q.push(u);
		}
	}
	cout<<"Yes"<<"\n";
	for (i=2;i<n+1;i++) cout<<ans[i]<<"\n";
}


Measured memory_bytes: 13148
c = []
for i in range(3):
    c.append(list(map(int, input().split())))
f = True
for i in range(2):
    tmp = []
    for j in range(3):
        tmp.append(c[i + 1][j] - c[i][j])
    if (tmp[0] == tmp[1]) and (tmp[1] == tmp[2]):
        pass
    else:
        f = False

for i in range(2):
    tmp = []
    for j in range(3):
        tmp.append(c[j][i+1] - c[j][i])
    if (tmp[0] == tmp[1]) and (tmp[1] == tmp[2]):
        pass
    else:
        f = False

print("Yes" if f else "No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  int n;
  cin >> n;
  vector<ll> a(n), s(n + 1, 0);
  rep(i, n) cin >> a[i];
  rep(i, n) s[i + 1] = s[i] + a[i];
  map<ll, ll> mp;
  rep(i, n + 1) mp[s[i]]++;
  ll ans = 0;
  for (auto x : mp) ans += x.second * (x.second - 1) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 18544
#include <vector>
#include <iostream>
using namespace std;
class UnionFind {
private:
	int size_; vector<int> g; vector<vector<int> > v;
public:
	UnionFind() : size_(0), g(vector<int>()), v(vector<vector<int> >()) {};
	UnionFind(int size__) : size_(size__) {
		g.resize(size__); v.resize(size__);
		for (int i = 0; i < size__; i++) g[i] = i, v[i] = { i };
	};
	int size() { return size_; }
	int root(int x) { return g[x]; }
	int size(int x) { return v[x].size(); }
	bool same(int x, int y) { return g[x] == g[y]; }
	void unite(int x, int y) {
		x = g[x], y = g[y];
		if (x == y) return;
		if (v[x].size() < v[y].size()) swap(x, y);
		v[x].insert(v[x].end(), v[y].begin(), v[y].end());
		for(auto &e : v[y]) g[e] = x;
		v[y].clear();
	}
	bool operator==(const UnionFind& u) { return g == u.g; }
	bool operator!=(const UnionFind& u) { return g != u.g; }
	int operator[](int x) { return g[x]; }
};
int n, q, c, x, y;
int main() {
	scanf("%d%d", &n, &q);
	UnionFind u(n);
	for(int i = 0; i < q; i++) {
		scanf("%d%d%d", &c, &x, &y);
		if(c) printf("%d\n", u.same(x, y) ? 1 : 0);
		else u.unite(x, y);
	}
}

Measured memory_bytes: 3724
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int c[N];
int s[N];
int f[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		cin >> c[i] >> s[i] >> f[i];
	}
	for (int i = 1; i <= n; i++)
	{
		int cur = 0;
		for (int j = i; j < n; j++)
		{
			cur = max(cur, s[j]);
			cur = (cur + f[j] - 1) / f[j] * f[j];
			cur += c[j];
		}
		cout << cur << endl;
	}
	return 0;
}


Measured memory_bytes: 256
from collections import deque

n = int(input())
w = list(map(int, input().split()))

d = deque(w)
a = 0
for i in range(len(w)):
    if a <= 0:
        a += d.popleft()
        continue
    if a > 0:
        a -= d.pop()
        
print(abs(a))

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

int main()
{
   static long i,j,k;
   long n;
   long cnt = 0;
   long left,right,mid;
   long ans = 0;
   double r;
   double pai =3.14159265358979;
   scanf("%lf",&r);
   printf("%lf %lf\n",pai*r*r,2*pai*r);
   return 0;
}

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

int h, w, ans;
char field[25][25];

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

void dfs(int x, int y) {
  if(field[y][x] == '.' && 0 <= x && x < w && 0 <= y && y < h) {
    field[y][x] = '#';
    ans++;
    for(int i = 0; i < 4; i++) {
      int nx = x+dx[i], ny = y+dy[i];
      dfs(nx, ny);
    }
  }
}

int main() {
  int sx, sy;
  while(cin >> w >> h, w+h) {
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
	cin >> field[i][j];
	if(field[i][j] == '@') {
	  sx = j;
	  sy = i;
	  field[i][j] = '.';
	}
      }
    }

    ans = 0;
    dfs(sx, sy);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,x,ans=0;
    cin >> a >> b >> c >> x;
    for (int i=0;i<a+1;i++){
        for (int I=0;I<b+1;I++){
            for (int q=0;q<c+1;q++){
                if ((500*i)+(100*I)+(50*q)==x) ans++;
            }
        }
    }
    cout << ans << endl;
}


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

struct edge{int to;ll cost;};
vector<edge> tree[nmax];
ll d[nmax];
int n;

void dijkstra(int s){
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
  fill(d,d+n,1e18);
  d[s]=0;
  pq.push(make_pair(0,s));
  while(!pq.empty()){
    pair<ll,ll> p=pq.top();
    pq.pop();
    int v=p.second;
    if(d[v]<p.first){
      continue;
    }
    for(int i=0;i<tree[v].size();i++){
      edge e=tree[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        pq.push(make_pair(d[e.to],e.to));
      }
    }
  }
}

int main(){
  int u,v,w,st;
  cin >> n;
  for(int i=0;i<n-1;i++){
    cin >> u >> v >> w;
    u--,v--;
    st=u;
    tree[u].push_back(edge{v,w});
    tree[v].push_back(edge{u,w});
  }
  dijkstra(st);
  for(int i=0;i<n;i++){
    cout << d[i]%2 << endl;
  }
}

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

#define ll long long 

using namespace std;

int n,l;
int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >>n>>l;
    vector <string> v(n);
    for (int i=0; i<n; i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    string all="";
    for (int i=0; i<v.size(); i++)
        all+=v[i];
    cout<<all;
    
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int r,c,co,gyou,retu;
	int rgou=0,cgou=0,rcgou=0;
	long long int count[100000];
	scanf("%d %d",&r,&c);
	for(co=0;co<(r*c);co++){
		scanf("%lld",&count[co]);
	}
	co=0;
	for(gyou=1;gyou<=r;gyou++){
		for(retu=1;retu<=c;retu++){
			printf("%lld",count[co]);
			if(retu<=c){printf(" ");}
			rgou+=count[co];
				if(retu>=c){printf("%d\n",rgou);rgou=0;rcgou+=rgou;}
			co++;
		}
	}
	co=0;
	gyou=1;
	retu=1;
	for(;;){
		cgou+=count[co];
		co+=c;
		gyou++;
		if(gyou>=r+1){
			printf("%d",cgou);
			rcgou+=cgou;
				if(retu<=c){printf(" ");}
			gyou=1;
			co=retu;
			retu++;
			cgou=0;
			if(retu>=c+1){
				printf("%d\n",rcgou);
				break;}
	}
	}
	
	
	
	
	return 0;
}

Measured memory_bytes: 1856
#include <stdio.h>

int main() {
	int n, tmp;
	float ans;

	scanf("%d", &n);

	if ((n % 2) == 0) {
		tmp = n / 2;
	}
	else {
		tmp = (n / 2) + 1;
	}
	ans = (float)tmp / (float)n;

	printf("%.10f", ans);

	return 0;
}

Measured memory_bytes: 128
if __name__ == '__main__':
	X, Y, A, B, C = map(int, input().split())
	p = [int(a) for a in input().split()]
	q = [int(a) for a in input().split()]
	r = [int(a) for a in input().split()]

	p.sort(reverse=True)
	q.sort(reverse=True)
	


	P = p[0:X]
	Q = q[0:Y]

	s = P+Q+r

	s.sort(reverse=True)

	S = s[0:X+Y]

	ans = sum(S)

	print(ans)

Measured memory_bytes: 23644
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';

int main() {
    int n,l;cin>>n>>l;
    vector<string>s(n);
    rep(i,n){
        cin>>s[i];
    }
    sort(s.begin(),s.end());
    rep(i,n){
        cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const in inf=1e9+7;
using P=pair<in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in n,k;
    cin>>n>>k;
    vector<in> a(n);
    rep(i,n) cin>>a[i];
    vector<in> sei(0),hu(0);
    // in cnt_zero=0;
    rep(i,n){
        if(a[i]>0) sei.emplace_back(a[i]);
        else hu.emplace_back(a[i]);
    }
    sort(all(sei));
    sort(all(hu));
    reverse(all(sei));

    if(n==k){
        in ans=1ll;
        rep(i,n){
            ans *=a[i];
            ans %=MOD;
        }
        if(ans<0) ans +=MOD;
        cout<<ans<<endl;
        return 0;
    }
    if(sei.empty()){
        if(k%2==0){
            in ans=1ll;
            rep(i,k){
                ans *= hu[i];
                ans %= MOD;
            }
            cout<<ans<<endl;
            return 0;
        }
        else{
            in ans=1ll;
            rep(i,k){
                ans *= hu[n-1-i];
                ans %=MOD;
            }
            if(ans<0) ans +=MOD;
            cout<<ans<<endl;
            return 0;
        }
    }

    in ans=1ll,sei_num=0,hu_num=0;
    if(k%2==1){
        ans *=sei[0];
        sei_num ++;
    }

    for(in i=0;i<k/2;i++){
        in kou_sei=0ll,kou_hu=0ll;
        if(sei_num-1ll<(in)sei.size() && !sei.empty()) kou_sei=sei[sei_num]*sei[sei_num+1];
        if(hu_num-1ll<(in)hu.size() && !hu.empty()) kou_hu =hu[hu_num]*hu[hu_num+1];

        if(kou_hu>kou_sei){
            kou_hu %=MOD;
            ans *=kou_hu;
            ans %=MOD;
            hu_num +=2;
        }
        else{
            kou_sei %=MOD;
            ans *=kou_sei;
            ans %=MOD;
            sei_num +=2;
        }
    }
    cout<<ans<<endl;
    //cout<<hu.size()<<" "<<sei.size()<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 6836
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <map>
#include <stack>
using namespace std;

int main(){
	int s = 0;
	for(int i = 0 ; i < 5 ; i++){
		int t; cin >> t;
		s += max(40,t);
	}
	cout << s / 5 << endl;
}

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define ALL(v) (v).begin(), (v).end()

typedef pair<int, int> P;
bool visit[55];
int edge[55][55];
int n, m;

void dfs(int v) {
    visit[v] = true;
    REP(i, n) {
        if(visit[i]) continue;
        if(!edge[v][i]) continue;
        dfs(i);
    }
}



int main(){
    cin >> n >> m;
    int ans = 0;

    vector<P> info(m);

    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        info[i] = make_pair(a, b);
        edge[a][b] = true;
        edge[b][a] = true;       
    }

    REP(i, m) {
        edge[info[i].first][info[i].second] = false;
        edge[info[i].second][info[i].first] = false;

        REP(j, n) visit[j] = false;

        dfs(0);

        REP(j, n) if(visit[j] == false) {
            ans++;
            break;
        }

        edge[info[i].first][info[i].second] = true;
        edge[info[i].second][info[i].first] = true;
    }

    cout << ans << endl;





    return 0;
}


Measured memory_bytes: 256