akhauriyash/Code-Regression huggingface dataset:
import math
X, N = list(map(lambda n : int(n), input().split(" ")))
if N == 0:
  print(X)
else:
  P = list(map(lambda p : int(p), input().split(" ")))
  Q = list(map(lambda p : [p, abs(X-p)], P))
  Q.sort(key=lambda q: (q[1], q[0]))

  cand = []
  for i in range(N):
    if i == 0 and Q[0][1] != 0:
      cand.append(X)
      break
    else:
      if Q[i][1] != math.ceil(i/2):
        cand.append(X + math.ceil(i/2))
        cand.append(X - math.ceil(i/2))
        break
  if len(cand) == 0:
    if N % 2 == 0:
      cand.append(X + int(N/2))
      cand.append(X - int(N/2))
    else:
      cand.append(X + int((N+1)/2))
      cand.append(X - int((N+1)/2))

  print(min(list(filter(lambda c: c not in P, cand))))

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void write(int x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,m;
int dp[1003][1003];
char c[1003][1003];
int main(){
	read(n),read(m);
	dp[1][1]=1;
	for (int i=1;i<=n;i++,getchar()) for (int j=1;j<=m;j++){
		c[i][j]=getchar();
		if ((i==1 && j==1) || c[i][j]=='#') continue;
		dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
	}
	write(dp[n][m]);
}

Measured memory_bytes: 5120
n, m = map(int, input().split())

swich = [0] * n

for i in range(m):
    _, *s = map(int, input().split())
    for j in range(len(s)):
        # swich[s[j] - 1] += 1 << (i)
        # swich[s[j] - 1] ^= 1 << (i)
        swich[s[j] - 1] |= 1 << (i)
    


p_list = list(map(int, input().split()))
p = 0
for i in range(m):
    # if p_list[i] == 1: 
    #     p += 1 << i
    p |= p_list[i] << i #上の処理と同じ

# print("++++++++++++++++++++++++")
# print(swich)
ans = 0
for i in range(1 << n):
    state_on_off = 0
    for index in range(n):
        if i >> index & 1 == 1:
            state_on_off ^= swich[index]
    if state_on_off == p:
        ans += 1
    # print(p, state_on_off,bin(i))
print(ans)

Measured memory_bytes: 9224
N,M=map(int,input().split())
box=[]
A=list(map(int,input().split()))
for i in A:
  box.append((i,1))
for _ in range(M):
  b,c=map(int,input().split())
  box.append((c,b))
box = sorted(box, key=lambda x:x[0])
box.reverse()
ans=0
count=0
for i in range(0,10**5):
  ans+=(box[i][0]*box[i][1])
  count+=box[i][1]
  if count >N:
    ans-=((count-N)*box[i][0])
    break
print(ans)

Measured memory_bytes: 33464
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
struct Item{
  int value;
  int weight;
};
 
int max(int x ,int y)
{
  if(x>=y)
    return x;
  else return y;
}
 
int main()
{
  int N,W;
  int i,w;
  struct Item *item;
  scanf("%d %d",&N,&W);
  int C[N+1][W+1];
  item=malloc(sizeof(item)*(N+1));
  for(i=1;i<=N;i++)
    scanf("%d %d",&item[i].value,&item[i].weight);
 
  for(w=0;w<=W;w++)
    C[0][w]=0;
 
  for(i=1;i<=N;i++)
    C[i][0]=0;
 
  for(i=1;i<=N;i++)
    for(w=1;w<=W;w++)
      if(item[i].weight<=w){
     
    C[i][w]=max(C[i-1][w],max(item[i].value+C[i-1][w-item[i].weight],item[i].value+C[i][w-item[i].weight]));
      }
      else{
    C[i][w]=C[i-1][w];
      }
 
  printf("%d\n",C[N][W]);
 
  return 0;
}

Measured memory_bytes: 4544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int P = 1e9 + 7;
const int maxn = 1e5 + 5;
int n;
ll a, b, c;
ll fac[maxn * 2], inv[maxn * 2], facinv[maxn * 2], fac_a[maxn], fac_b[maxn];
ll power(ll x, ll t) {
	ll ret = 1;
	for(; t; t >>= 1, x = x * x % P) {
		if(t & 1) {
			ret = ret * x % P;
		}
	}
	return ret;
}
ll C(int n, int m) {
	if(n < m) {
		return 0;
	}
	return fac[n] * facinv[m] % P * facinv[n - m] % P;
}
int main() {
	cin >> n >> a >> b >> c;
	a = a * power(100, P - 2) % P;
	b = b * power(100, P - 2) % P;
	c = c * power(100, P - 2) % P;
	ll tmp = power((a + b) % P, P - 2);
	a = a * tmp % P;
	b = b * tmp % P;
	c = c * power((P + 1 - c) % P, P - 2) % P;
	fac_a[0] = 1;
	fac_b[0] = 1;
	for(int i = 1; i <= n; ++i) {
		fac_a[i] = fac_a[i - 1] * a % P;
		fac_b[i] = fac_b[i - 1] * b % P;
	}
	fac[0] = 1;
	inv[1] = 1;
	facinv[0] = 1;
	for(int i = 1; i <= 2 * n; ++i) {
		fac[i] = fac[i - 1] * i % P;
		if(i != 1) {
			inv[i] = inv[P % i] * (P - P / i) % P;
		}
		facinv[i] = facinv[i - 1] * inv[i] % P;
	}
	ll ans = 0;
	for(int i = 0; i < n; ++i) {
		ll x = (fac_a[n] * fac_b[i] % P + fac_a[i] * fac_b[n] % P) % P;
		ll y = C(i + n - 1, n - 1) * (c + 1) % P * (i + n) % P;
		ans = (ans + x * y % P) % P;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll mod=1e9+7;;
    ll n;
    cin>>n;
    vll in(n);
    rep(i,0,n)cin>>in[i];
    vector<ll> res(60,0);
    rep(i,0,n){
        rep(j,0,60){
            if((in[i]>>j)&1)res[j]++;
        }
    }
    ll sum=0;
    rep(i,0,60){
        ll add=res[i]*(n-res[i])%mod;
        rep(j,0,i){
            add*=2;
            add%=mod;
        }
        if(add<0)add+=mod;
        sum+=add;
        sum%=mod;
    }
    cout<<sum<<endl;
    return 0;
}




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

typedef long long ll;
typedef unsigned long long ull;

#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)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

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

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  ll n, d;
  cin >> n >> d;
  vector<ll> x(n), y(n);
  REP(i, n){
    cin >> x[i];
    cin >> y[i];
  }
  int ans = 0;
  ll tmp = d * d;
  REP(i, n){
    ll val = x[i] * x[i] + y[i] * y[i];
    if (val <= tmp) ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 6428
#include <iostream>
#include<string>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<set>
#include <limits>
#include <numeric>
#include <type_traits>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
#define MAX_B 1001001
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL

int main(){
    int n;cin>>n;
    vector<P>p(n);
    rep(i,n){
        cin>>p[i].second>>p[i].first;
    }
    sort(ALL(p));
    int t=0;
    bool ans=true;
    rep(i,n){
        t+=p[i].second;
        if(t<=p[i].first){
            continue;
        }
        else ans=false;
    }
    cout<<(ans?"Yes":"No")<<endl;
}

Measured memory_bytes: 1792
S = int(input())

word = "NA","MMYY","YYMM","AMBIGUOUS"
S1 = int(S/100)
S2 = int(S%100)
answer = 0
if S1 > 0 and S1 < 13:
  if S2 >= 0 and S2 <= 99:
    answer = answer + 1
if S2 > 0 and S2 < 13:
  if S1 >= 0 and S1 <= 99:
    answer = answer + 2
print(word[answer])

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

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mod 1000000007

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

    string s; cin>>s; int w=0, l=0;

    for(int i=0;i<s.size();i++) {
        if(i%2 == 0 and s[i] != 'g') {
            l++;
        }
        if(i%2 != 0 and s[i] != 'p') {
            w++;
        }
    }

    cout<<w-l;


    return 0;
}



Measured memory_bytes: 512
import scala.io.StdIn

object Main {

  def cmp: PartialFunction[Char, Char] = {
    case 'A' => 'T'
    case 'G' => 'C'
    case 'C' => 'G'
    case _   => 'A'
  }

  def main(args: Array[String]): Unit = {

    val b = StdIn.readChar()
    val ans = cmp(b)
    println(ans)
  }

}


Measured memory_bytes: 25308
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll k,x;
	cin>>k>>x;
	if((k*500)>=x )
	    cout<<"Yes";
	else
	    cout<<"No";
    return 0;
}


//252908XL

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int a[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    sort(a, a + n);
    for(int i = 0; i < n - 1; i++){
        if (a[i] == a[i+1]){
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}

Measured memory_bytes: 896
//52
#include<iostream>

using namespace std;

int main() {
     for(int n;cin>>n;){
       int ans=0;
       for(int a=0;a<=9;a++){
	 for(int b=0;b<=9;b++){
	   for(int c=0;c<=9;c++){
	     for(int d=0;d<=9;d++){
	       ans+=a+b+c+d==n;
             }
	   }
	 }
       }
       cout << ans << endl;
     } 
   return 0;
    }



Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;

const int N=1e5+20;

int n,m,u,v,dp[N];
vector <int> adj[N];
bool vis[N];
queue <int> q;

void add(int node,int parent)
{
	vis[node]=true;
	dp[node]=parent;
	q.push(node);
}

void bfs()
{
	add(1,0);

	while(not q.empty())
	{
		int node=q.front();
		q.pop();

		for(auto child:adj[node])
		{
			if(vis[child]) continue;
			add(child,node);
		}
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	bfs();
	for(int i=1;i<=n;i++)
		if(not vis[i]) return 0 * printf("No");
	printf("Yes\n");
	for(int i=2;i<=n;i++) printf("%d\n",dp[i]);
}

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

int main(){
    int n, b[105], a[105];
    cin >> n;
    rep(i, n-1) cin >> b[i];
    int ans = 0;

    rep(i, n) {
        if (i==0) a[i] = b[i];
        else if (i==n-1) a[i] = b[i-1];
        else a[i] = min(b[i], b[i-1]);

        ans += a[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"
import "sort"

func main() {
	var n int
	fmt.Scan(&n)

	m := make(map[string]int)
	max_items := make(map[string]bool)
	var a string
	var max_count, current_count int

	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		prev, ok := m[a]

		if ok {
			current_count = prev + 1
		} else {
			current_count = 1
		}

		if max_count < current_count {
			max_items = make(map[string]bool)
			max_count = current_count
			max_items[a] = true
		} else if max_count == current_count {
			max_items[a] = true
		}

		m[a] = current_count

	}

	var keys []string
	for k := range max_items {
        keys = append(keys, k)
	}
	
	sort.Strings(keys)

	for kk := range keys {
		fmt.Println(keys[kk])
	}
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i + 3 <= n; i++) {
    if (s.substr(i, 3) == "ABC") ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from itertools import accumulate


def eratos(N):
    is_prime = [1]*(N+1)
    is_prime[0] = is_prime[1] = 0
    for i in range(2, int(N**0.5)+1):
        if is_prime[i]:
            for j in range(i**2, N+1, i):
                is_prime[j] = 0
    return is_prime


inf = 10**5
is_prime = eratos(inf)
like_2007 = [0]*(inf+1)
for i in range(1, inf+1):
    if is_prime[i] == 1 and i % 2 == 1:
        if is_prime[(i+1)//2]:
            like_2007[i] = 1
cumsum = list(accumulate(like_2007))
# print(like_2007)
# print(cumsum)

Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(cumsum[r]-cumsum[l-1])


Measured memory_bytes: 13748
/*input
5 5
1 2
1 3
3 4
3 5
16 8 17 3 18
2 1
2 3
1 3 7
2 1
2 3


*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin >> n;
  int c = (n + 1) / 2;
  cout << fixed << setprecision(15) << (ld)(c * 1.0 / n) << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n, d, a, x, h, finalans;
struct chr{
	long long x;
	long long h;
} m[200005];
long long fen[200005], hh[200005];
long long query(long long idx){
	long long x=0LL;
	while (idx>=1LL){
	//	cout << "glup" << idx<<endl;
		x+=fen[idx];
		idx-=idx&-idx;
	}
	return x;
}
void update(long long idx, long long val){
	while (idx<=n){
	//	cout << "glup" << idx << endl;
		fen[idx]+=val;
		idx+=idx&-idx;
	}
}
long long ffind(long long val){
	long long lo=1; long long hi=n; long long mid=0;
	while (lo<=hi){
	//	cout << "Glup" << lo << hi << endl;
		mid=(lo+hi)/2;
		if (hh[mid]<val) lo=mid+1;
		else if (hh[mid]>val) hi=mid-1;
		else return mid;
	}
	return hi;
}
bool msf(chr a, chr b){return a.x < b.x;}
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> d >> a;
for (long long i=0; i<n; i++){
	cin >> x >> h;
	m[i].x=x; m[i].h=h;
} sort(m, m+n, msf);
for (long long i=0; i<n; i++) hh[i+1]=m[i].x;
for (long long i=0; i<n; i++){
	m[i].h-= query(i+1)*a;
	if (m[i].h > 0){
		long long num = (m[i].h+a-1)/a;
		update(i+1, num); 
		update(ffind(hh[i+1]+2*d)+1, -num);
		finalans+=num;
	}
}
cout << finalans;
return 0;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    int ans = a+b;
    if(s==u){
        a--;
    }else{
        b--;
    }
    cout << a<<" "<<b << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n, m, q;
    cin>>n>>m>>q;
    vector<ll> a(n), b(m);
    f(i, n) cin>>a[i];
    f(i, m) cin>>b[i];
    while(q--){
        ll x;
        cin>>x;
        ll lb1 = -1, lb2 = -1, ub1 = -1, ub2 = -1;
        auto it = lower_bound(all(a), x);
        if(it != a.begin()){
            if(it == a.end()) --it;
            else if(*it != x) --it;
        }
        if(*it <= x) lb1 = *it;
        it = upper_bound(all(a), x - 1);
        if(it != a.end()) ub1 = *it;

        it = lower_bound(all(b), x);
        if(it != b.begin()){
            if(it == b.end()) --it;
            else if(*it != x) --it;
        }
        if(*it <= x) lb2 = *it;
        it = upper_bound(all(b), x - 1);
        if(it != b.end()) ub2 = *it;

        ll ans = LLONG_MAX;
        if(lb1 != -1 && lb2 != -1){
            ans = min(ans, max(abs(x - lb1), abs(x - lb2)));
        }
        if(lb1 != -1 && ub2 != -1){
            ll A = abs(x - lb1), B = abs(x - ub2);
            ans = min(ans, 2 * min(A, B) + max(A, B));
        }
        if(ub1 != -1 && ub2 != -1){
            ans = min(ans, max(abs(x - ub1), abs(x - ub2)));
        }
        if(ub1 != -1 && lb2 != -1){
            ll A = abs(x - ub1), B = abs(x - lb2);
            ans = min(ans, 2 * min(A, B) + max(A, B));
        }
        cout<<ans<<"\n";
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll N, K;
    cin >> N >> K;

    if(N >= K){
        //N -= (N+K-1)/K * K;
        N -= N/K * K;
    }

    ll ans = N;
    chmin(ans, K-N);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

int h, w;
int c[20][20];

int a[300][300];

int vis[300];

int solve( int x, int cost, int dep )
{
        //cout << x << " " << cost << " " << dep << endl;
        if( dep > 100 ) {
                return INT_MAX;
        }
        if( x == 1 ) {
                return cost;
        }

        int ret = INT_MAX;
        for(int i = 0; i < 10; i++) {
                if( x != i && !vis[i] ) {
                        vis[i] = 1;
                        ret = min( ret, solve(i, cost + c[x][i], dep + 1 ) );
                        vis[i] = 0;
                }
        }
        return ret;
}

int ans[12];

int main()
{
        scanf("%d %d", &h, &w);
        for(int i = 0; i < 10; i++) {
                for(int j = 0; j < 10; j++)
                        scanf("%d", c[i] + j);
        }

        for(int i = 0; i < h; i++) {
                for(int j = 0; j < w; j++)
                        scanf("%d", a[i] + j);
        }


        for(int i = 0; i < 10; i++) {
                memset( vis, 0, sizeof vis );
                vis[i] = 1;
                ans[i] = solve(i, 0, 0);
        }

        long long tot = 0;

        for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                        if( a[i][j] !=-1 ){
                                tot+= ans[ a[i][j] ];
                        }
                }
        }


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




        return 0;
}


Measured memory_bytes: 512
N = int(input())
a1 = input().split()
a2 = input().split()

for i in range(N):
  a1[i] = int(a1[i])
  a2[i] = int(a2[i])

candy = []
for i in range(N):
  sum_candy = sum(a1[:i+1])+sum(a2[i:])
  candy.append(sum_candy)
print(max(candy))
    

Measured memory_bytes: 3060
// Knapsack

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

class Main {
	public static long knapsack(long[] w, long[] p, int k, int n) {
		long[][] dp = new long[n+1][k+1];

		for(int i = 0; i <= n; i++) {
			dp[i][0] = 0;
		}

		for(int i = 0; i <= k; i++) {
			dp[0][i] = 0;
		}

		long max = 0;
		for(int i = 1; i <= n; i++) {
			for(long j = 1; j <= k; j++) {
				if(w[i-1] > j)
					dp[i][(int)j] = max(dp[i-1][(int)j], dp[i][(int)(j-1l)]);
				else
					dp[i][(int)j] = max(dp[i-1][(int)j], p[i-1]+dp[i-1][(int)(j-w[i-1])]);
				// System.out.print(dp[i][j] + " ");
				if(dp[i][(int)j] > max)
					max = dp[i][(int)j];
			}
			// System.out.println();
		}
		return max;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		
		int n = Integer.parseInt(s[0]);
		int k = Integer.parseInt(s[1]);

		long[] w = new long[n];
		long[] p = new long[n];

		for(int i = 0; i < n; i++) {
			String[] s1 = br.readLine().split(" ");
			w[i] = Long.parseLong(s1[0]);
			p[i] = Long.parseLong(s1[1]);
		}

		// System.out.println(Arrays.toString(w));
		// System.out.println(Arrays.toString(p));
		System.out.println(knapsack(w, p, k, n));
	}

	public static long max(long...arr) {
		long max = Long.MIN_VALUE;
		for(long i: arr) {
			if(i > max)
				max = i;
		}
		return max;
	}
}


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

bool Solve(map<int,int> nodes) {
  auto center = nodes.begin();
  if (center->first == nodes.size() - 1) {
    nodes[center->first] = nodes[center->first] + 1;
    center = nodes.begin();
  } else if (center->first != nodes.size()) {
    return false;
  }
  if (center->second != 2)
    return false;

  int pre = center->first - 1;
  for (auto p : nodes) {
    if (p.first != pre + 1 || p.second < 2)
      return false;
    ++pre;
  }

  return true;
}

int main() {
  int n;
  cin >> n;
  map<int,int> nodes;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    nodes[a] = nodes[a] + 1;
  }
  cout << (Solve(nodes) ? "Possible\n" : "Impossible\n");

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    int n;cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int k=0;k<n-1;k++) cout<<a[k]<<" ";
    cout<<a[n-1]<<endl;
    for(int i=1;i<n;i++){
        int v=a[i];
        int j=i-1;
        while(j>=0 && a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        for(int k=0;k<n-1;k++) cout<<a[k]<<" ";
        cout<<a[n-1]<<endl;
    }
}

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

int main() {
  char A;
  cin >> A;
  string B = "abcdefghijklmnopqrstuvwxyz";
  int C = 0;
  while(B.at(C) != A){
    C = C + 1;
  }
  cout << B.at(C + 1);
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))

s1 = 0
s2 = sum(W)

ans = float('inf')
for i in range(N - 1):
	s1 += W[i]
	s2 -= W[i]
	ans = min(ans, abs(s1 - s2))

print(ans)



Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
	var a [3][3]int
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			a[i][j] = nextInt()
		}
	}
	n := nextInt()
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = nextInt()
	}
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			for k := 0; k < n; k++ {
				if a[i][j] == b[k] {
					a[i][j] = 0
				}
			}
		}
	}
	c := make([]int, 8)
	for i := 0; i < 3; i++ {
		c[i] = a[i][0] + a[i][1] + a[i][2]
		c[i+3] = a[0][i] + a[1][i] + a[2][i]
		c[6] += a[i][i]
		c[7] += a[i][2-i]
	}
	for i := 0; i < 3; i++ {
		log.Println(a[i])
	}
	log.Println(c)
	if min(c...) == 0 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

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

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

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

int main()
{
  string s;
  cin >> s;
  if (s == "SUN")
    cout << 7 << endl;
  else if (s == "MON")
    cout << 6 << endl;
  else if (s == "TUE")
    cout << 5 << endl;
  else if (s == "WED")
    cout << 4 << endl;
  else if (s == "THU")
    cout << 3 << endl;
  else if (s == "FRI")
    cout << 2 << endl;
  else
    cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
s = int(input())

def f(n) :
  if n%2 == 0 :
    return n//2
  else :
    return 3*n+1

fd = {s:1}
for i in range(2,10**10) :
  s = f(s)
  if s in fd :
    print(i)
    break
  else :
    fd[s] = 1

Measured memory_bytes: 2940
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = Integer.parseInt(sc.next());
		long t = 0;
		while (t * (t + 1) / 2 < x) {
			t++;
		}
		System.out.println(t);
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 







int dp[2005][2005];
int f[2005];
int main()
{
     unsigned long long s;
     cin>>s;
     ll x2=(ll)1e9,y2=1LL;
     ll x1=(s%x2);
     if(x1!=0)x1=x2-x1;
     ll y1=(s+x1)/x2;
     cout<<0<<" "<<0<<" "<<x2<<" "<<y2<<" "<<x1<<" "<<y1;
}


























Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
#ifdef LOCAL
#include "1.h"
#else
#define dbg(...) 
#endif
ll n,m,i,j,k,in,cnt = 0,l,r,u,v,x,y,tc = 1,mod = 1000000007 , ans , inf = 1e18;
const ll  mx = 100001 ;
vector<vector<ll>> a(mx,vector<ll>(3,-1));
vector<vector<ll>> dp(mx,vector<ll>(3,-1));
ll mp[][2] = {{1,2},{0,2},{0,1}};
ll foo(int src, int choice=-1){
    if(choice==-1){ // can make any choice
        return dp[src][choice] = max({foo(src,0),foo(src,1),foo(src,2)});
    }
    if(dp[src][choice]!=-1)
        return dp[src][choice];
    if(src==n-1){
        return dp[src][choice] = a[src][choice];
    }

    else{
        ll ans_ = max(foo(src+1,mp[choice][0]),foo(src+1,mp[choice][1])) + a[src][choice];
        return  dp[src][choice] =  ans_;
    }


    

}
void solve(){
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    ll ans = -1;
    for(auto i : {0,1,2}){
        for (int j = 0; j < n; ++j)
        {
            dp[j][i] = -1;
        }
        ans = max(ans , foo(0,i));  
    }
    cout << ans << endl;
    
}
signed main(){                                          //F
    clock_t time = clock();                             //A
    ios_base::sync_with_stdio(0);                       //S
    cin.tie(0);                                         //T
    cout.tie(0);                                        //I
    cerr.tie(0);                                        //O
    if(0) cin>>tc;
    while(tc--)
        solve();
    dbg("Author - Amit dwivedi");
    return 0&fprintf(stderr, "Time ::%.3lf ms.\n",((clock() - time)*1000.0)/CLOCKS_PER_SEC);
}


Measured memory_bytes: 15872
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin>>s;
  string ss;
  int j=0;
  for(int i=0;i<s.size();i++){
    if((i+1)%2==1){
      ss+=s[i];
      j++;
    }
  }
  cout<<ss<<endl;
  return(0);
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
    int x,y;
    int z;
     while(1){
    scanf("%d%d", &x,&y);
    if(x==0 && y==0){
    break;
    }
    if(x>y){
    z=x;
    x=y;
    y=z;
    }
    printf("%d %d\n",x,y);
     }
    return 0;
     


}


Measured memory_bytes: 2028
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int result = 0;
		for(int i = 1; i <= X; i++){
			if((i + 1) * i / 2 >= X){
				result = i;
				break;
			}
		}
		System.out.println(result);
		sc.close();
	}
}

Measured memory_bytes: 23636
#include <iostream>

using namespace std;

void insertionSort(int array[],int size);

int main(void){
  int size;
  cin >> size;
  int array[size];
  for(int i = 0;i < size;i++){
    cin >> array[i];
  }
  insertionSort(array,size);

  return 0;
}

void insertionSort(int array[],int size){
  for(int j = 0;j < size;j++){
    int handle = array[j];
    int k = j-1;
    while((k >= 0) && (handle < array[k])){
      array[k+1] = array[k];
      k--;
    }
    array[k+1] = handle;
    for(int l = 0;l < size;l++){
      if(l == (size -1)){
        cout<<array[l]<<endl;
    }else{
      cout<<array[l]<<" ";
    }
    }
  }
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}

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

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

int main()
{

    long long N;
    cin>>N;
    long long arr[N];
    memset(arr,0,sizeof(arr));
    for(int i=0;i<N-1;i++)
    {
        int temp;
        cin>>temp;
        arr[temp-1]++;
    }
    for(int i=0;i<N;i++)
    {
        cout<<arr[i]<<"\n";
    }
}


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

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

  map<ll, ll> m;
  for (ll i = 2; i * i <= N; i++) {
    while (N % i == 0) {
      N /= i;
      m[i]++;
    }
  }
  if (1 < N) m[N]++;

  ll ans = 0;
  for (auto c : m) {
    ll cnt = 1;
    ll remain = c.second;
    while (remain >= cnt) {
      remain -= cnt;
      ans++; cnt++;
    }
  }

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


Measured memory_bytes: 3624
import sys
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]

num=['_']*n

if n==1 and m==0:
    print('0')
    sys.exit()

if n==1 and m==1 and sc[0][1]==0:
    print('0')
    sys.exit()

for i in range(m):
  if num[sc[i][0]-1]!='_' and num[sc[i][0]-1]!=sc[i][1]:
    print('-1')
    sys.exit()
  else:
    num[sc[i][0]-1]=sc[i][1]

if num[0]==0:
  print('-1')
  sys.exit()
    
if num[0]=='_':
    num[0]=1
    
for i in range(1,n):
    if num[i]=='_':
      num[i]=0
      
print(''.join(map(str,num)))

Measured memory_bytes: 9240
#include<stdio.h>
#define N 105
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, time = 0;
int color[N], d[N], f[N], array[N][N];

void DFS(){
  int i;
  for(i = 1; i < n+1; i++){
      color[i] = WHITE;
  }

  for(i = 1; i < n+1; i++){
    if(color[i] == WHITE) DFSvisit(i);
  }
}

void DFSvisit(int u){
  int i;
  color[u] = GRAY;
  d[u] = ++time;
  
  for(i = 1; i < n+1; i++){
    if((color[i] == WHITE) && (array[u][i] == 1)) DFSvisit(i);
  }
  color[u] = BLACK;
  f[u] = ++time;
}

main(){

  scanf("%d", &n);

  int i, u, v, j, e;
  for(i = 1; i < n+1; i++){
    for(j = 1; j < n+1; j++){
      array[i][j] = 0;
    }
  }

  for(i = 1; i < n+1; i++){
    scanf("%d%d", &u, &e);
    for(j = 1; j < e+1; j++){
      scanf("%d", &v);
      array[i][v] = 1;
    }
  }

  DFS();
  
  for(i = 1; i < n+1; i++){
    printf("%d ", i);
    printf("%d ", d[i]);
    printf("%d\n", f[i]);
  }
  return 0;
}

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

using namespace std;

char s[3010],t[3010];
int f[3010][3010];
vector<char>v;

inline int lcs(int n,int m){
	if(n==-1 || m==-1)return 0;
	if(f[n][m]!=-1)return f[n][m];
	f[n][m]=max(lcs(n-1,m),lcs(n,m-1));
	if(s[n]==t[m])f[n][m]=max(f[n][m],1+lcs(n-1,m-1));
	//printf("%d %d %d\n",n,m,f[n][m]);
	return f[n][m];
}
int main(){
	scanf("%s",s);
	scanf("%s",t);
	memset(f,-1,sizeof(f));
	int n=strlen(s),m=strlen(t);
	//printf("%d %d\n",n,m);
	lcs(n-1,m-1);
	int i=n-1,j=m-1;
	while(i>=0 && j>=0){
		if((i==0 || j==0)){
			if(f[i][j]==1)v.push_back(i==0?s[i]:t[j]);
			i--;j--;
		}else if(s[i]==t[j] && f[i][j]==f[i-1][j-1]+1){
			v.push_back(s[i]);
			i--;j--;
		}else{
			if(f[i][j]==f[i-1][j])i--;
			else j--;
		}
	}
	for(int i=v.size()-1;i>=0;i--)
		printf("%c",v[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 36096
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define ipr pair<ll,ll>
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 100005
#define endl "\n"
#define mod 998244353
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
   
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    ll a,b;
    cin>>a>>b;
    if(b>=a){
        cout<<"unsafe";
    }
    else cout<<"safe";
    return 0;
}

Measured memory_bytes: 3652
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String N=sc.next();
        String[] num = N.split("");
        long count = 0;
        
        for(int i=0;i<num.length;i++){
            count+= Long.parseLong(num[i]);
        }
        
        
        if(count%9==0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 54788
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll p,q,r; cin >> p >> q >> r;
  cout << min(p+q,min(q+r,r+p)) << endl;
}

Measured memory_bytes: 256
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll n;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>n;
	if(n&1)
	cout<<2*n;
	else
	cout<<n;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int n,v,j,k;
    cin >> n;
    int s[n];
    for (int i = 0; i < n; ++i)
    {
        cin >> s[i];
    }
    for (int i = 0; i < n; ++i)
    {
        v = s[i];
        j = i-1;
        while (j >= 0 && s[j] > v){
            s[j+1] = s[j];
            j -= 1;
        }
        s[j+1] = v;
        for (k = 0; k < n; ++k)
        {
            cout << s[k];
            if(k < n-1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    string s;
    cin >> s;
    if(s=="ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
    return 0;
}

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

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int coin = 0;
    int day = 0;

    while(coin < c){
        day++;
        coin += a;
        if(day%7 == 0){
            coin += b;
        }
    } 
    cout << day << endl;
    return 0;
}


Measured memory_bytes: 3112
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    x=parseMap(split(readline()))
    ans=1000000000
    for i in 1:100
        res=0
        for j in x
            res+=(j-i)^2
        end
        ans=min(ans,res)
    end
    print(ans)
end
main()

Measured memory_bytes: 168916
MOD=1000000007
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
pos=[]
neg=[]
nzero=0
for i in a:
    if i>0:
        pos.append(i)
    elif i<0:
        neg.append(-i)
    else:
        nzero+=1
if nzero+k>n:
    print(0)
elif nzero+k==n and len(pos)>0 and len(neg)>0:
    if nzero==0:
        res=1
        for i in pos+neg:
            res*=i
            res%=MOD
        if len(neg)%2:
            res*=-1
            res+=MOD
        print(res)
    elif len(neg)%2:
        print(0)
    else:
        res=1
        for i in pos+neg:
            res*=i
            res%=MOD
        print(res)
elif len(pos)==0:
    res=1
    if k%2 and nzero>0:
        print(0)
    elif k%2:
        neg.sort()
        for i in range(k):
            res*=MOD-neg[i]
            res%=MOD
        print(res)
    else:
        neg.sort(reverse=True)
        for i in range(k):
            res*=MOD-neg[i]
            res%=MOD
        print(res)
elif len(neg)==0:
    res=1
    pos.sort(reverse=True)
    for i in range(k):
        res*=pos[i]
        res%=MOD
    print(res)
else:
    pos.sort(reverse=True)
    neg.sort(reverse=True)
    ruip=[1 for i in range(len(pos)+1)]
    ruin=[1 for i in range(len(neg)+1)]
    for i in range(len(pos)):
        ruip[i+1]=ruip[i]*pos[i]
        ruip[i+1]%=MOD
    for i in range(len(neg)):
        ruin[i+1]=ruin[i]*neg[i]
        ruin[i+1]%=MOD
    np=0
    if len(pos)>=k:
        np=k
    elif (k-len(pos))%2:
        np=len(pos)-1
    else:
        np=len(pos)
    while np>=2 and (pos[np-1]*pos[np-2]<neg[k-np+1]*neg[k-np]):
        np-=2
        if len(neg)-1<k-np+1:
            break
    print((ruip[np]*ruin[k-np])%MOD)


Measured memory_bytes: 121036