akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;

class Main {
    public static void main(String args[]) {
        java.util.Scanner sc = new java.util.Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[][] adjacency = new int[n][n];

        for(int i=0; i<n; i++){
            int vIndex = Integer.parseInt(sc.next())-1;
            int nAdj = Integer.parseInt(sc.next());
            for(int j=0; j<nAdj; j++){
                int connectTo = Integer.parseInt(sc.next())-1;
                adjacency[vIndex][connectTo] = 1;
            }
        }

        BFS bfs = new BFS(adjacency);
        bfs.execute();
        bfs.printAnswer(); 
    }


    static class BFS{
        private final  int[][] adjacency;
        private final int[][] ans;
        private final Status[] status;
        private final int np;
        private Queue<Integer> q;

        public int getNp(){
            return this.np;
        }

        public BFS(int[][] adjacency){
            this.adjacency = adjacency;
            this.np = adjacency.length;
            this.ans = new int[adjacency.length][2];
            
            for(int i=0; i<np; i++){
                this.ans[i][0] = i+1;
                this.ans[i][1] = -1;
            }
            this.ans[0][1] = 0;

            Status[] status = new Status[np];
            Arrays.fill(status, Status.NOT_YET);
            status[0] = Status.DONE;
            this.status = status;

            this.q = new ArrayDeque<>();
            this.q.add(0);
        }

        private void searchNotYet(int vi){
            for(int i=0; i<np; i++){
                if( adjacency[vi][i] == 1 && i != vi && this.status[i] == Status.NOT_YET){
                    this.ans[i][1] = this.ans[vi][1]+1;
                    this.q.offer(i);
                    this.status[i] = Status.DONE;
                }
            }
            execute();
        }
        public void execute(){
            while(!this.q.isEmpty()){
                int bottom = this.q.poll();
                searchNotYet(bottom);
            }
        }
        public void printAnswer(){
            for(int i=0; i<np; i++){
                for(int j=0; j<2; j++) {
                    if(j== 1)   System.out.println(ans[i][j]);
                    else System.out.print(ans[i][j]+" ");
                }
            }
        }
    }

    static enum Status{
        DONE,
        CURRENT,
        NOT_YET
    }
}



Measured memory_bytes: 27932
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        if(s==t){
            cout<<"Yes"<<endl;
            return(0);
        }
        s.append(1,s[0]);
        s.erase(s.begin());
    }
    cout<<"No"<<endl;
    return(0);
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n, k; cin >> n >> k;
	vector<long long> g(11, n / 11);
	n %= 11;
	for(int i = 0; i < n; i++) g[i]++;
	long long ans = 0;
	for(int i = 0; i < 11; i++){
		long long has = g[i];
		for(int j = 1; j <= 2; j++){
			int pi = (i + j) % 11;
			if(pi < i) has = min(has, g[pi] - 1);
			else has = min(has, g[pi]);
		}
		if(has <= 0) continue;
		for(int j = 1; j < 6; j++){
			long long sum = 0;
			for(int x = 0; x < 3; x++){
				for(int y = 0; y < 3; y++){
					sum += 7 * (i + x) + (j + y);
					sum %= 11;
					sum += 11;
					sum %= 11;
				}
			}
			if(sum == k) ans += has;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(range(N + 1))
for i in range(N + 1):
    if i == 0:
        a[i] = 2
    elif i == 1:
        a[i] = 1
    else:
        a[i] = a[i - 1] + a[i -2]
print(a[N])

Measured memory_bytes: 3060
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  static int[] A;
        static void Main(string[] args)
        {
          //入力を受け取る
          var N = long.Parse(Console.ReadLine());
          var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          
          var dic = new Dictionary<int, int>();
          for(int i = 0; i < N ; i++){
            if(dic.ContainsKey(A[i])){
              dic[A[i]] += 1;
            }else{
              dic.Add(A[i],1);
            }
          }
          var ans = 0L;
          foreach(KeyValuePair<int, int> item in dic) {
            if(item.Value > item.Key){
              ans += item.Value-item.Key;
            }else if (item.Value < item.Key){
              ans += item.Value;
            }
          }
          Console.WriteLine(ans);
        }
  
}


Measured memory_bytes: 28252
#include<stdio.h>

int main(void){
	int i;
	int h1,m1,s1,h2,m2,s2;
	int sum,k,kaih,kaim,kais;

	for(i=0;i<3;i++){
		scanf("%d %d %d %d %d %d",&h1,&m1,&s1,&h2,&m2,&s2);
		sum=((h2-h1)*60+(m2-m1))*60+(s2-s1);
		
		kaih=sum/3600;
		k=sum%3600;

		kaim=k/60;
		kais=k%60;

		printf("%d %d %d\n",kaih,kaim,kais);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#pragma GCC optimize ("-O3")
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
#define tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define ll long long int
ll max(ll a, ll b) {  return a > b ? a : b; }
ll gcd(ll a, ll b) { if (a == 0) return b; return b == 0 ? a : gcd(b, a % b);}
#define case(i) cout<<"Case #"<<i<<": ";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) { cerr << "[ " << *it << " = " << a << " ]"; err(++it, args...);}
#define pii pair <ll , ll >
#define pb push_back
#define PRECISION 10
const ll inf = 1e16;
const int MAXN = 100001;
const int LOGN = 22;
const int MAXBIT = 61;
const int DIGITSIZE = 19;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
bool take_test_cases = 0;
bool print_case_no = 0;

void getac(int T) {
    ll n;
    cin>>n;
    ll k;
    cin>>k;
    int arr[n+1];
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    bool vis[n+1];
    memset(vis,false,sizeof(vis));
    int len=0;
    int curr=1;
    while(vis[curr]==false){
        vis[curr]=true;
        curr=arr[curr];
        len++;
    }
 
    ll cyclelen=0;
    ll start=curr;
    while(1){
        curr=arr[curr];
        cyclelen++;
        if(curr==start){
            break;
        }
    }
    ll prev=1;
    ll less=0;
    while(prev!=start){
        prev=arr[prev];
        less++;
    }
    
    if(k<=less){
        ll a=1;
        for(int i=0;i<k;i++){
            a=arr[a];
        }
        cout<<a<<'\n';
        return ;
    }
    k-=less;


    k%=cyclelen;

    for(int i=0;i<k;i++){
        start=arr[start];
    }
    cout<<start<<'\n';
}
int  main()
{

    fastio;
    int t = 1;
    if (take_test_cases) cin >> t;
    int t_t = 1;
    while (t--) {
        if (print_case_no)
        case (t_t);
        getac(t_t);
        t_t++;
    }
    return 0;
}

Measured memory_bytes: 4596
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int H, W, N; cin >> H >> W >> N;
    int sy, sx; cin >> sy >> sx;
    string T, A; cin >> T >> A;
    
    vector<vector<int>> TV(4, vector<int>(N+1));
    vector<vector<int>> AV(4, vector<int>(N+1));
    
    for(int i=0; i<N; i++){
        if(T[i]=='L') TV[0][i+1] = TV[0][i] + 1;
        else TV[0][i+1] = TV[0][i];
        
        if(T[i]=='R') TV[1][i+1] = TV[1][i] + 1;
        else TV[1][i+1] = TV[1][i];
        
        if(T[i]=='U') TV[2][i+1] = TV[2][i] + 1;
        else TV[2][i+1] = TV[2][i];
        
        if(T[i]=='D') TV[3][i+1] = TV[3][i] + 1;
        else TV[3][i+1] = TV[3][i];
        
        
        if(A[i]=='L') AV[0][i+1] = AV[0][i] + 1;
        else AV[0][i+1] = AV[0][i];
        
        if(A[i]=='R') AV[1][i+1] = AV[1][i] + 1;
        else AV[1][i+1] = AV[1][i];
        
        if(A[i]=='U') AV[2][i+1] = AV[2][i] + 1;
        else AV[2][i+1] = AV[2][i];
        
        if(A[i]=='D') AV[3][i+1] = AV[3][i] + 1;
        else AV[3][i+1] = AV[3][i];
    }
    
    int L = sx - 1;
    int R = W - sx;
    int U = sy - 1;
    int D = H - sy;
    int dl = 0;
    int dr = 0;
    int du = 0;
    int dd = 0;
    
    for(int i=0; i<N; i++){
        dl += TV[0][i+1] - TV[0][i];
        dr += TV[1][i+1] - TV[1][i];
        du += TV[2][i+1] - TV[2][i];
        dd += TV[3][i+1] - TV[3][i];

        if(dl > L || dr > R || du > U || dd > D){
            cout << "NO" << endl;
            return 0;
        }
        
        dl -= AV[1][i+1] - AV[1][i];
        dr -= AV[0][i+1] - AV[0][i];
        du -= AV[3][i+1] - AV[3][i];
        dd -= AV[2][i+1] - AV[2][i];
        
        dl = max(-R, dl);
        dr = max(-L, dr);
        du = max(-D, du);
        dd = max(-U, dd);
        if(dl > L || dr > R || du > U || dd > D){
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    return 0;
}



Measured memory_bytes: 7672
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,K,Dr,Ds,Dp;
  cin >> N >> K >> Dr >> Ds >> Dp;
	char c;
  vector<string>zyan(N);
        // そのうち一文字ずつ入れないといけなくなる！  
for (int i = 0; i < N; i ++) {
    cin >> c; 
      zyan.at(i) = c;
  }
int i =  0,answer = 0;
  for (i = 0; i < K; i ++) {
    if (zyan.at(i) == "r") {
    answer += Dp;
    }
    else if (zyan.at(i) == "s") {
      answer += Dr;
    }
    else if (zyan.at(i) == "p") {
      answer += Ds;
    }
  }
 for (; i < N; i ++) {
   if (zyan.at(i - K) != zyan.at(i)) {
 if (zyan.at(i) == "r" || zyan.at(i) == "saikyou") {
    answer += Dp;
    }
    else if (zyan.at(i) == "s" || zyan.at(i) == "saikyou") {
      answer += Dr;
    }
    else if (zyan.at(i) == "p" || zyan.at(i) == "saikyou") {
      answer += Ds;
    }
   }
 else {
  zyan.at(i) = "saikyou"; 
 }
 }
cout << answer << endl;
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000

/*
N=2*10^5
N個の箱に番号1-Nが書いてある
任意の整数i(1<=i<=N)に対して
iの倍数の番号の箱のボールの総和 %2 ==ai
*/

int main()
{
  int N;cin>>N;
  vector<int> a(N+1);
  for (int i=1;i<=N;i++)
    cin>>a[i];
  vector<int> b(N+1,0);
  
  for (int i=N;i>=1;i--)
  {
    //Nの倍数から順番に入れていく
    //iの倍数を足して、２で割ってa[i]と一致したら0
    //一致しなければ1をたす？？
    int d=1;
    int sum=0;
    while (d*i<=N)
    {
      sum += b[d*i];
      d++;
    }
    //cout<<i<<" "<<sum<<endl;
    if (sum % 2 != a[i]) b[i]=1;
  }
  
  //for (int i=1;i<=N;i++)
    //cout<<"b["<<i<<"]="<<b[i]<<endl;
  
  int count=0;
  for (int i=1;i<=N;i++)
  {
    if (b[i]==1) count++; 
  }
  cout<<count<<endl;
  for (int i=1;i<=N;i++)
  {
    if (b[i]==1) cout<<i<<" "; 
  }
}

Measured memory_bytes: 2432
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

vector<int>a,score;

vector<int>find_cycle(int i)
{
	int tmp=i,pf=0;
	vector<int>pref;
	while(a[tmp]!=i)
	{
		tmp=a[tmp];
		pf+=score[tmp];
		pref.push_back(pf);
	}
	tmp=a[tmp];
	pf+=score[tmp];
	pref.push_back(pf);
	return pref;
}

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;

	int n,k;
	cin>>n>>k;

	a.resize(n+1);
	score.resize(n+1);

	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}

	for(i=1;i<=n;i++)
	{
		cin>>score[i];
	}

	vector<vector<int>>v;

	for(i=1;i<=n;i++)
	{
		vector<int>pf=find_cycle(i);
		v.push_back(pf);
	}

	d(v);

	int Max=-1e18;

	for(int i=1;i<=n;i++)
	{
		int here=-1e18,j;
		if(k>v[i-1].size())
		{
			d(k);
			if(v[i-1].back()<=0)
			{
				for(j=0;j<v[i-1].size();j++)
				{
					here=max(here,v[i-1][j]);
				}
			}
			else
			{
				int num_of_cycles=k/v[i-1].size();
				d(num_of_cycles);
				here=num_of_cycles*v[i-1].back();
				int remain=k%v[i-1].size();
				d(remain);

				int new_add=(num_of_cycles==0?INT_MIN:0);

					for(int j=0;j<remain;j++)
					{
						new_add=max(new_add,v[i-1][j]);
					}
				here+=new_add;

				int new_here,nxt=0;

				if(num_of_cycles)
				{
					num_of_cycles--;
					new_here=num_of_cycles*v[i-1].back();
					for(j=0;j<v[i-1].size();j++)
					{
						nxt=max(nxt,v[i-1][j]);
					}
					new_here+=nxt;

				}

				here=max(here,new_here);
			}
		}
		else
		{
			for(j=0;j<k;j++)
			{
				here=max(here,v[i-1][j]);
			}
		}
		Max=max(Max,here);
	}
	cout<<Max<<endl;
	

}

Measured memory_bytes: 199076
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		StringBuilder answer = new StringBuilder("");
		char list[] = s.toCharArray();
		for (int i = 0; i < s.length(); i++) {
			char c = list[i];
			switch(c) {
				case '0':
					answer.append("0");
					break;
				case '1':
					answer.append("1");
					break;
				case 'B':
					if(answer.length() == 0) {
						break;
					}else {
						answer.deleteCharAt(answer.length()-1);
						break;
					}
			}
		}
		System.out.println(answer.toString());
		sc.close();
	}

}

Measured memory_bytes: 35660
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  string s; cin >> s;
  cout << s.size()/2 - count(ALL(s), 'p') << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

struct UnionFind {
    vector< int > data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return false;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int find(int k) {
        if(data[k] < 0) return k;
        return data[k] = find(data[k]);
    }

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

    int size(int k) {
        return -data[find(k)];
    }
};

int main() {
    int h, w;
    cin >> h >> w;
    UnionFind uf(h * w);
    char masu[h + 2][w + 2];
    // Fill(masu, 'X');
    fill(masu[0], masu[h + 2], 'X');
    rep(i, h) rep(j, w) cin >> masu[i + 1][j + 1];
    int v[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
    map<int, int> bk;
    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++)
            rep(k,4)
                if(masu[i][j] == '.' && masu[i + v[k][0]][j + v[k][1]] == '#'){
                    uf.unite((i-1) * w + j - 1, (i + v[k][0] - 1) * w + j + v[k][1] - 1);
                }
    rep(i, h) rep(j, w) if(masu[i + 1][j + 1] == '#') bk[uf.find(i * w + j)]++;
    ll ans = 0;
    for(auto b : bk)
        ans += (ll)b.second * (uf.size(b.first) - b.second);
    cout << ans << endl;
}

Measured memory_bytes: 7424
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List

solve :: Int -> Int -> [[Int]] -> (Int, [[Int]])
solve h w ass = (length coms, coms)
  where
    coms = rowop Nothing (zip [1..] (map (zip [1..]) ass))

rowop :: Maybe Int -> [(Int,[(Int,Int)])] -> [[Int]]
rowop _   []             = []
rowop pos ((y,xas):yxas) = thisRes ++ rowop thisPos yxas
  where
    (thisPos, thisRes)
      = colop Nothing
        $ map (\(x,a) -> if pos == Just x then (x,a+1) else (x,a)) xas

    colop :: Maybe Int -> [(Int,Int)] -> (Maybe Int, [[Int]])
    colop Nothing      []               = (Nothing, [])
    colop start@(Just x) [] | null yxas = (start, [])
                            | otherwise = (start, [[y, x, y+1, x]])
    colop start ((x,a):xas)
      | a `mod` 2 == 0 = colop start xas
      | otherwise = case start of
          Nothing -> colop (Just x) xas
          Just x' -> (pos', coms x' x ++ res')
      where coms x1 x2 = [[y,t,y,t+1] | t <- [x1..x2-1]]
            (pos', res') = colop Nothing xas

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

main = do
  cont <- B.getContents
  let [h, w] : ass = map bsReadInts (B.lines cont)
      (n, yss) = solve h w ass
  putStr $ unlines $ map (unwords . map show) ([n] : yss)


Measured memory_bytes: 52732
// 5/2 リアルタイム参加

#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int N, M, Q;
vector<int> a, b, c, d;

vector<int> comb;  // shikiri, ball

int dfs(int n, int m, string suretu = "") {
    if (n + m == 0) {
        // 最後の処理

        int A[N];

        int i = 0;
        int num_ball = 0;

        for (int p = 0; p < N + M; p++) {
            if (suretu[p] == 'n') {
                A[i] = num_ball;
                i++;
            } else {
                num_ball++;
            }
        }

        // for (int p = 0; p < N; p++) {
        //     cout << A[p] << " ";
        // }
        // cout << endl;

        // bool be = true;
        int ans = 0;
        for (int q = 0; q < Q; q++) {
            if (A[b[q]] - A[a[q]] == c[q]) ans += d[q];
        }

        return ans;
    }

    int score1 = 0, score2 = 0;

    // 仕切りを入れる場合（最初はダメ）
    if (n > 0 && n + m != N + M) {
        score1 = dfs(n - 1, m, suretu + 'n');
    }

    // ボールを入れる場合
    if (m > 0) {
        score2 = dfs(n, m - 1, suretu + 'm');
    }

    return max(score1, score2);
}

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

    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);

    for (int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }

    int ans = dfs(N, M);

    // return ans;
    cout << ans << endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  rep(i,N){
    cin >> a.at(i);
  }
  rep(i,N){
    cin >> b.at(i);
  }
  int p=0;
  rep(i,N){
    int t=0;
    rep(j,N){
      if(i==j){
        t += a.at(j)+b.at(j);
      }else if(i<j){
        t += b.at(j);
      }else{
        t += a.at(j);
      }
    }
    p = max(p,t);
  }
  cout << p << endl;
}

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

using namespace std;

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

int main(void)
{
  int n;
  cin >> n;
  vec<int> a(n + 1), b(n + 1, 0);
  rep(i, n) cin >> a[i + 1];
  for (int i = n; i > 0; i--) {
    int m = n / i;
    int sum = 0;
    for (int j = 2; j <= m; j++)
      sum += b[i * j];
    b[i] = (a[i] == sum % 2) ? 0 : 1;
  }
  int c = 0;
  rep(i, n) {
    if (b[i + 1]) c++;
  }
  cout << c << endl;
  rep(i, n) {
    if (b[i + 1]) cout << i + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define ll long long
#define faltu ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define binary(x) std::string binary = std::bitset<25>(x).to_string(); //to binary
#define inf 1000000007
#define mod 1000000007
#define pi pair<int,int>
#define lpi pair<int,int>
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define lvi vector<long long int>
#define pie 3.14159265358979323846
using namespace std;
int main()
{
	faltu;
	int n,m,mx=0,mn=100001;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		mx=max(mx,x);
		mn=min(mn,y);
	}
	if(mn>=mx)cout<<mn-mx+1<<endl;
	else cout<<"0"<<endl;

}





Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n<=1000)
    {
        printf("%d",1000-n);
    }
    else if(n<=2000)
    {
        printf("%d",2000-n);
    }
    else if(n<=3000)
    {
        printf("%d",3000-n);
    }
    else if(n<=4000)
    {
        printf("%d",4000-n);
    }
    else if(n<=5000)
    {
        printf("%d",5000-n);
    }
    else if(n<=6000)
    {
         printf("%d",6000-n);
    }
    else if(n<=7000)
    {
         printf("%d",7000-n);
    }
    else if(n<=8000)
    {
         printf("%d",8000-n);
    }
    else if(n<=9000)
    {
         printf("%d",9000-n);
    }
    else if(n<=10000)
    {
         printf("%d",10000-n);
    }
    return 0;
}

Measured memory_bytes: 1704
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
Integer n = sc.nextInt();
Long a = sc.nextLong();
for(int i = 1;i<n;i++) {
  Long b = sc.nextLong();
  Long hcf = hcf(a,b);
  a = lcm(a, b, hcf); 
}

System.out.println(a);
}

public static long hcf(long a, long b)
 {
 if(a==0)
  return b;
 else
  return hcf(b%a,a);
 }
 
  public static long lcm(long a, long b, long hcf)
 {
 return a/hcf*b;
 }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t


int main(void){
    int N;
    ll ret = 0;
    vector<int> a;
    cin >> N;
    for(int i = 0 ; i < N ; i++ ){
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    /*
    int min_val = INT_MAX;
    vector<int> b:
    for(int i = a.size() - 1; i >= 0 ; i-- ){
        min_val = min(min_val,a[i]);
        b.push_back(min_val);
    }
    reverse(b.begin(),b.end());
    */
    
    ret = a[0] - 1;
    int min_val = 2;
    
    for(int i = 1 ; i < a.size() ; i++ ){
        if( min_val > a[i] ){
            // 1とかなのでなにもできない
            //cout << 0 << endl;
        }else if( min_val == a[i] ){
            // 何も出来ない上にふやすしか
            min_val++;
            //cout << 0 << endl;
        }else{
            int temp = a[i] / min_val;
            if( a[i] % min_val == 0 )temp--;
            ret += temp;
            
            //cout << temp << endl;
        }
    }
    
    cout << ret << endl;
    
    return 0;
}


Measured memory_bytes: 892
N = input()
a = int(N[0])
b = int(N[1])
c = int(N[2])
d = int(N[3])

if a+b+c+d ==7:
	print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
	
elif a-b+c+d ==7:
	print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
	
elif a-b-c+d ==7:
	print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
	
elif a+b+c-d ==7:
	print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
	
elif a+b-c-d ==7:
	print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
	
elif a-b+c-d ==7:
	print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
	
elif a+b-c+d ==7:
	print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')

elif a-b-c-d ==7:
	print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
	

Measured memory_bytes: 3064
a, b = map(int, input().split())

if a in [1, 3, 5, 7, 8, 10, 12] and b in [1, 3, 5, 7, 8, 10, 12]:
  print("Yes")
elif a in [4, 6, 9, 11] and b in [4, 6, 9, 11]:
  print("Yes")
elif a == b == 2:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<cstdio>
using namespace std;
bool ban[410],vis[410][410];
int main(){
//	freopen("E.in","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
	int s,t;
	while(m--)
	{
		scanf("%d%d",&s,&t);
		if(vis[s][t]||vis[t][s]){
			ban[s]=1,ban[t]=1;
			for(int i=1;i<=n;i++)
				vis[i][s]=1,vis[i][t]=1;
		}
		else{
			vis[s][t]=1;
			for(int i=1;i<=n;i++)
				if(i!=s&&i!=t)
					if(vis[s][i]||vis[t][i]||vis[i][s]||vis[i][t])
						vis[i][s]=vis[i][t]=1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)
			if(!vis[i][j]&&!vis[j][i])
				ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
<?php
$n = fgets(STDIN);
for($i = 0; $i < $n; $i++){
    @$map[trim(fgets(STDIN))]++;
}
$n = fgets(STDIN);
for($i = 0; $i < $n; $i++){
    @$map[trim(fgets(STDIN))]--;
}
echo max(max($map),0);


Measured memory_bytes: 4604
#include<stdio.h>
  
void right_triangle(int x, int y, int z);
  
int main(void)
{
    int n;
    scanf("%d", &n);
    int x, y, z;
    for (int i = 0; i<n; i++) {
        scanf("%d %d %d", &x, &y, &z);
        right_triangle(x, y, z);
    }
    return 0;
}
  
void right_triangle(int x, int y, int z)
{
    int i = x * x;
    int j = y * y;
    int k = z * z;
    if (i == j + k || j == k + i || k == i + j) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}

Measured memory_bytes: 1008
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var Q = int.Parse(Console.ReadLine());

        var a = new long[100001];
        for (var i = 0; i < A.Length; i++)
        {
            a[A[i]]++;
        }
        var s = A.Sum();

        for (int i = 0; i < Q; i++)
        {
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            s += (input[1] - input[0]) * a[input[0]];
            a[input[1]] += a[input[0]];
            a[input[0]] = 0;
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 45528
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string> 
#include <cmath>
#include <cstdio>
using namespace std;
const int maxl=10000000;
char a[maxl];
int cpy[maxl];
int main()
{
	memset(a,0,sizeof(a));
	cin>>a;
	for(int i=0;i<strlen(a)-2;i++)
	{
			cpy[i]=abs(753-((a[i]-48)*100+(a[i+1]-48)*10+a[i+2]-48));
	}
	int l=strlen(a)-2;
	sort(cpy,cpy+l);
	
	cout<<cpy[0];
	return 0;
}

Measured memory_bytes: 10496
import java.io.*;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while (true){
            int n=sc.nextInt();
            if (n==0) break;
            int score[]=new int[n];
            int max=0,min=0,tot=0;
            boolean mx=true;
            boolean mn=true;
            for (int i=0;i<n;i++){
                score[i]=sc.nextInt();
                if (i==0){
                    max=score[i];
                    min=score[i];
                }
                if (score[i]>=max) max=score[i];
                if (score[i]<=min) min=score[i];
            }
            for (int i=0;i<n;i++){
                if (score[i]==max&&mx) mx=false;
                else if(score[i]==min&&mn) mn=false;
                else{
                    tot+=score[i];
                }
            }
            System.out.println(tot/(n-2));
        }
    }
}

Measured memory_bytes: 28792
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, X, Y, D;
int main() {
	cin >> N >> D;
	lint cnt = 0;
	REP(i, N) {
		cin >> X >> Y;
		if (X * X + Y * Y <= D * D) cnt++;
	}
	cout << cnt;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v(2 * M);
 
  for (int i = 0; i < N; i++) {
    int C = 0;
    for (int j = 0; j < M; j++) {
       cin >> v.at(2 * j) >>v.at(2 * j + 1);
 
      if (v.at(2 * j) == i + 1 || v.at(2 * j + 1) == i + 1) {
        C = C + 1;
      }
    }    
    cout << C << endl;
  }
}
   

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

int main() {
	int n, x, l;
	int cou = 0, d = 0;

	cin >> n >> x;
	for (int i = 0; i < n; ++i) {
		cin >> l;
		if (d <= x) {
			d += l;
			cou++;
		}
		else break;
	}
	if (d <= x) cou++;

	cout << cou << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}

// end of Template

int n,k;
pll p[60];
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>k;
    for(int i=1;i<=n;i++){
        ll x,y;
        cin>>x>>y;
        p[i] = mp(x,y);
    }
    sort(p+1,p+1+n);

    ll ans = LONG_LONG_MAX;
    for(int i=1;i<=n;i++){
        for(int j=i+k-1;j<=n;j++){
            ll width = p[j].fi - p[i].fi;
            vll y;
            for(int ii=i; ii<=j; ii++){
                y.pb(p[ii].se);
            }
            sort(y.begin(),y.end());
            for(int ii=0;ii<y.size();ii++){
                for(int jj=ii+k-1;jj<y.size();jj++){
                    ll height = y[jj] - y[ii];
                    ll a = height * width;
                    ans = min(ans,a);
                }
            }

        }
    }
    cout<<ans<<newl;

}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;

int main(void)
{
	int N; cin >> N;
	map<string, lli> cnt;
	rep(i, 0, N) {
		string a; cin >> a;
		sort(a.begin(), a.end());
		cnt[a]++;
	}
	lli ans = 0;
	for (map<string, lli>::iterator it = cnt.begin(); it != cnt.end(); it++)
		ans += (it->second) * (it->second - 1) / 2;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 11136
#include <stdio.h>
int main(void){
  int n,in[4],i,j,k,t,o[2]={1,-1};
  char c,op[3]="+-";
  bool found=false;
  for (i=0;i<4;i++){
    scanf("%c",&c);
    in[i]=(int)c-48;
  }
  for (i=0;i<2;i++){
    for (j=0;j<2;j++){
      for (k=0;k<2;k++){
        t=in[0]+in[1]*o[i]+in[2]*o[j]+in[3]*o[k];
        if (t==7){
          found=true;
          break;
        }
      }
      if (found) break;
    }
    if (found) break;
  }
  printf("%d%c%d%c%d%c%d=7\n",in[0],op[i],in[1],op[j],in[2],op[k],in[3]);
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#include <boost/range/irange.hpp>
using namespace std;
using boost::irange;

// 定義
typedef long long           ll;
typedef pair<ll, ll>        P;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
const ll                    INF = 2e9;
const ll                    INF_LL = 1LL<<60;
const ll                    MOD = 998244353;

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// 処理
void Solve()
{
	ll H, W;
	cin >> H >> W;
	vector<ll> word(26, 0);
	REP(i, H) {
		REP(j, W) {
			char a;
			cin >> a;
			word[a - 'a']++;
		}
	}

	ll bai4 = count_if(ALL(word), [](ll one){ return one != 0 && one % 4 == 0; });
	ll bai2 = count_if(ALL(word), [](ll one){ return one != 0 && one % 4 != 0 && one % 2 == 0; });
	ll odd = count_if(ALL(word), [](ll one){ return IsOdd(one); });

	string ans = "No";
	if (IsEven(H) && IsEven(W)) {
		if (bai2 == 0 && odd == 0) ans = "Yes";
	} else if (IsOdd(H) && IsOdd(W)) {
		ll bai2Num = (H + W - 2) / 2;
		if (bai2 <= bai2Num && odd == 1) ans = "Yes";
	} else {
		ll bai2Num = IsOdd(H) ? W / 2 : H / 2;
		if (bai2 <= bai2Num && odd == 0) ans = "Yes";
	}
	
	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N,K; cin >> N >> K;
	vector<int> x(N);
	repp(i,0,N) cin >> x[i];
	int ans = 1e9;
	repp(i,K-1,N){
		int a = max(0,x[i]), b = max(0,-x[i-K+1]);
		ans = min(ans,min(a,b)+a+b);
	}
	cout << ans << endl;
	return 0;
}


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

/*int main(){
	fixed;
	setprecision(10);
	int n;
	cin >> n;
	if(n % 2 == 0){
		cout << fixed << setprecision(10) << 0.5000000000 << endl;
	}else if(n == 1){
		cout << 1 << endl;
	}else{
		n = static_cast<double>(n);
		n--;
		n = ((n / 2) + 1 ) / (n + 1);
		cout << fixed << setprecision(10) << n << endl;
	}
}
*/

int N;

void solve() {
    cin >> N;
    cout.precision(10);
    cout << (double)(N - N / 2) / (double)N << endl;
    return;
}

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


Measured memory_bytes: 256
a = (0..2).map do
	gets.chomp.split(" ").map(&:to_i);
end
n = gets.to_i
b = n.times.map { gets.to_i }

existence = a.flatten.map { |el| b.include?(el) }

lines = [
  [0, 1, 2],
  [3, 4, 5],
  [6, 7, 8],
  [0, 3, 6],
  [1, 4, 7],
  [2, 5, 8],
  [0, 4, 8],
  [2, 4, 6]
]

result = lines.map do |l, m, n|
  existence[l] && existence[m] && existence[n]
end.reduce {|acc, el| acc || el }

puts result ? 'Yes' : 'No'


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;
const lli mod = 1000000007;
const lli e3 = 1 << 13;
const lli INF = 1ll << 62;

lli factorial(lli n,lli mod = mod){
  static lli dp[100000];
  if(dp[n]) return dp[n];
  if(n == 0) return dp[n] = 1;
  return dp[n] = (n*factorial(n-1))%mod;
}

lli powl(lli x,lli r,lli mod = mod){
  lli ret = 1;
  for(;r != 0;r >>= 1){
    if(r&1 != 0) ret *= x,ret %= mod;
    x *= x,x %= mod;
  }
  return ret;
}

lli inverse(lli x,lli mod = mod){
  return powl(x,mod-2,mod);
}

lli combination(lli n,lli m,lli mod = mod){
  static lli dp[e3][e3];
  if(m == 0) return dp[n][m] = 1;
  if(n == 0) return dp[n][m] = 0;
  if(dp[n][m]) return dp[n][m];
  if(n < m) return dp[n][m] = 0;
  return dp[n][m] = (combination(n-1,m-1)+combination(n-1,m))%mod;
}


lli n;
graph g;
vll cs;
lli c;
vll subtrees;
lli dp[e3][e3];
lli ans;


lli centroid(lli x,lli p){
  lli s = 0;
  bool f = true;
  for(auto y : g[x]){
    if(y.first == p) continue;
    lli z = centroid(y.first,x);
    if(z*2 > n) f = false;
    s += z;
  }
  s++;
  if((n-s)*2 > n) f = false;
  if(f) cs.push_back(x);
  return s;
}

int main(){
  cin >> n;
  for(lli i = 0;i < n-1;i++){
    lli x,y;
    cin >> x >> y;
    g[x][y] = g[y][x] = 1;
  }
  centroid(1,0);

  cerr << "view centroids" << endl;
  for(lli x : cs) cerr << x << " ";
  cerr << endl;

  if(cs.size() == 2){
    cout << (factorial(n/2)*factorial(n/2))%mod << endl;

    return 0;
  }
  c = cs[0];
  for(auto y : g[c]){
    subtrees.push_back(centroid(y.first,c));
  }

  cerr << "view subtrees" << endl;
  for(lli x : subtrees){
    cerr << x << " ";
  }
  cerr << endl;

  dp[0][0] = 1;
  for(lli i = 1;i <= subtrees.size();i++){
    for(lli j = 0;j <= n;j++){
      if(dp[i-1][j] == 0) break;
      for(lli k = 0;k <= subtrees[i-1];k++){
        dp[i][j+k] += ((((dp[i-1][j]*combination(subtrees[i-1],k)%mod)*combination(subtrees[i-1],k))%mod)*factorial(k))%mod;
        dp[i][j+k] %= mod;
      }
    }
  }
  // for(lli i = 0;i <= n;i++) cerr << dp[subtrees.size()][i] << endl;

  for(lli i = 0;i <= n;i++){
    ans += (((i%2 ? -1 : 1)*((dp[subtrees.size()][i]*factorial(n-i))%mod))+mod)%mod;
    ans %= mod;
  }

  cout << ans << endl;

}


Measured memory_bytes: 323200
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    long long a, b, k; cin >> a >> b >> k;

    if (a >= k) {
        cout << a - k << " " << b << endl;
    } else {
        auto rest = k - a;
        cout << 0 << " " << (b - rest >= 0 ?  b - rest : 0) << endl;
    }
}


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

int main(){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    int max_num;
    max_num = max(max(A, B), C);
    cout << A + B + C - max_num + max_num * pow(2, K) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
typedef long long ll;
const int INF = 1<<29;
const int N = 1e6 + 9;
ll a[N];
int main()
{
    fio;
    ll n, maxx = -1;
    cin >> n;
    string s;
    map <string, ll> m;
    map <string, ll> ::iterator it;
    for(int i = 0; i < n; i ++){
        cin >> s;
        m[s] ++;
    }
    for(it = m.begin(); it != m.end(); it ++)
    {
        maxx = max(it->second, maxx);
    }
    for(it = m.begin(); it != m.end(); it ++)
    {
        if(it->second == maxx){
            cout << it->first  << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 23808
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let v = read_vec::<usize>();
    let (n,x) = (v[0],v[1]);
    let ms: Vec<usize> = (0..n).map(|_| read()).collect();
    let sum: usize = ms.iter().sum();
    let min = ms.iter().min().unwrap();
    println!("{}",n + (x - sum) / min);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(){
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if((x-r<0)||(y-r<0)){
printf("No\n");
}else if((x+r>W)||(y+r>H)){
printf("No\n");
}else{
printf("Yes\n");
}
}

Measured memory_bytes: 1820
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
from collections import defaultdict
d = defaultdict(int)
n=i1()
a=0
for i in range(n):
    d[i1()]+=1
for i in d.values():
    if i%2==1:
      a+=1
print(a)

Measured memory_bytes: 15452
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long

signed main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  while (true) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2) {
        cout << count << endl;
        return 0;
      }
      a[i] /= 2;
    }
    count++;
  }
  cout << count << endl;
  return 0;
}


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

class Program {
  static void Main (string[] args) {
    int N = int.Parse(Console.ReadLine());
    string S = Console.ReadLine();
    char rem = 'A';
    int count = 0;
    for (int cnt = 0; cnt < N; cnt++) 
    {
      if (rem != S[cnt])
      {
        count++;
        rem = S[cnt];
      }
    }
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 11232
/**
*    author:  Dooloper
*    created: 11.08.2020 22:56:55
**/

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;

#define rep(i,n) for(int i = 0; i < (n); i++)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
   cout << H << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
#pragma endregion

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int a[4];
  for(int i = 0; i < 4; i++){
    a[i] = s[i] - '0';
  }
  for(int i = 0; i < (1<<3); i++){
    ll ans = a[0];
    for(int j = 0; j < 3; j++){
      if(i&(1<<j)){
        ans += a[j+1];
      }else{
        ans -= a[j+1];
      }
    }
    if(ans == 7){
      cout << a[0];
      for(int j = 0; j < 3; j++){
        if(i&(1<<j)){
          cout << "+" << a[j+1];
        }else{
          cout << "-" << a[j+1];
        }
      }
      cout << "=7" <<  endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3660
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans = "";
        for(int i=0;i<s.length();i++)
        ans+="x";
        System.out.println(ans);
    }

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


Measured memory_bytes: 24020
N,A,B = list(map(int, input().split()))

if (A+B)>0 and A>0:
  n=N//(A+B)
  AB=N%(A+B)
  A_cnt=AB//A
  if A_cnt>0:
    print((n+1)*A)
  else:
    print(n*A+AB)
elif A==0:
  print(0)

  
    
    
    
    

Measured memory_bytes: 3064