akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n, m;
	cin >> n >> m;
	int x = 1900 * m + 100 * (n - m);
	cout << x*pow(2, m) << en;


	return 0;
}



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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> d(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int temp;
            cin >> temp;
            d[i][j] = abs(a[i][j] - temp);
        }
    }
    int m = (h + w) * 80 + 2;
    vector<vector<vector<bool>>> dp(
        h, vector<vector<bool>>(w, vector<bool>(m, false)));
    dp[0][0][d[0][0]] = true;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 0; k < m; k++) {
                if (i + 1 < h) {
                    int diff_down = d[i + 1][j];
                    dp[i + 1][j][abs(k + diff_down)] =
                        dp[i + 1][j][abs(k + diff_down)] || dp[i][j][k];
                    dp[i + 1][j][abs(k - diff_down)] =
                        dp[i + 1][j][abs(k - diff_down)] || dp[i][j][k];
                }
                if (j + 1 < w) {
                    int diff_right = d[i][j + 1];
                    dp[i][j + 1][abs(k + diff_right)] =
                        dp[i][j + 1][abs(k + diff_right)] || dp[i][j][k];
                    dp[i][j + 1][abs(k - diff_right)] =
                        dp[i][j + 1][abs(k - diff_right)] || dp[i][j][k];
                }
            }
        }
    }
    for (int i = 0; i < m; i++) {
        if (dp[h - 1][w - 1][i]) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int mod = (int) 1e9 + 7;
const int N = 5e5 + 5;

ll n, m;

// mod inverse for first n elements O(1)
ll f[N], inv[N], finv[N];

void init() {
	f[0] = f[1] = inv[0] = inv[1] = finv[0] = finv[1] = 1;
	for (int i = 2; i < N; i++) {
		f[i] = (f[i - 1] * i) % mod;
		inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
		finv[i] = (finv[i - 1] * inv[i]) % mod;
	}
}

ll nCr(ll n, ll r) { // nCr for first n elements O(1)
	return (f[n] * ((finv[r] * finv[n - r]) % mod)) % mod;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	init();
	cin >> n >> m;
	ll res = nCr(m, n) * f[n] % mod;
	res = res * res % mod;
	for (int i = 1; i <= n; i++) {
		ll eq = nCr(n, i) * nCr(m, i) % mod * f[i] % mod;
		ll rem = nCr(m - i, n - i) * f[n - i] % mod;
		ll cur = eq * rem % mod * rem % mod;
		if (i & 1) {
			res -= cur;
		} else {
			res += cur;
		}
		res = (res + mod) % mod;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 15276
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/


ll dp[2003][2003];
ll memo[2003];

int main(){
    ll n,k; cin >> n >> k;


    dp[0][0] = 1;
    memo[0] = dp[0][0];
    for(int i=1;i<=n;i++){
        memo[i] = memo[i-1];
    }
    for(int i=0;i<n;i++){
        memo[0] = dp[i][0];
        for(int j=1;j<=n;j++){
            memo[j] = memo[j-1]+dp[i][j];
        }
        for(int j=0;j<=n;j++){
            if(j-1>=0){
                dp[i+1][j] += memo[j-1];
                dp[i+1][j] %= mod;
            }else{
                dp[i+1][j] = 0;
            }
        }
    }

    for(int i=1;i<=k;i++){
        ll ans = 1;
        ans *= dp[i][k];
        ll tmp = 0;
        for(int j=i-1;j<=n-k;j++){
            ll p = n-k-j+1;
            tmp += (dp[i-1][j] * p)%mod;
            tmp %= mod;
        }
        ans *= tmp;
        ans %= mod;
        cout << ans << endl;
    }
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int dsu[100005];

int dfind(int u) { return dsu[u] < 0 ? u : dsu[u] = dfind(dsu[u]); }
void dmerge(int u, int v) {
	u = dfind(u), v = dfind(v);
	if (u == v) return;
	dsu[u] += dsu[v];
	dsu[v] = u;
}

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

	int n, m; read(n, m);

	rep(i, 0, 100005) dsu[i] = -1;
	rep(i, 0, m) {
		int x, y, z; read(x, y, z);
		dmerge(x, y);
	}
	int ans = 0;
	rep(i, 1, n + 1) if (dfind(i) == i) ans++;
	die(ans);
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

const int BLOCK = 100000;

struct Path
{
	int x, y, cost;
	Path(int _x, int _y, int _cost)
	{
		x = _x; y = _y; cost = _cost;
	}
};

void solve()
{
	int h, w;
	cin >> h >> w;

	int ans = 0;

	vector< vector<int> > initial_maze( h, vector<int>(w, -1) );

	string s;
	for(int i = 0; i < h; ++i)
	{
		cin >> s;
		for(int j = 0; j < w; ++j)
		{
			initial_maze[i][j] = ((s[j] == '.') ? -1 : BLOCK);
		}
	}

	for(int i = 0; i < w; ++i)
	{
		for(int j = 0; j < h; ++j)
		{
			if (initial_maze[j][i] == BLOCK)
			{
				continue;
			}
			vector< vector<int> > maze( initial_maze );

			queue<Path> que;
			Path p(i, j, 0);
			maze[j][i] = max(0, maze[j][i]);
			que.push(p);

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

			while(!que.empty())
			{
				Path now = que.front();
				que.pop();

				for(int k = 0; k < 4; ++k)
				{
					int next_x = now.x + dx[k];
					int next_y = now.y + dy[k];
					if (next_x < 0 || w <= next_x || next_y < 0 || h <= next_y)
					{
						continue;
					}

					if (maze[next_y][next_x] == -1)
					{
						Path next(next_x, next_y, now.cost + 1);
						maze[next.y][next.x] = next.cost;
						que.push(next);
					}
					// cout << "come " << next.x << ", " << next.y << " " << next.cost << endl;
				}
			}

			for(int y = 0; y < h; ++y)
			{
				for(int x = 0; x < w; ++x)
				{
					if (maze[y][x] != BLOCK)
					{
						ans = max(ans, maze[y][x]);
					}
				}
			}
		}
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int K = scanner.nextInt();
    Queue<Long> queue = new LinkedList<>();
    for (long i = 1; i <= 9; i++) queue.add(i);
    long num = 1;
    for (int i = 0; i < K; i++) {
      num = queue.remove();
      long next = num * 10 + num % 10;
      if (next % 10 != 0) queue.add(next - 1);
      queue.add(next);
      if (next % 10 != 9) queue.add(next + 1);
    }
    System.out.println(num);
  }
}


Measured memory_bytes: 36180
import copy
n = int(input())

lis = []

for i in range(1,n+1):
    a, b = input().split()
    lis.append([a,int(b)*-1,i])

nlis = copy.deepcopy(lis)
nlis = sorted(lis)

for i in range(n):
    print(nlis[i][2])
    

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

typedef long long ll;

int gcd(int a,int b)
{
    if(a==0) return b;
    if(b==0) return a;
    if(a>b) return gcd(a%b,b);
    return gcd(b%a,a);
}

int isprime(int a)
{
    if(a==2) return 1;
    if(a%2==0)
    {
        return 0;
    }
    for(int i=3;i*i<=a;i+=2)
        if(a%i==0) return 0;
    return 1;
}
int main()
{
    vector < int > prime;
    for(int i=11;prime.size()<=55;i+=10)
        if(isprime(i))
    {
        prime.push_back(i);
    }
    int n;
    scanf(" %d",&n);
    cout<<prime[0];
    for(int i=1;i<n;i++)
        cout<<" "<<prime[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

pi = 0
qi = 0
ri = 0
ans = 0

for _ in range(X + Y):
    p = P[pi] if pi < X else 0
    q = Q[qi] if qi < Y else 0
    r = R[ri] if ri < C else 0

    if p > q:
        if p >= r:
            ans += p
            pi += 1
        else:
            ans += r
            ri += 1
    else:
        if q >= r:
            ans += q
            qi += 1
        else:
            ans += r
            ri += 1

print(ans)


Measured memory_bytes: 23328
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;

const int maxn = 1e5 + 3;
int wa[maxn], n, m, acnum;
bool ac[maxn];

int main() {
  //freopen("input.txt", "r", stdin);
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) {
      wa[i] = 0;
      ac[i] = false;
    }
    acnum = 0;
    int p;
    char st[5];
    memset(st, 0, sizeof(st));
    while (m--) {
      scanf("%d%s", &p, st);
      if (!strcmp(st, "WA"))
        if (!ac[p]) ++wa[p];
      if (!strcmp(st, "AC")) {
        if (!ac[p]) ++acnum;
        ac[p] = true;
      }
      memset(st, 0, sizeof(st));
    }
    if (!acnum) printf("0 0\n");
    else {
      int pe = 0;
      for (int i = 1; i <= n; i++)
        if (ac[i]) pe += wa[i];
      printf("%d %d\n", acnum, pe);
    }
  }
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){
  float x,y;
  
  while(scanf("%f%f",&x,&y)!=EOF){   
    if(x<35.5&&y<71)
      puts("AAA");
    else if(x<37.5&&y<77)
      puts("AA");
    else if(x<40&&y<83)
      puts("A");
    else if(x<43&&y<89)
      puts("B");
    else if(x<50&&y<105)
      puts("C");
    else if(x<55&&y<116)
      puts("D");
    else if(x<70&&y<148)
      puts("E");
    else
      puts("NA");
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin>>N;
double x;
string u;
double ans=0;
rep(i,N){
    cin>>x>>u;
    if(u=="BTC"){
        ans+=x*380000;
    }
    else{
        ans+=x;
    }
}

cout<<fixed<<setprecision(10)<<ans<<endl;

//system("pause");
return 0;
}

Measured memory_bytes: 256
# Reference: https://qiita.com/dn6049949/items/afa12d5d079f518de368
# self.data: 1-indexed
#    __1__
#  _2_   _3_
# 4   5 6   7
# f(f(a, b), c) == f(a, f(b, c))

class SegmentTree:
    # a = [default] * n
    def __init__(self, n, f=max, default=-10**18):
        self.num_leaf = 1
        while self.num_leaf < n:
            self.num_leaf *= 2
        self.data = [default] * (2*self.num_leaf)
        self.f = f

    # a[i] = x
    def update(self, i, x):
        i += self.num_leaf
        self.data[i] = x
        i >>= 1
        while i > 0:
            self.data[i] = self.f(self.data[2*i], self.data[2*i+1])
            i >>= 1

    # return f(a[l:r])
    def query(self, l, r):
        l += self.num_leaf
        r += self.num_leaf - 1
        lres, rres = self.data[0], self.data[0] # self.data[0] == default
        while l < r:
            if l & 1: # l % 2 == 1
                lres = self.f(lres, self.data[l])
                l += 1
            if not r & 1: # r % 2 == 0
                rres = self.f(self.data[r], rres)
                r -= 1
            l >>= 1 # l //= 2
            r >>= 1 # r //= 2
        if l == r:
            res = self.f(self.f(lres, self.data[l]), rres)
        else:
            res = self.f(lres, rres)
        return res

    # You can use lower_bound_index only if f == max.
    # It does not ensure (v <= a[i] if i > return_index)
    # return min({i | x <= i and v <= a[i]}, self.num_leaf)
    def lower_bound_index(self, x, v):
        x += self.num_leaf
        while self.data[x] < v:
            if x & 1: # x % 2 == 1
                if len(bin(x)) == len(bin(x+1)):
                    x += 1
                else:
                    return self.num_leaf
            else:
                x >>= 1
        while x < self.num_leaf:
            if self.data[2*x] >= v:
                x = 2*x
            else:
                x = 2*x + 1
        return x - self.num_leaf

def main():
    from sys import stdin
    input = stdin.buffer.readline

    n, q = map(int, input().split())
    a = list(map(int, input().split()))

    st = SegmentTree(n=n, f=max, default=-1)
    for i, ai in enumerate(a):
        st.update(i, ai)

    ans = []
    for _ in range(q):
        t, x, v = map(int, input().split())
        if t == 1:
            st.update(x-1, v)
        elif t == 2:
            ans.append(st.query(x-1, v))
        else:
            ans.append(min(st.lower_bound_index(x-1, v), n) + 1)
    
    for i in ans:
        print(i)

main()


Measured memory_bytes: 27956
#include <stdio.h>

int main(void){
    int x[5];
    scanf("%d %d %d %d %d",&x[0],&x[1],&x[2],&x[3],&x[4]);
    int i;
    for(i=0;i<5;i++){
        if(x[i]==0){
            printf("%d\n",i+1);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 2152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        int c0 = 0;
        int c1 = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '0') c0++;
            else c1++;
        }

        Console.WriteLine(2 * Math.Min(c0, c1));
    }
}

Measured memory_bytes: 11232
import java.awt.*;
import java.io.*;
import java.util.*;

public class Main {
    static ArrayList<Integer> adj[];
    static int c=0;
    static boolean vis[];
    static int cnt[];
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt(),x=sc.nextInt()-1,y=sc.nextInt()-1;
        adj=new ArrayList[n];
        for (int i=0;i<n;i++)adj[i]=new ArrayList<>();
        for (int i=0;i<n-1;i++){
            adj[i].add(i+1);
            adj[i+1].add(i);
        }
        vis=new boolean[n];
        adj[x].add(y);
        adj[y].add(x);
        cnt=new int[n];
        for (int i=0;i<n;i++){
            Arrays.fill(vis,false);
            int dist[]=new int[n];
            LinkedList<Integer> q=new LinkedList<>();
            q.add(i);
            vis[i]=true;
            while (!q.isEmpty()){
                int u=q.poll();
                for (int v:adj[u]){
                    if (vis[v])continue;
                    q.add(v);
                    vis[v]=true;
                    dist[v]=dist[u]+1;
                }
            }
            for (int z:dist)cnt[z]++;
        }
        StringBuilder sb=new StringBuilder();
        for (int i=1;i<n;i++)sb.append(cnt[i]/2+"\n");
        System.out.print(sb);

    }
    static void dfs(int i,int h,int st){
        if (i>st) {
            cnt[h]++;
        }
        if (vis[i])return;
        vis[i]=true;
        for (int u:adj[i]){
            if (vis[u])continue;
            dfs(u,h+1,st);
        }
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll count = 0;
    ll current = 0;
    ll N;
    vector<pair<bool, ll>> A;
    cin >> N;
    A.resize(N, pair<bool, ll>{true, 0});
    for(ll i = 0;i < N;i++) {
        ll temp;
        cin >> temp;
        A[i].second = temp - 1;
    }
    while(A[current].first) {
        if(current == 1) {
            cout << count << endl;
            return 0;
        }
        A[current].first = false;
        current = A[current].second;
        count++;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
//#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 1000000000

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void swap2(double* a, double* b)
{
	double tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

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

int factorial(int n)
{
	int a=1;

	if (n == 0)
		return 1;

	for (int i = 1; i <= n; i++)
		a *= i;

	return a;
}

int Con(int a, int b)
{
	return factorial(a) / (factorial(b) * factorial(a - b));
	
}

int a[20] = { 0 };

//int binary_search(int key)  
//{
//	int low, high, middle;
//
//	low = 0;
//	high = 20 - 1;
//
//
//
//	while (low <= high)
//	{
//		middle = (low + high) / 2;
//		if (key == a[middle])
//			return middle;
//		else if (key < a[middle])
//			high = middle - 1;
//		else if (key > a[middle])
//			low = middle + 1;
//	}
//	return INF;
//}

int binary_search(long long int key)
{
	long long int low = 0, high = 2000000000, middle;
	long long int p;

	while (low <= high)
	{
		middle = (low + high) / 2;
		//printf("%d    \n", middle);

		p = (middle * (middle + 1));

		if (p == key*2)
			return middle;
		else if (p >key*2)
			high = middle - 1;
		else
			low = middle + 1;
	}
	return 0;

}

int main()
{
	int N;
	int a[200000];

	scanf("%d", &N);

	for (int i = 0; i < N; i++)
		scanf("%d", &a[i]);

	sort(a, a + N);

	for (int i = 0; i < N - 1; i++)
	{
		if (a[i] == a[i + 1])
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES");
}



Measured memory_bytes: 1024
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        n: usize,
        d: [i32; n],
    }
    
    let mut answer = 0;

    for i in 0..(n-1) {
        for u in (i+1)..n {
            answer += d[i] * d[u];
        }
    }
    println!("{}", answer);
}


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

using namespace std;

using ll = long long;
using ld = long double;

using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;

#define pb push_back
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
struct d_ {
    template<typename T> d_ & operator ,(const T & x) { cerr << ' ' <<  x; return *this;}
    template<typename T> d_ & operator ,(const vector<T> & x) { for(auto x: x) cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) begin(x),end(x)
#define IN(n) ll n;cin >> n;
#define x first
#define y second

const ll N = 3007;
ll a,b,c,d;
const ll MOD = 998244353;
ll mod(ll a, ll b=MOD) {
  return ((a%b)+b)%b;
}
ll extended_euclid(ll a,ll b,ll &x,ll &y) {
    if (a == 0) { x = 0; y = 1; return b;}
    ll x1, y1; ll d = extended_euclid(b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll mod_inverse(ll a, ll n=MOD) {
  ll x, y;
  ll d = extended_euclid(a, n, x, y);
  if (d > 1) return -1;
  return mod(x,n);
}
struct Mt {
    ll x = 0;
    Mt(){}
    Mt(ll y):x(mod(y)){}
    bool operator==(Mt &y){return x==y.x;}
    Mt operator+(Mt y){return mod(x+y.x);}
    Mt operator-(){return mod(-x);}
    Mt operator-(Mt y){return mod(x-y.x);}
    Mt operator*(Mt y){return mod(x*y.x);}
    Mt operator/(Mt y){return mod(x*mod_inverse(y.x));}
    Mt operator+=(Mt y){return x=(*this+y).x;}
    Mt operator-=(Mt y){return x=(*this-y).x;}
    Mt operator*=(Mt y){return x=(*this*y).x;}
    Mt operator/=(Mt y){return x=(*this/y).x;}
};
ostream& operator<<(ostream& os, const Mt&m){
    os << m.x; return os;
}

ll DP[N][N];
Mt dp(ll h, ll w) {
    ll &ret = DP[h][w];
    if(~ret) return ret;
    if(h==a && w==b) return ret = 1;
    Mt cnt = 0;
    if(h>a) cnt += (Mt)w*dp(h-1,w);
    if(w>b) cnt += (Mt)h*dp(h,w-1);
    if(h>a && w>b) cnt -= Mt(h-1)*(w-1)*dp(h-1,w-1);
    return ret = cnt.x;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    CL(DP,-1);
    cin >> a >> b >> c >> d;
    cout << dp(c,d) << endl;
    return 0;
}


Measured memory_bytes: 74664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<string> s(N);
    vector<ll> t(N);
    map<string,int> mp; 

    rep(i,N){
        cin >> s[i] >> t[i];
        mp[s[i]] = i;
    }

    string X;
    cin >> X;

    int M = mp[X];

    ll ans = 0;

    for(int i = M+1;i < N;i++){
        ans += t[i];
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int INF=1e9;
const ll MOD=1e9+7;
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
    std::fill( (T*)array,(T*)(array+N),val );
}
int H,W;
string board[25];
int ans=0;
int tmpmx=0;
bool visited[25][25];
int turns[25][25];
int dy[] = { -1, 0, 1, 0};
int dx[] = { 0, -1, 0, 1};


ll ppow(ll n,ll p)
{
    ll ans=1;
    while(p!=0)
    {
        if(p&1) ans= (ans*n)%MOD;
        n= n*n %MOD;
        p = p >> 1;
    }
    return ans;
    
}

ll subtra(ll n,ll dislike)
{
    ll parent=n;
    ll child=1;
    for(int i=1;i<dislike;i++)
    {
        parent=(parent*(n-i))%MOD;
    }
    for(int i=1;i<=dislike;i++)
    {
        child=(child*i)%MOD;
    }
    child=ppow(child,MOD-2);
    return (parent*child)%MOD;
}

int main(void)
{
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans=ppow(2,n)-1;
    //cout << ans << endl;
    ans=(ans+MOD-subtra(n,a))%MOD;
    //cout << ans << endl;
    ans=(ans+MOD-subtra(n,b))%MOD;
    cout << ans << endl;
    //cout << ppow(n,b) << endl;
}

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

using namespace std;

int main() {
    /*int a,b,h,s;
    cin >> a >> b >> h;
    
    s=(a+b)*h/2;
    
    cout << s << endl;*/
    
    /*int N,A,B;
    cin >> N >> A;
    B=N*N-A;
    
    cout << B << endl;*/
    
   /* int A,B,C,D,s1,s2;
    cin >> A >> B >> C >> D;
    
    s1=A*B;
    s2=C*D;
    
    if(s1>s2){
        cout << s1 << endl;
    }
    else if(s1<s2){
        cout << s2 << endl;
    }
    else{
        cout << s1 << endl;
    }*/
    
   /* int a,b,c,s;
    cin >> a >> b >> c;
    
    s=0;
    if(a!=b){
        s=s+1;
    }
    if(a!=c){
        s=s+1;
    }
    if(b!=c){
        s=s+1;
    }
    if(a==b&&a==c&&b==c){
        s++;
    }
    cout << s << endl;*/
    
    /*int N,K,X,Y,s;
    cin >> N >> K >> X >> Y;
    
    if(N>K){
        s=K*X+Y*(N-K);
    }
    
    
    
    else if(N<=K){
        s=N*X;
    }
    
    cout << s << endl;*/
    
   /* long long N,A[200000],B[200000],s;
    cin >> N;
    
    int i = 0;
    while(i<N){
        cin >> A[i] >> B[i];
        i++;
    }
    
    i=0;
    while(i
    <N){
        s=A[i]*B[i];
        i++;
        cout << s << endl;
    }*/
    
    /* N,A,B,ans;
    cin >> N;
    
    for(int i=0;i<N;i++){
        
    }*/

    /*int N,L,maxL,sumL;
    cin >> N;
    
    maxL=0;
    sumL=0;
    for(int i=0;i<N; i++){
        cin >> L;
        maxL=max(L,maxL);
        sumL+=L;
    }
    if(maxL<sumL-maxL){
        cout << "Yes" << endl;
    }
    else if(maxL>=sumL-maxL){
        cout << "No" << endl;
    }*/
    
    int N,H;
    cin >> N;
    
    int u=0;
    int maxh=0;
    for(int i=0; i<N;i++){
        cin >> H;
        if(H>=maxh){
            u++;
        }
    
        maxh=max(maxh,H);
        
    }
        
    cout << u << endl;
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
def d_banned_k():
    from collections import Counter
    from functools import reduce
    N = int(input())
    A = [int(i) for i in input().split()]

    def comb(n, r):
        numerator = reduce(lambda x, y: x * y, range(n, n - r, -1))
        denominator = reduce(lambda x, y: x * y, range(1, r + 1))
        return numerator // denominator

    count = Counter(A)
    total = sum(comb(c, 2) for c in count.values())

    ans = []
    for a in A:
        v = count[a]
        ans.append(total - comb(v, 2) + comb(v - 1, 2))
    return ' '.join(map(str, ans))

print(d_banned_k())

Measured memory_bytes: 39480
# B
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if l[i] != l[j] != l[k] and l[i]+l[j] > l[k]:
                ans += 1
print(ans)


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

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

ll MOD = 1e9+7;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if(t & 1 == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

ll N,K;
mint f[200001];
mint f_inv[200001];

mint comb(ll a, ll b){
    return f[a] * f_inv[b] * f_inv[a-b];
}

int main(){
    cin >> N >> K;
    f[0] = f_inv[0] = mint(1);
    for(int i=1;i<=200000;i++) f[i] = f[i-1] * mint(i), f_inv[i] = f[i].inv();
    mint ans(0);
    for(int i=0;i<=K&&i<N;i++){
        ans += comb(N,i) * comb(N-1,N-i-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		List<Integer> al = new ArrayList<Integer>();
		for (int i = 0; i < 10; i++) {
			int a = sc.nextInt();
			al.add(a);
		}
		Collections.sort(al);
		for (int j = 0; j < 3; j++) {
			System.out.println(al.get(9 - j));
		}
	}
}


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

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

  int sum = N*L + N*(N-1)/2;

  if(L>=0){
    cout<<sum-L<<endl;
  }else if(L<0 && N>(-L)){
    cout<<sum<<endl;
  }else if(L<0 && N<=(-L)){
    cout<<(sum-(L+N-1))<<endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <deque>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
 
int main(void){
  int x,t;
  cin>>x>>t;
  if(x-t>0) cout<<x-t<<endl;
  else cout<<0<<endl;
  return 0;
}

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

// #include <boost/algorithm/string/join.hpp>
// using boost::algorithm::join;
//
// #include "boost/multi_array.hpp"
// boost::multi_array<int, 3> dp;
// dp.resize(boost::extents[10][9][8]);
//
// #include <boost/multiprecision/cpp_dec_float.hpp>  // quite slowly
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision; // mp::log10
// using bigint = boost::multiprecision::cpp_int;
// using rational = mp::cpp_rational;  // double d = static_cast<double>(r);

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

//constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
#define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vll P(A);
  vll Q(B);
  vll R(C);
  for (auto& p : P) {
    cin >> p;
  }
  for (auto& q : Q) {
    cin >> q;
  }
  for (auto& r : R) {
    cin >> r;
  }

  Sort(P); Reverse(P);
  Sort(Q); Reverse(Q);

  vll mixed;
  mixed.reserve(A+B+C);

  REP(i, min({A, X})) {
    mixed.emplace_back(P[i]);
  }
  REP(i, min({B, Y})) {
    mixed.emplace_back(Q[i]);
  }
  REP(i, C) {
    mixed.emplace_back(R[i]);
  }
  Sort(mixed); Reverse(mixed);

  ll ret = 0;
  REP(i, X+Y) {
    ret += mixed[i];
  }

  cout << ret << endl;

  return 0;
}

/* vim: set expandtab shiftwidth=2 softtabstop=2 : */


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

using namespace std;

typedef long long ll;

void solve() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = b - 1;
    x = min(x, n);
    cout << (a * x / b) - a * (x / b);
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 3612
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
        self.size = [1] * n
        # self.group_num = n

    def root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.root(self.table[x])
            return self.table[x]

    def get_size(self, x):
        r = self.root(x)
        return self.size[r]

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def union(self, x, y):
        r1 = self.root(x)
        r2 = self.root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.size[r1] += self.size[r2]
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
            self.size[r2] += self.size[r1]
        # self.group_num -= 1

n, k = LI()
P = LI()
C = LI()
U = UnionFind(n)
for i in range(n):
    U.union(P[i] - 1, i)

D = defaultdict(int)
for i in range(n):
    D[U.root(i)] += C[i]

ans = -INF
k -= 1
for j in range(n):
    r = D[U.root(j)]
    m = U.get_size(j)
    now = P[j] - 1
    ret_max = C[now]
    ret = C[now]
    if k // m and r >= 0:
        for l in range(k % m):
            now = P[now] - 1
            ret += C[now]
            ret_max = max(ret_max, ret)
        ret_max += k // m * r
    else:
        for l in range(min(m, k)):
            now = P[now] - 1
            ret += C[now]
            ret_max = max(ret_max, ret)
    ans = max(ans, ret_max)

print(ans)







Measured memory_bytes: 85616
#include<stdio.h>

int main(void)
{
	int data1,data2,i=0,n=0;
	int data[100]={0};
	while(scanf("%d %d",&data1,&data2)!=EOF)
	{
		data[i]=data1+data2;
		i++;
	}
	
	while(n<=i-1)
	{
		printf("%d\n",data[n]);
		n++;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


void solve(int w,int h,int n){
    vector<int >v[200];
    int cur=0;
    vector<vector<int>>id(h,vector<int>(w));
    string s[h];
    rep(i,h){
        getline(cin,s[i]);
        rep(j,w){
            if(s[i][j]!='#')id[i][j]=cur++;
        }
    }
    rep(i,h)rep(j,w-1){
        if(s[i][j]!='#'&&s[i][j+1]!='#'){
            v[id[i][j]].push_back(id[i][j+1]);
            v[id[i][j+1]].push_back(id[i][j]);
        }
    }
    rep(i,h-1)rep(j,w){
        if(s[i][j]!='#'&&s[i+1][j]!='#'){
            v[id[i][j]].push_back(id[i+1][j]);
            v[id[i+1][j]].push_back(id[i][j]);
        }
    }
    rep(i,cur)v[i].push_back(i);
    int m=1;
    int st=0,gl=0;
    rep(i,n){
        m*=cur;
        rep(j,h)rep(k,w){
            if(s[j][k]=='a'+i)st=st*cur+id[j][k];
            if(s[j][k]=='A'+i)gl=gl*cur+id[j][k];
        }
    }
    vector<int> dist(m,inf);
    queue<int> que;
    que.push(st);
    dist[st]=0;
    vector<int> pos(n),nxt(n);
    while(que.size()){
        int p=que.front();que.pop();
        int pp=p;
        rep(i,n){
            pos[n-i-1]=pp%cur;
            pp/=cur;
        }
        if(n==1){
            for(auto to : v[pos[0]]){
                if(dist[to]>dist[p]+1){
                    dist[to]=dist[p]+1;
                    que.push(to);
                }
            }
        }
        else if(n==2){
            for(auto to0 : v[pos[0]])for(auto to1 : v[pos[1]]){
                if(to0==to1)continue;
                if(to0==pos[1]&&to1==pos[0])continue;
                int nxt=to0*cur+to1;
                if(dist[nxt]>dist[p]+1){
                    dist[nxt]=dist[p]+1;
                    que.push(nxt);
                }
            }
        }
        else {
            for(auto to0 : v[pos[0]])for(auto to1 : v[pos[1]])for(auto to2 : v[pos[2]]){
                if(to0==to1||to1==to2||to2==to0)continue;
                if(to0==pos[1]&&to1==pos[0])continue;
                if(to0==pos[2]&&to2==pos[0])continue;
                if(to1==pos[2]&&to2==pos[1])continue;
                int nxt=to0*cur*cur+to1*cur+to2;
                if(dist[nxt]>dist[p]+1){
                    dist[nxt]=dist[p]+1;
                    que.push(nxt);
                }
            }
        }
    }
    cout<<dist[gl]<<endl;
}

int main(){
    int w,h,n;
    while(1){
        scanf("%d%d%d ",&w,&h,&n);
        if(w==0)break;
        solve(w,h,n);
    }
    return 0;
}


Measured memory_bytes: 9108
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    
    long long ans = 1;

    for (long long i = 1; i * i <= m; i++) {
        if (m % i == 0) {
            if (n <= m / i) {
                ans = max(ans, i);
            }

            if (n <= m / (m / i)) {
                ans = max(ans, m / i);
            }
        } 
    }

    cout << ans << endl;
}


Measured memory_bytes: 504