akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>

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

int n;

int main() {
    cin >> n;

    (n%1000) ? cout << 1000-n%1000 << endl : cout << 0 << endl;
    
    return 0;
}

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

long n,x,y,ans,check,num=1e10;

int main(){
  cin >> n;
  while(n--){
	cin >> x >> y;
    if(x != y)check = 1;
    if(x > y && num > y) num = y;
    ans += x;
  }
  cout << (check ? ans - num : 0) << endl;
}

Measured memory_bytes: 3544
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int N,c[20];

int f(int *c,int l){
	//if(!l)return 0;
	int res=l;
	//cout<<l<<": ";rep(i,20)cout<<c[i]<<(i<19?" ":"\n");
	rep(i,l){
		//cout<<"i"<<i<<" ";
		if(c[i]==-1)break;
		if(i%4<3&&c[i]==c[i+1]){
			//if(l==2)return 0;
			int d[20];
			rep(j,20)d[j]=c[j];
			for(int j=i;j<l-2;j++)d[j]=d[j+2];
			d[l-2]=-1;d[l-1]=-1;
			res=min(res,f(d,l-2));
		}
		if(i/4<4&&c[i]==c[i+4]){
			//if(l==2)return 0;
			int d[20];
			rep(j,20)d[j]=c[j];
			for(int j=i;j<=i+2;j++)d[j]=d[j+1];
			for(int j=i+3;j<l-2;j++)d[j]=d[j+2];
			d[l-2]=-1;d[l-1]=-1;
			res=min(res,f(d,l-2));
		}
		if(i%4<3&&i/4<4&&c[i]==c[i+5]){
			//if(l==2)return 0;
			int d[20];
			rep(j,20)d[j]=c[j];
			for(int j=i;j<=i+3;j++)d[j]=d[j+1];
			for(int j=i+4;j<l-2;j++)d[j]=d[j+2];
			d[l-2]=-1;d[l-1]=-1;
			res=min(res,f(d,l-2));
		}
		if(i%4>0&&i/4<4&&c[i]==c[i+3]){
			//if(l==2)return 0;
			int d[20];
			rep(j,20)d[j]=c[j];
			for(int j=i;j<=i+1;j++)d[j]=d[j+1];
			for(int j=i+2;j<l-2;j++)d[j]=d[j+2];
			d[l-2]=-1;d[l-1]=-1;
			res=min(res,f(d,l-2));
		}
		//if(!res)return 0;
	}
	//cout<<l<<"return "<<res<<endl;
	return res;
}

int main(){
	cin>>N;
	while(N--){
		rep(i,20)cin>>c[i];
		cout<<f(c,20)<<endl;
	}
}

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


int main(){
    while(1){
    
    int H,W;
    cin>>H>>W;
    if(H == 0 && W == 0) break;
    
    for(int i=0;i<H;i++){
        for(int i=0;i<W;i++){
            cout<<"#";    }
        cout<<endl;
        
    }
    cout<<endl;
}
    
  return 0;
}



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

struct node {
  struct node *right;
  int key;
  struct node *left;
};
typedef struct node * NodePointer;

void init(void);
NodePointer makenode(int);
void insert(int,NodePointer);
void preorder(NodePointer);
void inorder(NodePointer);
int find(int,NodePointer);

NodePointer head, tail;

int main(){
  char str[7];
  int n,k;

  init();
  scanf("%d" ,&n);
  while(n--){
    scanf("%s" ,str);

    if(str[0] == 'i'){
      scanf("%d" ,&k);
      insert(k, head);
    }else if(str[0] == 'p'){
      inorder(head->right);
      printf("\n");
      preorder(head->right);
      printf("\n");
    }else{
      scanf("%d" ,&k);
      if(find(k,head->right)){
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }
  }

  return 0;
}

void init(void){
  head=makenode(-1);
  tail=makenode(-1);
  head->right=tail;
  head->left=tail;
}

NodePointer makenode(int k){
  NodePointer x;

  x=malloc(sizeof(struct node));
  x->key = k;
  x->left = x->right = tail;

  return x;
}

void insert(int k, NodePointer p){
  if(k < p->key){
    if(p->left == tail){
      p->left = makenode(k);
    }else{
      insert(k , p->left);
    }
  }else{
    if(p->right == tail){
      p->right = makenode(k);
    }else{
      insert(k , p->right);
    }
  }
}

void preorder(NodePointer node){
  if(node != tail){
    printf(" %d", node->key);
    preorder(node->left);
    preorder(node->right);
  }
}

void inorder(NodePointer node){
  if(node != tail){
    inorder(node->left);
    printf(" %d", node->key);
    inorder(node->right);
  }
}

int find(int k,NodePointer node){
  if(node == tail){
    return 0;
  }

  if(node->key == k){
    return 1;
  }else if(node->key < k){
    return find(k , node->right);
  }else{
    return find(k , node->left);
  }
}


Measured memory_bytes: 14204
#include <bits/stdc++.h>
using namespace std;
#define rint register int
#define all(x) (x).begin(), (x).end()
#define rep(i, f, e) for (rint i = (f); i <= (e); ++i)
#define per(i, f, e) for (rint i = (f); i >= (e); --i)
string ans;
inline void solve(int a, int b, int c, int d, char A, char B) {
	int AB = a + b; 
	int cyc = AB / (b + 1);
	int l = 0, r = a / cyc + 1;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (mid * cyc + (b - mid) / cyc <= a) {
			l = mid + 1;
		} else {
			r = mid - 1;
		}
	}
	if (l) --l;
	r = (b - l) / cyc;
	a -= cyc * l + r;
	rep (i, c, d) {
		if (i <= (cyc + 1) * l) ans += (i % (cyc + 1) ? A : B);
		else if (AB + 1 <= (cyc + 1) * r + i) ans += ((AB - i + 1) % (cyc + 1) ? B : A);
		else ans += i <= (cyc + 1) * l + a ? A : B;
	}
}
int main() {
	int q, a, b, c, d;
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d%d%d", &a, &b, &c, &d);
		ans.clear();
		if (a > b) solve(a, b, c, d, 'A', 'B');
		if (a == b) rep (i, c, d) ans += i & 1 ? 'A' : 'B';
		if (a < b) solve(b, a, a + b - d + 1, a + b - c + 1, 'B', 'A'), reverse(all(ans));
		puts(ans.c_str());
	}
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
typedef struct a{
  double x;
  double y;
}Point;
void koch(int,Point,Point);
int main(){
  Point p1,p2;
  int n;
  p1.x =0;
  p1.y = 0;
  p2.x =100;
  p2.y = 0;
  scanf("%d",&n);
  printf("%f %f\n",p1.x,p1.y);
  koch(n,p1,p2);
   printf("%f %f\n",p2.x,p2.y);

  return 0;
}

void koch(int n, Point p1 , Point p2){
  Point s,t,u;
  if(n ==0 ) return;
  s.x = (2*p1.x+1*p2.x)/3;
  s.y =  (2*p1.y+1*p2.y)/3;
  t.x = (1*p1.x+2*p2.x)/3;
  t.y =  (1*p1.y+2*p2.y)/3;
  u.x = (t.x-s.x)*0.5 - (t.y-s.y)*0.866025+s.x;
  u.y = ((t.x-s.x)*0.866025) + ((t.y-s.y)*0.5)+s.y;
  koch(n-1, p1, s);
  printf("%f  %f\n",s.x,s.y);
  koch(n-1, s, u);
  printf("%f  %f\n",u.x,u.y);
  koch(n-1, u, t);
  printf("%f  %f\n",t.x,t.y);
  koch(n-1, t, p2);
}



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

int main()
{
  string s;
  cin >> s;
  size_t n = s.size();
  bool diff = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i >= j)
        continue;
      if (s[i] == s[j])
        diff = false;
    }
  }
  if (diff)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
cnt = [[0] * W for _ in range(H)]

for i in range(H):
    done = [0] * W
    for j in range(W):
        if maze[i][j] == '#':
            continue
        if done[j]:
            continue
        l = 0
        while j + l < W:
            if maze[i][j+l] == '#':
                break
            l += 1
        for k in range(l):
            cnt[i][j+k] += l
            done[j+k] = 1

for j in range(W):
    done = [0] * H
    for i in range(H):
        if maze[i][j] == '#':
            continue
        if done[i]:
            continue
        l = 0
        while i + l < H:
            if maze[i+l][j] == '#':
                break
            l += 1
        for k in range(l):
            cnt[i+k][j] += l
            done[i+k] = 1
ans = 0
for i in range(H):
    ans = max(ans, max(cnt[i]) - 1)

print(ans)

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

class data
{
public:
    int p, q, c;
    data(int p0, int q0, int c0){
        p = p0;
        q = q0;
        c = c0;
    }
};

void solve(int n, int start, int goal, vector<vector<int> > distance, vector<vector<int> > limit)
{
    vector<bool> easyCheck(n, false);
    queue<int> q;
    q.push(start);
    while(!q.empty()){
        int a = q.front();
        if(!easyCheck[a]){
            easyCheck[a] = true;
            for(int i=0; i<n; ++i){
                if(distance[a][i] > -1)
                    q.push(i);
            }
        }
        q.pop();
    }
    if(!easyCheck[goal]){
        cout << "unreachable" << endl;
        return;
    }

    vector<vector<vector<bool> > > check(n, vector<vector<bool> >(n, vector<bool>(31, false)));
    multimap<double, data> m;
    for(int i=0; i<n; ++i){
        if(distance[start][i] > -1)
            m.insert(make_pair(distance[start][i], data(i, start, 1)));
    }

    for(;;){
        multimap<double, data>::iterator it = m.begin();
        double t = it->first;
        int p = it->second.p;
        int q = it->second.q;
        int c = it->second.c;
        if(p == goal && c == 1){
            printf("%.10f\n", t);
            return;
        }
        m.erase(it);

        if(!check[p][q][c]){
            check[p][q][c] = true;
            for(int i=0; i<n; ++i){
                if(i == p || i == q || distance[i][p] == -1)
                    continue;
                for(int j=-1; j<=1; ++j){
                    if(0 < c+j && c+j <= limit[p][i] && !check[i][p][c+j])
                        m.insert(make_pair(t+distance[p][i]/static_cast<double>(c+j), data(i, p, c+j)));
                }
            }
        }
    }
}

int main()
{
    for(;;){
        int n, m, s, g;
        cin >> n >> m;
        if(n == 0 && m == 0)
            break;
        cin >> s >> g;
        -- s;
        -- g;

        vector<vector<int> > distance(n, vector<int>(n, -1));
        vector<vector<int> > limit(n, vector<int>(n, -1));
        for(int i=0; i<m; ++i){
            int x, y;
            cin >> x >> y;
            -- x;
            -- y;
            cin >> distance[x][y] >> limit[x][y];
            distance[y][x] = distance[x][y];
            limit[y][x] = limit[x][y];
        }

        solve(n, s, g, distance, limit);
    }

    return 0;
}

Measured memory_bytes: 13000
//Tonight's the night and it is going to happen again and again.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define endl "\n"
#define mod 1000000007
char a[1010][1010];
int dp[1010][1010];
int ways(int h,int w)
{
	if(a[h][w]=='#'){return 0;}
	if(h<=0||w<=0){return 0;}
	if(dp[h][w]!=-1){return dp[h][w];}
	if(h==1&&w==1)
	{
		return 1;
	}
	if(a[h-1][w]=='#'&&a[h][w-1]=='#'){return 0;}
    return dp[h][w]=(ways(h-1,w)+ways(h,w-1))%mod;
}
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif
 int h,w;cin>>h>>w;
 for(int i=1;i<h+1;i++)
 {
 	for(int j=1;j<w+1;j++)
 	{
 		dp[i][j]=-1;cin>>a[i][j];
 	}
 }
int k=ways(h,w);
cout<<k<<endl;
/*for(int i=1;i<h+1;i++)
 {
 	for(int j=1;j<w+1;j++)
 	{
 		cout<<dp[i][j]<<" ";
 	}cout<<endl;
 }*/
}

Measured memory_bytes: 8588
import itertools
n = int(input())
b = []
for i in range(n):
  a = int(input())
  c = []
  for j in range(a):
    x, y = map(int, input().split())
    c.append([x,y])
  b.append(c)
g = []
for i in list(itertools.product(range(2) ,repeat = n)):
  flag = True
  for j in range(n):
    if i[j] == 0:
      continue
    for x,y in b[j]:
      if i[x-1] != y:
        flag = False
        break
    if not flag:
      break
  if flag:
    g.append(sum(i))
print(max(g))

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p.at(i);
  
  int cnt = 0;
  rep(i, n) {
    if (p.at(i) != i+1)
      cnt++;
  }      

  cout << (cnt <= 2 ?"YES" :"NO") << "\n";

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);
		int x=stdin.nextInt();
		int a=stdin.nextInt();
		int b=stdin.nextInt();
		if(Math.abs(x-a)>Math.abs(x-b)) {
		System.out.println("B");
		} else {
			System.out.println("A");

		}

	}


}


Measured memory_bytes: 21844
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
 int i,j,n,m;
 scanf("%d%d",&n,&m);

 int a[m+1],b[m+1],path[n+1][n+1],x[n];

 for(i=0;i<n;++i)
  x[i]=i+1;

 for(i=0;i<=n;++i)
  for(j=0;j<=n;++j)
   path[i][j]=0;

 for(i=0;i<m;++i){
  scanf(" %d%d",&a[i],&b[i]);
  path[a[i]][b[i]]=1;
  path[b[i]][a[i]]=1;
 }

 int cnt,ans=0;
 do{
  if(x[0]==1){
   cnt=0;
   for(i=0;i<n-1;++i){
    if(path[x[i]][x[i+1]])
     cnt++;
   }
  if(cnt==n-1)ans++;
  }
 }while(next_permutation(x,x+n));

 printf("%d\n",ans);

return 0;}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;


int main(){
  string S;
  cin >>S;
  int N = S.size();
  Rep(i,N/2){
    if(S.at(i) != S.at(N-1-i) ){
      cout <<"No"; return 0;
    }
  }
  Rep(i,N/2){
    if(S.at(i) != S.at(N/2-1-i) ){
    cout <<"No"; return 0;
    }
  }  

  Rep(i,N/2){
    if(S.at(i+N/2+1) != S.at(N-1-i) ){
    cout <<"No"; return 0;
    }
  }   
  cout <<"Yes";
}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    string s;

    cin >> n >> s;

    for(int i = 0; i < s.size(); i++) {
        s[i] = (char) 'A' + ((s[i] - 'A' + n) % 26);
    }
    cout << s << endl;
}


Measured memory_bytes: 256
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

int32_t main()
{
	IOS;
	int T=1;
	//cin>>T;
	while(T--)
	{
		int n,a,b;
		cin>>n>>a>>b;
		int times=n/(a+b);
		int left=n%(a+b);
		int ans=times*a;
		ans+=min(a,left);
		cout<<ans;
	}

	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
x=list(map(int,input().split()))

mt=5*10**8

for i in range(n-k+1):
  mt=min(mt,2*abs(x[i])+abs(x[i+k-1]),abs(x[i])+2*abs(x[i+k-1]))

if x[0]>0:mt=min(mt,x[k-1])
elif x[-1]<0:mt=min(mt,abs(x[-1-k+1]))
print(mt)
    
  

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    string S;
    cin >> S;

    int cnt=0,cnt2=0;
    rep(i,2,S.size()-1){
        if(S[i]=='C') ++cnt;
    }
    rep(i,0,S.size()) if('A'<=S[i] and S[i]<='Z') ++cnt2;
    if(S[0]=='A' and cnt==1 and cnt2==2) cout << "AC" << endl;
    else cout << "WA" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

int main() {
	int n, k[100005];
	cin >> n;
	vector<pair<int, int>>v;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
		v.push_back(make_pair(k[i], i + 1));
	}
	sort(all(v));

	for (auto i : v) { cout << i.second << " "; }
}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

int N, W;
int v[101], w[101];
int dp[101][10001];

int main() {
	scanf("%d %d", &N, &W);
	rep(i, N) scanf("%d %d", &v[i], &w[i]);
	rep(i, N) rep(j, W + 1) {
		if(j < w[i]) dp[i + 1][j] = dp[i][j];
		else dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
	}
	printf("%d\n", dp[N][W]);
	return 0;
}

Measured memory_bytes: 7120
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
const int INF = 1e9;
const int MOD = 1e9+7;


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll N, K; cin >> N >> K;
    ll ans = 0;
    if(K == 0)
    {
        cout << N*N << endl;
        return 0;
    }
    for(ll b = 1; b <= N; b++)
    {
        ll p = N/b;
        ans += p * max((ll)0, b-K);
        ans += max((ll)0, N%b-K+1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = gets.chomp.to_i

work = []
for i in 1..n do
    work.push(gets.chomp.split(" ").map(&:to_i))
end

work.sort! {|a,b| a[1] <=> b[1]}

possible = true

sum = 0
for i in 1..n do
    sum += work[i-1][0]
    if sum > work[i-1][1]
        possible = false
        break
    end
end

if possible
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 18424
import java.util.Scanner;
//2-3
public class Main{
    public static void main(String [] args){
    	Scanner scan=new Scanner(System.in);
    	int n=scan.nextInt();
    	int k=scan.nextInt();
    	int a=0;
    	int b=0;
    	double c=0;
    	double ans=0;
    	for(int i=1;i<=n;i++){
    		a=i;
    		while(a<k) {
    			a*=2;
    			b++;
    		}
    		c=n*Math.pow(2, b);
    		ans+=1/c;
    		//System.out.println(c);
    		a=0;
    		b=0;
    		c=0;
    	}
    	System.out.println(ans);
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(i) sort((i).begin(),(i).end())
#define INF 2000000000
constexpr ll mod = 1000000007;

int coudp[100001];

int main() {
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<ll>pe(N,K-Q);	
	for (int i = 0;i < Q;++i) {
		int a;
		cin >> a;
		++pe[a - 1];
	}
	for (int i = 0;i < N;++i) {
		if (pe[i] > 0) {
			cout << "Yes" << "\n";
		}
		else {
			cout << "No" << "\n";
		}
	}



	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

int main(){
  int a,b,c,d,e,f,g,h,sumA,sumB;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  scanf("%d %d %d %d",&e,&f,&g,&h);
  sumA=a+b+c+d;
  sumB=e+f+g+h;
  if (sumA>sumB){printf("%d\n",sumA);
  }
  else{printf("%d\n",sumB);}

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#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 INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  ll cnt = 0;
  bool prev;
  REP(i, N) {
    ll tmp;
    cin >> tmp;
    if (i + 1 == tmp) {
      cnt++;
      if (prev) {
        cnt--;
        prev = false;
      } else {
        prev = true;
      }
    } else {
      prev = false;
    }
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

ll g1(ll n, int p) {
    if (n == 0) return 0;
    return n/p + g1(n/p, p);
}

ll g2(ll n, int p) {
    if (n%2 == 1) {
        return g1(n, p) - g2(n-1, p);
    }
    ll res = g1(n/2, p);
    if (p == 2) res += n/2;
    return res;
}

int main(){
    ll n;
    cin >> n;
    ll ans = min(g2(n, 2), g2(n,5));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,M = map(int, lines.pop(0).split(' '))
    X = list(map(int, lines.pop(0).split(' ')))
    if N >= M:
        print(0)
        sys.exit(0)
    X.sort()
    span = []
    for i in range(M-1):
        span.append( X[i+1] - X[i] )
    span.sort()
    for i in range(N-1):
        span.pop(-1)
    print(sum(span))

#
# main
#

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)


Measured memory_bytes: 13976
// ------------------------------------
// Date:2018/ 3/15
// Problem:AGC 014 CookieExchanges a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

int solve(int a, int b, int c)
{
  if (not(a % 2 == 0 and b % 2 == 0 and c % 2 == 0)) return 0;
  if (a == b and b == c) return -1;
  return solve((a + b) / 2, (b + c) / 2, (a + c) / 2) + 1;
}

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

  int a, b, c;
  cin >> a >> b >> c;
  int ans = solve(a, b, c);
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,d,i,x[200000],y[200000],count=0;
cin>>n>>d;
  for(i=0;i<n;i++){
cin>>x[i]>>y[i];
    if(x[i]*x[i]+y[i]*y[i]<=d*d){
      count++;
    }
  }
    cout<<count<<endl;
}
    


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

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

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int h, w;

bool isIn(int x, int y){
    return 0 <= x && x < h && 0 <= y && y < w;
}

int main(){
    int t;
    cin >> t;
    for(int q=0; q < t; q++){
        if(q) cout << endl;
        string s = "^><v";
        int direction, mx, my;
        int dx[4] = {1, 0, 0, -1};
        int dy[4] = {0, 1, -1, 0};
        cin >> h >> w;
        string field[h];
        for(int i=0; i < h; i++){
            cin >> field[i];
            for(int j=0; j < field[i].size(); j++) if(s.find(field[i][j]) != -1){mx = i; my = j, direction = s.find(field[i][j]); field[i][j] = '.';}
        }
        int n; cin >> n;
        string c; cin >> c;

        for(int i=0; i < c.size(); i++){
            if(c[i] == 'U'){
                direction = 0;
                if(isIn(mx-1, my) && field[mx-1][my] == '.')mx--;
            }
            if(c[i] == 'D'){
                direction = 3;
                if(isIn(mx+1, my) && field[mx+1][my] == '.')mx++;
            }
            if(c[i] == 'L'){
                direction = 2;
                if(isIn(mx, my-1) && field[mx][my-1] == '.')my--;
            }
            if(c[i] == 'R'){
                direction = 1;
                if(isIn(mx, my+1) && field[mx][my+1] == '.')my++;
            }
            if(c[i] == 'S'){
                for(int j=1; ; j++){
                    if(!isIn(mx-j*dx[direction], my+j*dy[direction])) break;
                    if(field[mx-j*dx[direction]][my+j*dy[direction]] == '#') break;
                    if(field[mx-j*dx[direction]][my+j*dy[direction]] == '*'){
                        field[mx-j*dx[direction]][my+j*dy[direction]] = '.';
                        break;
                    }
                }
            }
        }
        field[mx][my] = s[direction];
        for(int i=0; i< h; i++) cout << field[i] << endl;
    }
}

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

int a[200005];
int d[200005];

int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    if (n==0)  //0个元素特判一下
    {
        printf("0\n");
        return 0;
    }
    d[1]=a[1];  //初始化
    int len=1;
    for (int i=2;i<=n;i++)
    {
        if (a[i]<=d[len]) d[++len]=a[i];  //如果可以接在len后面就接上
        else  //否则就找一个最该替换的替换掉
        {
            int j=lower_bound(d+1,d+len+1,a[i])-d;  //找到第一个大于它的d的下标
            d[j]=a[i];
        }
    }
    printf("%d\n",len);
    return 0;
}


Measured memory_bytes: 1792
S = input()
total_w = [0]*len(S)
cnt_w = S.count('W')

cnt = 0
for i in range(len(S)):
    if S[i]=='W':
        cnt += 1
    total_w[i] = cnt_w - cnt

ans = 0
for i in range(len(S)):
    if S[i]=='B':
        ans += total_w[i]

print(ans)

Measured memory_bytes: 11240
using System;
using System.Collections.Generic;

class Program {
    static int Main(string[] args) {

        string v = Console.ReadLine();
        int n = int.Parse(v);

	
	    for (int i = 1; i <= n; i++) {
		    int x = i;
		    if (x % 3 == 0) {
			    Console.Write(" ");
			    Console.Write(i);
                continue;
		    }

            while (true) {
                if (x % 10 == 3) {
                    Console.Write(" ");
                    Console.Write(i);
                    break;
                }

                x /= 10;
                if (x == 0) {
                    break;
                }
            }
	    }

        Console.WriteLine("");

        return 0;
    }
}

Measured memory_bytes: 9212
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=gets.chomp
if S=="ABC"
    puts "ARC"
else
    puts "ABC"
end

Measured memory_bytes: 14212
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

int main() {
  size_t n, wmax;
  std::cin >> n >> wmax;

  std::vector<size_t> w(n);
  std::vector<size_t> v(n);
  for (size_t i = 0; i < n; ++i) std::cin >> w[i] >> v[i];

  std::vector<size_t> dp1(wmax + 1, 0);
  std::vector<size_t> dp2(wmax + 1, 0);

  for (size_t i = 1; i <= n; ++i) {
    const auto wi = w[i - 1];
    const auto vi = v[i - 1];
    for (size_t j = 0; j <= wmax; ++j) {
      dp1[j] = std::max(dp1[j], dp2[j]);
      if (j >= wi) dp1[j] = std::max(dp1[j], dp2[j - wi] + vi);
    }
    // dp2 = dp1;
    std::copy(dp1.begin(), dp1.end(), dp2.begin());
    std::fill(dp1.begin(), dp1.end(), size_t(0));
  }

  std::cout << dp2[wmax] << std::endl;
}


Measured memory_bytes: 1792
from math import sqrt
from sys import stdin
input = stdin.buffer.readline

def main():
    xs, ys, xt, yt = map(int, input().split())
    n = int(input())

    xyr = [(0, 0, 0)] * (n+2)
    xyr[0] = (xs, ys, 0)
    xyr[1] = (xt, yt, 0)
    for i in range(2, n+2):
        x, y, r = map(int, input().split())
        xyr[i] = (x, y, r)

    # dijkstra
    inf = float('inf')
    dic = {i: inf for i in range(n+2)}
    dic[0] = 0.0
    while True:
        ind, cost = min(dic.items(), key=lambda x: x[1])
        dic.pop(ind)

        if ind == 1:
            print(cost)
            break

        x, y, r = xyr[ind]
        for i, old_cost in dic.items():
            xi, yi, ri = xyr[i]
            new_cost = max(sqrt((x-xi)*(x-xi)+(y-yi)*(y-yi))-(r+ri), 0.0) + cost
            if new_cost < old_cost:
                dic[i] = new_cost

main()


Measured memory_bytes: 74540
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		vector<char> c(8);
		for(int i = 0; i < 8; ++i)
		{
			cin >> c[i];
		}
		sort(c.begin(), c.end());
		char Min[9];
		for(int i = 0; i < 8; ++i)
		{
			Min[i] = c[i];
		}
		sort(c.begin(), c.end(), greater<char>());
		char Max[9];
		for(int i = 0; i < 8; ++i)
		{
			Max[i] = c[i];
		}
		int a = atoi(Min);
		int b = atoi(Max);
		cout << b - a << endl;		
	}
}

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

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>

#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 dp[22][50010];

int main(){

   REP(i,22){
       REP(j,50010){
           dp[i][j] = INF;
       }
   }

    int n,m;
    cin >> n >> m;
    vector<int> c(m,0);
    REP(i,m){
        cin >> c[i];
        //cout << c[i] << endl;
    }

    //dp[i][j]:i番目までを使って総和がjとなるような枚数の最小

    dp[0][0] = 0;//0番目までで総和が0の枚数
    

    for(int i = 1;i <= c.size();i++){
        //cout << c[i-1] << endl;
        for(int j = 0;j <= n;j++){
            
            if(c[i-1] > j){//c[i]を使えない場合
                dp[i][j] = dp[i-1][j];
                //cout << "a" << " " << j << " " << dp[i][j] << endl;
            }else{//c[i]を使う場合
                dp[i][j] = min(dp[i-1][j],dp[i][j-c[i-1]]+1);
                //cout << "b" << " " << j << " " << dp[i][j] << endl;
            }
        }
        //cout << endl;
    }

    cout << dp[c.size()][n] << endl;   

    return 0;
}


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

int main() {
    int n;
    ll cnt=0,a;
    cin >> n;
    vector<int>V;
    for (int i=0;i<n;i++) {
        cin >> a;
        V.push_back(a);
        V.push_back(a);
    }

    sort(V.begin(),V.end());
    reverse(V.begin(),V.end());
    for (int i=1;i<n;i++) {
        cnt+=V[i];
    }
    cout << cnt;

}


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

int main(){
    string S, T;
    cin >> S >> T;

    //答えansを仮置きする
    //これが十分に大きくないと不正解となる
    //この値なら絶対に正しい答えが出る、という値を仮置きすること
    int ans = T.size();
    for(int start = 0; start <= S.size() - T.size(); start++){
        int diff = 0;
        for(int i = 0; i < T.size(); i++){
            if(T[i] != S[start + i]){
                diff++;
            }
        }
        ans = min(ans, diff);
    }

    cout << ans << endl;

    return 0;
}

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

using ll = long long;
const int INF = 1<<29;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var)  std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(int i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(int i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


int main() {

	int N,A,B,C;
	cin>>N>>A>>B>>C;
	vector<int> a(N,0);
	rep(i,N){
		cin>>a[i];
	}
	int minval=INF;
	//0->A, 1->B, 2->C, 3->使わない
	vector<int> pattern(N+1,0);
	while(1){
		//元になる竹が３つ全てある場合のみコスト計算
		vector<int> takecount(4,0);
		vector<int> takelength(4,0);
		rep(i,N){
			takecount[pattern[i]]++;
			takelength[pattern[i]]+=a[i];
		}
		if(takelength[0]>0 && takelength[1]>0 && takelength[2]>0){
			int t=0;
			t+=10*(takecount[0]+takecount[1]+takecount[2]-3);//合成
			t+=abs(A-takelength[0]) + abs(B-takelength[1]) + abs(C-takelength[2]);//延長縮小
			chmin(minval,t);
		}

		//カウントアップ
		pattern[0]++;
		rep(i,N){
			if(pattern[i]==4){
				pattern[i]=0;
				pattern[i+1]++;
			}
		}
		if(pattern[N]>0)break;
	}

	p(minval);
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=190;
int a[N][N];
int f[N][N][N][17];
int n,m;
int main(){
	cin>>n>>m;
	for (int i=1;i<=n;i++){
		scanf("\n");
		for (int j=1;j<=m;j++)
			a[i][j]=getchar()=='#';
	}
	for (int i=n;i>=1;i--){
		for (int j=1;j<=m;j++){
			if (a[i][j]!=a[i+1][j]||i==n)f[i][j][j][0]=i;
			else f[i][j][j][0]=f[i+1][j][j][0];
		}
		for (int j=1;j<=m;j++){
			for (int k=j+1;k<=m;k++){
				if (a[i][k]!=a[i][k-1])f[i][j][k][0]=i-1;
				else f[i][j][k][0]=min(f[i][j][k-1][0],f[i][k][k][0]);
			}
		}
	}
	if (f[1][1][m][0]==n){
		cout<<0<<endl;
		return 0;
	}
	for (int h=1;h<=16;h++){
		for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		for (int k=j;k<=m;k++){
			f[i][j][k][h]=f[min(f[i][j][k][h-1]+1,n)][j][k][h-1];
			int m=j;
			for (int u=1<<7;u;u>>=1){
				if (m+u>=k)continue;
				if (f[i][j][m+u][h-1]>=f[i][m+u+1][k][h-1])
					m+=u;
			}
			f[i][j][k][h]=max(f[i][j][k][h],
			max(min(f[i][j][m][h-1],f[i][m+1][k][h-1]),min(f[i][j][m+1][h-1],f[i][m+2][k][h-1])));
		}
		if (f[1][1][m][h]==n){
			cout<<h<<endl;
			return 0;
		}
	}
	cout<<"oops"<<endl;
}

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

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

    int n;
    cin >> n;

    int count = 0;
    for(int i=1; i <= n; i++) {
      int num;
      cin >> num;
      if(i % 2 != 0 && num % 2 != 0)
        count++;
    }
    cout << count;
}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(){
    string S, T;
    
    cin >> S >> T;
    
    int x=0;
    
    int al=S.size();
    
    for(int i=0; i<=al; i++){
        if(S[i]!=T[i]){
        x=x+1;
    }}
    cout << x << endl;
    
}

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

int main() {
  
  int n; cin >> n;
  
  int table[n][26];
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      table[i][j] = 0;
    }
  }
  
  for (int i = 0; i < n; i++) {
    string S; cin >> S;
    
    for (int j = 0; j < S.size(); j++) {
      char tmpC = S.at(j);
      int tmpN = tmpC - 'a';
      table[i][tmpN]++;
    }
  }
  
  vector<int> ans(26, 51);
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      ans[j] = min(ans[j], table[i][j]);
    }
  }
  
  for (int i = 0; i < 26; i++) {
    int tmpN = ans[i];
    char tmpC = i + 'a';
    for (int j = 0; j < tmpN; j++) cout << tmpC;
  }
  
  cout << endl;
  
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    sort(v.begin(),v.end());
    double ans = v[0];
    rep1(i,n){
        ans = (ans + v[i]) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <random>

using namespace std;

int main(){
    string a,b;
    cin >> a >> b;
    string output = "EQUAL";
    if(a.size() == b.size()){
        for(int i = 0;i<(int)a.size();i++){
            int aa = (char)a[i] - '0'; int bb = (char)b[i] - '0';
            if(aa == bb){
                continue;
            } else if(aa > bb){
                output = "GREATER";
            } else {
                output = "LESS";
            }
            break;
        }
    } else if (a.size() > b.size()){
        output = "GREATER";
    } else {
        output = "LESS";
    }
    cout << output << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll n; cin >> n;
  Vll a(n); 
  cin >> a;
  sort(all(a));
  reverse(all(a));

  ll ans = 0;
  ans += a[0];
  int j = 1;
  rep2(i, 1, n-1) {
    ans += a[j];
    if ((i&1) == 0) {
      ++j;
      // cout << j << '\n';
    }
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4776
#include<iostream>
#include<algorithm>
typedef long long lint;
using namespace std;

string str;
bool c[15];
lint ans;

void dfs(int d)
{
	if(d==str.size()-1)
	{
		lint tmp=0;
		for(int i=0;i<str.size();i++)
		{
			tmp*=10;
			tmp+=(str[i]-'0');
			if(c[i]==true)
			{
				ans+=tmp;
				tmp=0;
			}
		}
		return;
	}
	
	c[d]=true;
	dfs(d+1);
	c[d]=false;
	dfs(d+1);
	return;
}

int main()
{
	cin >> str;
	c[str.size()-1]=true;
	dfs(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()

vector<vector<ll>> T(100000);
queue<vector<ll>> ue;

int main() {
	int N, M;
	cin >> N >> M;
	ll a, b, c;
	for (int i = 0;i < M;i++) {
		cin >> a >> b;
		a--;b--;
		T[a].push_back(b);
		T[b].push_back(a);
	}
	cin >> M;
	vector<int> color(M);
	vector<vector<pair<ll, ll>>> query(11);
	vector<vector<ll>> ans(11, vector<ll>(N, -1));
	for (int i = 0;i < M;i++) {
		cin >> a >> b >> c;
		a--;
		color[i] = c;
		query[b].push_back({ i,a });
	}
	for (int k = 0;k < 11;k++) {
		int ss = query[k].size();
		sort(all(query[k]));
		for (int j = ss - 1;j >= 0;j--) {
			b = query[k][j].first;
			a = query[k][j].second;
			if (ans[k][a] < b)
				ue.push({ a,b,k });
		}
		while (!ue.empty()) {
			a = ue.front()[0];
			b = ue.front()[1];
			if (ans[k][a] < b) {
				ans[k][a] = b;
				c = ue.front()[2];
				if (c) {
					int saz = T[a].size();
					for (int i = 0;i < saz;i++)
						ue.push({ T[a][i],b,c - 1 });
				}
			}
			ue.pop();
		}
	}
	for (int i = 0;i < N;i++) {
		c = ans[0][i];
		for (int j = 1;j < 11;j++)
			c = max(ans[j][i], c);
		if (c == -1)
			cout << 0 << endl;
		else
			cout << color[c] << endl;
	}
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    
    long a, b, c, k;
    cin >> a >> b >> c >> k;
    
    if (k < a)
    {
        // All a
        cout << k << endl;
        return 0;
    }
    else // k - a > 0
    {
        // a = a
        if(k - a <= b)
        {
            b = k - a;
            c = 0;
        }
        else // k - a > b
        {
            //b = b;
            c = k - a - b;
        }
    }
    
    cout << a - c << endl;
    
    return 0;
    
    /*
    if(k<a)
    {
        cout << a << endl;
        return 0;
    }
    
    // A = A
    // Determine B
    if(k-a >= 0)
    {
        b = min(k-a, b);
    }

    // Determine C
    if(k-a-b >= 0)
    {
        c = min(k-a-b, c);
    }
    
    
    //cout << a << b << c << k << endl;
    cout << a - c << endl;
    
    return 0;
     */
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,i,left=0,right=0;
	char s[101];
	cin >> n >> s;
	for(i=0;i<n;i++){
		if(s[i]=='('){
			left++;
		}
		else if(s[i]==')'){
			if(left>0)left--;
			else right++;
		}
	}
//	printf("right=%d left=%d\n",right,left);
	for(i=0;i<right;i++)cout << '(';
	cout << s;
	for(i=0;i<left;i++)cout << ')';
	cout << endl;
	return 0;
}
	

Measured memory_bytes: 256
N, t = map(int, input().split())
C=[0]*N
T=[0]*N
cost = 1001
for i in range(N):
  C[i], T[i] = map(int, input().split())
  if T[i] <= t:
    cost = min(cost, C[i])
print(cost if cost != 1001 else 'TLE')  

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#define F first
#define S second


using namespace std;

typedef pair<string,int> P; 
bool cmp(const P &p,const P &q){
  return p.S > q.S;
}

int main(){
  int n;
  bool first = true;
  while(cin >> n && n){
    if(!first)cout << endl;
    string s;
    first = false;  
    vector<P> vec;
    int a,b,c;
    for(int i=0;i<n;i++){
    cin >> s >> a >> b >> c;
    vec.push_back(P(s,a*3+b*0+c*1));
    }

    stable_sort(vec.begin(),vec.end(),cmp);
    //reverse(vec.begin(),vec.end());
    for(int i=0;i<n;i++){
      cout << vec[i].F << "," << vec[i].S << endl;
    }
 
  }
  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
int a[10];
int vis[1000010];
int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k))
    {
        memset(vis,0,sizeof(vis));
        for(int i=0;i<k;i++)
        {
            scanf("%d",&a[i]);
            vis[a[i]]=1;
        }
        for(int i=n;i<=100000000;i++)
        {
            int ans;
            int num=i;
            bool flag=false;
            while(num)
            {
                ans=num%10;
                num/=10;
                if(vis[ans])
                {
                    flag=true;
                    break;
                }
            }
            if(!flag)
            {
                cout<<i<<endl;
                break;
            }
        }
    }
}


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

if not x in p:
    print(x)
    exit()
up = x + 1
down = x - 1
while True:
    if not down in p:
        print(down)
        exit()
    elif not up in p:
        print(up)
        exit()
    up += 1
    down -= 1

Measured memory_bytes: 9192
def solve():
	h,w,a,b = map(int, input().split())
	mx = max(h,w)
	mod = 10**9+7
	fac = [1]*(h+w+1)
	for i in range(1,h+w+1):
		fac[i]=fac[i-1]*i%mod
	rev = [1]*(mx+1)
	rev[-1] = pow(fac[mx], mod-2, mod)
	for i in range(mx-1, -1, -1):
		rev[i] = rev[i+1]*(i+1)%mod
	const = rev[h-a-1]*rev[a-1]%mod
	ans = sum(fac[h-a+i-1]*rev[i]*fac[a+w-2-i]*rev[w-i-1]%mod for i in range(b,w))
	print(ans*const%mod)

if __name__=="__main__":solve()

Measured memory_bytes: 14836