akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
using System.Diagnostics;

class Scanner
{
    private readonly char Separator = ' ';
    private int Index = 0;
    private string[] Line = new string[0];
    public string Next()
    {
        if (Index >= Line.Length)
        {
            Line = Console.ReadLine().Split(Separator);
            Index = 0;
        }
        var ret = Line[Index];
        Index++;
        return ret;
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

}

class Magatro
{
    private string S,T;
    private void Scan()
    {
        var sc=new Scanner();
        S=sc.Next();
        T=sc.Next();
    }

    public void Solve()
    {
        Scan();
        for(int i=S.Length-T.Length;i>=0;i--)
        {
            bool b=true;
            for(int j=0;j<T.Length;j++)
            {
                if(S[i+j]!='?'&&S[i+j]!=T[j])
                {
                    b=false;
                    break;
                }
            }
            if(b)
            {
                char[]ans=new char[S.Length];
                for(int j=0;j<S.Length;j++)
                {
                    if(S[j]=='?')
                    {
                        if(i<=j&&j<i+T.Length)
                        {
                            ans[j]=T[j-i];
                        }
                        else
                        {
                            ans[j]='a';
                        }
                    }
                    else
                    {
                        ans[j]=S[j];
                    }
                }
                Console.WriteLine(new string(ans));
                return;
            }
        }
        Console.WriteLine("UNRESTORABLE");
    }

    static public void Main(string[]args)
    {
        new Magatro().Solve();
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    string s;
    int q;
    cin >> s >> q;
    int len = s.size();
    int t,f;
    char c;
    bool inv = false;
    vector<char> fc, bc;
    REP(i,0,q) {
        cin >> t;
        if (t == 1) {
            inv = !inv;
        } else {
            cin >> f >> c;
            if ((f == 1 && !inv) || (f == 2 && inv)) fc.push_back(c);
            else bc.push_back(c);
        }
    }
    reverse(all(fc));
    if (inv) {
        reverse(all(fc));
        reverse(all(bc));
        reverse(all(s));
        for (auto &c: bc) cout << c;
        cout << s;
        for (auto &c: fc) cout << c;
    } else {
        for (auto &c: fc) cout << c;
        cout << s;
        for (auto &c: bc) cout << c;
    }
    cout << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();

		if (a <= c && c <= b) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  int a[15], x[15][15], y[15][15];
  rep(i, n)
  {
    cin >> a[i];
    rep(j, a[i])
    {
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }

  int Max = 0;
  rep(bi, (1 << n))
  {
    bitset<20> bs(bi);
    bool possible = true;
    rep(i, n)
    {
      if (bs[i] == 0)
        continue;
      rep(j, a[i])
      {
        if (bs[x[i][j]] != y[i][j])
        {
          possible = false;
          break;
        }
      }
      if (!possible)
        break;
    }
    if (possible)
    {
      int cnt = 0;
      rep(i, n) cnt += bs[i];
      Max = max(Max, cnt);
    }
  }
  cout << Max << endl;
  return 0;
}


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

N = int(input())
count = 0

for i in range(1, N + 1):
    a = []
    all_odd = 0
    for j in range(1, i + 1):
        if i % j == 0:
            a.append(j)
    for k in a:
        if k % 2 == 0:
            all_odd += 1
    if all_odd == 0 and len(a) == 8:
        count += 1

print(count)

Measured memory_bytes: 3060
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5 1
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2

output:
INF
0
-5
-3

OR
input:
4 6 0
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2
3 1 0

output:
NEGATIVE CYCLE
"""

import sys
from math import isinf


class Edge(object):
    __slots__ = ('source', 'target', 'cost')

    def __init__(self):
        self.cost = float('inf')
        self.source, self.target = None, None


def generate_edge_table(_v_info):
    for index, each in enumerate(_v_info):
        edge = init_edge_table[index]
        source, target, cost = map(int, each)
        edge.source = source
        edge.target = target
        edge.cost = cost
    return init_edge_table


def bellman_ford():
    distance[root] = 0

    for j in range(vertices - 1):
        for edge in edge_table:
            source, target, cost = edge.source, edge.target, edge.cost
            if distance[source] + cost < distance[target]:
                distance[target] = distance[source] + cost

    for edge in edge_table:
        source, target, cost = edge.source, edge.target, edge.cost
        if distance[source] + cost < distance[target]:
            print('NEGATIVE CYCLE')
            return list()

    return distance


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges, root = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])
    # assert len(init_vertices_table) == vertices_num

    distance = [float('inf')] * vertices
    init_edge_table = tuple(Edge() for _ in range(edges))

    edge_table = generate_edge_table(v_info)

    res = bellman_ford()
    if res:
        print('\n'.join(('INF' if isinf(ele) else str(ele) for ele in res)))

Measured memory_bytes: 8152
#include<iostream>
using namespace std;
int main(){
  int n,k,q;
  cin>>n>>k>>q;
  int m[n]={0};
  for(int i=0;i<q;i++){
    int x;
    cin>>x;
    m[x-1]++;
  }
  for(int i=0;i<n;i++){
  	if(k-(q-m[i])>0)
    cout<<"Yes"<<"\n";
    else
    cout<<"No"<<"\n";
  }
  return 0;
}
    


Measured memory_bytes: 1024
n=int(input())
lst=[0]*10000000
for i in range(1, 101):
  for j in range(1, i+1):
    for k in range(1, j+1):
      temp=i**2+j**2+k**2+i*j+j*k+k*i
      if i==j and j==k:
        lst[temp+1]+=1
      elif i==j and j!=k:
         lst[temp+1]+=3
      elif j==k and k!=i:
         lst[temp+1]+=3
      elif k==i and i!=j:
         lst[temp+1]+=3
      elif i!=j and j!=k and k!=i:
         lst[temp+1]+=6
for p in range(1, n+1):
  print(lst[p+1])

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>x;
	if(x<1200) cout<<"ABC"<<endl;
	else cout<<"ARC"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<typename Num>
        constexpr Num mypow(Num a, long long b) {
            if(b==0)return 1;
            if (a==0)return 0;
            Num x = 1;
              while (b > 0) {
                if(b & 1)x*=a;
                a*=a;
                b >>= 1;
              }
              return x;
        }

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    inline int RANDAM(){
        return rand()%26+1;
    }

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        vl c(26);
        rep(i,26)cin>>c[i];
        vvl s(n,vl(26));
        rep(i,n)rep(j,26)cin>>s[i][j];
        rep(i,n){
            cout<<7<<endl;
        }
    }

Measured memory_bytes: 3752
#! -*- coding:utf-8 -*-


s = list(str(input()))

if len(s) >= 4:
    if s[0] == 'Y' and s[1] == 'A' and s[2] == 'K' and s[3] == 'I':
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(void){
    int l,N;
  	bool ok = true;
  	cin >> N;
  	int i=0, a[N];
    for(int i=0;i<N;i++)cin >>a[i];
  
  	for(int i = 0; i < N; i++){
      if(a[i] % 2 == 0){
 		    if(a[i] % 3 != 0 && a[i] % 5 != 0){
           ok = false;
           break;
    }
    }
    }
    if(ok)cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	String s;
	int k;
	public void run(){
		s = sc.next();
		k = sc.nextInt();
		solve();
	}
	public void solve(){
		ArrayList<String> list = new ArrayList<String>();
		for(int a = 0; a < s.length(); a++){
			for(int b = a+1; b < s.length() + 1; b++){
				String nows = s.substring(a, b);
				if(list.size() >= k){
					if(nows.compareTo(list.get(k-1)) >= 0){
						break;
					}
				}
				
				for(int i = 0; i < k; i++){
					if(list.size() <= i){
						list.add(i, nows);
						break;
					}
					else if(nows.compareTo(list.get(i)) == 0){
						break;
					}
					else if(nows.compareTo(list.get(i)) < 0){
						list.add(i, nows);
						break;
					}
				}
			}
		}
		System.out.println(list.get(k-1));
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
	static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }	
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    vector<int> id(n), d(n), v(n);

    rep(i,n) {
        cin >> id[i] >> d[i] >> v[i];
    }

    double dp[1<<15][15];
    vector< vector<int> > path[1<<15];

    rep(i,1<<n) {
        path[i].resize(n);
        rep(j,n) {
            dp[i][j] = INF;
        }
    }

    rep(i,n) {
        dp[1<<i][i] = 0;
        path[1<<i][i].push_back(id[i]);
    }

    rep(k,1<<n) {
        rep(i,n) {
            if(!(k & (1<<i))) continue;
            rep(j,n) {
                if(k & (1 << j)) continue;
                double sum = 0;
                rep(l,v.size()) {
                    if(k & (1<<l)) sum += v[l]*20.0;
                }
                double t = 2000.0 / (70 + sum);
                double cost = abs(d[i]-d[j]) / t;

                if(dp[k|(1<<j)][j] > dp[k][i] + cost) {
                    dp[k|(1<<j)][j] = dp[k][i] + cost;
                    path[k|(1<<j)][j] = path[k][i];
                    path[k|(1<<j)][j].push_back(id[j]);
                }
            }
        }
    }

    double ans = INF;
    int idx;
    rep(i,n) {
        if(ans > dp[(1<<n)-1][i]) {
            ans = dp[(1<<n)-1][i];
            idx = i;
        }
    }

    rep(i,path[(1<<n)-1][idx].size()) {
        cout << path[(1<<n)-1][idx][i];

        if(i == path[(1<<n)-1][idx].size()-1) cout << endl;
        else cout << " ";
    }

    return 0;
}

Measured memory_bytes: 33920
#include<iostream>
#include<vector>
using namespace std;
int main(void){
    int n,m,o,size=0;
    vector<int> a;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> o;
        size += o;
    }
    if(size<=n){
        cout << n - size << endl;
    }else{
        cout << -1 << endl;
    }
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    int n,x,t;
    cin>>n>>x>>t;
    cout<<(n/x+(n%x?1:0))*t<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
typedef long long int ll;

struct State {
    int x, y, dir;
};

int N, M;
ll L;
char board[110][110];
State nxt[110][110][4][70];
string pat = "NESW";

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

int main() {
    while(cin >> N >> M >> L, N || M || L) {
        int sx, sy, d;
        for(int i=0; i<N; i++) {
            for(int j=0; j<M; j++) {
                cin >> board[i][j];
                if(pat.find(board[i][j]) != string::npos) {
                    sx = i, sy = j, d = pat.find(board[i][j]);
                }
            }
        }

        for(int i=0; i<N; i++) {
            for(int j=0; j<M; j++) {
                if(board[i][j] == '#') continue;
                for(int k=0; k<4; k++) {
                    int d = k;
                    int cnt_ng = 0;
                    while(cnt_ng < 4) {
                        int nx = i + dx[d], ny = j + dy[d];

                        bool ok = true;
                        if(nx < 0 || nx >= N || ny < 0 || ny >= M) ok = false;
                        if(board[nx][ny] == '#') ok = false;
                        if(ok) {
                            nxt[i][j][k][0] = State{nx, ny, d};
                            break;
                        }
                        else {
                            cnt_ng++;
                            d = (d + 1) % 4;
                        }
                    }
                }
            }
        }

        for(int m=1; m<65; m++) {
            for(int i=0; i<N; i++) {
                for(int j=0; j<M; j++) {
                    for(int k=0; k<4; k++) {
                        State t = nxt[i][j][k][m-1];
                        nxt[i][j][k][m] = nxt[t.x][t.y][t.dir][m-1];
                    }
                }
            }
        }

        State ans{sx, sy, d};
        for(int b=0; b<60; b++) {
            if(L >> b & 1) {
                ans = nxt[ans.x][ans.y][ans.dir][b];
            }
        }
        printf("%d %d %c\n", ans.x+1, ans.y+1, pat[ans.dir]);
    }
    return 0;
}


Measured memory_bytes: 36384
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int cnt=0;
    if(n>24){
    while(n>24){
        n=n-25;
        cnt++;
    }
    }
    if(n>9){
    while(n>9){
        n=n-10;
        cnt++;
    }
    }
    if(n>4){
    while(n>4){
        n=n-5;
        cnt++;
    }
    }
    cnt=cnt+n;
    printf("%d\n",cnt);
}


Measured memory_bytes: 2100
using System;
using System.Collections.Generic;
    class Program
    {
        static void Main(string[] args)
        {
            int input1 = int.Parse(Console.ReadLine());
            var input2 = Console.ReadLine();
            int input3 = int.Parse(Console.ReadLine());

            var moji = input2.Substring(input3-1,1);
            var tmp = "";
            var output = "";

            for (int i = 0; i < input1; i++)
            {
                tmp = input2.Substring(i, 1);
                if(tmp.Equals(moji))
                {
                    output = output + tmp;
                }
                else
                {
                    output = output + "*";
                }
            }

            Console.WriteLine(output);

        }
    }

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<tuple<string, int32, int32>> restaurants(n);
    REP(i,n){
        string s;
        cin >> s;
        int32 p;
        cin >> p;
        restaurants[i] = make_tuple(s,-p,i+1);
    }
    sort(ALL(restaurants));
    REP(i,n)ANS(get<2>(restaurants[i]));
    return 0;
}

Measured memory_bytes: 256
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
#s = {s():0 for _ in range(n)}

a = {}
for i in range(n):
	s = input()
	try:
		a[s] += 1
	except KeyError:
		a[s] = 1
b = sorted(a.items(),key = lambda x:x[0])

memo = max([i[1] for i in a.items()])
for i in b:
	"""print(i,"i")
	print(i[0],"i[0]")
	print(i[1],"i[1]")
	print(max(b)[0],"max(b)[0]")"""
	if i[1] == memo:
		print(i[0])


Measured memory_bytes: 48836
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string str;
ll sum = 0;

int main(){
    cin >> str;
    int n = str.size();
    ll cnt = 0;
    rep(i,n){
        cnt *= 10;
        cnt += str[i]-'0';
    }
    sum += cnt;
    cnt = 0;
    for(int i = 0; i < n-1; i++){
        cnt *= 10;
        cnt += str[i]-'0';
        sum += cnt*(1LL<<(n-i-2));
    }
    cnt = 0;
    ll p = 1;
    for(int i = 0; i < n-1; i++){
        cnt += (str[n-1-i]-'0')*p;
        p *= 10;
        sum += cnt*(1LL<<(n-i-2));
    }
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n-1; j++){
            cnt = 0;
            for(int k = i+1; k <= j; k++){
                cnt *= 10;
                cnt += str[k]-'0';
            }
            sum += cnt*(1LL<<(n-(j-i+1)-1));
        }
    }
    cout << sum << endl;
}


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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define sz(a) int((a).size())

int n, best = 0;
string s;

signed main()
{
	IOS;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		int lf[27] = {0}, rt[27] ={0};
		for (int j = 0; j <= i; j++) {
			lf[s[j]-'a']++;
		}
		for (int k = i+1; k < n; k++) {
			rt[s[k]-'a']++;
		}
		int cnt = 0;
		for (int l = 0; l < 26; l++) {
			if (lf[l] && rt[l]) cnt++;
		}
		best = max(cnt, best);
	}
	cout << best << endl;
	return 0;
}


Measured memory_bytes: 256
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
using namespace std;


int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
int main(){
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
   int ans = 2147483647;
   for(int i = 0; i < N; i++){
       cin >> h[i];
   }
sort(h.begin(),h.end());
   for(int i = 0 ; i < N - K +1; i++){
       ans = min(h[i+K-1]-h[i],ans);
   }
   cout << ans << endl;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int MOD;
class mint{
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

int ask(int t,int l,int b,int r){
	map<tuple<int,int,int,int>,int> memo;
	if(memo.count({t,l,b,r})>0) return memo[{t,l,b,r}];

	printf("? %d %d %d %d\n",t,l,b,r);
	fflush(stdout);
	int res; scanf("%d",&res);
	return memo[{t,l,b,r}]=res;
}

int main(){
	int h,w,n; scanf("%d%d%d%d",&h,&w,&n,&MOD);

	mint ans=0;
	rep(i,h){
		int m=ask(i,0,i,w-1);
		for(int k=1;k<=m;k++){
			int lo=-1,hi=w-1;
			while(hi-lo>1){
				int mi=(lo+hi)/2;
				if(ask(i,0,i,mi)>=k) hi=mi;
				else                 lo=mi;
			}
			ans+=pow(mint(2),i*w+hi);
		}
	}
	printf("! %d\n",ans.to_int());

	return 0;
}


Measured memory_bytes: 3788
n, q = map(int, input().split())
s = input().replace('AC','#.')
lr = [list(map(int, input().split())) for _ in range(q)]

accs = [0]
for i in s:
    accs.append(accs[-1] + (i == '.'))
for l, r in lr:
    print(accs[r] - accs[l])


Measured memory_bytes: 95392
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  int r = readln.chomp.to!int;
  int g = readln.chomp.to!int;
  writeln = (g - r) * 2 + r;
}


Measured memory_bytes: 256
n, x = map(int, input().split())
while n != 0 or x != 0:
    ans = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    ans += 1
    print(ans)
    n, x = map(int, input().split())


Measured memory_bytes: 5596
<?php
// Your code here!
$num = trim(fgets(STDIN));
$c = substr($num,-1,1);

if($c == 2 OR $c == 4 OR $c == 5 OR $c==7 OR $c == 9){
    echo 'hon';
}elseif($c == 0 OR $c == 1 OR $c == 6 OR $c == 8){
    echo 'pon';
}else{
    echo 'bon';
}
?>



Measured memory_bytes: 16052
A,B,C,X,Y = (int(i) for i in input().split())


# ABピザをZ枚買ったとする
mcost = 2 ** 30
for i in range(0,200001,2):
    XX = max(0, X - (i // 2))
    YY = max(0,Y - (i // 2))
    cost = XX * A + YY * B + i * C
    if mcost > cost:
        mcost = cost

print(mcost)


Measured memory_bytes: 39792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<chrono>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds; 
#define lli long long int
#define fr(i,a,b) for(lli i=a;i<b;i++)
#define bfr(i,a,b) for(lli i=a;i>=b;i--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
#define tc int t;cin>>t;while(t--)
#define mod 1000000007LL
#define mod2 998244353LL
#define all(vec) vec.begin(),vec.end()  
#define ld long double
#define pb push_back
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 


int main()
{
  
                        
     fio
     

      string s;
      cin>>s;

      if(s[0]==s[1] && s[1]==s[2]  && s[0]=='R')cout<<3;
      else if((s[0]==s[1] || s[1]==s[2]) && s[1]=='R')cout<<2;
      else if(s[0]==s[1] && s[1]==s[2]  && s[0]=='S')cout<<0;
      else cout<<1;



      






     





    
        


   

     
     




     

     
     


     

     
     
     

     
      
     





      


            
    
        
      









    

    
     
     



     



     


     
    
     




      
     

     
              


return 0;}    


Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
using namespace std;
char str[101919];
int cnt[10000];
int main(){
//	freopen("A.in","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",str+1);
		for(int j=1;j<=m;j++)
			cnt[str[j]-'a']++;
	}
	int cnt0=0,cnt2=0;
	if(n%2==1)
		cnt2+=m;
	if(m%2==1)
		cnt2+=n;
	if(n%2==1&&m%2==1)
		cnt0=1,cnt2-=2;
	for(int i=0;i<26;i++)
	{
		if(cnt[i]%4==0) continue;
		else if(cnt[i]%2==0) cnt2-=2;
		else cnt0--;
	}
	if(cnt2<0||cnt0<0)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
#define maxval 10003000

int main(){
   IOS;
ll t;t=1;//cin>>t;
while(t--){
ll n,m;cin>>n>>m;
vector<ll> adj[n];
for(ll i=0;i<m;i++){
    ll u,v;cin>>u>>v;
    adj[u-1].pb(v-1);
    adj[v-1].pb(u-1);
}
ll visit[n]={0};
ll ans[n]={0};
visit[0]=1;
queue<ll> q;
q.push(0);
while(!q.empty()){
    ll s=q.front();
q.pop();
    for(ll i=0;i<adj[s].size();i++){
        if(!visit[adj[s][i]]) {visit[adj[s][i]]=1;q.push(adj[s][i]);if(ans[adj[s][i]]) continue;ans[adj[s][i]]=s+1;}
    }
    
    
}
ll x=0;
for(ll i=0;i<n;i++){
    if(visit[i]==0){x=1;break;}
}
if(x) cout<<"No\n";
else{
    cout<<"Yes\n";
    for(ll i=1;i<n;i++) cout<<ans[i]<<"\n";
}

} 
    
    

    
return 0;    
}

Measured memory_bytes: 13816
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1000000007
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll mod_pow(ll x, ll n, ll mod) {
	ll bit = 1;
	while (n) {
		if (n & 1)bit = bit * x % mod;
		x = x * x % mod;
		n /= 2;
	}
	return bit;
}
signed main() {
	ll n;
	cin >> n;
	cout << (n - 1) / 2 << endl;
	ggr
}

Measured memory_bytes: 256
n,k=map(int,input().split())
H=[]
for i in range(n):
    H.append(int(input()))

H.sort()

#print(H)

ans=H[n-1]-H[0]

for i in range(n-k+1):
    #print(H[i+k-1]-H[i])
    ans=min(ans,H[i+k-1]-H[i])

print(ans)


Measured memory_bytes: 7384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int N;
	cin >> N;
	int B[2001], W[2001];
	rep1(i, N * 2) {
		char c;
		int a;
		cin >> c >> a;
		if (c == 'B') B[a] = i;
		else W[a] = i;
	}

	int Bkazu[2001][4002] = {}, Wkazu[2001][4002] = {};
	int Bkari[4001] = {}, Wkari[4001] = {};
	rep1(i, N) {
		Bkari[B[i]] = 1;
		Wkari[W[i]] = 1;
		for (int j = 2 * N; j > 0; j--) {
			Bkazu[i][j] = Bkazu[i][j + 1] + Bkari[j];
			Wkazu[i][j] = Wkazu[i][j + 1] + Wkari[j];
		}
	}
	
	int dp[2001][2001];
	rep(i, 2001) rep(j, 2001) dp[i][j] = 1e9;
	dp[0][0] = 0;
	rep(i, N + 1) {
		rep(j, N + 1) {
			if (i < N && B[i + 1] + Bkazu[i][B[i + 1]] + Wkazu[j][B[i + 1]] >= i + j + 1) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + B[i + 1] + Bkazu[i][B[i + 1]] + Wkazu[j][B[i + 1]] - i - j - 1);
			if (j < N && W[j + 1] + Bkazu[i][W[j + 1]] + Wkazu[j][W[j + 1]] >= i + j + 1) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + W[j + 1] + Bkazu[i][W[j + 1]] + Wkazu[j][W[j + 1]] - i - j - 1);
		}
	}

	co(dp[N][N]);

	Would you please return 0;
}

Measured memory_bytes: 78464
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <stack>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>

 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.14159265358979323846264;
 const int mod=1000000007;
 vector<vector<vector<double>>> dp;
 int N;

 double f(int i,int j,int k){
   if(dp[i][j][k]>=numeric_limits<double>::epsilon())return dp[i][j][k];
   if(i==0&&j==0&&k==0)return 0;
   double ret=0;
   if(i)ret+=f(i-1,j,k)*i;
   if(j)ret+=f(i+1,j-1,k)*j;
   if(k)ret+=f(i,j+1,k-1)*k;
   ret+=N;
   return dp[i][j][k]=ret*1./(i+j+k);
 }

int main(){
	std::cout << std::fixed;
	std::cout << std::setprecision(12);
	int n;
	cin>>n;
  N=n;
	int a[333]={},cnt[4]={};
	FOR(i,0,n){
    cin>>a[i];
    cnt[a[i]]++;
  }
  vector<vector<vector<double>>> dp2(n+1,vector<vector<double>>(n+1,vector<double>(n+1,0.)));
  dp=dp2;
  cout<<f(cnt[1],cnt[2],cnt[3]);

	return 0;
}


Measured memory_bytes: 432128
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d,n=1,x=0,y;
    VI m(5);
    string s,s1,s2;
    cin >> s;
    rep(i,4) if (s[i] == '2') c++;

    cout << c << endl;
    return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,k,a[N],dis[N],ans=0;
vector<int> E[N];
void dfs(int u) {
    dis[u]=0;
    for(int v:E[u]) dfs(v),dis[u]=max(dis[u],dis[v]+1);
    if(dis[u]==k-1&&a[u]!=1) dis[u]=-1,ans++;
}
int main() {
    cin>>n>>k;
    for(int i=1;i<=n;i++) a[i]=gi();
    if(a[1]!=1) ans++,a[1]=1;
    for(int i=2;i<=n;i++) E[a[i]].push_back(i);
    dfs(1);printf("%d\n",ans);
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


Measured memory_bytes: 11136
N, M = map(int, input().split())
edges = [[] for _ in range(N)]

for _ in range(M):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    edges[s].append(t)

def E(stop):
    dp = [-1] * N
    dp[N - 1] = 0
    for i in range(N - 1)[:: -1]:
        total = 0
        maxE = 0
        for to in edges[i]:
            total += dp[to]
            if maxE < dp[to]:
                maxE = dp[to]
        size = len(edges[i])
        if size > 1 and stop == i:
            size -= 1
            total -= maxE
        dp[i] = total / size + 1
    return dp[0]

ans = float('inf')
for s in range(N):
    ans = min(ans, E(s))

print(ans)

Measured memory_bytes: 57688
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
int main()
{
	//freopen("3.txt","r",stdin);
	int n;
	cin >> n;
	while(n--)
	{
		int a[11];
		int flag=1;
		int b=0,c=0;
		for(int i=0;i<10;i++)
			{
				cin >> a[i];
				if(a[i]>b)
				{
					b=a[i];
				}
				else if(a[i]>c)
				{
					c=a[i];
				}
				else
				{
					flag=0;
				}
			}
		if(flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
 }
}

Measured memory_bytes: 3072
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		
		long dog = Long.parseLong(br.readLine());
		String res = "";
		
		while(dog-- > 0) {
			res = (char)('a' + (dog%26)) + res;
			dog /= 26;
		}
		
		bw.write(res + "\n");
		bw.flush();
	}

}


Measured memory_bytes: 37292
n,m = map(int, input().split(" "))
a = [list(map(int, input().split(" "))) for i in range(n)]
ans = 0
#print(a)
for i in range(2 ** 3):
  total = []
  minus = [1 for _ in range(3)]
  for j in range(3):
    if i >> j & 1:
      minus[j] *= -1
  for k in range(n):
    total.append(a[k][0] * minus[0] + a[k][1] * minus[1] + a[k][2] * minus[2])
  ans = max(ans, sum(sorted(total, reverse=1)[:m]))
print(ans)

Measured memory_bytes: 9292
N, L = [int(s) for s in input().split()]
apples = [i+L for i in range(N)]
abstaste = [abs(i) for i in apples]
if min(apples) == min(abstaste):
  ans = sum(apples) - min(abstaste)
else:
  ans = sum(apples) + min(abstaste)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
  int n;
  cin>>n;
  set<int> s;
  for(int i=0;i<n;i++)
  {
      int x;
      cin>>x;
      s.insert(x);
  }
  if(s.size()==n) cout<<"YES";
  else cout<<"NO";
}

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

int n, m, s;
vector<int> a;

int main(){
    cin >> n >> m;
    s = 0;
    a.resize(n);
    for (int i = 0; i < n; ++i){
        cin >> a[i];
        s += a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    if (a[m-1] >= s/(4*m) + (s % (4*m) != 0)) cout << "Yes";
    else cout << "No";
}   

Measured memory_bytes: 256
#include <iostream>

int main(){
    int N;
    int d[101];
    std::cin >> N;

    for(int i=0; i<N; i++){
        std::cin >> d[i];
    }

    int flg[101] = { 0 };
    for(int j=0; j<N; j++){
        if(flg[d[j]] == 0) flg[d[j]] = 1;
    }

    int sum = 0;
    for(int k=0; k<101; k++){
        sum += flg[k];
    }

    std::cout << sum << std::endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d;
	int n,count;
	
	while(scanf("%d",&n)!=EOF)
	{
		count=0;
		a=0;
		while(a<=9)
		{
			b=0;
			while(b<=9)
			{
					c=0;
				while(c<=9)
				{
					d=0;
					while(d<=9)
					{
						if(a+b+c+d==n)
						{
							count++;
						}
						d++;
					}
					c++;
				}
				b++;
			}
			a++;
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 596
def myAnswer(N:int,M:int) -> int:
   if(2 * N <= M):
      counter = N
      M -= 2*N
      counter += M//4
   else:
      counter = M//2
   return counter

def modelAnswer():
   return
def main():
   N,M = map(int,input().split())
   print(myAnswer(N,M))

if __name__ == '__main__':
   main()

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

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

    int n; cin >> n;
    int f[4] = {0};
    FOR(i,0,n-1){
        int a; cin >> a;
        f[a]++;
    }

    double dp[n+1][n+1][n+1];
    //cout << f[1] << ' ' << f[2] << ' ' << f[3] << endl;
    FOR(c, 0, n) FOR(b, 0, n-c) FOR(a, 0, n-b-c) {
        int z = a+b+c;
        if (z == 0) dp[a][b][c] = 0;
        else {
            double toNext = (double)z/n * 1.0 / pow(1.0 - (1.0-(double)z/n), 2);

            dp[a][b][c] = toNext;
            //cout << "ew " << a << ' ' << b << ' ' << c << " :: " << dp[a][b][c] << '\n';
            if (a >= 1) dp[a][b][c] += (double)a/z*dp[a-1][b][c];
            if (b >= 1) dp[a][b][c] += (double)b/z*dp[a+1][b-1][c];
            if (c >= 1) dp[a][b][c] += (double)c/z*dp[a][b+1][c-1];
        }
        //cout << a << ' ' << b << ' ' << c << " :: " << dp[a][b][c] << '\n';
    }

    cout << fixed << setprecision(10) << dp[f[1]][f[2]][f[3]] << '\n';

    // 1
    // 1 * 2/3 + 2 * 1/3 * 2/3 + 3 * 1/3 * 1/3 * 2/3 + ...
    // 2/3 * ( 1 + 2 * 1/3 + 3 * 1/3 * 1/3 ) * ...
    //      S = 1 + 2r + 3r2 + 4r3 + ...
    //     rS =      r + 2r2 + 3r3 + ...
    // S(1-r) = 1 +  r +  r2 +  r3 + ...
    //        = (1-rn)/(1-r)
    //      S = (1-rn)/(1-r)2
    //        = 1/(1-r)2     for n to inf since |r| < 1
    //      
    // S = 1 / (1- 1/3)^2 = 1 / 4/9 = 9/4
    // 2/3 * S = 9/4 * 2/3 = 3/2
}



Measured memory_bytes: 213248
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

struct Wit {
    int p;
    int b;
};

void solve() {
    int N; cin >> N;
    vector<vector<Wit>> vec(N);

    FOR(i, 0, N) {
        int a; cin >> a;
        vec[i].resize(a);
        FOR(j, 0, a) {
            cin >> vec[i][j].p >> vec[i][j].b;
            --vec[i][j].p;
        }
    }

    auto judge = [&N, &vec](int bit) -> bool {
        for (int i = 0; i < N; ++i) {
            if (!(bit & (1 << i))) continue;
            for (auto xy : vec[i]) {
                if (xy.b == 1 && !(bit & (1 << xy.p))) return false;
                if (xy.b == 0 && (bit & (1 << xy.p))) return false;
            }
        }
        return true;
    };

    int ret = 0;
    FOR(bit, 0, 1<<N) {
        if (judge(bit)) {
            int count = 0;
            FOR(i, 0, N) {
                if (bit & (1 << i)) ++count;
            }
            chmax(ret, count);
        }
    }
    cout << ret << endl;    
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 9999999999;
const ll mod = 1e9 + 7;


int main(){
	ll x,k;
	cin>>x>>k;
	if(500*x >= k){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}



	return 0;
}





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

typedef long long int ll;
ll MOD = 1000000007;

// ====================================================================

int main()
{
  string s;
  cin >> s;
  vector<vector<ll>> dp(s.size(), vector<ll>(13, 0));

  // 1行目を初期化する
  if (s[0] == '?')
    for (int i = 0; i < 10; i++)
      dp[0][i] = 1;
  else
    dp[0][s[0] - '0'] = 1;

  // 配るDPをしていく
  for (int k = 0; k < s.size() - 1; k++)
  {
    if (s[k + 1] == '?')
    { // 次の文字が自由に決められる
      for (int i = 0; i < 13; i++)
      {
        for (int j = 0; j < 10; j++)
        { // 全ての文字を試す
          dp[k + 1][(i * 10 % 13 + j) % 13] += dp[k][i];
          dp[k + 1][(i * 10 % 13 + j) % 13] %= MOD;
        }
      }
    }
    else
    { // 次の文字が指定されている
      for (int i = 0; i < 13; i++)
      {
        dp[k + 1][(i * 10 % 13 + (s[k + 1] - '0')) % 13] += dp[k][i];
        dp[k + 1][(i * 10 % 13 + (s[k + 1] - '0')) % 13] %= MOD;
      }
    }
  }
  cout << dp[s.size() - 1][5] << endl;
}

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

int main() {
  int N, A, c = 0, C;
  cin >> N >> A;
  
  while (A % 2 == 0) {
      A /= 2;
      c++;
    }
  C = c;
  
  for (int i = 1; i < N; i++) {
    cin >> A;
    c = 0;
    while (A % 2 == 0) {
      A /= 2;
      c++;
    }
    if (C > c)
      C = c;
  }
  cout << C << endl;
}


Measured memory_bytes: 256