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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 55, M = 1010;

int n, m;
int x[N], y[N];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i ++ ) cin >> x[i] >> y[i];
	
	LL res = 4e18;
	for (int a = 0; a < n; a ++ )
		for (int b = 0; b < n; b ++ )
			for (int c = 0; c < n; c ++ )
				for (int d = 0; d < n; d ++ )
					if (x[a] > x[b] && y[c] > y[d])
					{
						int cnt = 0;
						for (int i = 0; i < n; i ++ )
							if (x[i] <= x[a] && x[i] >= x[b])
								if (y[i] <= y[c] && y[i] >= y[d])
									cnt ++ ;
						
						if (cnt >= m)
						{
							LL area = (LL)(x[a] - x[b]) * (LL)(y[c] - y[d]);
							res = min(res, area);
						}
					}
	
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 3548
#include <stdio.h>

int main(){
  int i1[2] = {0};

  for(int n = 0; n < 4; n++){
    scanf("%d",&i1[0]);
    i1[1] += i1[0];
  }

  printf("%d\n",i1[1] / 60);
  printf("%d\n",i1[1] % 60);
}

Measured memory_bytes: 2684
#include <iostream>

using namespace std;

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

	if (n == 25)
	{
		cout << "Christmas" << endl;
	}
	else if(n == 24)
	{
		cout << "Christmas Eve" << endl;
	}
	else if (n == 23)
	{
		cout << "Christmas Eve Eve" << endl;
	}
	else
	{
		cout << "Christmas Eve Eve Eve" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

long long n, a[100000], b[100000], d = 0;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = n - 1; i >= 0; i--) {
		if ((a[i] + d) % b[i]) {
			long long t = 0, j = (a[i] + d) / b[i];
			do{
				t = b[i] * j - a[i];
				j++;
			} while (t < d);
			d = t;
		}
	}
	cout << d << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N;
    cout<<(24-N)+24<<endl;
    return 0;
}


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

int main() {
    int a;
    string s;
    cin >> a >> s;
    if(a < 3200) {
        cout << "red" << endl;
    }
    else {
        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int count = 0;
        int num = a;

        while(num <= b){
            String numa = String.valueOf(num);
            StringBuffer numb = new StringBuffer(numa);

            if(numa.contentEquals(numb.reverse())){
                count++;
            }
            num++;
        }
        System.out.println(count);


    }
}


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

int main() {
    string s;
    cin >> s;
    if (s.find('A') != string::npos && s.find('B') != string::npos) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
	int k;
	cin >> k;
	queue<ll> q;
	for(ll i=1; i<10; i++) q.push(i);
	rep(_,k-1){
		ll t = q.front();
		ll s = t*10+t%10;
		q.pop();
		if(t%10) q.push(s-1);
		q.push(s);
		if(t%10 != 9) q.push(s+1);
	}
	cout << q.front() <<  endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
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;

int n,y;

int main(){
    cin>>n>>y;

    bool flag=false;
    int ans1,ans2,ans3;
    rep(i,0,n+1){
        rep(j,0,n+1){
            if(n-i-j<0) continue;
            if(10000*i+5000*j+1000*(n-i-j)==y){
                ans1=i;
                ans2=j;
                ans3=n-i-j;
                flag=true;
                break;
            }
        }
    }
    if(flag) cout<<ans1<<" "<<ans2<<" "<<ans3<<"\n";
    else cout<<-1<<" "<<-1<<" "<<-1<<"\n";
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end(),[](int a, int b) { return a > b; })
#define Reverse(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;

int main() {
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll> p(a),q(b),r(c);
    rep(i,a) cin>>p[i];
    rep(i,b) cin>>q[i];
    rep(i,c) cin>>r[i];
    Sort(p);Sort(q);Sort(r);
    ll ans = 0;
    rep(i,x) ans+=p[i];
    rep(i,y) ans+=q[i];
    ll  xx=x-1,yy=y-1,zz=0;
    while(xx>=0 || yy>=0){
        if(xx>=0 && yy>=0){
            if(p[xx]<q[yy] && p[xx]<r[zz]){
                ans-=p[xx];ans+=r[zz];
                xx--;
            }
            else if(p[xx]>=q[yy] && q[yy]<r[zz]){
                ans-=q[yy];ans+=r[zz];
                yy--;
            }
        }
        else if(xx<0 && q[yy]<r[zz]){
            ans-=q[yy];ans+=r[zz];
            yy--;
        }
        else if(yy<0 && p[xx]<r[zz]){
            ans-=p[xx];ans+=r[zz];
            xx--;
        }
        else break;
        zz++;
        if(zz==c) break;
    }
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int n, a[202];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	int cnt = 0;
	for(int i = 1; i < n-1; i++){
		if(a[i] < a[i-1] && a[i] > a[i+1]) cnt++;
		if(a[i] > a[i-1] && a[i] < a[i+1]) cnt++;
	}
	cout << cnt << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  map<string, ll> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    m[s[i]]++;
  }
  ll cnt = 0;
  for (auto v : m) {
    cnt += (v.second * (v.second - 1) / 2);
  }
  cout << cnt << endl;
}

Measured memory_bytes: 18176
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

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

  for (int i = 1; i <= c; ++i) {
    if (a * i > b) {
      break;
    }
    res += 1;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
my_list=[]
count=0
w=input()
w=w.lower()
while(True):
    var=input()
    if(var=="END_OF_TEXT"):
        break
    else:
        var=var.split()
        my_list+=var
for t in my_list:
    t=t.lower()
    if(w == t):
        count+=1
    else:
        None
print(count)


Measured memory_bytes: 5556
#include<bits/stdc++.h>
using namespace std;
int M = 1000000007;

int main() {
    long long a,b,x;
    cin >> a >> b >> x;
    if (x < a) {
        cout << x % M << "\n";
    }
    else {
        cout << (((x - a) / (a - b) + 1) % M * (b % M) % M + x) % M << '\n';
    }
    return 0;
}



Measured memory_bytes: 3104
# coding: utf-8
# Your code here!

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

def d(n):
    div = []
    for i in range(1,n+1):
        if(n % i == 0):
            div.append(i)
    return div
        
a_d = d(a)
b_d = d(b)
s = []
l = []
ab = []

if len(a_d) < len(b_d):
    s = a_d
    l = b_d
else:
    s = b_d
    l = a_d

for i in s:
    if i in l:
        ab.append(i)
print(ab[len(ab)-k])
    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    int x,y;
    x=a.size();
    y=b.size();
    int dp[x+1][y+1];
    for(int i=0;i<=x;i++)
    {
        for(int j=0;j<=y;j++)
        {
            if(i==0)
            dp[i][j]=0;
            if(j==0)
            dp[i][j]=0;
        }
    }
    for(int i=1;i<=x;i++)
    {
        for(int j=1;j<=y;j++)
        {
            if(a[i-1]==b[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else 
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    // for(int i=0;i<=x;i++)
    // {
    //     for(int j=0;j<=y;j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<dp[x][y];
    // int p,q;
    // p=x,q=y;
    // vector<char> v;
    // while(p>=0 && q>=0)
    // {
    //     if(a[p-1]==b[q-1])
    //     {
    //         v.push_back(a[p]);
    //         p--;
    //         q--;
    //     }
    //     else
    //     {
    //         if(dp[p-1][q]>dp[p][q-1])
    //         {
    //             p--;
    //         }
    //         else 
    //         {
    //             q--;
    //         }
    //     }
    // }
    // reverse(v.begin(),v.end());
    // for(int i=0;i<=v.size();i++)
    // {
    //     cout<<v[i];
    // }
    int index = dp[x][y];
    char lcs[index+1]; 
    lcs[index] = '\0';
   int i = x, j = y; 
   while (i > 0 && j > 0) 
   { 
      if (a[i-1] == b[j-1]) 
      { 
          lcs[index-1] = a[i-1]; 
          i--; j--; index--;      
      } 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  cout<<lcs;
}

Measured memory_bytes: 38772
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int[] pasta=new int[3];
		int[] drink=new int[2];
		pasta[0]=sc.nextInt();
		pasta[1]=sc.nextInt();
		pasta[2]=sc.nextInt();
		drink[0]=sc.nextInt();
		drink[1]=sc.nextInt();
		Arrays.sort(pasta);
		Arrays.sort(drink);
		System.out.println(pasta[0]+drink[0]-50);
		sc.close();
	}
}

Measured memory_bytes: 17160
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

int main(void){

char num_str[1002];

int num;

long sum = 0;

int i;

char tmp;

while (1){

fgets(num_str,sizeof(num_str),stdin);

if (num_str[0] =='0') break;

for (i = 0; i < strlen(num_str)-1; i++){

tmp = num_str[i];

num = atoi(&tmp);

sum = sum + num;

}

printf("%ld\n",sum);

sum = 0;

memset(num_str,1002, 0);

}

return 0;

}
 

Measured memory_bytes: 532
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

ll n, k, x[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> k;
    rep(i, 0, n) cin >> x[i];
    ll ans = inf;
    rep(i, 0, n-k+1) {
      ll ma = x[i+k-1], mi = x[i];
      ans = ma * mi < 0 ? min(ans, min(2 * ma + abs(mi), 2 * abs(mi) + ma)) \
                        : min(ans, (ma < 0 ? abs(mi) : abs(ma)));
    }
    cout << ans << endl;
    return 0;
}



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

ll N, K, A[100000], B[100000];

ll solve(ll k) {
  ll ret = 0;
  REP(i, 0, N) if((A[i] | k) == k) ret += B[i];
  return ret;
}

int main(void) {
  cin >> N >> K;
  REP(i, 0, N) cin >> A[i] >> B[i];

  ll ans = solve(K);
  REP(i, 0, 30) {
    if(K & (1 << i)) {
      ll k = 0;
      REP(j, 0, 30) if(i != j) k = k | (K & (1 << j));
      REP(j, 0, i) k = k | (1 << j);
      ans = max(ans, solve(k));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
N=int(input())
S=str(input())
t=0
r=0
b=0
g=0
for i in range(N):
    if S[i]=='R':
        r+=1
    elif S[i]=='B':
        b+=1
    else:
        g+=1
for i in range(N):
    for j in range(i+1,N):
        if S[i]==S[j]:
            continue
        else:
            try:
                if S[2*j-i]!=S[j] and S[2*j-i]!=S[i]:
                    t+=1
                else:
                    continue
            except IndexError:
                break
print (r*b*g-t)

Measured memory_bytes: 9248
#include<set>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (lc|1)
using namespace std;
inline int read(){
	int x=0; bool f=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=(x<<3)+(x<<1)+(ch^48);
	return f?-x:x;
}
const long long inf=0x3f3f3f3f3f3f3f3f;

int n,x,d;
int m[55],f[55];
long long sz[55],s[55];
int head[55],nx[55],to[55],ec=1;
inline void add(int a,int b){
	nx[++ec]=head[a]; head[a]=ec; to[ec]=b;
}
void dfs(int x){
	sz[x]=1; s[x]=m[x];
	for(int i=head[x];i;i=nx[i]){
		int t=to[i];
		dfs(t); sz[x]+=sz[t]; s[x]+=s[t];
	}
}
struct node{
	int id;
	long long val,co;
	inline bool friend operator < (node a,node b){
		return a.val*b.co>b.val*a.co;
	}
}nd[55];

inline int solve(int v){
	int ret=0;
	for(int i=1;i<=n;++i){
		if(nd[i].co>v) continue;
		int tmp=min((long long)nd[i].id==1?inf:d-min(d,n),v/nd[i].co);
		ret+=tmp*nd[i].val;
		v-=tmp*nd[i].co;
	}
	return ret;
}

long long dp[55*55*55],tmp[55*55*55];
int q[55*55*55],h,t;

int main(){
	n=read(); x=read(); d=read(); m[1]=read();
	for(int i=2;i<=n;++i) m[i]=read(),add(f[i]=read(),i); dfs(1);
	for(int i=1;i<=n;++i) nd[i].id=i,nd[i].val=sz[i],nd[i].co=s[i];
	sort(nd+1,nd+1+n); memset(dp,0x3f,sizeof(dp));
	int tot=n*n*n,lim=min(n,d); dp[0]=0;
	for(int i=1;i<=n;++i){
		long long v=nd[i].val,c=nd[i].co,ttmp=lim;
		if(nd[i].id==1) lim=n;
		for(int u=0;u<v;++u){
			h=1; t=0;
			memcpy(tmp,dp,sizeof(dp));
			for(int j=u;j<=tot;j+=v){
				//printf("%lld %lld %d %d\n",v,c,u,j);
				if(h<=t&&(j-q[h])>lim*v) ++h;
				if(h<=t) tmp[j]=min(tmp[j],dp[q[h]]+c*((j-q[h])/v));
				while(h<=t&&dp[q[t]]-c*(q[t]/v)>=dp[j]-c*(j/v)) --t; q[++t]=j;
			}
			memcpy(dp,tmp,sizeof(dp));
		}
		lim=ttmp;
	}
	int ans=0;
	for(int i=0;i<=tot;++i) if(dp[i]<=x) ans=max(ans,i+solve(x-dp[i]));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6312
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<i64,i64>;

int main(){
    int F;
    cin >> F;
    cout << (F - 30) / 2 << endl;
}



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

int main()
{
    int i,l,a[10],k;
    for(i=0;i<5;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+5);
    scanf("%d",&k);
    if(a[4]-a[0]<=k)
    {
        printf("Yay!");
    }
    else printf(":(");
    return 0;
}


Measured memory_bytes: 256
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#define For(i,j,k) for(int i=j;i<=k;i++)
#define Dow(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
using namespace std ;
inline int read() {
	int x = 0 , f = 1 ;
	char ch = getchar() ;
	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }
	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }
	return x * f ;
}

const int inf = 1e9; 
int n,Mn,sum;

int main() {
	n = read();
	Mn = inf;
	For(i, 1, n) {
		int x = read();
		if( x%10!=0 && x<Mn ) Mn = x;
		sum+=x;
	}
	if(sum%10!=0) {
		printf("%d\n",sum);
		return 0;
	}
	if(Mn==inf) puts("0");
	else printf("%d\n",sum-Mn);
	return 0;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vl vector <long>
#define vll vector < ll >
#define pll pair < ll , ll >
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MODCONST 1000000007
//#define v[i] abs(v[i])

using namespace std;

void solve()
{
    ll n,m;
    cin>>n>>m;
    cout<<(n*(n-1))/2+(m*(m-1))/2<<endl;
}

int main()
{
    fastio ;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll tc=1;
    //cin>>tc; //for number of testcases
    //ll ts = tc;
    while(tc--){
        //cout<<"Case #"<<ts-tc<<": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	double a, ans;
	int i;
	while (scanf("%lf", &a) != EOF) {
		ans = a;
		for (i = 2; i <= 10; i++) {
			if (i % 2) {
				a /= 3.0;
			}
			else {
				a *= 2.0;
			}
			ans += a;
		}
		printf("%lf\n", ans);
	}
	return 0;
}

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

int main()
{
    int N;
    string S;
    cin >> N >> S;
    string a;
    
    for (int i = 0; i < S.size(); ++i)
    {
        int c = S[i] - 65;
        c += N;
        c = c % 26;
        a += (char)(c + 65);
    }
    
    cout << a << endl;
    
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Queue<Double> point = new LinkedList<Double>();
		try (Scanner sc = new Scanner (System.in)){
			while (true) {
				int n = sc.nextInt();
				if (n == 0) break;

				double[] score = new double[n];
				double avg = 0;

				for (int i=0; i<n; i++) {
					score[i] = sc.nextInt();
					avg += score[i];  //total
				}

				avg /= n;  //平均値

				double sd = 0;

				for (int i=0; i<n; i++) {
					sd += Math.pow((score[i]-avg), 2);
				}
				sd /= n;
				sd = Math.sqrt(sd);

				point.add(sd);
			}
			int b = point.size();
			for (int i=0; i<b; i++) System.out.printf("%.8f\n", point.remove());
		}
	}
}



Measured memory_bytes: 32588
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int MAX = 1e9;
const ll LLMAX = 1e18;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

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

    int left = A + B;
    int right = C + D;

    if (left > right) {
        cout << "Left" << endl;
    } else if (left == right) {
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }

    return 0;
}


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

int main() {
  int64_t N, ans;
  cin >> N;
  for (int i=0; i<=sqrt(N); i++) {
    if (i*i<=N) {
      ans=i*i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3588
#include <iostream>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    a>=-100;
    b<=100;
    if(a+b>=a-b && a+b>=a*b)
        cout<<a+b;

    else if(a-b>=a+b && a-b>=a*b)
        cout<<a-b;

     else if(a*b>=a+b && a*b>=a-b)
        cout<<a*b;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,m;
  while(cin >>n>>m,n||m){
    int ans[100][100][2];
    for(int i=0; i<100; i++)
      for(int j=0; j<100; j++)
	for(int k=0; k<2; k++)
	  ans[i][j][k] = 1e+9;
    for(int i=0,a,b,cost,time; i<n; i++){
      cin >>a>>b>>cost>>time;
      a--;b--;
      ans[a][b][0] = ans[b][a][0] = cost;
      ans[a][b][1] = ans[b][a][1] = time;
    }
    for(int k=0; k<2; k++){
      for(int l=0; l<m; l++){
	for(int i=0; i<m; i++){
	  for(int j=0; j<m; j++){
	    ans[i][j][k] = min(ans[i][j][k],ans[i][l][k]+ans[l][j][k]);
	  }
	}
      }
    }
    int t=0;
    cin >>t;
    while(t--){
      int p,q,r;
      cin >>p>>q>>r;
      cout <<ans[p-1][q-1][r]<<endl;
    }
  }
  return 0;
}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cout<<#x<<" = "<<x<<endl;

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    char a;

    cin>>a;

    if((a-'A')<=25)
    {
        cout<<"A";
    }
    else
        cout<<"a";
}

int main()
{    
   

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li t=1;

    // cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int n, m, j, i, k;
char s, c, a;
int main(){
	scanf("%c%c%c", &s, &c, &a);
	if(c=='B'){
		printf("ARC");
	}
	if(c=='R'){
		printf("ABC");
	}
	return 0;
}

Measured memory_bytes: 3720
#include <iostream>                               

using namespace std;

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

    for(int i=1; i<B;i++){
        if(i*A % B == C){ 
            cout << "YES" << endl;
            return 0;
        }   
    }   
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;

int main(){
    string s;
    cin>>s;
    int count=0;
    int maxl=0;
    rep(i,s.size()){
        if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){count++;}
        else {maxl=max(maxl,count);count=0;}
    }
    maxl=max(maxl,count);
    cout<<maxl;
    return 0;
}

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

#define int long long
#define ar array 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,a,b) for(int i = a; i < b; i++)
 
using namespace std;

typedef long long ll; 
typedef vector<int> vi;
typedef pair<int,int> pii;
 
 
const  int mxN = 1e5+5;
const  long long INF= 1e18;
const long long mod= 1e9+7;
 	
signed main(){
	double r;
	cin >> r;
	r = r * 2;
	r = r * 3.14159;
	cout << r;
}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	



Measured memory_bytes: 3772
A,B = map(int,input().split())

if A > B and B != 1:
	print("Alice")
elif A > B and B == 1:
	print("Bob")

if B > A and A != 1:
	print("Bob")
elif B > A and A == 1:
	print("Alice")

if A == B:
	print("Draw")

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  vector<ll> waters, sugars;
  for (int i = 0; 100 * a * i <= f; i++) {
    for (int j = 0; 100 * b * j <= f; j++) {
      ll can_w = 100 * a * i + 100 * b * j;
      if (can_w <= f) waters.push_back(can_w);
    }
  }
  for (int i = 0; c * i <= f; i++) {
    for (int j = 0; d * j <= f; j++) {
      ll can_s = c * i + d * j;
      if (can_s <= f) sugars.push_back(can_s);
    }
  }

  double con = 0;
  ll ans_ws = 0, ans_s = 0;
  for (auto w : waters) {
    for (auto s : sugars) {
      // if (s * (100 + e) > (w + s) * e) continue;
      // if (s > e * (w / 100)) continue;
      // double tmp = (double)(100 * s) / (w + s);
      // if (con < tmp) {
      //   con = tmp;
      //   ans_ws = w + s, ans_s = s;
      // }

      if (s * (100 + e) > (w + s) * e) continue;
      if (w + s == 0 && s > 0) continue;
      if (w + s > f) continue;
      if (ans_s * (w + s) <= s * ans_ws) {
        ans_s = s, ans_ws = w + s;
      }
    }
  }
  cout << ans_ws << " " << ans_s << endl;
  return 0;
}


Measured memory_bytes: 5356
import java.util.*;
class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int sum=0;
        int n=sc.nextInt();
        int k=sc.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++)
        {
            arr[i]=sc.nextInt();
        }
        Arrays.sort(arr);
        for(int i=0;i<k;i++)
        {
            sum=sum+arr[i];
        }
        System.out.println(sum);
    }
}

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

const ll m = 1000000007;

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

  ll cnt = 0;
  for (ll i = k; i <= n + 1; i++) {
    cnt += i * (n - i + 1) + 1;
    cnt %= m;
  }
  cout << cnt << endl;
}


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

int main() {
  int n, k, i, count = 1;
  cin >> n >> k;
  
  vector<int> a(n), b;
  for(i = 0; i < n; i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(), a.end());
  
  for(i = 1; i < n; i++){
    if(a.at(i - 1) == a.at(i)){
      count++;
    }
    else{
      b.push_back(count);
      count = 1;
    }
  }
  b.push_back(count);
  
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  
  int ans = 0;
  if(b.size() <= k){
    cout << 0 << endl;
  }
  else{
    for(i = k; i < b.size(); i++){
      ans += b.at(i);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    for(int i = 1; i < n; i++){
        if (a[i] + a[i-1] >= l){
            cout << "Possible" << endl;
            for(int j = 1; j < i; j++) cout << j << endl;
            for(int j = n-1; j >= i; j--) cout << j << endl;
            return 0;
        }
    }
    cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


signed main(){
    string s,t;
    cin >> s >> t;
    bool ans = false;
    REP(i,s.size()){
        if(s == t){
            ans = true;
        }
        else{
            string u = s;
            REP(j,s.size()){
                if(j == s.size()-1){
                    u[j] = s[0];
                }
                else{
                    u[j] = s[j+1];
                }
            }
            s = u;
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> dp(1000000,INF);
  dp[0]=0;
  for(int i=1; i<1000000; i++){
    chmin(dp[i],dp[i-1]+1);
    for(int j=6; j<=i; j*=6){
      chmin(dp[i],dp[i-j]+1);
    }
    for(int j=9; j<=i; j*=9){
      chmin(dp[i],dp[i-j]+1);
    }
  }
  cout << dp[n] << endl;
}



Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define f(i,a,b) for(int i=a;i<b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,n) f(i,0,n)
#define rrep(i,n) rf(i,n-1,0)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mii map<int,int>
#define mci map<char,int>
#define inf (int)(1e18)
using namespace std;

void fast_IO_file()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	fast_IO_file();
	int l, r, d, c = 0;
	cin >> l >> r >> d;

	for (int i = l; i <= r; i++)
	{
		if (i % d == 0)
			c++;
	}

	cout << c << endl;
	return 0;
}

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

typedef struct stick{
  int length;
  struct stick* next;
}Stick;

void scan_length_all(int n_sticks, Stick **head);

int main(){
  int n_sticks;
  int cnt_triangles = 0;
  Stick *header = NULL;

  scanf("%d", &n_sticks);
  scan_length_all(n_sticks, &header);

  Stick *a, *b, *c;
  for(a=header; a!=NULL; a=a->next){
    for(b=a->next; b!=NULL; b=b->next){
      for(c=b->next; c!=NULL; c=c->next){
        if(c->length >= (a->length + b->length)){
          break;
        }
        
        if((a->length < (b->length + c->length))&&(b->length < (a->length + c->length))){
          cnt_triangles++;
        }
      }
    }
  }
  
  printf("%d", cnt_triangles);
}

void scan_length_all(int n_sticks, Stick **head){
  int i;
  Stick *tmp, **p;

  for(i=0; i<n_sticks; i++){
  	if((tmp = (Stick *)malloc(sizeof(Stick))) == NULL){
    	printf("error");
        exit(-1);
    }
  	scanf("%d", &(tmp->length));

    for(p=head; *p != NULL; p=&((*p)->next)){
    	if(tmp->length < (*p)->length){
        	break;
        }
    }
    tmp->next = *p;
    *p = tmp;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
  int N;
  cin>>N;
  vector<int>a(N);
  vector<int>sum1(N),sum2(N);
  rep(i,N){
    cin>>a[i];
  }
  sum1[0]=a[0];
  sum2[N-1]=a[N-1];
  for(int i=1;i<N;i++){
    if(sum1[i-1]<a[i]){
      sum1[i]=a[i];
    }
    else{
      sum1[i]=sum1[i-1];
    }
  }
  for(int i=N-1;i>=1;i--){
    if(sum2[i]<a[i-1]){
      sum2[i-1]=a[i-1];
    }
    else{
      sum2[i-1]=sum2[i];
    }
  }
  cout<<sum2[1]<<endl;
  for(int i=1;i<N-1;i++){
    cout<<max(sum1[i-1],sum2[i+1])<<endl;
  }
  cout<<sum1[N-2]<<endl;
  return 0;
}

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

using namespace std;

using ll = long long;

bool judge(string& s, int n) {
    for (int i = 0; i < n; i++) {
        if (s[i] != s[n - 1 - i]) return false;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.length();
    string s2 = "";
    for (int i = 0; i < n; i++) {
        if (s[i] != 'x') s2 += s[i];
    }
    if (!judge(s2, s2.length())) {
        cout << -1 << endl;
        return 0;
    }
    int cnt = 0, ans = 0;
    for (int i = 0, j = n - 1, cnt2 = 0; i < n; i++) {
        if (s[i] == 'x') {
            cnt++;
        } else {
            while (j >= 0) {
                if (s[j] == 'x') cnt2++, j--;
                else if (s[j] == s[i]) {
                    break;
                } else {
                    j--;
                }
            }
            if (i > j) break;
            ans += abs(cnt - cnt2);
            int tmp = max(cnt, cnt2);
            cnt = tmp;
            cnt2 = tmp;
            j--;
            if (i == j) break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

const int inf = 1000001;

class St{
	public:
	int c, p, cost;
	St() {}
	St(int _c, int _p, int _cost): c(_c), p(_p), cost(_cost) {}
	
	bool operator>(const St& st) const{
		return cost > st.cost;
	}
};

int exdij(int a[101][101], int c, int n, int s, int t)
{
	int r = inf, mcost[101][11];
	bool vis[101][11];
	priority_queue<St, vector<St>, greater<St> > que;
	
	que.push(St(c, s, 0));
	fill(&vis[0][0], &vis[100][10], true);
	fill(&mcost[0][0], &mcost[100][10], inf);
	while(!que.empty()){
		St st = que.top();
		que.pop();
		if(st.p == t){
			r = st.cost;
			break;
		}
		if(!vis[st.p][st.c]){
			continue;
		}
		vis[st.p][st.c] = false;
		
		for(int i = 1; i <= n; i++){
			if(mcost[i][st.c] > st.cost+a[st.p][i]){
				mcost[i][st.c] = st.cost+a[st.p][i];
				que.push(St(st.c, i, mcost[i][st.c]));
			}
			if(st.c && mcost[i][st.c-1] > st.cost+a[st.p][i]/2){
				mcost[i][st.c-1] = st.cost+a[st.p][i]/2;
				que.push(St(st.c-1, i, mcost[i][st.c-1]));
			}
		}
	}
	
	return r;
}

int main()
{
	int c, n, m, s, d, t, u, f, a[101][101];
	
	while(cin>>c>>n>>m>>s>>d && (c+n+m+s+d)){
		fill(&a[0][0], &a[n][n], inf);
		for(int i = 0; i <= n; i++){
			a[i][i] = 0;
		}
		while(m--){
			cin >> t >> u >> f;
			a[t][u] = a[u][t] = f;
		}
		
		cout << exdij(a, c, n, s, d) << endl;
	}
	
	return 0;
}

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

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        String[] input = br.readLine().split(" ");
        String[] hp_str = br.readLine().split(" ");

        int N = Integer.parseInt(input[0]);
        int K = Integer.parseInt(input[1]);

        int[] hp = new int[N];

        for(int i = 0; i < N; i++){
          hp[i] = Integer.parseInt(hp_str[i]);
        }

        Arrays.sort(hp);
        int tmp = N - 1;
        long result = 0;

        if(K >= N){
          result = 0;
        }else{
          while(K > 0){
            hp[tmp] = -1;
            K--;
            tmp--;
          }

          for(int i = 0; i < N; i++){
            if(hp[i] == -1){
              continue;
            }else{
              result += hp[i];
            }
          }
        }
        
        System.out.println(result);
      }
    }
}

Measured memory_bytes: 56284
// ref: https://img.atcoder.jp/arc096/editorial.pdf

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

vector<int64> v_max(const vector<int64>& v){
    vector<int64> ret; ret.push_back( 0ll );
    int64 maxKCal=INT_MIN;
    for(uint i=0; i<v.size(); ++i){
        maxKCal = max(maxKCal, v[i]);
        ret.push_back( maxKCal );
    }
    return ret;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int64 N, C; cin >> N >> C;
    vector<int64> vDistR(N); // distance
    vector<int64> vKCal (N); // kcal
    for(int i=0; i<N; ++i){ cin >> vDistR[i] >> vKCal[i]; }
    
    vector<int64> vDistL(N); // distance
    for(int i=0; i<N; ++i){ vDistL[N-1-i] = C - vDistR[i]; }
    
    
    // R: clockwise
    vector<int64> vR;
    int64 prevKCal=0, prevDist=0;
    for(int i=0; i<N; ++i){
        int64 kcal = prevKCal + vKCal[i] - (vDistR[i] - prevDist);
        vR.push_back( kcal );
        prevKCal = kcal;
        prevDist = vDistR[i];
    }
    vector<int64> vR_max = v_max(vR);
    // L: counterclockwise
    vector<int64> vL;
    prevKCal=0ll, prevDist=0ll;
    for(int i=0; i<N; ++i){
        int64 kcal = prevKCal + vKCal[N-1-i] - (vDistL[i] - prevDist);
        vL.push_back( kcal );
        prevKCal = kcal;
        prevDist = vDistL[i];
    }
    vector<int64> vL_max = v_max(vL);
    
    
    int64 sum=0;
    // R: clockwise
    sum = max(sum, vL_max[N-1]);
    for(int i=0; i<N; ++i){
        int64 tmp1 = vR[i];
        int64 tmp2 = vR[i] + vL_max[N-1-i] - vDistR[i];
        sum = max(sum, max(tmp1, tmp2));
    }
    // L: counterclockwise
    sum = max(sum, vR_max[N-1]);
    for(int i=0; i<N; ++i){
        int64 tmp1 = vL[i];
        int64 tmp2 = vL[i] + vR_max[N-1-i] - vDistL[i];
        sum = max(sum, max(tmp1, tmp2));
    }
    
    cout << sum << endl;
    
    return 0;
}

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

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

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

const int MAX = 1e5 + 5;
const ll INF = 1e14 + 5;
const int MOD = 1e9 + 7;

struct edge { int to, cost; };
vector<edge> G[MAX];
ll d[MAX];

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

    rep(i, M) {
        int l, r, c;
        cin >> l >> r >> c;
        l--, r--;
        edge e = edge();
        e.to = r, e.cost = c;
        G[l].push_back(e);
    }

    for (int i = 1; i < N; ++i) {
        edge e = edge();
        e.to = i - 1, e.cost = 0;
        G[i].push_back(e);
    }

    rep(i, N) {
        d[i] = INF;
    }

    d[0] = 0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0, 0));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;

        if (d[v] < p.first) continue;

        for (auto e : G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }

    if (d[N - 1] != INF) {
        cout << d[N - 1] << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 8056
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
const long long INF=9e15;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(long long i = 0; i < n; i++)
#define rep2(i,k,n) for(long long i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long id=0;id<N;id++) cin>>v.at(id)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);
  vlin(a,N);
  sort(all(a));
  ll M = 0;
  rep(i, N) chmax(M, a[i]);
  vl dp(M+1);
  rep(i, N){
    if(dp[a[i]] == 0){
      for(ll j = a[i]; j <= M; j += a[i])
      dp[j]++;
    }
    else dp[a[i]]++;
  }

  ll res = 0;

  rep(i, N){
    if(dp[a[i]] == 1) res++;
  }

  cout << res << endl;
}

Measured memory_bytes: 12760
N = int(input())
d = [int(i) for i in input().split()]
d = sorted(d)
low_num = d[int(N/2) - 1]
up_num = d[int(N/2)]
answer = 0
if(low_num == up_num):
    answer = 0
else:
    answer = up_num - low_num
print(answer)

Measured memory_bytes: 14120
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << min(c,b/a) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;

const int MAX_N = 300000;
typedef unsigned long long ull;
typedef long long ll;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    string A, B;
    cin >> A >> B;
    if(A.size() > B.size()){
        cout << "GREATER" <<endl;
    }else if(A.size() < B.size()){
        cout << "LESS" << endl;
    }else{
        bool flag = true;
        REP(i, A.size()){
            if(A[i] > B[i]){
                cout << "GREATER" << endl;
                flag = false;
                break;
            }else if(A[i] < B[i]){
                cout << "LESS" << endl;
                flag = false;
                break;
            }
        }
        if(flag) cout << "EQUAL" << endl;
    }
    return 0;
}

Measured memory_bytes: 256