akhauriyash/Code-Regression huggingface dataset:
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
MOD = 10 ** 9 + 7

zeros = A.select(&:zero?)
minus = A.select(&:negative?).sort
plus = A.select(&:positive?).sort

def select_max(zeros, minus, plus)
  mcnt = minus.size
  pcnt = plus.size
  k = K
  val = 1

  while k > 0
    if mcnt >= 2 && pcnt >= 2 && k >= 2
      pv = plus[-2] * plus[-1]
      mv = minus[0] * minus[1]

      if pv < mv
        val *= mv

        minus.shift(2)
        mcnt -= 2
        k -= 2
      else
        val *= plus.pop

        pcnt -= 1
        k -= 1
      end
    elsif mcnt >= 2 && k >= 2
      a, b = minus.shift(2)

      val *= (a * b)

      mcnt -= 2
      k -= 2
    elsif pcnt >= 2 && k >= 2
      a, b = plus.pop(2)

      val *= (a * b)

      pcnt -= 2
      k -= 2
    elsif pcnt >= 1
      val *= plus.pop

      pcnt -= 1
      k -= 1
    elsif mcnt >= 1
      return -1
    else
      return 0
    end

    val %= MOD
  end

  val
end

def select_min(zeros, minus, plus)
  val = 1

  A.sort_by { |a| a.abs }.take(K).each { |a|
    val *= a
    val %= MOD
  }

  val
end

max_v = select_max(zeros.dup, minus.dup, plus.dup)

if max_v >= 0
  puts max_v
elsif zeros.size > 0
  puts 0
else
  puts select_min(zeros.dup, minus.dup, plus.dup)
end



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

int dp[4000][4000];
int b[4000];
int sum[4000];

int main(){
	int n,m;cin>>n>>m;
	string s;cin>>s;
	vector<P>v;
	rep(i,m){
		int l,r;scanf("%d%d",&l,&r);l--;r--;
		if(v.empty())v.push_back(P(l,r));
		else if(v.back().first==l)v.back().second=max(v.back().second,r);
		else if(v.back().second<r)v.push_back(P(l,r));
	}
	for(auto p:v)b[p.first]=p.second;
	for(int i=1;i<n;i++)b[i]=max({i,b[i],b[i-1]});
	int cnt=0;
	rep(i,n){
		if(s[i]=='1')cnt++;
		sum[i]=cnt;
	}
	dp[0][cnt]=1;
	rep(i,n)rep(j,cnt+1){
		if(dp[i][j]==0)continue;
		int a=j-(sum[n-1]-sum[b[i]]);
		if(a)(dp[i+1][j-1]+=dp[i][j])%=MOD;
		if(b[i]-i+1-a)(dp[i+1][j]+=dp[i][j])%=MOD;
	}
	cout<<dp[n][0]<<endl;
}

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

int main()
{
	int a, b, c;
	cin >> a;
	int i = a;
	int x = 0;
	cin >> b >> c;
	while (i <= b) {
		if (c % i == 0) {
			x = x + 1;
		}
		i++;
	}
	cout << x << endl;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin>>n;
    vector<int> A,B,C;
    long long a,b,c;
    for(int i=0;i<n;i++){
        cin>>a>>b>>c;
        A.push_back(a);
        B.push_back(b);
        C.push_back(c);
    }
    vector<vector<long long int>> dp(3,vector<long long int>(n,0));
    for(int i=0;i<n;i++){
        dp[0][i]=A[i];
        dp[1][i]=B[i];
        dp[2][i]=C[i];
    }


    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            long long int val=INT_MIN;
            for(int k=0;k<3;k++){
                if(k!=j){
                    val=max(val,dp[k][i-1]);
                }
            }
            dp[j][i]=dp[j][i]+val;
        }
    }
    cout<< max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));

}


Measured memory_bytes: 4844
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy[4] = {-1, 0, +1, 0};
int dx[4] = {0, +1, 0, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------

ll n;

void search(ll i, bool seven, bool five, bool three, ll &ans){
    if(i > n)return;
    if(seven && five && three)ans++;

    search(i * 10 + 7, true, five ? true : false, three ? true :false, ans);
    search(i * 10 + 5, seven ? true : false, true, three ? true : false, ans);
    search(i * 10 + 3, seven ? true : false, five ? true : false, true, ans);
}

int main(void){
    cin >> n;
    ll ans = 0;
    search(0, false, false ,false, ans);
    cout << ans << endl;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
typedef long long ll;
vector<ll> v[300000];
priority_queue<ll> pq;
int main(void){
	int n;
	cin >> n;
	ll taxy[n];
	fill(taxy, taxy + n, 0);
	for(int i = 0; i < n; i++){
		int q;
		cin >> q;
		for(int j = 0; j < q; j++){
			int a;
			cin >> a;
			v[i].push_back(a);
		}
	}
	ll sum = 0;
	for(int i = n - 1; i >= 0; i--){
		for(int j = 0; j < v[i].size(); j++) pq.push(v[i][j]);
		if(taxy[i] < pq.top()){
			taxy[i] = pq.top();
			pq.pop();
		}
		sum += taxy[i];
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 21856
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

kkk = []

for i in range(n):
    kkk.append(l())

su = 0


for i in range(n-1):
    for j in range(i+1,n):
        su += math.sqrt((kkk[i][0] - kkk[j][0])**2 + (kkk[i][1] - kkk[j][1])**2)

print(su/(n/2))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;
const int MAX = 710000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
 
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(){
    ll x, y, i, j;
    ll ans=1;
    cin >> x >> y;
    if((x+y) % 3 != 0){
        cout << 0;
        exit(0);
    }
    i = (2*x - y)/3;
    j = (2*y - x)/3;
    if(i < 0 || j < 0){
        cout << 0;
    }
    else {
        COMinit();
        cout << COM(i+j, i) % mod;
    }
}  

Measured memory_bytes: 16896
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long int n, k, a, b, c, x, y,ans;
int main()
{
	cin >> n >> k;
	for (int i = 0; i < k; i++)
	{
		cin >> x >> y;
		a = min(x, n-x+1);
		b = min(y, n - y+1);
		c = min(a, b);
		ans = c % 3;
		if (ans == 0)
			ans = 3;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
import math
import itertools
subete=1
n=int(input())
ichi=[]
for i in range(n):
	ichi.append(list(map(int,input().split())))
for i in range(1,n+1):
	subete=subete*i
route=[]
for i in itertools.permutations(range(n)):
	route.append(i)
gokei=0
for i in range(len(route)):
	kari=0
	for j in range(1,n):
		kari+=math.sqrt((ichi[route[i][j]][0]-ichi[route[i][j-1]][0])**2+(ichi[route[i][j]][1]-ichi[route[i][j-1]][1])**2)
	gokei+=kari
print(gokei/(subete))

Measured memory_bytes: 8052
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut aseq = vec![0; n];
    for i in 0..n {
        aseq[i] = read::<i64>();
    }
    let mut ans = 1 << 60;
    for &s in [1, -1].iter() {
        let mut sign = s;
        let mut sum = 0;
        let mut lans = 0;
        for i in 0..n {
            sum += aseq[i];
            if sum * sign <= 0 {
                lans += (sum - sign).abs();
                sum = sign;
            }
            sign *= -1;
        }
        ans = std::cmp::min(ans, lans);
    }
    println!("{}", ans);
}


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n), rp(n);
  for(int i=0; i<n; i++){
    cin >> p[i];
    rp[i]=p[i];
  }

  sort(p.begin(), p.end());
//  for(int i=0; i<n; i++){
//    cout << p[i] << endl;;
//  }

  int cnt=0;
  for(int i=0; i<n; i++){
    if(p[i]!=rp[i]) cnt++;
  }

  if(cnt==2 || cnt==0) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
def search(ans, i=0):
    if i == 3:
        if ans == 7:
            print('{0[0]}{1[0]}{0[1]}{1[1]}{0[2]}{1[2]}{0[3]}=7'.format(value,opr))
            sys.exit()
        return
    for j in range(3):
        ans -= int(value[i+1])
        opr.append('-')
        search(ans, i+1)
        ans += int(value[i+1])
        opr.pop(i)

        opr.append('+')
        ans += int(value[i+1])
        search(ans, i+1)
        ans -= int(value[i+1])
        opr.pop(i)
    return

value = input()
ans = int(value[0])
opr = []
search(ans)


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>;
const int INF = 1001001001;
int main(){
  int N,M;
  cin>>N;
  map<string,int>S;
  string s,t;
  for(int i=0;i<N;i++){
   cin>>s;
   S[s]++;
   }
   map<string,int>T;
  cin>>M;
  for(int i=0;i<M;i++){
    cin>>t;
   T[t]++;
   }
  int ans=0;
  for(auto p : S){
    auto k=p.first;
    auto v=p.second;
    ans=max(ans,p.second-T[k]);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6;
int x[N];
int main(){
	int n, k;
	scanf("%d %d",&n,&k);
		memset(x,0,sizeof(x));
		int r, s, p;
		string str;
		scanf("%d %d %d",&r,&s,&p);
		getchar();
		cin >> str;
		long long ans = 0;
		for(int i = 0; i < n; i++){
			if(str[i] == 'r'){
				if(i < k){
					ans += p;
					x[i] = 1;
				} 
				else if(x[i-k] != 1) {
					ans += p;
					x[i] = 1;
				}
				else x[i] = 0;				
			}
			else if(str[i] == 's'){
				if(i < k){
					ans += r;
					x[i] = 2;
				} 
				else if(x[i-k] != 2) {
					ans += r;
					x[i] = 2;			
				}
				else x[i] = 0;
			}
			else if(str[i] == 'p'){
				if(i < k){
					 ans += s;
					 x[i] = 3;
				}
				else if(x[i-k] != 3) {
					ans += s;
					x[i] = 3;					
				}
				else x[i] = 0;
			}
		}
		printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll n;
string s;

template< class T >
struct CumulativeSum {
  vector< T > data;

  CumulativeSum(int sz) : data(sz, 0) {};

  void add(int k, T x) {
    data[k] += x;
  }

  void build() {
    for(int i = 1; i < data.size(); i++) {
      data[i] += data[i - 1];
    }
  }

  T query(int k){
    if(k < 0) return (0);
    return (data[min(k, (int) data.size() - 1)]);
  }

  T query(int l,int r){// 区間[l,r]
	return query(r) - query(l - 1);
  }
};

int main(){
	cin >> n >> s;
	CumulativeSum<ll> cnt(n);
	rep(i,n){
		if(s[i] == 'E')cnt.add(i,1);
	}
	cnt.build();
	ll ans = INF;
	rep(i,n){
		// cout << cnt.query(i-1) << " " << cnt.query(i+1,n-1) << endl;
		ans = min(ans, i - cnt.query(i-1)+ cnt.query(i+1,n-1));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3076
N=int(input())
T=[]
X=[]
Y=[]
for i in range(N):
    t,x,y=map(int,input().split())
    T.append(t)
    X.append(x)
    Y.append(y)
count=0
t,x,y=0,0,0
for i in range(N):
    # |x-X|+|y-Y|<=t-T
    # t%2=(x+y)%2
    if abs(X[i]-x)+abs(Y[i]-y)<=T[i]-t and T[i]%2==(X[i]+Y[i])%2:
        count+=1
    t,x,y=T[i],X[i],Y[i]
if count==N:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 11840
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,cnt=1;
	cin>>a>>b;
	int s=b-a+1;
	if(a>0)cout<<"Positive"<<endl;
	else if(a<=0 && b>=0)cout<<"Zero"<<endl;
	else if(a<0 && b<0 && s%2!=0)cout<<"Negative"<<endl;
	else if(s%2==0)cout<<"Positive"<<endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define all(v) begin(v),end(v)
#define pb push_back
#define inf (1e9)
#define eps (1e-9)

typedef long long Integer ;
typedef long double Real;
const Real PI = acosl(-1);
typedef pair<int, int> P;

template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  return os << '('
    << get<0>(t) << ", "
    << get<1>(t) << ", "
    << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, set<T> v) {
  os << "(set";
  for (T item: v) os << ' ' << item;
  os << ")";
  return os;
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
  if (v.size() == 0) { return os << "(empty)"; }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
  rep (i, v.size()) is >> v[i];
  return is;
}

//           ^   >  v   <
int dx[] = { -1, 0, 1,  0 };
int dy[] = {  0, 1, 0, -1 };

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<bool> vb;

int d[200];

int main() {

  int n, q;
  while (cin >> n >> q, n and q) {
    rep (i, 200) d[i] = 0;
    rep (_, n) {
      int m; cin >> m;
      rep (__, m) {
        int x; cin >> x;
        d[x]++;
      }
    }
    int ans = 0;
    int mx = 0;
    rep (i, 200) {
      if (d[i] >= q and mx < d[i]) {
        mx = d[i];
        ans = i;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

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

using ll = long long;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

int S[10002];

void init(int n) {
	rep(i, n)S[i] = i;
}

int root(int x) {
	return S[x]==x ? x : S[x] = root(S[x]);
}

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

void unite(int x, int y) {
	if(root(x) != root(y))S[S[x]] = S[y];
}

int main(){
	cin.tie(0);
	
	int n, q;
	cin>>n>>q;
	
	init(n);
	
	rep(i, q) {
		int c, x, y;
		cin>>c>>x>>y;
		if(c)cout<<same(x, y)<<endl;
		else unite(x, y);
	}

	return 0;
}



Measured memory_bytes: 3248
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k; string s;
	cin >> n >> s >> k;
	rep(i, 0, n) {
		if (s[i] != s[k - 1]) s[i] = '*';
	}
	cout << s;
	return 0;
}


Measured memory_bytes: 3648
import static java.lang.Math.sqrt;

import java.util.*;

public class Main {
	
	static Scanner sc = new Scanner(System.in);
	static int n;
	static ArrayList<Integer> sieve = new ArrayList<Integer>();
	
	static boolean read() {
		n = sc.nextInt();
		return (n == 0) ? false : true;
	}
	
	static int solve() {
		int ans, lb, ub;
		
		ub = n;
		ans = 0;
		for(lb = 3; lb < ub; lb += 2) {
			ub = n - lb;
			if(isPrime(lb) && isPrime(ub)) ans++;
		}
		
		return ans;
	}
	
	public static void main(String[] args) {
		while(read()) {
			System.out.println(solve());
		}
	}
	
	
	static boolean isPrime(int k) {
		if(k == 2) return true;
		boolean is_prime = true;;
		for(int i = 3; i <= sqrt(k); i += 2) {
			if(k % i == 0) {
				is_prime = false;
				break;
			}
		}
		return is_prime;
	}
}

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

int main(){
    int n;
    cin>>n;
    int arr[n];
    int k;
    cin>>k;
    for(int i=1;i<=n;i++){
        cin>>arr[i-1];
    }

    int dp[n+1];
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(arr[1]-arr[0]);
    for(int i=3;i<=n;i++){
        int temp=INT_MAX;
        for(int j=1;j<=k && (i)>j;j++){
            temp=min(temp,dp[i-j]+abs(arr[i-1]-arr[i-1-j]));
        }
        dp[i]=temp;
    }
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void) {
	int n, a, b;
	cin >> n;
	vector<pair<int, int> > num(n);
	for (int i = 0; i < n; ++i) {
		cin >> a >> b;
		num[i] = { a,b };
	}
	sort(num.begin(), num.end());
	cout << num[n - 1].first + num[n - 1].second << endl;
	return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;

    while (!(h == 0 && w == 0))
    {
        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
            {
                if ((x + y) % 2 == 0)
                    cout << "#";
                else
                    cout << ".";
            }
            cout << endl;
        }
        cout << endl;
        cin >> h >> w;
    }
}


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



int main(){
    int N;
    cin >> N;
    cout << N*(N+1)/2 << endl;
}

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

namespace ABC143
{
    class D
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var L = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();

            var indexMax = 0;
            var count = 0;

            for (int i = 0; i < N - 2; i++)
            {
                for (int j = i + 1; j < N - 1; j++)
                {
                    indexMax = Array.BinarySearch(L, L[i] + L[j]);
                    if (indexMax < 0) indexMax = ~indexMax;
                    else
                    {
                        while (L[indexMax] == L[indexMax - 1]) indexMax--;
                    }


                    count += indexMax - (j + 1);

                    /*
                    for (int k = N - 1; j < k; k--)
                    {
                        if (L[k] < L[i] + L[j])
                        {
                            count += k - j;
                            break;
                        }
                    }
                     */
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

#define rep(i, n) for ( ll i = 0; i < (n); ++i )
#define reps(i, n) for ( ll i = 1; i <= (n); ++i )
#define _rep(i, n) for ( ll i = (n) - 1; i >= 0; --i )
#define _reps(i, n) for ( ll i = n; i > 0; --i )
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll =  long long;
using P = pair<ll, ll>;

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

	ll h[n];
	rep( i, n ) {
		cin >> h[i];
	}

	ll c[n];
	c[0] = 0;
	c[1] = abs(h[1] - h[0]);
	for ( ll i = 2; i < n; i++ ) {
		c[i] = min(c[i - 1] + abs(h[i] - h[i - 1]), c[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << c[n - 1] << endl;

	return 0;
}


Measured memory_bytes: 1792
from collections import defaultdict
n = int(input())
Ss = []
for i in range(n):
    tmp = defaultdict(int)
    S = input()
    for s in S: tmp[s] += 1
    Ss.append(tmp)

alpha = 'abcdefghijklmnopqrstuvwxyz'
ans = {}
for s in alpha:
    ans[s] = Ss[0][s]
    for i in range(1,n):
        ans[s] = min(Ss[i][s],ans[s])

for s in alpha:
    if ans[s] != 0: print(s*ans[s],end='')
print()

Measured memory_bytes: 3444
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

//Shuffle
public class Main{

	class Scanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-') return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}
	}

	void run(){
		Scanner sc = new Scanner();
		long mask = (1L << 32)-1;
		Comparator<Long> C = new Comparator<Long>() {
			public int compare(Long o1, Long o2) {
				return (int) ((o1>>32)-(o2>>32));
			}
		};
		int[] p = new int[5000], q = new int[5000];
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			int m = sc.nextInt(), P = sc.nextInt(), Q = sc.nextInt(), R = sc.nextInt();
			List<Long> l = new ArrayList<Long>();
			//int(32bit)を2つ並べて1つのlong(64bit)とする、2つの値は区間の左端、右端
			l.add(((long)P<<32)|Q);
			for(int i=0;i<m;i++){
				p[i] = sc.nextInt(); q[i] = sc.nextInt();
			}
			for(int i=m-1;i>=0;i--){
				long t1 = n-q[i], s2 = t1+1, t2 = n-p[i], s3 = n-p[i]+1, y = q[i];
				List<Long> next = new ArrayList<Long>();
				for(int j=0;j<l.size();j++){
					long x = l.get(j);
					long s = x>>32, t = x&mask;
					if(t<=t1){
						next.add((s+y)<<32 | (t+y));
					}
					else if(t<=t2){
						if(s<=t1){
							next.add((s+y)<<32 | (t1+y));
							s = s2;
						}
						next.add((s-s2+p[i]+1)<<32 | (t-s2+p[i]+1));
					}
					else{
						if(s<=t1){
							next.add((s+y)<<32 | (t1+y));
							s = s2;
						}
						if(s<=t2){
							next.add((s-s2+p[i]+1)<<32 | (t2-s2+p[i]+1));
							s = s3;
						}
						next.add((s-s3+1)<<32 | (t-s3+1));
					}
				}
				//区間数が多くなってきたら隣り合っている区間の結合処理
				//あと最後は必ず行う
				if(i==0||1100<=next.size()){
					l = new ArrayList<Long>();
					Collections.sort(next, C);
					long ss = next.get(0)>>32, tt = next.get(0)&mask;
					for(int j=1;j<next.size();j++){
						long x = next.get(j);
						long s = x>>32, t = x&mask;
						if(tt+1==s)tt = t;
						else{
							l.add((ss<<32)|tt);
							ss = s; tt = t;
						}
					}
					l.add((ss<<32)|tt);
				}
				else{
					l = next;
				}
			}
			int res = 0;
			for(long x:l){
				long s = x>>32, t = x&mask;
				if(R<s)break;
				if(R<t)t = R;
				res+=t-s+1;
			}
			System.out.println(res);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 10000
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

int main()
{
  int K;
  while (scanf("%d", &K), K) {
    int sum = 0;
    REP(i, K*(K-1)/2) {
      int c; scanf("%d", &c);
      sum += c;
    }
    assert(sum % (K-1) == 0);
    printf("%d\n", sum / (K-1));
  }
}

Measured memory_bytes: 0
fun main(args: Array<String>) {
    readLine()!!.toInt()
    val a = readLine()!!.split(' ').map(String::toInt)

    var any = 0
    var col = 0
    val exist = Array(8, { i -> false })
    for (ai in a) {
        when (ai) {
            in 1..3199 -> {
                val idx = ai / 400
                if (exist[idx] == false) {
                    exist[idx] = true
                    col++
                }
            }
            else -> any++
        }
    }
    val min = Math.max(1, col)
//    val max = Math.min(8, col + any)
    val max = col + any // wtf
    println("$min $max")
}

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

int main()
{
	int n;
    cin>>n;
    long long sum=0;
    for(int i=1; i<=n; i++){
        if(i%5!=0 && i%3!=0) sum+=i;
    }
    cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3624
# -*- coding: utf-8 -*-
H, W = [int(n) for n in input().split()]
A = []

for h in range(H):
    A.append([str(n) for n in input().split()])

result = "#" * (W+2) 
for a in A:
    result += "\n#{}#".format("".join(a))
result += "\n"+"#" * (W+2)
print(result)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main() {
	srand((unsigned)time(NULL));
	int n; char a[11][11]; int b, c[11], d = -1;
	for (int i = 0; i < 11; i++) { c[i] = 0; }
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
			if (a[i][j] != 'x') { c[i]++; }
		}
		if (c[i] == n) { d = i; }
	}
	for (int i = 0; i < 1000; i++) {
		if (d >= 0) { cout << d + 1 << endl; }
		else { cout << rand() % n + 1 << endl; }
		cin >> b;
	}
	return 0;
}

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

int main() {
    int X, y500, y5;
    cin >> X;
    y500 = X / 500;
    X %= 500;
    y5 = X / 5;
    cout << y500 * 1000 + y5 * 5 << endl;
}

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

using namespace std;

const int MAX_N = 22;
const int MOD = 1000000007;

int N;
int a[MAX_N];
int dp[MAX_N][1 << MAX_N];

int add(int a, int b) {
  return (a + b) % MOD;
}
int inv(int pos) {
  return (1 << N) - 1 - (1 << pos);
}
int getbit(int num, int pos) {
  return (num & (1 << pos)) > 0 ? 1 : 0;
}

int main() {
  // auto start = std::chrono::steady_clock::now();
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> N;
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) {
      int good;
      cin >> good;
      a[i] = a[i] | (good << j);
    }
  }
  dp[0][0] = 1;
  for(int i = 0; i < N; ++i) {
    for(int state = 0; state < (1 << N); ++state) {
      if(dp[i][state]) {
        for(int j = 0; j < N; ++j) {
          if(!getbit(state, j) && getbit(a[i], j)) {
            int nstate = state ^ (1 << j);
            dp[i + 1][nstate] = add(dp[i + 1][nstate], dp[i][state]);
          }
        }
      }
    }
  }
  cout << dp[N][(1 << N) - 1] << "\n";
  /*
  auto end = chrono::steady_clock::now();
  chrono::duration<double> elapsed_seconds = end - start;
  cout << "elapsed time: " << elapsed_seconds.count() << "s\n";
  */
  return 0;
}

Measured memory_bytes: 93632
// Problem : A - Plural Form
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#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;

// Macros

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(x) (int) x.size()
#define mod 1000000007
#define EPS 1e-9
#define inf 1e10
#define PI acos(-1.0)
#define int long long
#define N 100005

// Solution

void solve() {
  string s;
  cin >> s;
  if (s[sz(s) - 1] == 's')
    s += "es";
  else
    s += 's';
  cout << s;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  int tests;
  tests = 1;
  // cin>>tests;

  for (int test = 1; test <= tests; test++) {
    // cout<<"Case #"<<test<<": ";
    solve();
  }

  return 0;
}

Measured memory_bytes: 3684
#133c
L,R = map(int, input().split())

#https://ttrsq.exblog.jp/24409121/
#a*b%MOD = a%MOD * b%MOD

MOD = 2019

#ありえる%MODを列挙
ij_set = set()
for i in range(L,R+1):
    #print(i)
    if i%MOD not in ij_set:
        ij_set.add(i%MOD)
    else:
        break #MODした値が一緒になる→2019の倍数を挟んでいる→%MODが0になる値が含まれているので、それ以上考える必要なし。
        
ij_list = list(ij_set)
ij_list.sort(reverse=False)
#print(ij_list)

ans = MOD - 1

#ありえる%MODの組み合わせを全て試す
for i in range(len(ij_list) - 1):
    for j in range(i+1,len(ij_list)):
        if ans > ij_list[i]*ij_list[j]%MOD:
            ans = ij_list[i]*ij_list[j]%MOD
            #print(ij_list[i],ij_list[j])
        
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(void){
    int X,x;
    cin >> X;
    x=X;
    int fX=0;
    for(;;){
        fX += X%10;
        X -= X%10;
        if(X==0)break;
        else X /= 10;
    }
    if(x%fX==0){
        cout << "Yes" << "\n";
    }
    else{
        cout << "No" << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  int n,k;
  cin >> n >> k;
  int64_t mod =1E9 +7;
  vector<vector<int64_t>> cont(n+1 , vector<int64_t>(n+1));
  
  cont.at(1).at(1) = 1;
  for(int i = 0 ; i <= n ; i++){
    cont.at(i).at(0) = 1;
  }
  
  for(int i = 1 ; i <= n ; i++){
    for(int j = 1 ; j <= i ; j++){
      cont.at(i).at(j) = cont.at(i-1).at(j) % mod + cont.at(i-1).at(j-1) % mod;
    }
  }
  
  for(int i = 1 ; i <= k ; i++){
    if(n-k+1 < i){
      cout << 0 << endl;
    }
    else{
      int64_t a = cont.at(n-k+1).at(i) % mod;
      int64_t b = cont.at(k-1).at(i-1) % mod;
      
      cout << a*b % mod << endl;
    }
  }
}

Measured memory_bytes: 31616
#include<stdio.h>
#define N 100
#define INF 99999
#define min(a,b) ((a) < (b) ? (a) : (b))

int main(){
  int i,j,k,l,n,p[N + 1],m[N + 1][N + 1];

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

  for(i = 1; i <= n; i++) {
    m[i][i] = 0;
  }
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n - l + 1; i++){
      j = i + l - 1;
      m[i][j] = INF;
      for(k = i; k <= j - 1; k++){
	m[i][j] = min(m[i][j],m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
      }
    }
  }

  printf("%d\n",m[1][n]);
  return 0;
  
}



Measured memory_bytes: 2108
#include<cstdio>
using namespace std;
int main()
{
   int n,m,ans,sum;
   while(scanf("%d%d",&n,&m)!=EOF)
   {
       ans=0,sum=n+m;
       while(sum)
       {
           ans++;
           sum/=10;
       }
       if(!ans)ans++;
       printf("%d\n",ans);
   }
}

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

struct Data{
	int count;
	int time[500][2],size;
}data[10000];

int main(void){
	int i,j,k,n,m,r,ts,te,no,flg,rst;

	while(cin>>n>>m && n){
		cin>>r;
		memset(data,0,sizeof(data));

		while(r--){
			cin>>ts>>no>>no>>flg;
			no--;
			if(flg){
				if(!data[no].count) data[no].time[data[no].size][0] = ts;
				data[no].count++;
			}
			else{
				data[no].count--;
				if(!data[no].count) data[no].time[data[no].size++][1] = ts;
			}
		}

		cin>>r;
		while(r--){
			cin>>ts>>te>>no;

			rst = 0;
			no--;
			for(i=0;i<data[no].size && data[no].time[i][1]<ts;i++);
			for(j=i;j<data[no].size && data[no].time[j][0]<te;j++);
			j--;
			for(k=i+1;k<j;k++){
				rst+=data[no].time[k][1]-data[no].time[k][0];
			}

			if(i > j){}
			else if(data[no].time[i][0] <= ts){
				if(data[no].time[j][1] <= te){
					if(i!=j) rst += data[no].time[j][1]-data[no].time[j][0];
					rst += data[no].time[i][1] - ts;
				}
				else{
					if(i!=j){
						rst += data[no].time[i][1] - ts;
						rst += te - data[no].time[j][0];
					}
					else rst += te - ts;
				}
			}
			else{
				if(data[no].time[j][1] <= te){
					if(i!=j) rst += data[no].time[j][1]-data[no].time[j][0];
					rst += data[no].time[i][1]-data[no].time[i][0];
				}
				else{
					if(i!=j) rst += data[no].time[i][1]-data[no].time[i][0];
					rst += te - data[no].time[j][0];
				}
			}

			cout<<rst<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 39000
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

void Main()
{
	int N;
	cin >> N;
	vector<double> A(N, 0.0);
	double denominator = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		denominator += 1 / A[i];
	}

	//cout << setprecision(10) << 1 / denominator;
	cout << 1 / denominator;
}
 
int main()
{
	Main();
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define nn 65536*4
#define ll long long
#define mod 998244353

int in[43];
int main()
{
	for(int i=0;i<3;i++)
	{
		int x,y;cin>>x>>y;
		in[x]++,in[y]++;		
	}
	for(int i=1;i<=4;i++) if(in[i]>2) 
	{
		puts("NO");exit(0);
	};
	puts("YES");
}

Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10 ** 6)
import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, M, K, As, Bs):
    sum_A = [0]
    max_read_A = 0
    for i in range(N):
        sum_A.append(sum_A[-1] + As[i])
        if sum_A[-1] <= K:
            max_read_A = i + 1
    sum_B = [0]
    max_read_B = 0
    for i in range(M):
        sum_B.append(sum_B[-1] + Bs[i])
        if sum_B[-1] <= K:
            max_read_B = i + 1

    # print(sum_A, max_read_A)
    # print(sum_B, max_read_B)

    ans = 0
    for i in range(max_read_A + 1):
        B_read_time = K - sum_A[i]
        B_read_num = bisect.bisect_right(sum_B, B_read_time) - 1
        ans = max(ans, i + B_read_num)
        # print(i, B_read_num)

    print(ans)

if __name__ == '__main__':
    N, M, K = map(int, input().split())
    As = [int(i) for i in input().split()]
    Bs = [int(i) for i in input().split()]

    # import random
    # N, M, K = 200000, 200000, 10 ** 9
    # As = [random.randint(1, 1) for _ in range(N)]
    # Bs = [random.randint(1, 1) for _ in range(M)]
    solve(N, M, K, As, Bs)


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

int main(){
    ll n,ans = 0;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    priority_queue<pair<ll,ll>> pq;
    for(int i = 0;i < n;i ++){
        cin >> a[i];
    }
    for(int i = 0;i < n;i ++){
        cin >> b[i];
        pq.push(make_pair(b[i],i));
    }
    while(!pq.empty()){
        ll i = pq.top().second,ln,rn;
        pq.pop();
        ln = (i==0?b[n-1]:b[i-1]);
        rn = (i==n-1?b[0]:b[i+1]);

        if((b[i]-a[i])%(ln+rn)==0){
            ans += (b[i]-a[i])/(ln+rn);
            b[i] = a[i];
        }else if(ln+rn<b[i]){
            ll k = (b[i]%(ln+rn)==0?b[i]/(ln+rn)-1:b[i]/(ln+rn));
            b[i] -= k*(ln+rn);
            ans += k;
            pq.push(make_pair(b[i],i));
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9456
n = int(input())
a = list(map(int, input().split()))
checker = [1 for _i in range(10**6+1)]
a.sort()
a.append(-1)
result = 0
for i in range(n):
    if a[i] == a[i-1]:
        continue
    if a[i] == a[i+1]:
        checker[a[i]] = 0
    result += checker[a[i]]
    checker[a[i]] = 0
    x = 2
    while a[i]*x <= 10**6:
        checker[a[i]*x] = 0
        x += 1
print(result)

Measured memory_bytes: 170560
s = list(str(input()))
q = int(input())

from collections import deque
s = deque(s)

cnt = 0

for i in range(q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        cnt += 1
    else:
        t, f, c = query
        if f == '1':
            if cnt%2 == 0:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if cnt%2 == 0:
                s.append(c)
            else:
                s.appendleft(c)
s = list(s)
if cnt%2 == 1:
    s.reverse()
print(''.join(s))


Measured memory_bytes: 100864
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 100000
#define FI freopen("input.txt","r",stdin)
#define FO freopen("output.txt","w",stdout)
#define sc(a) scanf("%d",&a);
#define sc2(a,b) scanf("d",&a,&b);
#define fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
vector<ll>graph[MAX];
bool visit[MAX];

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b && a!=c)|| (a==c && a!=b)|| (b==c &&b!=a))
       cout<<"Yes\n";
       else
        cout<<"No\n";
    return 0;
}




Measured memory_bytes: 2560
//ABC160 E

#include <bits/stdc++.h>
using namespace std;

int X,Y,A,B,C;
int p[100000],q[100000],r[100000];
long long ans = 0;

int main() {
  cin >> X >> Y >> A >> B >> C;
  
  for(int i=0;i<A;i++){
    scanf("%d",&p[i]);
  }
  for(int i=0;i<B;i++){
    scanf("%d",&q[i]);
  }
  for(int i=0;i<C;i++){
    scanf("%d",&r[i]);
  }

  sort(p,p+A);
  sort(q,q+B);
  sort(r,r+C);
  reverse(p,p+A);
  reverse(q,q+B);
  reverse(r,r+C);
  int z[X+Y+C];
  for(int i=0;i<X;i++){
    z[i] = p[i];
  }
  for(int i=X;i<X+Y;i++){
    z[i] = q[i-X];
  }
  for(int i=X+Y;i<X+Y+C;i++){
    z[i] = r[i-X-Y];
  }

  sort(z,z+X+Y+C);
  reverse(z,z+X+Y+C);
  
  for(int i=0;i<X+Y;i++){
    ans += z[i];
  }
  
  
  printf("%lld\n",ans);
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
 
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    int n,i,s[N],a[N];
    for(i=0;i<N;i++){
        a[i]=0;
    }
    int d=-1; 
    cin>>n;
    for(i=0;i<n;i++){
        cin>>s[i];
        d=max(d,s[i]);
        a[s[i]]++;
    }
    bool ok = true;
    if(d%2==1){
        int cnt = 0;
        for(i=d;i>=d/2+1;i--){
            if(i == d/2+1){
                if(a[i]!=2) ok = false;
            }
            else{
                if(a[i]<2) ok = false;
            }
            cnt += a[i];
        }
        if(cnt != n) ok = false;
    }
    else{
        int cnt = 0;
        for(i=d;i>=d/2;i--){
            if(i!=d/2){
                if(a[i]<2) ok = false;
            }
            else{
                if(a[i]!=1) ok = false;
            }
            cnt += a[i];
        }
        if(cnt != n) ok = false;
    }

    cout << (ok ? "Possible\n" : "Impossible\n");
 
    return 0;
}

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

#define endl "\n"
#define int long long

int distance(int a, int b) {
	return a * a + b * b;
}

signed main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	int d;
	cin >> n;
	cin >> d;
	d *= d;
	int cont = 0;

	while (n--) {
		int a, b;
		cin >> a >> b;
		cont += (distance(a, b) <= d);
	}

	cout << cont << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define debug(...)
#include <complex.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;

int n ;
string s;

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >>  n >> s;
    vi dp(n + 2);
    for(int i = 0; i < n; i++){
        dp[i + 1] = dp[i] + (s[i] == 'W');
    }
    vi dp2(n + 2);
    for(int i = n - 1; i >= 0; i--){
        dp2[i] = dp2[i + 1] + (s[i] == 'E');
    }
    int ans = (int)1e9;
    for(int i = 0; i < n; i++){
        int nw = dp[i] + dp2[i + 1];
        ans = min(ans , nw);
    }
    cout << ans << '\n';




    return 0;
}













Measured memory_bytes: 2964
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n, 0), b(n+1, INF);
    rep1(i, n-1) cin >> b[i+1];
    ll ans = 0;
    rep1(i, n) ans += min(b[i], b[i+1]);

    cout << ans << endl;
}

Measured memory_bytes: 3616
i = gets.split(" ").map(&:to_i)
kotae = 0
2.times{
if i[0] >= i[1] then
  kotae += i[0]
  i[0] = i[0] - 1
else
  kotae += i[1]
  i[1] = i[1] - 1
end}
print kotae

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
 
int main(){
	int n;
	scanf("%d", &n);
	int a = 0, b = 0, c = 0;
	f(i, 0, n){
		int t;
		scanf("%d", &t);
		if (t & 1)++a;
		else if (t & 2)++b;
		else ++c;
	}
	if (c >= a || b == 0 && c + 1 >= a)printf("Yes\n");
	else printf("No\n");
}

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

using namespace std;

typedef long long ll;

ll T, N, a, b, c, d;
map <ll, ll> dp;

ll calc(ll x)
{
    if (x == 0) return 0;
    if (dp.find(x) != dp.end()) return dp[x];
    if ((double) x * d >= (double) 2e18) dp[x] = 2e18;
    else dp[x] = x * d;
    if (x % 2 == 0) dp[x] = min(dp[x], calc(x / 2) + a);
    else dp[x] = min(dp[x], min(calc(x / 2) + d, calc(x / 2 + 1) + d) + a);
    if (x % 3 == 0) dp[x] = min(dp[x], calc(x / 3) + b);
    else dp[x] = min(dp[x], 
    min(calc(x / 3) + d * (x - x / 3 * 3), calc(x / 3 + 1) + d * (x / 3 * 3 + 3 - x)) + b);
    if (x % 5 == 0) dp[x] = min(dp[x], calc(x / 5) + c);
    else dp[x] = min(dp[x], 
    min(calc(x / 5) + d * (x - x / 5 * 5), calc(x / 5 + 1) + d * (x / 5 * 5 + 5 - x)) + c);
    return dp[x];
}

int main()
{
    cin >> T;
    while (T--)
    {
        cin >> N >> a >> b >> c >> d;
        dp.clear();
        cout << calc(N) << endl;
    }
    return 0;
}

Measured memory_bytes: 4384
import java.util.Scanner;

public class Main {
    static Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
        String S = in.next();
        if (S.equals("Sunny")) System.out.println("Cloudy");
        else if (S.equals("Cloudy")) System.out.println("Rainy");
        else System.out.println("Sunny");
    }
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr,0,sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int a, b, c;
        cin >> a >> b >> c;
        int d = c - a - b;
        if(d > 0 and 4 * a * b < d * d){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    } 
}

Measured memory_bytes: 31488
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  string s;
  cin>>s;
  if(s[0]=='S') cout<<"Cloudy"<<endl;
  else if(s[0]=='C') cout<<"Rainy"<<endl;
  else cout<<"Sunny"<<endl;
  return 0;
}


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

int main(void) {
	// your code goes here
	int h,w,i,j,b[101]={0},c[101]={0};
	char a[101][101];
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++){
		scanf("%s",&a[i][j]);
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			
			if(a[i][j]=='#') {
				b[i]=1;
				c[j]=1;
			}
		}
	}
	for(i=0;i<h;i++){
		if(b[i]!=1) continue;
		for(j=0;j<w;j++){
			if(c[j]==1) printf("%c",a[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

int N, A[50];

int solve(int i, int m) {
  if (m == 0) {
    return 1;
  }
  if (i >= N) {
    return 0;
  }
  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

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

  int Q, M;
  cin >> Q;
  for(int i = 0; i < Q; i++) {
    cin >> M;
    if (solve(0, M)) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3100
#


def main():
    n = int(input())
    s = [int(s) for s in input().split(" ")]
    buka = {}
    for i in s:
        if i in buka:
            buka[i] += 1
        else:
            buka[i] = 1
    for i in range(n):
        if i + 1 in buka:
            print(buka[i + 1])
        else:
            print("0")


if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
	ios::sync_with_stdio(false), cin.tie(0);
	int n;
	cin >> n;
	vector<vector<int> > a(2, vector<int>(100123));
	for(int i = 0; i < n; ++ i){
		int x;
		cin >> x;
		a[i % 2][x] ++;
	}
	int v0  = max_element(a[0].begin(), a[0].end()) - a[0].begin();
	int v1  = max_element(a[1].begin(), a[1].end()) - a[1].begin();
	if(v0 == v1){
		sort(a[0].begin(), a[0].end(), greater<int>());
		sort(a[1].begin(), a[1].end(), greater<int>());
		int ans1 = n - a[0][0] - a[1][1], ans2 = n - a[0][1] - a[1][0];
		cout << min(ans1, ans2) << '\n';
	}
	else {
		int ans = n - a[0][v0] - a[1][v1];
		cout << ans << '\n';
	}
}
	


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

typedef int64_t Int;

int main(){
  Int N;
  cin>>N;
  bool frag=false;
  for(int h=1;h<=3500;++h){
    for(int n=h;n<=3500;++n){
      Int Q=4*Int(h)*Int(n)-N*(Int(h)+Int(n));
      if(Q>0 && N*Int(n)*Int(h)%Q==0){
        cout<<h<<" "<<n<<" "<<N*Int(n)*Int(h)/Q<<endl;
        frag=true;
        break;
      }
    }
    if(frag){
      break;
    }
  }
}

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

using namespace std;

#define int long long

signed main(){
	string s;
	cin>>s;
	map<char, int > mp;
	for(int i=0;i<4;i++){
		mp[s[i]]++;
	}
	if(mp.size() != 2){
		cout<<"No\n";
	}
	else{
		for(auto it : mp){
			if(it.second != 2){
				cout<<"No";
				return 0;
			}
		}
		cout<<"Yes\n";
	}
	return 0;
}

Measured memory_bytes: 256