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

const ll mod = 1000000007;

const int MAX = 6000010;

long long inv[MAX];

ll powmod(ll a, int p){
    ll ret = 1;
    while(p){
        if(p & 1) ret = ret * a % mod;
        a = a * a % mod;
        p >>= 1;
    }
    return ret;
}

// テーブルを作る前処理
void COMinit() {
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
    }
}
int main(){
    COMinit();
    int n; cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    map<ll, int> mp;
    for(int i = 0; i < n; i++){
        ll tmp = a[i];
        for(int j = 2; j*j <= tmp; j++){
            int p = 0;
            while(tmp % j == 0){
                tmp /= j;
                p++;
            }
            mp[j] = max(mp[j], p);
        }
        if(tmp != 1) mp[tmp] = max(mp[tmp], 1);
    }
    ll lcm = 1;
    for(auto p: mp){
        lcm *= powmod(p.first, p.second);
        lcm %= mod;
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += lcm * inv[a[i]];
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 51320
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (ll)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main()
{
#ifndef LOCAL
	ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
  	ll n, k; cin >> n >> k;
	vector<ll> a(n);
	for(auto& i : a){
		cin >> i;
	}
	vector<pair<ll, bool> >subs;
	rep(i, 0, n){
		ll sm = 0;
		rep(j, i, n){
			sm += a[j];
			subs.pb({sm, true});
		}
	}
	ll res = 0;
	for(ll b = 42; b >= 0; b--){
		if(count_if(all(subs), [&](auto& p){ return (p.ft & (1ll << b)) and p.sd;}) >= k){
			res |= (1ll << b);
			for(auto& i : subs){
				if(!(i.ft & (1ll << b))){
					i.sd = false;
				}
			}
		}
	}
	cout << res << "\n";
  
    return 0;
}


Measured memory_bytes: 10476
#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <algorithm>

using namespace std;

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

#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()

int main(){
	string str;
	int n;
	while(cin>>str>>n){
		if(str == "0" && n == 0) break;
		string s;
		rep(i, n - str.size()) s += "0";
		s+=str;
		//cout<<s<<endl;
		map<string, int> mp;
		int cnt = 1;
		while(1){
			if(mp[s] > 0){
				stringstream ss;
				ss<<s;
				int a;
				ss>>a;
				cout<<mp[s]-1<<" "<<a<<" "<<cnt - mp[s]<<endl;
				break;
			}
			mp[s] = cnt;
			string t = s, u = s;
			sort(all(t));
			sort(rall(u));
			int a, b;
			stringstream tt, uu;
			tt<<t; uu<<u;
			tt>>a; uu>>b;
			//cout<<a<<" "<<b<<endl;
			stringstream ss;
			ss<<(b-a);
			ss>>s;
			//cout<<s<<" ";
			string v(n-s.size(), '0');
			s = v + s;
			//cout<<v<<endl;
			cnt++;
		}
	}
}

Measured memory_bytes: 1272
N,x=map(int,input().split())
a=[0]
a+=list(map(int,input().split()))
#print(a)
ans=0
for i in range(N):
  if a[i]+a[i+1]>x:
    need=a[i]+a[i+1]-x 
    if need<=a[i+1]:
      a[i+1]-=need
      ans+=need
    else:
      need2=need-a[i+1]
      ans+=need
      a[i]-=need2
      a[i+1]=0
      
print(ans)
#print(a)

Measured memory_bytes: 14252
import java.util.*;
public class Main {
	public static ArrayList<Integer> list;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		list = new ArrayList<Integer>();
		makeList(1000000);
		while(true) {
			int n  = stdIn.nextInt();
			int p = stdIn.nextInt();
			
			if(n == -1 &&p == -1) break;
			int ans = solv(n,p);
			System.out.println(ans);
			
		}
	}
	
	public static void makeList(int a) {
		boolean[] isPrime = new boolean[a];
		int ispln = isPrime.length;
		for(int i = 2; i < ispln; i++) {
			isPrime[i] = true;
		}
		for(int i = 2; i < ispln; i++) {
			if(isPrime[i]) {
				list.add(i);
				for(int j = i + i; j < ispln; j += i) {
					isPrime[j] = false;
				}
			}
		}
	}
	
	public static int solv(int n, int p) {
		ArrayList<Integer> listTMP = new ArrayList<Integer>();
		int count = 0;
		int lsi = list.size();
		for(int i = 0; i < lsi && count <= p; i++) {
			int ts = list.get(i);
			if(ts > n) {
				listTMP.add(ts);
				count++;
			}
		}
		PriorityQueue<Integer> listAns = new PriorityQueue<Integer>();
		int ltsi = listTMP.size();
		for(int i = 0; i < ltsi; i++) {
			for(int j = i; j < ltsi; j++) {
				listAns.add(listTMP.get(i) + listTMP.get(j));
			}
		}
		for(int i = 0; i < p-1; i++) {
			
			int tmp = listAns.poll();
		}
		return listAns.poll();
		
	}
	
}

Measured memory_bytes: 61232
N,W = map(int, input().split())
INF = 10**12
dp = [[INF for i in range(110000)] for j in range(N+1)]

"""
dp[i][v] i個目の品物に対して、価値vをgetしうる重さの最小値
"""
dp[0][0] = 0

for i in range(N):
    w,v = map(int, input().split())
    for j in range(110000):
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])
        if v + j < 110000 and dp[i][j] != INF:
            # print("aaa",v+j,min(dp[i][v+j],dp[i][j]+w))
            dp[i+1][v+j] = min(dp[i][v+j],dp[i][j]+w)
            # print(dp[i+1][v+j],min(dp[i][v+j],dp[i][v]+w))


res = dp[N]
ans = 0
for v,r in enumerate(res):
    if r <= W:
        ans = v
print(ans)

Measured memory_bytes: 187580
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

const long long MOD = 1000000007;

int main() {
  long long N;
  long long a[60] = {0};
  cin >> N;
  rep(i, N) {
    long long temp;
    cin >> temp;
    long long x = 1;
    rep(j, 60) {
      if(temp & x) {
        a[j]++;
        // cout << j << endl;
      }
      x *= 2;
    }
  }
  long long ans = 0;
  long long x = 1;
  rep(i, 60) {
    ans += ((((a[i] * (N-a[i])) % MOD) * x));
    ans %= MOD;
    x *= 2;
    x %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
const int BASE = 1e9 + 7;

int main()
{
  ios::sync_with_stdio(0);
  int n, m, x;
  cin >> n >> m;
  vector <int> isBroken(n + 1, 0);
  while (m--)
  {
    cin >> x;
    isBroken[x] = 1;
  }

  vector <int> f(n + 1, 0);
  f[0] = 1;
  f[1] = 1 - isBroken[1];
  for (int i = 2; i <= n; i++)
    if (!isBroken[i])
      f[i] = (f[i - 1] + f[i - 2]) % BASE;

  cout << f[n] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main(){
	int N,K; cin >> N >> K;
	vector<int> A(N);
	int d = A[0];
	int M = 0;
	rep(i,N){
		cin >> A[i];
		d = GCD(d,A[i]);
		M = max(M,A[i]);
	}
	cout << (K % d == 0 && K <= M ? "POSSIBLE" : "IMPOSSIBLE") << endl;

}



Measured memory_bytes: 640
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    AL = [[i+1, a] for i, a in enumerate(A)]
    AL = sorted(AL, key=lambda x: x[1])
    ans = []
    for al in AL:
        ans.append(str(al[0]))
    print(' '.join(ans))

resolve()

Measured memory_bytes: 28752
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>

#define INF 0x3f3f3f3f
#define F first
#define S second
using namespace std;

typedef pair<int, int> ii;

int main(){
    ios::sync_with_stdio(0);

    int n, x, ans;
    vector<int> arr;

    cin >> n >> x;
    arr.push_back(x);

    for(int i = 0; i < n; i++){
        cin >> x;
        arr.push_back(x);
    }

    sort(arr.begin(), arr.end());
    ans = arr[1] - arr[0];

    for(int i = 0; i < n; i++){
        ans = __gcd(ans, arr[i + 1] - arr[i]);
    }
    cout << ans << '\n';

}


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

using namespace std;

int n;

void solve(){
    int i,j;
    string str;
    cin >> n >> j;
    long long ans = 0;
    for(ans = 0;n > 0;ans++)n/=j;
    cout << ans << endl;
}

int main(){
    solve();
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

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

    rep(k,n)
    {
        int r;
        cout << "Case " << k+1 << ":" << endl;
        cin >> r;

        REP(10)
        {
            r = ((r * r) %(1000*1000))/100;
            cout << r << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗

int main() {
    ll n;
    cin >> n;
    ll ans=0;
    rrep(i,1,1000001){
        int x=n-i-1;
        if(x<0) break;
        ans+=x/i+1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for x1 in range(H):
        for y1 in range(W):
            if S[x1][y1] == ".":  # left and upper sides of S[i][j]
                U[x1][y1] = U[x1 - 1][y1] + 1
                L[x1][y1] = L[x1][y1 - 1] + 1
            x2, y2 = -x1 - 1, -y1 - 1
            if S[x2][y2] == ".":  # right and under sides
                D[x2][y2] = D[x2 + 1][y2] + 1
                R[x2][y2] = R[x2][y2 + 1] + 1
    ans = -float("inf")
    for i in range(H):
        for j in range(W):
            ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
    print(ans)


if __name__ == "__main__":
    main()

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

int main(){
  int n, m;
  cin >> n;
  map<string, int> mp;
  string blue;
  for(int i = 0; i < n; i++){
    cin >> blue;
    mp[blue]++;
  }
  cin >> m;
  string red;
  for(int i = 0; i < m; i++){
    cin >> red;
    mp[red]--;
  }
  int ans = -1;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    ans = max(ans, itr->second);
  }
  if(ans == -1) ans = 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/* 
   10022 ??則???????属???????????????\???????????????n?????蔵???
   "??則????????即?属???????????????\?????????"?????????????????????????????????????????????
*/
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public  static void main(String[] args){
    solve();
    }
    static void solve(){
    String n = kbd.next();
    int ans = 0;
    while(kbd.hasNext()){
        String s = kbd.next();
        if(s.equals("END_OF_TEXT")){
        System.out.println(ans);
        }
        else{
        if(n.compareToIgnoreCase(s)==0){ // ????????????????????????????????????
            ans++;
        }
        }
    }
    }
}

Measured memory_bytes: 18116
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;
int main() {
	int a, b, c, x;
	int cnt = 0;
	cin >> a >> b >> c >> x;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int t = 0; t <= c; t++) {
				if (i * 500 + j * 100 + t * 50 == x)
					cnt++;
			}
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
using System;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            int X = int.Parse(input);
            input = Console.ReadLine();
            int A = int.Parse(input);
            input = Console.ReadLine();
            int B = int.Parse(input);

            int ans = (X - A) % B;

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

int main()
{
	string str;
	int w, h;
	cin >> w >> h ;

	vector<long long int> p(w);
	vector<long long int> q(h);

	for (int i = 0; i < w; i++)
		cin >> p[i];
	for (int j = 0; j < h; j++)
		cin >> q[j];

	sort(p.begin(), p.end());
	sort(q.begin(), q.end());

	long long int cnt = 0;
	int k = 0;
	int l = 0;
	
	while((w>0) && (h>0))
	{
		if (p[k] < q[l])
			{
				cnt += p[k] * (h + 1);
				k++;
				w--;
			}
		else
		{
			cnt += q[l] * (w + 1);
			l++;
			h--;
		}
	}
	while (w > 0)
	{
		cnt += p[k];
		k++;
		w--;
	}
	while (h > 0)
	{
		cnt += q[l];
		l++;
		h--;
	}


	cout << cnt << endl;

	//		sort(c, c + n, greater<int>()); //降順ソート

	return 0;
}

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

using namespace std;

const int N = 1e5 + 5;
int a[N];

int main() {
    //freopen("input.txt", "r", stdin);
    int n;
    ios_base::sync_with_stdio(false);
    cin >> n;
    a[0] = 0;
    a[n+1] = 0;
    long long sum = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i <= n; ++i) {
        sum += abs(a[i+1] - a[i]);
    }
    for (int i = 1; i <= n; ++i) {
        long long ans = sum - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i-1] - a[i+1]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define pb push_back
#define fread() freopen("in.txt", "r", stdin)
#define fwrite() freopen("out.txt", "w", stdout)
using namespace std;

const int maxn = 1e6+2;

typedef long long i64;
typedef vector<int> vi;


int main() {
	/*#ifndef ONLINE_JUDGE
		fread(); fwrite();
	#endif*/

	int T, n;
	int L,R;
	while(scanf("%d %d", &L, &R)==2){
		if(L > R) swap(L,R);
		//printf("%d %d\n", L,R);
		if(L <=0 and R>=0) printf("Zero\n");
		else if(L>0) printf("Positive\n");
		else {
			int cnt = abs(L) - abs(R) + 1;
			///printf("%d %d\n", L,R); printf("%d\n", cnt);
			printf("%s\n", cnt&1  ? "Negative" : "Positive");
		}
	}
	return 0;
}


Measured memory_bytes: 3676
def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort(reverse = True)
    ans = A[0]
    kazu = (N-2)//2
    amari = (N-2)%2
    for i in range(1,kazu+1,1):
        #print(i)
        ans += (A[i]*2)

    if amari==1:
        ans += A[i+1]*amari

    print(ans)

main()


Measured memory_bytes: 31644
import sys
s=[list(map(int,e.split(',')))for e in sys.stdin]
for i in range(1,len(s)):
 k=len(s[i]);b=k>len(s[i-1])
 for j in range(k):
  t=j-b;s[i][j]+=max(s[i-1][t*(j>0):t+2])
print(*s[-1])


Measured memory_bytes: 5612
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;


#define INF (1ll<<60)

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

vector<vector<int>> G;
int main(int argc, char const *argv[]) {
  long long a,b,c;cin>>a>>b>>c;
  int res=0;
  while(true){
    if(a%2||b%2||c%2){
      cout<<res<<endl;
      return 0;
    }
    if(a==b&&b==c){
      cout<<-1<<endl;
      return 0;
    }
    long long aa=(a+b)/2,bb=(b+c)/2,cc=(c+a)/2;
    a=aa;
    b=bb;
    c=cc;
    res++;
  }
  return 0;
}


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

int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  if(a+b>=k){
    cout << min(a,k);
  }
  else{
    cout << a-(k-a-b);
  }
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int a, b; cin >> a >> b;
    int res = 0, cur = 1;
    while (cur < b) {
        cur += a - 1;
        res++;
    }
    cout << res << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include<string>
using namespace std;
 
int main() {
    string s;
    cin>>s;
    int x=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='R')
        {
            int y=1;
            int j = i+1;
            for(j=i+1;j<s.length();j++)
            {
                if(s[j]=='R')
                y++;
                else
                break;
            }
            i = j-1;
            x = max(x,y);
        }
    }
    cout<<x;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,a,b;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
		char c;
		scanf(" %c",&c);
		if(c=='R')a++;
		else b++;
	}
	if(a>b)cout<<"Yes\n";
	else cout<<"No\n";
}


Measured memory_bytes: 256
# Wrote in Apr 10, 2020 18:36 by reetok
require 'time'
require 'prime'
require 'bigdecimal'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=".split(\" \").map(&:to_i)")
  t = []
  n.times do
    t.push(eval("gets.chomp#{datatype}"))
  end
  return t
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
class Integer
  def divisor_list
    devisors = [1]
    2.upto(self/2) do |i|
      devisors << i if self%i == 0
    end
    devisors << self
    return devisors.uniq.sort
  end
end
class Array
  def upper(a) #a yori ue
    self.sort.select{|n|n>=a}
  end
  def downer(a) #a yori shita
    self.sort.select{|n|n<=a}
  end
end
#---------------

def main()
  loop do
      a = gets.chomp
      if a == "0"
          break
      end
      puts a.split("").map(&:to_i).inject(:+)
  end
end
main()


Measured memory_bytes: 7260
#include <iostream>
#include <cmath>

using namespace std;

int main(void)
{
    while (true) {
        u_int n;
        cin >> n;
        if (!n)
            break;

        u_int data[n];
        double ave = 0;
        for (u_int i = 0; i < n; i++) {
            cin >> data[i];
            ave += data[i];
        }
        ave /= n;

        double dev = 0;
        for (u_int i = 0; i < n; i++)
            dev += (data[i] - ave) * (data[i] - ave);
        dev = sqrt(dev / n);
        
        printf("%f\n", dev);
    }
    
    return 0;
}

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

using namespace std;

const int N = 1e6 + 6;

int deg[N];
set<int> g[N];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    g[a].insert(b);
    g[b].insert(a);
    ++deg[a];
    ++deg[b];
  }
  bool ok = 1;
  int dual = 0, triple = 0;
  for (int i = 1; i <= n; ++i) {
    ok &= ((deg[i] & 1) == 0);
    if (deg[i] == 4)
      ++dual;
    else if (deg[i] >= 6)
      ++triple;
  }
  if (!ok || (triple == 0 && dual < 2)) {
    puts("No");
    return 0;
  }
  if (triple || dual > 2) {
    puts("Yes");
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    if (g[i].size() == 2) {
      auto it = g[i].begin();
      int u = *it; g[i].erase(it);
      it = g[i].begin();
      int v = *it; g[i].erase(it);
      g[u].erase(i);
      g[v].erase(i);
      g[u].insert(v);
      g[v].insert(u);
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (g[i].size() > 0)
      ++cnt;
    // cerr << i << " " << g[i].size() << endl;
  }
  puts(cnt <= 2 ? "No" : "Yes");
  return 0;
}

Measured memory_bytes: 58752
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstring>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
 
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;

#define INT_MX 2147483647
#define INF ((int)1e9)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define sz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define PB push_back
#define PF push_front
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


vector<vector<int>> v;

tuple<int,int,int> bfs(int a, int b, int n){
    int len = 0, mem = 1;
    queue<int> q;
    vector<int> pt;
    
    q.push(b);
    q.push(a);
    pt.rs(n);
    pt[a] = 1;
    pt[b] = -1;
    while(true){
        if(pt[q.front()] != mem){
            mem = pt[q.front()];
            len++;
        }
        for(auto i:v[q.front()]){
            if(pt[i] == pt[q.front()]*-1){
                if(pt[q.front()] == -1) return make_tuple(i, q.front(), len/2);
                else   return make_tuple(q.front(), i, len/2);
            }
            if(pt[i] == 0){
                pt[i] = pt[q.front()];
                q.push(i);
            }
        }
        q.pop();
    }
}

int dfs(int x, int block){
    int res = 0;
    
    for(auto i:v[x]){
        if(i != block)
            res = max(res, dfs(i, x)+1);
    }
    return res;
}

void solve(){
    int n, pa, pb, root, block, len, res;
    pii ipt;
    
    cin >> n >> pa >> pb;
    
    v.rs(n);
    rep(i,n-1){
        cin >> ipt.F >> ipt.S;
        ipt.F--;
        ipt.S--;
        v[ipt.F].EB(ipt.S);
        v[ipt.S].EB(ipt.F);
    }
    
    tie(root, block, len) = bfs(pa-1, pb-1, n);
    
    res = dfs(root, block);
    
    cout << len + res << '\n';
    
}

int main(){
    IOS;
    
    solve();
}



Measured memory_bytes: 9208
n = int(input())
a = list(map(int, input().split()))
dp = [[0] * (n+1) for _ in range(n+1)]
s = [0] * (n+1)
for i in range(n):
    s[i+1] = s[i] + a[i]
for l in range(2, n+1):
    for i in range(n-l+1):
        j = i + l
        dp[i][j] = s[j] - s[i] + min(dp[i][k] + dp[k][j] for k in range(i+1, j))
print(dp[0][n])

Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
void solve(long long N, long long K){
    double ans = 0;
    ll m = 1;
    ll cnt = 0;
    while(K >= m){
        m = 2*m;
        cnt++;
    }
    //cout << cnt << endl;
    if(N <= K){
        for(ll i = 1; i <= N; ++i){
            //cout << ans << endl;
            //cout << N << " " << cnt << " " << pow(0.5, (double)cnt) << endl;
            ans = ans + (1/(double)N) * pow(0.5, (double)cnt);
            cnt--;
        }
    }else{
        ll n = N;
        //cout << K << " " << cnt << " " << (1/(double)N) << endl;
        for(ll i = 1; i < K; ++i){
            ans = ans + (1/(double)N) * pow(0.5, (double)cnt);
            cnt--;
        }
        for(ll i = K; i <= N; ++i){
            ans = ans + (1/(double)N);
        }
    }
    std::cout << std::setprecision(12);
    std::cout << std::fixed;
    cout << ans << endl;
}
*/

void solve(ll N, ll K){
    double ret = 0;
    for(int i = 1; i <= N; i++){
        double tmp = 1.0/N;
        int now = i;
        while(now < K){
            now *= 2;
            tmp /= 2;
        }
        ret += tmp;
    }
    std::cout << std::setprecision(12);
    std::cout << std::fixed;
    cout << ret << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


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

using namespace std;

const int maxn = 1e6 + 7;
const int mod = 998244353;
const int inv2 = mod + 1 >> 1;
int n,m;

int fac[maxn];
int inv[maxn];
int ans;
int Add(int x,int y){return (x += y) >= mod ? x - mod : x;}
int Sub(int x,int y){return (x -= y) <    0 ? x + mod : x;}
int Mul(int x,int y){return 1LL * x * y % mod;}
int Pow(int x,int k,int re = 1){
	for(; k; k >>= 1,x = Mul(x,x))
		if(k & 1)re = Mul(re,x);
	return re;
}
int C(int n,int m){
	if(n < m || m < 0)return 0;
	return Mul(fac[n],Mul(inv[m],inv[n - m]));
}
int main(){
	cin >> n >> m;
	if(n < m)swap(n,m);
	fac[0] = inv[0] = 1;
	for(int i = 1; i <= n + m; ++i)fac[i] = Mul(fac[i - 1],i);
	inv[n + m] = Pow(fac[n + m],mod - 2);
	for(int i = n + m - 1; i; --i)inv[i] = Mul(inv[i + 1],i + 1);
	for(int i = 1; i <= m; ++i){
		int tmp = Mul(C(2 * i,i),C(n + m - 2 * i,m - i));
		ans = Add(ans,tmp);
	}
	ans = Mul(ans,Pow(C(n + m,m),mod - 2));
	ans = Mul(ans,inv2);
	ans = Add(ans,n);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 8064
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

int K, A, B;

signed main(void) {
	cin >> K >> A >> B;

	int ans = 1;
	int money = 0;

	if (B - A <= 2) {
		// better to just add one at every process
		ans += K;
	} else {
		while (K > 0) {
			if (money > 0) {
				ans += B;
				money --;
			} else {
				if (ans < A) {
					ans++;
				} else {
					if (K > 1) {
						ans -= A;
						money ++;
					} else {
						ans++;
					}
				}
			}
			K--;
		}
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#define BS 8 //BoardSize
#define NOT_FREE 1
#define FREE 0
#define noQueen -1
#define Queen 2

void putQueen(int);
void printBoard(void);

int board[BS][BS];
int row[BS],col[BS],dpos[2*BS-1],dneg[2*BS-1];

int main(){
  int i,j,k,r,c;
  for(i=0;i<BS;i++){
    row[i]=col[i]=FREE;
  }
  for(i=0;i<2*BS-1;i++){
    dpos[i]=dneg[i]=FREE;
  }
  
  for(i=0;i<BS;i++){
    for(j=0;j<BS;j++){
      board[i][j]=noQueen;
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d %d",&r,&c);
    board[r][c]=Queen;
  }

  putQueen(0);

  return 0;
}

void printBoard(){
  int i,j;
  for(i=0;i<BS;i++){
    for(j=0;j<BS;j++){
      if(board[i][j]!=noQueen){
	if(row[i]!=j)return;
      }
    }
  }
 
  for(i=0;i<BS;i++){
    for(j=0;j<BS;j++){
      if(row[i]==j){
	printf("Q");
      }else{
	printf(".");
      }
    }
    printf("\n");
  }
}


void putQueen(int i){
  int j;
  if(i==BS){
    printBoard(); 
    return;
  }

  for(j=0;j<BS;j++){
    if(col[j]==NOT_FREE||dpos[i+j]==NOT_FREE||dneg[i-j+BS-1]==NOT_FREE){
      continue;
    }
    // put a queen at (i, j)
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+BS-1]=NOT_FREE;
    // try the next row
    putQueen(i+1);
    // remove the queen at (i, j) for backtracking
    row[i]=col[j]=dpos[i+j]=dneg[i-j+BS-1]=FREE;
  }
}



Measured memory_bytes: 2108
#pragma comment (linker, "/STACK:526000000")
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(100);
}

void solve(){
	int k, n;
	cin >> n >> k;
	vector<long double> inputs;
	REP(i, n) {
		long double a;
		cin >> a;
		inputs.push_back((a+1.0000L)/2.00000L);
	}
	long double ans = 0;
	long double tmp = 0;
	REP(i, n) {
		tmp += inputs[i];
		if (i >= k) {
			tmp -= inputs[i - k];
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return;
}

int main() {
	init();
	solve();
}

Measured memory_bytes: 6000
# D - Road to Millionaire
def main():
    N, *A = map(int, open(0).read().split())
    money, left, right = 1000, 0, 0
    while right < N:
        if A[right] > A[left]:
            stock, money = divmod(money, A[left])
            money += A[right] * stock
        left = right
        right += 1
    print(money)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9188
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>

const int maxn = 1e5 + 20;

int n, m;
std::vector<int> G[maxn];
bool vis[maxn];

int dfs(int u,int fa)
{
	if(G[u].size() > 2) return u;
	
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		
		if(v != fa) return dfs(v, u);
	}
	
	return u;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1, u, v; i < n; i++)
	{
		scanf("%d%d", &u, &v);
		u++, v++;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	for(int i = 1; i <= n; i++)
		if(G[i].size() == 1) vis[dfs(i, 0)] = true, m++;
	
	for(int i = 1; i <= n; i++)
		if(vis[i]) m--;
	
	m = std::max(m, 1);
	printf("%d\n", m);	
	return 0;
}

Measured memory_bytes: 6272
def dfs(a, ans):
    if len(a) < n + 1:
        cur = a[-1]
        while (cur <= m):
            a.append(cur)
            ans = dfs(a, ans)
            a.pop()
            cur += 1
    else:
        score = 0
        for c in condition:
            if (a[c[1]] - a[c[0]] == c[2]):
                score += c[3]
        ans = max(ans, score)
        return ans
    return ans


n, m, q = [int(val) for val in input().split()]
condition = []
ans = 0
for i in range(q):
    condition.append([int(val) for val in input().split()])
ans = dfs([1], ans)

print(ans)


Measured memory_bytes: 9212
#include <iostream>
#include <limits>
#include <cfenv>
#include <cmath>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <list>
#include <random>
#include <functional>


#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, int>;

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;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

constexpr int N = 1e5;
std::array<int, N> A;
std::array<lli, N+1> Count, Wait;
std::array<lli, N+1> S;

int main(void){
    int n, m; scanf("%d%d", &n, &m);
    REP(i, n) scanf("%d", &A[i]), A[i]--;
    // a -> b に遷移する場合 | お気に入り設定でどれだけ変化するか考えよう
    // a < b の場合 : a < j ≤ b なる全ての j に関してコストが j - a - 1 だけ減少する
    // a > b の場合 : 1, a < j < m なるすべての j に関してコストが j - a - 1だけ減少する
    //               2, a < j + m ≤ b + m なる全ての j に関して ( : 0 ≤ j < m)
    //                     コストが j + m - a - 1 だけ減少する
    lli T = 0;
    for(int i = 1; i < n; ++i){
        if(A[i-1] < A[i]){
            int l = A[i-1] + 2;
            int r = A[i] + 1;
            Count[l]++; Count[r]--;
            Wait[r] += r - l;
            T += A[i] - A[i-1];
        }
        else{
            int l = A[i-1] + 2;
            int r = m;
            Count[l]++; Count[r]--;
            Wait[r] += r - l;
            l = 0; r = A[i] + 1;
            Count[l]++; Count[r]--;
            Wait[r] += r - l;
            S[l] += m - A[i-1] - 2;
            S[r] -= m - A[i-1] - 2;
            T += (A[i] + m - A[i-1]);
        }
    }

    REP(i, m) Count[i+1] += Count[i], S[i+1] += S[i];

    Count[0] -= Wait[0]; S[0] += Count[0];
    REP(i, m) Count[i+1] += Count[i] - Wait[i+1], S[i+1] += Count[i+1];
    lli mx = 0;
    REP(i, m) if(mx < S[i]) mx = S[i];
    printf("%lld\n", T - mx);
    
    return 0;
}


Measured memory_bytes: 2944
// C - GP 2
#include <bits/stdc++.h>

using namespace std;

#define	MOD 998244353

vector<long long> fact, finv;

void init_fact(int n = 1000000)
{
	fact.resize(n); finv.resize(n);
	fact[0] = finv[n - 1] = 1;
	for (int i = 1; i < n; i++) fact[i] = fact[i - 1] * i % MOD;
	for (long long x = MOD - 2, a = fact[n - 1]; x > 0; a = a * a % MOD, x >>= 1)
		if (x & 1) finv[n - 1] = finv[n - 1] * a % MOD;
	for (int i = n - 2; i >= 0; i--) finv[i] = finv[i + 1] * (i + 1) % MOD;
}

long long cnr(int n, int r)
{
	if (r < 0 || r > n) return 0;
	if (r == 0 || r == n) return 1;
	return fact[n] * finv[r] % MOD * finv[n - r] % MOD;
}

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

	long long n, m;
	cin >> n >> m;

	init_fact(2000000);

	long long ans = 0;
	for (int k = 0; k <= min(m, n); k++) {
		if ((3 * m - k) % 2) continue;
		long long c = (3 * m - k) / 2;
		ans = (ans + cnr(c + n - 1, c) * cnr(n, k) % MOD) % MOD;
	}

	long long r = 0;
	for (int k = 0; k <= min(m, n); k++) {
		if ((m - k) % 2) continue;
		long long c = (m - k) / 2;
		r = (r + cnr(c + n - 1, c) * cnr(n, k) % MOD - cnr(c + n - 2, c) * cnr(n - 1, k) % MOD + MOD) % MOD;
	}
	ans = (ans - r * n % MOD + MOD) % MOD;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 31488
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#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 <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
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; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
using vi=vector<ll>;

string f(ll n){
	string s=to_string(n);
	string ret;
	rep(i,6-(int)s.size())ret.push_back('0');
	ret+=s;
	return ret;
}

bool solve(){
	ll n,m;cin>>n>>m;
	vector<ll>v[n+1];
	vector<ll>p(m);
	vector<ll>y(m);
	rep(i,m){
		cin>>p[i]>>y[i];
		v[p[i]].push_back(y[i]);
	}
	rep(i,n+1)sort(all(v[i]));

	rep(i,m){
		cout<<f(p[i])+f((lower_bound(all(v[p[i]]),y[i])-v[p[i]].begin())+1)<<endl;
	}
	return false;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


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

#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;string s;
    cin >> n >> s;
    int r=0,w=0;
    REP(i,n){
        if(s[i]=='R')r++;
        else w++;
    }
    int r2=r;
    REP(i,r){
        if(s[i]=='R'){
            r2--;
        }
    }
    COUT(min({r,w,r2}));
}


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

L = [A, B, C]
L.sort(reverse = True)

if (L[1] - L[2]) % 2 == 0 :
    ans = (L[0] * 2 - L[1] - L[2]) // 2
else :
    ans = (L[0] * 2 - L[1] - L[2] + 3) // 2

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    s64 a, b;
    cin >> a >> b;
    
    s64 x;
    cin >> x;

    s64 s = CEIL(a, x);

    cout << MAX(0, (b / x) - s + 1) << "\n";

    return 0;
}



Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<vector>
#include<algorithm>

#define	mp	make_pair
#define	pb	push_back

using namespace std;

typedef	pair<int,int>	pii;

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

int main(){
	for(int r;scanf("%d",&r),r;){
		int w[2],h[2],x[2],y[2];
		static int room[2][500][500];
		vector<pii> roomcnt[2];	// <auth lev,number of rooms>
		for(int k=0;k<2;k++){
			scanf("%d%d%d%d",&w[k],&h[k],&x[k],&y[k]);
			x[k]--,y[k]--;
			for(int i=0;i<h[k];i++)for(int j=0;j<w[k];j++)	scanf("%d",&room[k][i][j]);

			static bool visited[500][500];
			for(int i=0;i<h[k];i++)for(int j=0;j<w[k];j++)	visited[i][j]=false;
			visited[y[k]][x[k]]=true;
			roomcnt[k].pb(mp(0,0));

			int cnt=0,lev=0;
			priority_queue< pair<int,pii> > pq;
			pq.push(mp(-room[k][y[k]][x[k]],mp(y[k],x[k])));
			while(!pq.empty()){
				pair<int,pii> a=pq.top();	pq.pop();
				int nowlev=-a.first,x=a.second.second,y=a.second.first;
				cnt++;
				if(lev<nowlev){
					roomcnt[k].pb(mp(cnt,nowlev));
					lev=nowlev;
				}
				else	*(roomcnt[k].rbegin())=mp(cnt,lev);
				for(int i=0;i<4;i++){
					int xx=x+dx[i],yy=y+dy[i];
					if(0<=xx && xx<w[k] && 0<=yy && yy<h[k] && !visited[yy][xx]){
						pq.push(mp(-room[k][yy][xx],mp(yy,xx)));
						visited[yy][xx]=true;
					}
				}
			}
		}

		int ans=1<<30;
		for(int i=0;i<roomcnt[0].size();i++){
			int rem=r-roomcnt[0][i].first;
			vector<pii>::iterator it=lower_bound(roomcnt[1].begin(),roomcnt[1].end(),mp(rem,0));
			if(it!=roomcnt[1].end()){
				int lev1=roomcnt[0][i].second;
				int lev2=it->second;
				ans=min(ans,lev1+lev2);
			}
		}
		printf("%d\n",ans);
	}

	return 0;
}

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

int main(){
	int n;
	
	int c[17];
	for(int i=0 ; i < 17 ; i++ ){
		c[i] = (i+1)*(i+1);
	}
	int dp[301] = {1};
	for(int i=0 ; i < 17 ; i++ ){
		for(int j = c[i] ; j <= 300 ; j++ ){
			dp[j] += dp[j-c[i]];
		}
	}
	
	while( cin >> n , n ){
		cout << dp[n] << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for(int i=0;i<(int)(n);++i)
#define FOR(i, b, n)  for(int i=b;i<(n);++i)
#define ALL(c) (c).begin(),(c).end()
#define SS size()
#define PB push_back
#define ST first
#define ND second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;

typedef vector<vi> vvi;

template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }


int main() {
  // freopen("./aaa.txt", "r", stdin);
  ios::sync_with_stdio(0);
  int n; cin >> n; 

  ll ans = 0, sum = 0; 
  map<ll,int> cnt; 
  cnt[0]=1;
  REP(i,n) {
    int a; cin >> a; 
    sum += a; 
    ans += cnt[sum]++;
  }
  cout << ans << endl;

}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
        cin.tie(0);
        cout.tie(0);
    ios::sync_with_stdio(false);

    cin>>n>>k>>s;
    char c;
    c=s[k-1];
    for(char cc='A';cc<='Z';cc++){
        if(c==cc){
            c=alph[cnt];
            break;
        }
        cnt++;
    }
    rep(i,Size(s)){
        if(i==k-1)cout<<c;
        else cout<<s[i];
    }
    cout<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,n) for(int _tmp=n,i=a;i<=_tmp;++i)
#define dep(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define fec(i,a) for(__typeof a.begin() i=a.begin();i!=a.end();++i)
#define For(i,u) for(int i=H[u];i;i=nxt[i])
#define re(i,a,b) for (int i=a;i<b;++i)
#define si(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
template<class T> inline void read(T&x){char c;bool fu=0;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x*=-1;}
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z) {read(x,y);read(z);}
typedef unsigned long long ll;
typedef pair<int,int> pii;
const int N=111111;
//head
ll ans,ans2;
int n;
int main() {
	read(n);
	ans=1;ans2=1;
	rep(i,1,n){
		ll x,y;
		read(x,y);
		if(ans<x)ans=x;
		if(ans%x!=0)ans=(ans/x+1)*x;
		ll tmp2=ans/x*y;
		if(tmp2<ans2){
			if(ans2%y!=0)ans2=(ans2/y+1)*y;
			ans=ans2/y*x;
		}else ans2=ans/x*y;
		if(i==n){
			cout<<ans+ans2<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 200005
using namespace std;
typedef long long ll;
inline int read(){
	int sum = 0, t = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){ if(ch == '-') t = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9'){ sum = sum * 10 + ch - '0'; ch = getchar(); }
	return sum * t;
}

int n, k, a[N];
ll v1[N], v2[N];
ll ans;

void solve(int l, int r){
	if(l == r){
		ans += (a[l] >= 0);
		return ;
	}
	int mid = l + r >> 1;
	v2[mid] = 0;
	for(int i = mid + 1; i <= r; i++)
		v2[i] = v2[i - 1] + a[i];
	v1[mid + 1] = 0;
	for(int i = mid; i >= l; i--)
		v1[i] = v1[i + 1] + a[i];
	sort(v1 + l, v1 + mid + 1);
	sort(v2 + mid + 1, v2 + r + 1);
	for(int i = mid + 1, j = mid + 1; i <= r; i++){
		while(v2[i] + v1[j - 1] >= 0 && j > l) j--;
		ans += mid + 1 - j;
	}
	solve(l, mid); solve(mid + 1, r);
}

int main(){
	n = read(), k = read();
	for(int i = 1; i <= n; i++)
		a[i] = read() - k;
	solve(1, n);
	printf("%lld\n", ans);
}


Measured memory_bytes: 4096
n = int(input())
H = list(map(int, input().split()))

UP = True
pre = 0
bottom = 0
count = 0

for i in range(n):
    if UP:
        if H[i] >= pre:
            pre = H[i]
            continue
        else:
            count += pre - bottom
            pre = H[i]
            UP = False
    else:
        if H[i] <= pre:
            pre = H[i]
            continue
        else:
            bottom = pre
            pre = H[i]
            UP = True

if UP:
    count += pre - bottom

print(count)
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  ll n;
  cin >> n;
  vs s(n);
  rep(i,n) cin >> s[i];
  
  rep(i,n){
    sort(s[i].begin(),s[i].end());
  }
  sort(s.begin(),s.end());
  
  ll cnt = 0;
  ll kamo = 1;
  rep(i,n-1){
    if(s[i]==s[i+1]){
      kamo++;
      
      //cout << i << " " << kamo << endl;
    }
    else{
      cnt+=kamo*(kamo-1)/2;
      kamo=1;
    }
  }
  //cout << kamo << endl;
  //cout << cnt << endl;
  cnt += kamo*(kamo-1)/2;
  cout << cnt << endl;
  
}


Measured memory_bytes: 7296
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        String s = scanner.next();
        for (int i = 0; i < 4; i++) {
            boolean[] a = new boolean[n + 2];
            a[0] = (i & 1) == 0;
            a[1] = (i & 2) == 0;
            for (int j = 0; j < n; j++) {
                a[j + 2] = a[j] ^ a[j + 1] ^ s.charAt(j) == 'o';
            }
            if (a[0] == a[n] && a[1] == a[n + 1]) {
                for (int j = 1; j <= n; j++) {
                    System.out.print(a[j] ? "S" : "W");
                }
                System.out.println();
                return;
            }
        }
        System.out.println(-1);
    }
}

Measured memory_bytes: 32100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  ll A, B, C, N;
  cin >> A >> B >> C >> N;
  if(N <= A) {
    cout << N;
  }
  else if(N <= A + B) {
    cout << A;
  }
  else {
    cout << A - (N - A - B) << endl;
  }
}

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

using namespace std;

int fun(int x){
  int ret = 0;
  while(x % 2 == 0){
    x /= 2;
    ret++;
  }
  return ret;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v;
  int ans = 0;
  for(int i=0, cur; i<n; i++){
    cin >> cur;
    v.push_back(cur);
  }
  for(auto x : v){
    ans += fun(x);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384