akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

#define N 100001
#define nil -1
#define WHITE 0
#define BLACK 1
#define INF 9999999

typedef struct{
  int prev,next,cost;
}Edge;
 
int n,d[N];
Edge e[500000];

void dijkstra(int);
void initializeSingleSource(int);

int main(){

  int i,j,u,k,c,ed=0,v,w=INF,r;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
      for(j=0;j<k;j++){
	e[ed].prev=u;
	scanf("%d%d",&e[ed].next,&e[ed].cost);
	ed++;
      }
  }
  
  dijkstra(ed);

  for(i=0;i<n;i++) printf("%d %d\n",i,d[i]);
  
  return 0;
}


void dijkstra(int edges){

  int i,flag;

  for(i=0;i<n;i++){
   d[i]=INF;
  }
  d[0]=0;
    
  flag=1;
  while(flag!=0){
    flag=0;
    for(i=0;i<edges;i++){
      if(e[i].cost+d[e[i].prev]<d[e[i].next]){
	d[e[i].next]=e[i].cost+d[e[i].prev];
	flag=1;
      }
    }
  }
}
  

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

int K,S;

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

    int cnt = 0;
    for (int X = 0; X <= K; X++)
    {
        for (int Y = 0; Y <= K; Y++)
        {
            int Z = S-X-Y;
            if(0<=Z && Z<=K) cnt++;
        }
    }
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <queue>
#include <numeric>
#include "bits/stdc++.h"
using namespace std;

#define INF 100000000

int main() {
    int N, M;
    cin >> N >> M;
    int m = floor(sqrt(M));
    int ans = 1;
    for (int i = floor(M/N); i >=1; i--) {
        if (M % i == 0) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


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

int main(){
	int A,B,C,X;
	scanf("%d%d%d%d", &A,&B,&C,&X);
	int ans=0;
	for(int i=0; i<=A; i++){
		for(int j=0; j<=B; j++){
			for(int k=0; k<=C; k++){
				if(i*500+j*100+k*50==X && i+j+k!=0){
					ans++;
				}
			}
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
// 等差数列の和の公式
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000
//#define int long long int

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  int x;
  cin >> x;
  int sum;
  FOR(i, 1, x+1) {
    sum = (1 + i) * i / 2;
    if(sum >= x) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
s = gets.chomp.split("")
sum = s.count("R") * s.count("G") * s.count("B")

ngs = []
n.times do |first|
  (first + 1...n).each do |second|
    third = second + (second - first)
    break if third >= n
    ngs << [first, second, third]
  end
end

ngs.each do |i, j, k|
  sum -= 1 if s[i] != s[j] && s[i] != s[k] && s[j] != s[k]
  # sum -= 1 if [s[i], s[j], s[k]].uniq.size == 3
end

puts sum


Measured memory_bytes: 228472
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define fast ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define umll unordered_map<ll,ll>
#define mll map<ll,ll>
#define forr(i,p,n) for(ll i=p;i<(ll)n;i++)
#define fore(i,n,k) for(ll i=n-1;i>=k;i--)
#define MAXN 1000003
typedef long long ll;
using namespace std;
ll mult(ll a, ll b, ll p = MOD) {return ((a % p) * (b % p)) % p;}
ll add(ll a, ll b, ll p = MOD) {return (a % p + b % p) % p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD) {ll m0 = m; ll y = 0, x = 1; if (m == 1)return 0; while (a > 1) {ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t;} if (x < 0)x += m0; return x;}
using namespace __gnu_pbds;
typedef tree<ll, null_type, less< ll>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
void functiontosolve()
{
    ll n;
    cin >> n;
    ll a[n];
    forr(i, 0, n) cin >> a[i];
    ll dp[n];
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    forr(i, 2, n) {
        dp[i] = min(dp[i - 1] + abs(a[i - 1] - a[i]), dp[i - 2] + abs(a[i - 2] - a[i]));
    }
    cout << dp[n - 1] << "\n";
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int test;
    test  = 1;
    forr(i, 1, test + 1) {
        functiontosolve();
    }
    return 0;
}

Measured memory_bytes: 5180
words = {}
n = int(input())
for i in range(n):
    s = input()
    if not s in words:
        words[s] = 1
    else:
        words[s] += 1
m = int(input())
for i in range(m):
    s = input()
    if not s in words:
        words[s] = -1
    else:
        words[s] -= 1

print(max(0, max(words.values())))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/


int main(){
    int N; cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; ++i) cin >> a[i];

    multiset<int> se{a[0]};
    for(int i=1; i<N; ++i){
        auto itr = se.lower_bound(a[i]);
        if(itr == se.begin()){
            se.insert(a[i]);
        }
        else{
            itr--;
            se.erase(itr);
            se.insert(a[i]);
        }
    }


    cout << se.size() << endl;
}

Measured memory_bytes: 5376
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = input[0];
            var B = input[1];

            for (int i = 0; i <= 1000; i++)
            {
                if (Math.Floor(i * 0.08) == A && Math.Floor(i * 0.1) == B)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
            Console.WriteLine("-1");
        }
    }
}

Measured memory_bytes: 13268
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace::std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
typedef long long lint;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define all(x) (x).begin(),(x).end()
#define INF (1LL<<60)
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto i:v)output(i);
int main(){
    lint n,W;
    cin>>n>>W;
    vector<lint> v(n),w(n),sv(n,0),sw(n,0);
    vector<pair<lint,lint>>p(n);
    rep(i,n)cin>>p[i].second>>p[i].first;
    lint ans=0;
    sort(all(p),[](const auto& s,const auto& t){return s.first*t.second>s.second*t.first;});
    rep(i,n)v[i]=p[i].first;
    rep(i,n)w[i]=p[i].second;
    sw[0]=w[0];
    sv[0]=v[0];
    rep(i,n-1)sv[i+1]=sv[i]+v[i+1];
    rep(i,n-1)sw[i+1]=sw[i]+w[i+1];
    function<void (lint,lint,lint)> f = [&](lint i,lint cur_v,lint cur_w) {
        if (W<cur_w) return;
        if (i == n) {
            ans=max(ans,cur_v);
            return;
        }
        lint lr_v = cur_v;
        lint lr_w = cur_w;
        auto itr=upper_bound(sw.begin(),sw.end(),W-cur_w+(i?sw[i-1]:0));
        lint j=itr-sw.begin();
        lr_w+=sw[j-1]-(i?sw[i-1]:0);
        lr_v+=sv[j-1]-(i?sv[i-1]:0);
        if (lr_w==W||j==n) {
            ans=max(ans,lr_v);
            return;
        }
        double lr_ans=lr_v+v[j]*(W-lr_w)/(double)w[j];
        if(lr_ans<=ans)return;
        if(W>=cur_w+w[i])f(i+1,cur_v+v[i],cur_w+w[i]);
        f(i+1,cur_v,cur_w);
    };
    f(0, 0, 0);
    cout<<ans<<endl;
}


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

int main(){
  int N,K;  cin >> N >> K;
  int l[50];
  for(int i = 0;i < N;i++)cin >> l[i];

  sort(&l[0],&l[N-1]+1,greater<int>());

  int sum = 0;

  for(int i = 0;i < K;i++)sum += l[i];

  cout << sum << endl;

}


Measured memory_bytes: 256
def bfs(fd, n):
    visited = set()
    ans = 1
    for i in range(1, n + 1):
        if i in visited: continue
        volume = 1
        queue = fd[i]
        visited.add(i)
        while queue:
            x = queue.pop()
            if x in visited: continue
            visited.add(x)
            volume += 1
            queue |= fd[x]
        ans = max(ans, volume)
    return ans

if __name__ == "__main__":
    n, m = map(int, input().split())
    fd = {i+1:set() for i in range(n)}
    for _ in range(m):
        a, b = map(int, input().split())
        fd[a].add(b)
        fd[b].add(a)
    print(bfs(fd, n))

Measured memory_bytes: 108984
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps=1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt"
int memo[52][52][52][52];
struct aa {
	int tx;
	int ty;
	int kx;
	int ky;
	int time;
};
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };
int main() {
	while (1) {
		for (int i = 0; i < 52; ++i) {
			for (int j = 0; j < 52; ++j) {
				for (int k = 0; k < 52; ++k) {
					for (int l = 0; l < 52; ++l) {
						memo[i][j][k][l] = 1e9;
					}
				}
			}
		}
		int W, H; cin >> W >> H;
		if (!W)break;
		int tx, ty, kx, ky; cin >> tx >> ty >> kx >> ky;
		vector<vector<int>>field(H+2, vector<int>(W+2,1));
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				cin >> field[i+1][j+1];
			}
		}
		queue<aa>que;
		que.push(aa{ tx,ty,kx,ky });
		memo[tx][ty][kx][ky] = 0;
		int ans = -1;
		while (!que.empty()) {
			aa atop=que.front();
			que.pop();
			const int ntx = atop.tx;
			const int nty = atop.ty;
			const int nkx = atop.kx;
			const int nky = atop.ky;
			if (ntx == nkx&&nty == nky) {
				ans = atop.time;
				break;
			}
			for (int way = 0; way < 4; ++way) {
				int nexttx = ntx + dx[way];
				int nextty = nty + dy[way];
				way = (way + 2) % 4;
				int nextkx = nkx + dx[way];
				int nextky = nky + dy[way];
				way = (way + 2) % 4;
				if (field[nextty][nexttx]) {
					nexttx = ntx; nextty = nty;
				}
				if (field[nextky][nextkx]) {
					nextkx = nkx; nextky = nky;
				}
				if (memo[nexttx][nextty][nextkx][nextky]>atop.time + 1) {
					memo[nexttx][nextty][nextkx][nextky] = atop.time + 1;
					que.push(aa{ nexttx,nextty,nextkx,nextky,atop.time + 1 });
				}
			}

		}
		if (ans != -1) {
			cout << ans << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 31712
#include<iostream>
using namespace std;
int t[4],u[4],v[4];
bool input(){
  //if(!cin>>t[0])return 0;
  for(int i=1;i<4;i++)cin>>t[i];
  for(int i=0;i<4;i++)cin>>u[i];
  return 1;
}
int main(){
  int h,b;
  while(cin>>t[0]){
    input();
    h=b=0;
    for(int i=0;i<4;i++){
      if(t[i]==u[i])h++;
      else{
	for(int j=0;j<4;j++){
	  if(t[i]==u[j])b++;
	}
      }
    }
    cout<<h<<' '<<b<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(){
  int k,s;
  int x,y,z;
  int count;

  scanf("%d%d", &k, &s);

  for(x = 0; x <= k; x++){
    for(y = 0; y <= k; y++){
      z = s - x - y;
      if(0 <= z && z <= k)count++;
    }
  }

  printf("%d", count);
  return 0;
}


Measured memory_bytes: 128
N = input()
K = int(input())
m = len(N)
dp = [[[0] * (K+1) for _ in range(2)] for _ in range(m + 1)]
dp[0][0][0] = 1

for i in range(1, m + 1):
    l = int(N[i - 1])
    for k in range(K + 1):
        dp[i][1][k] += dp[i - 1][1][k]
        if l != 0:
            dp[i][1][k] += dp[i - 1][0][k]
        else:
            dp[i][0][k] += dp[i - 1][0][k]
        if k - 1 >= 0:
            dp[i][1][k] += 9 * dp[i - 1][1][k - 1]
            if l != 0:
                dp[i][0][k] += dp[i - 1][0][k - 1]
                dp[i][1][k] += (l - 1) * dp[i - 1][0][k - 1]

print(dp[m][0][K] + dp[m][1][K])

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	s := nextString(sc)
	p := nextString(sc)

	if strings.Contains(s+s, p) {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}



Measured memory_bytes: 1096
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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; }
// const ll INF = 1LL <<60;
const int INF = 10000;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n;
  cin>>n;
  int a[n];
  int b[n];
  int cnt = 0;
  for(int i = 0; i < n; i++) {
    cin>>a[i];
    b[i]=abs(a[i]);
    if(a[i]<0) cnt++;
  }
  // for(int i = 1; i < n; i++) cout<<b[i]<<" ";
  sort(b,b+n);
  if(cnt%2==0){
    ll ans = 0;
    for(int i = 0; i < n; i++){
      ans+=b[i];
    }
    cout<<ans<<endl;
    return 0;
  }
  else{
    ll ans = -1*b[0];
    for(int i = 1; i < n; i++){
      ans+=b[i];
    }
    cout<<ans<<endl;
    return 0;
  }

  
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
int main()
{	
	char s[100];
	scanf("%s",s);
	int a=0,aa=0,b;
	b=strlen(s);
	for(int i=0;i<b;i++)
	{
		for(int j=0;j<b;j++)
		{
			if(s[i]==s[j])
			{
				aa++;
			}
		}
		if(aa%2!=0){
			a++;
			printf("No\n");
			break;
		}
		aa=0;
	}
	if(a==0)printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;	cin >> n >> m;
  vector<int> h(n);
  vector<bool>	ok(n,true);
  for(int i=0;i<n;i++){
    cin >> h.at(i);
  }
  
  for(int i=0;i<m;i++){
    int a,b;	cin >> a >> b;	a--;	b--;
    if(h.at(a)<=h.at(b))	ok.at(a)=false;
    if(h.at(b)<=h.at(a))	ok.at(b)=false;
  }
  int ans=0;
  for(bool f:ok){
    if(f)	ans++;
  }
  cout << ans;
}

Measured memory_bytes: 3724
#include <stdio.h>

/*  選択ソート(0オリジン) */
int selectionSort(int A[], int N) {
    int i, j, t, sw =0, minj;
    for(i=0;i<N-1;i++) {
        minj = i;
        for(j=i;j<N;j++) {
            if(A[j]<A[minj]) minj = j;
        }
        t=A[i]; A[i]=A[minj]; A[minj]=t;
        if(i!=minj) sw++;
    }
    return sw;
}

int main(void) {
    int A[100], N, i, sw;

    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = selectionSort(A,N);

    for(i=0;i<N;i++) {
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",sw);

    return 0;
}


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

bool chmax(ll& a, ll b){
    if (a < b){
        a = b; 
        return 1; 
    } 
    return 0; 
    }

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vector<P> a(n);
  ll tot=0;
  rep(i,n){
    cin>>a[i].first;
    a[i].second=i;
  }
  sort(a.begin(),a.end(),greater<P>());
  vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
  rep(i,n){
      for(int j=0;i+j<n;j++){
        chmax(dp[i+1][j],dp[i][j]+a[i+j].first*(a[i+j].second-i));
        chmax(dp[i][j+1],dp[i][j]+a[i+j].first*(n-1-j-a[i+j].second));
      }
  }

  ll res=0;
  rep(i,n+1)chmax(res,dp[i][n-i]);
  cout<<res<<endl;
  return 0;
  }


Measured memory_bytes: 34620
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	const int INF = 1e13;
	int n,m,l;
	std::cin >> n >> m >> l;
	std::vector<std::vector<int> > dist(n,std::vector<int>(n,INF));
	rep(i,m) {
		int a,b,c;
		std::cin >> a >> b >> c;
		a--;b--;
		dist[a][b] = c;
		dist[b][a] = c;
	}
	rep(k,n) rep(i,n) rep(j,n) if(dist[i][k] + dist[k][j] < dist[i][j]) dist[i][j] = dist[i][k]+dist[k][j];
	rep(i,n) rep(j,n) {
		if(dist[i][j]>l) dist[i][j] = INF;
		else dist[i][j] = 1;
	}
	rep(k,n) rep(i,n) rep(j,n) if(dist[i][k] + dist[k][j] < dist[i][j]) dist[i][j] = dist[i][k]+dist[k][j];
	int q;
	std::cin >> q;
	rep(i,q) {
		int s,t;
		std::cin >> s >> t;
		s--;t--;
		if(dist[s][t]==INF) print(-1);
		else print(dist[s][t]-1);
	}

	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, y, z = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    int A,x = 0;
    cin >> A;
    while(A % 2 == 0){
      A /= 2;
      x++;
    }
    if(z == 0){
      y = x;
      z++;
    }
    else{
      if(y > x){
        y = x;
      }
    }
  }
  cout << y << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>

void main()
{
	int x[200], y[200];
	int i, N, ni, di;
	int xMax, yMax, xMin, yMin;
	
	x[0] = y[0] = 0;
	
	while(1)
	{
		xMax = yMax = xMin = yMin = 0;
		
		scanf("%d", &N);
		if(N == 0) break;
		
		for(i = 1; i < N; i++)
		{
			scanf("%d%d", &ni, &di);
			
			x[i] = x[ni] - (int)(cos((90 * di) * M_PI / 180));
			y[i] = y[ni] - (int)(sin((90 * di) * M_PI / 180));
		}
		
		for(i = 0; i < N; i++)
		{
			if(xMax < x[i]) {
				xMax = x[i];
			} else if(xMin > x[i]) {
				xMin = x[i];
			}
			if(yMax < y[i]) {
				yMax = y[i];
			} else if(yMin > y[i]) {
				yMin = y[i];
			}
		}
		
		printf("%d %d\n", xMax - xMin + 1, yMax - yMin + 1);
	}
}

Measured memory_bytes: 604
<?php
$S=trim(fgets(STDIN));
$Q=trim(fgets(STDIN));
for($I=0;$I<$Q;$I++){
  $C=explode(' ',trim(fgets(STDIN)));

  if($C[0][2]=='i'){
    $p='';
    for($i=$C[1];$i<=$C[2];$i++) $p.=$S[$i];
    echo $p,PHP_EOL;
    continue;
  }
  if($C[0][2]=='v'){
    $l=$C[1]+($C[2]-$C[1]+1)/2;
    for($i=$C[1];$i<$l;$i++){
      $j=$C[2]-$i+$C[1];
      $s=$S[$j];
      $S[$j]=$S[$i];
      $S[$i]=$s;
    }
    continue;
  }
  for($i=$C[1];$i<=$C[2];$i++) $S[$i]=$C[3][$i-$C[1]];
}

Measured memory_bytes: 15520
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int main(){
	int H, W, sy, sx, gy, gx, blockcount;
	cin >> H >> W;
	sy = 0; sx = 0; gy = H-1; gx = W-1;
	blockcount = 0;
	int maze[H][W];
	for( int i=0; i<H; i++ ){
			string temp;
			cin >> temp;
		for( int j=0; j<W; j++ ){
			if( temp[j] == '#' ){
				blockcount++;
				maze[i][j] = -1;
			}
			else{
				maze[i][j] = 0;
			}
		}
	}
	pii cntpos;
	vector<pii> bw = {pii(0, -1), pii(1, 0), pii(0, 1), pii(-1, 0)};
	queue<pii> Q;
	Q.emplace(sx, sy);
	while( !Q.empty() ){
		cntpos = Q.front(); Q.pop();
		for( auto d : bw ){
			int posx = cntpos.first+d.first;
			int posy = cntpos.second+d.second;
			if(
				maze[posy][posx] == 0
				&&
				0 <= posx && posx < W
				&&
				0 <= posy && posy < H
				&&
				( ( posx != sx ) || ( posy != sy ) )
			){
				maze[posy][posx] = maze[cntpos.second][cntpos.first]+1;
				Q.emplace(posx, posy);
			}
		}
	}
	if( maze[gy][gx] == 0 ){
		cout << "-1" << endl;
		return 0;
	}
	cout << (H*W) - blockcount - maze[gy][gx] - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    static final int SIZE = 100;

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

        int A = sc.nextInt();
        int B = sc.nextInt();

        System.out.println(solve(A, B));

        sc.close();
    }

    static String solve(int A, int B) {
        char background;
        char foreground;
        int backCount;
        int foreCount;
        if (A <= B) {
            background = '.';
            foreground = '#';
            backCount = A;
            foreCount = B;
        } else {
            background = '#';
            foreground = '.';
            backCount = B;
            foreCount = A;
        }

        char[][] grids = new char[SIZE][SIZE];
        for (int r = 0; r < SIZE; ++r) {
            Arrays.fill(grids[r], background);
        }

        int r = 2;
        int c = 0;
        for (int i = 0; i < foreCount; ++i) {
            grids[r][c] = foreground;
            if (c % 4 == 0) {
                grids[r - 1][c] = foreground;
            } else {
                grids[r + 1][c - 1] = foreground;
                grids[r + 1][c] = foreground;
                grids[r + 1][c + 1] = foreground;
            }

            c += 2;
            if (c == SIZE - 2) {
                r += 4;
                c = 0;
            }
        }

        r = 1;
        c = 1;
        for (int i = 0; i < backCount - 1; ++i) {
            grids[r][c] = foreground;

            c += 2;
            if (c == SIZE - 3) {
                r += 3;
                c = 0;
            } else if (c == 2) {
                ++r;
                c = 1;
            }
        }

        return String.format("%d %d\n%s", SIZE, SIZE,
                Arrays.stream(grids).map(String::new).collect(Collectors.joining("\n")));
    }
}

Measured memory_bytes: 29140
#include <stdio.h>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>

using namespace std;

struct edge { int to, cost; edge(int t_, int c_) :to(t_), cost(c_) {} };

const int INF = 987654321;

int dijkstra(int a, int b, vector<vector<edge>>&graph)
{
	vector<int>dist;
	dist.resize(graph.size());
	fill(dist.begin(), dist.end(), INF);
	dist[a] = 0;
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>que;
	que.push(make_pair(0, a));
	while (!que.empty())
	{
		auto par = que.top(); que.pop();
		if (dist[par.second] < par.first)continue;
		for (auto outv : graph[par.second])
		{
			if (dist[outv.to] > dist[par.second] + outv.cost)
			{
				dist[outv.to] = dist[par.second] + outv.cost;
				que.push(make_pair(dist[outv.to], outv.to));
			}
		}
	}
	if (dist[b] == INF)return -1;
	return dist[b];
}

int main()
{
	int n, k;
	for (;;)
	{
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0)break;
		vector<vector<edge>>graph;
		graph.resize(n);
		for (int i = 0; i < k; ++i)
		{
			int p; scanf("%d", &p);
			if (p == 0)
			{
				int a, b; scanf("%d %d", &a, &b);
				--a; --b;
				printf("%d\n", dijkstra(a, b, graph));
			}
			else
			{
				int c, d, e; scanf("%d %d %d", &c, &d, &e);
				--c; --d;
				graph[c].push_back(edge(d, e));
				graph[d].push_back(edge(c, e));
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2776
x,k,d=map(int,input().split())
if x<0:
  x=-1*x
if x>=k*d:
  print(x-k*d)
else:
  ans=(x-k*d)%(2*d)
  if ans>d:
    print(2*d-ans)
  else:
    print(ans)
    

Measured memory_bytes: 9048
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

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

    cout << n-i+1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = (int)1e5 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vector <ll> arr(n);
    for (auto &it : arr) {
        cin >> it;
    }
    sort(arr.begin(), arr.end(), greater<ll>());
    ll sum = arr[0];
    int i = 2, iter = 1;
    while (i < n) {
        if (i == n - 1) {
            sum += arr[iter];
            ++i;
            continue;
        }
        sum += 2 * arr[iter];
        i += 2;
        ++iter;
    }
    cout << sum << endl;
    return 0;
}

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

int main(){
  int n,t[110],m,p[110][2],sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t[i];
    sum+=t[i];
  }
  cin>>m;
  for(int i=0;i<m;i++){
    for(int j=0;j<2;j++){
      cin>>p[i][j];
    }
  }
  for(int i=0;i<m;i++){
    int a=t[p[i][0]-1]-p[i][1];
    if(0<=a) cout<<sum-a<<endl;
    else cout<<sum-a<<endl;
  }
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, x, t;
    cin >> n >> x >> t;
    float attempts = (float)n/x;
    cout << (int)(ceil(attempts) * t) << endl;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner scanner = new Scanner(System.in);
    int minimumNumber = scanner.nextInt();
    boolean primeNumberFlag = true;
    while (true) {
      primeNumberFlag = true;
      for (int i = minimumNumber - 1; i > 1; i--) {
        if (minimumNumber % i == 0) {
          primeNumberFlag = false;
          break;
        }
      }
      if (primeNumberFlag) {
        break;
      }
      minimumNumber++;
    }
    System.out.println(minimumNumber);
  }

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

int main(){
    long long int n, k; cin >> n >> k;
	long long int a = n - (n/k)*k;
	long long int b = abs(a-k);
	cout << min(a, b) << endl;
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <unordered_map>
using namespace std;
#define n_l '\n'
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: "; cerr << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cerr << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cerr << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cerr << endl
#define run(a, b) cerr << fixed << setprecision(6) << (double) (b - a) / (double) (CLOCKS_PER_SEC) << " s" << endl;
#define ll long long
#define INF (2147483647)
#define MOD (int)(1e9 + 7) 

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    if(n > 10) {
        cout << k << endl;
    }
    else {
        cout << (10 - n) * 100 + k << endl;
    }
    return 0;
}

































Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <cstdlib>
#include <cctype>
using namespace std;

int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;
    
    S[K-1] = tolower(S[K-1]);

    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    string S, ans = "aaa";
    rep(i, 3){
        cin >> S;
        ans[i] = S[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll kai(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y&1){
    return (x*kai(x,y-1))%MOD;
  }else{
    ll t = kai(x,y/2);
    return (t*t)%MOD;
  }
}

ll comb(ll a,ll b,vector<ll> &p){
  if(a == 0)return 1;
  if(b == 0)return 1;
  ll ans = p[a+b];
  ans = (ans*kai(p[a],MOD-2))%MOD;
  ans = (ans*kai(p[b],MOD-2))%MOD;
  return ans;
}

int main(){
  string s,t;
  cin >> s >> t;
  int n;
  n = s.size() - t.size();
  int ans = INF;
  rep(i,n+1){
    ll res = 0;
    for(int j = i;j <= i+t.size()-1;j++){
      if(t.at(j-i) != s.at(j)){
        res++;
      }
    }
    if(res < ans)ans = res;
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3604
using System;
using System.Linq;

namespace DPL_1_B_cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var vs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int N = vs[0];
            int W = vs[1];
            int[,] dp = new int[N + 1, W + 1];
            int[] v = new int[N + 1];
            int[] w = new int[N + 1];
            v[0] = 0; w[0] = 0;
            for (int i = 0; i < N + 1; i++)
            {
                dp[i, 0] = 0;
            }
            for (int j = 0; j < W + 1; j++)
            {
                dp[0, j] = 0;
            }
            for (int i = 0; i < N; i++)
            {
                var vw = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                v[i + 1] = vw[0];
                w[i + 1] = vw[1];
            }
            for (int i = 0; i < N; i++)
            {
                for (int j = 1; j < W + 1; j++)
                {
                    if (j >= w[i + 1])
                    {
                        dp[i + 1, j] = Math.Max(dp[i, j], dp[i, j - w[i + 1]] + v[i + 1]);
                    }
                    else
                    {
                        dp[i + 1, j] = dp[i, j];
                    }

                }
            }
            Console.WriteLine(dp[N, W]);
        }
    }
}



Measured memory_bytes: 13584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t x,k,d,q,r;
  cin>>x>>k>>d;
  x=abs(x);
  q=x/d;
  r=x%d;
  if(r>d-r){
    q++;
    r=d-r;
  }
  if(k<q) cout<<x-d*k<<endl;
  else if((k-q)%2==0) cout<<r<<endl;
  else if((k-q)%2==1) cout<<d-r<<endl;
}

Measured memory_bytes: 3632
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int Q, N; string s;
int main() {
	cin >> Q;
	while (Q--) {
		cin >> N >> s;
		int c1 = 0, c2 = 0;
		for (char c : s) {
			if (c == 'B') c1++;
			else c2++;
		}
		int ret = 0;
		for (int i = 0; i < s.size(); i++) {
			int d1 = c1, d2 = c2;
			vector<int> v(s.size());
			for (int j = 0; j < s.size(); j++) v[j] = j;
			int ptr = 0;
			for (int j = 0; d1 > 0 && d2 > 0; j++) {
				ptr = (i == j ? ptr + N : ptr + N - 1) % v.size();
				if (s[v[ptr]] == 'B') d1--;
				else d2--;
				v.erase(v.begin() + ptr);
				if (ptr == v.size()) ptr = 0;
			}
			ret = max(ret, d1);
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3144
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    string s1, s2;
    cin >> s1 >> s2;
    if (s1 == "H") {
        cout << s2 << endl;
    }
    else {
        if (s2 == "H")
            cout << "D" << endl;
        else 
            cout << "H" << endl;
    }

}


//#define LOCAL

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



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


Measured memory_bytes: 256
##### ABC087B - Coins
a, b, c, x = list(map(int, [input().rstrip() for _ in range(4)]))
count = 0

for i in range(min(a, int(x / 500)) + 1):
    for j in range(min(b, int((x - i * 500) / 100)) + 1):
        if (x - i * 500 - j * 100) / 50 <= c:
            count += 1
print(count)

Measured memory_bytes: 3064
while True:
    t=int(input())
    if t == 0:
        break
    n=int(input())
    b=0
    for i in range(n):
        s,f=map(int,input().split())
        a=f-s
        b+=a
    if t<=b:
        print("OK")
    else:
        print(t-b)


Measured memory_bytes: 5596
N,M = map(int,input().split())
P = list(map(int,input().split()))
cs = [0] * N
prices = []
# paper,ic,事前購入
for _ in range(N-1):
  prices.append(list(map(int,input().split())))

for i in range(M-1):
  cur = P[i]
  nxt = P[i+1]
  cs[min(nxt-1, cur-1)] += 1
  cs[max(nxt-1, cur-1)] -= 1  

for i in range(N-1):
  cs[i+1] += cs[i]

res = 0
for i in range(N-1):
  times = cs[i]
  a,b,c = prices[i]
  res += min(a*times, b*times+c)
print(res)


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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536870912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// bit: &/and, |/or, ^/xor, ~/not

#define	MOD 1000000007

const double PI=3.14159265358979323846;

int	main() {
	double a, b, x;
	cin >>a >>b >>x;
	double t=atan((b*a*a-x)*2/(a*a*a));
	if (x*2<b*a*a)
		t=atan(b*b*a/(2*x));
	cout <<setprecision(9) <<t/PI*180 <<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <map>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	while(1){
		char field[8][9];
		int left = 8, right = 0, top = 8, bottom = 0;
		rep(y, 8){
			if(scanf("%s", field[y]) == EOF)
				return 0;
			rep(x, 8){
				if(field[y][x] == '1'){
					left = min(left, x);
					right = max(right, x);
					top = min(top, y);
					bottom = max(bottom, y);
				}
			}
		}

		int w = right - left + 1, h = bottom - top + 1;
		if(h==4)
			puts("B");
		else if(w==4)
			puts("C");
		else if(w==2 && h==2)
			puts("A");
		else if(w==2 && h==3)
			puts(field[top][left] == '1' ? "F" : "D");
		else
			puts(field[top][left] == '1' ? "E" : "G");
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int n;
    cin >> n;
    cout << (n-2)*180 << endl;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

int main(){
  int n;
  vector<int> s;
  double ans;
  double ave;
  int temp;

  while(true){
    cin >> n;
    if( n == 0){
      break;
    }
    s.resize(n);
    for( auto &i :s){
      i = 0;
    }
    for( int i = 0; i < n; ++i){
      cin >> temp;
      s[i] = temp;
    }
    
    ave = 0;
    for( auto i : s){
      ave += i; 
    }
    ave /= n;

    ans = 0;
    for( auto i : s){
      ans += (i-ave)*(i-ave);
    }
    ans /= n;

    cout << fixed << setprecision(5) << sqrt(ans) << endl;
  }
  return 0;
}

Measured memory_bytes: 3252
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    string a, b;
    cin >> a >> b;
    const string c = a + b;
    int x = atoi(c.c_str());
    for (int i = 1; i <= 1000; i++)
    {
        if (i * i == x)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int Dist[2000][2000];
int N, X, Y;

int main(){
  cin >> N >> X >> Y;
  X--; Y--;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      Dist[i][j] = abs(i - j);
    }
  }
  
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      int now = min(Dist[i][X] + Dist[Y][j] + 1, Dist[i][Y] + Dist[X][j] + 1);
      Dist[i][j] = min(now, Dist[i][j]);
    }
  }
  
  vector <int> ans(N);
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      ans[Dist[i][j]]++;
    }
  }
  
  for (int i = 1; i < N; i++){
    cout << ans[i] << endl;
  }
  

  return 0;
}


Measured memory_bytes: 16000
import sys;input=sys.stdin.readline

n,q=map(int, input().split())
event=[]
for _ in range(n):
    s,t,x=map(int,input().split())
    event.append((s-x-0.5,1,x))
    event.append((t-x-0.5,-1,x))
for i in range(q):
    event.append((int(input()),0,i))

event.sort()
is_stop=False
stop=set()
minstop=float('inf')
ans=[-1]*q
for t,e,x in event:
    if e > 0:
        stop.add(x)
        if x<minstop:
            minstop=x
            is_stop=True
    elif e<0:
        stop.remove(x)
        if minstop==x:
            is_stop=False
    elif len(stop)>0:
        if not is_stop:
             minstop=min(stop)
             is_stop=True
        ans[x]=minstop

print('\n'.join(map(str, ans)))

Measured memory_bytes: 102516
# AtCoder Beginner Contest 121
# https://atcoder.jp/contests/abc121
import sys
#import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main_lte():
    A, B = i2nn()
    n = A
    for i in range(A+1, B+1):
        n ^= i
    print(n)

# t桁目
def calc_t(n, t):
    d = n % (2**t)
    h = 2**(t-1)
    if d >= h and d % 2 == 0:
        return h
    else:
        return 0

# 0～n の xor
def calc_old(n):
    ans = 0
    # 10^3  < 2^10   # 1000 < 1024
    # 10^12 < 2^40
    # 1桁目
    d = n % 4
    if d == 1 or d == 2:
        ans += 1
    # 2桁目
    d = n % 4
    if d == 2:
        ans += 2
    # 3桁目
    d = n % 8
    if d == 4 or d == 6:
        ans += 4
    # 4桁目
    d = n % 16
    if d == 8 or d == 10 or d == 12 or d == 14:
        ans += 8
    return ans

def calc(n):
    ans = 0
    # 1桁目
    d = n % 4
    if d == 1 or d == 2:
        ans += 1
    # 2桁目以降
    for t in range(2, 40+1):
        ans += calc_t(n, t)
    return ans

# (A^...^B)
# = (1^...^A-1) ^ (1^...^A-1) ^ (A^...^B)
# = (1^...^A-1) ^ (1^...^B)
def main():
    A, B = i2nn()
    n = calc(A-1) ^ calc(B)
    print(n)

main()


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;
typedef pair<int,int> ii;

#define MAX 3010
int N,S,A[MAX];

const ll mod = 998244353LL;


int bf() {
  map<string,int> mp;
  int cnt = 0;
  rep(i,(1<<N)) {
    rep(j,(1<<N)) {
      int sum = 0;
      bool fail = false;
      rep(k,N) {
	if( !(i&(1<<k)) && (j&(1<<k)) ) {
	  fail = true;
	  break;
	}
	if( (j&(1<<k)) ) {
	  sum += A[k];
	}
      }
      if( fail ) continue;
      if( sum == S ) {
	++cnt;
	cout << "* " << cnt << " : ";
	string st = "";
	rep(k,N) {
	  if( (j&(1<<k)) ) {
	    st += (string(5-(int)to_string(A[k]).size(),' ') + to_string(A[k]));
	    cout << string(5-(int)to_string(A[k]).size(),' ') << A[k];
	  } else {
	    st += string(5,' ');
	    cout << string(5,' ');
	  }
	} puts("");
	mp[st]++;
      }
    }
  }
  puts("----");
  for(auto v : mp) {
    cout << v.fst << " : " << v.snd << endl;
  }
  puts("----");
  return cnt;
}

ll dp[3002];

void solve() {
  vector<ll> pow2;
  pow2.pb(1);
  rep(i,N+1) {
    pow2.pb((pow2.back()*2LL)%mod);
  }
  
  //cout << "Answer: " << bf() << endl;;
  dp[0] = 1;
  rep(i,N) {
    //int nex = ( cur + 1 ) & 1;
    //rep(j,S+1) rep(k,N+1) dp[nex][j][k] = dp[cur][j][k];
    for(int j=S;j>=0;--j) {
      if( j + A[i] <= S ) {
	//( dp[nex][j+A[i]][k+1] += dp[cur][j][k] ) %= mod;
	( dp[j+A[i]] += dp[j] ) %= mod;
      }
      ( dp[j] *= 2LL ) %= mod;
    }
  }
  cout << dp[S] << endl;
}

int main() {
  cin >> N >> S;
  rep(i,N) cin >> A[i];
  solve();
  return 0;
}


Measured memory_bytes: 3716
/*
 *  Author : Jun_SH
 *  Solution for ddcc2020-qual A
 */
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
    int f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    int ans=0;
    if(a==1){
        ans+=30000;
    }
    else if(a==2){
        ans+=20000;
    }
    else if(a==3)
        ans+=10000;
    if(b==1){
        ans+=30000;
    }
    else if(b==2){
        ans+=20000;
    }
    else if(b==3)
        ans+=10000;
    if(ans==60000)ans+=40000;
    cout<<ans*10<<endl;
}


Measured memory_bytes: 256