akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
using static Func;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], D = I[1];
		var l = -1;
		var c = 0;
		while (l + 1 < N)
		{
			l += 2 * D + 1;
			c++;
		}
		WriteLine(c);
	}
}
static class Func
{
	public static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	public static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	public static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; }
	public static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; }
	public static int FirstBinary(int min, int max, Predicate<int> pred)
	{
		while (min < max)
		{
			var mid = (min + max) / 2;
			if (pred(mid)) max = mid;
			else min = mid + 1;
		}
		return min;
	}
	public static long GCD(long a, long b)
	{
		var n = (ulong)Abs(a); var m = (ulong)Abs(b);
		if (n == 0) return (long)m; if (m == 0) return (long)n;
		int zm = 0, zn = 0;
		while ((n & 1) == 0) { n >>= 1; zn++; }
		while ((m & 1) == 0) { m >>= 1; zm++; }
		while (m != n)
		{
			if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; }
			else { n -= m; while ((n & 1) == 0) n >>= 1; }
		}
		return (long)n << Min(zm, zn);
	}
	public static long Mod(long a, long mod) => (a % mod + mod) % mod;
	public static long Inverse(long a, long mod) => Mod(SolveLinear(Mod(a, mod), mod)[0], mod);
	public static long Pow(long a, long b, long mod)
	{
		var p = 1L;
		var x = a;
		while (b > 0)
		{
			if ((b & 1) == 1) p = (p * x) % mod;
			b >>= 1;
			x = (x * x) % mod;
		}
		return p;
	}
	public static long[] SolveLinear(long n, long m)
	{
		var A = new long[,] { { n < 0 ? -1 : 1, 0 }, { 0, m < 0 ? -1 : 1 } };
		n = Abs(n); m = Abs(m);
		while (m > 0)
		{
			long q = n / m, r = n % m;
			n = m; m = r;
			for (var i = 0; i < 2; i++)
			{
				var x = A[i, 1];
				A[i, 1] = A[i, 0] - q * x;
				A[i, 0] = x;
			}
		}
		return new long[] { A[0, 0], A[1, 0] };
	}
	public static int CombineHashCodes(int h1, int h2) => (((h1 << 5) + h1) ^ h2);
}


Measured memory_bytes: 11348
s = input()
a = int(s[0])
k = len(s)
n = int(s)

if k == 1:
    print(n)
    exit()

if (n + 1) % 10**(k-1) == 0:
    print(a + 9*(k-1))
    exit()
else:
    print(a - 1 + 9*(k-1))




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

li = []
ans = 0

for i in range(m):
    lia = list(map(int,input().split()))
    li.append(lia[1:])

lip = list(map(int,input().split()))

switch = []

def onoff(count):
    global ans
    if count == n:
        for i in range(m):
            sum = 0
            for j in li[i]:
                sum += switch[j-1]
            if sum % 2 != lip[i]:
                break
            if i == m-1:
                ans += 1
    else:
        switch.append(0)
        onoff(count+1)
        switch.pop(-1)
        switch.append(1)
        onoff(count+1)
        switch.pop(-1)

onoff(0)

print(ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

const long long MOD = 1000000007;

int main(int argc, char *argv[])
{
	int N, M;
	bool a[100002];

	cin >> N >> M;
	for (int i = 0; i <= N; i++) {
		a[i] = true;
	}
	for (int i = 0; i < M; i++) {
		int b;
		cin >> b;
		a[b] = false;
	}
	long long dp[100002] = {0};
	dp[0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j <= min(N, i + 2); j++) {
			if (a[j]) {
				dp[j] += dp[i];
				dp[j] %= MOD;
			}
		}
	}
	cout << dp[N] << "\n";

	return 0;
}

Measured memory_bytes: 1152
fn main() {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).unwrap();
  let n: u32 = s.trim().parse().unwrap();
  let x = n / 111 + if n % 111 == 0 { 0 } else { 1 };
  println!("{}", 111 * x);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
namespace mint {
  int md = 1e9 + 7;
  inline void add (int &a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    a += b; if (a >= md) a -= md;
  }
  inline void sub (int &a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    a -= b; if (a < 0) a += md;
  }
  inline int sum (int a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    add(a, b); return a;
  }
  inline int dif (int a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    sub(a, b); return a;
  }
  template<class... A>
  inline int prod (A... args) {
    long long ret = 1;
    for (int a :	initializer_list<int>{args...}) {
      assert(0 <= a && a < md);
      ret *= a;
      ret %= md;
    }
    return (int)(ret % md);
  }
  inline void mul (int &a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    a = prod(a, b);
  }
  inline int inv (int a) {
    assert(0 <= a && a < md);
    a %= md;
    if(a < 0) a += md;
    int b = md, u = 0, v = 1;
    while (a) {
      int t = b / a;
      b -= a * t; swap(a, b);
      u -= v * t; swap(u, v);
    }
    assert(b == 1);
    if(u < 0) u += md;
    return u;
  }
  inline int quot (int a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    return prod(a, inv(b));
  }
  inline void div (int& a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    a = quot(a, b);
  }
  inline int pow (int a, long long b) {
    assert(0 <= a && a < md);
    int res = 1;
    for (; b; b >>= 1) {
      if (b & 1) mul(res, a);
      mul(a, a);
    }
    return res;
  }
  namespace factorials {
    int sz;
    vector<int> fact, finv;
    void init (int n) {
      sz = n;
      fact.resize(n); finv.resize(n);
      fact[0] = 1;
      for (int i = 1; i < n; i++) fact[i] = prod(fact[i - 1], i);
      finv[n - 1] = inv(fact[n - 1]);
      for (int i = n - 2; i >= 0; i--) finv[i] = prod(finv[i + 1], i + 1);
    }
  }
  inline int fct (int i) {
    using namespace factorials;
    assert(0 <= i && i < sz);
    return fact[i];
  }
  inline int fnv (int i) {
    using namespace factorials;
    assert(0 <= i && i < sz);
    return finv[i];
  }
  inline int binom (int n, int k) {
    using namespace factorials;
    assert(0 <= n && n < sz);
    if (0 < k || n < k) return 0;
    return prod(fact[n], finv[k], finv[n - k]);
  }
}
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> b[j];
  }
  vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
  for (int i = 0; i <= n; i++) {
    dp[i][0] = 1;
  }
  for (int j = 0; j <= m; j++) {
    dp[0][j] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = mint::sum(
        dp[i - 1][j],
        dp[i][j - 1]
      );
      if (a[i - 1] != b[j - 1]) {
        mint::sub(dp[i][j],
          dp[i - 1][j - 1]
        );
      }
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,c;
    cin  >> n >> m >> c;
    vector<int> b(m);
    for(int i=0; i<m; i++){
        cin >> b[i];
    }
    vector<vector <int> > a(n, vector<int>(m));
    for( int i=0; i<n; i++){
        for( int j=0; j<m; j++){
            cin >> a.at(i).at(j);
        }
    }
    int num;
    int flag;
    num = 0;
    flag = 0;
    for( int i=0; i<n; i++){
        for( int j=0; j<m; j++){
            flag = flag + a[i][j]*b[j];
        }
        flag = flag + c;
        if(flag > 0){
            num++;
            flag = 0;
        }else{
            flag = 0;
        }
    }
    cout << num << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int n, m, total, pricemax, i, j;
  int price[1024];

  while(1){
    scanf("%d %d", &n, &m);
    if( (n == 0)&&(m == 0) ) break;
    for(i = 0; i < n; i++){
      scanf("%d", &price[i]);
    }

    total = 0;
    pricemax = 0;

    for(i = 0; i < n - 1; i++){
      for(j = i+1; j < n; j++){
        total = price[i] + price[j];
        if( (total > pricemax)&&(total <= m) ){
          pricemax = total;
        }
      }
    }
    if(pricemax == 0){
      printf("NONE\n");
    }else{
      printf("%d\n", pricemax);
    }

  }

  return 0;
}





Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef long long lint;

int main(){
    int n; cin >> n;
    lint place[n+1];
    For(i, 1, n+1){
        int a; cin >> a;
        place[a] = i;
    }
    set<lint> s = {0, n+1};
    lint ans = 0;
    For(i, 1, n+1){
        auto itr = s.lower_bound(place[i]);
        ans += i * (*(itr)-place[i]) * (place[i]-*(--itr));
        s.insert(place[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<map>
using namespace std;
typedef pair<int, pair<int, int> >PP;
typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec;
int inf=-1;
ll mod = pow(10, 9) + 7;

int main(){
    int n;cin>>n;
    int k;cin>>k;
    int h[100010];
    int cnt=0;
    for(int i=0;i<n;i++){
        cin>>h[i];
        if (h[i]>=k){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

pair<ll, ll> a[100002];

int main(int, char**)
{
	ll n, m;
	cin >> n >> m;

	ll ans = 0;
	ll x = 0;
	for (int i = 0; i < n; ++i)
			cin >> a[i].first >> a[i].second;

	sort(a, a+n);

	for (int i = 0; i < n; ++i) {
			if ((x + a[i].second) >= m) {
					ans += ((m - x) * a[i].first);
					cout << ans << endl;
					break;
			}

			x += a[i].second;
			ans += (a[i].first * a[i].second);
	}

	return 0;
}


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

struct edge {
    long long to, cost;
};
// firstが最短距離, secondは頂点距離
typedef pair<long long, long long> P;

void dijkstra(long long s, vector<vector<edge>>& G, vector<long long>& d) {
    priority_queue<P, vector<P>, greater<P>> que;
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        long long v = p.second;
        if (d[v] < p.first) continue;
        for (long long i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long INF = 1000000000000007;

    long long N, M, S, T;
    cin >> N >> M >> S >> T;
    vector<vector<edge>> yenG(N);
    vector<long long> yenD(N, INF);
    vector<vector<edge>> sunukuG(N);
    vector<long long> sunukuD(N, INF);
    long long u, v, a, b;
    for (long long i = 0; i < M; i++) {
        cin >> u >> v >> a >> b;
        yenG[u - 1].push_back({v - 1, a});
        yenG[v - 1].push_back({u - 1, a});
        sunukuG[u - 1].push_back({v - 1, b});
        sunukuG[v - 1].push_back({u - 1, b});
    }
    dijkstra(S - 1, yenG, yenD);
    dijkstra(T - 1, sunukuG, sunukuD);
    long long ans = 1000000000000000;
    vector<long long> D(N);
    for (long long i = 0; i < N; i++) {
        D[i] = yenD[i] + sunukuD[i];
    }
    for (long long i = N - 1; i > 0; i--) {
        if (D[i] < D[i - 1]) {
            D[i - 1] = D[i];
        }
    }
    for (auto i : D) {
        cout << ans - i << endl;
    }
}

Measured memory_bytes: 19016
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

int main() 
{
    FAST;
    ll n,d,x,y,co;
    cin>>n>>d;
    d=d*d;
    co=0;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        if((x*x)+(y*y)<=d)
            co++;
    }
    cout<<co;
    subt;
    return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <ctime>
#include <map>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;

int main() {
  int a, b; cin >> a >> b;
  if (a * b % 2 == 0) cout << "No";
  else cout <<"Yes";
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    if (2 * n <= m) {
        ans += n;
        m -= 2 * n;
        ans += (m / 4);
    }
    else {
        ans += (m / 2);
    }
    cout << ans << endl;
}

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

#define fi first
#define se second

typedef long long ll;

using namespace std;

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("file.in" "r", stdin);
    int n;
    cin >> n;
    cout << 360 * n / gcd(360, n) / n;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>

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

int sq[17];
int dp[301][18];

int solve(int rem,int idx){
	int i,res=0;

	if(rem == 0) return 1;
	if(rem < 0) return 0;
	if(dp[rem][idx] != -1) return dp[rem][idx];

	REP(i,idx,17){
		res += solve(rem - sq[i], i);
	}
	return dp[rem][idx] = res;
}

int main(void){
	int i,n;

	REP(i,1,18) sq[i-1] = i * i;
	memset(dp,-1,sizeof(dp));

	while(scanf("%d",&n) && n){
		printf("%d\n",solve(n,0));
	}

	return 0;
}

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

double n, r, x1, y4, x2, y2, x3, y3, xa, ya, xb, yb, xc, yc, ma, mb, mc, y_hasil, x_hasil;

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> x1 >> y4 >> x2 >> y2 >> x3 >> y3;
		ma = (x2-x1)/(y4-y2);
		mb = (x3-x2)/(y2-y3);
		mc = (x3-x1)/(y4-y3);
		xa = (x1+x2)/2;
		ya = (y4+y2)/2;
		xb = (x2+x3)/2;
		yb = (y2+y3)/2;
		xc = (x3+x1)/2;
		yc = (y3+y4)/2;
		
	//	cout << ma << " " << xa << " " << mb << " " << xb << " " << yb << " " << ya << "\n";
		if(y4 - y2 == 0){
			x_hasil = (x2 + x1) / 2;
			y_hasil = mb*(x_hasil - xb) + yb;
		}else if(y2 - y3 == 0){
			x_hasil = (x2 + x3) / 2;
			y_hasil = ma*(x_hasil - xa) + ya;
		}else{
			x_hasil = (ma*xa - mb*xb + yb - ya)/(ma - mb);
			y_hasil = ma*(x_hasil - xa) + ya;
		}
		
		r = sqrt((x_hasil - x1)*(x_hasil - x1) + (y_hasil - y4)*(y_hasil - y4));
		
		cout << fixed << setprecision(3) << x_hasil << " " << y_hasil << " " << r << "\n";
	}
	return 0;
}

Measured memory_bytes: 3184
def div_cnt(input_n):
    cnt = 0
    while input_n % 2 == 0:
        input_n /= 2
        cnt += 1

    return cnt

input_n = int(input())
input_a = list(map(int,input().split()))
cnt = min(map(div_cnt,input_a))

print(cnt)

Measured memory_bytes: 2940
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();
        int n = 0;
        for(int i = 0 ; i < s.length() - 1 ; i++ ){
            if(s.charAt(i) != s.charAt(i + 1)){
                n++;
            }
        }
        System.out.println(n);
    }
}

Measured memory_bytes: 39004
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>

#include<cassert>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

string S;
int cur = 0;//?§£???????§???????

int expression();//????????£?¨?

int digit(){
	// assert(isdigit(S[cur]));
	// cout<<"S[cur]="<<S[cur]<<endl;;
	int n = S[cur++] - '0';
	return n;
}

int number(){
	int n = digit();
	while(cur<S.size() && isdigit(S[cur]))n = n*10+digit();
	return n;
}

int factor(){
	if(S[cur]!='(')return number();
	cur++;
	int n=expression();
	// assert(S[cur++]==')');
	cur++;
	return n;
}

int term(){
	int a = factor();
	while(cur<S.size() && (S[cur]=='*' || S[cur]=='/')){
		char op = S[cur++];
		int b = factor();
		if(op=='*')a*=b;else a/=b;
	}
	return a;
}

int expression() {
	int a = term();
	while (cur<S.size() && (S[cur] == '+' || S[cur] == '-')) { // ?¶???????????????????????¶???????
		char op = S[cur++];
		int b = term();
		if (op == '+')a+=b;else a-=b;
	}
	return a;
}

int main(){
	int N;
	int ans[50];
	cin>>N;
	rep(i,N){
		cur=0;
		cin>>S;
		S.resize(S.size()-1);
		ans[i]=expression();
	}
	rep(i,N)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define VREP(it, v) for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;

template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename K, typename V>
using pbds_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
ll n, k, p[5005], c[5005];
ll dp[5005];
ll dp2[5005];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	REP(i, 0, n){
		cin >> p[i];
		p[i]--;
	}
	ll ans = -1000000001;
	REP(i, 0, n){
		cin >> c[i];
		//ans = max(ans, c[i]);
	}
	
	REP(i, 0, n){
		//starting point is i
		ll cur = i;
		ll tot = 0;
		ll period = 0;
		while (true){
			period++;
			tot += c[p[cur]];
			dp[period] = max(dp[period - 1], tot);
			if (period == 1){
				dp2[period] = tot;
			} else {
				dp2[period] = max(dp2[period - 1], tot);
			}
			cur = p[cur];
			if (cur == i) break;
		}
		
		if (tot >= 0 && k >= period){
			if ((k/period) > 1){
				ans = max(ans, ((k/period) - 1)*tot + dp[period]);
			}
			ans = max(ans, (k/period)*tot + dp[k%period]);
		}
		
		if (tot < 0 && k >= period){
			//if (dp[period] == 0) continue;
			ans = max(ans, dp2[period]);
		}
		
		if (k < period){
			//if (dp[k] == 0) continue;
			ans = max(ans, dp2[k]);
		}
	}
	cout << ans << endl;
}

//cout.flush()
//cout << fixed << setprecision(9) << x << endl;

Measured memory_bytes: 3812
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		while (true) {
			int chukan = sc.nextInt(); int kimatsu = sc.nextInt(); int saishi = sc.nextInt();
			if (chukan==-1 && kimatsu==-1 && saishi==-1) return;
			
			String ans = "";
			int sum = chukan + kimatsu;
			if (chukan==-1 || kimatsu==-1) ans = "F";
			else if (sum >= 80) ans = "A";
			else if (65<=sum && sum<80) ans = "B";
			else if (50<=sum && sum<65) ans = "C";
			else if (30<=sum && sum<50) {
				if (50 <= saishi) ans = "C";
				else ans = "D";
			}
			else ans = "F";
			
			System.out.println(ans);
		}
		
	}
}


Measured memory_bytes: 26412
#include<iostream>
#include<algorithm>
 
using namespace std;
typedef long long Int;
#define INF (1LL<<60)

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	
	Int N,M;
	cin >> N >> M;

	// ((N-M)*100 + M*1900) * pow(2,M)
	Int tmp = 1;
	for(int i=0;i<M;i++) tmp = tmp*2;
	Int ans = ((N-M)*100 + M*1900) * tmp;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
def count_children(cr, cl):
    # supposed that number of move times is large and even(ex. 10**100).
    return (cr - cr // 2 + cl // 2), (cr // 2 + cl - cl // 2)


def main():
    S = input()
    # children move around `RL` patterns
    rl_index = -1
    rl_patterns = list()
    r_seq_cnt = 0
    l_seq_cnt = 0
    before_c = S[0]
    for i, c in enumerate(S):
        if (before_c, c) == ('R', 'R'):
            r_seq_cnt += 1
        elif (before_c, c) == ('L', 'L'):
            l_seq_cnt += 1
        elif (before_c, c) == ('R', 'L'):
            rl_index = i
            l_seq_cnt = 1
        else:
            rl_patterns.append((rl_index, r_seq_cnt, l_seq_cnt))
            r_seq_cnt = 1
        before_c = c
    rl_patterns.append((rl_index, r_seq_cnt, l_seq_cnt))
    counts = [0 for _ in range(len(S))]
    for rl_pattern in rl_patterns:
        rl_index, r_seq_cnt, l_seq_cnt = rl_pattern
        left_num, right_num = count_children(r_seq_cnt, l_seq_cnt)
        counts[rl_index - 1] += left_num
        counts[rl_index] += right_num
    print(' '.join(map(str, counts)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 15996
n = int(input())
da = list(map(int,input().split()))
m = int(input())
daa = [list(map(int,input().split())) for i in range(m)]
ans = 0
for i in da:ans += i
for i in range(m):
    print(ans + daa[i][1] - da[daa[i][0]-1])

Measured memory_bytes: 3064
N = int(input())

ans = 0
for i in range(2, N):
    if i * i > N:
        break
    e = 0
    while N % i == 0:
        e += 1
        N //= i
    if e > 0:
        for j in range(1, 10):
            if e >= j:
                e -= j
                ans += 1
            else:
                break
if N > 1:
    ans += 1

print(ans)


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


int main() {
  int a[5];
  cin >>a[0];
  cin >>a[1];
  cin >>a[2];
  cin >>a[3];
  cin >>a[4];
  int answer = 0;
  int k,amari;
  amari =10;
  for(int i = 0;i !=5;i++){
    k = a[i]/10;
    if(k*10 == a[i]){
      answer += (k*10);
    }else{
      answer += ((k+1)*10);
      if(amari > a[i]-k*10){
        amari = a[i]-k*10;
      }
    }
  }
  cout << answer-10+amari;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func min(nums ...int) int {
	m := 1<<63-1
	for _, n := range nums {
		if n < m {
			m = n
		}
	}
	return m
}

func main() {
	sc.Split(bufio.ScanWords)

	n, a, b, c, d, e := nextInt(), nextInt(), nextInt(), nextInt(), nextInt(), nextInt()
	ans := 0

	m := min(a, b, c, d, e)
	ans += n/m
	if n % m != 0 {
		ans++
	}
	ans += 4

	fmt.Println(ans)
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 205
#define MAX_P 1005
struct edge{ int to,cost,v; };
  
int N,M,P;
  
double dp[MAX_P][MAX_N];
vector<edge> G[MAX_N];
  
int main(){
  
  cin>>N>>M>>P;
  for(int i=0;i<M;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a--,b--;
    G[a].push_back((edge){b,c,d});
    G[b].push_back((edge){a,c,d});
  }
  for(int i=0;i<MAX_P;i++)
    for(int j=0;j<MAX_N;j++)
      dp[i][j]=-1e9;
  
  dp[0][0]=0;
  for(int i=0;i<P;i++){
    for(int j=0;j<N;j++){
      if(dp[i][j]==-1e9)continue;
      for(int k=0;k<(int)G[j].size();k++){
        edge e=G[j][k];
        dp[i+1][j]=max(dp[i+1][j],dp[i][j]+(double)e.v/(double)e.cost);
        if(i+e.cost<=P)
          dp[i+e.cost][e.to]=max(dp[i+e.cost][e.to],dp[i][j]+e.v);
      }
    }
  }
  
  printf("%.10f\n",dp[P][0]);
  return 0;
}

Measured memory_bytes: 5440
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

const int MOD = 1e9 + 7;
int D[4040][4040];

void solve(){
	int n, m; scanf("%d%d", &n, &m);
	char S[2][3030];
	scanf("%s", S[0]+1);
	for(int i=1;i<=n;i++)S[1][i] = S[0][i];
	rep(i, m){
		int x, y; scanf("%d%d", &x, &y);
		sort(S[0]+x, S[0]+y+1);
		sort(S[1]+x, S[1]+y+1, [](int x,int y){return x > y;});
	}
	int s[2][4040] = {};
	rep(u, 2)for(int i=1;i<=n;i++)s[u][i] = s[u][i-1] + (S[u][i] == '1');
	D[0][0] = 1;
	for(int i=1;i<=n;i++){
		for(int j=s[0][i];j<=s[1][i];j++)D[i][j] = ((j?D[i-1][j-1]:0) + D[i-1][j]) % MOD;
	}
	printf("%d", D[n][s[0][n]]);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 12544
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

class JOI{
public:
    int j,o,i;
    
    JOI():j(0),o(0),i(0){}
    JOI(int a,int b,int c):j(a),o(b),i(c){};
    
};

vector<string> data;

vector<vector<JOI>> dp(1001,vector<JOI>(1001));
int m,n;

void makeDP(){
    rep(i,m){
        rep(j,n){
            JOI ad(0,0,0);
            if(data[i][j]=='J')ad.j++;
            if(data[i][j]=='O')ad.o++;
            if(data[i][j]=='I')ad.i++;

            JOI cent,right,under;
            if(i-1>=0&&j-1>=0)cent = dp[i-1][j-1];
            if(i-1>=0)right = dp[i-1][j];
            if(j-1>=0)under = dp[i][j-1];
            
            dp[i][j].j = right.j + under.j - cent.j + ad.j;
            dp[i][j].o = right.o + under.o - cent.o + ad.o;
            dp[i][j].i = right.i + under.i - cent.i + ad.i;
        }
    }
}


int main(){
    cin>>m>>n;
    int q;
    cin>>q;
    data.resize(n);
    rep(i,m) cin>>data[i];

    makeDP();
    
    
    rep(i,q){
        int y1,x1,y2,x2;
        cin>>y1>>x1>>y2>>x2;
        x1--,y1--,x2--,y2--;
        JOI a,b,c;
        if(y1-1>=0)a = dp[y1-1][x2];
        if(x1-1>=0)b = dp[y2][x1-1];
        if(y1-1>=0&&x1-1>=0)c=dp[y1-1][x1-1];
//        cout<<dp[y2][x2].j<<" "<<a.j<<" "<<b.j<<" "<<c.j<<endl;

        int x = dp[y2][x2].j - a.j - b.j +c.j;
        int y = dp[y2][x2].o - a.o - b.o +c.o;
        int z = dp[y2][x2].i - a.i - b.i +c.i;
        cout<<x<<" "<<y<<" "<<z<<endl;
    }
}

Measured memory_bytes: 15816
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

ll countUp(vector<int> s1, vector<int> s2, vector<int> s3)
{
    ll c = 0;
    for (auto itr = s1.begin(); itr != s1.end(); ++itr) {
        int idx1 = (*itr);
        for (auto itr2 = upper_bound(s2.begin(), s2.end(), idx1); itr2 != s2.end(); ++itr2) {
            int idx2 = (*itr2);
            int d = idx2 - idx1;
            auto itr3 = upper_bound(s3.begin(), s3.end(), idx2);
            int n = distance(itr3, s3.end());
            if (binary_search(s3.begin(), s3.end(), idx2 + d)) n--;
            c += n;
        }
    }
    return c;
}


int main(int argc, char **argv)
{
    int N;
    string S;
    cin >> N >> S;

    vector<int> rs, gs, bs;
    REP(i, N) {
        if (S[i] == 'R') rs.push_back(i);
        else if (S[i] == 'G') gs.push_back(i);
        else bs.push_back(i);
    }

    ll c = 0;
    c += countUp(rs, gs, bs);
    c += countUp(rs, bs, gs);
    c += countUp(gs, rs, bs);
    c += countUp(gs, bs, rs);
    c += countUp(bs, rs, gs);
    c += countUp(bs, gs, rs);

    cout << c << endl;

    return 0;
}


Measured memory_bytes: 3676
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#include <map>
#include <vector>
#include <algorithm>
#include <functional>

#include <sstream>
#include <iostream>

using namespace std;
typedef long long llint;
const llint inf = 1000000000000000000LL;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

const int MAXN = 2005;

enum { FIRST, SECOND };

int N;
vector<int> a;

int memo[MAXN][MAXN][2];

int solve(int i, int j, int turn) {
  int nxt = max(i, j) + 1;
  if (nxt == N) return abs(a[i] - a[j]);

  int &sol = memo[i][j][turn];
  if (sol >= 0) return sol;

  if (turn == FIRST)
    sol = max(solve(nxt, j, FIRST),
	      solve(i, nxt, SECOND));
  else
    sol = min(solve(i, nxt, SECOND),
	      solve(nxt, j, FIRST));

  return sol;
}

int main(void) 
{
  int Z, W;

  cin >> N >> Z >> W;
  a.resize(N);
  REP(i, N) cin >> a[i];

  a.insert(a.begin(), W);
  a.insert(a.begin(), Z);

  N += 2;

  memset(memo, -1, sizeof memo);
  printf("%d\n", solve(2, 1, FIRST));
  
  return 0;
}




Measured memory_bytes: 31872
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

ll ceil1(ll a,ll b)
{	if(a%b==0)
		return a/b;
	else
		return a/b+1;}


void solve()
{
	int n,m,w1,w2,cnt=0;
	cin>>n>>m;
	string arr1[n],arr2[m];
	for(int i=0;i<n;i++)
		cin>>arr1[i];
	for(int i=0;i<m;i++)
		cin>>arr2[i];
	w1=arr1[0].size();
	w2=arr2[0].size();
	for(int j=0;j+m<=n;j++)				
		for(int i=0;i+w2<=w1;i++)		
			{
				cnt=0;
				for(int k=0;k<m;k++)
					for(int l=0;l<w2;l++)
						if(arr1[j+k][i+l]==arr2[k][l])
							cnt++;
				if(cnt==m*w2)
				{
					cout<<"Yes";
					return;
				}
			}
	cout<<"No";
	return;
}

int main()
{
	fast;
	ll q=1;
	// cin>>q;
	while(q--)
		solve();
	return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back 
using namespace std;
int gcd(int a, int b){
	return b == 0 ? a : gcd(b, a % b);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int k;
	cin >> k;
	ll ans = 0;
	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= k; j++){
			for(int p = 1; p <= k; p++){
				ans += gcd(gcd(i, j), p);
			}
		}
	}
	cout << ans << '\n';


}

Measured memory_bytes: 3652
import math
import functools

def find_divisor(n):
    sqrt = math.ceil(math.sqrt(n))
    divisors = {}
    target = n
    for i in range(2, sqrt):
        while target % i == 0:
            target = target // i
            if i in divisors:
                divisors[i] += 1
            else:
                divisors[i] = 1
    return divisors


N = int(input())
counter = 0

for i in range(1, N + 1):
    if i % 2 == 0:
        continue
    divisors = find_divisor(i)
    values = divisors.values()
    if divisors and functools.reduce((lambda x, y: x * y), map(lambda x: x + 1, values)) == 8:
            counter += 1

print(counter)


Measured memory_bytes: 3688
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <queue>
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    string s;
    cin>>s;
    if(s.size()==2){
        cout<<s<<endl;
    }else{
        cout<<s[2]<<s[1]<<s[0]<<endl;
    }
}

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

using namespace std;


int main() {
      
   string a;
   string b;
   cin>>a>>b;
   if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0])
      printf("YES");
      
   else
     printf("NO");
       
     
	return 0;
}

Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>

#define for0(i,n) for(int i = 0;i < (n);i++)
#define for1(i,n) for(int i = 1;i<=(n);i++)
#define for2(i,n) for(ll i = 2;i<=(n);i++)
#define rep(i,st,en,cnt) for(ll i = st;i <= en;i+=cnt)
#define PB push_back
#define MP make_pair
#define fastio cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define bit(x,n) (x & (1<<(n)))
#define EPS 1e-8
#define INF 0x3f3f3f3f3
#define NEGINF -INF
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define inp_arr(a,n) for0(i,n) {cin>>a[i];}
#define out_arr(a,n) for0(i,n) {cout<<a[i]<<" ";}

using namespace std;

typedef pair<int,int> ii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<ll> > vvl;
typedef vector<pair<long long, long long> > vll;

ii DR8[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
ii DR4[] = {{-1,0},{0,-1},{0,1},{1,0}};

const ll mod = 998244353;
/*
ll nop = 100;
vi primes(nop+1,1);

void sieve(){
    primes[1] = primes[0] = 0;
    for(ll i = 2;i * i <= nop;i++){
        if(primes[i]){
            for(ll j = i*i; j <= nop;j+=i){
                primes[j] = 0;
            }
        }
    }
}

ll gcd(ll a,ll b){    //a larger, b smaller
    if(b>a) swap(b,a);
    if(b==0) return a;
    return gcd(b,a%b);
}

void extgcd(ll a,ll b,ll& x,ll& y){  //a smaller b larger
    if(a==0) {
        x = a;y = b;
        return;
    }
    extgcd(b%a,a,x,y);
    ll y1 = y,x1 = x;
    x = y1 - (b/a)*x1;
    y = x1;
}

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

ll bexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans *= num;
        }
        num *= num;
        e>>= 1;
    }
    return ans;
}
*/
ll mexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans = (ans*num)%mod;
        }
        num = (num*num)%mod;
        e>>=1;
    }
    return ans%mod;
}

ll modinv(ll a){
    return mexp(a,mod-2);
}

void solve() {
    ll n,s;
    cin>>n>>s;
    vl a(n);
    inp_arr(a,n);
    vvl dp(n+1,vl(s+1,0)),dp2(n+1,vl(s+1,0));
    dp[0][0] = mexp(2LL,n);
    for0(i,n) {
        for0(j,s+1) {
            if(j+a[i] <= s) {
                dp[i+1][j+a[i]] = (dp[i+1][j+a[i]] + (dp[i][j]*modinv(2))%mod)%mod;

            }
            dp[i+1][j] = (dp[i+1][j] + dp[i][j])%mod;
        }
    }
    cout<<dp[n][s]<<endl;
}

int main() {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t = 1;
    //cin>>t;
    for1(T,t){
        //cout<<"Case #"<<T<<": ";
        solve();
    }
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif */
    return 0;
}


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

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

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

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

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

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

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

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

fn main() {
    input!{
        x: usize,
        y: usize,
    }
    println!("{}", x + y / 2);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
int main(void)
{
   long long n;
   cin >> n;

    long long t = 1;
   for (long long i = 1; i <= n; i++) {
       if (i * i == n) {
           t = i * i;
           break;
       }
       if (i * i > n) {
           break;
       }
       t = i * i;
   }

   cout << t << endl;


    return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

int fac[100001];

int pw(int a, int b) {
	if(!b) return 1;
	if(b & 1) return (1LL * a * pw(a, b - 1)) % mod;
	int x = pw(a, b / 2);
	return (1LL * x * x) % mod;
}

int cnk(int n, int k) {
	if(n < 0 || k < 0 || n < k) return 0;
	int a = fac[n];
	int b = (1LL * fac[k] * fac[n - k]) % mod;
	return (1LL * a * pw(b, mod - 2)) % mod;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	fac[0] = 1;
	for(int i = 1; i <= 100000; i++)
		fac[i] = (1LL * fac[i - 1] * i) % mod;
	int n;
	cin >> n;
	int a[n + 1];
	vector<bool> is(n + 1, false);
	int rep;
	for(int i = 0; i < n + 1; i++) {
		cin >> a[i];
		if(is[a[i]])
			rep = a[i];
		is[a[i]] = true;
	}
	int xy = -1;
	for(int i = 0; i < n + 1; i++)
		if(a[i] == rep)
			if(xy == -1) xy = i;
			else xy += n - i;
	for(int i = 1; i < n + 2; i++)
		cout << (0LL + cnk(n - 1, i) + cnk(n - 1, i - 2) + 2 * cnk(n - 1, i - 1) + mod - cnk(xy, i - 1)) % mod << '\n';
}

Measured memory_bytes: 2048
// マニ

#include<bits/stdc++.h>
#define ll            long long 
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define rrep(i,a,b) for(ll int i=a;i>=b;i--)
#define all(a)      (a).begin(),(a).end()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define PI 3.14159265358979323846
#define tr(i, cont) for(auto i=cont.begin();i!=cont.end();i++)
#define ios            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define trace(x)                 cerr << #x << ": " << x << "\n";
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << "\n";
#define ar array
#define endl "\n"
using namespace std;

int main(){
    ios;
    ll n,m,k;
    cin>>n>>m>>k;
    vi a(n+1,0),b(m+1,0);
    rep(i,1,n+1){
        cin>>a[i];
        a[i]+=a[i-1];
    }
    rep(i,1,m+1){
        cin>>b[i];
        b[i]+=b[i-1];
    }
    ll i=n,j=0;
    ll ans=0;
    while(1){
        while(j+1<=m && a[i]+b[j+1]<=k){
            j++;
        }
        if(a[i]+b[j]<=k)
            ans=max(ans,i+j);
        i--;
        if(i==-1) break;
        // trace2(i,j);
    }
    cout<<ans;
}


Measured memory_bytes: 6336
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
bool Edge[100][100];
void Calc(){
	int N = rei();
	int K = rei();
	if(K > (N-1)*(N-2)/2){
		cout << -1 << endl;
		return;
	}
	int c = N*(N-1)/2;
	for(int i=1;i<N;i++){
		for(int j=1;j<i;j++){
			if(i != j){
				if(K > 0){
					Edge[i][j] = true;
					c--;
					K--;
				}
			}
		}
	}
	cout << c << "\n";
	for(int i=0;i<N;i++){
		for(int j=0;j<i;j++){
			if(!Edge[i][j]){
				cout << i+1 << " " << j+1 << "\n";
			}
		}
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
//#include "/Users/HIMANSHU PANDEY/Desktop/coding/stdc++.h"
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define ins insert
#define sb substr
#define con continue
#define ub upper_bound
#define lb lower_bound
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define pll pair<ll,ll>
#define pld pair<ld,ld>
using namespace std;
 
ll power(ll x, ll y);
ll mpower(ll x, ll y, ll p);
ll modInv(ll a, ll m);
ll gcdExtended(ll a, ll b, ll *x, ll *y);
bool isPrime(ll n);
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,i,j,k,l,h,p,q,r,x,y,z,a,b,c,d,f,n,m,M=1000000007;
    char ch,ch2,ch3;
    string s,s1,s2,s3;
     t=1;
    //cin>>t;
    while(t--)
    {
        vector<ll> v,w;
        unordered_map<ll,ll> N;
        set<ll> S,SS;
        z=0;
		cin>>n;
	    for(i=1;i<=n;i++)
	    {
	        for(j=1;j<=n;j++)
	        {
	            if(i*j>=n)
	            {
	                break;
	            }
	            else
	            {
	                z++;
	            }
	        }
	    }
	    cout<<z;
    }
    return 0;
}
 
ll modInv(ll a, ll m)
{
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    ll res = (x%m + m) % m;
    return res;
}
 
ll gcdExtended(ll a, ll b, ll *x, ll *y){
    if (a == 0){
        *x = 0, *y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;
    return gcd;
}
 
ll mpower(ll x, ll y, ll p){
    ll res = 1;
    x = x % p;
    while(y > 0){
        if(y & 1) res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
 
ll power(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}
 
bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    ll p=sqrt(n);
    for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
  int n, m;
  string key;
  vector<string> vec_keys;
  bool isOpend = true;
  
  cin >> n;
  cin.ignore();
  while (n--) {
    cin >> key;
    cin.ignore();
    vec_keys.push_back(key);
  }

  cin >> m;
  cin.ignore();
  while (m--) {
    cin >> key;
    cin.ignore();
    auto itr = find(vec_keys.begin(), vec_keys.end(), key);
    if (itr != vec_keys.end()) {
      isOpend ? cout << "Opened by " << key << endl :
        cout << "Closed by " << key << endl;
      isOpend ^= 0x01;
    } else {
      cout << "Unknown " << key << endl;
    }
  }
}



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

int main() {
  int n,l;
  cin >> n >> l;
  vector<int> t(n);
  for (int i = 0;i < n;i++){
    t[i] = l + i;
  }
  int e = t[0];
  
  for (int i = 1;i < n;i++){
    if (abs(e) >= abs(t[i])){
      e = t[i];
    }
  }
  int ans = 0;
  for (int i = 0;i < n;i++){
     ans += t[i];
  }
  
  cout << ans - e << endl;
}

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

int main(){
    int n;
    cin>>n;
    vector<int>a(n+1);
    rep(i,n)cin>>a[i+1];
    map<int,int>mp;
    ll ans=0;
    for(int i=2; i<=n; ++i){
        mp[a[i-1]+i-1]++;
        ans+=mp[i-a[i]];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 21160
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<class Val>
map<Val, int> factorize(Val n){
    map<Val, int> res;
    for(Val i=2; (long long)i*i<=n; ++i){
        while(n%i==0){
            n /= i;
            ++res[i];
        }
    }
    if(n!=1) ++res[n];
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    while(cin >> N) {
        map<int, int> a;
        for(int i = 2; i <= N; ++i) {
            auto f = factorize(i);
            each(p, f) {
                a[p.first] += p.second;
            }
        }
        ll ans = 1;
        each(p, a) {
            ans = ans*(p.second + 1) % ((ll)1e9 + 7);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 764