akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n;
int a[1000001];
char s[1000001];
signed main()
{
	int k,ans=0;
	scanf("%d%d",&n,&k);
	while(n)
	{
		n/=k;
		ans++;
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
using namespace std;

int main(void){
    int n,m,nsum,sum;
    while(1) {
        nsum = 0;
        sum = 0;
        cin >> n >> m;
        if(n == 0) break;
        vector<int> num(n,0);
        rep(i,n) {
            cin >> num[i];
        }
        rep(i,m) {
            nsum += num[i];
        }
        rep(i,n-m-1) {
            nsum = nsum - num[i] + num[i+m];
            if(nsum > sum) sum = nsum;
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 3092
/*g++ main.cpp -o main.out*/
/*./main.out*/

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

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<' '<<b<<' '<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
char a[100100];
long long b[100100];
int main()
{
    long long n,q,i,j;
    scanf("%lld %lld",&n,&q);
    scanf("%s",a);
    for(i=0,j=0;a[i+1]!='\0';i++)
    {
        b[i]=j;
        if(a[i]=='A'&&a[i+1]=='C')
            j++;
    }
    b[i]=j;
    while(q--)
    {
        scanf("%lld%lld",&i,&j);
        printf("%lld\n",b[j-1]-b[i-1]);
    }
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;

ll comb[51][51];
vector<ll> v;

ll sum = 0;
double max_ave;

int main(void)
{

    int N, A, B;
    cin >> N >> A >> B;

    for (int i = 0; i < 51; ++i)
    {
        comb[i][0] = 1;
        comb[i][i] = 1;
    }

    for (int i = 1; i < 51; ++i)
    {
        for (int j = 1; j < 51; ++j)
        {
            comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
        }
    }
    map<ll, ll> mp; // 各要素の個数を求める
    ll t = 0;
    for (int i = 0; i < N; ++i)
    {
        ll a;
        cin >> a;
        t = a;
        v.push_back(a);
        mp[a]++;
    }
    if (mp[t] == N)
    {
        ll ans = 0;
        for (int i = A; i <= B; ++i)
        {
            ans += comb[B][i];
        }
        cout << t << endl;
        cout << ans << endl;
    }
    else
    {
        sort(v.begin(), v.end());

        map<ll, ll> mp1; // 最大値を求める際に使った要素の個数
        for (int i = 0; i < A; ++i)
        {
            sum += v[N - i - 1];
            mp1[v[N - i - 1]]++;
            t = v[N - i - 1];
        }

        max_ave = (double)sum / A;

        ll ans = 0;

        if (mp1[t] == A)
        {
            for (int i = A; i <= min((ll)B, mp[t]); ++i)
            {
                ans += comb[mp[t]][i];
            }
        }
        else
        {
            ans = 1;
            for (auto itr = mp1.begin(); itr != mp1.end(); ++itr)
            {
                ans *= comb[mp[(*itr).first]][(*itr).second];
            }
        }

        cout << fixed << setprecision(8) << max_ave << endl;
        cout << ans << endl;
    }
    //cout << max_ave << endl;
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int H,W,K;
    cin >> H >> W >> K;
    char a[H][W]; REP(i,H)REP(j,W) cin >> a[i][j];

    int sx, sy;
    REP(i,H)REP(j,W) if(a[i][j] == 'S'){sx=i; sy=j;}

    int d[H][W]; REP(i,H)REP(j,W) d[i][j] = INF;

    vector<P> v{P(1,0),P(-1,0),P(0,1),P(0,-1)};
    int ans = INF;
    queue<tpl> q; q.emplace(sx,sy,0);
    while(!q.empty()){
        int i,j,cost; tie(i,j,cost) = q.front(); q.pop();

        if(cost > K) continue;
        if(a[i][j]=='#' || d[i][j]<INF) continue;
        if(i==0 || j==0 || i==H-1 || j==W-1){
            ans = 1;
            break;
        }
        
        d[i][j] = cost;
        int mn = (min({i,j,H-1-i,W-1-j}) + K-1) / K;
        chmin(ans, 1+mn);

        for(auto &p : v){
            int x = i+p.first, y = j+p.second;
            q.emplace(x,y,cost+1);
        }
    }

    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

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


int main() {
	int n, y;
	cin >> n >> y;

	int res1000 = -1, res5000 = -1, res10000 = -1;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j + i <= n; j++) {
			int k = n - i - j;
			int total = 1000 * i + 5000 * j + 10000 * k;
			if (total == y) {
				res1000 = i; res5000 = j; res10000 = k;
			}
		}
	}

	cout << res10000 << " " << res5000 << " " << res1000 << endl;
}

Measured memory_bytes: 256
N, P = map(int, input().split())
A = list(map(int, input().split()))
odd = 0
even = 0
for i in range(N):
  if A[i] %2 == 0:
    even += 1
  else:
    odd += 1
if P == 0:
  if even == N:
    print(2**N)
  else:
    print(2**(N-1))
    
else:
  if even == N:
    print(0)
  else:
    print(2**(N-1))

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
//   cout<<std::setprecision(12)<<

int main()
{
    ll i,j,k,l,m,n,x;
     cin >> x;

     l = x/500;
     ll ans = l*1000;
     l = x%500;
     l = l/5;
     ans += (l*5);

     cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#define int long long
using namespace std;
int uiop[123456];
string test[123456];
signed main() {
	int n, b = 0, sum = 0, ans = 0; string s, t = "a", u = "a";
	for (int h = 0; h < 8; h++) {
		cin >> s; if (ans < s.size()) { ans = s.size(); t = s; }
		int a = 0;
		for (int i = 0; i < b; i++) {
			if (test[i] == s) {
				uiop[i]++; a++;
			}
		}
		if (a == 0) {
			test[b] = s; uiop[b]++; b++;
		}
	}
	for (int h = 0; h < b; h++) {
		sum = max(sum, uiop[h]);
	}
	for (int h = 0; h < b; h++) {
		if (uiop[h] == sum) {
			u = test[h];
		}
	}
	cout << u << ' ' << t << endl;
}


Measured memory_bytes: 3968
import java.util.* ;
public class Main{
  public static void main(String args[]){
       	Scanner sc = new Scanner(System.in);
    int A = sc.nextInt() ;
    int B = sc.nextInt() ;
    int plus = A+B;
    int minus = A-B;
    int kakeru = A*B;
    
    if(B>-B){
      if(plus<kakeru)
        System.out.println(kakeru);
      else
        System.out.println(plus);
    }else{
      if(minus<kakeru)
        System.out.println(kakeru);
      else
        System.out.println(minus);
      
    } 
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;

int main() {
	pair<ll, ll> a, b;
	cin >> a.first >> a.second >> b.first >> b.second;
	ll res;
	if (a.first >= b.second || b.first >= a.second) {
		res = 0;
	}
	else if (a.first >= b.first) {
		res = min(a.second, b.second) - a.first;
	}
	else if (b.first >= a.first) {
		res = min(a.second, b.second) - b.first;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

void factorize(ll N, ll M, set<ll>& V) {
    ll L = gcd(N,M);
    M = L;
    for (ll i = 2; i * i <= L; i++) {
        if (M % i == 0) {
            V.insert(i);
            while (M % i == 0) M /= i;
        }
    }
    if (M != 1) V.insert(M);
}

int main() {
    ll A, B; cin >> A >> B;
    set<ll> VA;
    factorize(A, B, VA);
    cout << VA.size() + 1 << endl;
}


Measured memory_bytes: 3552
package main

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

func main() {
	a := receiveInput()
	n := len(a)

	var sum int
	for _, v := range a {
		sum += v
	}
	avg := sum / n

	cost1 := evalCost(a, avg)
	cost2 := evalCost(a, avg+1)

	if cost1 < cost2 {
		fmt.Println(cost1)
	} else {
		fmt.Println(cost2)
	}
}

func receiveInput() []int {
	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var n int
	fmt.Scanf("%d", &n)

	var a []int
	for i := 0; i < n; i++ {
		a = append(a, nextInt((sc)))
	}

	return a
}

func nextInt(sc *bufio.Scanner) int {
	if sc.Scan() {
		i, err := strconv.Atoi(sc.Text())
		if err != nil {
			panic(err)
		}
		return i
	} else {
		panic("failed to scan")
	}
}

func evalCost(a []int, avg int) int {
	var cost int
	for _, v := range a {
		cost += (v - avg) * (v - avg)
	}
	return cost
}


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

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

ll mod_pow(ll a, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        ll tmp = mod_pow(a, n / 2);
        return (tmp * tmp) % MOD;
    }
    return (a * mod_pow(a, n - 1)) % MOD;
}

vector<ll> fact;
vector<ll> inv_fact;

void comb_init(int n) {
    fact.resize(n + 1);
    inv_fact.resize(n + 1);
    fact[0] = inv_fact[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % MOD;
        inv_fact[i] = (inv_fact[i - 1] * mod_pow(i, MOD - 2)) % MOD;
    }
}

ll comb(int n, int k) {
    if (n < k) return 0;
    ll ret = fact[n];
    (ret *= inv_fact[k]) %= MOD;
    (ret *= inv_fact[n - k]) %= MOD;
    return ret;
}

int main() {
    ll N, M;
    cin >> N >> M;
    ll ans = 1;
    comb_init(200000);
    for (ll i = 2; i * i <= M; i++) {
        int cnt = 0;
        while (M % i == 0) {
            M /= i;
            cnt++;
        }
        (ans *= comb(cnt + N - 1, N - 1)) %= MOD;
    }
    if (M > 1) (ans *= N) %= MOD;
    cout << ans << endl;
}

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

using namespace std;
string s;
int ans,here;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>s;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'R') here++;
        if(s[i] =='S') here = 0;
        ans = max(here,ans);
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 3636
#include <iostream>
#include<cmath>
using namespace std;
int main(void){
    int a,b,c,d,e,x,y,z,h,j,k;
    cin>>a>>b>>c>>d>>e;
    x=abs(a);
    y=x*c;
    h=b-a;
    j=h*e;
    z=b*e;
    if(a<0){
        k=y+d+z;
        cout<<k<<endl;
    }
    else if (a>0){
    cout<<j<<endl;
    }
    return 0;
    
}



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

Measured memory_bytes: 3060
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#define ll long long
#define inf 20021225
#define N 100010
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
vector<int> E[N];
struct edge{int to,lt;}e[N]; int in[N],cnt;
void add(int x,int y){e[++cnt].to=y, e[cnt].lt=in[x], in[x]=cnt;}
int a[N],b[N],id[N],fa[N],rk[N],n,m; ll sum[N],f[N];
bool cmp(int x,int y){return a[x]<a[y];}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void dfs(int x,int fr)
{
	sum[x]=b[x];
	for(int i=in[x];i;i=e[i].lt)
		dfs(e[i].to,x),sum[x]+=sum[e[i].to]; 
}
void solve(int x,int fr)
{
	if(!in[x])	return void(f[x]=a[x]+b[x]); f[x]=1e18;
	for(int i=in[x];i;i=e[i].lt)
	{
		int y=e[i].to; solve(y,x);
		f[x]=min(f[x],sum[x]-sum[y]+max(1ll*a[x],f[y]));
	}
}
int main()
{
	n=read(),m=read(); int x,y;
	for(int i=1;i<=n;i++)	a[i]=read(),b[i]=read(),a[i]=max(a[i]-b[i],0),id[i]=i;
	for(int i=1;i<=m;i++)	x=read(),y=read(),E[x].push_back(y),E[y].push_back(x);
	sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;i++)	rk[id[i]]=i,fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		x=id[i];
		for(int j=0;j<E[x].size();j++)
		{
			y=E[x][j]; y=find(y);
			if(rk[y]<rk[x]) add(x,y),fa[y]=x;
		}
	}
	dfs(id[n],0); solve(id[n],0); printf("%lld\n",f[id[n]]);
	return 0;
}

Measured memory_bytes: 13820
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<unordered_map>
#define deg(x) cout<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;typedef long long LL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=1e9+7;
const ll inf=1e9+7;
const long double eps=1e-8;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
const double pi=acos(-1);

map<string,int> mp;
int main()
{
    TB
    int n;
    cin>>n;
    while(n--){
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<'\n';
    cout<<"WA x "<<mp["WA"]<<'\n';
    cout<<"TLE x "<<mp["TLE"]<<'\n';
    cout<<"RE x "<<mp["RE"]<<'\n';
    return 0;
}


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

ll getPos(vector<int> a, int n) {
    ll ans=0;
    vector<ll> fac(n);
    fac[0]=1;
    for (int i=1;i<n;i++) fac[i]=fac[i-1]*i;
    vector<int> ca(n);
    for (int i=0;i<n;i++) {
        a[i]--;
        int c=0;
        for (int j=0;j<a[i];j++) {
            if (ca[j]==1) c++;
        }
        ans+=fac[n-1-i]*(a[i]-c);
        ca[a[i]]=1;
    }
    return ans;
}

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for (int i=0;i<n;i++) cin >> p[i];
    for (int i=0;i<n;i++) cin >> q[i];
    ll ansp=getPos(p,n);
    ll ansq=getPos(q,n);
    cout << abs(ansp-ansq) << endl;
}

Measured memory_bytes: 256
from collections import deque

n,m = map(int, input().split())
g = [[] for _ in range(n)]
prev = [0] * n

for i in range(m):
    a,b = map(int, input().split())
    g[a-1].append(b)
    g[b-1].append(a)

count = 0
prev[0] = 1

def keiro(pre,q,now):
    global count
    if len(q) == 0:
            return

    now = q.popleft()
    
    for no in g[now-1]:
        if pre[no-1] == 0:

            pre_1 = pre.copy()
            pre_1[no-1] = 1
            if sum(pre_1) == n:
                count+=1
                return
            q.append(no)
            keiro(pre_1,q,no)
        else:

            keiro(pre,q,no)


keiro(prev,deque([1]),1)
print(count)



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

using namespace std;

int main(){

unsigned long long int n,a,b,k,p ;

    cin>> n>> a>> b;

    if(a == 0)
        cout << "0\n";
    else if(n < a+b && n<a)
        cout << n<<"\n";
    else if(n < a+b && n>=a)
        cout << a<<"\n";
    else{
        k = n/(a+b);
        p =n%(a+b);
        if(n%(a+b) >= a) p = a;
        
        cout << (k)*a + p<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
(let* ((n (read))
       (c (make-hash-table :test 'equal :size n))
       (ans 0))
  (loop :for i :from 1 :to n
        :for s := (read-line)
        :unless (gethash s c)
        :do (progn
              (setf (gethash s c) t)
              (incf ans)))
  (format t "~A~%" ans))


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

#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define clr(x) memset((x), 0, sizeof((x)));
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long i64;
typedef unsigned long long ull;

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

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

int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

ll gcd(ll a, ll b) {
    a = abs(a);
    b = abs(b);
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

typedef ll ptdata;

struct pt {
    ptdata x, y;

    pt() { }

    pt(ptdata x, ptdata y) : x(x), y(y) { }

    inline pt operator-(const pt &r) const {
        return pt(x - r.x, y - r.y);
    }

    inline pt operator+(const pt &r) const {
        return pt(x + r.x, y + r.y);
    }

    inline pt operator*(const ptdata &r) const {
        return pt(x * r, y * r);
    }

    inline ptdata sqlen() const {
        return abs(x * x + y * y);
    }

    inline bool operator<(const pt &r) const {
        if (x != r.x) return x < r.x;
        return y < r.y;
    }

    inline bool operator==(const pt &r) const {
        return x == r.x && y == r.y;
    }
};

ostream &operator<<(ostream &os, const pt &p) {
    return os << "(" << p.x << "," << p.y << ")";
}

inline ptdata cross(const pt &l, const pt &r) {
    return l.x * r.y - l.y * r.x;
}

inline ptdata dot(const pt &l, const pt &r) {
    return l.x * r.x + l.y * r.y;
}


ll pwmod(ll a, ll n, ll mod) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return ret;
}

template<typename T>
inline T sqr(T x) {
    return x * x;
}


inline void solve() {
    int n = nxt();
    int L = nxt();
    vector<int> a(n);
    forn(i, n) {
        a[i] = nxt();
    }
    int pos = -1;
    for (int i = 0; i + 1 < n; ++i) {
        if (a[i] + a[i + 1] >= L) {
            pos = i;
            break;
        }
    }
    if (pos == -1) {
        cout << "Impossible\n";
        return;
    }
    cout << "Possible\n";
    forn(i, pos) {
        cout << i + 1 << "\n";
    }
    for (int i = n - 1; i > pos; --i) {
        cout << i << "\n";
    }
}

void prepare() {

}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);


    prepare();

    int t = 1;
    //t = nxt();
    forn(i, t) {
        solve();
    }

    //cerr << "Time " << clock() / (double) CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <algorithm>
#include <iostream>
using namespace std;
int t[200],h[200];
int main(){
  int n,m;
  while(cin>>n>>m,n||m){
    for(int i=0;i<n;++i) cin>>t[i];
    for(int i=0;i<m;++i) cin>>h[i];
    int S=0,H=0;
    for(int i=0;i<n;++i) S+=t[i];
    for(int i=0;i<m;++i) H+=h[i];
    int c = 1<<28;    
    int s1=-1,s2=-1;
    for(int i=0;i<n;++i)
      for(int j=0;j<m;++j){
	if(S-t[i]+h[j]==H-h[j]+t[i] && c>t[i]+h[j]){
	  c=t[i]+h[j];
	  s1=t[i];
	  s2=h[j];
	}
      }
    if(c==1<<28) cout << -1 << endl;
    else cout << s1 << " " << s2 << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char[] torikumi = sc.next().toCharArray();
		int lose = 0;
		for(char c:torikumi) {
			if(c=='x')
				lose++;
		}
		
		System.out.println(lose>=8 ? "NO" : "YES");
		sc.close();
	}
}


Measured memory_bytes: 21844
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];Arrays.fill(a, -1);
		boolean flag = true;
		for (int i = 0; i < m; i++) {
			int s = sc.nextInt()-1;
			if(a[s]==-1)a[s] = sc.nextInt();
			else {
				if(a[s] == sc.nextInt())continue;
				else flag = false;
			}
		}
		if(!flag)System.out.println(-1);
		else if(n==1) {
			if(a[0]==-1)System.out.println(0);
			else System.out.println(a[0]);
		}else if(a[0]==0) {
			System.out.println(-1);
		}else {
			for (int i = 0; i < n; i++) {
				if(a[i]!=-1)System.out.print(a[i]);
				else{
					if(i!=0)System.out.print(0);
					else System.out.print(1);
				}
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 23380
A, B = map(int, input().split())
import fractions
g = fractions.gcd(A,B)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

fac = factorization(g)
fac

if fac[0][0] == 1:
    ans = 1
else:
    ans = len(fac)+1
print(ans)

Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;

const int N = 100228;
vector<int> e[N];

void nein() {
    cout << "No\n";
    exit(0);
}

void ja() {
    cout << "Yes\n";
    exit(0);
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif  
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int n;
    cin >> n;

    vector<pair<int, int>> ans;

    int m = n + 1 - (n % 2);

    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            if (i + j != m) {
                ans.emplace_back(i, j);
            }
        }
    }

    cout << ans.size() << "\n";
    for (auto val: ans) {
        cout << val.first << " " << val.second << "\n";
    }
}

Measured memory_bytes: 2688
N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(M)]

UF = list(range(N + 1))
SIZE = [0] + [1] * N  # 1-indexed


def find(x):
    if UF[x] != x:
        UF[x] = find(UF[x])
    return UF[x]


def unite(x, y):
    m = min(find(x), find(y))
    SIZE[m] = SIZE[find(x)] + SIZE[find(y)]
    UF[find(x)] = m
    UF[find(y)] = m


def is_same(x, y):
    return find(x) == find(y)


def scan_uf():
    for i in range(len(UF)):
        find(i)


ans = [N * (N - 1) // 2]
for a, b in AB[::-1]:
    if not is_same(a, b):
        ans += [ans[-1] - SIZE[find(a)] * SIZE[find(b)]]
        unite(a, b)
    else:
        ans += [ans[-1]]
print(*ans[-2::-1], sep='\n')


Measured memory_bytes: 31088
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a[ohara],b[ohara],c[ohara],d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
vector<ll> g[ohara];
bool vi[ohara];
ll dis[ohara];
map<P,ll> mp;

//-------------------------↓↓↓↓↓↓------------------------

void dfs(ll now,ll depth){
    if(vi[now])return;
    vi[now]=true;
    dis[now]=depth;
    rep(i,Size(g[now])){
        dfs(g[now][i],depth+mp[{now,g[now][i]}]);
    }
}

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

    cin>>n;
    rep(i,n-1)cin>>a[i]>>b[i]>>c[i];
    rep(i,n-1){
        a[i]--;b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
        mp[{a[i],b[i]}]=c[i];
        mp[{b[i],a[i]}]=c[i];
    }
    dfs(0,0);
    rep(i,n){
        if(dis[i]%2==0)Cout("0");
        else Cout("1");
    }
    return 0;
}


Measured memory_bytes: 53888
# -*- coding: utf-8 -*-

import math

a, b, C = map(int, raw_input().split())
radC = math.radians(C)
c = math.sqrt(a*a+b*b-2*a*b*math.cos(radC))
S = a*b/2*math.sin(radC)
print S
print a+b+c
print 2*S/a

Measured memory_bytes: 6652
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<tuple>
#include<stack>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tpl;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 305

const ll INF = 1e9 + 7;
const ll MOD = 10000;

ll dp[105][5][5];
//dp[i][j][k]:=i日目の時点でパスタjをk日連続で食べているときの翌日以降の組合せ
ll N, K;
ll plan[105];

ll dfs(ll day,ll pasta,ll cnt){

	//本日の日付day,本日食べるパスタpasta、現在の連続数cnt

	if (day == N)
	{
		//最後まで問題がなかったので解として適する
		return 1LL;
	}

	if (dp[day][pasta][cnt] != -1)
	{
		//既に調べた
		return dp[day][pasta][cnt];
	}

	ll ret = 0;

	if (plan[day + 1] > 0)//翌日の予定が決まっている場合
	{
		if (pasta == plan[day + 1])//今日食べるパスタと翌日のパスタが同じ種類の場合
		{
			if (cnt == 2)//既に本日の時点で2日連続で食べている場合は不適
			{
				return 0LL;
			}
			else
			{
				//本日の時点で2連続はしていないのでまだ食べられる
				//パスタplan[day]を連続して食べるのでcntを1つ増やす
				ret += dfs(day + 1, plan[day + 1], cnt + 1);
				ret %= MOD;
			}
		}
		else
		{
			//違うパスタを食べるのでカウントをリセットする
			ret += dfs(day + 1, plan[day + 1], 1);
			ret %= MOD;
		}
	}
	else
	{
		//予定がない場合
		for (int i = 1; i <= 3; i++)//全てのパスタを試す
		{
			if (pasta == i)//今日食べるパスタと翌日のパスタが同じ種類の場合
			{
				if (cnt == 2)//既に本日の時点で2日連続で食べている場合は調べない
				{
					continue;
				}
				else
				{
					//2日連続でまだ食べていないのでまだ食べられる
					ret += dfs(day + 1, i, cnt + 1);
					ret %= MOD;
				}
			}
			else
			{
				//違う種類のパスタを食べる
				ret += dfs(day + 1, i, 1);
				ret %= MOD;
			}
		}
	}
	return dp[day][pasta][cnt] = (ret % MOD);
}

int main() {

	cin >> N >> K;
	for (int i = 0; i < K; i++)
	{
		ll a, b;
		cin >> a >> b;
		plan[a] = b;//a日目はbを食べる
	}

	for (int i = 0; i < 105; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			for (int k = 0; k < 5; k++)
			{
				dp[i][j][k] = -1;
			}
		}
	}

	ll ans = 0;
	if (plan[1] > 0)
	{
		//初日に既に予定が決まっている場合
		ans = dfs(1, plan[1], 1);
	}
	else
	{
		//初日の予定がない場合は全部調べる
		for (int i = 1; i <= 3; i++)
		{
			ans += dfs(1, i, 1);
			ans %= MOD;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
int main(void){
  int n,i=0,k=0,j=0,flag,temp;
  int A[1000000];
  scanf("%d",&n);
  while(scanf("%d ",&A[i])==1){
    i++;
  }
  flag=1;
  while(flag){
    flag=0;
    for(j=n-1;j>=1;j--){
      if(A[j]<A[j-1]){
        k++;
        temp=A[j];
        A[j]=A[j-1];
        A[j-1]=temp;
        flag=1;
      }
    }
  }
  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d",A[n-1]);
  printf("\n");
  printf("%d\n",k);
}

Measured memory_bytes: 1856
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;

#define abs(N) ((N>0)?N:-1*N)
#define min(A,B) ((A>B)?B:A)
#define max(A,B) ((A<B)?B:A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

int main(){

	while(true){
		string str;
		int n,h,sz,sum=0;
		cin >> str;
		if(str=="-") break;
		cin >> n;
		for (int i = 0; i < n; ++i) {
			cin >> h;
			sum += h;
		}
		sz = str.size();
		int s = sum % sz;
		print(str.substr(s,sz-s));
		print(str.substr(0,s));
		println("");
	}

	return 0;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
typedef pair<ll,ll> Pair;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }

const ll INF=99999999999999;
const ll MOD=1000000007;

struct UnionFind { 
    vector<ll> par; //par[i]:iの親の番号
    UnionFind(ll N) : par(N) {
      for(ll i = 0; i < N; i++) par[i] = i; //最初は全て根
    }
    
    ll root(ll x) {
      if(par[x] == x) return x;
      return par[x] = root(par[x]);
    }
    
    void unite(ll x, ll y) {
      ll rx = root(x); //rx:xの根
      ll ry = root(y); //ry:yの根
      if(rx == ry) return;
      par[rx] = ry; 
    }
    
    bool connected(ll x, ll y) {
      ll rx = root(x);
      ll ry = root(y);
      return rx == ry;
    }
  };
 
int main() {
  ll n,m;
  cin >> n >> m;
  vl x(m), y(m), z(m);
  rep(i,m){
    cin >> x[i] >> y[i] >> z[i];
  }
  UnionFind UF(n);
  rep(i,m){
    UF.unite(x[i], y[i]);
  }
  vl cnt(n,0);
  rep(i,n){
    cnt[UF.root(i)]++;
  }
  ll ans = 0;
  rep(i,n){
    if(cnt[i]) ans++;
  }
  cout << ans;
    
 return 0;
}


Measured memory_bytes: 4608
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: f64
    }
    let num = (n / 2f64).ceil();
    println!("{}", num / n);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec << std::endl; }
  os << "--------" << std::endl;
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

int main()
{
  ll MAX_A = 2000;
  ll N, K;
  std::cin >> N >> K;
  std::vector< ll > va(N, 0LL);
  std::vector< ll > vunder(MAX_A + 2, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
    vunder[va[i]+1]++;
  }

  // この値未満のものが何個あるかを調べる
  for (ll i = 1; i <= MAX_A + 1; i++) {
    vunder[i] += vunder[i-1];
  }

  ll ans = 0LL;
  for (ll i = 0; i < N; i++) {

    // 最初の数列では、自分の値未満だが転倒数にならないものがある
    ll cnt = vunder[va[i]];
    for (ll j = 0; j < i; j++) {
      if (va[j] < va[i]) {
        cnt--;
      }
    }
    ans = (ans + cnt * K) % MOD;

    // Σ を求める
    ll num = (K * (K-1) / 2) % MOD;
    ll val = (vunder[va[i]] * num) % MOD;
    ans = (ans + val) % MOD;
  }

  print(ans);
  return 0;
}


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

int main(){
	int n,t,a;
	cin>>n>>t>>a;
	int h[n],m=0;
	double p[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
		p[i]=abs(a-(t-h[i]*0.006));
		if(p[i]<p[m]) m=i;
	}
	cout<<m+1;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
	int n,r;
	while(cin>>n>>r){
		if(n>=10){
			cout<<r<<endl;
		}
		else{
			cout<<r+100*(10-n)<< endl;
		}
	}
	return 0; 
} 


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

struct Edge
{
    ll to;
    ll cost;
};

using Graph = vector<vector<Edge>>;

void dfs(const Graph &g, vll &dist, ll v)
{
    for (auto nv : g[v])
    {
        if (dist[nv.to] != -1)
            continue;

        dist[nv.to] = dist[v] + nv.cost;
        dfs(g, dist, nv.to);
    }
}

void Main()
{
    ll n = in();
    Graph g(n);
    rep(i, n - 1)
    {
        ll a = in(), b = in(), c = in();
        --a;
        --b;
        g[a].pb({b, c});
        g[b].pb({a, c});
    }

    ll q = in(), k = in();
    --k;
    vll dist(n, -1);
    dist[k] = 0;
    dfs(g, dist, k);
    rep(i, q)
    {
        ll x = in(), y = in();
        --x;
        --y;
        cout << dist[x] + dist[y] << endl;
    }
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 14336
import sys
import math
sys.setrecursionlimit(10**6)


def main(input, print):
    N, D = map(int, input().split())
    ans = 0
    for i in range(N):
        X, Y = map(int, input().split())
        d = math.sqrt(X**2+Y**2)
        if D >= d:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 68796
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

int N;
int B[4]={};
double dp[304][304][304];


double dfs(int x,int y,int z){
    if(dp[x][y][z]!=-1)return dp[x][y][z];
    if(!x && !y && !z)return 0;
    
    double r[3]={-1,-1,-1};
    if(x!=0)r[0]=dfs(x-1,y,z)*x/(x+y+z);
    if(y!=0)r[1]=dfs(x+1,y-1,z)*y/(x+y+z);
    if(z!=0)r[2]=dfs(x,y+1,z-1)*z/(x+y+z);
    double c=0;
    REP(i,3){
        if(r[i]!=-1){c+=r[i];}
    }
    dp[x][y][z]=c+((double)N/(x+y+z));
    //cout << x MM y MM z MM dp[x][y][z] << endl;
    return dp[x][y][z];
    
}

signed main(void){
    int A[304];
    cin >> N;
    REP(i,N){
        cin >> A[i];
        B[A[i]]++;
    }
    //cout << B[1] MM B[2] MM B[3] << endl << endl;
    
    REP(i,304){REP(j,304){REP(k,304){
       dp[i][j][k]=-1; 
    }}}
    
    double Ans=dfs(B[1],B[2],B[3]);
    
    printf("%.10f\n",Ans);
    
    return 0;
}



Measured memory_bytes: 219776
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GC032A2
{
    class Program
    {
        public static List<int> B = new List<int>();
        public static List<int> ans = new List<int>();
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] b = new int[n];
            string[] input = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
            {
                b[i] = int.Parse(input[i]);
                B.Add(b[i]);
            }
            for (int i = B.Count; i >0; i--)
            {
            pull_from_B(B.Count);
            }
            if (B.Count == 0)
            {
                ans.Reverse();
                foreach(int member in ans)
                    {
                        Console.WriteLine(member);
                    }
            }
            else
                {
                    Console.WriteLine(-1);
                }
            }
            public static void pull_from_B(int u)
            {
                if (B.IndexOf(u) == (u - 1))
                {
                    ans.Add(u);
                    B.Remove(u);
                }
                else
                {
                    pull_from_B(u - 1);
                }
            }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>
int main(void){
  int n,l,eat,sum=0,i;
  scanf("%d%d",&n,&l);
  if(l>=0){
    eat=0;
  }else if(n+l>0){
    eat=-l;
  }else{
    eat=n-1;
  }
  for(i=0;i<n;i++){
    sum+=i;
  }

  printf("%d\n",sum-eat+l*(n-1));
  return(0);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
/*#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>*/

typedef long long ll ;
typedef double db;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define sf(a)		 scanf("%d",&a)
#define sfl(a)		scanf("%lld",&a)
#define sff(a,b)	 scanf("%d %d",&a,&b)
#define sffl(a,b)	scanf("%lld %lld",&a,&b)
#define pb(a)         push_back(a)
#define loop0(i,n)          for(int i=0;i<n;i++)
#define loop1(i,n)          for(int i=1;i<=n;i++)
#define loopab(a,b)       for(int i=a;i<=b;i++)
#define gcd(a, b)     __gcd(a, b)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
//define abs(x)		fabs(x)
#define pcase(z,x)     cout<<"Case "<<z<<": "<<x<<"\n"
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;

int main()
{
	ll n,k,x;
	cin>>n>>k;
	x = n%k;
	if(abs(x-k)<x)cout<<abs(x-k)<<nw;
	else cout<<x<<nw;
	return 0;
}

Measured memory_bytes: 256
import std.functional,
       std.algorithm,
       std.container,
       std.typetuple,
       std.typecons,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main()
{
auto ip = readln.split.to!(int[]);
if(ip[0] < ip[1] && ip[1] < ip[2]) writeln("Yes");
else writeln("No");
}


Measured memory_bytes: 2480
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  cout << 2018 << s.substr(4, 6) << endl;


  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
l=0
l0=0
a_sum=sum(a)
for i in range(n):
    l+=a[i]
    if l*2>=a_sum:
        l0=l-a[i]
        break
print(min(2*l-a_sum,a_sum-2*l0))

Measured memory_bytes: 25768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;

template<typename IntType>
IntType all_pattern(IntType a, IntType b, IntType mod_) {
  IntType res = 1;
  for (a %= mod_; b; a = a * a % mod_, b >>= 1)
    if (b & 1) res = res * a % mod_;
  return res;
}

int main(int argc, char **argv) {
    i64 k;
    cin >>k;

    i64 remain{0};
    for (int i=0; i<k; ++i) {
        remain += 7*all_pattern<i64>(10, i, k);
        remain %= k;
        if (remain==0) {
            cout << (i+1) << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}


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

const int N = 1e6 + 100;

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

    string s;
    cin >> s;
    cout << s.substr(0, 3) << endl;

    return 0;
}


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

int main() {

int N,D,X;
cin >>N>>D>>X;
int A[N+10];
int hettakazu=0;
for (int i=1;i<=N;i++){
   cin>>A[i];
   for(int j=0;j<1000;j++){
      if(j*A[i]+1<=D){
         hettakazu++;
      }
      else{break;}
}
}
cout<<hettakazu+X<<endl;
}

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

int n;
vector<int> p;

void input() {
    cin >> n;
    p = vector<int>(n);
    for(int i = 0; i < n; i++) {
        cin >> p.at(i);
    }
//    cout << s;
}

void solve() {
    auto sorted = p;
    sort(begin(sorted), end(sorted));
    int count = 0;
    for(int i =0; i< n ; i++) {
        if(p.at(i) != sorted.at(i)) {
            count++;
        }
    }
    if (count > 2) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}



int main() {
    input();
    solve();

}


Measured memory_bytes: 256
n, m, q = map(int, input().split())
ans = [[0] * (n+2) for _ in range(n+2)]
lr = [list(map(int, input().split())) for _ in range(m)]
for l, r in lr:
    ans[0][r] += 1
    ans[0][-1] -= 1
    ans[l+1][-1] -= 1
    ans[l+1][r] -= 1

for i in range(n+2):
    for j in range(n+1):
        ans[i][j+1] += ans[i][j]

for i in range(n+1):
    for j in range(n+2):
        ans[i+1][j] += ans[i][j]

for _ in range(q):
    p, q = map(int, input().split())
    print(ans[p][q])

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b; cin>>a>>b;
    if (a+b>=10){
        cout<<"error\n";
    }else{
        cout<<a+b<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256