akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int numsum(ll x){
  int sum = 0;
  while(x){
    sum += x%10;
    x/=10;
  }
  return sum;
}

int check(ll x, ll y){
  cerr << x << " " << y << endl;
  cerr << numsum(x)*y << " " << numsum(y)*x << endl;
  return numsum(y)*x <= numsum(x)*y;
}

int check(ll x){
  int sx = numsum(x);
  
  for(ll i=x;i<10000000;i++){
    int si = numsum(i);
    if(x*si > i*sx){
      return false;
    }
  }

  return true;
}

int di(ll x){
  for(int i=0;x;i++){
    if(x) x/=10;
    else return i;
  }
  return 0;
}

int main(){

  if(false){
    for(int i=1;i<10000000;i++){
      if(check(i)) printf("%d\n", i);
    }
    return 0;
  }
  
  
  int k;

  scanf("%d",&k);

  int maxt = 9;

  vector<string> ans;
  
  set<string> ss;

  for(int i=1;i<10;i++) ss.insert(to_string(i));

  string prev = "";
  
  for(int i=1;;i++){
    for(auto s: ss){
      if(k == 0) return 0;

      string t = s;
      int l = i - s.size();
      for(int i=0;i<l;i++) t += "9";

      if(prev.size() && check(stoll(prev), stoll(t))){
        cout << prev << endl;
        k--;
      }
      prev = t;
    }

    if(i >= 3){
      for(int i=0;i<10;i++){
        string t = to_string(maxt + i + 1);
        ss.insert(t);
        t = t.substr(0, t.size()-1);
        auto it = ss.find(t);
        if(it != ss.end()) ss.erase(it);
      }
      maxt += 10;
    }
  }
  
  return 0;
}



Measured memory_bytes: 256
def c(x,y,h,w)
  (x + y % 2) % 2 == 0 ? ?# : ?.
end

loop {
  h, w = gets.split.map(&:to_i)

  break if h == 0 && w == 0
  
  h.times{|y|
    w.times{|x| print c(x,y,h,w) }
    puts
  }
  puts
}



Measured memory_bytes: 6852
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int n = in.nextInt();
            BigDecimal bdecN = new BigDecimal(n);
            BigDecimal bdecNMinus1 = new BigDecimal(n - 1);

            BigDecimal bdecRes = (bdecN.multiply(bdecNMinus1)).divide(new BigDecimal(2));
            out.print(bdecRes.longValue());
        }

    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <math.h>
using namespace std;

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

	cin >> A >> B >> C;

	if (A < C && C < B && A < B)
		cout << "Yes" << endl;
	else if (B < C && C < A && B < A)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,w[105],v[105],f[100005];
int main() {
	cin>>n>>m;
	for(int i=1;i<=n;i++)
      cin>>w[i]>>v[i];
	memset(f,0x3f,sizeof(f)),f[0]=0;
	for(int i=1;i<=n;i++)
		for(int j=100000;j>=v[i];j--)
          f[j]=min(f[j],f[j-v[i]]+w[i]);
	int ans=0;
	for(int i=1;i<=100000;i++)
      if(f[i]<=m)ans=i;
	cout<<ans;
}

Measured memory_bytes: 3928
#include <cstdio>
#include <cstring>

int a,b,c;
bool flag[61];
int main(void){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	memset(flag,false,sizeof(flag));
	int t=0;
	while(1){
		if(flag[t%60])break;
		flag[t%60]=true;
		int rest=(c-t+6000000)%60;
		if(rest<=a){
			printf("%d\n",t+rest);
			return 0;
		}
		t+=a+b;
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 1024
//itp1_7-c
#include <iostream>
#include <vector>
using namespace std;

int main(){
 int r,c;
 int x;
 cin>>r>>c;
 vector< vector<int> > a(r+1, vector<int>(c+1));

 for(int i=0;i<r;i++)
  for(int j=0;j<c;j++){
   cin>>x;
   a[i][j]=x;
  }
 for(int i=0;i<r;i++)
  for(int j=0;j<c;j++)
   a[i][c]+=a[i][j];
  
 for(int i=0;i<=c;i++)
  for(int j=0;j<r;j++)
   a[r][i]+=a[j][i];

 for(int i=0;i<=r;i++){
  for(int j=1;j<=c;j++){
   cout<<a[i][j-1]<<" ";
  }
  cout<<a[i][c]<<endl;
 }
 return 0;
}

Measured memory_bytes: 1256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		String OP = sc.next();
		int B = sc.nextInt();
		if (OP.endsWith("+"))  System.out.println(A+B);
		else  System.out.println(A-B);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n,k;
    cin >> n >> k;
    Vi p(n+1),c(n+1);
    repi(i,1,n+1) cin >> p[i];
    repi(i,1,n+1) cin >> c[i];
    Vi seen(n+1,0);
    ll ans=-INF;
    repi(i,1,n+1){
        if(seen[i]==1) continue;
        ll pos=i;
        ll sum=0;
        Vi loop;
        while(seen[pos]==0){
            seen[pos]=1;
            loop.pb(pos);
            pos=p[pos];
            sum+=c[pos];
        }
        int si=loop.size();
        if(k<=si){
            for(auto start:loop){
                ll res=0;
                ll posi=start;
                rp(j,k){
                    posi=p[posi];
                    res+=c[posi];
                    chmax(ans,res);
                }
            }
        }else{
            if(sum<=0){
                for(auto start:loop){
                    ll res=0;
                    ll posi=start;
                    rp(j,si){
                        posi=p[posi];
                        res+=c[posi];
                        chmax(ans,res);
                    }
                }
            }else{
                for(auto start:loop){
                    ll res=sum*(k/si-1);
                    ll posi=start;
                    rp(j,k-si*(k/si-1)){
                        posi=p[posi];
                        res+=c[posi];
                        chmax(ans,res);
                    }
                }
            }
        }
    }
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3812
h,w=map(int,input().split())
t=[list(input())for i in range(h)]
def check(x,y):
    dx=[0,0,1,-1]
    dy=[1,-1,0,0]
    for k in range(4):
        x=i+dx[k]
        y=j+dy[k]
        if 0<=x and x<h and 0<=y and y<w and t[x][y]=="#":
            return True
for i in range(h):
    for j in range(w):
        if t[i][j]=="#":
            if check(i,j):
                pass
            else:
                print("No")
                exit()
print("Yes")



Measured memory_bytes: 3064
#include<iostream>
#include<utility>
#include<tuple>
#include<set>
#include<list>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;
#define int long long

const long long MAXN = 1e6;
const long long MOD = 1e9+7;
const long long INF = __LONG_LONG_MAX__ / 2;

using namespace std;

vector<pair<int, int> > ranges;
vector<pair<int, int> > nextranges;
vector<pair<int, int> > result;

void mergeRange(){
    sort(nextranges.begin(),nextranges.end());
    vector<pair<int, int> >::iterator it = nextranges.begin();
    pair<int,int> current = *(it)++;
    while (it != nextranges.end()){
       if (current.second > it->first){ // you might want to change it to >=
           current.second = std::max(current.second, it->second); 
       } else {
           ranges.push_back(current);
           current = *(it);
       }
       it++;
    }
    ranges.push_back(current);
}

signed main(){
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  for (int i = 0; i < N-1; i++)
  {
    int rMax = A + D*i - C * (N-1-i);
    int rMin = A + C*i - D * (N-1-i);
    if (rMin <= B && B <= rMax){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string A,B,C;
  cin >>A>>B>>C;
  char t='a';
  int az=A.size(),bz=B.size(),cz=C.size();
  int a=0,b=0,c=0;
  while(true){
    if(t=='a'){
      if(a == az){
        cout << "A" << endl;
        return 0;
      }
      t=A[a];
      a++;
    }
    if(t=='b'){
      if(b == bz){
        cout << "B" << endl;
        return 0;
      }
      t=B[b];
      b++;
    }
    if(t=='c'){
      if(c == cz){
        cout << "C" << endl;
        return 0;
      }
      t=C[c];
      c++;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>

using namespace std;

int main()
{
  int N, M;
  map< string, int > cards;
  string s;

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> s;
    cards[s]++;
  }

  cin >> M;
  for(int i = 0; i < M; i++) {
    cin >> s;
    cards[s]--;
  }

  int ans = 0;
  for(auto it = cards.begin(); it != cards.end(); ++it) {
    ans = max(ans, (*it).second);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    reverse(All(s));
    vector<int> a;
    for(int i=0;i<=n;i++){
        bool ok=false;
        int M = 0;
        for(int j=1;j<=m;j++){
            if(s[min(i+j,n)]=='0'){
                ok=true;
                M=min(i+j,n+1);
            }
        }
        if(ok){
            i=M-1;
            if(M==n+1){
                M--;
            }
            a.push_back(M);
        }else{
            cout<<-1<<endl;
            return 0;
        }
    }
    for(int i=a.size()-1;i>0;i--){
        a[i]-=a[i-1];
    }
    reverse(All(a));
    for(auto it:a){
        if(it!=0){
            cout<<it<<' ';
        }
    }
    cout<<endl;
}

Measured memory_bytes: 1480
#include <iostream>

using namespace std;

typedef long long int ll;

int main() {
    ll a, b, x;

    cin >> a >> b >> x;

    if ((a % x) == 0) {
        cout << b / x - a / x + 1 << endl;
    } else {
        cout << b / x - a / x << endl;
    }

    return 0;
}




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

int main() {
  int N,M;
  cin >> N;
  
  vector<string> word;
  vector<int> cnt;
  
  int i,j;
  string tmp;
  
  cin >> tmp;
  word.push_back(tmp);
  cnt.push_back(1);
  bool exist;
  
  for(i=1;i<N;i++){
    cin >> tmp;
    exist = false;
    for(j=0;j<word.size();j++){
      if(tmp == word.at(j)){
        cnt.at(j) += 1;
        exist = true;
        break;
      }
    }
    if(exist != true){
      word.push_back(tmp);
      cnt.push_back(1);
    }
  }
  
  cin >> M;
  for(i=0;i<M;i++){
    cin >> tmp;
    //exist = false;
    for(j=0;j<word.size();j++){
      if(tmp == word.at(j)){
        cnt.at(j) -= 1;
        //exist = true;
        break;
      }
    }
    /*if(exist != true){
      word.push_back(tmp);
      cnt.push_back(1);
    }*/
  }
  
  int max;
  max = 0;
  for(i=0;i<cnt.size();i++){
    if(max < cnt.at(i)){
      max = cnt.at(i);
    }
  }
  cout << max;
       
        
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+7;

ll n,a[maxn];
int main(){
    cin>>n;
    for(int i=1;i<=n;++i) cin>>a[i];
    for(int i=1;i<=n;++i) a[i]-=i;
    sort(a+1,a+1+n);
    ll x=a[(n+1)/2];
    ll ans=0;
    for(int i=1;i<=n;++i) ans+=abs(x-a[i]);
    print(ans);
    return 0;
}
//6 5 4 3 2 1
//5 3 1 -1 -

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


int main(){

    int N, M;
    long long int a[1000][3];

    cin >> N >> M;
    for( int i = 0; i < N; i++ ){
        for( int j = 0; j < 3; j++ ){
            cin >> a[i][j];
        }
    }

    
    long long int ans = 0;

    for( int i = 0; i < 8; i++ ){
        long long int sum = 0;
        long long int b[10000] = {};
        for( int j = 0; j < N; j++ ){
            for( int k = 0; k < 3; k++ ){
                if( i/(1<<k) % 2 == 0) b[j] += a[j][k];
                else b[j] -= a[j][k];
            }
        }
        sort( b, b+N );
        for( int j = N-1; j >= N-M; j-- ) sum += b[j];
        ans = max( ans, sum );
    }
    
    cout << ans << endl;

    return 0;

}

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

int main() {
  int n;
  int i, k;
  cin >> n;
  int isDerangeList[n];
  for (i = 0; i < n; i++) {
    cin >> k;
    if (k == i + 1) {
      isDerangeList[i] = 0;
    } else {
      isDerangeList[i] = 1;
    }
  }
  int swpcnt = 0;
  for (i = 0; i < n; i++) {
    if (isDerangeList[i] == 0) {
      swpcnt++;
      i++;
    }
  }
  cout << swpcnt << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.*;

class Main {
	private static String str = null;
	private static boolean satisfy(int p, int q, int r) {
		String formula = str.replaceAll("P", Integer.toString(p))
			.replaceAll("Q", Integer.toString(q))
			.replaceAll("R", Integer.toString(r));
		while (formula.indexOf('+') != -1 || formula.indexOf('*') != -1 || formula.indexOf('-') != -1) {
			formula = formula.replaceAll("-0", "2")
				.replaceAll("-1", "1")
				.replaceAll("-2", "0")
				.replaceAll("\\(0\\+0\\)", "0")
				.replaceAll("\\(0\\+1\\)", "1")
				.replaceAll("\\(0\\+2\\)", "2")
				.replaceAll("\\(1\\+0\\)", "1")
				.replaceAll("\\(1\\+1\\)", "1")
				.replaceAll("\\(1\\+2\\)", "2")
				.replaceAll("\\(2\\+0\\)", "2")
				.replaceAll("\\(2\\+1\\)", "2")
				.replaceAll("\\(2\\+2\\)", "2")
				.replaceAll("\\(0\\*0\\)", "0")
				.replaceAll("\\(0\\*1\\)", "0")
				.replaceAll("\\(0\\*2\\)", "0")
				.replaceAll("\\(1\\*0\\)", "0")
				.replaceAll("\\(1\\*1\\)", "1")
				.replaceAll("\\(1\\*2\\)", "1")
				.replaceAll("\\(2\\*0\\)", "0")
				.replaceAll("\\(2\\*1\\)", "1")
				.replaceAll("\\(2\\*2\\)", "2");
		}
		return formula.equals("2");
	}
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		while (!(str = sc.next()).equals(".")) {
			int count = 0;
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					for (int k = 0; k < 3; k++) {
						if (satisfy(i, j, k)) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}

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

#define MAX_N 3000000

long long bit[MAX_N], n, m, a, b, c;

long long sum1(int i) {
	long long sum = 0;
	while (i > 0) {
		sum += bit[i];
		i -= i&-i;
	}
	return sum;
}

void add(int i, int x) {
	while (i <= n) {
		bit[i] += x;
		i += i&-i;
	}
}

int main() {
	cin >> n >> m;
	for (int j = 0; j < m; j++) {
		cin >> a >> b >> c;
		if (a == 0) {
			add(b, c);
		}
		else {
			cout << sum1(c) - sum1(b - 1) << endl;
		}
	}
	return 0;
}

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

int n;
int a[101];
int gcd(int a, int b){
	if(a == 0)return b;
	if(b == 0)return a;
	if(a > b)a = a % b;
	else b = b % a;
	return gcd(a, b);
}

signed main(){
	scanf("%lld", &n);
	for(int i = 0;i < n;i++)scanf("%lld", &a[i]);
	int ans = 1;
	for(int i = 0;i < n;i++){
		ans = (ans/gcd(ans, a[i])*a[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

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

#define ll                  long long int
#define llu                 long long unsigned
#define ld                  long double
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);
#define endl                "\n"
#define pb                  push_back
#define bp                  pop_back
#define pf                  push_front
#define fp                  pop_front
#define mp                  make_pair
#define ms(a,b)             memset((a),(b),sizeof(a))
#define min3(a,b,c)         min(a,min(b,c))
#define max3(a,b,c)         max(a,max(b,c))
#define min4(a,b,c,d)       min(min(a,b),min(c,d))
#define max4(a,b,c,d)       max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)     min(min3(a,b,c),min(d,e))
#define NUM                 1000000
#define PI		    2*acos(0.0)
#define maximum             (-1*INF)
#define READ(f) 	    freopen("f", "r", stdin)
#define WRITE(f) 	    freopen("f", "w", stdout)
const int INF = 1e5 + 10 ;

int main()
{
    ll n, temp;
    cin>>n;
    vector<ll> v(n);
    for(ll i = 0; i < n-1; i++)
    {
        cin>>temp;
        v[temp-1]++;
    }
    for(ll i = 0; i < n; i++)
        cout<<v[i]<<endl;
    return 0;
}


Measured memory_bytes: 4844
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 1e5;
int N;
int a[MAX_N];


int main() {
  cin >> N;
  rep(i,N) cin >> a[i];

  sort(a, a+N);

  int n = a[N-1];
  if (n%2 == 0) {
    int i = upper_bound(a, a+N, n/2) - a;
    if (i >= N-1) {
      cout << n << ' ' << a[N-2] << endl;
      return 0;
    }
    int r1 = a[i], r2 = a[i-1];
    if (r1 - n/2 > n/2 - r2) {
      cout << n << ' ' << r2 << endl;
    } else {
      cout << n << ' ' << r1 << endl;
    } 
  } else {
    int i = upper_bound(a, a+N, (n+1)/2-1) - a;
    if (i >= N-1) {
      cout << n << ' ' << a[N-2] << endl;
    }
    int r1 = a[i], r2 = a[i-1];
    if (r1 == (n+1)/2) {
      cout << n << ' ' << r1 << endl;
      return 0;
    }
    if (r2 == (n+1)/2-1) {
      cout << n << ' ' << r2 << endl;
      return 0;
    }
    if (r1 - (n+1)/2 > (n+1)/2-1 - r2) {
      cout << n << ' ' << r2 << endl;
    } else {
      cout << n << ' ' << r1 << endl;
    }
  }

}


Measured memory_bytes: 640
N=gets.to_i
    $as=N.times.map{gets.split.map{|e|e.to_i-1}}
    $queue=Array.new
    def push_queue(i)
      op=$as[i][0]
      return if op.nil?
      opop=$as[op][0]
      return if i!=opop
      $queue << [i,op]
      return
    end
     
    day=0
     
    N.times do |i|
      push_queue(i)
    end
     
    until $queue.empty?
      day+=1
      queue_cur=$queue
      $queue=Array.new
      until queue_cur.empty?
        a,b=queue_cur.shift
        if $as[a][0]==b && $as[b][0]==a
          $as[a].shift
          $as[b].shift
          push_queue(a)
          push_queue(b)
        end
      end
    end
    puts $as.all?{|es|es.empty?} ? day : -1


Measured memory_bytes: 13588
#include <stdio.h>

int main(void){

  int a,b,c;
  scanf("%d %d %d", &a, &b, &c);

  if (a == b && a != c) {
    printf("Yes\n");
  } else if (b == c && b != a) {
    printf("Yes\n");
  } else if (c == a && c != b) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

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

typedef long long ll;

int u[700][700];

int r=0;

int main(){
	int n,m,t,p;
	while(cin >> n >> m >> t >> p,n&&m&&t&&p){
		for(int i=0;i<700;i++){
			for(int j=0;j<700;j++){
				u[i][j]=0;
			}
		}
		vector<int> d(t),c(t),x(p),y(p);
		for(int i=0;i<t;i++){
			cin >> d[i] >> c[i];
		}
		for(int i=0;i<p;i++){
			cin >> x[i] >> y[i];
		}
		int xx=r,yy=r;
		int xxx=r+n,yyy=r+m;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				u[xx+i][yy+j]=1;
			}
		}
		for(int i=0;i<t;i++){
			if(d[i]==1){
				for(int k=yy;k<yyy;k++){
					int pp=1;
					for(int j=xx+c[i];j<xx+c[i]+35;j++){
						if(j-pp>=0){
							u[j][k]+=u[j-pp][k];
							u[j-pp][k]=0;
						}
						pp+=2;
					}
				}
				xx+=c[i];
				for(int j=35;j>=0;j--){
					if(u[xx+j][yy]>=1){
						xxx=xx+j+1;
						break;
					}
				}
			}
			else{
				for(int k=xx;k<xxx;k++){
					int pp=1;
					for(int j=yy+c[i];j<yy+c[i]+35;j++){
						if(j-pp>=0){
							u[k][j]+=u[k][j-pp];
							u[k][j-pp]=0;
							//cout << u[k][j-pp] << " " << j << " " << pp << endl;
						}
						pp+=2;
					}
				}
				yy+=c[i];
				for(int j=35;j>=0;j--){
					if(u[xx][yy+j]>=1){
						yyy=yy+j+1;
						break;
					}
				}
			}
		}
		for(int i=0;i<p;i++){
			printf("%d\n",u[xx+x[i]][yy+y[i]]);
		}
	}
}



Measured memory_bytes: 5052
fn main() {
    let s = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    };
    let (w, h) = {
        let mut ws = s.split_whitespace();
        let w: i32 = ws.next().unwrap().parse().unwrap();
        let h: i32 = ws.next().unwrap().parse().unwrap();
        (w, h)
    };
    println!("{:?} {:?}", w * h, (w + h) * 2);
}


Measured memory_bytes: 5032
#include<iostream>
using namespace std;
int main(){
  
  int a,b;
  cin >> a >> b;
  while(a != 0){
    
    for(int i = 1;i < a;i++){
      if(i==1 || i==3 || i==5 || i==7 || i==8 || i==10){
	b += 31;
      }
      else if(i==4 || i==6 || i==9 || i==11){
	b += 30;
      }
      else if(i == 2){
	b += 29;
      }
    }

    if(b%7 == 1) cout << "Thursday" << endl;
    else if(b%7 == 2) cout << "Friday" << endl;
    else if(b%7 == 3) cout << "Saturday" << endl;
    else if(b%7 == 4) cout << "Sunday" << endl;
    else if(b%7 == 5) cout << "Monday" << endl;
    else if(b%7 == 6) cout << "Tuesday" << endl;
    else cout << "Wednesday" << endl;
    cin >> a >> b;
  }
  return (0);
}

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

const double PI = acos(-1);

int main(){	
	int a,b,h,m;
	cin >> a >> b >> h >> m;
	double th = double(h*60+m)/720 * 2*PI;
	double tm = double(m)/60 * 2*PI;
	double xh = a*cos(th), yh = a*sin(th);
	double xm = b*cos(tm), ym = b*sin(tm);
	double dx = xh-xm, dy = yh-ym;
	double ans = sqrt(dx*dx + dy*dy);
	printf("%.10f\n", ans);
	return 0;

}





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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MAX=100005;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,n){cout<<arr[i][j]<<" ";}cout<<endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    string s;
    cin>>n>>k>>s;
    ll happy=0;
    ll lr = 0;
    ll rl = 0;
    rep(i,n){
        if(i>0){
//            if(s[i]==*"R"&&s[i-1]==*"L"){
//                lr ++;
//            }
//            if(s[i]==*"L"&&s[i-1]==*"R"){
//                rl ++;
//            }
            if(s[i]==s[i-1]){
                happy ++;
            }
        }

    }
    ll ans= min(n-1,happy+2*k);
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int H,W;
main()
{
	cin>>H>>W;
	vector<pair<int,pair<int,bool> > >A;
	for(int i=0;i<H+W;i++)
	{
		int a;cin>>a;
		A.push_back(make_pair(a,make_pair(i<H?H:W,i<H)));
	}
	sort(A.begin(),A.end());
	long ans=0;
	int h=H,w=W;
	for(int i=0;i<H+W;i++)
	{
		if(!A[i].second.second)
		{
			ans+=1L*A[i].first*(h+1);
			w--;
		}
		else
		{
			ans+=1L*A[i].first*(w+1);
			h--;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4596
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;



int main(){
  int n, ma, mb;
  cin >> n >> ma >> mb;
  int a[n], b[n], c[n];
  REP(i,n)cin >> a[i] >> b[i] >> c[i];

  static int dp[41][401][401];
  REP(k,41)REP(i,401)REP(j,401)dp[k][i][j] = INFi;

  REP(k,n)dp[k][0][0] = 0;

  REP(k,n){
    REP(i,401){
      REP(j,401){
        if(i >= a[k] && j >= b[k]){
          dp[k+1][i][j] = min(dp[k][i-a[k]][j-b[k]] + c[k], dp[k][i][j]);
        }else{
          dp[k+1][i][j] = dp[k][i][j];
        }
      }
    }
  }

  int ans = INFi;
  for(int i = 1; i * (max(ma,mb)) <= 400; i++ ){
    // if( dp[n][i*ma][i*mb]!= INFi)cout << "i " << i << endl;
    ans = min(ans, dp[n][i*ma][i*mb]);
  }

  if(ans == INFi){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 25984
def inputNum():
    numList = []
    for i in range(5):
        numList.append(int(input()))
    return numList


def kJudge(k):
    for i in range(0, 4):
        for j in range(i, 5):
            if abs(numList[i] - numList[j]) > k:
                return ":("
    return "Yay!"


numList = inputNum()
k = int(input())
print(kJudge(k))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using namespace atcoder;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

// operate from left !!
struct S{
    ll tento,c0,c1;
};
using F = int;
S op(S a,S b) {return S{a.tento + b.tento + a.c1*b.c0,a.c0 + b.c0,a.c1 + b.c1};}
S e() {return S{0,0,0};}
S mapping(F a,S b){
    if (a == 1) return S{b.c0*b.c1 - b.tento,b.c1,b.c0};
    else return b;
}
F composition(F a,F b){return a^b;}
F id() {return 0;}

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

    int N,Q; cin >> N >> Q;
    vector<S> A(N);
    rep(i,N) {
        int a; cin >> a;
        if (a) A[i] = S{0,0,1};
        else A[i] = S{0,1,0};
    }
    lazy_segtree<S,op,e,F,mapping,composition,id> st(A);
    rep(i,Q) {
        int t,l,r; cin >> t >> l >> r;
        --l;
        if (t == 1) {
            st.apply(l,r,1);
        } else {
            cout << st.prod(l,r).tento << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 21164
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

bool check(int x,int y,int z){
	if(x*x == y*y+z*z) return 1;
	else return 0;
}

int main(){
	int n;
	int a,b,c;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a >> b >> c;
		if(a>=b && a>=c && check(a,b,c)) printf("YES\n");
		else if(b>=c && b>=a && check(b,c,a)) printf("YES\n");
		else if(c>=a && c>=b && check(c,a,b)) printf("YES\n");
		else printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 1116
while true
    n, m = gets.chomp.split.map(&:to_i)
    break if [n, m] == [0, 0]
    arr = gets.chomp.split.map(&:to_i)
    max = nil
    arr.combination(2){|x, y| max = x + y if (max.nil? || max < x + y) && x + y <= m}
    puts max.nil? ? "NONE" : max
end


Measured memory_bytes: 7028
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner st = new Scanner(System.in);
		String s = st.nextLine();
		String copy = s.replace("BC", "X");
		long cou = 0;
		long ans = 0;
		for (int i = 0; i < copy.length(); i++) {
			char a = copy.charAt(i);
			if (a == 'A') {
				cou++;
			} else if (a == 'X') {
				ans += cou;
			} else {
				cou = 0;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 32988
#include <bits/stdc++.h>
using namespace std;
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTG(c) sort((c).begin(),(c).end(),greater<auto>())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
int main(){
 int n, ans=0;
 cin >> n;
 VI a(n);
 REP(i, n){
   cin >> a[i];
   ans ^= a[i];
 }
 if(ans==false)  cout << "Yes" << endl;
 else cout << "No" << endl;
}

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

int main(void)
{
  int n,a[40]={0},o,r,ct; //ctテ」ツ?ッテ」ツつ、テ」ツδ凝」ツδウテ」ツつーテヲツ閉ーテ」ツ?ョテァツョツ。テァツ青?
  string ivent;
  r=0;
  o=0;
  ct=0;
  
  cin >> n;
  while(1) { 
    cin >> ivent;
    if(ivent=="HIT") {
      r++;
      if(r>=4) {
	a[ct]++;
      } 
    } else if(ivent=="HOMERUN") {
      if(r<=3) { 
	a[ct]+=r+1;
      } else {
	a[ct]+=4;
      }
      r=0;

    } else if(ivent=="OUT") {
      o++;
      if(o==3) {
	ct++;
	o=0;
	r=0;      
      }  
    }
    if(ct==n) break;

  }

  for(int i=0;i<n;i++){
    cout << a[i] << endl;
  }
  
}

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

using namespace std;

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

  int M; cin>>M;
  vector<pair<int, int>> DC(M);
  long sum = 0;
  long len = 0;
  for (int i = 0; i < M; i++) {
    long d, c; cin>>d>>c;
    sum += d * c;
    len += c;
  }
  auto res = (sum-1)/9 + len-1;
  cout << res << endl;

  return 0;
}


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

using namespace std;

#define pq priority_queue
#define MZ 1000000007

int num[2][105][2];
int n;
bool ok[105][105];
bool used[105];
int fa[105];

bool found(int x)
{
    for(int i=1;i<=n;i++)
    {
        if(ok[x][i] && !used[i])
        {
            used[i]=1;
            if(!fa[i] || found(fa[i]))
            {
                fa[i]=x;
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int ans=0;
    scanf("%d",&n);
    for(int i=0;i<2;i++)
        for(int j=1;j<=n;j++)
            scanf("%d%d",&num[i][j][0],&num[i][j][1]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            if(num[0][i][0]<num[1][j][0] && num[0][i][1]<num[1][j][1])
                ok[i][j]=1;
        }
    for(int i=1;i<=n;i++)
    {
        memset(used,0,sizeof(used));
        if(found(i))
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  int A[M];
  for (int i=0; i<M; i++) cin >> A[i];
  
  int total = 0;
  for (int i=0; i<M; i++) {
    total += A[i];
  }
  
  int rest = N - total;
  if (rest >= 0) cout << rest << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 3636
n,m = map(int,input().split())
s = [0] * m
c = [0] * m
for i in range(m):
    s[i],c[i] = map(int, input().split())

if n>1:
    ans=[1]+[0]*(n-1)
else:
    ans=[0]
flag = False


for i in range(m):
    if n>2 and s[i]==1 and c[i]==0:
        flag = True
    ans[s[i]-1]=c[i]
    for j in range(i+1,m):
        if s[i]==s[j]:
            if c[i]!=c[j]:
                flag=True

if flag:
    print(-1)
else:
    print("".join(map(str,ans)))

Measured memory_bytes: 3064
import java.util.*;
import java.awt.Point;

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

		while(true){
			int w = sc.nextInt(), h = sc.nextInt();
			if(w==0 && h==0) break;
			char[][] map = new char[h][w];

			for(int i=0;i<h;i++){
				String s = "";
				for(int j=0;j<w;j++) s += sc.next();
				map[i] = s.toCharArray();
			}

			State st = null;
			Queue<State> open = new PriorityQueue<State>();
			Map<State, State> closed = new HashMap<State, State>();

			for(int x=0;x<w;x++){
				if(map[h-1][x] == 'S'){
					open.add(new State(0, new Foot(x, h-1, true)));
					open.add(new State(0, new Foot(x, h-1, false)));
				}
			}

			int ans = Integer.MAX_VALUE;
			while(!open.isEmpty()){
				st = open.poll();
				if(closed.get(st) != null) continue;
				closed.put(st,st);
				if(st.ans(map)){
					ans = st.cost;
					break;
				}
				open.addAll(st.nexts(map));
			}
			if(ans == Integer.MAX_VALUE) System.out.println("-1");
			else System.out.println(ans);
		}
	}
}

class State implements Comparable<State>{
	int cost;
	Foot foot;

	public State(int cost, Foot foot){
		this.cost = cost;
		this.foot = foot;
	}

	public ArrayList<State> nexts(char[][] map){
		ArrayList<State> al = new ArrayList<State>();

		for(int i=0;i<9;i++){
			Foot f = foot.copy();
			int rst = f.move(i,map);

			if(rst != -1){
				int c = cost;
				c += rst;
				al.add(new State(c,f));
			}
		}
		return al;
	}

	public boolean ans(char[][] map){
		return map[foot.p.y][foot.p.x]=='T';
	}

	public int compareTo(State st){
		return this.cost - st.cost;
	}

	public boolean equals(Object o){
		State st = (State)o;
		return this.foot.p.equals(st.foot.p) &&
			this.foot.nextFlg==st.foot.nextFlg;
	}

	public int hashCode(){
		return foot.p.x + foot.p.y;
	}
}

class Foot{
	Point p;
	boolean nextFlg;

	final int[][] dr = new int[][]{{1,-2}, {1,-1}, {1,0}, {1,1}, {1,2},
																 {2,-1}, {2,0}, {2,1},
																 {3,0}};
	final int[][] dl = new int[][]{{-1,-2}, {-1,-1}, {-1,0}, {-1,1}, {-1,2},
																 {-2,-1}, {-2,0}, {-2,1},
																 {-3,0}};

	public Foot(int x, int y, boolean nextFlg){
		this.p = new Point(x,y);
		this.nextFlg = nextFlg;
	}

	public int move(int to, char[][] map){
		int h = map.length;
		int w = map[0].length;

		if(nextFlg){
			nextFlg = !nextFlg;
			this.p.translate(dl[to][0], dl[to][1]);
		}
		else{
			nextFlg = !nextFlg;
			this.p.translate(dr[to][0], dr[to][1]);
		}

		if(p.x<0 || p.x>=w || p.y<0 || p.y>=h || map[p.y][p.x]=='X')
			return -1;
		else if(map[p.y][p.x] == 'S' || map[p.y][p.x] == 'T')
			return 0;
		else
			return map[p.y][p.x] - '0';
	}

	public Foot copy(){
		Foot cp = new Foot(p.x, p.y, nextFlg);
		return cp;
	}
}

Measured memory_bytes: 19000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  ll n; cin>>n;
  vector<ll> a(n);
  rep(i, n) cin>>a.at(i);
  sort(a.begin(), a.end());
  double av=a.at(0);
  rep(i, n) {
    av=(av+a.at(i))/2;
  }
  cout << fixed << setprecision(6);
  cout << av << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>
#define vl vector<LL>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n,m,l;
	cin>>n>>m>>l;
	vl a(m),b(m),c(m);
	vll g(n,vl(n,1LL*mod*mod));
	vll g2(n,vl(n,1LL*mod*mod));
	FOR(i,0,m){
		cin>>a[i]>>b[i]>>c[i];
		a[i]--;b[i]--;
		g[a[i]][b[i]]=g[b[i]][a[i]]=c[i];
	}
	cerr<<"In1"<<endl;
	FOR(i,0,n){
		g[i][i]=g2[i][i]=0;
	}
	FOR(k,0,n){
		FOR(i,0,n){
			FOR(j,0,n){
				g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
			}
		}
	}
	FOR(i,0,n){
		FOR(j,0,n){
			if(l>=g[i][j])g2[i][j]=1;
		}
	}
	FOR(k,0,n){
		FOR(i,0,n){
			FOR(j,0,n){
				g2[i][j]=min(g2[i][j],g2[i][k]+g2[k][j]);
			}
		}
	}
	cerr<<"WF"<<endl;

	int q;
	cin>>q;
	vi s(q),t(q);
	FOR(i,0,q){
		cin>>s[i]>>t[i];
		s[i]--;t[i]--;
		LL ans=g2[s[i]][t[i]]-1;
		if(ans>mod)ans=-1;
		cout<<ans<<endl;
	}

}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,0,n){
        cin>>v[i];
    }
    int ans=0;
    rep(i,0,n){
        int c=1;
        while(v[i]==v[i+1]){
            c++;
            i++;
        }
        ans+=c/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <cctype>
#include <array>
#include <algorithm>
#include <queue>
#include <functional>

char days[7][5] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

void solve() {
    char str[5]; scanf("%s", str);
    int i = std::find_if(days, days+7, [&](const char a[5]) { return !strcmp(a, str); }) - days;
    printf("%d\n", 7-i);
}

int main()
{
		solve();
	

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int pre[200005];


signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int tot=0;
    int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        pre[i]=pre[i-1]+x;
        tot+=x;
    }
    int ans=1e17;
    for(int i=1;i<n;i++)
    {
        ans=min(ans,abs(tot-pre[i]*2));
    }
    cout<<ans;
} 




Measured memory_bytes: 1792
sx, sy, tx, ty = map(int, input().split())
tx -= sx
ty -= sy

r = 'U' * ty + 'R' * tx + 'D' * ty + 'L' * (tx+1) + \
    'U' * (ty+1) + 'R' * (tx+1) + 'DR' + 'D' * (ty+1) + 'L' * (tx+1) + 'U'
print(r)

Measured memory_bytes: 3060
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
#endif


#ifdef _DEBUG
void init_global_C() { }
#else

#endif

int AL;
vi A;
vector<char> op;
bool found;

void dfs(int n, int sum) {
    if (n >= AL) {
        if (sum == 7) found = true;
        return;
    }

    REP(i,2) {
        if (i == 0) {
            op[n-1] = '+';
            dfs(n + 1, sum + A[n]);
        }
        else {
            op[n-1] = '-';
            dfs(n + 1, sum - A[n]);
        }

        if (found) return;
    }
}

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

    string S; cin >> S;
    AL = S.size();
    A = vi(AL);
    REP(i, AL) A[i] = S[i] - '0';

    op = vector<char>(AL - 1);

    int sum = A[0];
    found = false;
    dfs(1, sum);

    cout << A[0];
    REP(i, 3) cout << op[i] << A[i + 1];
    cout << "=7" << endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
a = int(s[:2])
b = int(s[2:])
yymm = 0
mmyy = 0
if 0 < a and a < 13:
  mmyy = 1
if 0 < b and b < 13:
  yymm = 1
if mmyy and yymm:
	print("AMBIGUOUS")
elif mmyy:
  print("MMYY")
elif yymm:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3064
x,n = map(int, input().split())
ans_y = None
if n == 0:
  print(x)
elif n == 1:
  p = list(map(int, input().split()))
  if x == p[0]:
    print(x-1)
  else:
    print(x)
else:
  p = list(map(int, input().split()))
  p.sort()
  m = float("inf")
  if x<p[0] or p[n-1]<x:
    print(x)
  else:
    for y in [y for y in range(p[0]-1,p[n-1]+2) if not y in p]:
      if abs(x-y)<m:
        m = abs(x-y)
        ans_y = y
  if ans_y != None:
    print(ans_y)

Measured memory_bytes: 9216