akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#include <string>
using namespace std;
const int MIN_N =-(1e9);
int main()
{
	int n, k, i, moves,m;
	cin >> n >> k;
	int p[n+1], c[n+1];
	long long sum,maxm=MIN_N,track=MIN_N;
	for(i = 1; i <= n; i++)
		cin >> p[i];
	for(i = 1; i <= n; i++)
		cin >> c[i];
	for(i = 1; i <= n; i++)
	{
		sum = 0;
		moves = 0;
		m = i;
		track=MIN_N;
		do
		{
			moves++;
			if(moves>k)
				break;
			m = p[m];
			if(m == i)
			{
				sum = sum + c[m];
				track=max(track,sum);
				maxm=max(maxm,sum);
			//cout << "i = " << i << "moves = " << moves << "sum = " << sum <<"max = " <<maxm<<"\n";
				break;
			}
			sum = sum + c[m];
			track=max(track,sum);
			if(moves>k)
				break;
			maxm=max(maxm,sum);
			//cout << "i = " << i << "moves = " << moves << "sum = " << sum <<"max = " <<maxm<<"\n";
		}while(true);
		if(moves > k)
		{
			continue;
		}
		maxm = max(maxm, sum * (k / moves));
		maxm = max(maxm, track + (sum * (k / moves - 1)));
		int temp = k % moves;
		sum=sum * (k / moves);
		moves *= k/moves;
		//cout << "i = " << i << "moves = " << moves <<"sum = " << sum << "max = " <<maxm<<"\n";
		while(temp--)
		{
			m=p[m];
			sum=sum+c[m];
			maxm=max(maxm,sum);
			moves++;
			//		cout << "i = " << i << "moves = " << moves <<"sum = " << sum << "max = " <<maxm<<"\n";
		}
	}
	cout << maxm << endl;
	
	return 0;
	
}


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

using namespace std;

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;

int main() {
  int w, h, x, y;
  fscanf(stdin, "%d%d%d%d ", &w, &h, &x, &y);
  double res = (double)w * h / 2;
  int m = w == x*2 && h == y*2 ? 1 : 0;
  fprintf(stdout, "%.10f %d\n", res, m);
  return 0;
}


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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

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

struct Tree {
	int n;
	vector<vector<int>> a;
	vector<int> level;
	vector<int> par;

	Tree(int _n): n(_n), a(_n), par(_n) {}

	void dfs(int v, int p = -1) {
		par[v] = p;
		for (int x : a[v]) {
			if (x == p) {
				continue;
			}
			level[x] = level[v] + 1;
			dfs(x, v);
		}
	}

	void addEdge(int u, int v) {
		a[u].push_back(v);
		a[v].push_back(u);
	}

	int getDiam() {
		level.assign(n, 0);
		dfs(0);
		int v = max_element(all(level)) - level.begin();
		level.assign(n, 0);
		dfs(v);
		return *max_element(all(level));
	}

	void addVertex(itn v) {
		a.emplace_back(1, v);
		a[v].push_back(n);
		n += 1;
		par.push_back(0);
	}

	void markLevels() {
		int d = getDiam();
		int end = max_element(all(level)) - level.begin();

		for (int i = 0; i < d / 2; ++i) {
			end = par[end];
		}

		if (d % 2 == 0) {
			level.assign(n, 0);
			dfs(end);
		} else {
			int r1 = end;
			int r2 = par[r1];
			level.assign(n, 0);
			dfs(r1, r2);
			dfs(r2, r1);
		}
	}
};

void remax(int& what, int x) {
	what = max(what, x);
}

unsigned long long getAnswer(Tree tree) {
	int d = tree.getDiam();
	tree.markLevels();
	unsigned long long ans = d % 2 + 1;
	int cols = d / 2 + 1;
	vector<int> max_deg(cols);
	int n = tree.n;
	for (int i = 0; i < n; ++i) {
		remax(max_deg[tree.level[i]], (int)tree.a[i].size() - 1);
	}
	if (d % 2 == 0) {
		max_deg[0] += 1;
	}
	max_deg.pop_back();
	for (int x : max_deg) {
		ans *= x;
	}

	if (d % 2 == 0) {
		int root = min_element(all(tree.level)) - tree.level.begin();

		for (int x : tree.a[root]) {
			tree.level.assign(n, 0);
			tree.dfs(root, x);
			tree.dfs(x, root);

			unsigned long long tmp = 2;
			int cols = d / 2 + 1;
			vector<int> max_deg(cols);
			int n = tree.n;
			for (int i = 0; i < n; ++i) {
				remax(max_deg[tree.level[i]], (int)tree.a[i].size() - 1);
			}
			max_deg.pop_back();
			for (int y : max_deg) {
				tmp *= y;
			}
			ans = min(ans, tmp);
		}
	}

	return ans;
}

int main() {
	int n = nxt();
	if (n == 1) {
		cout << "1 0\n";
		return 0;
	}
	Tree tree(n);
	for (int i = 0; i < n - 1; ++i) {
		int u = nxt() - 1, v = nxt() - 1;
		tree.addEdge(u, v);
	}

	int d = tree.getDiam();

	auto ans = getAnswer(tree);

	cout << d / 2 + 1 << " " << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
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 N; cin >> N;
    vector<int> B(N-1);
    for(int &b:B) cin >> b;
    
    int ans = B[0] + B[N-2];
    for(int i=0; i<N-2; i++){
        ans += min(B[i], B[i+1]);
    }
    
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;

class Main{
  public static void main(String args[]){
    Set<String> used_words = new HashSet<String>();
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    
    boolean flag = true;
    String previous = scan.next();
    used_words.add(previous);
    for(int i=1;i<n;i++){
      String current = scan.next();
      if(!used_words.add(current)||previous.charAt(previous.length()-1)!=current.charAt(0)){
        flag=false;
        break;
      }else{
        previous=current;
      }
    }
    scan.close();
    System.out.println(flag?"Yes":"No");
    return;
  }//main
}//Main

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

namespace ConsoleApp1
{
    static class COtoshidama
    {        
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');
            var n = int.Parse(s[0]);
            var y = int.Parse(s[1]);

            for (int i = 0; i <= n; i++)
            {
                for (int j = 0; j <= n - i; j++)
                {
                    int k = n - j - i;

                    int total = 10000 * i + 5000 * j + 1000 * k;
                    if (total == y)
                    {
                        Console.WriteLine($"{i} {j} {k}");
                        Console.ReadLine();
                        return;
                    }
                }
            }
            
            Console.WriteLine($"-1 -1 -1");
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13140
//2734　吉原直樹　問0277
import java.util.Scanner;
public class Main{
    int kind;
    int su;
    int kei;
    int []seki = {6000,4000,3000,2000};
    public void solve(){
        Scanner sc = new Scanner(System.in);
        for(int k=0;k<4;k++){
            kind=sc.nextInt();
            switch(kind){
                case 1:
                kind=6000;
                break;
                case 2:
                kind=4000;
                break;
                case 3:
                kind=3000;
                break;
                case 4:
                kind=2000;
                break;
            }
            su=sc.nextInt();
            kei=kind*su;
            System.out.println(kei);
        }
    }
    
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17308
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int x;
  cin >> x;

  for (ll a = 0; a < 1000; a++) {
    for (ll b = -1000; b < 1000; b++) {
      if (pow(a, 5) - pow(b, 5) == x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4012
#include <stdio.h>
#include <stdlib.h>


typedef struct{
  int parent;
  int cnum;
  int child[2];
} Node;

int hieght(int);

Node A[100000];

int main(){
  int n;
  int N;
  int num;
  int i,j;
  int jag;
  int depth;
  int jag1;
  int h;
  
  
  
  scanf("%d",&n);
  for(i=0;i<n;i++) A[i].parent=-1;
  for(i=0;i<n;i++){
    scanf("%d",&num);
    A[num].cnum=0;
    for(j=0;j<2;j++){
      scanf("%d",&A[num].child[j]);
      if(A[num].child[j]!=-1){
        A[A[num].child[j]].parent=num;
        A[num].cnum++;
    }
  }
}
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, ",i,A[i].parent);
    jag=A[i].parent;
    //sibling
    jag1=0;
    printf("sibling = ");
    for(j=0;j<A[jag].cnum;j++){
       if(jag==-1) break;
       if(A[jag].child[j]!=i&&A[jag].child[j]!=-1) {
          printf("%d, ",A[jag].child[j]);
          jag1=1;
       }
    }
    if(jag1==0) printf("-1, ");
    //
    //defree
    printf("degree = %d, ",A[i].cnum);
    //
    depth=0;
    while(1){
      if(jag==-1){
	printf("depth = %d, ",depth);
	break;
      }
      else{
	depth++;
	jag=A[jag].parent;
      }
    }
    //height
    h=height(i);
    printf("height = %d, ",h);   

    if(depth==0) printf("root\n");
    else if(A[i].cnum!=0) printf("internal node\n");
    else printf("leaf\n");
  }

  return 0;
}

int height(int i){
   int hr=0;
   int hl=0;
   
   if(A[i].cnum==0) return 0;

   hl=height(A[i].child[0]);
   hr=height(A[i].child[1]);
   if(hl>hr) {
     hl++;
     return hl;
   }
   else {
     hr++;
     return hr;
   }
}
   



Measured memory_bytes: 2108
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>

signed main() {
    intmax_t N, X, M;
    scanf("%jd%jd%jd", &N, &X, &M);

    const size_t L = 35;
    std::vector<std::vector<intmax_t>> nxt_num(L + 1, std::vector<intmax_t>(M, 0));
    std::vector<std::vector<intmax_t>> nxt_sum(L + 1, std::vector<intmax_t>(M, 0));
    for (intmax_t n = 0; n < M; ++n) {
        nxt_num[0][n] = (n * n) % M;
        nxt_sum[0][n] = n;
    }
    for (size_t i = 0; i < L; ++i) {
        for (intmax_t n = 0; n < M; ++n) {
            nxt_num[i + 1][n] = nxt_num[i][nxt_num[i][n]];
            nxt_sum[i + 1][n] = nxt_sum[i][n] + nxt_sum[i][nxt_num[i][n]];
        }
    }

    size_t i = 0;
    intmax_t cur = X;
    intmax_t res = 0;
    while (N > 0) {
        if (N & 1) {
            res += nxt_sum[i][cur];
            cur = nxt_num[i][cur];
        }
        N >>= 1;
        ++i;
    }

    printf("%jd\n", res);
    return 0;
}


Measured memory_bytes: 60380
n,m=map(int,input().split())
g=[[] for i in range(n)]
h=list(map(int,input().split()))
used=set([])
for i in range(m):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

ans=[]
for i in range(n):
    if(i in used):
        continue
    else:
        gi=g[i]
        hi=h[i]
        for j in gi:
            if(hi <= h[j]):
                break
        else:
            ans.append(i)
        used.add(i)
print(len(ans))

Measured memory_bytes: 39508
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    int n;
    cin >> n;
    
    vector<int> ans(n + 1, 0);
    for (ll x = 1; x * x <= n; ++x) {
        for (ll y = 1; y * y <= n; ++y) {
            for (ll z = 1; z * z <= n; ++z) {
                if (x * x + y * y + z * z + x * y + y * z + z * x <= n) {
                    ans[x * x + y * y + z * z + x * y + y * z + z * x]++;
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i) cout << ans[i] << "\n";
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int N;
    cin >> N;
    vector<int> A(N+1),B(N+1,0);
    for(int i=2; i<N+1; i++){
        cin >> A.at(i);
        B.at(A.at(i)) += 1;
    }
    for(int i=1; i<N+1; i++){
        cout << B.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 4764
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long int ll;
int N, K;
int X1[50], Y1[50], Z1[50], X2[50], Y2[50], Z2[50];
int XX[100], YY[100], ZZ[100];
int X_X[100], Y_Y[100], Z_Z[100];
int COU[100][100][100];
ll ans;
int main()
{
	scanf("%d%d", &N, &K);
	for (int i = 0; i < N; i++){
		scanf("%d%d%d", &X1[i], &Y1[i], &Z1[i]);
		scanf("%d%d%d", &X2[i], &Y2[i], &Z2[i]);
	}
	
	for (int i = 0; i < 2 * N; i++){
		for (int j = i + 1; j < 2 * N; j++){
			if (i < N&&j < N){
				if (X1[i] < X1[j])XX[j]++;
				else XX[i]++;
			}
			else if (i < N){
				if (X1[i] < X2[j - N])XX[j]++;
				else XX[i]++;
			}
			else{
				if (X2[i - N] < X2[j - N])XX[j]++;
				else XX[i]++;
			}
		}
	}
	for (int i = 0; i < 2 * N; i++){
		for (int j = i + 1; j < 2 * N; j++){
			if (i < N&&j < N){
				if (Y1[i] < Y1[j])YY[j]++;
				else YY[i]++;
			}
			else if (i < N){
				if (Y1[i] < Y2[j - N])YY[j]++;
				else YY[i]++;
			}
			else{
				if (Y2[i - N] < Y2[j - N])YY[j]++;
				else YY[i]++;
			}
		}
	}
	for (int i = 0; i < 2 * N; i++){
		for (int j = i + 1; j < 2 * N; j++){
			if (i < N&&j < N){
				if (Z1[i] < Z1[j])ZZ[j]++;
				else ZZ[i]++;
			}
			else if (i < N){
				if (Z1[i] < Z2[j - N])ZZ[j]++;
				else ZZ[i]++;
			}
			else{
				if (Z2[i - N] < Z2[j - N])ZZ[j]++;
				else ZZ[i]++;
			}
		}
	}
	for (int i = 0; i < 2 * N; i++){
		if (i < N)X_X[XX[i]] = X1[i];
		else X_X[XX[i]] = X2[i-N];
		if (i < N)Y_Y[YY[i]] = Y1[i];
		else Y_Y[YY[i]] = Y2[i - N];
		if (i < N)Z_Z[ZZ[i]] = Z1[i];
		else Z_Z[ZZ[i]] = Z2[i - N];
	}
	for (int i = 0; i < N; i++){
		for (int j = XX[i]; j < XX[i + N]; j++){
			for (int k = YY[i]; k < YY[i + N]; k++){
				for (int l = ZZ[i]; l < ZZ[i + N]; l++){
					COU[j][k][l]++;
				}
			}
		}
	}
	for (int i = 0; i < 2 * N; i++){
		for (int j = 0; j < 2 * N; j++){
			for (int k = 0; k < 2 * N; k++){
				if (COU[i][j][k] >= K){
					ans += (ll)(X_X[i+1] - X_X[i])*(ll)(Y_Y[j + 1] - Y_Y[j])*(ll)(Z_Z[k + 1] - Z_Z[k]);
				}
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4988
function color(rate) {
    if (1 <= rate && rate <= 399) return "gray";
    if (400 <= rate && rate <= 799) return "brown";
    if (800 <= rate && rate <= 1199) return "green";
    if (1200 <= rate && rate <= 1599) return "light_blue";
    if (1600 <= rate && rate <= 1999) return "blue";
    if (2000 <= rate && rate <= 2399) return "yellow";
    if (2400 <= rate && rate <= 2799) return "orange";
    if (2800 <= rate && rate <= 3199) return "red";
    return "free";
}
function Main(input) {
    input = input.split("\n");
    var a = input[1].split(" ");
    var col = {};
    var ans = 0;
    for (var i of a) {
        if (!col[color(i)]) {
            col[color(i)] = 1;
            if (color(i) != "free") ans++;
        }
        else col[color(i)]++;
    }
    if (ans == 0) console.log(1 + " " + col.free);
    else console.log(ans + " " + (ans + (col.free ? col.free : 0)));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
LL read() {
    LL k = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9')
        k = k * 10 + c - 48, c = getchar();
    return k * f;
}
int main() {
    int k = read(), x = read();
    for(int i = x - k + 1; i <= x + k - 1; ++i)
        printf("%d ", i);
    printf("\n");


    return 0;
}

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

namespace AthleteProgramming2
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            n -= 1;
            int[] array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            InsertSort(array);
        }

        static void InsertSort(int[] array)
        {
            for (int k = 0; k < array.Length - 1; k++)
            {
                Console.Write("{0} ", array[k]);
            }
            Console.WriteLine(array[array.Length - 1]);
            for (int i = 1; i < array.Length; i++)
            {
                int v = array[i];
                int j = i - 1;
                while (j >= 0 && array[j] > v)
                {
                    array[j + 1] = array[j];
                    j--;
                }
                array[j + 1] = v;
                for(int k = 0; k < array.Length - 1; k++)
                {
                    Console.Write("{0} ",array[k]);
                }
                Console.WriteLine(array[array.Length - 1]);
            }
            
        }

    }
}

Measured memory_bytes: 9644
fun main(args: Array<String>) {
    var (a, b, c, d) = readLine()!!.split(" ").map{it.toInt()}
    var i = 0
    while (a*c > 0) {
        if (i%2==0) {
            c -= b
        } else {
            a -= d
        }
        i++
    }
    println(if (c <= 0) "Yes" else "No")
}


Measured memory_bytes: 36268
import java.util.*;
public class Main {
 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		int[] cost = new int[n];
		int[] time = new int[n];
		for(int i=0; i<n; i++) {
			cost[i] = sc.nextInt();
			time[i] = sc.nextInt();
		}
		int ans=0;
		for(int i=0; i<n; i++) {
			if(time[i]<=t && cost[ans]>cost[i]) {
				ans=i;
			}
		}
		if(time[ans]<=t) {
			System.out.println(cost[ans]);
		}else {
			System.out.println("TLE");
		}
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int n,m;
bool check(int x, int y){
    if(x >=0 and y >=0 and x < n and y < m) return true;
    return false;
}

signed main(){
    ios_base::sync_with_stdio(false);
   // freopen("input.txt", "r", stdin);
    int n, k; cin>>k>>n;
    int a[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    int ans=(a[n-1]-a[0]);
    //cout<<ans<<endl;
    for(int i=1; i<n; i++){
        //cout<<k - (a[i]- a[i-1])<<endl;
        ans = min(k - (a[i]- a[i-1]), ans);
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 5192
N, M = list(map(int, input().split()))

ans = 0

def dfs(n, visited):
    global ans
    visited.append(n)
    if len(visited) == N:
        ans += 1
    else:
        for i in l[n-1]:
            if i not in visited:
                dfs(i, visited)
    visited.remove(n)

l = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    l[a-1].append(b)
    l[b-1].append(a) 

dfs(1, [])
print(ans)


Measured memory_bytes: 3064
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().decode().rstrip()
T = readline().decode().rstrip()
count = 0
for i in range(len(S)):
    if S[i] != T[i]:
        count+=1
print(count) 

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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("D.in", "r", stdin);
	freopen ("D.out", "w", stdout);
#endif
}

const int N = 1e5 + 1e3, Mod = 1e9 + 7;

int fac[N], ifac[N];

inline int fpm(int x, int power) {
	int res = 1;
	for (; power; power >>= 1, x = 1ll * x * x % Mod)
		if (power & 1) res = 1ll * res * x % Mod;
	return res;
}

void Fac_Init(int maxn) {
	fac[0] = ifac[0] = 1;
	For (i, 1, maxn) fac[i] = 1ll * fac[i - 1] * i % Mod;
	ifac[maxn] = fpm(fac[maxn], Mod - 2);
	Fordown (i, maxn - 1, 1) ifac[i] = ifac[i + 1] * (i + 1ll) % Mod;
}

inline int comb(int n, int m) {
	if (n < 0 || m < 0 || n < m) return 0;
	return 1ll * fac[n] * ifac[n - m] % Mod * ifac[m] % Mod;
}

int n, app[N], rest;

int main() {

	File();

	n = read();

	For (i, 1, n + 1) {
		int x = read();
		if (app[x]) {
			rest = app[x] + n - i; break;
		} else app[x] = i;
	}

	Fac_Init(n + 1);

	For (i, 1, n + 1) {
		int ans = (Mod + comb(n + 1, i) - comb(rest, i - 1)) % Mod;
		printf ("%d\n", ans);
	}

	return 0;

}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T> >
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll 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;
    if (t & 1) a *= *this;
    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;
  }
};
mint dp[110][6][6][6];

bool ng(int a,int b, int c){
  return (a == 1 && b == 2 && c==3);
}

int main() {
  int n;
  cin >> n;
  dp[0][0][0][0] = 1;
  rep(i, n) {
    rep(a, 4) {
      rep(b, 4) {
        rep(c, 4) {
          rep(d, 4) {
            if(ng(b,c,d)) continue;
            if(ng(b,d,c)) continue;
            if(ng(c,b,d)) continue;
            if(ng(a,b,d)) continue;
            if(ng(a,c,d)) continue;

            dp[i + 1][b][c][d] += dp[i][a][b][c];
          }
        }
      }
    }
  }
  mint ans = 0;
  rep(a, 4) {
    rep(b, 4) {
      rep(c, 4) { ans += dp[n][a][b][c]; }
    }
  }
  cout << ans.x << endl;
  return 0;
}

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

#define ll long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define F first
#define S second
#define pii pair<ll int,ll int>
#define vi vector<ll,ll>
#define INF 1000000007


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll int n,d,a;
	cin >> n >> d >> a;
	vector <pii> v(n);
	for(ll int i=0;i<n;i++){
		cin >> v[i].F >> v[i].S;
		v[i].S = (v[i].S+a-1)/a;
	}
	sort(v.begin(),v.end());
	int pre[n+1],sm=0;
	memset(pre,0,sizeof(pre));
	ll int ans=0;
	for(ll int i=n-1;i>=0;i--){
		pii p = {v[i].F-2*d,-INF};
		ll int lidx = lower_bound(v.begin(),v.end(),p)-v.begin();
		ll int left = v[i].S+sm;
		if(left>0){
			ans += left;
			pre[lidx] += left;
			sm -= left;
		}
		sm += pre[i];
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long x, k, d, ans;
  cin >> x >> k >> d;
  x = llabs(x);
  if (x/d >= k) ans = x - k*d;
  else {
    k -= x/d;
    if (k%2 == 0) ans = x%d;
    else ans = d - (x%d);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int n,m,c,a[25][25],b[25],num,ans; 
int main(){
	cin>>n>>m>>c;
	for(int i=1;i<=m;i++) cin>>b[i];
	for(int i=1;i<=n;i++)
	{
		num=0;
		for(int j=1;j<=m;j++)
		    cin>>a[i][j],num+=a[i][j]*b[j];
		if(num+c>0) ans++;
	}
	cout<<ans;
 	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,a,b;
int d[11][11];
vector<P> G[3][205];
int f[105][105];
int dp[205];

int dijk(int ac,int bc){
	for(int i=0;i<202;i++){
		dp[i]=INF;
	}
	dp[0]=0;
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,0));
	while(que.size()){
		P q=que.top();
		que.pop();
		int v=q.second;
		if(q.first>dp[v])continue;
		for(int i=0;i<3;i++){
			for(int j=0;j<G[i][v].size();j++){
				int co=G[i][v][j].second;
				if(i==1)co=ac;
				if(i==2)co=bc;
				if(co+q.first<dp[G[i][v][j].first]){
					dp[G[i][v][j].first]=co+q.first;
					que.push(P(co+q.first,G[i][v][j].first));
				}
			}
		}
	}
	//printf("%d %d %d\n",ac,bc,dp[201]);
	return dp[201];
}

int main(void){
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			scanf("%d",&d[i][j]);
		}
	}
	for(int i=0;i<100;i++){
		G[1][i].push_back(P(i+1,-1));
	}
	for(int i=101;i<201;i++){
		G[2][i].push_back(P(i+1,-1));
	}
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			for(int k=0;k<a;k++){
				for(int l=0;l<b;l++){
					f[i][j]=max(f[i][j],d[k][l]-(k+1)*i-(l+1)*j);
				}
			}
			G[0][i].push_back(P(201-j,f[i][j]));
		}
	}
	bool flag=true;
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			if(dijk(i+1,j+1)!=d[i][j])flag=false;
		}
	}
	if(flag){
		printf("Possible\n");
		int siz=0;
		for(int i=0;i<3;i++){
			for(int j=0;j<202;j++){
				siz+=G[i][j].size();
			}
		}
		printf("%d %d\n",202,siz);
		for(int i=0;i<3;i++){
			for(int j=0;j<202;j++){
				for(int k=0;k<G[i][j].size();k++){
					if(i==0){
						printf("%d %d %d\n",j+1,G[i][j][k].first+1,G[i][j][k].second);
					}else if(i==1){
						printf("%d %d X\n",j+1,G[i][j][k].first+1);
					}else{
						printf("%d %d Y\n",j+1,G[i][j][k].first+1);
					}
				}
			}
		}
		printf("%d %d\n",1,202);
	}else{
		printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int K,A,B;cin >> K >> A >> B;
    bool ok = false;
    for(int i = A;i <= B;i++){
        if(i % K == 0)ok = true;
    }
    if(ok)cout << "OK" << endl;
    else cout << "NG" << endl;
}

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

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

constexpr auto inf = 1e9;

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

using ll = long long;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;

	auto kakuinowa = [&](int i)
	{
		int num = 0;
		int tmp = i;

		while (tmp)
		{
			num += tmp % 10;
			tmp /= 10;
		}

		return num;
	};

	list<int> ans;

	for (int i = 1; i <= n; i++)
	{
		int tmp = kakuinowa(i);
		if (tmp >= a && tmp <= b)
		{
			ans.push_back(i);
		}
	}

	cout << accumulate(ans.begin(), ans.end(), 0) << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)
  const int INF =1 << 30;
  int dp[2][402][402];

  int main(){
    int n,ma,mb;
    cin >> n >> ma >> mb;
    vector<vector<int>> v(n,vector<int> (3));
    rep(i,n){
      int x,y,z;
      cin >> x >> y >> z;
      v[i][0]=x;v[i][1]=y;v[i][2]=z;
    }
    int now=0;
    int nxt=1;
    rep(i,401) rep(j,401) {
      dp[now][i][j]=INF;
      dp[nxt][i][j]=INF;
    }
    //printf("ok\n");
    dp[now][0][0]=0;
    dp[nxt][0][0]=0;
    rep(i,n){
      for (int x=0;x <= 400;x++){
        for (int y=0;y <= 400;y++){
          //if (i > 2 || x >= 400 || y >= 400) printf("i=%d x = %d y = %d\n",i,x,y);
          if (dp[now][x][y]==INF) continue;
          else {
            dp[nxt][x][y]=min(dp[nxt][x][y],dp[now][x][y]);
            dp[nxt][min(x+v[i][0],401)][min(y+v[i][1],401)]=min(dp[nxt][min(x+v[i][0],401)][min(y+v[i][1],401)],dp[now][x][y]+v[i][2]);
            //dp[nxt][min(x+v[i][0],401)][min(y+v[i][1],401)]=min(dp[nxt][min(x+v[i][0],401)][min(y+v[i][1],401)],dp[now][x][y]+v[i][2]);
          }
        }
      }
    //  rep(s,7) {
    //    rep(t,7){
    //      if (dp[nxt][s][t]==INF) cout << "F";
    //      else cout << dp[nxt][s][t];
    //    }
    //    printf("\n"); 
    //  }
    //  printf("\n");
      swap(now,nxt);
    }
    //printf("ok\n");
    int ans=INF;
    rep(i,401){
      rep(j,401){
        if (i==0 || j==0) continue;
        if (mb*i==ma*j) ans=min(ans,dp[now][i][j]);
      }
    }
    if (ans==INF) cout << -1 << endl;
    else cout << ans << endl;
    

    return 0;
  }


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n;
    cin >> n;
    set<int> s;
    rep(i, n) {
        int tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;
 
int main(void){
  string s;
  cin>>s;
  cout<<s.substr(0,s.size()-8)<<endl;
  return 0;
}

Measured memory_bytes: 256
$<.readlines.map {|a| a.split.map(&:to_i)}.each do |a, b, n|
  f = ->(x, i = 1, sum = 0) {
    return sum if i > n or x.zero?
    f.(x * 10 % b, i + 1, sum + x * 10 / b)
  }
  puts f.(a % b)
end


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

public class Main {
	static final int ways = 5;
	static long[] a = new long[ways];
	static long n;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = Long.parseLong(sc.next());
		for (int i = 0; i < ways; i++) {
			a[i] = Long.parseLong(sc.next());
		}

		long min = Arrays.stream(a).min().orElse(0);
		long ans = (long) Math.ceil((double) n / min + 4);
		System.out.println(ans);

	}

}


Measured memory_bytes: 26964
#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>>y;
	cout<<(x+y+1)/2<<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);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
/*
 _ _ _   _    _   _    _   _ _ _   _    _   _ __ _   __       __
|  _ _| | |  | | | |  | | |  _  | | |  | | |  __  | |   \   /   |
| |_ _  | |__| | | |  | | | |_| | | |__| | | |__| | | |\ \_/ /| |
|_ _  | |  __  | | |  | | |  _ <  |  __  | |  __  | | | \   / | |
 _ _| | | |  | | | |__| | | |_| | | |  | | | |  | | | |  \_/  | |  _   _   _
|_ _ _| |_|  |_| |_ __ _| |_ _ _| |_|  |_| |_|  |_| |_|       |_| |_| |_| |_|

*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
const int MOD=1e9 + 7;
const int N=1000100;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){  
                                                        for (auto &v : vec) is >> v; return is; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

void solve(){
    ll n;
    cin>>n;
    ll ans=0,times=1;
    while(n){
        ans+=times;
        n/=2;
        times*=2LL;
    }
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t = 1;
    // cin>>t;
    for (long int tt = 1; tt <= t; tt++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int a[3][3];
int main()
{
    scanf("%d%d%d",&a[0][0],&a[0][1],&a[1][1]);
    int sum=a[1][1]*3;
    a[2][2]=sum-a[0][0]-a[1][1];
    a[2][1]=sum-a[0][1]-a[1][1];
    a[2][0]=sum-a[2][2]-a[2][1];
    a[1][0]=sum-a[0][0]-a[2][0];
    a[0][2]=sum-a[0][0]-a[0][1];
    a[1][2]=sum-a[0][2]-a[2][2];
    for(int i=0;i<3;++i)
    {
        for(int j=0;j<3;++j)printf("%d ",a[i][j]);
        putchar('\n');
    }
}

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

int main(void)
{
    int n;
    int h[100001];
    int dp[100001];
    cin >> n;

    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    
    for(int i = 2; i < n; i++) {
        int step_2 = abs(h[i-2] - h[i]);
        int step_1 = abs(h[i-1] - h[i]);
        step_2 += dp[i-2];
        step_1 += dp[i-1];

        dp[i] = min(step_2, step_1);
    }

    cout << dp[n-1];
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int N;
    cin >> N;
    bool flg = false;
    REP (i, 10) {
        REP (j, 10) {
            if (i * j == N) {
                flg = true;
                break;
            }
        }
        if (flg)
            break;
    }
    cout << (flg ? "Yes" : "No") << endl;
    return 0;
}


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

ll MOD = 1e9+7;

const static ll Max = 100000+5;
const static ll INF = 1e18+5;
vector<set<ll>> G(Max);
ll N, Q, K, M;
map<pair<ll, ll>, ll> C;
ll DP[Max];

vector<vector<bool>> Map;

void Dijkstra2(ll s){
    for(int i = 0; i < Max; i++) DP[i] = INF;
    DP[s] = 0;
    for(auto v : G[s]) DP[v] = C[make_pair(s, v)];
    priority_queue< pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>> > Q;
    for(auto v : G[s]){
        if(C.find(make_pair(s, v)) != C.end()) Q.push(make_pair(C[make_pair(s, v)], make_pair(s, v)));
    }

    while(!Q.empty()){
        auto next = Q.top(); Q.pop();
        auto w = next.second.second;
        
        for(auto v : G[w]) if(C.find(make_pair(w, v)) != C.end()){
            if(DP[w] + C[make_pair(w, v)] <= DP[v]){
                DP[v] = DP[w] + C[make_pair(w, v)];
                Q.push(make_pair(C[make_pair(w, v)], make_pair(w, v)));
            }
        }
    }
    
    ll DP2[Max]; for(int i = 0; i < Max; i++) DP2[i] = INF;
    DP2[s] = 0;
    for(auto v : G[s]) {
        DP2[v] = C[make_pair(s, v)];
        if(DP[v] == DP2[v]) Map[s][v] = Map[v][s] = false;
    }
    priority_queue< pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>> > Q2;
    for(auto v : G[s]){
        if(C.find(make_pair(s, v)) != C.end()) Q2.push(make_pair(C[make_pair(s, v)], make_pair(s, v)));
    }

    while(!Q2.empty()){
        auto next = Q2.top(); Q2.pop();
        auto w = next.second.second;

        //if(next.second.first == s && DP2[w] != DP[w]){
          //  Map[s][w] = Map[w][s] = true;
            //cout << s << " " << w << " " << DP[w] << " " << DP2[w] << endl;
        //}
        //else Map[s][w] = Map[s][w] = false;
        
        for(auto v : G[w]) if(C.find(make_pair(w, v)) != C.end()){
            if(DP2[w] + C[make_pair(w, v)] == DP[v]){
                DP2[v] = DP2[w] + C[make_pair(w, v)];
                Q2.push(make_pair(C[make_pair(w, v)], make_pair(w, v)));
                Map[w][v] = Map[v][w] = false;
            }
            //else Map[w][v] = true;
        }
        
    }
}


int main(){
    cin >> N >> M;
    Map.resize(N);
    for(int i = 0; i < N; i++) Map[i].resize(N);
    for(int i = 0; i < M; i++){
        ll a, b, c; cin >> a >> b >> c; a--; b--;
        G[a].insert(b);
        G[b].insert(a);
        C[make_pair(a, b)] = c;
        C[make_pair(b, a)] = c;
        Map[a][b] = Map[b][a] = true;
    }

    for(int i = 0; i < N; i++){
        Dijkstra2(i);
    }

    ll ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++) if(Map[i][j]) ans++;
    }
    cout << ans/2 << endl;



}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
	int n,k;
	cin>>n;
	cin>>k;
	int h[n+1];
	for(int i=1;i<=n;i++)
	{cin>>h[i];
 
	}
  a[1]=0;
  a[2]=abs(h[2]-h[1]);
 
  for (int i = 3; i <=n; ++i)
  {int x=10000000000;
  	for(int j=max(i-k,1);j<=i-1;j++)
  	{x=min(a[j]+abs(h[j]-h[i]),x);
 
  	}
  	a[i]=x;
  }
  cout<<a[n]<<endl;
 
}

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

int main() {
int n,i,x,y;
cin>>n;
y=0;
for(i=1 ; i<=n;i++){
  cin>>x;
  if(x!=i){
    y=y+1;

  }
}
if(y<=2){
    	cout<<"YES";}
else{
        cout<<"NO";}
}



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

using namespace std;

void solve(){
	int n; cin>>n;
	unordered_map<long, long> mp;
	long long int s = 0;
	for(int i = 0; i < n; i++){
		long a; cin>>a;
		mp[a]++;
		s+=a;
	}
	int q; cin>>q;
	while(q--){
		long b, c; cin>>b>>c;
		if(mp.find(b) != mp.end() && mp[b]){
			s = (s - (b * mp[b]) + (c * mp[b]));
			mp[c] += mp[b];
			mp[b] = 0;
		}
		cout << s << "\n";
	}
}
int main() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 6644
object Main extends App {
	val a = scala.io.StdIn.readLong

	def fn(x: Long): Long = {
		var tp = x
		var n = 1000000000L
		var ans = 0L

		for(i <- 0  until 10){
			ans += tp / n
			tp = tp % n
			n = n/10L
		}

		return ans
	}

	if(a % fn(a) == 0){
		println("Yes")
	}else{
		println("No")
	}

}

Measured memory_bytes: 27448
#include <iostream>

using namespace std;

const int MOD = 1000000007;

int cnt[100005];

long long pow(long long x, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n % 2 == 1) res = res * x % MOD;
    x = x * x % MOD;
    n = n / 2;
  }
  return res;
}


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

  int d = (N - 1) % 2;
  for (int i = 0; i < N; ++i) {
    int A;
    cin >> A;
    cnt[A]++;

    if (A % 2 != d || cnt[A] > 2 || A == 0 && cnt[0] > 1) {
      cout << 0 << endl;
      return 0;
    }
  }

  cout << pow(2, N / 2) << endl;
}


Measured memory_bytes: 3876
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    // 準備
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long k = sc.nextLong();

    if( a > 0 && k > 0) {
      if(a<=k) {
        k -= a;
        a = 0;
      } else {
        a -= k;
        k = 0;
      }
    }
    if( b > 0 && k > 0) {
      if(b<=k) {
        k -= b;
        b = 0;
      } else {
        b -= k;
        k = 0;
      }
    }
    System.out.println(a + " " + b);
  }
}

Measured memory_bytes: 23636
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    c = -1
    r = 0
    for b in a:
        if b == c:
            c = -1
            r += 1
        else:
            c = b
    return r


print(main())


Measured memory_bytes: 6852
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

result = sum(B)

for i in range(N-1):
  if A[i] + 1 == A[i+1]:
    result += C[A[i]-1]
print(result)

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, a, b, c;
  cin >> n >> a >> b >> c;

  map<char, int> cnt;
  cnt['A'] = a;
  cnt['B'] = b;
  cnt['C'] = c;

  vvi occ(3);
  vector<string> qs;
  rep(i,0,n) {
    string s;
    cin >> s;
    qs.pb(s);
    occ[s[0]-'A'].pb(i);
    occ[s[1]-'A'].pb(i);
  }

  int i = 0;
  string out;
  for (auto q: qs) {
    char l = q[0], r = q[1];

    if (cnt[l] == 0 and cnt[r] == 0) return cout << "No\n", 0;
    char ans;
    if (cnt[l] > cnt[r]) ans=r;
    else if (cnt[r] > cnt[l]) ans=l;
    else {
      auto nl = upper_bound(all(occ[l-'A']), i);
      auto nr = upper_bound(all(occ[r-'A']), i);
      if (nl == occ[l-'A'].end()) ans=r;
      else if (nr == occ[r-'A'].end()) ans=l;
      else if (*nl < *nr) ans=l;
      else ans=r;
    }

    if (ans==l) {
      ++cnt[l];
      --cnt[r];
    } else {
      ++cnt[r];
      --cnt[l];
    }

    out.pb(ans);
    ++i;
  }

  cout << "Yes\n";
  for (auto x:out) cout << x << '\n';

}

Measured memory_bytes: 8356
#include<bits/stdc++.h>
using namespace std;
struct node {

long long int a,val;
};
bool comp(struct node p, struct node q)
{

    if(p.val<q.val)
        return true;
    return false;
}
int main()
{
   long long  int a,b,c,d,i,j,k,l;
    cin>>a>>b;
    struct node n[a];
    for(i=0;i<a;i++)
    {

        cin>>n[i].val>>n[i].a;
    }

    sort(n,n+a,comp);

   unsigned long long int sum=0;
  i=0;
    while(i<a)
    {
        if(n[i].a<=b)
        {
            b-=n[i].a;
            sum+=n[i].a*n[i].val;
//            cout<<b<<endl;

            i++;
            //cout<<sum;

        }
        else{

            sum+=b*n[i].val;
            //cout<<b;
            break;
        }
    }
    cout<<sum;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> box(n);
  for(int i = 0; i < n; i++){
    cin >> box.at(i);
  }
  int cnt = 0, j = 0;
  for(int i = 0; i < n; i++){
    cnt++;
    if(box.at(j) == 2){
      break;
    }
    if(cnt == n){
      cout << -1 << endl;
      return 0;
    }
    j = box.at(j)-1;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3768
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = rl().rstrip()
    N = sum(int(ni) for ni in N)
    print('Yes' if N % 9 == 0 else 'No')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 73724
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int N,K;
double ans = 0.0;

double check( int num ) {
  int cnt = 0;
  if ( num >= K ) return 0.0;
  for ( int i = 0; i < 20; i++ ) {
    num *= 2;
    cnt++;
    if ( num >=K ) return cnt*1.0;
  }
}

int main() {
  cin >> N >> K;
  
  for ( int i = 1; i  <= N; i++ ) {
    double num = check(i);
    double n = pow(1.0/2.0, num);
      ans += n;
  }
  ans *= 1/(N*1.0);
  printf("%.12f\n", ans);
  return 0;
}


Measured memory_bytes: 256
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw1 = read_func().strip().split()
    input_raw2 = read_func().strip().split()
    sum_list1 = []
    sum_list2 = []
    for i in range(N):
        if i > 0:
            sum_list1.append(int(input_raw1[i]) + sum_list1[i - 1])
            sum_list2.append(int(input_raw2[i]) + sum_list2[i - 1])
        else:
            sum_list1.append(int(input_raw1[i]))
            sum_list2.append(int(input_raw2[i]))
    max_num = 0
    for i in range(N):
        if i > 0:
            num = sum_list1[i] + sum_list2[N - 1] - sum_list2[i - 1]
        else:
            num = sum_list1[i] + sum_list2[N - 1]
        if num > max_num:
            max_num = num

    print max_num
if __name__ == '__main__':
    main()

Measured memory_bytes: 2696