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


const int MAX_N = 1 << 17;
int n, dat[2*MAX_N-1];

void init(int n_) {
  n = 1;
  while(n < n_) n *= 2;

  for(int i=0;i<2*n-1;i++) dat[i] = INT_MAX;
}

void update(int k, int a) {
  k += n - 1;
  dat[k] = a;
  while(k > 0) {
    k = (k-1)/2;
    dat[k] = min(dat[k*2+1], dat[k*2+2]);
  }
}

int query(int a, int b, int k, int l, int r) {
  if(r <= a || b <= l) return INT_MAX;

  if(a <= l && r <= b) return dat[k];
  else {
    int vl = query(a, b, k*2+1, l, (l+r)/2);
    int vr = query(a, b, k*2+2, (l+r)/2, r);
    return min(vl, vr);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n_, q;
  cin >> n_ >> q;
  init(n_);
  for(int i=0;i<q;i++) {
    int c, xi, yi;
    cin >> c >> xi >> yi;
    if(c) {
      int ans = query(xi, yi+1, 0, 0, n);
      cout << ans << endl;
    } else {
      update(xi, yi);
    }
  }
}



Measured memory_bytes: 4152
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

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

	int n, m, k;
	cin >> n >> m >> k;
	vector<int> a(n);
	vector<int> b(m);
	for (auto &t : a) {
		cin >> t;
	}
	for (auto &t : b) {
		cin >> t;
	}
	vector<int> psa(n + 1);
	vector<int> psb(m + 1);
	for (int i = 0; i < n; i++) {
		psa[i + 1] = psa[i] + a[i];
	}
	for (int i = 0; i < m; i++) {
		psb[i + 1] = psb[i] +  b[i];
	}
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		if (psa[i] > k) continue;
		int cnt_less = upper_bound(psb.begin(), psb.end(), k - psa[i]) - psb.begin();
		ans = max(ans, i + cnt_less - 1);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=999999999;

int main() {
   int A,B,C;
   cin>>A>>B>>C;
   if(A==B){cout<<C<<endl;}
   if(C==B){cout<<A<<endl;}
   if(A==C){cout<<B<<endl;}
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const ll mod = 1000000007;
const int N = 81;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
ll n, x, d;
int main() {
	while(~scanf("%lld%lld%lld",&n, &x, &d)) {
		if(!d) {
			if(!x) printf("1\n");
			else printf("%lld\n",n+1ll);
		} else {
			map<int, ll> _map;
			ll ret = 0;
			if(d < 0) x = -x, d = -d;
			ll mn = 0, mx = 0;
			vector< pair<ll,pll> > cur;
			rep(k, 1, n + 1) {
				mn += k - 1;
				mx += n - k;
				ll kx = k * x;
				if(kx < 0) {
					ll yushu = kx % d;
					ll be = kx / d;
					ll l = be + mn;
					ll r = be + mx;
					cur.pb({yushu,{l,r}});
				} else {
					ll yushu = (kx + mn * d) % d;
					ll l = (kx + mn * d) / d;
					ll r = (kx + mx * d) / d;
					cur.pb({yushu,{l,r}});
				}
			}
			cur.pb({0,{0,0}});
			sort(all(cur));
			rep(i, 0, sz(cur)) {
				ll yushu = cur[i].fi;
				ll l = cur[i].se.fi, r = cur[i].se.se;
				int t;
				if(!_map.count(yushu)) {
					ret += (r - l + 1);
					_map[yushu] = r + 1;
				} else {
					ret += max(0ll, r - max(_map[yushu], l) + 1);
					_map[yushu] = max(_map[yushu], r + 1);
				}
			}
			printf("%lld\n", ret);
		}
	}
    return 0;
}


Measured memory_bytes: 18028
first_set_count = int(input());
first_set = [int(n) for n in input().split()];
second_set_count = int(input());
second_set = [int(n) for n in input().split()];

def binary_search(num, s, start, end):
    while start < end:
        mid = (end + start) // 2;
        if num == s[mid]:
            return True;
        elif num > s[mid]:
            start = mid + 1;
        else:
            end = mid;
    return False;

count = 0;
for num in second_set:
    if binary_search(num, first_set, 0, len(first_set)):
        count += 1;
print(count);



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

#define int long long int
#define ff first
#define ss second
#define pb push_back


int bexp(int a, int b)
{
	int res = 1;

	while (b)
	{
		if (b & 1) res = (res * a);

		a = (a * a); 
		b >>= 1;
	}
	return res;
}

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

#define N 100010
#define MOD 1000000007

int ncr(int n, int r)
{
	if (n < r)
		return 0;
	else if (r == 0)
		return 1;
	else if (r == 1)
		return n;
	else if (r == 2)
		return (n * (n - 1)) / 2;
	else
		return (n * (n - 1) * (n - 2)) / 6;
}

string s;
int r, n;

int solve(int m, int r)
{
	int ans = ncr(m - 1, r - 1) * bexp(9, r - 1) * (s[0] - '0' - 1) + ncr(m - 1, r) * bexp(9, r);
	// cout << ans << "\n";
	
	int p = 1;
	int i = 0;
	for (i = 0; i < r - 1; ++i)
	{
		while (p < n && s[p] == '0')
			p++;

		if (p == n)
			break;
		ans += ncr(n - p - 1, r - i - 2) * bexp(9, r - i - 2) * (s[p] - '0' - 1) + ncr(n - p - 1, r - i - 1) * bexp(9, r - i - 1);
		// cout << ans << "\n";
		p++;
	}
	if (i == r - 1)
		ans++;
	return ans;
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(10);

	cin >> s >> r;
	
	n = s.size();

	cout << solve(n, r);
	return 0;
}

Measured memory_bytes: 256
import numpy as np


n = int(input())
a = [i for i in list(map(int, input().split()))]
b = [i for i in list(map(int, input().split()))]

ans = 0
for i in range(n):
  ans += b[i] if a[i] > b[i] else a[i]
  if b[i] - a[i] > 0:
    num_enemy_next = max(a[i+1]-(b[i] - a[i]), 0)
    ans += a[i+1] - num_enemy_next
    a[i+1] = num_enemy_next
print(ans)

Measured memory_bytes: 27144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int mn = min(X, Y);
    int sum = mn * min(A+B, C*2);
    X -= mn, Y -= mn;
    if (X == 0) {
        sum += min(Y*B, Y*C*2);
    } else {
        sum += min(X*A, X*C*2);
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	for (int i = 1; i < N; ++i) {
		string X = S.substr(0, i);
		string Y = S.substr(i, N - i);

		int Dx[26] = { 0 };
		int Dy[26] = { 0 };
		REP(x, X.size()) {
			Dx[(int)X[x] - (int)'a'] = 1;
		}
		REP(y, Y.size()) {
			Dy[(int)Y[y] - (int)'a'] = 1;
		}
		int cnt = 0;
		REP(d, 26) {
			if (Dx[d] == 1 && Dy[d] == 1)cnt++;
		}
		ans = max(ans, cnt);
	}
	OUT(ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int N, K;
    scanf("%d%d", &N, &K);

    int i;
    double p[200000+1] = {0};
    p[0] = 0.0;
    for( i = 1; i <= N; i++ ){
        scanf("%lf", &p[i]);
        p[i] = p[i-1] + (p[i]+1)/2;
        //printf("%.6f ", p[i]);
    }

    float x=0;
    double ans=0;
    for( i = 1; i <= N-(K-1); i++ ){
        x = p[i+(K-1)] - p[i-1];
        if( x > ans ) ans = x;
    }

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

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main(){
  int n;
  string s;
  cin >> n;
  int i;
  long long a[5]={},ans=0;
  for(i=0;i<n;i++){
    cin >> s;
    if(s[0]=='M')a[0]++;
    if(s[0]=='A')a[1]++;
    if(s[0]=='R')a[2]++;
    if(s[0]=='C')a[3]++;
    if(s[0]=='H')a[4]++;
  }
  int j,k;
  for(i=0;i<3;i++){
    for(j=i+1;j<4;j++){
      for(k=j+1;k<5;k++){
        ans+=a[i]*a[j]*a[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;
const ll MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}


long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve(long long N, long long K){
  COMinit();
  for(ll i=1; i<=K; i++) 
    std::cout << COM(N-K+1, i)*COM(K-1, i-1) % MOD << std::endl;
}

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



Measured memory_bytes: 119808
using System;

namespace abc113A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C = A + (B / 2);
            Console.WriteLine(C);
        }
    }
}


Measured memory_bytes: 11092
import bisect
n=int(input())
l=list(map(int,input().split()))
dic={}
ans=0
for i in range(n):
    a=i-l[i]
    if a in dic.keys():
       dic[a].append(i)
    else:
       dic[a]=[i]
for i in range(n):
  a=i+l[i]
  if a in dic.keys():
    s=dic[a]
  else:
    continue
  k=bisect.bisect_right(s,i)
  ans+=(len(s)-k)
print(ans)

Measured memory_bytes: 60412
#include "stdio.h"

int main(void){
  int P,Q,R;
  scanf("%d %d %d",&P,&Q,&R);
  
  int idou[3]={P+Q,R+Q,R+P};
  int min=P+Q;
  
  for(int i=0; i<3; i++){
  	if(idou[i]<min)
      min=idou[i];
  }
  printf("%d",min);
}


Measured memory_bytes: 128
n,l,t=map(int,input().split())
inf=[]
s=0
for _ in range(n):
   x,y=map(int,input().split())
   if y==1:
       x+=t
   else:
       x-=t
   inf.append(x%l)
   s+=x//l
inf.sort()
for i in range(n):
    print(inf[(i+s)%n])

Measured memory_bytes: 55000
from collections import deque
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
edge = [[] for _ in range(N)]

for _ in range(M):
	u, v = map(int, input().split())
	u -= 1
	v -= 1
	edge[u].append(v)
	
S, T = map(int, input().split())
S -= 1
T -= 1
has_reached = [[-1] * N for _ in range(3)]
q = [deque() for _ in range(3)]
q[0].append(S)
has_reached[0][S] = 0
i = 0

while q[0] or q[1] or q[2]:
	if q[i]:
		now_node = q[i].popleft()
		for next_node in edge[now_node]:
			if has_reached[i - 2][next_node] < 0:
				has_reached[i - 2][next_node] = has_reached[i][now_node] + int(i == 0)
				q[i - 2].append(next_node)
			
	i = (i + 1) % 3
	
print(has_reached[0][T])
'''
for i in range(3):
	print(has_reached[i])
'''

Measured memory_bytes: 59772
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N);
  rep(i,0,N) {
    cin >> A[i];
  }
  sort(all(A));
  reverse(all(A));
  i64 ans = 0;
  i64 j = 1;
  i64 cnt = 0;
  ans += A[0];
  rep(i,2,N) {
    cnt++;
    ans += A[j];
    if(cnt == 2) {
      cnt = 0;
      j++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4840
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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

if a+b < c:
    left = 4*a*b
    right = (c-a-b)**2
    if left < right:
        print('Yes')
    else:
        print('No')
else:
    print('No')



Measured memory_bytes: 3316
n = int(input())
a = list(map(int, input().split()))
count = 0
counter = 0

for i in range(len(a)-1):
    if i == len(a)-2 and a[i]==a[i+1]:
        count += int((i+2-counter)//2)
    if a[i]!=a[i+1]:
        count += int((i+1-counter)//2)
        counter = i + 1

print(count)      

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;


int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);
	
	int N, L; scanf("%d%d", &N, &L);
	int sum = N*(N - 1) / 2 + N*L;
	int diff=100000000, ret;
	for (int i = 0; i < N; i++){
		int pie = sum - (i + L);
		if (abs(pie - sum) < diff){
			diff = abs(pie - sum);
			ret = pie;
		}
	}

	printf("%d", ret);

	//if (-N < L < 0){
	//	printf("%d", sum + L*N);
	//}
	//else if (L <= -N){
	//	printf("%d",sum )
	//}
	//else if (L >= 0){

	//}



	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 128
'use strict';

const main = (input) => {
    const nums = input.split(' ');
    const x1 = parseInt(nums[0], 10);
    const y1 = parseInt(nums[1], 10);
    const x2 = parseInt(nums[2], 10);
    const y2 = parseInt(nums[3], 10);
    const xdiff = x2 - x1;
    const ydiff = y2 - y1;
    const x3 = x2 - ydiff;
    const y3 = y2 + xdiff;
    const x4 = x3 - xdiff;
    const y4 = y3 - ydiff;
    console.log(x3 + ' ' + y3 + ' ' + x4 + ' ' + y4);
};

const isTest = false;

if (isTest) {
    main('0 0 0 1');
    main('2 3 6 6');
    main('31 -41 -59 26');
} else {
    main(require('fs').readFileSync('/dev/stdin', 'utf8'));
}

Measured memory_bytes: 21064
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a,b,x = LI()
    if a > x or a+b < x:
        return 'NO'


    return 'YES'


print(main())




Measured memory_bytes: 7752
import java.util.*;

public class Main {
  
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();

    int maxDiv = 1;
    for (int i = 1; i <= Math.sqrt(M); i++) {
      if (M % i == 0) {
        int d1 = i;
        int d2 = M/i;
        if (M/d1 >= N) {
          maxDiv = Math.max(maxDiv, d1);
        }
        if (M/d2 >= N) {
          maxDiv = Math.max(maxDiv, d2);
        }
      }
    }
    System.out.println(maxDiv);
  }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int min(int,int);
int main()
{
	int n,i;
	cin>>n;
	int p=n-1;
	int a[p];
	for(i=0; i<p; i++)
	cin>>a[i];
	if(p==1)
	cout<<a[0]*2;

	if(p>1)
	{
		int s=0; 
		for(i=0; i<p-1; i++)
		s+=min(a[i],a[i+1]);
		s+=a[p-1]+a[0];
		cout<<s;
	}
	
}
int min(int a,int b)
{
	if(a>=b)
	return b;
	else return a;
	
}

Measured memory_bytes: 256
sel='E'
#A
if sel=='A':
    N,M=map(int,input().split())
    ans=0
    ans+=M*(M-1)//2
    ans+=N*(N-1)//2
    print(ans)

#B
if sel=='B':
    def ispal(s):
        for i in range(len(s)//2+1):
            if s[i]!=s[-(i+1)]:
                return False
        return True

    S=input()
    N=len(S)
    if ispal(S) and ispal(S[:(N-1)//2]) and ispal(S[(N+3)//2-1:]):
        print('Yes')
    else:
        print('No')

#C
if sel=='C':
    L=int(input())
    print((L**3)/27)

#D
if sel=='D':    
    N=int(input())
    A=[int(i) for i in input().split()]
    kin=list(set(A))
    cnt={}
    for k in kin:
        cnt[k]=0
    for a in A:
        cnt[a]+=1
    SUM=0
    for k in kin:
        SUM+=cnt[k]*(cnt[k]-1)//2
    for a in A:
        if cnt[a]>=2:
            print(SUM-cnt[a]+1)
        else:
            print(SUM)
        
#E
if sel=='E':
    def add(in1, in2):
        return [a + b for a, b in zip(in1, in2)]

    def split(ar, k, w):
        a = 0
        if max(max(ar)) > k:
            return -1
        tm = ar[0]
        for i in range(1, w):
            tm = add(tm, ar[i])
            if max(tm) > k:
                a += 1
                tm = ar[i]
        return a        

    h, w, k = map(int, input().split())
    s = [[int(i) for i in input()] for j in range(h)]
    ans = h*w

    for i in range(2**(h-1)):
        data = []
        temp = s[0]
        sp = bin(i+2**h)[4:]
        for j in range(1, h):
            if sp[j-1] == "0":
                temp = add(temp, s[j])
            else:
                data.append(temp)
                temp = s[j]
        data.append(temp)
        ans_ = split([list(x) for x in zip(*data)], k, w)
        if ans_ == -1:
            continue
        ans_ += sp.count("1")
        if ans > ans_:
            ans = ans_
    print(ans)



# #F
# if sel=='F':
#     N,S=map(int,input().split())
#     A=[int(i) for i in input().split()]
    



Measured memory_bytes: 3476
n,m=map(int,input().split())
ab = []
for _ in range(m):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  ab.append({a,b})
import itertools

cnt = 0
for v in itertools.permutations(range(1,n)):
  l = 0
  ok = True
  for v2 in v:
    if {l,v2} not in ab:
      ok = False
      break
    l = v2
  if ok:
    #print(v)
    cnt += 1
  
print(cnt)

Measured memory_bytes: 9212
s=input()
if s[0]=='A':
    if s[2:-1].count('C')==1:
        if (s[1]+s[2:-1].replace('C', '')+s[-1]).islower() :
            print('AC')
        else:
            print('WA')
    else:
        print('WA')
else:
    print('WA')

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

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i++)
#define per(i,a,b) for(int i = (a) ; i >= (b) ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int INF = 1e9;
const LL mod = 1e9 + 7;
const int maxn = 2e5 + 7;

int main() {
    int n;
    while(~sd(n)) {
        LL ans = 0;
        rep(i,1,n) {
            if(i % 3 == 0 || i % 5 == 0) continue;
            ans += 1LL * i;
        }
        plld(ans);
    }
    return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define repeat_from_reverse(i, m, n) for( int i = (n) - 1; (i) >= (m); --(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t t=0; t<v.size(); ++t){cout << " " << #v << "[" << t << "]=" << v[t];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    const string DREAM = "maerd", DREAMER = "remaerd", ERASE = "esare", ERASER = "resare";
    string s; cin >> s;
    
    reverse(s.begin(), s.end());
    
    while (s.length() > 0) {
        
        if (s.substr(0, 5) == DREAM)         s = s.substr(5);
        else if (s.substr(0, 7) == DREAMER)  s = s.substr(7);
        else if (s.substr(0, 5) == ERASE)    s = s.substr(5);
        else if (s.substr(0, 6) == ERASER)   s = s.substr(6);
        else {cout << "NO" << endl; return 0;}
        
    }
    cout << "YES" << endl;
    return 0;
}
            
    

Measured memory_bytes: 512
s=input().split()
a=int(s[0])
b=int(s[1])
k=int(s[2])
if a>=k:
    print(str(a-k)+" "+str(b))
else:
    if a+b>=k:
        print("0 "+str(b+a-k))
    else:
        print("0 0")

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main() {

    char s[11];
    scanf("%s", s);
    int l = strlen(s);

    int isCheck = 1;

    if (s[0] != 'A') {
        isCheck = 0;
    }


    int cnt = 0;
    int cposi;
    for (int i = 2; i < l - 1; i++) {

        if (s[i] == 'C') {
            cnt++;
            cposi = i;
        }
    }

    if (cnt != 1) {
        isCheck = 0;
    }

    for (int i = 1; i < l; i++) {
        if (i != cposi) {
            if (!(s[i]-'a' >= 0 && s[i]-'a' <= 26)) {
                isCheck = 0;
                break;
            }
        }
    }
    
    
    if (isCheck == 1) {
        printf("AC");
    } else {
        printf("WA");
    }




    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int N; cin >> N;
    ll ans = 0;
    for (int i =1;i <= N;++i){
        for (int j = i;j <= N;j += i) {
            ans += (ll)j;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 100010;

inline int in() {int x; scanf("%d",&x); return x;}
inline ll lin() {ll x; scanf("%lld",&x); return x;}

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

vector < int > g[345];

int inp[345][345];

int bad[345];
int arr[345];
int play[345];
int cnt[345];

int n, m;

int P(int mid){
    for(int i = 1; i <= 333; i++){
        arr[i] = 1; bad[i] = 0;
        cnt[i] = 0; play[i] = 0;
    }
    while(1){
        for(int i = 1; i <= n; i++){
            if(play[i] == 0){
                cnt[inp[i][arr[i]]]++;
                play[i] = 1;
            }
        }
        for(int i = 1; i <= 300; i++){
            if(cnt[i] > mid){
                bad[i] = 1;
            }
        }
        for(int i = 1; i <= n; i++){
            if(bad[inp[i][arr[i]]]){
                arr[i]++;
                if(arr[i] > m) return 0;
                play[i] = 0;
            }
        }
        int how = 0;
        for(int i = 1; i <= n; i++){
            if(play[i]){
                how++;
            }
        }
        if(how == n){
            break;
        }
    }
    return 1;
}

int main(){
    n = in(), m = in();
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            inp[i][j] = in();
        }
    }
    int low = 1, high = n, ans = n;
    while(low <= high){
        int mid = (low + high) >> 1;
        if(P(mid)){
            ans = mid;
            high = mid - 1;
        }else {
            low = mid + 1;
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
  int N, A[100];
  
  scanf("%d", &N);

  for (int i = 0; i < N; i++)
  {
    scanf("%d", &A[i]);
  }

  sort(A, A + N);

  printf("%d\n", abs(A[0] - A[N - 1]));

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
    int N; cin >> N;
    vector<int> vs;
    vector<pair<int, int>> ord;
    for (int i = 0; i < N; ++i) {
        int a; cin >> a;
        vs.push_back(a);
        ord.push_back(make_pair(a, i));
    }

    sort(ord.begin(), ord.end(), greater<pair<int, int>>());

    for (int i = 0; i < N; ++i) {
        if (i == ord.front().second) {
            cout << ord[1].first << endl;
        } else {
            cout << ord[0].first << endl;
        }
    }

    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a%2 == 0 || b%2 == 0) {
  	cout << "Even" << endl;
  }
  else {
  	cout << "Odd" << endl;
  }
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define nmod         -1000000007
#define N            1000000//31630=sqrt(pow(10,9))
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
//bool pf[N+1ll];
//vec prim;
//void sieve()
//{
//    repi(i,0,N)
//    pf[i]=true;
//	pf[0] = pf[1] = false;
//    for (int i = 2; i <= N; i++) {
//        if (pf[i]) 
//		{
//            prim.push_back(i);
//            for (int j = i + i; j <= N; j+=i) {
//                pf[j] = false;
//            }
//        }
//    }
//}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) 
{
    return (ll)(log(x) / log(base));
}
ll a[200005],dp[200005],prefix[200005];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS; 
    while(TESTS--)
    {
    	ll m,k,g,i,l,h,j,mx,my,ans,d,n,x;
    	cin>>n;
    	cin>>a[1]>>a[2];
    	prefix[1]=a[1], prefix[2]=a[2];
    	repi(i,3,n)
    	{
    		cin>>a[i];
    		prefix[i]=prefix[i-2]+a[i];
		}
		dp[0]=0; dp[1]=0;
		repi(i,2,n)
		{
			if(i%2==0)
			dp[i]=max(prefix[i-1],dp[i-2]+a[i]);
			else
			dp[i]=max(dp[i-2]+a[i],dp[i-1]);
		}
		cout<<dp[n];
	}
	return 0;
} 


Measured memory_bytes: 8412
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 200010;
const LL mod = 998244353;

struct Line
{
    int l, r;
}a[N];

LL f[N], s[N];
int n, k;

int main()
{
    scanf("%d%d", &n, &k);

    for (int i = 1; i <= k; i ++ ) scanf("%d%d", &a[i].l, &a[i].r);

    f[1] = 1;
    s[1] = 1;
    for (int i = 2; i <= n; i ++ )
    {
        for (int j = 1; j <= k; j ++ )
        {
            f[i] = (f[i] + s[max(0, i - a[j].l)] - s[max(0, i - a[j].r - 1)]) % mod;
        }
        s[i] = (s[i - 1] + f[i]) % mod;
    }

    printf("%lld\n", (f[n] + mod) % mod);

    return 0;
}

Measured memory_bytes: 6832
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

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

	ld x;
	cin >> x;
	ld cur = 100;
	int ans = 0;
	while(cur < x) {
		cur = cur * 1.01;
		cur = floor(cur);
		ans++;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3744
S = gets.chomp
s = S.split('')
l = S.length
t = S.unpack("C*")
if  s.count('A') != 1 || s.count('C') != 1 || s.index('A') != 0 || s.index('C') <= 1 || s.index('C') == l-1  
    puts 'WA'
elsif t.any?{|x| x == 66 || (68 <= x && x <= 90 ) }
    puts 'WA'
else
    puts 'AC'
end



Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

struct edge{int to,cost;};

template<typename T> class TreeDPRerooting
{
    using Func=function<T(T,T)>;
    vector<vector<edge>> G;
    int N;
    Func merge,lift;
    T e; // identity element

public:
    vector<vector<T>> sumL,sumR;
    vector<T> dp,res;

    TreeDPRerooting(vector<vector<edge>> G,Func merge,Func lift,T e):
        G(G),merge(merge),lift(lift),e(e),N(G.size()),dp(N),sumL(N),sumR(N),res(N)
    {
        dfs(0,-1);
        reroot(0,-1);
    } 

    T dfs(int v,int par)
    {
        // TreeDP
        T res=e;
        for(edge e:G[v]) if(e.to!=par){
            res=merge(res,lift(dfs(e.to,v),e.cost));
        }
        return dp[v]=res;
    }

    void reroot(int v,int par)
    {
        // accumulate children's information from left and right
        sumL[v].assign(G[v].size()+1,e);
        sumR[v].assign(G[v].size()+1,e);

        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            sumL[v][i+1]=merge(sumL[v][i],lift(dp[e.to],e.cost));
        }
        for(int i=G[v].size()-1;i>=0;i--){
            edge e=G[v][i];
            sumR[v][i]=merge(sumR[v][i+1],lift(dp[e.to],e.cost));
        }

        // calculate res[v] using children's information(L[v],R[v],dp)
        res[v]=sumR[v][0];

        // reroot v with its children
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(e.to!=par){
                int tmp=dp[v];
                dp[v]=merge(sumL[v][i],sumR[v][i+1]);
                reroot(e.to,v);
                dp[v]=tmp;
            }
        }
    }
};

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

    int N; cin>>N;
    vector<vector<edge>> G(N);
    for(int i=0;i<N-1;i++){
        int a,b,c; cin>>a>>b>>c;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    auto merge=[](int a,int b){
        return max(a,b);
    };
    auto lift=[](int a,int cost){
        return a+cost;
    };
    TreeDPRerooting<int> treedp(G,merge,lift,0LL);
    vector<int> dp=treedp.res;
    for(int i=0;i<N;i++){
        cout<<dp[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 7812
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>

using namespace std;
typedef pair<bool, int> P;

int n;

int main() {
	while (cin >> n, n) {
		stack<P> s;
		bool before;
		{
			bool a;
			cin >> a;
			s.push(P(a, 0));
			before = a;
		}
		for (int i = 1; i < n; i++) {
			int a;
			cin >> a;
			if (i % 2 == 0) {
				//1idx??§?\???°???????????£??????
				if (s.top().first != a)s.push(P(a, i));
			}
			else {
				//1idx??§??¶??°???????????£??????
				if (s.top().first != a) {
					s.pop();
					if (s.size() == 0) {
						s.push(P(a, 0));
					}
				}
			}
		}
		int ans = 0;
		int now = n;
		while (s.size()) {
			auto tmp = s.top(); s.pop();
			if (tmp.first == 0)ans += (now - tmp.second);
			now = tmp.second;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, t, a[200005] = {}, z = 0;
    cin >> n >> t;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) z += min(t, a[i] - a[i - 1]);
    cout << z + t << '\n';
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.Collator;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      StringBuilder line  = new StringBuilder();
      StringBuilder wordA = new StringBuilder();
      StringBuilder wordB = new StringBuilder();
      Collator collator = Collator.getInstance();
      int turn = Integer.parseInt(br.readLine());
      int pointA = 0;
      int pointB = 0;
      int result = 0;


      for ( int i = 0; i < turn; i++ ) {

        line.append(br.readLine());
        wordA.append(line.substring(0, line.indexOf(" ")));
        wordB.append(line.substring(line.indexOf(" ")+1, line.length()));

        result = collator.compare(wordA.toString(),wordB.toString());
        pointA += result == 0 ? 1 : result < 0 ? 0 : 3;
        pointB += result == 0 ? 1 : result < 0 ? 3 : 0;

        line.setLength(0);
        wordA.setLength(0);
        wordB.setLength(0);
      }

      System.out.println(pointA + " " + pointB);
    }
  }
}


Measured memory_bytes: 29928
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
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>;

#define ll long long
#define ull unsigned long long
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define inf 1000000000000000000
#define iinf -1000000000000000000
#define __   ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define mod 1000000007
#define base 1949313259
#define en '\n'

ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }

ll ar[]={0,0,1,-1};
ll br[]={1,-1,0,0};

ll bigmod(ll n,ll pow){
if(pow==0) return 1;
if(pow==1) return n%mod;

ll ans=bigmod(n,pow/2);
ans=(ans*ans)%mod;

if(pow%2==1){ans=(ans*n)%mod;}
return ans%mod;
}

ll fact[1000005];

ll nCr(ll n,ll r){

ll ans=fact[n];
ans=(ans*bigmod(fact[r],mod-2))%mod;
ans=(ans*bigmod(fact[n-r],mod-2))%mod;
return ans;
}

string s,s1,s2;
ll n,m;
ll arr[500010];
ll brr[500010];
vector<ll>v,v1;

map<ll,ll>mp;
ll vis[500005];

int main()
{__
        ll i,j,a,b,c,d,e,f,g,x,y,z,t,k,l,r;
        fact[0]=1;

      //  for(i=1;i<=1000000;i++) fact[i]=(fact[i-1]*i)%mod;
        ll ans=0,sum=0,temp;
        cin>>n;
        for(i=0;i<n;i++){
            cin>>arr[i];
        mp[arr[i]]++;
        sum+=arr[i];
        }

        cin>>m;

        for(i=0;i<m;i++){
            cin>>a>>b;

            sum-=mp[a]*a;
            sum+=mp[a]*b;
            mp[b]+=mp[a];
            mp[a]=0;
            cout<<sum<<endl;
        }
}




Measured memory_bytes: 10296
//↓template↓

#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 pi = acos(-1);
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↑





int ans = 100005;
int main() {
	int n, k[105];
	cin >> n;
	for (int i = 0; i < n; ++i) { cin >> k[i]; }
	for (int i = 1; i < n; ++i) { k[i] += k[i - 1]; }
	for (int i = 1; i < n; ++i) {
		ans = min(ans, abs(k[i] - k[n - 1] + k[i]));
	}
	cout << ans << endl;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101010];
int B[101010];
int nim;
set<int> S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		S.insert(A[i]^(A[i]-1));
		nim ^= A[i];
	}
	
	int ret=0;
	while(nim) {
		x=1;
		while(x<nim) x=x*2+1;
		if(S.count(x)==0) return _P("-1\n");
		nim ^= x;
		ret++;
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 640
#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 <functional>
#include <cassert>

typedef long long ll;
using namespace std;

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


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


int main(){
  int a,b,c;

  scanf("%d%d%d",&a,&b,&c);
  
  for(int i=0;i<100000;i++){

    if(a%2 || b%2 || c%2){
      printf("%d\n",i);
      return 0;
    }

    int new_a = (c+b)/2;
    int new_b = (a+c)/2;
    int new_c = (a+b)/2;

    a = new_a;
    b = new_b;
    c = new_c;
  }

  printf("-1\n");
  
  
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    
using namespace std;
int gcd(int a, int b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 
int main()
{
    int N;
    int tsum=0;
    int sum=0;
    scanf("%d", &N);
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            tsum=gcd(i,j);
            for(int k=1;k<=N;k++){
                sum=sum+gcd(tsum,k);
            }
        }
    }
    printf("%d", sum);

    return 0;
}


Measured memory_bytes: 3844
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
#define diup(v,a,k) distance((v).begin(),(k)+upper_bound((v).begin(),(v).end(),(a)))
#define dilo(v,a,k) distance((v).begin(),(k)+lower_bound((v).begin(),(v).end(),(a)))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
//---------------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
ll binomial(ll N, ll K) {
  if(K < 0 || N < K) return 0;
  ll ret = 1;
  for(ll i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
void Main(){
  int n,a,b;
  cin>>n>>a>>b;
  vl c(n);
  cin>>c;
  sort(rrng(c));
  map<ll,int> mp;
  rep(i,a){
    mp[c[i]]++;
  }
  if(mp.size()==1){
    ll eq = (*mp.begin()).first;
    int cnt=0;
    rep(i,n) if(eq==c[i]) cnt++;
    ll can = min(cnt,b);
    ll ans=0;
    srep(i,a,can+1){
      ans += binomial((ll)cnt,(ll)i);
    }
    cout<<setprecision(8)<<fixed<<(double)eq<<endl;
    cout<<ans<<endl;
  }else{
    double ave=0;
    rep(i,a) ave+=c[i];
    ave/=a;
    ll eq = c[a-1];
    ll cnt=0; ll use=0;
    rep(i,n) if(c[i]==eq) 
    if(i<a){
      cnt++; use++;
    } else{
      cnt++;
    }
    ll ans=binomial(cnt,use);
    cout<<setprecision(8)<<fixed<<ave<<endl;
    cout<<ans<<endl;
  }

} int main(int argc,char** argv)
{fastio; myio; myloopset Main();}


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

ll n;

void Process() {
  cout << n + n * n + n * n * n << "\n";
}

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

  while (cin >> n) {
    Process();

    if (cin.eof())
      break;
  }

  return 0;
}

Measured memory_bytes: 3648
/**
  * @file pb.cpp
  * @brief atcoder

  *

  * @author yao
  * @date 2018-10-06
  */
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#define ft frist
#define sd second
#define INF ((int)1e9)
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#endif //DBG

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

int main()
{
    int n,m,ans=INF;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;++i)
    {
        int c,t;
        scanf("%d%d",&c,&t);
        if(t>m) continue;
        ans = std::min(ans,c);
    }
    if(ans == INF) return puts("TLE"), 0;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int lmatch(string t, string p){
  int lm = -1;
  for(int i = 0; i < t.size(); i++){
    int j = 0;
    
    while(t[i+j] == p[j] || t[i+j] == '?'){
      j++;
    }
    if(j >= p.size()) lm = i;
  }
  return lm;
}

int main(){
  string s, p;
  cin >> s >> p;
  
  int m = lmatch(s, p);
  if(m == -1){
    cout << "UNRESTORABLE";
    return 0;
  }else{
    for(int i = 0; i < s.size(); i++){
      if((i < m || i >= m + p.size()) && s[i] == '?') s[i] = 'a';
      else if ((i < m || i >= m + p.size()) && s[i] != '?') continue;
      else s[i] = p[i - m];
    }
    cout << s;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	char ch;

	while (1) {
		scanf("%c", &ch);

		if ('a' <= ch && ch<= 'z') {
			ch = ch - 32;
		}else if ('A' <= ch && ch <= 'Z') {
			ch = ch + 32;
		}
		printf("%c", ch);
		if (ch == '\n') {
			break;
		}
		
	}
	

}



Measured memory_bytes: 2112