akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
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); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  string s;
  cin >> s;
  int cnt = 0;
  rep(i, sz(s) / 2) {
    if (s[i] == s[sz(s) - 1 - i]) continue;
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;


ull N;
ull A[200001], S[200001];

const ull mod = ull(1E9) + 7;

ull my_plus(ull a, ull b) {
    return ((a % mod + b % mod) % mod);
}

ull my_mult(ull a, ull b) {
    return ((a % mod * b % mod) % mod);
}

int main() {
    cin >> N;

    ull i, j;

    for (i = 0; i < N; i++) {
        cin >> A[i];       
    }
    ull sum = 0;
    ull ans = 0;
    S[N - 1] = A[N - 1];

    ans = my_mult(A[N - 2], S[N - 1]);

    //cout << ans << endl;
    
    for (i = N-2; i > 0; i--) {
        S[i] = my_plus(A[i], S[i + 1]);
        ans = my_plus(ans, my_mult(A[i-1], S[i]));

        //cout << "S[i]=" << S[i] << "ans=" << ans << endl;

    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6264
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long


LL n;

int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  cin >> n;
  int cnt = 0;

  set<LL> a;
  for (LL i = 1; i * i <= n; i += 1) {
    if (n % i == 0) {
      a.insert(i);
      a.insert(n / i);
    }
  }
  for (LL i = 1; i * i <= n - 1; i += 1) {
    if ((n - 1) % i == 0) {
      a.insert(i);
      a.insert((n - 1) / i);
    }
  }
  for (auto v: a) {
    if (v == 1) continue;
    LL t = n;
    while (t != 0 && t % v == 0) {
      t /= v;
    }
    t -= (t / v) * v;
    if(t == 1) {
      //cout << v << endl;
      cnt += 1;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;

vector<int> colors;  // 1.黒 0.白 -1.未確定

using Graph = vector<vector<pair<int, int>>>;

void dfs(Graph &G, int v, int cur = 0) {
    colors.at(v) = cur;  // 現在の色を設定

    for (pair<int, int> nextV : G.at(v)) {  // 隣接頂点を調べる

        if (colors.at(nextV.first) != -1) continue;  // 色が確定している（探索済み）

        int nextColor = colors.at(nextV.first);
        int nextDistance = nextV.second;

        if (nextDistance % 2) {  // 距離が奇数の場合
            dfs(G, nextV.first, 1 - cur);
        } else {  // 距離が偶数の場合
            dfs(G, nextV.first, cur);
        }
    }
}

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

    Graph G(N);

    for (int i = 0; i < N - 1; i++) {
        int tmpU, tmpV, tmpW;
        cin >> tmpU >> tmpV >> tmpW;
        G.at(tmpU - 1).push_back(make_pair(tmpV - 1, tmpW));  // 頂点番号は0始まり（0 インデックス）
        G.at(tmpV - 1).push_back(make_pair(tmpU - 1, tmpW));  // 頂点番号は0始まり（0 インデックス）
    }

    colors.assign(N, -1);

    dfs(G, 0);

    for (int color : colors) {
        cout << color << endl;
    }

    return 0;
}

Measured memory_bytes: 8192
from collections import defaultdict

def a():
    N = int(input())
    D = list(map(int,input().split()))[:N]
    M = int(input())
    T = list(map(int,input().split()))[:M]

    L = set(D+T)
    D_count = defaultdict(int)
    T_count = defaultdict(int)

    for d in D: D_count[d] += 1
    for t in T: T_count[t] += 1

    for t in T_count:
        if t not in D_count: D_count[t] = 0
        if D_count[t] < T_count[t]:
            print("NO")
            return
    
    print("YES")
    return

a()

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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

int main(){
	setIO();
	int n; cin >> n;
	cout << (((n+999)/1000*1000)-n) << endl;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
#define ll long long
#define FOR(x) for(ll i = 0;i<(x);i++)
#define ALL(v) (v).begin(),(v).end()


using namespace std;


int main(){
ll a,b;
cin>>a>>b;
if(a%2==1&&b%2==1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n,k,q;
    cin >> n >> k >> q;
    vector <int> a(q);
    vector <double> point(n);
    for(int i=0;i<q;i++)
    {
        cin >> a[i];
    }
    for(int i=0; i<q; i++)
    {
        point[a[i]-1]++;
    }
    for(int i=0; i<n; i++)
    {
        if(k-(q-point[i])<1) cout << "No\n";
        else cout << "Yes\n";
    }
}

Measured memory_bytes: 1792
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])

  if temp!=1:
    arr.append([temp, 1])

  if arr==[]:
    arr.append([n, 1])

  return arr

ans = 0

n = int(input())
for i,j in factorization(n):
  if i == 1:
    continue
  for k in range(int((2 * j)**0.5), 0 ,-1):
    if k*(k+1) <= 2 * j and (k+1)*(k+2) >= 2 * j:
      ans += k
      break
print(ans)


Measured memory_bytes: 63368
#include<iostream>
#include<algorithm>
#include<vector>
#include<fstream>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
ll D;
ll c[26];
ll s[366][26];
ll t[366];

ll total_max_score;
ll ft[366];

//スコア計算
ll score(ll days){
	ll ans=0;
	ll last[26];
	rep(i,26)last[i]=0;
	for(ll d=1;d<=days;d++){
		ans+=s[d][t[d]];
		last[t[d]]=d;
		rep(i,26){
			ans-=c[i]*(d-last[i]);
		}
	}
	return ans;
}

ll whole_score;
ll score_typ[26];
void recalc(ll i){
	ll ans=0;
	ll last=0;
	for(ll d=1;d<=D;d++){
		if(t[d]==i){
			ans+=s[d][i];
			last=d;
		}
		ans-=c[i]*(d-last);
	}
	whole_score-=score_typ[i];
	score_typ[i]=ans;
	whole_score+=score_typ[i];
	if(whole_score>total_max_score){
		total_max_score=whole_score;
		for(ll d=1;d<=D;d++){
			ft[d]=t[d];	
		}
	}
}
void change(ll d,ll q){
	ll b=t[d];
	t[d]=q;
	recalc(b);
	recalc(q);
}
void init_score(){
	total_max_score=-1e17;
	whole_score=0;
	rep(i,26){
		score_typ[i]=0;
		recalc(i);
	}
}

//貪欲法
void greedy(){
	for(ll d=1;d<=D;d++){
		ll ma=-1e17,pt=0;
		rep(i,26){
			t[d]=i;
			ll res=score(d);
			if(ma<res){
				ma=res;
				pt=i;
			}
		}
		t[d]=pt;
	}
}

//日程を√cに応じて分配
void distribute(){
	vector<ll> v;
	rep(i,26){
		for(ll x=1;x*x<=c[i];x++){
			v.push_back(x);
		}
	}
	for(ll d=1;d<=D;d++){
		t[d]=v[rand()%(ll)v.size()];
	}
}

//局所探索_改
void local_search(){
	rep(u,50000){//日付を一つ選んで、コンテストを変更
		ll d=rand()%D+1;
		ll q=rand()%26;
		ll b=t[d];
		ll bef_score=whole_score;
		change(d,q);
		ll aft_score=whole_score;
		if(bef_score>aft_score){
			change(d,b);
		}
	}
	rep(u,50000){//日付を二つ選んで、コンテストをswap
		ll bef_score=whole_score;
		ll d1,d2;
		do{
			d1=rand()%D+1;
			d2=rand()%D+1;
		}while(d1==d2);
		ll p=t[d1],q=t[d2];
		change(d1,q);
		change(d2,p);
		ll aft_score=whole_score;
		if(bef_score>aft_score){
			change(d1,p);
			change(d2,q);
		}
	}
}


int main(){
	//ifstream ifs("input.txt");
	cin>>D;
	rep(i,26)cin>>c[i];
	for(ll d=1;d<=D;d++)rep(j,26)cin>>s[d][j];
	greedy();
	//distribute();
	init_score();
	local_search();
	//ofstream ofs("output.txt");
	for(ll d=1;d<=D;d++){
		cout<<ft[d]+1<<"\n";
	}
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
int main(){
   ll A,B;
   cin >> A >> B;
   ll num = 2;
   ll ans = 0;

   ans += ((B+1)/2 - A/2) % 2;

   REP(i,43){
       ll a,b;
       if (A/(num*2) == B/(num*2)){
           if (A % (num * 2) >= num) {
               a = (A % (num * 2)) - num + 1  - 1;
           } else {
               a = 0;
           }

           if (B % (num * 2) >= num) {
               b = (B % (num * 2)) - num + 1;
           } else {
               b = 0;
           }



       }else {
           if (A % (num * 2) >= num) {
               a = (num * 2) - (A % (num * 2));
           } else {
               a = num;
           }

           if (B % (num * 2) >= num) {
               b = (B % (num * 2)) - num + 1;
           } else {
               b = 0;
           }

       }
       ans += num * ((a+b) % 2);
       num = num * 2;
   }

   cout << ans << endl;

}






Measured memory_bytes: 256
/**
*    created: 03.07.2020 02:40:22
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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 long double pi = acos(-1.0);
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

int l[10000];


signed main() {

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

    
    int n;
    cin >> n;

    l[0] = 2;
    l[1] = 1;
    rep2(i,2,100) {
        l[i] = l[i-1] + l[i-2];
    } 
    cout << l[n] << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(void){
  int n, a, b;
  cin >> n >> a >> b;
  int big, small;
  if (a >= b) {
    big = b;
  } else {
    big = a;
  }
  small = n - a - b;
  if (small < 0) small = 0 - small;
  else small = 0;
  cout << big << " " << small;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
 
using namespace std;
 
#define PB(x)	push_back(x)
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP(x)	make_pair(x)
 
#define debug(_x)		cerr << #_x << '=' << _x << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << _x << ' ' << #_y << '=' << _y << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << _x << ' '; cerr << endl;
 
#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)
 
#define int long long int
 
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef unsigned long long ull;
 
const int INF = LONG_LONG_MAX >> 1;
const int NINF = LONG_LONG_MIN;
const int mmod = 100000000000ll;

int used[3][3];

int32_t main() {
	FAST_IO;
	
	int A[3][3];
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++) cin >> A[i][j];
		
	int N;
	cin >> N;
	set<int> b;
	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;
		b.insert(x);
	}
	
	
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++) {
			if (b.find(A[i][j]) != b.end())
				used[i][j] = true;
		}
	
	if (used[0][0] == 1 && used[1][0] == 1 && used[2][0] == 1) {
		cout << "Yes" << endl;
	} else if (used[0][1] == 1 && used[1][1] == 1 && used[2][1] == 1) {
		cout << "Yes" << endl;
	} else if (used[0][2] == 1 && used[1][2] == 1 && used[2][2] == 1) {
		cout << "Yes" << endl;
	} else if (used[0][0] == 1 && used[0][1] == 1 && used[0][2] == 1) {
		cout << "Yes" << endl;
	} else if (used[0][0] == 1 && used[0][1] == 1 && used[0][2] == 1) {
		cout << "Yes" << endl;
	} else if (used[1][0] == 1 && used[1][1] == 1 && used[1][2] == 1) {
		cout << "Yes" << endl;
	} else if (used[2][0] == 1 && used[2][1] == 1 && used[2][2] == 1) {
		cout << "Yes" << endl;
	} else if (used[0][0] == 1 && used[1][1] == 1 && used[2][2] == 1) {
		cout << "Yes" << endl;
	} else if (used[0][2] == 1 && used[1][1] == 1 && used[2][0] == 1) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main() {
    double x1, x2, x3, px, y1, y2, y3, py,r;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        if (y1 == y2) {
            px = (x1 + x2) / 2;
            py = (x1 - x3)*(x2 - x3) / (2 * (y3 - y1)) + (y1 + y3) / 2;
        }
        else if (y1 == y3) {
            px = (x1 + x3) / 2;
            py = (x1 - x2)*(x3 - x2) / (2 * (y2 - y1)) + (y1 + y2) / 2;
        }
        else {
            px = ((x1*x1 - x2*x2) / (y2 - y1) - (x1*x1 - x3*x3) / (y3 - y1) + y3 - y2) / (2 * ((x1 - x2) / (y2 - y1) - (x1 - x3) / (y3 - y1)));
            py = (px - (x1 + x2) / 2)*(x1 - x2) / (y2 - y1) + (y1 + y2) / 2;
        }
        r = sqrt((px - x1)*(px - x1) + (py - y1)*(py - y1));
        printf("%.3f %.3f %.3f\n", px, py, r);
    }
    return 0;
}

Measured memory_bytes: 3152
n = int(input())
a = list(map(int, input().split()))
mod =10**9+7

b = [format(x,'b').zfill(60) for x in a]

ones = [0 for i in range(60)]
for x in b:
    for i in range(60):
        if x[59-i]=='1':
            ones[i] += 1

pow_two = [pow(2,i,mod) for i in range(60)]

ans = 0
for i in range(60):
    ans += ones[i]*(n-ones[i])*pow_two[i]
    ans %= mod
print(ans)

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

using namespace std;
const int N = 2e5 + 3;
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
#endif
	int n, cur = 0, x, res;
	scanf("%d %d", &n, &x);
	for (res = 0; cur <= x && res <= n; ++res) {
		int a;
		scanf("%d", &a);
		cur += a;
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 256
n,m=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
a=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

a.sort(reverse=True)

s=sum(a)

if a[m-1]*m*4>=s:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	vector<long long> csum(n);
	
	// input
	for(int i=0; i<n; i++){
		cin >> a[i];
	}

	csum[0] = a[0];
	for(int i=1; i<n; i++){
		csum[i] = csum[i-1] + a[i];
	}

	long long imid;
	double min_diff = 2020202020;
	double mid = csum[n-1]/((double) 2);

	for(int i=0; i<n; i++){
		if(min_diff > fabs(csum[i]-mid)){
			min_diff = fabs(csum[i]-mid);
			imid = i;
		}
	}

	cout << abs((csum[imid])-(csum[n-1]-csum[imid])) << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,i,flag=1,p;
  map<long long int,long long int > ma;
  cin>>n;
  for(i=0;i<n;i++)
  {
    cin>>p;
    if(ma[p]==0)
    {
      ma[p]++;
    }
    else
    {
      flag=0;
    }
  }
  if(flag==0)
    cout<<"NO";
  else cout<<"YES\n";
  return 0;
}

Measured memory_bytes: 12800
s=list(input())
t=list(input())

a=len(s)
b=len(t)

ans=[]
ans1=[]

if b>a:
  print('UNRESTORABLE')
  

else:
  for i in range(a-b+1):
    ch=0
    for j in range(b):
      if s[i+j]==t[j] or s[i+j]=='?':
        ch+=1
        
    if ch==b:
      ans.append(i)
      
  if len(ans)==0:
    print('UNRESTORABLE')
    
  else:
    for k in ans:
      r=[]
      for h in range(a):
        if s[h]=='?':
          r.append('a')
        else:
          r.append(s[h])
       
      f=0
      for l in range(k,k+b):
        r[l]=t[f]
        f+=1
        
      ans1.append(r)
    ans2=[]
    for w in ans1:
      u=''.join(w)
      ans2.append(u)
    
    ans2.sort()
    print(ans2[0])

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

int main()
{
    int n,k,s;
    cin >> n >> k >> s;
    int f=1,f1=0;
    if(s%2);
    else
    f1=1;
    for(int i=0;i<n;i++)
    {
        if(k-->0)
        cout << s << " ";
        else if(s<1000000000)
        cout << 1000000000 << " ";
        else
        cout << 999999999 << " ";
    }
    return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>

#include <string.h>
#define inf 0x7fffffff
using namespace std;
//1232
int a,b,c,k,n,m,l[5200][5010],j[100010],o[100200],i,d,dx[10]={0,1,0,-1},dy[10]={1,0,-1,0};
long long x,y,z;
stack<int> s;
struct P
{
    int x;
    int y;
    bool operator<(const P &a)const
    {
        return y>a.y;
    }
};

 map<int, int> p;
queue<P> q;
priority_queue<int> q1;
string r,r1[110];
//char r[2000000],r1[5000000];
vector<P> v[5010];

bool sdf(int a,int b)
{
    if(l[a]!=l[b])
    return l[a]<l[b];
        else
        return l[a+c]<l[b+c];
}

//alohomora
int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;)
        k++,t+=k;
    printf("%d",k);
    return 0;
}

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

int main(){
  int A,B;
  cin >> A >> B;
  if((B-1)%(A-1)==0){
    cout << (B-1)/(A-1) <<endl;
  }else{
  cout << (B-1)/(A-1)+1 <<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int w,h;
int mp[20][20],memo[20][20];
void saiki(int x,int y){
  if(y >= h-1) memo[y][x]++;
  else {
    for(int i=-1;i<=1;i++) {
      int nx = x+i, ny = y+1;
      if(nx==x && mp[ny][nx] == 2)while(mp[ny][nx] == 2) ny+=2;
      if(nx <0|| nx >= w ||mp[ny][nx] == 1) continue;

      if(memo[ny][nx]>0&&mp[ny][nx]==0) memo[y][x] += memo[ny][nx];
      else if(mp[ny][nx] == 0)saiki(nx,ny),memo[y][x] += memo[ny][nx];

    }
    if(memo[y][x] == 0) mp[y][x] = 1;
  }
}
int main() {
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    for(int i=0;i<=19;i++)
      for(int j=0;j<=19;j++)memo[i][j] = mp[i][j] = 0;
     
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin >> mp[i][j];
  
    for(int i=0;i<w;i++)
      if(mp[0][i] !=1) saiki(i,0);
     
    int cnt = 0;
    for(int i=0;i<w;i++)cnt+=memo[0][i];
    cout <<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  1e5 + 10 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , x , k , Q , ans ; string s,t;
double dp[305][305][305];
double solve(int i , int j , int k){

    if(i == 0 && j == 0 && k == 0)
        return 0.0;

    double &ret = dp[i][j][k];

    if(ret != -1)
        return ret;

    ret = (double)n/(double)(i + j + k);

    if(i > 0)
        ret += (double)i/(double)(i + j + k)*solve(i - 1,j,k);
    if(j > 0)
        ret += (double)j/(double)(i + j + k)*solve(i + 1,j - 1,k);
    if(k > 0)
        ret += (double)k/(double)(i + j + k)*solve(i , j + 1 , k - 1);

    return ret ;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//   freopen("test.in","r",stdin);

    cout<<setprecision(10)<<fixed;
    cin>>n;
    int one = 0 , two = 0 , three = 0;

    for(int i = 0 ; i < n ; ++i){
        cin>>x;
        if(x == 1) one++;
        if(x == 2) two++;
        if(x == 3) three++;
    }

    for(int i = 0 ; i<= n ; ++i)
        for(int j = 0 ; j<=n ; ++j)
            for(int k = 0 ; k<=n ; ++k)
                dp[i][j][k] = -1;

    cout<<solve(one,two,three)<<'\n';


    return 0;
}


Measured memory_bytes: 219520
m=([0]*14).map{[0]*14}
while l=gets
x,y,t=l.split(',').map{|i|i.to_i+2}
m[x][y]+=1
m[x-1][y]+=1
m[x+1][y]+=1
m[x][y-1]+=1
m[x][y+1]+=1
if t>3
m[x-1][y-1]+=1
m[x-1][y+1]+=1
m[x+1][y-1]+=1
m[x+1][y+1]+=1
if t>4
m[x-2][y]+=1
m[x+2][y]+=1
m[x][y-2]+=1
m[x][y+2]+=1
end
end
end
m=m[2..11].map{|i|i[2..11]}.flatten
p m.count(0),m.max

Measured memory_bytes: 6132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

vector <ll> color(10000, 0);
vector <ll> d(10000, INF);
priority_queue <pair <ll, ll>> pq;
vector <vector <pair <ll, ll>>> m(10000, vector <pair <ll, ll>> ());
ll n;

void dijkstra() {
  d.at(0) = 0;
  pq.push(make_pair(0, 0));
  while (!pq.empty()) {
    pair <ll, ll> u = pq.top();
    pq.pop();
    color.at(u.second) = 2;
    if (d.at(u.second) < u.first*(-1)) continue;
    rep(i, m.at(u.second).size()) {
      pair <ll, ll> v = m.at(u.second).at(i);
      if (color.at(v.first) != 2) {
        if (d.at(u.second)+v.second < d.at(v.first)) {
          d.at(v.first) = d.at(u.second)+v.second;
          color.at(v.first) = 1;
          pq.push(make_pair(d.at(v.first)*(-1), v.first));
        }
      }
    }
  }
}

int main() {
  cin >> n;
  rep(i, n) {
    ll u, k;
    cin >> u >> k;
    rep(j, k) {
      ll v, c;
      cin >> v >> c;
      m.at(u).push_back(make_pair(v, c));
    }
  }
  dijkstra();
  rep(i, n) {
    cout << i << ' ' << d.at(i) << endl;
  }
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    ll n;

    cin>> n;

    ll c= 0, t;

    for(ll i=0; i<n; i++)
    {
        cin>> t;

        while ( t%2== 0)
        {
             c++;
             t/=2;
        }

    }

    cout << c;
    nl;
    return 0;
}




Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define For(i, l, r) for(register int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(register int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

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

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

const int N = 110;
int a[N], b[N], c[N], d[N];

int g[N][N], match[N], n, m;
bool vis[N];

bool dfs (int now){
	For (i, 1, n) {
		if (g[now][i] && !vis[i]){
			vis[i] = true;
			if (!match[i] || dfs(match[i])){
				match[i] = now;
				return true;
			}
		}
	}
	return false;
} 

int main () {
	n = read();
	For (i, 1, n) a[i] = read(), b[i] = read();
	For (i, 1, n) c[i] = read(), d[i] = read();
	For (i, 1, n) For (j, 1, n) if (a[i] < c[j] && b[i] < d[j]) g[i][j] = true;

	int ans = 0;
	For (i, 1, n) { Set (vis, false); if (dfs(i)) ans++; }
	cout << ans << endl;
	return 0;
}


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

using namespace std;


inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

void solve() {
    int N; cin >> N;
    map<string, int> mp;
    mp["AC"] = 0;
    mp["WA"] = 0;
    mp["TLE"] = 0;
    mp["RE"] = 0;

    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        mp[s]++;
    }

    print("AC", "x", mp["AC"]);
    print("WA", "x", mp["WA"]);
    print("TLE", "x", mp["TLE"]);
    print("RE", "x", mp["RE"]);
}


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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch WhenIHitMyPocket | diff WhenIHitMyPocket.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address WhenIHitMyPocket.cpp && ./a.out

/*
 
 3/3/2019
 
 20:01-20:36 misunderstanding of problem statement. Fuck.
 
 
 */

LL K,A,B;

LL solve() {
  if(B-A<=2) return K+1;
  if(K<A+1) return K+1;
  LL C=(A+B-2)/(B-1);
//  dump(C,K<(A+1)*C);
  if(K<(A+1)*C) {
    LL cycle=K/(A+1),a=(B-1)*cycle,b=K%(A+1);
//    dump(cycle,a,b)
    return 1+a+b;
  } else {
    LL a=(B-1)*C,rem=K-(A+1)*C,b=rem/2*(B-A),c=rem%2;
    return 1+a+b+c;
  }
}

LL solve_wrong() {
  if(B==1||(A==1&&B==2)) return K+1;
  LL cycle=K/(A+1);
  LL res=cycle*(A*B-1);
  dump(cycle,A*B-1,res);
  K=K%(A+1);
  res+=max(K,B*(K-1)-1);
  dump(K,res);
  
  /*
  if(K==1) res+=K;
  else if(B==2&&K<=3) res+=K;
  else if(B==3&&K<=2) res+=K;
  else res+=B*(K-1)-1;*/
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>K>>A>>B;
  cout<<solve()<<endl;
  
  return 0;
}


Measured memory_bytes: 256
fun main() {
    val digits = readLine()!!.trim().toCharArray().map{it - '0'}.toIntArray()
    val mod = 2019
    var digit = 1
    for (i in digits.indices.asIterable().reversed().drop(1)) {
        digit = digit * 10 % mod
        digits[i] = (digits[i + 1] + digits[i] * digit) % mod
    }
    val counts= IntArray(mod){0}.also{it[0] = 1}
    for (d in digits) {
        counts[d]++
    }
    println(
        counts.map{(it * (it - 1L)) shr 1}.sum()
    )
}


Measured memory_bytes: 53236
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	vector<int> C(N);
	vector<pair<int, int> > T(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> T[i].second;
	}
	for (int i = 0; i < N; i++) {
		cin >> T[i].first;
	}
	sort(T.begin(), T.end());
	for (int i = 0; i < N; i++) {
		A[i] = T[i].second;
		B[i] = T[i].first;
	}
	C = A;
	sort(C.begin(), C.end());
	for (int i = 0; i < N; i++) {
		if (C[i] > B[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	bool ok = false;
	for (int i = 0; i < N - 1; i++) {
		if (C[i + 1] <= B[i]) {
			ok = true;
		}
	}

	if (ok) {
		cout << "Yes" << endl;
		return 0;
	}



	map<int, int> mp;
	for (int i = 0; i < N; i++) {
		mp[C[i]] = i;
	}
	vector<int> P(N);
	for (int i = 0; i < N; i++) {
		P[i] = mp[A[i]];
	}
	int a = 0;
	int cnt = 0;
	while (true) {
		a = P[a];
		cnt++;
		if (a == 0)break;
	}
	//cerr << cnt << endl;
	if (cnt == N) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}

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

#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  solve();
  return 0;
}

void solve() {
  int n, a;
  std::cin >> n >> a;
  cout(std::max((int)0, n * n - a));
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>

#include <iomanip>
#include <list>
#define fo(i,n) for(int i=0;i<n;i++)
#define ll long long


using namespace std;
int main(){
int n,k=0;
cin>>n;
int a[n];
int b[n];
fo(i,n){
    cin>>a[i];
    b[i]=0;
}
fo(i,n){
   b[a[i]-1]=i+1;
}
fo(i,n){
    cout<<b[i]<<" ";
}
}

Measured memory_bytes: 1536
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N=nextInt();
		int A=nextInt();
		int B=nextInt();

		long ans =0;
		for(int i=1;i<=N;i++){
			int tmp = i;
			int sum=0;
			while(tmp>=10){
				sum+=tmp%10;
				tmp=tmp/10;
			}
			sum+=tmp;
			if(A<=sum && sum <=B){
				ans+=i;
			}
		}

		System.out.println(ans);




	}




	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21332
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, X = LI()
    L = LI()
    ans = 1
    d = 0
    for l in L:
        d += l
        if d > X:
            break
        ans += 1
    return ans

print(main())

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramB
    {
        static void Main()
        {
            System.Console.WriteLine(Line.Replace("?", "D"));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  ll n, k;
  cin >> n >> k;
  vl 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){
    int v = i;
    ll cycle_sum = 0;
    int cycle_cnt = 0;
    
    while(true){
      cycle_cnt++;
      cycle_sum += c[v];
      v = p[v];
      
      if(i == v)
        break;
    }
    
    ll path = 0;
    int cnt = 0;
    
    while(true){
      cnt++;
      path += c[v];
      
      if(cnt > k)
        break;
      
      int num = (k-cnt)/cycle_cnt;
      ll score = path + max(0LL, cycle_sum)*num;
      ans = max(ans, score);
      
      v = p[v];
      if(v == i)
        break;
    }
  }
  
  cout << ans << endl;
  
  return 0;
  
}

Measured memory_bytes: 3716
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

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

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

void f(ll rest,string s){
    if(rest==0){
        cout<<s<<endl;
    }else{
        for(char c='a';c<='c';c++){
            f(rest -1,s+c);
        }
    }
}


int main(){
    ll c[3][3];
    rep(i,3) rep(j,3) cin>>c[i][j];
    
    ll a[3]={c[0][0]+c[0][1]+c[0][2],c[1][0]+c[1][1]+c[1][2],c[2][0]+c[2][1]+c[2][2]};
    ll b[3]={c[0][0]+c[1][0]+c[2][0],c[0][1]+c[1][1]+c[2][1],c[0][2]+c[1][2]+c[2][2]};
    rep(i,3){
        for(ll j=0;j<3;j++){
            if(abs(a[i]-a[j])%3!=0){
                cout<<"No"<<endl;
                return 0;
            }if(abs(b[i]-b[j])%3!=0){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(); 
        int b = sc.nextInt();
        int c;
        int [] in = new int [a];
        for(int i=0;i<2*b;i++){c = sc.nextInt();
                              in[c-1]++;}       
        for(int i=0;i<a;i++){System.out.println(in[i]);}
	}
}


Measured memory_bytes: 23892
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

def check(cir,num):
    m = len(cir)
    a = sum(cir)
    if num == 0:
        ss = 0
    elif num == 1:
        ss = max(cir)
    else:
        ac = list(accumulate([0]+cir))
        l = 0
        r = 1
        ss = ac[r]-ac[l]
        i = 0
        while 1:
            if r == m:
                l = ac[l+1:r].index(min(ac[l+1:r])) + l+1
                ss = max(ss,ac[r]-ac[l])
                break
            elif i%2==0:
                r = ac[r+1:l+num+1].index(max(ac[r+1:l+num+1])) + r+1
            else:
                l = ac[l+1:r].index(min(ac[l+1:r])) + l+1
            i+=1
            ss = max(ss,ac[r]-ac[l])

        num = m-num
        l = 0
        r = num
        i = 0
        ss = max(ss,a-ac[r]+ac[l])
        while 1:
            if r == m:
                l = ac[l+1:r-num+1].index(max(ac[l+1:r-num+1])) + l+1
                ss = max(ss,a-ac[r]+ac[l])
                break
            elif i%2==0:
                r = ac[r+1:l+m].index(min(ac[r+1:l+m])) + r+1
            else:
                l = ac[l+1:r-num+1].index(max(ac[l+1:r-num+1])) + l+1
            i+=1
            ss = max(ss,a-ac[r]+ac[l])
    return ss


from itertools import accumulate

n,k = readints()
p = [x-1 for x in readints()]
c = readints()

circles = []
used = [0]*n

for i in range(n):
    if not used[i]:
        circles.append([c[i]])
        used[i] = 1
        j = p[i]
        while not used[j]:
            circles[-1].append(c[j])
            used[j] = 1
            j = p[j]

score = -10**20

for cir in circles:
    m = len(cir)
    a = sum(cir)
    if k>m:
        if a>0:
            score = max(score, (k//m)*a + check(cir,k%m), (k//m-1)*a + check(cir,m))
        else:
            score = max(score,check(cir,m))
    else:
        score = max(score,check(cir,k))

print(score)










Measured memory_bytes: 75132
#include<bits/stdc++.h>
using namespace std;
int main(){
    long n;
    int i=1;
    int j=1;
    cin>>n;
    long rep=(long)sqrtl((double)n);
    long x,y;
    for (long i = rep; i >= 1; i--)
    {
        if(n%i==0){
            x=i;
            y=n/i;
            cout<<x+y-2<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char a[4];
	int num[4],i;
	scanf("%s",a);
	for(i=0;i<4;i++)
	{
		num[i]=a[i]-'0';
	}
	if(num[0]+num[1]+num[2]+num[3]==7)
	{
		printf("%d+%d+%d+%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]-num[1]+num[2]+num[3]==7)
	{
		printf("%d-%d+%d+%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]-num[1]-num[2]+num[3]==7)
	{
		printf("%d-%d-%d+%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]-num[1]-num[2]+num[3]==7)
	{
		printf("%d-%d-%d+%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]-num[1]-num[2]-num[3]==7)
	{
		printf("%d-%d-%d-%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]-num[1]+num[2]-num[3]==7)
	{
		printf("%d-%d+%d-%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]+num[1]-num[2]+num[3]==7)
	{
		printf("%d+%d-%d+%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]+num[1]+num[2]-num[3]==7)
	{
		printf("%d+%d+%d-%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]+num[1]-num[2]-num[3]==7)
	{
		printf("%d+%d-%d-%d=7\n",num[0],num[1],num[2],num[3]);
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;
typedef vector<vi> mat;
inline ll read(){
	ll Hashimoto=0,Kanna=1;
	char I_Love=getchar();
	while(I_Love<'0'||I_Love>'9'){
		if(I_Love=='-')Kanna=-1;
		I_Love=getchar();
	}
	while(I_Love>='0'||I_Love<='9'){
		Hashimoto=Hashimoto*10+I_Love-'0';
		I_Love=getchar();
	}
	return Hashimoto*Kanna;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<Kanna;I_Love++)cout<<Hashimoto[I_Love]<<(I_Love==Kanna-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<Kanna;I_Love++)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

int n;

int I_Love_Hashimoto_Kanna() {
  fastio;
  cin>>n;
  int ans=0;
	FOR(i,0,n){
  	int x;
  	cin>>x;
  	while(x%2==0)x/=2,ans++;
	}
	Tone(ans);
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	if(x==2||y==2)
	{
		printf("No\n");
	}
	else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11))
	{
		printf("Yes\n");
	}
	else if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12))
	{
		printf("Yes\n");
	}
	else 
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for( auto &k : a ) cin >> k;
	vector<int> b(a);
	sort( b.begin(), b.end() );
	vector<int> even;
	vector<int> odd;
	for( int i = 0; i < n; ++i ){
		if( i % 2 == 0 ) even.push_back(b[i]);
		else odd.push_back(b[i]);
	}
	int cnt = 0;
	for( int i = 0; i < n; ++i ){
		if( i % 2 == 0 && !( binary_search( even.begin(), even.end(), a[i] ) ) ){
			++cnt;
		} else if( i % 2 == 1 && !( binary_search( odd.begin(), odd.end(), a[i]) ) ){
			++cnt;
		}
	}
	cout << cnt/2 << endl;
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
typedef long long ll;
map<int, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<bool> counter(4);
	for (int i = 0; i < 4; i++) counter[i] = false;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s.at(i) == 'N') counter[0] = true;
		else if (s.at(i) == 'W') counter[1] = true;
		else if (s.at(i) == 'S') counter[2] = true;
		else counter[3] = true;
	}
	if ((counter[0] == true && counter[2] == false) || (counter[0] == false && counter[2] == true) || (counter[1] == true && counter[3] == false) || (counter[1] == false && counter[3] == true)) {
		cout << "No\n";
	}
	else cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 256