akhauriyash/Code-Regression huggingface dataset:
local n, q = io.read("*n", "*n")
for i = 1, q do
  local v, w = io.read("*n", "*n")
  if n == 1 then
    print(math.min(v, w))
  else
    while v ~= w do
      if v < w then
        w = (w + n - 2) // n
      else
        v = (v + n - 2) // n
      end
    end
    print(v)
  end
end


Measured memory_bytes: 1400
'use strict'

const main = input => {
	const args = input.split('\n')
	const n = parseInt(args[0].split(' ')[0], 10)
	const p = args[1].split(' ').map(Number)
	let cnt = 0

	for (let i = 1; i < (n - 1); i++) {
		if (p[i - 1] < p[i] && p[i] < p[i + 1]) cnt ++
		else if (p[i - 1] > p[i] && p[i] > p[i + 1]) cnt ++
	}

	console.log(cnt)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <set>
#include <utility>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>

using namespace std;

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

	int count = b / a;
	int result = min(count, c);
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
def conv(s,b):
    j = 1
    sn = s
    bn = b
    i = 2

    while sn != bn :
        bn = b * j
        while sn < bn :
            sn = s*i
            i += 1
        j += 1
    return bn

def main():
    A,B = map(int,input().split())
    if A > B :
        small = B
        big = A
    else :
        small = A
        big = B
    print(conv(small,big))

main() 


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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}


int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, L;
    cin >> n >> L;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i+1 < n; i++) {
        if(a[i] + a[i+1] >= L) {
//            cout << "i: " << i << endl;
            cout << "Possible" << "\n";
            int At = n-1;
            while(At > i+1) {
                cout << At << "\n";
                At--;
            }
            At = 1;
            while(At <= i+1) {
                cout << At << "\n";
                At++;
            }
            return 0;
        }
    }
    cout << "Impossible" << endl;
}





Measured memory_bytes: 3772
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;
bool sr(ll a, ll b)
{
	return a > b;
}
bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(ll n)
{
	int count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}
template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}

int main()
{
	string s;
	cin >> s;

	vector<string> aki = {"AKI", "KI", "HA", "H", "BA", "B", "RA", "R"};
	bool ans = false;
	rep(i, 17)
	{
		string tmp = "";
		rep(j, 4)
		{
			if (i & 1 << j)
			{
				tmp += aki[j * 2];
			}
			else
			{
				tmp += aki[j * 2 + 1];
			}
		}
		if(s==tmp){
			ans=true;
		}
		
	}
	if(ans){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}


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

const int N = 5020;
const int L = 13;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
ll add(ll x, ll y)
{
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll mult(ll x, ll y)
{
	return (x * y) % MOD;
}

ll C[N];
ll p2[N];
ll dp[L][N];
int n, m;
char s[N];
ll A[N], B[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	scanf(" %s ", s);
	m = strlen(s);

//	printf("%d %d\n", n, m);

	C[0] = 1;
	p2[0] = 1;
	for (int i = 1; i < N; i++)
	{
		C[i] = 0;
		for (int j = 0; j < i; j++)
			C[i] = add(C[i], mult(C[j], C[i - 1 - j]));
		p2[i] = add(p2[i - 1], p2[i - 1]);
	}
	
	/*
	for (int i = 0; i < 10; i++)
		printf("%lld ", C[i]);
	printf("\n");
	for (int i = 0; i < 10; i++)
		printf("%lld ", p2[i]);
	printf("\n");
	*/

	for (int i = 0; i <= n; i += 2)
		dp[0][i] = mult(C[i / 2], p2[i / 2]);
	for (int k = 1; k < L; k++)
		for (int i = 0; i <= n; i++)
			for (int j = 0; j <= i; j++)
				dp[k][i] = add(dp[k][i], mult(dp[k - 1][j], dp[k - 1][i - j]));
	A[0] = 1;
	for (int k = 0; k < L; k++)
	{
		if (((m >> k) & 1) == 0) continue;
		for (int i = 0; i <= n; i++)
		{
			B[i] = 0;
			for (int j = 0; j <= i; j++)
				B[i] = add(B[i], mult(A[j], dp[k][i - j]));
		}
		for (int i = 0; i <= n; i++)
			A[i] = B[i];
	}
	for (int i = 0; i <= n; i++)
		B[i] = 0;
	B[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		B[i] = B[i - 1];
		for (int k = 1; 2 * k <= i; k++)
			B[i] = add(B[i], mult(B[i - 2 * k], mult(p2[k], C[k - 1])));
	}
	ll ans = 0;
	for (int i = 0; i <= n - m; i++)
		ans = add(ans, mult(B[i], A[n - m - i]));
	printf("%lld\n", ans);

	return 0;
}

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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 300000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    int a[n * 3];
    rep(i, 0, n * 3)
        cin >> a[i];
    ll pref[n * 3], suff[n * 3];
    multiset<int> s;
    ll sum = 0;
    rep(i, 0, n * 3)
    {
        if (sz(s) < n || a[i] > *s.begin())
        {
            if (sz(s) == n)
            {
                sum -= *s.begin();
                s.erase(s.begin());
            }
            sum += a[i];
            s.insert(a[i]);
        }
        pref[i] = sum;
    }
    s.clear();
    sum = 0;
    repb(i, n * 3 - 1, -1)
    {
        if (sz(s) < n || a[i] < *(--s.end()))
        {
            if (sz(s) == n)
            {
                sum -= *(--s.end());
                s.erase(--s.end());
            }
            sum += a[i];
            s.insert(a[i]);
        }
        suff[i] = sum;
    }
    ll ans = -big;
    rep(i, n - 1, n * 2)
        ans = max(ans, pref[i] - suff[i + 1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10768
'use strict'
function main(input) {
  const func = n => n % 2 ? 3 * n + 1 : n / 2
  let a = [Number(input)]
  let i = 1
  while (i < 1000000) {
    let current = func(a[i - 1])
    if (a.indexOf(current) !== -1) break
    a.push(current)
    i++
  }
  console.log(a.length + 1)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
N,T = map(int,input().split())
A = list(map(int,input().split()))
dif = []
max_A = 0
for i in range(N):
    max_A = max(max_A,A[-1-i])
    dif.append(max_A-A[-1-i])
ans = 0
dif.sort(reverse=True)
for i in range(N-1):
    if dif[i]!=dif[i+1]:
        print(i+1)
        break

Measured memory_bytes: 15020
n = int(input())
pos = 0

flag = True
for _ in range(n):
    k, num = input().split()
    num = int(num)
    if k == "(":
        pos += num
    else:
        pos -= num

    if pos < 0:
        flag = False

if not flag or pos != 0:
    print("NO")
else:
    print("YES")



Measured memory_bytes: 5608
def selectionSort(number, array)
  count_num = 0
  for i in 0..number-1 do
    minj = i
    # change_array = array[minj]
    for j in i..number-1 do
      if array[j].to_i < array[minj].to_i
        # change_array = array[minj]
        minj = j
        change_array = array[minj]
      end
    end
    if minj != i
      array[minj] = array[i]
      array[i] = change_array
      count_num += 1
    end
  end
  puts array.join(" ").strip
  puts count_num
end

number = gets.to_i
array = gets.to_s.split(" ")

selectionSort(number,array)



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

bool isOk(string s) {
    if(s.at(0) != 'A') return false;
    int count = 0;
    for(int i = 1; i < s.size(); i++) {
        if('a' <= s.at(i) && s.at(i) <= 'z') continue;
        if(i < 2 || s.size() - 2 < i || s.at(i) != 'C') return false;
        count++;
    }
    return count == 1;
}

int main() {
    string s;
    cin >> s;

    if(isOk(s)) cout << "AC" << endl;
    else cout << "WA" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <tuple>
template <typename T> constexpr T my_abs(const T &x) { return x < 0 ? -x : x; }
using ll = long long;
constexpr int MOD = 998244353;
inline int quick_pow(int a, int n)
{
	int res = 1;
	while (n)
	{
		if (n & 1)
			res = (ll)res * a % MOD;
		a = (ll)a * a % MOD;
		n >>= 1;
	}
	return res;
}
constexpr int LIM = 1e6;
int all[LIM + 5], sum[LIM + 5];
int main()
{
	// freopen("AGC038-C.in", "r", stdin);
	int n, ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int val;
		scanf("%d", &val);
		auto add = [&] (int idx)
		{
			all[idx] = (all[idx] + (ll)val * sum[idx]) % MOD;
			sum[idx] = (sum[idx] + val) % MOD;
		};
		for (int j = 1; j * j <= val; j++)
		{
			if (val % j)
				continue;
			add(j);
			if (j * j != val)
				add(val / j);
		}
	}
	for (int i = LIM; i; i--)
	{
		for (int j = i + i; j <= LIM; j += i)
			all[i] = (all[i] - all[j] + MOD) % MOD;
		ans = (ans + (ll)all[i] * quick_pow(i, MOD - 2)) % MOD;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 7936
z=[1]+[0]*50
nCr=[z.dup]
for i in 1..50
	nCr<<z.dup
	for j in 1..i
		nCr[i][j]=nCr[i-1][j]+nCr[i-1][j-1]
	end
end

n, a, b=gets.split.map &:to_i
v=gets.split.map &:to_i

h={}
v.each{|e| h[e]=v.count(e)}

s, m, i=0, 1, 0
h.to_a.sort.reverse.each do |x, c|
	if s==0 && c>=a
		j, r=a, 0
		while j<=b
			r+=nCr[c][j]
			j+=1
		end
		puts x, r
		break
	end
	if i+c<a
		s+=x*c; m*=c; i+=c
	else
		q=a-i
		s+=x*q
		puts "%.9f"%(s.to_f/a), m*nCr[c][q]
		break
	end
end


Measured memory_bytes: 1788
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
#define ll long long
int main(){
	int n;
	string s;
	cin >> n >> s;
	ll ans, c1 = 0, c2 = 0, c3 = 0;
	for (int i = 0; i < s.size(); i++){
		if (s[i] == 'R') c1++;
		else if (s[i] == 'G') c2++;
		else c3++;
	}
	ans = c1 * c2 * c3;
	for (int i = 1; i < n; i++){
		for (int j = 0; j < n; j++){
			if (j - i < 0 || j + i >= n) continue;
			if (s[j - i] != s[j] && s[j] != s[j + i] && s[j + i] != s[j - i]) ans--;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,H,W;
  cin >> H >> W >> N;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  vector<int> k;
  rep(i,N)
  {
    rep(j,a[i])
    {
      k.pb(i+1);
    }
  }
  vector<vector<int>> grid(H,vector<int>(W));
  rep(i,H)
  {
    rep(j,W)
    {
      if(i%2==0)
      {
        grid[i][j] = k[i*W+j];
      }
      else
      {
        grid[i][W-1-j] = k[i*W+j]; 
      }
      
    }
  }
  rep(i,H)
  {
    rep(j,W)
    {
      if(j!=W-1) cout << grid[i][j] << " ";
      else cout << grid[i][j] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3640
# Your code here!
a,b = gets.split
n=a.to_i
d=b.to_i
num=0
for i in 1..n
  c,h=gets.split
  x=c.to_i
  y=h.to_i
  e=x**2 + y**2
  f=Math.sqrt(e)
 
  if d>=f
      num+=1
  end
      
end
puts num



Measured memory_bytes: 14364
main = interact $ unlines . map (show' . magic_square . read') . init . lines
 where
  read' n = replicate (read n) (replicate (read n) 0)
  show' = init . unlines . map (concat . map (justifyr 4 . show)) 

magic_square sq = add_number (center (length sq) + 1) (center (length sq)) 1 sq
 where center n = div n 2 + 1

add_number l c x sq
 | x > (length sq)^2 = sq
 | c > length sq = add_number l 1 x sq
 | c < 1 = add_number l (length sq) x sq
 | l > length sq = add_number 1 c x sq
 | sq!!(l-1)!!(c-1) /= 0 = add_number (succ l) (pred c) x sq
 | otherwise = add_number (succ l) (succ c) (succ x) (insert_number l c x sq)

insert_number l c x sq = let ls = replace c x (sq!!(l-1)) in replace l ls sq
replace i r xs = let (xs1,(x:xs2)) = splitAt (i-1) xs in xs1 ++ (r:xs2)
justifyr n = reverse . take n . (++ (replicate n ' ')) . reverse

Measured memory_bytes: 4308
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<char,int> P;
static const int INF=1<<24;


stack<P> st;
string s;

int main(){
	int n;
	char tc,tt;
	int tx;
	cin>>n;
	rep(i,n){
		cin>>tc>>tx;
		//cout<<tc<<" "<<tx<<endl;
		
		if(st.size()==0){
			P tmp;
			tmp.F=tc;
			tmp.S=tx;
			st.push(tmp);
			//cout<<i<<" "<<st.top().F<<" "<<st.top().S<<endl;
		}
		else if(tc==')'&&st.top().F=='('){
			if(tx>st.top().S){
				tx-=st.top().S;
				st.pop();
				P tmp;
				tmp.F=tc;
				tmp.S=tx;
				st.push(tmp);
			}
			else{
				P tmp=st.top();
				st.pop();
				tmp.S-=tx;
				st.push(tmp);
			}
		}
		else if(tc==st.top().F){
			P tmp=st.top();
			st.pop();
			tmp.S+=tx;
			st.push(tmp);
		}
		else{
			P tmp;
			tmp.F=tc;
			tmp.S=tx;
			st.push(tmp);
		}
		if(st.size()!=0){
			while(st.top().S==0){
				st.pop();
				if(st.size()==0) break;
			}
		}
		//cout<<st.top().F<<" "<<st.top().S<<endl;
	}
	if(st.size()==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 1200
#include<iostream>

using namespace std;

int main() {
    int n, x, y, ans = 1;
    cin >> n >> x;
    for (int i = 2; i <= n; i++) {
        cin >> y;
        if (y >= x)ans++, x = y;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;

ll K, N;
ll A[200010];

int main()
{
  std::cin >> K >> N;
  rep( i, N )
    std::cin >> A[i];

  std::sort( A, A+N );

  ll ans = 0;

  rep( i, N )
    ans = std::max( ans, (A[(i+1)%N]-A[i]+K)%K );

  std::cout << K-ans << std::endl;

  return 0;
}

Measured memory_bytes: 1792
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,k = LI()
    num = 0
    frac = 0
    while n * 2**num < k:
        num+=1
    frac += 1/2**num
    # print(frac)

    for i in range(n-1,0,-1):
        while i * 2**num < k:
            num += 1
        frac += 1/2**num
    
    ans = frac * (1/n)
    print(ans)
main()

Measured memory_bytes: 74760
/*Stay true to yourself, yet always be open to learn. Work hard, and never give up on your dreams, 
even when nobody else believes they can come true but you. These are not cliches but real tools you 
need no matter what you do in life to stay focused on your path.
*/
 
 /*Pppppppp    UU      UU     CCCCCCCC    CCCCCCCC     HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pppppppp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pp          UU      UU     CC          CC           HH     HH     UU      UU
   pp          UUUUUUUUUU     CCCCCCCC    CCCCCCCC     HH     HH     UUUUUUUUUU
   */
 
#include <bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define ford(i,a,b) for(int i=b;i>=a;i--)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{

    fast;
    int n;
    double m;
    cin >>n>>m;
    double s=0;
    double a[n];
    loop(i,n){
    	cin>>a[i];
    	s+=a[i];
    }
    int k=0;
    double mv = s/(4*m);
    // cout<<mv<<" ";
    loop(i,n){
     if(a[i]>=mv)
     k++;
    }
    if(k<m)
    cout<<"No"<<endl;
    else
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, A, B := sc.nextInt(), sc.nextInt(), sc.nextInt()
	diff := B - A
	var ans int
	if diff%2 == 0 {
		ans = diff / 2
	} else {
		if abs(1-B) < abs(N-A) {
			aDiff := abs(1 - A)
			ans = aDiff
			bDiff := abs(1 - B)
			ans += (bDiff-aDiff-1)/2 + 1
		} else {
			aDiff := abs(N - A)
			bDiff := abs(N - B)
			ans = bDiff
			ans += (aDiff-bDiff-1)/2 + 1
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ff first
#define ss second
#define nl '\n'
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); srand(time(0));
  int tc; tc = 1;
  for(int tt=1; tt<=tc; tt++) {
    // cout << "Case #" << tt << ": ";
    ll a,b,c,x,y; cin >> a>>b>>c>>x>>y;
    if( x > y ) { swap(x, y); swap(a, b); }
    ll ans = min( x * (c+c), x * (a+b) );
    ll rem = y - x;
    ans += min( rem * (c+c), rem*b );
    cout << ans << nl;
  }
  
  return 0;
}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


Measured memory_bytes: 256
N, M = input().strip().split()
n, k = [int(N), int(M)]
a = list(map(int, input().strip().split()))
le = 0
ri = 10000000000
while ri - le > 1:
    mid = (le + ri) // 2
    num = 0
    for i in a:
        num += (i-1) // mid
    if num <= k:
        ri = mid
    else:
        le = mid
print(ri)

Measured memory_bytes: 30676
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
int main() {
	int N, T;
	cin >> N >> T;
	int t[200100];
	for (int i = 0; i < N; ++i) {
		cin >> t[i];
	}
	t[0] = 0;
	ll sum = 0;
	for (int i = 0; i < N-1; ++i) {
		if (t[i] + T <= t[i + 1]) {
			sum += T;
		}
		else {
			sum += t[i + 1] - t[i];
		}
	}
	sum += T;
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1024
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
def A():
    a = IR(2)
    b = IR(2)
    print(min(a)+min(b))

#B
def B():
    n = I()
    d, x = LI()
    a = IR(n)
    ans = x
    for i in a:
        k = 0
        while k * i + 1 <= d:
            ans += 1
            k += 1
    print(ans)


#C
def C():
    n = I()
    a = LI()
    a.insert(0, 0)
    a.append(0)
    ans = 0
    for i in range(1, n + 2):
        ans += abs(a[i] - a[i - 1])
    #print(ans)
    for k in range(1, n + 1):
        if a[k - 1] < a[k]:
            if a[k] > a[k + 1]:
                print(ans - 2 * min(abs(a[k] - a[k - 1]), abs(a[k] - a[k + 1])))
            else:
                print(ans)
        if a[k - 1] > a[k]:
            if a[k] < a[k + 1]:
                print(ans - 2 * min(abs(a[k] - a[k - 1]), abs(a[k] - a[k + 1])))
            else:
                print(ans)
        if a[k - 1] == a[k]:
            print(ans)


#D
def D():
    a, b = LI()
    print(100, 100)
    ans = [["#"] * 100 if i < 50 else ["."] * 100 for i in range(100)]
    for i in range(a - 1):
        ans[(i // 50) * 2][i % 50 * 2] = "."
    for i in range(b - 1):
        ans[-((i // 50) * 2) - 1][i % 50 * 2] = "#"
    for ansi in ans:
        print("".join(ansi))
    return

if __name__ == '__main__':
    D()


Measured memory_bytes: 38384
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools
#from scipy.misc import comb

sx,sy,tx,ty = map(int, input().split())
ans = 'U'*(ty-sy) + 'R'*(tx-sx) + 'D'*(ty-sy) + 'L'*(tx-sx+1) + 'U'*(ty-sy+1) + 'R'*(tx-sx+1) + "DR" + 'D'*(ty-sy+1) + 'L'*(tx-sx+1) + 'U'
print(ans)

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

int main() {
	// your code goes here
	char s[20];
	int n,i; cin >> s;
	n=strlen(s);
	int amax=0,memo=0;
	for(i=0;i<n;i++){
		if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
			memo++;
			amax=max(amax,memo);
		} else {
			memo=0;
		}
	}
	cout << amax << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i) >> b.at(i);
    c.at(i) = a.at(i);
  }
  sort(c.begin(),c.end());
  int k;
  for(int i=0;i<n;i++){
    if(a.at(i) == c.at(n-1)){
      k = i;
      break;
    }
  }
  int ans = b.at(k) + a.at(k);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int a, b, c;
    int k;
    int n;
 
    scanf("%d%d%d", &a, &b, &c);
    n = 0;
    for (k = a; k <= b; k++) {
        if (c % k == 0) n++;
    }
    printf("%d\n", n);
    return 0;
}


Measured memory_bytes: 2140
# 0:50 事前にスマホで問題読んでる
n = int(input())
b = list(map(int,input().split()))
a = [0]*n
a[0] = b[0]
a[n-1] = b[n-2]
for i in range(1,n-1):
    a[i] = min(b[i],b[i-1])
print(sum(a))

Measured memory_bytes: 3064
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> color(H);
    REP (i, H) {
        cin >> color[i];
    }

    int ans = 0;
    REP (ib, 1 << H) REP (jb, 1 << W) {
        int sum = 0;
        REP (i, H) REP (j, W) {
            if ((ib >> i) & 1) {
                continue;
            }
            if ((jb >> j) & 1) {
                continue;
            }
            if (color[i][j] == '#') {
                sum++;
            }
        }
        if (sum == K) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3192
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
   char ai[10];
   for(int i=0;i<10;i++)
   {
          scanf("%c",&ai[i]);
          if((i+1)%3==0&&i!=8)
            getchar();
   }
   printf("%c%c%c",ai[0],ai[4],ai[8]);
   return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[]args) {
		int ans = 0;
		int x = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();

		for(int i = 0; i < n; i++) {
			if('I' == s.charAt(i)) {
				x += 1;
			}else if('D' == s.charAt(i)){
				x -= 1;
			}
			ans = Math.max(x, ans);
		}
		System.out.println(ans);
	}
}


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

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll k = 1; k <= n; k++) {
        ll p = n / k;
        ll toadd = p * (p + 1) * k / 2;
        ans += toadd;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <stdio.h>
int main(void){
  int child[100000] = {0}, LR = 1, count = 0, Lpointer = 0, n;
  char str[100099] = {0};
  fgets(str, 100099, stdin);
  for(int i = 0;; i++){
    if(str[i] == '\n' || str[i] == 0){
      n = i;
      break;
    }
  }
  for(int i = 0; i < n + 1; i++){
    if(i == 0){
      if(str[i] == 'R'){LR = 1;}
      else {LR = 0; Lpointer = i;}
      count++;
    }else{
      if(str[i] == 'R'){
        if(LR == 0){
          if(Lpointer - 1 >= 0){
            child[Lpointer - 1] += count / 2;
          }
          child[Lpointer] += count - (count / 2);
          LR = 1;
          count = 1;
        }else{
          count++;
        }
      }else if(str[i] == 'L'){
        if(LR == 1){
          if(i - 1 >= 0){
            child[i - 1] += count - count / 2;
          }
          child[i] += (count / 2);
          LR = 0;
          count = 1;
          Lpointer = i;
        }else{
          count++;
        }
      }else{
        if(LR == 1){
          if(i - 1 >= 0){
            child[i - 1] += count - count / 2;
          }
          child[i] += count / 2;
        }else{
          if(Lpointer - 1 >= 0){
            child[Lpointer - 1] += count / 2;
          }
          child[Lpointer] += count - (count / 2);
        }
        break;
      }
    }
  }
  for(int i = 0; i < n - 1; i++){
  	printf("%d ", child[i]);
  }
  printf("%d\n", child[n - 1]);
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef pair<int, pii> pip;
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;

double d[1000][1000];
double dp[1000][1000];

int main(){
	int n, m;
	while(cin>>n>>m){
		if(n == 0 && m == 0) break;
		for(int i = 0; i <= n; i++){
			dp[0][i] = 1.0;
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n ; j++){
				cin>>d[i][j];
			}
		}
		for(int i = 1; i < m; i++){
			for(int j = 0; j < n; j++){
				dp[i][j] = -1.0;
				for(int k = 0; k < n; k++){
					dp[i][j] = max(dp[i][j], dp[i-1][k]*d[k][j]);
				}
			}
		}
		double ans = -1;
		for(int i= 0; i < n; i++){
			ans = max(dp[m-1][i], ans);
		}
		printf("%.2lf\n", ans);
	}
}

Measured memory_bytes: 5752
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int sum = 0;
			int count = 0;
			for(int i=1;i<n;i++){
				sum = 0;
				for(int j=i;j<n;j++){
					sum += j;
					if(sum==n){
						count++;
						break;
					}else if(sum>n){
						break;
					}
				}
			}
			System.out.println(count);
		}
	}	
}

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

struct UnionFind{
    vector<int> par;
    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++){
            par[i] = -1;
        }
    }
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        else{
            if(par[rx] > par[ry]) swap(rx, ry);
            par[rx] += par[ry];
            par[ry] = rx;
       }
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    void check(){
        for(auto x : par){
            cout << x << " ";
        }
        cout << endl;
    }
};

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

    int n, m, k;
    cin >> n >> m >> k;
    vector<int> A(m), B(m), C(k), D(k);

    UnionFind uf(n);

    for(int i = 0; i < m; i++){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        uf.unite(A[i], B[i]);
    }

    for(int i = 0; i < k; i++){
        cin >> C[i] >> D[i];
        C[i]--;
        D[i]--;
    }

    vector<int> Ans(n, 0);
    for(int i = 0; i < n; i++){
        Ans[i] = -uf.par[uf.root(i)] - 1;
    }

    for(int i = 0; i < m; i++){
        Ans[A[i]]--;
        Ans[B[i]]--;
    }

    for(int i = 0; i < k; i++){
        if(!uf.same(C[i], D[i])) continue;
        Ans[C[i]]--;
        Ans[D[i]]--;
    }

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

    return 0;
}

Measured memory_bytes: 3200
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	for {
		h := nextInt()
		w := nextInt()
		if h == 0 {
			break
		}
		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				if i == 0 || i == h-1 || j == 0 || j == w-1 {
					fmt.Printf("#")
				} else {
					fmt.Printf(".")
				}
			}
			fmt.Println()
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1084
import java.util.*;
public class Main {
	static String hyou = "qwertyuiopasdfghjklzxcvbnm";
	static String hyou2= "QWERTYUIOPASDFGHJKLZXCVBNM";
	static char henkan(char n){
		for(int i=0;i<hyou.length();i++){
			if(hyou.charAt(i)==n)return hyou2.charAt(i);
		}
		return n;
	}
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			String input = in.nextLine();
			String result="";
			for(int s=0;s<input.length();s++){
				result+=henkan(input.charAt(s));
			}
			System.out.println(result);
		}
	}
}

Measured memory_bytes: 17212
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();
        int a = scan.nextInt();
        k%=500;
        if(k>a)
        {
            System.out.println("No");
        }
        else
        {
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 20948
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class DFloorFunction {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            long a = s.nextLong(), b = s.nextLong(), n = s.nextLong();
            long x = Math.min(b - 1, n);
            long v1 = (a * x) / b;
            long v2 = a * (x / b);
            w.println(v1 - v2);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

struct Team {
	int id, u, ac, time;
	bool operator<(Team &r) {
		if (ac != r.ac) return ac > r.ac;
		if (time != r.time) return time < r.time;
		return id < r.id;
	}
}teams[1000];

bool is_select(int num, int unum) {
	if (num < 10) { return unum < 3; }
	if (num < 20) { return unum < 2; }
	if (num < 26) { return unum < 1; }
	return false;
}

void solve(int n) {
	for (int i = 0; i < n; i++) {
		cin >> teams[i].id >> teams[i].u >> teams[i].ac >> teams[i].time;
	}
	sort(teams, teams + n);
	
	int u_num[1000] = {0};
	int num = 0;
	
	for (int i = 0; i < n; i++) {
		if (is_select(num, u_num[teams[i].u])) {
			cout << teams[i].id << endl;
			u_num[teams[i].u]++;
			num++;
		}
	}
}

int main() {
	int n;
	while (cin >> n, n) {
		solve(n);
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define pb push_back

int main()
{
    ll N;
    cin >> N;
    vec L(N);
    REP(i,0,N) cin >> L[i];
    
    ASC(L);
    ll c, cnt = 0;
    REP(i,0,N-2) {
        REP(j,i+1,N-1) {
            c = lower_bound(ALL(L), L[i]+L[j]) - L.begin();
            cnt += MAX(c-j-1,0);
        }
    }
    PR(cnt);


    return 0;
}

/*



*/

Measured memory_bytes: 256
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        q: usize,
        edges: [(usize, usize);n-1],
        queries: [(usize,usize);q]
    }

    let mut adj_list: Vec<Vec<usize>> = vec![Vec::new(); n];

    for e in &edges {
        let first = e.0;
        let second = e.1;
        adj_list[first - 1].push(second - 1);
        adj_list[second - 1].push(first - 1);
    }

    let mut counter_array: Vec<usize> = vec![0; n];
    for q in &queries {
        let node = q.0;
        let add_count = q.1;
        counter_array[node - 1] += add_count;
    }

    let mut point = vec![0; n];
    let mut visited = vec![false; n];

    // スタック (頂点, これまでのカウンタの合計)
    let mut stack: VecDeque<(usize, usize)> = VecDeque::new();
    // 最初のノード
    stack.push_front((0, 0));

    while !stack.is_empty() {
        let pop = stack.pop_front().unwrap();
        let node = pop.0;
        let add_count = pop.1;
        let add = counter_array[node];
        point[node] = add_count + add;
        visited[node] = true;

        for c in &adj_list[node] {
            if !visited[*c] {
                stack.push_front((*c, point[node]));
            }
        }
    }

    for i in 0..n {
        if i != n - 1 {
            print!("{} ", point[i]);
        } else {
            print!("{}", point[i]);
        }
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 43260
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  long double n,k;
  cin >> n >> k;

  //何回2倍したらkを超えるか
  vector<ll> a(n);

  for(int i=0;i<n;i++){
    long double b=i+1;
    long double c=0;
    while(b<k){
      b*=2;
      c++;
    }
    a[i]=c;
  }

  long double p=0;
  for(int i=0;i<n;i++)p+=1/pow(2,a[i]);

  p/=n;

  printf("%.12Lf",p);




}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl t(5);
  rep(i, 5) cin >> t[i];
  ll mn = *min_element(all(t));
  cout << (n + mn - 1) / mn + 4 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  ll l=s.length(),ans=0;
  lvector v(l,0);
  rep(i,l) v[i]=s[i]-'0';
  reverse(ALL(v));
  rep(i,3) v.emplace_back(0);
  rep(pos,l+1) {
    ll d=v[pos],e=v[pos+1]+1;
    ll num1=10-d+min(e,10ll-e);e--;
    ll num2=d+min(e,10ll-e);
    if(num1<=num2) {ans+=10-d;;v[pos+1]++;}
    else ans+=d;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 18844
n,m=map(int,input().split())
a=[list(input())for i in range(n)]
t=[list(input())for i in range(m)]
c=0
p=[]
for i in range(n-m+1):
    d=a[i:i+m]
    for h in range(n-m+1):
        for j in range(m):
            s=d[j]
            p.append(s[h:h+m])
        else:
            if p==t:
                c=1
            else:
                p=[]
print("No"if c!=1else"Yes")

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
}c(200005);

int main() {
	int N;
	cin >> N ;
	vector<int> C(N);
	for (int n = 0;n < N;++n) {
		cin >> C[n];
	}
	sort(C.begin(), C.end());
	//ans = 2^NΣ2^i*Ci(1 + N-i)*2^(N-i-2)
	//    = (4^(N-1)ΣCi(N-i))
	mint ans =1;
	for (int n = 0; n < N - 1; ++n) {
		ans *= 4;
	}
	mint anssub = 0;
	for (int n = 0;n< N;++n) {
		anssub += ((mint)C[n] * (mint)(1 + N - n));
	}
	ans *= anssub;

	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 7168