akhauriyash/Code-Regression huggingface dataset:
def answer(n: int, s: str) -> int:
    result = 0
    for i in range(1, n):
        x = set(s[i:])
        y = set(s[:i])
        common_characters = x.intersection(y)
        result = max(result, len(common_characters))

    return result

def main():
    n = int(input())
    s = input()
    print(answer(n,s))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9072
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int dp(vector<int> &h, vector<int> &dp_table, int N) {
	dp_table.at(0) = 0;
	dp_table.at(1) = abs(h.at(1) - h.at(0));
	for (int i = 2; i < N; i++) {
		int cost1 = abs(h.at(i) - h.at(i-1)) + dp_table.at(i-1);
		int cost2 = abs(h.at(i) - h.at(i-2)) + dp_table.at(i-2);
		dp_table.at(i) = min(cost1, cost2);
	}
	return dp_table.at(N-1);
}

int main() {
	int N;
	cin >> N;

	vector<int> h(N);
	for (int i = 0; i < N; i++) {
		cin >> h.at(i);
	}

	vector<int> table(N, -1);
	auto res = dp(h, table, N);

	cout << res << endl;
}


Measured memory_bytes: 1024
<?php
# スペース区切りの整数の入力
fscanf(STDIN, "%d %d %d %d %d", $a_price, $b_price, $ab_price, $a_amount, $b_amount);

$anser = 0;

//aとb必要な場合
if($a_amount && $b_amount){
  if (($a_price + $b_price) / 2 > $ab_price) {
    if($a_amount > $b_amount){
      $anser += $b_amount * ($ab_price * 2);
      $a_amount -= $b_amount;
      $b_amount = 0;
    }else{
      $anser += $a_amount * ($ab_price * 2);
      $b_amount -= $a_amount;
      $a_amount = 0;
    }
  } else {
    $anser += $a_amount * $a_price;
    $a_amount = 0;
    $anser += $b_amount * $b_price;
    $b_amount = 0;
  }
}

if($a_amount){
  if ($a_price > ($ab_price * 2)) {
    $anser += $a_amount * ($ab_price * 2);
  } else {
    $anser += $a_amount * $a_price;
  }  
}elseif($b_amount){
  if ($b_price > ($ab_price * 2)) {
    $anser += $b_amount * ($ab_price * 2);
  } else {
    $anser += $b_amount * $b_price;
  }
}

echo($anser);
?>

Measured memory_bytes: 4604
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<functional>
#include<cstring>
#include<iterator>
#define MAX_N 100000
#define F first
#define S second 
#define MP make_pair
using namespace std;
typedef pair<int, int> P;

const int INF = 1e9;

int main() {
	int n, m, pp, q, r;

	while (cin >> n&&n){	
		int save = -1, ans = 0;
		vector<int>vep, vep2, vep3;
		vep.push_back(1);
		vep.push_back(n);
	    vector<int> vec, vec2, vec3;
		vec.push_back(1);
		vec.push_back(n);
		cin >> m >> pp >> q >> r;
		for (int i = 0; i < m; i++) {
			int x, y, p, p2;
			scanf("%d%d", &x, &y);
			p = lower_bound(vec.begin(), vec.end(), x) - vec.begin();
			if (vec[p] != x) {
				vec.insert(vec.begin() + p, x);
				vep.insert(vep.begin() + p, vec[p] - vec[p - 1] + vep[p - 1]);
			}
			if (vec[p] + 1 != vec[p + 1]) {
				vec.insert(vec.begin() + p + 1, x + 1);
				vep.insert(vep.begin() + p + 1, vep[p] + 1);
			}
			p2 = lower_bound(vec.begin(), vec.end(), y) - vec.begin();
			if (vec[p2] != y) {
				vec.insert(vec.begin() + p2, y);
				vep.insert(vep.begin() + p2, vec[p2] - vec[p2 - 1] + vep[p2 - 1]);
			}
			if (vec[p2] + 1 != vec[p2 + 1]) {
				vec.insert(vec.begin() + p2 + 1, y + 1);
				vep.insert(vep.begin() + p2 + 1, vep[p2] + 1);
			}
			for (int j = p2 + 1; j < vec.size(); j++) {
				vec2.push_back(vec[j] - vec[p2 + 1] + 1);
				vep2.push_back(vep[j]);
			}
			int size = vec2[vec2.size() - 1];
			for (int j = p + 1; j < p2 + 1; j++) {
				vec2.push_back(vec[j] - vec[p + 1] + 1 + size);
				vep2.push_back(vep[j]);
			}
			size = vec2[vec2.size() - 1];
			for (int j = 0; j < p + 1; j++) {
				vec2.push_back(vec[j] - vec[0] + 1+size);
				vep2.push_back(vep[j]);
			}
			vec3 = vec;
			vep3 = vep;
			vec = vec2;
			vep = vep2;
			vec2 = vec3;
			vep2 = vep3;
			vec2.clear();
			vep2.clear();
		}
		int p, p2;
		p = lower_bound(vec.begin(), vec.end(), pp) - vec.begin();
		
		if (vec[p] != pp) {
			vec.insert(vec.begin() + p, pp);
			vep.insert(vep.begin() + p, vec[p] - vec[p - 1] + vep[p - 1]);
		}
		if (vec[p] + 1 != vec[p + 1]) {
			vec.insert(vec.begin() + p + 1, pp + 1);
			vep.insert(vep.begin() + p + 1, vep[p] + 1);
		}
		p2 = lower_bound(vec.begin(), vec.end(), q) - vec.begin();
		if (vec[p2] != q) {
			vec.insert(vec.begin() + p2, q);
			vep.insert(vep.begin() + p2, vec[p2] - vec[p2 - 1] + vep[p2 - 1]);
		}
		if (vec[p2] + 1 != vec[p2 + 1]) {
			vec.insert(vec.begin() + p2 + 1, q + 1);
			vep.insert(vep.begin() + p2 + 1, vep[p2] + 1);
		}
		for (int i = p; i <= p2; i++) {
			if (i + 1<=p2 && vep[i + 1] - vep[i] == vec[i + 1] - vec[i]) {
				if (vep[i + 1] <= r) {
					ans += vep[i + 1] - vep[i];
					if (save != vep[i])
						ans++;
					save = vep[i + 1];
				}
				if (vep[i] <= r&&vep[i + 1] > r) {
					ans += r - vep[i];
					if (save != vep[i])
						ans++;
					save = q;
				}
			}
			else{
				if (vep[i] <= r&&save != vep[i]) {
					ans++;
					save = vep[i];
				}
			}
	}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1764
#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;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

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

    int n, k;
    cin>>n>>k;
    vector<int>v(n);
    for(auto &x:v)
        cin>>x;
    long long s = 0;
    sort(v.begin(), v.end());
    for(int i=0;i<k;i++)
        s+=v[i];
    cout<<s;

    return 0;
}

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

vector<char> x{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char y;


int main() {
  cin >> y;
  
  for (int i = 0; i < 25; i++){
    if (y == x.at(i)) cout << x.at(i+1) << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
	using namespace std;
	#define int long long 
	#define rep(i,n) for(int i=0;i<n;i++)
	void printv(vector<char> v){
		for(int i=0;i<v.size();i++){
			cout<<v[i];
		}
		cout<<endl;
	}
	bool comp(pair<int,int>a,pair<int,int> b){
		return a.second<b.second;
	}
	bool check(int x){
		while(x!=1){
			if(x%2){
				return 0;
			}
			else x/=2;
		}
		return 1;
	}
	int tcpow(int x) {
		int pow=0;
		while(x!=0){
			x/=2;
			pow++;
		}
		return pow;
	}	
	int d,k,a,b,t;
	int funt(int y){
		if(y%k || y==0)	return a*y + (y/k)*t +b*(d-y);
		else return a*y + (y/k -1)*t +b*(d-y);
	}
	int minn=1e18;
	int findy(int start,int end){
		if(start==end) return funt(start);
		if(start>end) return INT_MAX;
		if(funt((start+end)/2)>minn) return minn;
		int a=findy(start,(start+end)/2);
		//cout<<a<<endl;
		int b=findy((start+end)/2+1,end);
		//cout<<b<<endl;
		if(minn>min(a,b)) minn=min(a,b);
		return min(a,b);

	}
	signed main(){
		int tt=1;
		//cin>>tt;
		while(tt--){
			int a;
			cin>>a;
			cout<<a+ a*a+ a*a*a<<endl;
		}
	}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;
typedef long long ll;

const int MAX = 1e5+10;
const int MOD = 1e9+7;

int N;
string S;
int count[MAX];

int main () {
    cin >> N >> S;
    for (int i = 0; i < N; i++) count[S[i] - 'a']++;
    ll ans = 1;
    for (int i = 0; i < 26; i++) {
        (ans *= (count[i]+1)) %= MOD;
    }
    cout << ans-1 << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>

int main(void){
    char a[11], b[11], c[11];

    scanf("%s %s %s", a, b, c);
    if(a[strlen(a)-1] == b[0] && b[strlen(b)-1] == c[0]){
        printf("YES");
    }else{
        printf("NO");
    }
    return 0;
}

Measured memory_bytes: 1704
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <climits>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef pair<int, int> pii;

int main()
{
	double a[11] = { 48,51,54,57,60,64,69,75,81,91,9999999999999 };
	string s[11] = { "light fly","fly","bantam","feather","light","light welter","welter","light middle","middle","light heavy","heavy" };
	double x;
	while (cin >> x)
	{
		for (int i = 0; i < 11; i++)
		{
			if (x <= a[i])
			{
				cout << s[i] << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1228
#include<stdio.h>
#include<math.h>




int main ()
{
	int n,i,j,y,x,a;
	int M[101][101];
    int S[101];

	scanf("%d",&n);
	
	
	
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&S[i-1],&S[i]);
		
	}



 
		
	for(i=1;i<=n;i++)
	{
		M[i][i]=0;
	}
	
	for(x=2;x<=n;x++)
	{
		for(i=1;i<=n-x+1;i++)
		{
		  j=i+x-1;
			M[i][j]=2147483647;
			for(y=i;y<=j-1;y++)
			{
			    a=M[i][y]+M[y+1][j]+S[i-1]*S[y]*S[j];
				if(M[i][j]>=a)
				{
					M[i][j]=a;
					} 
		  
		        
					}
        
		}
	}
	
	
	printf("%d\n",M[1][n]);




	return 0;
}



Measured memory_bytes: 2056
//Sinhaeng Hhjian
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=5e6+7;
typedef long long ll;
ll prime[maxn], book[maxn];
void prim(){
	int c=0;
	memset(book, 0, sizeof(book));
	for(ll i=2;i<maxn;i++){
		if(book[i]==0){
			prime[c++]=i;
			for(ll j=i*i;j<maxn;j+=i)
				book[j]=1;
		}
	}
}
ll qpow(ll a, ll b){
	ll ans=1;
	while(b){
		if(b%2)
			ans=ans*a;
		a*=a;
		b/=2;
	}
	return ans;
}
int main(){
	prim();
	ll n, p;
	scanf("%lld%lld", &n, &p);
	ll ans=1;
	for(int i=0;prime[i]*prime[i]<=p;i++){
		int c=0;
		while(p%prime[i]==0){
			c++;
			p/=prime[i];
		}
		if(c>=n)
			ans*=qpow(prime[i], c/n);
	}
	if(p!=1 && n==1)
		ans*=p;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 43264
import numpy as np

n, k = map(int, input().split())
z = np.zeros(10**5 + 1)
for i in range(n):
  a, b = map(int, input().split())
  z[a] += b

a = 0
for i in range(1, 10**5 + 1):
  if k <= z[i]:
    a = i
    break
  k -= z[i]

print(int(a))


Measured memory_bytes: 13140
#include <stdio.h>
#include <iostream>

using namespace std;

double a,b,c,d,e,f;
double x,y;

int main(){
  while(  cin >> a >> b >> c >> d >> e >> f ){
    printf("%.3f %.3f\n", ((c-(b*((a*f-c*d)/(a*e-b*d))))/a),(a*f-d*c)/(a*e-b*d));
  }
}

Measured memory_bytes: 1236
#include <iostream>
#include <limits.h>
#include <algorithm>

int main()
{
	int n, m, r;
	std::cin >> n >> m >> r;
	
	int rs[100];
	for (int i = 0; i < r; ++i)
	{
		std::cin >> rs[i];
		--rs[i];
	}
	
	long long int dist[310][310] = { 0 };
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			if (i != j)
				dist[i][j] = INT_MAX;
		}
	}
	
	for (int i = 0; i < m; ++i)
	{
		int a, b;
		long long int c;
		std::cin >> a >> b >> c;
		--a;
		--b;
		
		dist[a][b] = c;
		dist[b][a] = c;
	}
	
	for (int k = 0; k < n; ++k)
	{
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				if (dist[i][j] > dist[i][k] + dist[k][j])
				{
					dist[i][j] = dist[i][k] + dist[k][j];
				}
			}
		}
	}
	
	std::sort(rs, rs + r);
	
	long long int ans = LONG_MAX;
	do
	{
		long long int count = 0;
		
		for (int i = 1; i < r; ++i)
			count += dist[rs[i - 1]][rs[i]];
		
		ans = std::min(ans, count);
	} while (std::next_permutation(rs, rs + r));
	
	std::cout << ans;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
c = list(map(int , input().split()))
ans = 0
for i in range(1,n+1):
    ans += b[a[i-1]-1]
    if i < n:
        if a[i] ==  a[i-1]+1 :
            ans += c[a[i]-2]
print(ans)

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

 
int main() {

  int n,d;
  int a;
  cin>>n>>d;

  a=(1+d)+d;
  for(int i=0;i<=n;i++){
    if(a*i>=n){
      cout << i << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<map>
#include<deque>
#include<stack>
#include<algorithm>
#define N 100005
using namespace std;
const int INF=0x7fffffff;
const double Pi=acos(-1);
int A[N];
struct Data{int x,Num;}Ji[N],Ou[N];
bool Cmp(Data A,Data B)
{
	return A.Num>B.Num;
}
int main()
{
	int i,n,M=1e5,Ans;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&A[i]);
	for(i=1;i<=n;i+=2){Ji[A[i]].Num++;Ji[A[i]].x=A[i];}
	for(i=2;i<=n;i+=2){Ou[A[i]].Num++;Ou[A[i]].x=A[i];}
	sort(Ji+1,Ji+M+1,Cmp);sort(Ou+1,Ou+M+1,Cmp);
	if(Ji[1].x==Ou[1].x)Ans=min(n-Ji[1].Num-Ou[2].Num,n-Ji[2].Num-Ou[1].Num);
	else Ans=n-Ji[1].Num-Ou[1].Num;
	printf("%d\n",Ans);
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
int x[55];
ll dp[55][2505];
int main(){
    int n, a;
    scanf("%d%d", &n, &a);
    for(int i=1;i<=n;i++) scanf("%d", &x[i]);
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        for(int j=n-1;j>=0;j--){
            for(int k=j*50;k>=0;k--){
                dp[j+1][k+x[i]] = (dp[j+1][k+x[i]] + dp[j][k]);
            }
        }
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
        ans += dp[i][a*i];
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 4376
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	long long int a,b,c,d,e;
	cin>>a>>b>>c;
	d=4*a*b;
	e=(c-(a+b))*(c-(a+b));
	if(c<=a+b||e<=d){
		cout<<"No";
	}
	else cout<<"Yes";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
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; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,minN = INF,cnt=0;
	cin >> n;
	vector<ll>p(n);
	rep(i, n)cin >> p[i];
	for (ll i = 0; i < n; i++) {
		if (p[i] <= minN) {
			cnt++;
		}
		minN = min(p[i], minN);
	}
	cout << cnt << endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  vector<int> a(n), b(n), c(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) cin >> b[i];
  for(int i = 0; i < n; ++i) cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  long long cnt = 0;
  for(int i = 0; i < n; ++i) {
    cnt += (long long)(lower_bound(a.begin(), a.end(), b[i]) - a.begin()) * (n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin()));
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1536
def main():
    N = int(input())
    L = [(0, 1), (-2, 1)]
    for leng in range(2, 17):
        min_v = (-2*(4**(leng+(2-1)//2) - 1))//3
        max_v = (4**(leng+(2-1)//2) - 1)//3
        L.append((L[-1][0], max_v))
        L.append((min_v, max_v))
    # print(*L, sep='\n')
    S = [(1, 1)]
    for leng in range(1, 32):
        if leng & 1:
            S.append((L[leng][0], L[leng-1][0]-1))
        else:
            S.append((L[leng-1][1]+1, L[leng][1]))
    # print(*S, sep='\n')
    ans = ["0"] * 32
    cnt = 31
    for le, ri in S[::-1]:
        if ri < le:
            le, ri = ri, le
        if le <= N <= ri:
            ans[cnt] = "1"
            N -= (-2)**cnt
        cnt -= 1
    print(int("".join(ans[::-1])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
#define nin(n) int n; cin >> n;
#define kin(k) int k; cin >> k;
int main() {
  nin(n);
  kin(k);
  cout << n+1-k << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)

ans = []
for i in range(m) :
  if a[i] < sum(a) / (4 * m) :
    continue
  else :
    ans.append(a[-1])

if len(ans) == m :
  print('Yes')
else :
  print('No')

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
    
	int A, B;
	int m = scanf("%d %d", &A, &B);
	if (m == EOF) {
		printf("scan error!\n");
		return 0;
	}

	//printf("%d\t%d\t%d\n", A, B, C);


	int add = A + B;
	int rest = A - B;
	int seki = A * B;
	
	if (add > rest) {
		if (add > seki) {
			printf("%d\n", add);
		}
		else {
			printf("%d\n", seki);
		}
	}
	else {
		if (rest > seki) {
			printf("%d\n", rest);
		}
		else {
			printf("%d\n", seki);
		}
	}
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <random>
#include <chrono>
#include <bitset>
#include <fstream>
#include <sstream>

using namespace std;

typedef long long ll;
typedef long double ld;

ll big = 1000000007ll;
float likeabutterfly;
string likeabee;
ll n,m,q,h,k,w;
ll T;

vector<ll> C;
map<ll,ll> M;
vector<ll> B;


int main()
{
    ll c1,c2,c3,c4,c5,c6;
    ll a,b,c,e,g;
    ll x,y,z;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);


    cin >> n;
    for(c1 = 0; c1 < n; c1++){
        cin >> a;
        C.push_back(a);
        B.push_back(a);

    }
    sort(B.begin() , B.end());

    for(c1 = 0; c1 < n; c1++){
        M[B[c1]] = c1;
    }
    for(c1 = 0; c1 < n; c1++){
        C[c1] = M[C[c1]];
    }
    ll ans = 0;

    ll where = 0;
    for(c1 = 0; c1 < n; c1++){

       if(C[c1] % 2 == 0){

        ans += c1%2;


       }

    }

    cout << ans<< "\n";


	return 0;
}




Measured memory_bytes: 8044
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = Console.ReadLine();
			var sLength = s.Length;
			var startIndex = 0;
			var endIndex = 0;

			for(int i = 0; i < sLength; i++)
			{
				if(s[i] == 'A')
				{
					startIndex = i;
					break;
				}
			}
			for(int i = sLength - 1; i >= 0; i--)
			{
				if(s[i] == 'Z')
				{
					endIndex = i;
					break;
				}
			}

			Console.WriteLine(endIndex - startIndex + 1);
        }
	}
}


Measured memory_bytes: 11616
def main():
    x = input()
    l = x.split(" ")
    A = int(l[0])
    B = int(l[1])

    if A == B:
        print("Draw")
    elif A == 1:
        print("Alice")
    elif B == 1:
        print("Bob")
    elif A > B :
        print("Alice")
    elif A < B :
        print("Bob")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n,index;
    cin>>n;
    int k=int(sqrt(2*n));
    if(k*(k+1)==2*n){
        k++;
        cout << "Yes\n"<<k<<endl;
        vector<vector<int> > ans(k);
        for(int i=0;i<k;i++){
            index=0;
            for(int j=(i*(i-1)/2)+1;j<=i*(i+1)/2;j++,index++){
                ans[index].pb(j);
            }
            for(int j=(i*(i-1)/2)+1;j<=i*(i+1)/2;j++,index++){
                ans[i].pb(j);
            }
        }
        for(int i=0;i<k;i++){
            cout<< k-1<<" ";
            for(int j=0;j<k-1;j++){
                cout <<ans[i][j]<<" ";
            }
            cout << endl;
        }
    }
    else{
        cout << "No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 2304
n = int(input())
lst = [int(input()) for i in range(n)]
m = max(lst)
tmp = lst[:]
del tmp[tmp.index(max(tmp))]
s = max(tmp)
if lst.count(m) > 1:
  for i in range(n):
    print(m)
else:
  for i in range(n):
    if lst[i]==m:
      print(s)
    else:
      print(m)
  


Measured memory_bytes: 70104
#include <iostream>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define pb push_back
#define MOD 1000000007
#define ll long long

int main(void)
{
  int n;
  cin >> n;

  //A: 0, G: 1, C: 2, T: 3
  int A = 0, G = 1, C = 2, T = 3;
  vec<vec<vec<ll>>> dp(4, vec<vec<ll>>(4, vec<ll>(4, 1)));
  dp[A][G][C] = 0;
  dp[A][C][G] = 0;
  dp[G][A][C] = 0;
  rep(i, n) {
    if (i < 3) continue;
    vec<vec<vec<ll>>> ndp(4, vec<vec<ll>>(4, vec<ll>(4, 0)));
    
    rep(x, 4) rep(y, 4) rep(z, 4) {
      rep(w, 4) ndp[y][z][w] += dp[x][y][z];
      if (y == A && z == G) {
        ndp[y][z][C] -= dp[x][y][z];
      } else if (y == G && z == A) {
        ndp[y][z][C] -= dp[x][y][z];
      } else if (y == A && z == C) {
        ndp[y][z][G] -= dp[x][y][z];
      } else if (x == A && y == G) {
        ndp[y][z][C] -= dp[x][y][z];
      } else if (x == A && z == G) {
        ndp[y][z][C] -= dp[x][y][z];
      }
      rep(w, 4) ndp[y][z][w] %= MOD;
    }
    dp = ndp;
  }
  ll ans = 0;
  rep(x, 4) rep(y, 4) rep(z, 4) ans = (ans + dp[x][y][z]) % MOD;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define for_t int t;cin>>t;while(t--)
#define MOD 1000000007
#define fi first
#define se second
#define le length
#define debug(n1) cout << n1 << endl
#define set_bits(n) __builtin_popcount(n);
#define rep(i , j , n) for(ll i = j ; i <= n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef map<int, int>mapp;

void func(int arr[], int n, vector<int> &ans) { 
  stack < int > s;
  s.push(0); 
  rep(i,1,n-1){ 
    if (s.empty()){ 
      s.push(i); 
      continue; 
    }
    while (s.empty() == false && arr[s.top()] < arr[i]) 
    {          
        ans[s.top()]=i; 
        s.pop(); 
    } 
    s.push(i); 
  } 
  while (s.empty() == false) { 
    ans[s.top()]=-1; 
    s.pop(); 
  }
}


int main() {
    SPEED;
    int n;
    cin>>n;
    vi vec(n);
    rep(i,0,n-1){
        cin>>vec[i];
    }
    int tans =0;
    int ans = 0;
    per(i,n-1,1){
        if(vec[i]<=vec[i-1]){
            tans++;
            ans =max(ans, tans);
        }
        else{
            tans = 0;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 640
from collections import Counter

N = int(input())
S = [input() for i in range(N)]

c = Counter(S)
mc = c.most_common()
L = []
for p in mc:
    if p[1] < mc[0][1]:
        break
    L.append(p[0])
L.sort()
for l in L:
    print(l)


Measured memory_bytes: 47636
#include<iostream>

using namespace std;

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

	cin>>n;
    if(n<=1000)
	{
	for(int i=0;i<n;i++)
		{
		cin>>a>>b>>c;
		if( a<=1000 , a>0 , b<=1000 , b>0 , c<=1000 , c>0)
			{
			a = a*a;
			b = b*b;
			c = c*c;
			if( a+b ==c || a+c == b || c+b ==a )
				{
					cout<<"YES"<<endl;
				}
			else
				{
					cout<<"NO"<<endl;
				}
			}
		}
	}

}

Measured memory_bytes: 1156
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>

using namespace std;

int main()
{
        // 整数の入力
    long long N,ai,i,total;
    cin >> N;
    total = 0;
    for (i=0;i<N;i++){
        cin >> ai;
        while (ai % 2 == 0){
            ai = ai/2;
            total++;
        }
    }

    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
#define pb push_back

typedef long long ll;
using namespace std;
int MOD = 1000000007;
int N;
int A[100000];
int b, idx;
ll powMod(int a, int n, int m){
  ll pro = 1, tmp = a;
  for(; n > 0; n >>= 1){
    if(n & 1) pro = (pro * tmp) % m;
    tmp = tmp * tmp % m;
  }
  return pro;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  FOR(i, 0, N) cin >> A[i];
  sort(A, A + N);
  b = N % 2;
  FOR(i, 0, N){
    if(A[i] != (i + b) / 2 * 2 + 1 - b){
      cout << 0 << endl;
      return 0;
    }
  }
  cout << powMod(2, N / 2, MOD) << endl;
  return 0;
}


Measured memory_bytes: 640
#include <atcoder/convolution>
#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace atcoder;
using namespace std;

typedef long long ll;

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	vector<ll> a(n, 0), b(m, 0);
	for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
	for (int i = 0; i < m; ++i) scanf("%lld", &b[i]);
	auto conv = convolution(a, b);
	for (ll e : conv) printf("%lld ", e);
}

Measured memory_bytes: 27196
#include <iostream>
using namespace std;
int main()
{
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(x-r<0||y-r<0||x+r>W||y+r>H)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3108
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		int C = scan.nextInt();
		List<Integer> bList = new ArrayList<>();

		int ans = 0;

		for (int i = 0; i < M; i++) {
			bList.add(scan.nextInt());
		}

		for (int i = 0; i < N; i++) {
			long temp = 0;

			for (int j = 0; j < M; j++) {
				temp += bList.get(j) * scan.nextInt();
			}
			if(temp + C > 0){
				ans++;
			}

		}
		System.out.println(ans);
		scan.close();
	}
}


Measured memory_bytes: 23380
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE


static int ANS = 0;
void DFS(int V,vector<vector<int> >&GRAPH,vector<int>& used, vector<int>& LIS, vector<int> & data,vector<int> & ANS)
{
  if(used[V] == 1)return;
  used[V] = 1;
  // DEBUG(V);
  int P = data[V];
  auto itr = lower_bound(ALL(LIS),P);
  int mem = *itr;
  *itr = P;
  int SIZE = distance(LIS.begin(),lower_bound(ALL(LIS),INF));
  ANS[V] = SIZE;
  for (int i = 0; i < GRAPH[V].size(); i++)
  {
    if(used[GRAPH[V][i]] == 0)
    {
      DFS(GRAPH[V][i],GRAPH,used,LIS,data,ANS);
    }
  }
  *itr = mem;

  

  return;
}

void solve(void)
{
  int N;
  cin>>N;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
  }
  vector<vector<int> > GRAPH(N);
  for (int i = 0; i < N-1; i++)
  {
    int A,B;
    cin>>A>>B;
    A--;B--;
    GRAPH[A].push_back(B);
    GRAPH[B].push_back(A);
  }
  vector<int> used(N,0);
  vector<int> LIS(N+1,INF);
  vector<int> ANS(N,0);
  DFS(0,GRAPH,used,LIS,vec,ANS);
  for (int i = 0; i < N; i++)
  {
    cout<<ANS[i]<<endl;
  }
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 37428
#include<bits/stdc++.h>
#define pa pair<int,int>
#define CLR(a,x) memset(a,x,sizeof(a))
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
const int maxn=1e5+10;

inline char gc(){
	return getchar();
	static const int maxs=1<<16;static char buf[maxs],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxs,stdin),p1==p2)?EOF:*p1++;
}
inline ll rd(){
    ll x=0;char c=gc();bool neg=0;
    while(c<'0'||c>'9'){if(c=='-') neg=1;c=gc();}
    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();
    return neg?(~x+1):x;
}

int N,p[maxn][2],r[maxn],d[maxn],l[maxn],u[maxn],rnk[maxn];
map<int,int> rl,dl,sl,ul;
bool flag[maxn];
ll ans;
int c1,c2;
bool xh[maxn],yh[maxn];
int stk[maxn],sh;

inline bool cmp1(int a,int b){
	return p[a][0]==p[b][0]?p[a][1]<p[b][1]:p[a][0]<p[b][0];
}

void dfs(int x){
	if(flag[x]) return;
	flag[x]=1;
	stk[++sh]=x;
	if(!xh[p[x][0]]) c1++;
	if(!yh[p[x][1]]) c2++;
	xh[p[x][0]]=yh[p[x][1]]=1;
	if(r[x]) dfs(r[x]);
	if(d[x]) dfs(d[x]);
	if(l[x]) dfs(l[x]);
	if(u[x]) dfs(u[x]);
}

int main(){
    //freopen("","r",stdin);
    N=rd();
    for(int i=1;i<=N;i++) p[i][0]=rd(),p[i][1]=rd(),rnk[i]=i;
    sort(rnk+1,rnk+N+1,cmp1);
	for(int x=N;x;x--){
		int i=rnk[x];
		r[i]=rl[p[i][1]];
		rl[p[i][1]]=i;
		d[i]=dl[p[i][0]];
		dl[p[i][0]]=i;
	}for(int x=1;x<=N;x++){
		int i=rnk[x];
		l[i]=sl[p[i][1]];
		sl[p[i][1]]=i;
		u[i]=ul[p[i][0]];
		ul[p[i][0]]=i;
	}
	
	for(int x=1;x<=N;x++){
		int i=rnk[x];
		if(flag[i]) continue;
		// printf("%d %d %d %d %d\n",i,l[i],r[i],d[i],u[i]);
		c1=0,c2=0;
		dfs(i);
		for(;sh;sh--) xh[p[stk[sh]][0]]=yh[p[stk[sh]][1]]=0;
		ans+=1ll*c1*c2;
	}
	printf("%lld\n",ans-N);
    return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

int lcm(int x, int y){
	int g = gcd(x,y);
	return x/g*y;
}

int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum = (sum%MOD*i%MOD)%MOD;
    }
    return sum;
}

int main(){
	int n,m; cin >> n >> m;
	if (abs(n-m) > 1){
		cout << 0 << endl;
		return 0;
	}
	int d = 1;
	if (n==m) d = 2;
	n = facctorialMethod(n);
	m = facctorialMethod(m);
	cout << (n%MOD*m%MOD*d)%MOD << endl;
}

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

using namespace std;

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

    int n, cnt = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int a;
        cin >> a;
        if (i % 2 == 1 && a % 2 == 1)
            cnt++;
    }
    cout << cnt << endl;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int X;
	cin >> X;

	int ret = 8;

	if(400 <= X && X <= 599){ ret = 8;}
	else if(600 <= X && X <= 799){ ret = 7;}
	else if(800 <= X && X <= 999){ ret = 6;}
	else if(1000 <= X && X <= 1199){ ret = 5;}
	else if(1200 <= X && X <= 1399){ ret = 4;}
	else if(1400 <= X && X <= 1599){ ret = 3;}
	else if(1600 <= X && X <= 1799){ ret = 2;}
	else if(1800 <= X && X <= 1999){ ret = 1;}

	printf("%d\n", ret);
	return 0;
}


Measured memory_bytes: 3784
/*
最初にスタート地点からでるときはスピードが１でなければならないのを忘れてた
ゴールは到着したら即終了というわけではない
というかゴールにスピード１以外で到着しても良い（でもゴールしたいときは１でないといけない）
*/

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<cmath>
#include<cstdio>
#include<queue>
#include<iomanip>
#include<deque>
#define F first
#define S second
#define MAX_N 32
#define MAX_D 32
#define INF (1<<28)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;
typedef pair<double,double> P;
typedef pair<int,P> iP;
typedef pair<int,int> iiP;
typedef pair<iiP,P> PP;
typedef vector<vector<iP> > VViP;
int n,m,s,g;
VViP G;
double mincost[MAX_N][MAX_N][MAX_D]; // mincost[from][to][speed]
int sp[] = {-1,0,+1};

void dijkstra()
{

  deque<PP> deq; // iiPP(iiP(now,pre),P(cost,speed))

  
  deq.push_front(PP(iiP(s,s),P(0,1)));

  mincost[s][s][1] = 0; 
  double ans = INF;  

  
  while(!deq.empty())
    {
      PP p = deq.front(); deq.pop_front();
      int now,pre;
      double cost,speed;
      now = p.F.F, pre = p.F.S;
      cost = p.S.F, speed = p.S.S;

      if(cost >= ans)
	continue;      

      if(now == g && speed == 1)
	{
	  ans = min(ans,cost);	
	  continue;
	}	

      for(int i=0;i<G[now].size();i++)
	{
	  iP ip = G[now][i]; // VViP -> iP(to,P(distance,limit))
	  int to = ip.F;
	  double dis,lim;
	  dis = ip.S.F, lim = ip.S.S;
	  if(pre == to)
	    continue;

	  for(int j=0;j<3;j++)
	    {
	      double new_speed = speed + sp[j];
	      if(new_speed <= 0 || new_speed > lim)
		continue;

	      if(now == s && pre == s && new_speed != 1)
		continue;

	      if(mincost[now][to][(int)new_speed] > cost + (double)dis/new_speed)
		{
		  mincost[now][to][(int)new_speed] = cost + (double)dis/new_speed;
		  if(mincost[now][to][(int)new_speed] < deq.front().S.F)deq.push_front(PP(iiP(to,now),P(mincost[now][to][(int)new_speed],new_speed)));
		  else 
		    deq.push_back(PP(iiP(to,now),P(mincost[now][to][(int)new_speed],new_speed)));
		}
	    }

	}

    }
  

  if(ans == INF)
    cout << "unreachable" << endl;
  else 
    cout << setiosflags(ios::fixed) << setprecision(5) << ans << endl;
  
}

int main()
{

  while(true)
    {
      cin >> n >> m;
      if(n+m == 0)
	break;
      G.clear();
      G.resize(n+1);
      rep(i,n+1)
	rep(j,n+1)
	  rep(k,31)
	    mincost[i][j][k] = INF;

      cin >> s >> g;
      rep(i,m)
	{
	  int x,y;
	  double d,c;
	  cin >> x >> y >> d >> c;
	  G[x].push_back(iP(y,P(d,c)));
	  G[y].push_back(iP(x,P(d,c)));
	}
      
      dijkstra();
  
    }
  return 0;
}

Measured memory_bytes: 3432
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < n-2; i++) {
        for (int j = i+1; j < n-1; j++) {
            int k = lower_bound(a+j+1, a + n, a[i]+a[j]) - a-j-1;
            ans += k;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {

			const int Num = 10;
			int[] Heights = new int[Num];
			for(int i = 0 ; i < Num ; i++)
			{

				String In = Console.ReadLine();
				Heights[i] = int.Parse(In);

			}

			Array.Sort<int>(Heights, (a,b) => b - a);
			const int OutNum = 3;
			for(int i = 0 ; i < OutNum; i++)
			{

				Console.WriteLine(Heights[i].ToString());

			}
			
        }

    }
}

Measured memory_bytes: 9156
//I am so vegetable
#include <bits/stdc++.h>
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _defor(i,a,b) for((i) = (a);(i)<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
//#define _LOCAL_
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll N = 2005;
const int MOD = 1e9 + 7;
const double exps = 1e-6;
int qpow(int n, int y) {
	int ans = 1;
	while (y) {
		if (y & 1)ans *= n;
		n *= n;
		y >>= 1;
	}
	return ans;
}
int main() {
#ifdef _LOCAL_
	ifstream cin("E:\\acm dream\\in.txt");
	ofstream cout("E:\\acm dream\\out.txt");
#endif
	//srand((unsigned)time(nullptr));
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n, k; cin >> n >> k;
	cout << qpow(k - 1, n - 1) * k << '\n';
	return 0;
}

Measured memory_bytes: 256
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

#define ALL(set) (set).begin(), (set).end()

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	int n, a, b;
	cin >> n >> a >> b;
	int answer = 0;
	for(int i = 1; i <= n; ++i)
	{
		string number = to_string(i);
		int result = 0;
		for(auto &c : number) result += (c - '0');
		if(result >= a && result <= b) answer += i;
	}
	cout << answer << '\n';
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

map<ll, unordered_map<ll, ll>> memo;

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

int n;
ll a[MAX_N];

ll ans;

ll forward_vec[MAX_N];
ll backward_vec[MAX_N];

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%lld", &(a[i]));
  }

  forward_vec[0] = a[0];
  for (int i = 1; i < n; ++i) {
    forward_vec[i] = gcd(forward_vec[i - 1], a[i]);
  }

  backward_vec[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    backward_vec[i] = gcd(backward_vec[i + 1], a[i]);
  }

  ans = -1;

  for (int i = 0; i < n; ++i) {
    int left = i - 1;
    int right = i + 1;

    if (left < 0) {
      ans = max(ans, backward_vec[right]);
    } else if (right >= n) {
      ans = max(ans, forward_vec[left]);
    } else {
      ans = max(ans, gcd(forward_vec[left], backward_vec[right]));
    }
  }

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

  return 0;
}


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

using namespace std;

class DisjoinSet
{
public:
    vector<int> rank, p;

    DisjoinSet() {}
    DisjoinSet(int size)
    {
        rank.resize(size, 0);
        p.resize(size, 0);
        for (int i = 0; i < size; i++)
        {
            makeSet(i);
        }
    }
    void makeSet(int x)
    {
        p[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y)
    {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y)
    {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y)
    {
        if (rank[x] > rank[y])
        {
            p[y] = x;
        }
        else
        {
            p[x] = y;
            if (rank[x] == rank[y])
            {
                rank[y]++;
            }
        }
    }

    int findSet(int x)
    {
        if (x != p[x])
        {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main()
{
    int n, a, b, q;
    int t;
    cin >> n >> q;
    DisjoinSet ds = DisjoinSet(n);

    for (int i = 0; i < q; i++)
    {
        cin >> t >> a >> b;
        if (t == 0)
        {
            ds.unite(a, b);
        }
        else if (t == 1)
        {
            if (ds.same(a, b))
            {
                cout << 1 << endl;
            }
            else
            {
                cout << 0 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int lli;
typedef pair<int,int> pii;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N,M;
	while(true){
		cin >> N >> M;
		if(!N&&!M) break;
		vector<lli> C(M),x(N+1);
		REP(i,0,M) cin >> C[i];
		REP(i,1,N+1) cin >> x[i];
		vector<vector<lli>> dp(N+1,vector<lli>(256,INF_));
		dp[0][128]=0;
		lli ans=INF_;
		REP(i,0,N+1){
			REP(j,0,256){
				if(i!=N){
					REP(k,0,M){
						lli v=j+C[k];
						if(v<0) v=0;
						if(v>=256) v=255;
						dp[i+1][v]=min(dp[i+1][v],dp[i][j]+(v-x[i+1])*(v-x[i+1]));
					}
				}
				if(i==N) ans=min(ans,dp[i][j]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

bool solve(int n, int *a) {
	int min = *std::min_element(a, a + n);
	int max = *std::max_element(a, a + n);
	if (max - min > 1) return false;
	if (max == min) return min <= n / 2 || min == n - 1;
	int min_cnt = std::count(a, a + n, min);
	int max_cnt = n - min_cnt;
	if (max_cnt == 1) return false;
	return max >= min_cnt + 1 && max <= min_cnt + max_cnt / 2;
}

int main() {
	int n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	std::cout << (solve(n, a) ? "Yes" : "No") << std::endl;
	
	return 0;
}



Measured memory_bytes: 640
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 120000
using namespace std;
namespace IO{
	const int BS=(1<<20)+5; int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD,*TL,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout);}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush(),OS=OT;}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top;
	}
	int read(){
		int nm=0,fh=1; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}
using namespace IO;
LL n,m,p[M],l,r,t[M],ans1,ans2,sum1,sum2,sum,ans;
int main(){
	n=read();
	for(LL i=1;i<=n;i++) p[i]=read();sort(p+1,p+n+1);
	if(n==3){printf("%lld\n",p[n]-p[1]+max(p[n]-p[2],p[2]-p[1]));return 0;}
	if(n&1){
		for(LL i=1;i<((n+1)>>1)-1;i++) ans1-=2*p[i];
		ans1-=p[(n+1)>>1]+p[((n+1)>>1)-1];
		for(LL i=n;i>((n+1)>>1);i--) ans1+=2*p[i];
		
		for(LL i=n;i>((n+1)>>1)+1;i--) ans2+=2*p[i];
		ans2+=p[(n+1)>>1]+p[((n+1)>>1)+1];
		for(LL i=1;i<((n+1)>>1);i++) ans2-=2*p[i];
		
		ans=max(ans1,ans2);
	}
	else{
		for(LL i=1;i<=n/2;i++) ans+=p[i+(n/2)]-p[i];
		for(LL i=1;i<n/2;i++) ans+=p[n-i+1]-p[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024