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

using namespace std;

struct UnionFind{
    vector<int> par;

    UnionFind(int N) : par(N) {
        for (int i = 0; i < N; ++i) {
            par[i] = i;
        }
    }

    int root(int x){
        if(par[x] == x) {
            return x;
        }
        return par[x] = root(par[x]);
    }

    void unite(int x, int y){

        int rx = root(x);
        int ry = root(y);
        if(rx == ry){
            return;
        }
        par[rx] = ry;
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(){
    int n, m;
    cin >> n >> m;
    UnionFind g(n);
    int x, y;
    for (int i = 0; i < m; ++i) {
        cin  >> x >> y;
        g.unite(x, y);
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> x >> y;
        if(g.same(x, y)){
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}


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

using namespace std;

#define N 3001

int n;
int vis[N][N] = {0};
double dp[N][N], a[N], ans = 0;

double solve(int n, int c)
{
	if (n == 0)
	{
		if (c <= 0)
			return 1;
		return 0;
	}
	if (vis[n][c])
		return dp[n][c];
	vis[n][c] = 1;
	return dp[n][c] = a[n - 1] * solve(n - 1, c - 1) + (1 - a[n - 1]) * solve(n - 1, c);
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	ans = solve(n, n / 2 + 1);
	cout << setprecision(10) << ans << endl;
	return 0;
}


Measured memory_bytes: 105344
#include <stdio.h>
#include <algorithm>
#include <set>
using namespace std;
using ll = long long;
int n, k, p[200010], ord[200010];
set<int> s;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%d", p + i);
	for (int i = 0; i < k; i++)
		s.emplace(p[i]);
	for (int i = n - 2; 0 <= i; i--) {
		if (p[i] < p[i + 1])
			ord[i] = ord[i + 1] + 1;
		else
			ord[i] = 0;
	}

	int cnt = n - k + 1, unc = k - 1 <= ord[0];

	for (int i = 0; i + k < n; i++) {
		bool valid = true;
		valid &= (*s.begin()) == p[i];
		s.erase(p[i]);
		s.emplace(p[i + k]);
		valid &= (*s.rbegin()) == p[i + k];

		bool isunc = k - 1 <= ord[i + 1];
		if (1 <= unc && isunc)
			valid = true;
		if (isunc)
			unc = 1;

		if (valid)
			cnt--;
	}
	printf("%d\n", cnt);
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int main() {
 int N,K,x;
 int a=0;
 cin >> N >> K;
  for(int i; i<N ; i++){
   cin >> x;
    if(K-x>x){
      a = a+2*x;
    }else{
      a = a+(K-x)*2;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 3524
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
int inf = 1000000000;


int main(){

  long long int n;
  cin >> n;
  if( n==1 ){
    cout << 1 << endl;
    return 0;
  }
  for(int i=0; i<=n; i++){
    long long int tmp = i*i;
    if( tmp > n ){
      cout << (i-1)*(i-1) << endl;
      return 0;
    }
  }

  return 0;
}





//


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second

#define END puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();

int main() {
    clue();
    return 0;
}
int clue() {

    string s;
    cin>>s;

    int cnt=0;
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R') {
        cnt=3;
    }
    else if((s[0]=='R'&&s[1]=='R') || (s[1]=='R'&&s[2]=='R')) {
        cnt=2;
    }
    else if(s[0]=='R'||s[1]=='R'||s[2]=='R') {
        cnt=1;
    }
    else {
        cnt=0;
    }

    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int main() {
  int N, K;
  int x;
  int res = 0;

  cin >> N;
  cin >> K;
  REP(i, N) {
    cin >> x;
    res += min(x, K - x);
  }
  cout << res * 2 << endl;
}


Measured memory_bytes: 3620
#include <iostream>

int main(void){
    std::string S;
    int N;
    char ans = '1';
    long long tmp = -1, K;
    std::cin >> S >> K;
    N = S.size();
    for (int i = 0; i < N; ++i){
        if (S.at(i) != '1'){
            ans = S.at(i);
            break;
        } else {
            tmp = i;
        }
    }

    if (K - 1 <= tmp) {
        ans = '1';
    }

    std::cout << ans << std::endl;

    return 0;
}


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

string toUpper(string s){
    string t = s;
    for(int i=0; i<s.size(); i++){
        t[i] = toupper(s[i]);
    }

    return t;
}

int main(){
    string target, source;
    cin >> target;
    target = toUpper(target);

    int cnt=0;
    while(1){
        cin >> source;
        if(source == "END_OF_TEXT") break;
        source = toUpper(source);
        if(target == source) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3208
program prob1
    implicit none
    integer :: x, y
    read(*,*) x,y

    if(x == 1 .and. y == 1) then
        write(*,*) "1000000"
    else
        write(*,*) (max(4-x, 0)+max(4-y, 0))*100000
    end if


    stop
contains
end program prob1


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

class Main{
	public void run(){
		String s = next();
		int k = ni();
	
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<s.length();i++){
			char c = s.charAt(i);
			int numA = ('z' - c + 1) % 26;
			if(numA <= k){
				k -= numA;
				sb.append('a');
			}else{
				sb.append(c);
			}
		}
		k %= 26;
		char c = sb.charAt(s.length() - 1);
		c -= 'a';
		c = (char)(c + k);
		c %= 26;
		c += 'a';
		sb.setCharAt(s.length()-1, c);

		out.println(sb.toString());
	}

	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().run();
		out.flush();
	}

	public Main(){
	}

	int ni(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;	}

	long nl(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}

	double nd(){
		return Double.parseDouble(next());
	}

	String next(){
		int c;
		while(!isAlNum(c = read()));
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	String nextLine(){
		int c;
		while(!isAlNumOrSpace(c = read()));
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNumOrSpace(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
	private static boolean isAlNumOrSpace(int c){
		return isAlNum(c) || c == ' ' || c == '\t';
	}
	void debug(Object... os){
		out.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 10704
#include <iostream>
#include <string>
using namespace std;
int main(){
	string alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	while( 1 ){
		int n;
		cin >> n;
		if( n == 0 ) break;
		int k[100];
		for( int i = 0; i < n; i++ ){
			cin >> k[i];
		}
		string s;
		cin >> s;
		int a = 0;
		string out;
		for( int i = 0; i < s.length(); i++ ){
			for( int j = 52; j < alpha.length(); j++ ){
				if( s[i] == alpha[j] ){
					out[a] = alpha[j-k[i%n]];
					cout << out[a++];
				}
			}
		}
		//out[a] = '\0';
		cout << out << endl;
	}
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
int main()
{
    string s;
    cin >> s;
     
    ll N = s.size();
    ll S = stol(s);
    ll P = pow(10LL, N);
    vector<ll> p;
    for (int i = 0; i <= 9; i++) {
        p.emplace_back(i);
    }
     
    ll diff = -1;
    string t;
    do {
        ll T = 0;
        string str;
        for (int i = 0; i < N; i++) {
            T *= 10LL;
            T += p[i];
            str += (p[i] + '0');
        }
        ll U = abs(S - T), V = min(U, P - U);
        if (diff < V) {
            diff = V;
            t = str;
        } else if (diff == V) {
            t = min(t, str);
        }
    } while (next_permutation(p.begin(), p.end()));
     
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3380
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int b;
int main(){
  int n,m,p;
  cin >> n >> m >> p;
  a[0] = p;
  for(int i=1;i<=m;i++){
    cin >> a[i];
  }
  
  sort(a,a+m+1);
  int now = lower_bound(a,a+m+1,p)-a;
  
  int rui[100001]={}; // 時計
  for(int i=now+1;i!=now;i++){
    if(i == m+1){
      if(now == 0) break;
      rui[0] = rui[i-1]+(a[0]+n-a[i-1]);
      i = 0;
    }
    else rui[i] = rui[i-1]+(a[i]-a[i-1]);
  }
  int rui2[100001]={}; //反時計
  for(int i=now-1;i!=now;i--){
    if(i == -1){
      if(now == m) break;
      rui2[m] = rui2[i+1]+(a[i+1]+n-a[m]);
      i = m;
    }
    else rui2[i] = rui2[i+1]+(a[i+1]-a[i]);
  }
 
  int ans = INT_MAX;
  for(int i=0;i<=m;i++){
    if(i == m) ans = min(ans,rui[i]+rui[i]+rui2[0]);
    else ans = min(ans,rui[i]+rui[i]+rui2[i+1]);
    if(i == 0) ans = min(ans,rui2[i]+rui2[i]+rui[m]);
    else ans = min(ans,rui2[i]+rui2[i]+rui[i-1]);
  }

  cout << ans << "00" << endl;
  return (0);
}

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if(a > b) swap(a, b);
	if(a > c) swap(a, c);
	if(b > c) swap(b, c);
	cout << (a == 5 && b == 5 && c == 7 ? "YES" : "NO") << endl;
	return 0;
}

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

const int N = 1e5+7;
long long pref[N], suf[N];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int x, y, z;
    cin>>x>>y>>z;

    int n = x+y+z;
    vector<pair<int, int>> v;
    long long ans = 0;
    for (int i=0; i<n; i++) {
        int a, b, c;
        cin>>a>>b>>c;
        ans += a;
        v.push_back({b-a, c-a});
    }

    sort(v.begin(), v.end(), [](auto a, auto b) {return a.first-a.second > b.first - b.second;});

    priority_queue<int> pq;
    long long sum = 0;
    for (int i=0; i<y; i++) pq.push(-v[i].first), sum += v[i].first;
    pref[y-1] = sum;

    for (int i=y; i<n; i++) {
        pq.push(-v[i].first);
        sum += v[i].first + pq.top();
        pq.pop();
        pref[i] = sum;
    }

    while(pq.size())    pq.pop();
    sum = 0;
    for (int i=0; i<z; i++)    pq.push(-v[n-i-1].second), sum += v[n-i-1].second;
    suf[n-z] = sum;

    for (int i=z; i<n; i++) {
        pq.push(-v[n-i-1].second);
        sum += v[n-i-1].second + pq.top();
        pq.pop();
        suf[n-i-1] = sum;
    }

    long long mx = -1e18;
    for (int i=y-1; i+z<n; i++) {
        mx = max(mx, pref[i]+suf[i+1]);
    }

    ans += mx;
    cout<<ans<<endl;
}


Measured memory_bytes: 2676
#include <stdio.h>

int tadoru(char amida[30][11],int tatenum,int dannsuu,int select,int atari);

int main(void) {
	int tatenum;
	int select;
	int atari;
	int dannsuu;
	char amida[30][11];
	int i;
	int drawtate;
	int drawyoko;
	while(1) {
		scanf("%d",&tatenum);
		if(tatenum==0)break;
		scanf("%d",&select);
		scanf("%d",&atari);
		scanf("%d",&dannsuu);
		for(i=0;i<dannsuu;i++)scanf("%s",amida[i]);
		if(tadoru(amida,tatenum,dannsuu,select,atari)) {
			printf("0\n");
		} else {
			for(drawtate=0;drawtate<dannsuu;drawtate++) {
				for(drawyoko=0;drawyoko<tatenum;drawyoko++) {
					if(amida[drawtate][drawyoko]=='1')continue;
					if(drawyoko>0 && amida[drawtate][drawyoko-1]=='1')continue;
					if(drawyoko<tatenum-1 && amida[drawtate][drawyoko+1]=='1')continue;
					amida[drawtate][drawyoko]='1';
					if(tadoru(amida,tatenum,dannsuu,select,atari)) {
						printf("%d %d\n",drawtate+1,drawyoko+1);
						goto last;
					}
					amida[drawtate][drawyoko]='0';
				}
			}
			printf("1\n");
			last:
				;
		}
	}
	return 0;
}

int tadoru(char amida[30][11],int tatenum,int dannsuu,int select,int atari) {
	int pos;
	int yokopos;
	yokopos=select;
	for(pos=0;pos<dannsuu;pos++) {
		if(yokopos>1 && amida[pos][yokopos-2]=='1')yokopos--;
		else if(yokopos<tatenum && amida[pos][yokopos-1]=='1')yokopos++;
	}
	return (yokopos==atari);
}

Measured memory_bytes: 0
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	map<int, int>mp;
	int ans = 0, cnt = 0;
	REP(i, N) {
		int a;
		cin >> a;
		if (mp[a] == 0)ans++;
		mp[a]++;
	}
	eFOR(i, 1, 100000) {
		if (mp[i] > 0) {
			//cout << i << " " << mp[i] << endl;
			if (mp[i] % 2 == 1)continue;
			else cnt++;
		}
	}
	if (cnt % 2 == 1)ans--;
	cout << ans << endl;

	return 0;
}



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

int main(){
    int n;
    cin >> n;
    int v[n], c[n];
    for(int i = 0; i < n; i++) cin >> v[i];
    for(int i = 0; i < n; i++) cin >> c[i];
    
    int cnt = 0;
    vector <int> ans(n);
    for(int i = 0; i < n; i++){
        ans[i] = v[i] - c[i];
    }
    sort(ans.begin(), ans.end(), greater<int>());
    
    for(int i = 0; i < n; i++){
        if(ans[i] > 0){
            cnt += ans[i];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 100010
#define M 200010
typedef pair<int,pair<int,int> > P;
vector<int> v[N];

int rs[M],rg[M];

int dis[N],n,m,q;
unordered_set<int> way[N];
priority_queue<P,vector<P>,greater<P> >Q;
void Dijkstra(){
	lol(i,n)dis[i]=mod;
	Q.push(make_pair(0,make_pair(0,-1)));
	while(!Q.empty()){
		int cost=Q.top().first;
		int now=Q.top().second.first;
		int from=Q.top().second.second;
		Q.pop();
		if(dis[now]<cost)continue;
		if(dis[now]==cost){
			way[now].insert(from);
			continue;
		}
		way[now].clear();
		way[now].insert(from);
		dis[now]=cost;
		lol(i,v[now].size()){
			Q.push(make_pair(cost+1,make_pair(v[now][i],now)));
		}
	}
}

int cnt=0;
void DFS(int x){
	cnt++;
	lol(i,v[x].size()){
		int to=v[x][i];
		if(way[to].size()==0)continue;
		way[to].erase(x);
		if(way[to].size()==0)DFS(to);
	}
}

int main(){
	cin>>n>>m>>q;
	lol(i,m){
		int a,b;cin>>a>>b;a--,b--;
		v[a].push_back(b);
		v[b].push_back(a);
		rs[i]=a,rg[i]=b;
	}
	Dijkstra();
	lol(u,q){
		int r;cin>>r;r--;
		int a=rs[r],b=rg[r];
		if(way[a].size()>0){
			way[a].erase(b);
			if(way[a].size()==0)DFS(a);
		}
		if(way[b].size()>0){
			way[b].erase(a);
			if(way[b].size()==0)DFS(b);
		}
		cout<<cnt<<endl;
	}
	return 0;
}



Measured memory_bytes: 26612
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll LL_INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  REP(i,N){  int a; cin >> a;}
  N -= K;
  K--;
  cout << 1 + (N + K - 1) / K << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lint long long int
using namespace std;
int main()
{
	lint a,b,c,k;
	lint ans=0;
	cin>>a>>b>>c>>k;
	ans=a;
	if(a+b<=k)
	{
		k-=a+b;
		ans-=k;
	}
	else if(k<a)
	{
		ans=k;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3576
#include <stdio.h>
#define SIZE 3

int main(void) {
  int a[SIZE] = {0};
  int i = 0;
  int j = 0;
  int tmp = 0;

  scanf("%d", &a[0]);
  scanf("%d", &a[1]);
  scanf("%d", &a[2]);

  for (i = 0; i < SIZE; i++) {
    for (j = 0; j < SIZE; j++) {
      if (a[i] < a[j]) {
	tmp = a[i];
	a[i] = a[j];
	a[j] = tmp;
      }
    }
  }

  printf("%d %d %d\n", a[0], a[1], a[2]);
  
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
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<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
const int MN=3e5+5;
int ans,tmp;
char s[MN];
int main()
{
	int i,N=read();
	scanf("%s",s+1);
	for(i=1;i<N;++i)tmp+=s[i]=='W';ans=tmp;
	for(i=N-1;i;--i)tmp+=s[i+1]=='E',tmp-=s[i]=='W',ans=min(ans,tmp);
	printf("%d\n",ans);
}

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

using namespace std;
typedef long long ll;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<bool> v(n+1,0);
    while(k--)
    {
        int m;
        cin >> m;
        for(int i=0;i<m;i++)
        {
            int x;
            cin >> x;
            v[x]=1;
        }
    }
    int res=0;
    for(int i=1;i<=n;i++) res+=(v[i]==0);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int h;
        int w;
        int n;
        int count = 0;
        int longerArgs;
        int smallerArgs;
        int sum = 0;

        Scanner scan = new Scanner(System.in);
        h = scan.nextInt();
        w = scan.nextInt();
        n = scan.nextInt();

        longerArgs = h > w ? h : w;
        smallerArgs = h > w ? w : h;

        for (int i = 0; i < smallerArgs; i++) {
            sum += longerArgs;
            count++;
            if (sum >= n) {
                break;
            }
        }

        System.out.println(count);
        scan.close();

    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long N,X;
  cin >> N >> X;
  vector<long> x(N+1);
  for(int i=0;i<N;i++) cin >> x[i];
  x[N] = X;
  VSORT(x)
  vector<long> sa(N);
  for(int i=0;i<N;i++){
    sa[i] = x[i+1] - x[i];
  }
  
  int D=INF;
  if(sa.size() == 1){
    cout << sa[0] << endl;
    return 0;
  }
  else{
      for(int i=1;i<N;i++){
      int GCD = __gcd(sa[i],sa[i-1]);
      D = min(D,GCD);
      }
  }
  cout << D << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<memory>
#include<array>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
  stack<int> st;
  int n;

  while ( cin >> n )
    {
      if ( n == 0 )
        {
          cout << st.top() << endl;
          st.pop();
        }
      else
        st.push(n);
    }
  
  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
#define MAX_RANGE 1500
#define MAX_VALUE 1000
using namespace std;

int h[MAX_RANGE], w[MAX_RANGE];

int htype[MAX_VALUE * MAX_RANGE + 1], wtype[MAX_VALUE * MAX_RANGE + 1];

void calcAns(int hsum, int wsum) {
  int ans = 0;
  for (int i = 1; i <= min(hsum, wsum); i++)
    ans += htype[i] * wtype[i];
  cout << ans << endl;
}

void calcTypeNumber(int n, int m) {
  for (int i = 0; i < n; i++) {
    int temp = h[i];
    htype[temp]++;
    for (int j = i + 1; j < n; j++) {
      temp += h[j];
      htype[temp]++;
    }
  }

  for (int i = 0; i < m; i++) {
    int temp = w[i];
    wtype[temp]++;
    for (int j = i + 1; j < m; j++) {
      temp += w[j];
      wtype[temp]++;
    }
  }
}

void initArray() {
  for (int i = 0; i < MAX_VALUE * MAX_RANGE + 1; i++) {
    htype[i] = wtype[i] = 0;
  }
}

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) return 0;

    for (int i = 0; i < n; i++)
      cin >> h[i];
    for (int i = 0; i < m; i++)
      cin >> w[i];

    int hsum = 0, wsum = 0;
    for (int i = 0; i < n; i++)
      hsum += h[i];
    for (int i = 0; i < m; i++)
      wsum += w[i];

    initArray();

    calcTypeNumber(n, m);
    
    calcAns(hsum, wsum);
  }
}

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

#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)

void recursive_debug(string) { cerr << endl; }

template<class H,class... T>
void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}

template<class T,class U>
ostream& operator<<(ostream& ost, const pair<T,U> &p) {
    ost << "(" << p.first << ", " << p.second << ")";
    return ost;
}

template<class T>
ostream& operator<<(ostream &ost, const vector<T> &v) {
    ost << "[";
    for(T t : v) ost << t << ",";
    ost << "]";
    return ost;
}

struct State {
    ll score;
    vector<int> types;
    bool operator<(const State& rhs) const {
        return (score < rhs.score);
    }
    bool operator>(const State& rhs) const {
        return (score > rhs.score);
    }
};


int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int D, M = 26;
    cin >> D;
    vector<ll> c(M);
    rep(i,M) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(M));
    rep(d,D) rep(i,M) cin >> s[d][i];

    set<State> cur_states = {{0, {}}};
    size_t SIZE = 1100;

    rep(d,D) {
        set<State> nxt_states;
        for (auto &cur_itr : cur_states) {
            const State state = cur_itr;
            vector<int> last(M, -1);
            rep(i,state.types.size()) {
                last[state.types[i]] = i;
            }
            ll minus_score = 0;
            rep(i,M) {
                minus_score -= c[i] * (d - last[i]);
            }
            rep(i,M) {
                State nxt_state {
                    state.score + s[d][i] + minus_score + c[i] * (d - last[i]),
                    state.types
                };
                nxt_state.types.push_back(i);
                
                nxt_states.insert(nxt_state);
                if (nxt_states.size() > SIZE) {
                    nxt_states.erase(nxt_states.begin());
                }
            }
        }

        cur_states = std::move(nxt_states);
    }

    for (int t : cur_states.begin()->types) {
        cout << t+1 << endl;
    }
    debug(cur_states.begin()->score);

    return 0;
}


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


int main() {
  long long N, K;
  cin >> N >> K;

  long long temp1 = N % K,
      temp2 = abs(temp1 - K);

  long long answer = (temp1 < temp2) ? temp1 : temp2;
  cout << answer << endl;
}

Measured memory_bytes: 256
import java.io.{PrintWriter, _}
import java.util._


object Main {
  def main(args: Array[String]): Unit = {
    val inputStream = System.in
    val outputStream = System.out
    val in = new InputReader(inputStream)
    val out = new PrintWriter(outputStream)
    val solver = new Task
    solver.solve(1, in, out)
    out.close()
  }

  class Task {
    def solve(testNumber: Int, in: InputReader, out: PrintWriter): Unit = {
      val s = in.nextInt
      println(s * 800 - s / 15 * 200)
    }
  }

  class InputReader(val stream: InputStream) extends AutoCloseable {
    //reader = new BufferedReader(new FileReader(stream), 32768);
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer = new StringTokenizer("")


    def next: String = {
      while ( {
        tokenizer == null || !tokenizer.hasMoreTokens
      }) try
        tokenizer = new StringTokenizer(reader.readLine)
      catch {
        case e: IOException =>
          throw new RuntimeException(e)
      }
      tokenizer.nextToken
    }

    def nextLine: String = {
      try
        return reader.readLine
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      ""
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    override def close(): Unit = {
    }
  }

}


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

using namespace std;

#include <vector>
#include <list>
#include <cstring>
#include <cmath>
#define scan(x) scanf("%d", &x)
#define scanl(x) scanf("%lld", &x)

void printarray(int* arr, int n){
	for(int i=0;i<n;i++){
		printf("%d ", arr[i]);
	}
	printf("\n");
}

void printvector(vector <int> A){
	for(auto i=A.begin();i!=A.end();i++){
		cout<<*i<<" ";
	}
	cout<<endl;
}

int main(){

	#ifndef ONLINE_JUDGE
    freopen("D:/Programming/input.txt", "r", stdin);
    freopen("D:/Programming/output.txt", "w", stdout);
	#endif

    int n;scan(n);
    int k;scan(k);

    int arr[n]={0};
    while(k--){
    	int d;scan(d);
    	for(int i=0;i<d;i++){
    		int x;scan(x);
    		arr[x-1]++;
    	}
    }
    int count=0;
    for(int i=0;i<n;i++){
    	if(arr[i]==0)count++;
    }
    //printarray(arr, n);
    cout<<count;
	return 0;
}

Measured memory_bytes: 3772
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
int main()
{
fast;
string s,t;
cin>>s>>t;
vector< vector<ll> >arr(s.size(),vector<ll>(26,-1));
for(ll i=s.size()-2;i>=0;i--)
{
    for(ll j=0;j<26;j++)
    {
        arr[i][j]=arr[i+1][j];
    }
    arr[i][s[i+1]-97]=i+1;
}
ll ans=-1;
ll cnt=-1;
for(ll i=0;i<t.size();i++)
{
    if(ans==-1)
    {
        if(t[i]==s[0])
        {
            ans=0;
            cnt++;
        }else if(arr[0][t[i]-97]==-1)
        {
            ans=-1;
            break;
        }else
        {
            ans=arr[0][t[i]-97];
            cnt++;
        }
    }else
    {
        if(arr[ans][t[i]-97]==-1)
        {
            ans=-1;
            i--;
        }else{

        ans=arr[ans][t[i]-97];
        }
    }
}
if(ans==-1)
{
    cout<<-1<<endl;
}else
{
    ll x=s.size()*cnt+ans+1;
    cout<<x<<endl;
}
return 0;
}


Measured memory_bytes: 24784
import java.util.Scanner;

class Main {
    private static void solve() {
        Scanner scanner = new Scanner(System.in);

        int[] counts = new int[101];
        while (scanner.hasNext()) {
            counts[scanner.nextInt()]++;
        }
        int maximum = 0;
        for (int i = 0; i < counts.length; i++) {
            if (counts[i] > maximum) {
                maximum = counts[i];
            }
        }
        for (int i = 0; i < counts.length; i++) {
            if (counts[i] == maximum) {
                System.out.println(i);
            }
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

vector<int> solve(int n, int m, const vector<int> & a, const vector<int> & b) {
    vector<vector<int> > g(n);
    REP (i, m) {
        g[a[i]].push_back(i);
        g[b[i]].push_back(i);
    }
    constexpr int root = 0;
    vector<int> parent(n, -1);
    queue<int> que;
    que.push(root);
    while (not que.empty()) {
        int x = que.front();
        que.pop();
        for (int e : g[x]) {
            int y = x ^ a[e] ^ b[e];
            if (y == root or parent[y] != -1) continue;
            parent[y] = x;
            que.push(y);
        }
    };
    if (count(ALL(parent), -1) >= 2) {
        return vector<int>();
    }
    return parent;
}

// generated by online-judge-template-generator v4.1.0 (https://github.com/kmyk/online-judge-template-generator)
const string YES = "Yes";
const string NO = "No";
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int N;
    int M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    REP (i, M) {
        cin >> A[i] >> B[i];
        -- A[i];
        -- B[i];
    }
    auto ans = solve(N, M, A, B);
    if (ans.empty()) {
        cout << NO << endl;
    } else {
        cout << YES << endl;
        REP3 (i, 1, N) {
            cout << ans[i] + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 11752
# include <iostream>
# include <algorithm>
# include <cmath>
using namespace std;

# define ll long long

ll gcd(ll a, ll b){
  return b==0 ? a : gcd(b, a%b);
}

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

int main(){

  int N, M;
  cin >> N >> M;
  string S, T;
  cin >> S >> T;

  int g = gcd(N,M);
  int n = N/g;
  int m = M/g;

  bool flag = true;
  for(int k=0; k<g; k++){
    if(S[n*k] != T[m*k]){
      flag = false;
      break;
    }
  }

  if(flag) cout << lcm(N, M) << endl;
  else cout << -1 << endl;
  return 0;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

string s;
int ans[100005], nd[100005][2], ret[100005];

pair<int, bool> go(int i, int p, bool d) {
    if (ans[i] != -1)
        return {i, d};
    int nxt = i + (s[i] == 'L' ? -1 : 1);
    if (nxt == p) {
        nd[i][0] = nd[p][0] = i;
        nd[i][1] = nd[p][1] = p;
        ans[i] = 0;
        ans[p] = 1;
        return {i, d};
    }
    auto pi = go(nxt, i, !d);
    nd[i][0] = nd[pi.first][0];
    nd[i][1] = nd[pi.first][1];
    ans[i] = ans[pi.first] ^ (d != pi.second);
    return {i, d};
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> s;
    int n = s.length();

    memset(ans, -1, sizeof(ans));
    for (int i=0; i<n; i++) {
        go(i, -1, 0);
        ret[nd[i][ans[i]]]++;
    }

    for (int i=0; i<n; i++)
        cout << ret[i] << " \n"[i==n-1];

    return 0;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            if (0 < Console.ReadLine().ToArray().Select(c => 'A' <= c && c <= 'Z').Count(c => c))
            {
                Console.WriteLine("A");
            }
            else
            {
                Console.WriteLine("a");
            }
        }
    }
}


Measured memory_bytes: 26484
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
#define pi (acos(-1))
///#define for(i,a,b) for(i=(a);i<(b);++i)
///freopen("input.txt","r",stdin);
///   freopen("output.txt","w",stdout);
int n,m;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mk make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define TEST int test; cin >> test;while(test--)
#define ii pair<int,int>
#define iil pair<ll,ll>
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define INF 2147483647


int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);


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


ll mod(ll a, ll b)
{
    ll c = a % b;
    if (c < 0)
        c += b;
    return c;
}
ll power(ll x, unsigned long long y)
{
    int res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x);

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x);  // Change x to x^2
    }
    return res;
}
int isPrime[5000000] ;
vector< vector<ll> > pf(1000000), pr(1000000);
void sieve(int n)
{
    for(int i = 2 ; i*i <= n ; i++)
    {
        if(!isPrime[i])
        {
            // v.pb(i);
            for(int j = i+i ; j <= n; j = j + i)
            {
                isPrime[j] = 1;
                pf[j].pb(i);
            }
        }
    }
    return;
}
const int n = 1e6;
ll cn[n+10], cn1[n+10];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s,t;
    cin >> s >> t;
    int l  = s.size();
    if( s == t.substr(0,l)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;



}


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

int main() {
  using pii = pair<int, int>;
  // これ以降 pii という型名はpair<int, int> と同じ意味で使える
  using vi = vector<int>; // intの1次元の型に vi という別名をつける
  using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
//
//  pii p;
//  p = make_pair(1, 2);
//  int N = 10, M = 20;
//  vvi data(N, vi(M));  // N * M の2次元配列
//
  string s,t,tlst,ans;
  int n;
  ans = "Yes";
  cin >> s >>t;
  n = t.size();
  tlst = t.at(n-1);
  s = s + tlst;
  if(s != t){
    ans = "No";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define MAXN 10000

using namespace std;
typedef long long ll;

int main()
{
	//freopen("t.txt","r",stdin);
	int n, max, a[100],j;
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a[i];
	}
	max=a[1];
	int d=1;
	for (int i=2;i<=n;i++){
		
		if (a[i]>=max){
			max=a[i]; d++;
		}
	}
	cout<<d;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
int n,m,ans;
int main()
{
	scanf("%d%d%d",&n,&m,&ans);
	int bns=max(n,m);
	ans=ans%bns==0?ans/bns:(ans/bns+1);
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 764
// 2019/07/03
// AtCoder Beginner Contest 056 - B

#include <bits/stdc++.h>
using namespace std;

int main() {
    int w, a, b, x1, x2, ans;
    cin >> w >> a >> b;
    if(a < b){
        x1 = a;
        x2 = b;
    } else {
        x1 = b;
        x2 = a;
    }
    ans = max(0, x2 - (x1 + w));

    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <queue>

int main() {
    int n; std::cin >> n;
    std::priority_queue<double, std::vector<double>, std::greater<double>> q;
    for (int i = 0; i < n; i++) {
        double a; std::cin >> a;
        q.push(a);
    }

    while(q.size() > 1) {
        auto a = q.top(); q.pop();
        auto b = q.top(); q.pop();
        q.push((a+b)/2);
    }
    std::cout << std::fixed << std::setprecision(15) << q.top() << std::endl;
    return 0;
}

Measured memory_bytes: 3280
#!/usr/bin/env python3
import math
# スペース区切りの整数の入力
X, K, D = map(int, input().split())

cross = abs(-(-X//D))

if cross >= K:
    if X >= 0:
        X -= D*K
    else:
        X += D*K
    print(abs(X))
else:
    if X >= 0:
        X -= D*cross
    else:
        X += D*cross
    
    if (K-cross)%2 == 0:
        print(abs(X))
    else:
        if X >= 0:
            print(abs(X-D))
        else:
            print(abs(X+D))





Measured memory_bytes: 9140
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cassert>
#include<iomanip>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define eps (1e-8)
#define equals(a,b) (fabs((a)-(b)) < eps)
#define MAX 2000000
#define all(n) (n).begin(),(n).end()
using namespace std;
struct Circle
{
  double x,y,r;
  Circle(double x=inf,double y=inf,double r=inf):x(x),y(y),r(r){}
  bool operator < (const Circle& c)const
  {
    if(!equals(x,c.x))return x < c.x;
    return y < c.y;
  }
};

bool compare_y(Circle a,Circle b)
{
  return a.y < b.y;
}

int N;
Circle A[MAX];

double compute(Circle *a,int n)
{
  if(n <= 1)return inf;
  int m = n/2;
  double x = a[m].x;
  double y = a[m].y;
  double r = a[m].r;
  double d = min(compute(a,m),compute(a+m,n-m));
  inplace_merge(a,a+m,a+n,compare_y);

  vector<Circle> b;

  rep(i,n)
    {
      double nx = a[i].x - x;
      double ny = a[i].y - y;
      double ndist = sqrt(nx*nx + ny*ny) - a[i].r - r;
      //if(equals(ndist,d) || ndist > d)continue;
      //if(nx >= d)continue;
     
      rep(j,(int)min((int)b.size(),10))
	{
	  int last = b.size()-j-1;
	  double dx = a[i].x - b[last].x;
	  double dy = a[i].y - b[last].y;
	  double dist = sqrt(dx*dx + dy*dy) - a[i].r - b[last].r;

	  if(equals(dist,d) || dist > d)continue;
	  d = min(d,sqrt(dx*dx + dy*dy) - a[i].r - b[last].r);
	}
      b.push_back(a[i]);
    }
  return d;
}



int main()
{
  while(cin >> N,N)
    {
      assert(N < MAX);
      rep(i,N)cin >> A[i].r >> A[i].x >> A[i].y;
      sort(A,A+N);


      cout << setiosflags(ios::fixed) << setprecision(8) << compute(A,N) << endl;
    }
  return 0;
}

Measured memory_bytes: 53580
#include <iostream>
 
int main()
{
    int n, a;
 
    std::cin >> n;
    int min = 1000000, max = -1000000;
    long sum = 0;
    for (int i = 0; i < n; ++i){
        std::cin >> a;
        if (a < min) min = a;
        if (a > max) max = a;
        sum += a;
    }
 
    std::cout << min << " " << max << " " << sum << std::endl;
 
    return 0;
}

Measured memory_bytes: 3076
#include <stdio.h>

int main (void){

int a[4][13]={0};
int i, j, k, num, n;
char mark;

scanf("%d", &n);

for(k = 0; k < n; k++){
	scanf(" %c%d", &mark, &num);
	if(mark == 'S')
		a[0][num - 1] = 1;
	else if(mark == 'H')
		a[1][num - 1] = 1;
	else if(mark == 'C')
		a[2][num - 1] = 1;
	else if(mark == 'D')
		a[3][num - 1] = 1;
}

for(i = 0; i < 4; i++){
	for(j = 0; j < 13; j++){
		if(a[i][j] == 0){
			if(i == 0)
				printf("S %d\n", j + 1);
			else if(i == 1)
				printf("H %d\n", j + 1);
			else if(i == 2)
				printf("C %d\n", j + 1);
			else if(i == 3)
				printf("D %d\n", j + 1);
		}
	}
}
return 0;
}



Measured memory_bytes: 2012
//ΔAGC022A
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
char ch[33];
int n,a[33];
void chk(){
	int i,j;
	for(i=0;i<=n;i=i+1)
		for(j=i+1;j<=n;j=j+1)
			if(a[i]==a[j])
				return;
	for(i=0;i<=n;i=i+1)
		cout<<(char)(a[i]+'a'-1);
	exit(0);
}
int main()
{
	int i;
	cin>>ch;
	n=strlen(ch);
	for(i=0;i<n;i=i+1)
		a[i]=ch[i]-'a'+1;
	for(;n>=0;n=n-1){
		while(a[n]<26){
			a[n]++;
			chk();
		}
		a[n]=0;
	}
	cout<<-1;
	return 0;
}

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

int main() {
	int N, Y;
	cin >> N >> Y;
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= N - i; ++j) {
			if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
				cout << i << ' ' << j << ' ' << N - i - j;
				exit(0);
			}
		}
	}
	cout << "-1 -1 -1";
}

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

using namespace std;

typedef long long ll;

int main(void)
{
  int N;
  double K;
  cin >> N >> K;
  double ans = 0.0;
  for (ll x = 1; x <= N; x++) {
    double y = ceil(log2(K / (double) x));
    if (y < 0) y = 0.0;
    ans += pow(0.5, y);
  }
  ans /= (double) N;
  cout << fixed << setprecision(10);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void) {
	int n , i , j , count[6] = {0};
	double input;
	
	scanf("%d",&n);
	
	for ( i = 0; i < n; i++ ) {
		scanf("%lf",&input);
		if ( input < 165.0 )
			count[0]++;
		if ( 165.0 <= input && input < 170.0 )
			count[1]++;
		if ( 170.0 <= input && input < 175.0 )
			count[2]++;
		if ( 175.0 <= input && input < 180.0 )
			count[3]++;
		if ( 180.0 <= input && input < 185.0 )
			count[4]++;
		if ( 185.0 < input )
			count[5]++;
	}
	for ( i = 0; i < 6; i++ ) {
		printf("%d:",i+1);
		for ( j = 0; j < count[i]; j++ ) {
			printf("*");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;

int main(){
    vector<ll> a(3);
    rep(i, 3) cin >> a[i];
    sort(a.begin(),a.end());
    ll cou = 0;
    cou += a[1] - a[0];
    cou += a[2] - a[1];
    cout << cou << endl;
}
   

Measured memory_bytes: 256
//Date:12-11-17

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<float.h>
#include<math.h>
#include<ctype.h>
#include<limits.h>
#include<time.h>
#define ll long long
#define For(i,n)	for(i=0;i<n;i++)
#define rep(i ,a ,b)	for(i=(a);i<=(b);i++)
#define mset(a ,value)	memset(a ,value ,sizeof(a))
#define s(a)	scanf("%d" ,&a);
#define ls(a)	scanf("%ld" ,&a)
#define lls(a)	scanf("%lld" ,&a)
#define reg(i)	register int i
#define infinite INT_MAX
#define MAX 1001
int min(int a,int b){	return (a<b?a:b);	}
int max(int a,int b){	return (a>b?a:b);	}
const int mod = 1e9+7;
int n;
bool prime[1001];
ll power(ll a, ll b, ll mod){
	ll x = 1, y = a;
	while (b){
		if (b%2)	x = (x*y)%mod;
		y = (y*y)%mod;
		b /= 2;
	}
	return x%mod;
}	

void sieve(){
	ll i ,j;
	mset(prime ,1);
	prime[1] =false;
	for(i=2;i<=1000;i++){
		if(prime[i]==true){
			j=i*i;
			while(j<=1000){
				prime[j] = false;	j+=i;
			}
		}
	}
}

main(){
	int n ,a ,b ,i;
	s(n);	s(a);	 s(b);
	ll p[n];
	For(i ,n)	lls(p[i]);
	ll f=0;
	rep(i ,1 ,n-1){
		if((p[i]-p[i-1])*a>b)	f+=b;
		else f+=((p[i]-p[i-1])*a	);
	}
	printf("%lld" ,f);
	return 0;
}

Measured memory_bytes: 896