akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <utility>
#include <vector>
#include <cmath>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s) {int c;for(;;){c=gcu();if(c=='\n'||c==' ')return true;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

vector<int> sieve;

void make_sieve(int m) {
	sieve = vector<int>(m, true);
	for (int i = 4; i < m; i += 2)
		sieve[i] = false;
	for (int i = 3, e = sqrt(m); i <= e; i += 2) {
		if (!sieve[i])
			continue;
		for (int j = i * i; j < m; j += i)
			sieve[j] = false;
	}
}

int main()
{
	int n, m = 0;
	vector<int> d;
	while ((n = in())) {
		d.push_back(n);
		m = max(m, n);
	}

	make_sieve(m * 2 + 1);
	vector<int> map(m * 2 + 1);

	int c = 0;
	for (int i = 2; i <= m * 2; i++)
		map[i] = sieve[i] ? ++c: c;

	for (int p: d)
		out(map[p * 2] - map[p], '\n');
}


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

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

// 自動でmodを取ってくれる整数型
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint f(int n){ // 2のn乗
    if(n==0) return 1;
    mint x=f(n/2);
    x*=x;
    if(n%2==1) x*=2;
    return x;
}

// a^n mod を計算する
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//////////////////////////
int n;
vector<vector<int>> to(100005);
mint black[100005];
mint white[100005];


void dfs(int u,int p){
    black[u]=1;
    white[u]=1;
    for(int v : to[u]){
        if(v==p) continue;
        dfs(v,u);
        black[u]*=white[v];
        white[u]*=(black[v]+white[v]);
    }
}

int main(){
    cin>>n;
    int x, y;
    rep(i,n-1) {
        cin>>x>>y;
        x--;
        y--;
        to[x].push_back(y);
        to[y].push_back(x);
    }
    dfs(0,-1);
    mint ans=black[0]+white[0];
    cout<<ans<<endl;
}


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

int main() {
 int a;
 cin >> a ;
  if(a <1200){
  cout << "ABC" << endl;
  }
  else if(a >=1200 && a < 2800){
  cout << "ARC" << endl;
  }
  else{
  cout << "AGC" << endl;
  }

}


Measured memory_bytes: 256
s_a=list(input())
s_b=list(input())
s_c=list(input())
next_player="a"

while(1):
    if (len(s_a)==0 and next_player=="a") or (len(s_b)==0 and next_player=="b") or (len(s_c)==0 and next_player=="c"):
        print(next_player.upper())
        break
    if next_player=="a":
        next_player=s_a[0]
        del s_a[0]
    elif next_player=="b":
        next_player=s_b[0]
        del s_b[0]
    else:
        next_player=s_c[0]
        del s_c[0]

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

half = a*a*b/2

from math import atan,pi
if x <= half:
    c = 2*x/a/b
    ans = atan(c/b)
else:
    c = 2*x/a/a - b
    if abs(b-c) < 10**(-7):
        ans = pi / 2
    else: ans = atan(a/(b-c))
print(90-ans*180/pi)

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


int main() {
	
	string s;
	cin >> s;
	int len = s.size(), mcnt=0;
	for(int i=0; i<len; i++){
		int cnt=0;
		for(int j=i; j<len; j++){
			if(s.at(j)=='A'||s.at(j)=='T'||s.at(j)=='G'||s.at(j)=='C') cnt++;
			else break;
		}
		mcnt = max(mcnt, cnt);
	}
	cout << mcnt << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

using ll = long long int;

int main(void) {
  string s;
  string t;
  int c = 0;
  cin >> s;
  t.push_back(s[0]);
  for (auto i = s.begin() + 1; i != s.end(); i++) {
    if (t.size()==0 or t[0] == *i) {
      t.push_back(*i);
    } else {
      t.pop_back();
      c++;
    }
  }
  std::cout << c*2 << std::endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT0(i, n) RPT(i, 0, n - 1)
#define RPT1(i, n) RPT(i, 1, n)

int H, N, A[100001];
string ans;

void resolve()
{
    cin >> H >> N;
    RPT1(i, N) cin >> A[i];

    int total = 0;
    RPT1(i, N) total += A[i];

    ans = (total >= H) ? "Yes" : "No";
    cout << ans << endl;
}

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


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        string a, b; cin >> a >> b;
        while (a.size() && b.size()) {
                if (a == b) {
                        cout << "Yes";
                        return;
                }
                b.pop_back();
        }
        cout << "No";
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
using namespace std;
int main(){
string s;
cin>>s;
if(s=="Sunny"s) cout<<"Cloudy"<<endl;
if(s=="Cloudy"s) cout<<"Rainy"<<endl;
if(s=="Rainy"s) cout<<"Sunny"<<endl;
return 0;
}

Measured memory_bytes: 256
n=int(input())
h=[int(i) for i in input().split()]
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]))
print(dp[n-1])

Measured memory_bytes: 13980
A1, A2, A3 = map(int,input().split())
B1, B2, B3 = map(int,input().split())
C1, C2, C3 = map(int,input().split())

N = int(input())

T1 = []
T2 = []
T3 = []
Y1 = []
Y2 = []
Y3 = []
N1 = []
N2 = []

for i in range(N):
    num = int(input())
    if num == A1:
        T1.append(A1)
        Y1.append(A1)
        N1.append(A1)
    if num == A2:
        T2.append(A2)
        Y1.append(A2)
    if num == A3:
        T3.append(A3)
        Y1.append(A3)
        N2.append(A3)
    if num == B1:
        T1.append(B1)
        Y2.append(B1)
    if num == B2:
        T2.append(B2)
        Y2.append(B2)
        N1.append(B2)
        N2.append(B2)
    if num == B3:
        T3.append(B3)
        Y2.append(B3)
    if num == C1:
        T1.append(C1)
        Y3.append(C1)
        N2.append(C1)
    if num == C2:
        T2.append(C2)
        Y3.append(C2)
    if num == C3:
        T3.append(C3)
        Y3.append(C3)
        N1.append(C3)
    
if len(T1) == 3 or len(T2) == 3 or len(T3) == 3 or len(Y1) == 3 or len(Y2) == 3 or len(Y3) == 3 or len(N1) == 3 or len(N2) == 3:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		int changeNum = 0;
		Scanner scan = new Scanner(System.in);

		int sNum = scan.nextInt();
		int sColNum = 0;
		int preNum = 0;

		for(int i =0; i < sNum; i++) {

			sColNum = scan.nextInt();

			if(sColNum == preNum){
				changeNum++;
				preNum = 0;
				continue;
			}

			preNum = sColNum;

		}

		System.out.print(changeNum);
		scan.close();

	}

}

Measured memory_bytes: 23764
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
# define mp make_pair
# define x first
# define y second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  string s; cin >> s;
  int n = s.size();

  int ans = 0;

  rep(i, n){
    int k = 0, m = i;
    while(m < n && (s[m]=='A' || s[m]=='C' || s[m]=='G' || s[m]=='T')){
      k++;
      m++;
    }
    chmax(ans, k);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3652
#include <iostream>
 
using namespace std;
 
int main() {
  int i;
  cin >> i;
  int k[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << k[i - 1];
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		int[] points = new int[M];
		for (int i = 0; i < M; i++) {
			points[i] = sc.nextInt();
		}
		
		Arrays.sort(points);
		int[] segments = new int[M-1];
		for (int i = 0; i < M-1; i++) {
			segments[i] = points[i+1] - points[i];
		}
		
		Arrays.sort(segments);
		long distance = 0;
		for (int i = 0; i < M-N; i++) {
			distance += segments[i];
		}
		
		System.out.println(distance);
	}
}


Measured memory_bytes: 50184
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

int main(void){
    int l, r, d;
    cin >> l >> r >> d;

    int ans = 0;
    for(int i = l;i <= r;++i){
        if(i %d == 0){
            ans += 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3572
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int N, Q;
vector<int> A;

void input(void) {
	cin >> N >> Q;
	A.resize(N);
	for (auto& ai : A)
		cin >> ai;
}

vector<ll> acc, acc_skip;

void build_acc(void) {
	acc.resize(N);
	acc_skip.resize(N);
	acc[0] = A[0];
	acc[1] = A[0] + (ll)A[1];
	acc_skip[0] = A[0];
	acc_skip[1] = A[1];
	for (int i = 2; i < N; ++i) {
		acc[i] = acc[i - 1] + A[i];
		acc_skip[i] = acc_skip[i - 2] + A[i];
	}
}

ll solve(int x) {
	int ok = (N + 1) / 2, ng = 0;
	while (ok - ng > 1) {
		int mid = (ok + ng) / 2;
		if (abs(A[N - mid - 1] - x) < abs(A[N - 2 * mid - 1] - x))
			ok = mid;
		else ng = mid;
	}
	ll res = acc[N - 1] - acc[N - ok - 1];
	if (N - 2 * ok - 1 >= 0)
		res += acc_skip[N - 2 * ok - 1];
	return res;
}

int main(void) {
	input(); build_acc();
	while (Q--) {
		int X; cin >> X;
		cout << solve(X) << endl;
	}
	return 0;
}

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

using namespace std;
vector<pair<int, int> > adj[100005];
int cost[100005];

void dfs(int u, int cur){
    if(cost[u] != -1) return;;
    cost[u] = cur;
    for(auto p:adj[u])
        dfs(p.first, (cur + p.second) % 2);
}
int main() {
    int n;
    scanf("%d", &n);
    for(int i=0; i<n-1; i++){
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        adj[x].push_back({y, z});
        adj[y].push_back({x, z});
    }
    memset(cost, -1, sizeof(cost));
    dfs(1, 0);
    for(int i=1; i<=n; i++){
        printf("%d\n", cost[i]);
    }

}

Measured memory_bytes: 7552
//h17-1
//#include <bits/stdc++.h>
#include<iostream>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int main(){
    int W,H;
    char c;
    cin >> W >> H >> c;

    cout << "+";
    for(int i=1; i<W-1; i++) cout << "-";
    cout << "+" << endl;

    for(int i=1; i<H-1; i++){
        cout << "|";
        if(i == H/2){
            for(int j=0; j<(W-3)/2; j++) cout << ".";
            cout << c;
            for(int j=0; j<(W-3)/2; j++) cout << ".";
        }
        else{
            for(int j=1; j<W-1; j++) cout << ".";
        }
        cout << "|" << endl;
    }

    cout << "+";
    for(int i=1; i<W-1; i++) cout << "-";
    cout << "+" << endl;

    return 0;
}


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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	set<int> bag;
	int n = 3;
	while(n--) {
		int x;
		cin >> x;
		bag.insert(x);
	}
	if(bag.size() == 2) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

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

int main(){
    int n, m, out=0;
    cin >> n >> m;
    int i;
    for (i=n-1;i>=1;i--){
        out+=i;
    }
    for (i=m-1;i>=1;i--){
        out+=i;
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)


//template functions
/////////////////////////
long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}
long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}
long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}

/////////////////////////


//Answer


int main() {

string S;
cin>>S;
if(S=="SSS"){
cout<<0<<endl;
}else if(S=="RRR"){
cout<<3<<endl;
}else if(S=="RRS"||S=="SRR"){
cout<<2<<endl;
}else{
cout<<1<<endl;
} 


}

Measured memory_bytes: 3624
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<cstring>
#include<set>
#include<stdio.h>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define ll long long
using namespace std;
void fast()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int a,a1,b,t;ll s;
int main()
{
    fast();
    cin>>a>>b>>t;a1=a;
    while(t>=a1)
    {
        s+=b;
        a1+=a;
    }
    cout<<s;
    return 0;
}


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

int main(){
  int N,M; cin >> N >> M;
  char A[20];
  int ans = 0;
  for(int i=N;i<=M;i++){
    snprintf(A,20,"%d",i);
    if(A[0] == A[4] && A[1] == A[3]) 
    ans++;
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
use std::env;
use std::io::*;
use std::str::*;
use std::mem;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}
fn read_char() -> char {
    let c = read::<String>();
    let c = c.chars().collect::<Vec<char>>();
    c[0]
}
fn read_String_Vec() -> Vec<char> {
    let S = read::<String>();
    S.chars().collect::<Vec<char>>()
}

fn vecchar_to_String(Vs: Vec<char>) -> String {
    let mut S = String::new();
    for i in 0..Vs.len() {
        S.push(Vs[i]);
    }
    S
}

/*
A : 65
Z : 90
a : 97
z : 122
*/

/*
let N = read::<i32>();
let S = read::<String>();
let S = read_String_Vec();
let C = read_char();
*/

/*
 .to_string() : * -> String
 &*S          : String -> &str
*/

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let N = read::<i64>();
    let mut mpl = 1;
    for i in 0..N {
        mpl = (mpl * (i+1)) % 1000000007;
    }
    println!("{}", mpl%1000000007);

}


Measured memory_bytes: 4352
N = int(input())
H = list(map(int, input().split()))
reverse_H = H[::-1]
for i in range(N-1):
    if reverse_H[i] < reverse_H[i+1]:
        if reverse_H[i] < reverse_H[i+1] - 1:
            print("No")
            exit()
        reverse_H[i+1] -= 1
print("Yes")

Measured memory_bytes: 14396
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int compare(const void *a,const void *b){
	return *(int*)a-*(int*)b;
}

int siumaimin(int n, int a[n]){
    qsort(a,n,sizeof(a[n]),compare);
    return a[0];
}


int main(void){
    int n,i;
    scanf("%d",&n);

    int h[n],c[n],a[2];

    for(i=0;i<n;i++){
        scanf("%d",&h[i+1]);    
    }

/* kまでの最小　c[k] kの高さh[k]   */

    for(i=0;i<n+1;i++){
        c[i]=0;
    }

    for(i=0;i<n;i++){
        if(i==0){
            c[i+2]=fabs(h[2]-h[1]);
            if(n==2){
                break;
            }else{
                continue;
            }
        }

        if(i==n-1) break;
        
        a[0] = c[i + 1] + fabs(h[i + 2] - h[i + 1]) ;
        a[1] =  c[i] + fabs(h[i + 2] - h[i]);
        c[ i + 2 ] = siumaimin(2,a);

        // if(c[i + 1] + fabs(h[i + 2] - h[i + 1]) > c[i] + fabs(h[i + 2] - h[i])){
        //     c[i+2] =  c[i] + fabs(h[i + 2] - h[i]);
            
        // }else{
        //     c[i+2] = c[i+1] + fabs(h[i + 2] - h[i + 1]);
        // }
        //printf("%d\n",c[i+2]);
    }
    printf("%d\n",c[n]);
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const ll inf=1e9;
const int MAX = 510000;
const ll MOD = 998244353;

inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

int main(){
  ll n,k;cin>>n>>k;
  vll p(n),c(n);
  rep(i,0,n){
    cin>>p[i];p[i]--;
  }
  rep(i,0,n)cin>>c[i];
  ll ans=-inf;
  rep(i,0,n){
    ll v=i;
    ll sum=0,cnt=0;
    while(true){
      cnt++;
      sum+=c[v];
      v=p[v];
      if(v==i)break;
    }
    ll path=0,d=0;
    while(true){
      d++;
      path+=c[v];
      if(d>k)break;
      ll num=(k-d)/cnt;
      ll score=path+max(0LL,sum)*num;
      ans=max(ans,score);
      v=p[v];
      if(v==i)break;
    }
    
  }cout<<ans<<endl;
}






Measured memory_bytes: 3712
#include<stdio.h>
#define NUM 200000

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

int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] > array[pivot]);
    do { j--; } while (array[pivot] > array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}


int main(){
  int n,k,h[NUM],jj = 0;
  long sum = 0;
  int tmp;

  /*入力とソート*/
  scanf("%d",&n);
  scanf("%d",&k);

  for(int i = 0;i < n;i++){
    scanf("%d",&h[i]);
  }

  quick_sort(h, 0, n - 1);

  

    /*出力*/

  
  for(int i = 0;i < n;i++){
    if(i < k){
      h[i] = 0;
    }
    sum += h[i];
  }
  printf("%ld\n",sum);
 

  return 0;
}


Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Set;

public class Main implements Runnable {

	Set<Integer> set = new HashSet<>();
	int max = 0;

	public static void main(String[] args) {

		new Thread(null, new Main(), "", 16 * 1024 * 1024).start();

	}

	@Override
	public void run() {
		exec();
	}

	private void exec() {

		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();

		System.out.println(n * n * n);

	}

	private int search(int num) {
		if(set.contains(num)) {
			return search(num + 1);
		} else {
			return num;
		}

	}

}

class FastScanner {

	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	public FastScanner(InputStream in) {
		this.in = in;
	}

	private boolean hasNextByte() {
		if(ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if(buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if(hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while(hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}

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

}


Measured memory_bytes: 22612
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;

signed main(){
  int n;
  cin>>n;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> h(n);
  for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>h[i];

  for(int i=0;i<101;i++){
    for(int j=0;j<101;j++){
      bool f=true;
      int H=-1;
      for(int k=0;k<n;k++){
        if(H==-1&&h[k]>0){
          H=h[k]+abs(x[k]-i)+abs(y[k]-j);
          break;
        }
      }
      for(int k=0;k<n;k++){
        if(max(0LL,H-abs(x[k]-i)-abs(y[k]-j))!=h[k])f=false;
      }
      if(f&&H>0){
        cout<<i<<" "<<j<<" "<<H<<endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

#define INFTY 1000000001

struct card{
	int n;
	char suit;
};

void swap(card &a, card &b){
	card x = a;
	a = b;
	b = x;
	return;
}

int partition(vector<card> &A, int p, int r){
	int x = A[r].n;
	int i = p - 1;
	for (int j = p; j < r; j++){
		if (A[j].n <= x){
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}

void quicksort(vector<card> &A, int p, int r){
	if (p < r){
		int q = partition(A, p, r);
		quicksort(A, p, q - 1);
		quicksort(A, q + 1, r);
	}
	return;
}


void merge(vector<card> &A, int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	vector<card> L(n1 + 1);
	for (int i = 0; i < n1; i++) L[i] = A[left + i];
	vector<card> R(n2 + 1);
	for (int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1].n = INFTY;
	R[n2].n = INFTY;
	int i = 0;
	int j = 0;
	for (int k = left; k < right; k++){
		if (L[i].n <= R[j].n){
			A[k] = L[i];
			i = i + 1;
		}
		else{
			A[k] = R[j];
			j = j + 1;
		}
	}

}

void mergeSort(vector<card> &A, int left, int right){
	if (left + 1 < right){
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int main(){

	int n;
	cin >> n;
	vector<card> A(n), B(n);
	for (int j = 0; j < n; j++){
		cin >> A[j].suit >> A[j].n;
		B[j] = A[j];
	}

	quicksort(A, 0, n - 1);
	mergeSort(B, 0, n);

	bool isStable = true;
	for (int j = 0; j < n; j++){
		if (A[j].suit != B[j].suit){
			isStable = false;
			break;
		}
	}
	cout << (isStable ? "Stable" : "Not stable") << endl;

	for (int j = 0; j < n; j++) cout << A[j].suit << " " << A[j].n << endl;

	return 0;
}


Measured memory_bytes: 5116
N, X, Y = map(int, input().split())

L = [0 for _ in range(N)]
for i in range(1, N):
    for j in range(i+1, N+1):
        l = min(abs(j-i), abs(X-i) + 1 + abs(Y-j))
        L[l] += 1
for l in L[1:]:
    print(l)

Measured memory_bytes: 46172
n,k=map(int,input().split())
a=list(map(int,input().split()))

inter = 0
for i in range(n):
    for j in range(i+1,n):
        if a[i] > a[j]:
            inter += 1
outer = 0
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            outer += 1

ans = inter*k + outer*k*(k-1)//2
ans %= 10**9+7
print(ans)

Measured memory_bytes: 41836
#!/usr/bin/env python3

def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

x, y, z = read_line(int, int, int)

def f(i):
    return i * y + (i + 1) * z

i = 0
while True:
    if x < f(i + 1):
        break
    i += 1

print(i)


Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
    int n, a, b;
    int  train;

    scanf("%d %d %d", &n, &a, &b);

    train = n*a;

    if(b > train){
        printf("%d", train);
    }else{
        printf("%d", b);
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long L;
using namespace std;
  
#define N 100005
#define U [N]={}
map<L,L> path[N];
L par U,dep U,siz U,hev U,cst U,add U,pos U,hl_par U,bit U,
k,n,q,a,b,c,i,p,r;
char s[5];
void dfs(L a){
    siz[a]=1;
    for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){
        L d=I->first;
        if(d==par[a]) continue;
        par[d]=a;
        dep[d]=dep[a]+1;
        cst[d]=I->second;
        dfs(d);
        siz[a]+=siz[d];
        if(!hev[a] || siz[hev[a]]<siz[d])
            hev[a]=d;
    }
}
    
L edgecost(L a){
    L ret=add[a]+add[par[a]]+cst[a];
    return ret%k ? ret : 0;
}
    
L sum(L i){
    L ret=0;
    while(i){
        ret+=bit[i];
        i-=i&-i;
    }
    return ret;
}
void S(L i, L x){
    x=edgecost(x)-sum(i+1)+sum(i);
    i++;
    while(i<N){
        bit[i]+=x;
        i+=i&-i;
    }
}
  
main(){
    cin >> n >> k;
    for(i=0; i<n-1; i++){
        cin >> a >> b >> c;
        path[a][b]=path[b][a]=c;
    }
    dfs(0);
    
    for(c=i=0; i<n; i++){
        if(!i|hev[par[i]]-i)
        for(a=i;!c|a;a=hev[a]){
            pos[a]=c++;
            hl_par[a]=i;
        }
    }
     
    for(i=0; i<n; i++)
        S(pos[i],hev[i]);
     
    cin >> q;
    for(i=0; i<q; i++){
        cin>>s>>a>>b;
        if(*s&2){
            for(c=0;p=hl_par[a],r=hl_par[b],p-r;a=par[p])
                dep[p]<dep[r]?swap(p,r),swap(a,b),0:0,
                c+=sum(pos[a])-sum(pos[p])+edgecost(p);
            cout<<c+abs(sum(pos[a])-sum(pos[b]))<<endl;
        }else{
            add[a]+=b;
            S(pos[a],hev[a]);
            if(a)S(pos[a]-1,a);
        }
    }
}

Measured memory_bytes: 31964
from heapq import heappop, heappush
from collections import defaultdict
N, M = map(int, input().split())
H = []
D = defaultdict(list)
for _ in range(N):
    a, b = map(int, input().split())
    if a > M:
        continue
    else:
        D[a].append(b)

ans = 0
for a in range(1, M+1):
    for b in D[a]:
        heappush(H, -b)
    if H:
        ans -= heappop(H)

print(ans)
        



Measured memory_bytes: 77528
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,a1,a2,a3,a4;
int main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a%2==b%2)
	{
		cout<<(b-a)/2;
		return 0;
	}
	if(a>b)
		swap(a,b);
	a1=(n-a+n-b+1)/2,a2=(a-1+b-1+1)/2;
	cout<<min(a1,a2);
	return 0;
}


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

int main(){
    int n,k,x,y,sum=0,o;
cin>>n>>k>>x>>y;
if(n<k){
    o=n;
}
else
    o=k;
for(int i=0;i<o;i++){
sum+=x;
}
for(int i=0;i<n-k;i++){
sum+=y;

}
cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
  val (n, xi) = readLine()!!.split(" ").map { it.toInt() }
  val x = xi.toLong()
  val ys = readLine()!!.split(" ").map { it.toLong() }.sorted()

  if (x == ys.sum()) {
    println(n)
    return
  }

  var sum = 0L
  var count = 0
  for (i in 0 until n - 1) {
    if (sum + ys[i] <= x) {
      sum += ys[i]
      count++
    } else {
      break
    }
  }

  println(count)
}


Measured memory_bytes: 37932
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
//YESNO

using namespace std;


struct St
{
	int color;
	int n;
	bool operator < (const St& st) const
	{
		return (n > st.n);
	}
};

int X, Y, A, B, C;
int P[100010];
int Q[100010];
int R[100010];

St st[300010];

signed main()
{
	cin >> X >> Y >> A >> B >> C;

	int total = 0;
	REP(i, A)
	{
		cin >> P[i];
		st[total].color = 0;
		st[total++].n = P[i];
	}
	REP(i, B)
	{
		cin >> Q[i];
		st[total].color = 1;
		st[total++].n = Q[i];
	}
	REP(i, C)
	{
		cin >> R[i];
		st[total].color = 2;
		st[total++].n = R[i];
	}

	ARY_SORT(st, total);

	int x = 0;
	int y = 0;
	int m = 0;
	int ans = 0;
	for (int i = 0; i < total; i++)
	{
		if (st[i].color == 0)
		{
			if (x < X)
			{
				x++;
				ans += st[i].n;
			}
		}

		if (st[i].color == 1)
		{
			if (y < Y)
			{
				y++;
				ans += st[i].n;
			}
		}

		if (st[i].color == 2)
		{
			m++;
			ans += st[i].n;
		}

		if (x + y + m >= X + Y)
		{
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 7296
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}





int main(){
    ll n;
    cin>>n;
    vector<ll> A(n);
    cin>>A;
    ll ans=0;
    for(int i=1;i+1<n;i++){
        vector<ll> B={A[i-1],A[i],A[i+1]};
        sort(B.begin(),B.end());
        if(B[1]==A[i]){ans++;}
    }
    cout<<ans<<endl;
    
    
    return 0;
}


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

const int D = 20;

int N;
vector<vector<ll>> S;

// [l, r]
bool good(int l, int r) {
  rep(d,D) {
    if(S[r+1][d] - S[l][d] > 1) return false;
  }
  return true;
}

int main () {
  cin >> N;

  S.resize(N+1, vector<ll>(D, 0));

  rep(i,N) {
    int A;
    cin >> A;
    rep(d,D) {
      S[i+1][d] = S[i][d] + ((A>>d)&1);
    }
  }

  ll ans = 0;
  for(int i = 0; i < N; i++) {
    int l = i, r = N;
    while(r - l > 1) {
      int m = (l+r)/2;
      if(good(i,m)) {
        l = m;
      } else {
        r = m;
      }
    }
    ans += l - i + 1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 39296
#include <iostream>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <tuple>
using namespace std;

template <class T> void chmax(T &x, T y) {if(x<y) x=y;}
template <class T> void chmin(T &x, T y) {if(x>y) x=y;}

int n;
char str[10];
vector<string> ans;

void dfs(int s,char x)
{
    if(s==(1<<n)-1)
    {
        ans.emplace_back(str);
        return;
    }
    int r=((1<<n)-1)^s;
    int b=r&-r;
    int t=r;
    do
    {
        if(t&b)
        {
            for(int i=0;i<n;++i) if(t>>i&1) str[i]=x;
            dfs(s|t,x+1);
        }
        t--;
        t&=r;
    } while(t);
}

main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);

    cin>>n;
    dfs(0,'a');
    sort(begin(ans),end(ans));
    for(auto &s:ans)
    {
        cout << s << "\n";
    }
}

Measured memory_bytes: 7796
#include<iostream>
#include<algorithm>
using namespace std;
int n,k,a[5000];
int dp[5050][5050]={1};
bool C(int m)
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<k;j++)dp[i+1][j]=0;
		for(int j=0;j<k;j++)
		{
			if(dp[i][j]){
				dp[i+1][j]=1;
				if(i!=m&&j+a[i]<k)dp[i+1][j+a[i]]=1;
			}
		}
	}
	for(int i=max(0,k-a[m]);i<k;i++)if(dp[n][i])return true;
	return false;
}
main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	int l=0,f=n+1,m;
	while(f-l>1)
	{
		m=(f+l)/2;
		(C(m-1)?f:l)=m;
	}
	cout<<l<<endl;
}

Measured memory_bytes: 98944
// https://atcoder.jp/contests/soundhound2018-summer-qual/tasks/soundhound2018_summer_qual_c

fun main() {
    soundhound2018c()
}

fun soundhound2018c() {
    val (n, m, d) = readLine()!!.split(" ").map { it.toLong() }
    var beauty = 0.0
    var count = 0L
    if (d == 0L) {
        count = n
    } else {
        for (i in 1..n) {
            if (i - d > 0L) count++
            if (i + d <= n) count++
        }
    }
    beauty = count.toDouble() / n / n
    var t = beauty
    for (i in 2 until m) {
        beauty += t
    }
    println("%.10f".format(beauty))
}

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

#define F first
#define S second
#define sz(x) (int) (x).size()
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int MOD = 1e9 + 7;
const int MN = 2e5 + 2, LN = 18;

int N, h[MN], a[MN];
ll t[3*MN];

void update(int id, int l, int r, int i, ll v) {
    if (l == r) {t[id] = v; return;}
    int m = (l + r) / 2;
    if (i <= m) update(id * 2, l, m, i, v);
    else update(id * 2 + 1, m + 1, r, i, v);
    t[id] = max(t[id * 2], t[id*2+1]);
}

ll query(int id, int l, int r, int ll, int rr) {
    if (l > r || l > rr || r < ll) return 0;
    if (l >= ll && r <= rr) return t[id];
    int m = (l+r)/2;
    if (rr<=m) return query(id*2,l,m,ll,rr);
    else if (ll>m) return query(id*2+1,m+1,r,ll,rr);
    else return max(query(id*2,l,m,ll,m),query(id*2+1,m+1,r,m+1,rr));
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> h[i];
    for (int i = 1; i <= N; i++) cin >> a[i];
    ll ret = 0;
    for (int i = 1; i <= N; i++) {
        ll temp = query(1, 1, N, 1, h[i]-1);
        ret = max(ret, temp + a[i]);
        update(1, 1, N, h[i], temp + a[i]);
    }
    cout << ret << '\n';
    return 0;
}

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

vector<int> E[200];
int d[200]={}, f[200]={};

int func(int pos, int time){
    if(d[pos]>0){
        return time;
    }
    d[pos] = time;
    time++;
    for (int to : E[pos]){
        time = func(to, time);
    }
    f[pos] = time;
    time++;
    return time;
}

int main(){
    int n;
    cin >> n;
    rep(i, n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v;
            cin >> v;
            E[u].push_back(v);
        }
    }
    int time = 1;
    for (int i = 1; i <= n; i++){
        if(d[i]==0){
            time = func(i, time);
        }
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    // printf("%d\n", N);
    return 0;
}


Measured memory_bytes: 3140
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int num = 1;
    int ans = 0;

    while (num < b)
    {
        ans++;
        num += a-1;
    }
    

    cout << ans << endl;

    return 0;
}


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

using namespace std;
using ll = long long;

const int MOD = 1000000007;
ll dp[101][4][4][4] = {0};

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  dp[0][0][0][0] = 1;
  // T = 0, A = 1, G = 2, C = 3
  for (int i = 0; i < N; i++) {
    for (int a = 0; a < 4; a++) {
      for (int b = 0; b < 4; b++) {
        for (int c = 0; c < 4; c++) {
          for (int d = 0; d < 4; d++) {
            if (ng(b, c, d) || ng(c, b, d) || ng(b, d, c)) continue;
            if (ng(a, c, d) || ng(a, b, d)) continue;
            dp[i + 1][b][c][d] = (dp[i + 1][b][c][d] + dp[i][a][b][c]) % MOD;
          }
        }
      }
    }
  }
  ll res = 0;
  for (int a = 0; a < 4; a++) {
    for (int b = 0; b < 4; b++) {
      for (int c = 0; c < 4; c++) {
        res = (res + dp[N][a][b][c]) % MOD;
      }
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
///WRONG LIFE
///DIE(RETRY)
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define endl '\n'

using ll = long long;
using db = long double;
using row = vector<int>;
using ii = pair<int, int>;

const int N = 2e5 + 5, M = 26, A = 6561, LG = 19, MOD = 1e9+7;
const int BLOCK = 500;
const long double EPS = 1e-7;
using pii = pair<int,int>;
int dp[3005][3005];
int n, q, x, y;
int a[3005];
const int INV2 = 500000004;
int main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE

  ll n, m; cin >> n >> m;

  if(n * 2 >= m)cout << m / 2 << '\n';
  else
    cout << n + (m-2*n)/4 << '\n';

    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    SSSS = 998244353
    D = string_to_int(inputs[0])
    # {distance: numbers}
    nodes = {}
    for i, d in enumerate(D):
        i += 1
        if d not in nodes:
            nodes[d] = [i]
        else:
            nodes[d].append(i)

    if 0 not in nodes:
        return 0

    prev = -1
    prev_num = -1
    count = 0
    for d in sorted(nodes.keys()):
        if d == 0:
            if not (len(nodes[d]) == 1 and nodes[d][0] == 1):
                return 0
            count = 1
            prev_num = 1
            prev = d
            continue
        if abs(d - prev) != 1:
            return 0

        count *= prev_num ** len(nodes[d])
        prev_num = len(nodes[d])
        prev = d
    return count % SSSS


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 68972
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ll n,k;
    cin>>n>>k;
    ll first[n];
    for(ll i=0;i<n;i++){
        cin>>first[i];
    }
    for(int i=k;i<n;i++){
        if(first[i-k]<first[i]){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
}
    //int temp=1;
    //vector<int> third;
    //int j=0;
    //for(int i=k-1;i<n;i++){
        //third.push_back((mul*first[i])/temp);
        //mul=mul*first[i];
        //temp=temp*second[j];
        //cout<<third[j]<<" ";
        //j++;
   // }
    //unordered_multiset<int> var;
    //var.insert(third[0]);
    
            //init++;
            



Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin >> n;
  string s;cin >> s;
  vector<int> e(n+1),w(n+1);
  for(int i=0;i<n;i++){
    if(s[i]=='W'){
      w[i+1]=w[i]+1;
    }
    else{
      w[i+1]=w[i];
    }
  }
  for(int i=n-1;i>=0;i--){
    if(s[i]=='E'){
      e[i]=e[i+1]+1;
    }
    else{
      e[i]=e[i+1];
    }
  }
  int ans=inf;
  for(int i=0;i<n;i++){
    chmin(ans,w[i]+e[i+1]);
  }
  cout << ans << endl;
}

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

typedef long long LL;

const int N=1000;
const char db[8][10][10]={
  {},
  {},
  {},
  {
	"a..",
	"a..",
	".aa"
  },
  {
	"aaca",
	"bbca",
	"acbb",
	"acaa"
  },
  {
	"aabba",
	"bcc.a",
	"b..cb",
	"a..cb",
	"abbaa"
  },
  {
	"aabc..",
	"ddbc..",
	"..aabc",
	"..ddbc",
	"bc..aa",
	"bc..dd"
  },
  {
	"aabbcc.",
	"dd.dd.a",
	"..d..da",
	"..d..db",
	"dd.dd.b",
	"..d..dc",
	"..d..dc"
  }
};

int n;

void into(){
  scanf("%d",&n);
}

char ans[N+9][N+9];

void Get_ans(int x,int y,int n){
  for (int i=0;i<n;++i)
	for (int j=0;j<n;++j) ans[x+i][y+j]=db[n][i][j];
}

void Get_ans(){
  if (n<=2) return;
  if (n==3) {Get_ans(0,0,n);return;}
  for (int i=0;i<n;++i)
	for (int j=0;j<n;++j) ans[i][j]='.';
  int x=0,y=0,m=n;
  for (;m>=8;m-=4,x+=4,y+=4) Get_ans(x,y,4);
  Get_ans(x,y,m);
}

void work(){
  Get_ans();
}

void outo(){
  if (n<=2) puts("-1");
  else
    for (int i=0;i<n;++i){
	  for (int j=0;j<n;++j)
	    putchar(ans[i][j]);
      puts("");
    }
}

int main(){
  into();
  work();
  outo();
  return 0;
}

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

int main() {
    int N,M;
    cin >> N;
    string s[N];
    for(int i = 0; i < N; ++i) cin >> s[i];
    cin >> M;
    string t[M];
    for(int i = 0; i < M; ++i) cin >> t[i];

    //mapに投入してmaxを取る
    map<string, int> mp;
    int ans = 0;
    
    for(int i = 0; i < N; ++i) mp[s[i]]++;
    for(int i = 0; i < M; ++i) mp[t[i]]--;

    for(int i = 0; i < N; ++i){
        if(ans < mp[s[i]]) ans = mp[s[i]];
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
object Main extends App {
	val n = scala.io.StdIn.readInt
	var temp1 = scala.io.StdIn.readLine
	var s = Map(temp1 -> 1)
	for(i<-1 until n){
		temp1 = scala.io.StdIn.readLine
		s.get(temp1) match {
			case None => s = s ++ Map(temp1 -> 1)
			case Some(x) => s = s++ Map(temp1 -> (x+1))
		}
	}

	val m = scala.io.StdIn.readInt
	var temp2 = scala.io.StdIn.readLine
	var t = Map(temp2 -> 1)
	for(i<-1 until m){
		temp2 = scala.io.StdIn.readLine
		t.get(temp2) match {
			case None => t = t ++ Map(temp2 -> 1)
			case Some(x) => t = t++ Map(temp2 -> (x+1))
		}
	}

	var key = (s.keySet ++ t.keySet).map(x => (test(s.get(x)) - test(t.get(x))))
	
	def test(x: Option[Int]): Int = {
		x match {
			case None => 0
			case Some(t) => t
		}
	}

	
	if(key.max < 0){
		println(0)
	}else{
		println(key.max)
	}

}

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

void solve(long long N)
{
    vector<long long> dp(100010, INT_MAX);

    dp.at(0) = 0;
    for (int i = 1; i <= 100000; i++)
    {
        int now = 1;
        while (now <= i)
        {
            dp.at(i) = min(dp.at(i), dp.at(i - now) + 1);
            now *= 6;
        }

        now = 1;
        while (now <= i)
        {
            dp.at(i) = min(dp.at(i), dp.at(i - now) + 1);
            now *= 9;
        }
    }
    cout << dp.at(N) << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 1024