akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%ull",&n)
#define ull             unsigned long long int
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod 998244353
#define var    int i,j,k,z=0,c=0,t,x,y,l,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

ll n,m,cnt[1000005],csum[1000005],inv[1000005];

void inverse(ll m)
{
    //m is prime;
    inv[1] = 1;
    for(int i = 2; i < 1000004; ++i)
    inv[i] = (m - (m/i) * inv[m%i] % m) % m;
}

int main()
{
    //freopen("lcm.in","r",stdin);
    ll var;
    inverse(mod);
    //sfl(t);
    t=1;
    while(t--)
    {
        sfl(n);
        z=0;y=0;
        for(i=0;i<n;i++)
        {
            sfl(x);
            cnt[x]++;
            z=max(z,x);
            y+=(x);
        }
        y%=mod;
        ll ans=0;
        for(i=z;i>=1;i--)
        {
            c=0;
            for(j=i;j<=z;j+=i)
            {
                c+=(cnt[j]*j);
                csum[i]-=csum[j];
                if(csum[i]<0)csum[i]+=mod;
            }
            c%=mod;
            csum[i]+=(c*c);csum[i]%=mod;
            ans+=(csum[i]*inv[i]);
            ans%=mod;
        }
        ans-=y;ans+=mod;ans%=mod;
        ans*=inv[2];ans%=mod;
        pf("%lld\n",ans);
        for(i=z;i>=1;i--)
        {
            cnt[i]=0;csum[i]=0;
        }
    }
}


Measured memory_bytes: 23680
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;



int main(){
	lli N,K;
	cin>>N>>K;
	
	if(K%2){
		lli x=N/K;
		cout<<x*x*x;
	}
	else{
		lli k=K/2;
		lli x=N/k;
		lli y=x/2;
		lli z=x-y;
		cout<<y*y*y+z*z*z;
	}
}

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

int N;
int K;
int D[10] = {0};

int main() {
    scanf("%d%d", &N, &K);
    
    memset(D, 0, sizeof(D));
    for (int i = 0; i < K; i++) {
        int x;
        scanf("%d", &x);
        D[x] = 1;
    }
    int r = N;
    while (r < 10 * N) {
        int x = r;
        while (x) {
            if (D[x % 10]) break;
            x /= 10;
        }
        if (x == 0) break;
        r++;
    }
    printf("%d\n", r);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll M;
    cin >> M;
    ll K;
    cin >> K;
    if(K>=(1<<M)){
        prt(-1)
        return 0;
    }
    if(M==1){
        if(K==0)prt("0 0 1 1")
        else prt(-1)
        return 0;
    }
    set<ll> A,B;
    for(ll i=0;i<(1<<M);++i)A.insert(i);
    for(ll i=0;i<M;++i){
        if(K&(1<<i)){A.erase(1<<i);
        B.insert(1<<i);}
    }
    for(auto x=A.begin();x!=A.end();x++){
        cout<<*x<<" ";
    }
    for(auto x=B.begin();x!=B.end();x++){
        cout<<*x<<" ";
    }
    for(auto x=prev(A.end());;x--){
        cout<<*x<<" ";if(x==A.begin())break;
    }
    if(!B.empty())
    for(auto x=prev(B.end());;x--){
        cout<<*x<<" ";if(x==B.begin())break;
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 7936
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)1e9+7)
#define MAX ((ull)1e6)

int main(){
	int n;
	cin >> n;
	ull a[n], b[n], c[n];
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++) cin >> b[i];
	for(int i=0; i<n; i++) cin >> c[i];
	sort(a, a+n);
	sort(c, c+n);

	ull ans=0;
	for(int i=0; i<n; i++){
		ans+=(lower_bound(a, a+n, b[i])-a)*(n-(upper_bound(c, c+n, b[i])-c));
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    map<char, int> cnt;
    for(auto i : s){
        cnt[i]+=1;
        if(cnt[i]>2){
            cout << "No" << endl;
            return 0;
        }
    }
    if(cnt.size()==2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
       
        int num = scan.nextInt();
        int mod = num % 10;
        
		if ( (mod == 2) || (mod == 4) || (mod == 5) || (mod == 7) || (mod == 9) ) {
		    System.out.println("hon");	
		}
        else if ( mod == 0 ||  mod == 1 ||  mod == 6 ||  mod == 8 ) {
            System.out.println("pon");
        }
        else {
            System.out.println("bon");
        }
        scan.close();
    }
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n, l;
    cin >> n >> l;
    int t[n];
    rep(i, n) { t[i] = l + (i + 1) - 1; }
    auto c = [](int a, int b) { return abs(a) < abs(b); };
    sort(t, t + n, c);
    ll sum = 0;
    repd(i, 1, n) { sum += t[i]; }

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

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
 
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL D,T,S;
 
string ans = "Yes";

void solve(){
	if(S*T<D) ans = "No";
}
 
int main(){
    cin >> D >> T >> S;
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
#define MAX 2000000
#define INFTY 2000000001
int T[MAX + 1];
int size;
void maxheap(int i)
{
	int l, r, max_k;
	l = i * 2;
	r = l + 1;
	if (r <= ::size)
	{
		max_k = max({ T[i],T[l],T[r] });
		if (max_k == T[l])
		{
			swap(T[i], T[l]);
			maxheap(l);
		}
		else if (max_k == T[r])
		{
			swap(T[i], T[r]);
			maxheap(r);
		}
	}
	else if (l == ::size)
	{
		if (T[l] > T[i])swap(T[l], T[i]);
		maxheap(l);
	}
}

void heapIncreaseKey(int i, int k)
{
	if (k < T[i])return;

	T[i] = k;
	int l = i;
	int p = l / 2;
	while (l > 1 && T[p] < T[l])
	{
		swap(T[p], T[l]);
		l = p;
		p = l / 2;
	}
}

void insert(int key)
{
	::size++;
	T[::size] = -INFTY;
	heapIncreaseKey(::size, key);
}

int heapExtractMax()
{
	if (::size < 1)return -1;
	int max = T[1];
	T[1] = T[::size];
	::size--;
	maxheap(1);
	return max;
}

int main()
{
	::size = 0;
	char str[10];
	while (1)
	{
		scanf("%s", &str);
		if (str[0] == 'i')
		{
			int k;
			scanf("%d", &k);
			insert(k);
		}
		else
		{
			if (str[1] == 'x')
			{
				printf("%d\n", heapExtractMax());
			}
			else
			{
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

ll powmod(ll a, ll b, ll m = mod) {
    int res = 1;
    while (b > 0) {
        if (b & 1) {
            res = (res * a) % m;
            --b;
        } else {
            a = (a * a) % m;
            b >>= 1;
        }
    }
    return res % m;
}

ll rev(ll n) {
    return powmod(n, mod - 2);
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<int> primes(1e6 + 1, 0);
    ll ans = 0;
    for (auto &i:a) {
        cin >> i;
        ans += rev(i);
        for (int j = 2; j * j <= i; ++j) {
            if (i % j == 0) {
                int pow = 0;
                while (i % j == 0) {
                    i /= j, pow++;
                }
                primes[j] = max(primes[j], pow);
            }
        }
        if (i != 1) {
            primes[i] = max(primes[i], 1);
        }
    }
    for (int i = 2; i <= 1e6; ++i) {
        if (primes[i] != 0) {
            (ans *= powmod(i, primes[i])) %= mod;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4224
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

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

  cout.precision(16);
  cout << fixed;

  int n;
  cin >> n;

  int ans = 0;

  for (int i = 1; i <= n; ++i) {
    if (to_string(i).length() % 2 == 0) {
      i *= 10;
      
      --i;

      continue;
    }

    ++ans;
  }

  cout << ans;
}


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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
string kasanari(string s1,string s2){
    vector<char> s1_c;
    vector<char> s2_c;
    REP(i,s1.size()){
        s1_c.push_back(s1[i]);
    }
    REP(i,s2.size()){
        s2_c.push_back(s2[i]);
    }
    sort(s1_c.begin(),s1_c.end());
    sort(s2_c.begin(),s2_c.end());
    string ans;ans="";
    int k=0;
    REP(i,s1_c.size()){
        for(int j=k;j<s2_c.size();j++){
            if(s1_c[i]==s2_c[j]){
                ans.push_back(s1_c[i]);
                k=j+1;
                break;
            }
        }
    }
    return ans;
}
int main() {
    //COMint();
    int n=in();
    string ans;
    string s=in<string>();
    vector<char> s_c;
    if(n==1){
        REP(i,s.size()){
            s_c.push_back(s[i]);
        }
        sort(s_c.begin(),s_c.end());
        REP(i,s_c.size()){
            ans.push_back(s_c[i]);
        }
        cout<<ans<<endl;
        return 0;
    }
    string s_next;
    cin>>s_next;
    ans=kasanari(s,s_next);
    REP(i,n-2){
        cin>>s_next;
        ans=kasanari(ans,s_next);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($( { splits.next().unwrap().parse::<$t>().unwrap() },)*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (h, a) = input!(u64, u64);

    let n = h / a;
    if h % a == 0 {
        println!("{}", n);
    } else {
        println!("{}", n + 1);
    }
}

fn main() {
    solve();
}


Measured memory_bytes: 4352
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;

    int ac = 0;
    vector <bool> aced(n, false);
    vector <int> wa_count(n, 0);

    for (int i = 0; i < m; i++) {
        int p;
        string s;
        cin >> p >> s;
        p--;

        if (!aced[p]) {
            if (s == "WA") {
                wa_count[p]++;
            } else {
                ac++;
                aced[p] = true;
            }
        }
    }

    int wa = 0;
    for (int i = 0; i < n; i++) {
        if (aced[i]) {
            wa += wa_count[i];
        }
    }

    cout << ac << ' ' << wa << "\n";
    return 0;
}

Measured memory_bytes: 888
#include <cstdio>
using namespace std;
inline int rd()
{
	int x=0,p=1;
	char a=getchar();
	while((a<48||a>57)&&a!='-')a=getchar();
	if(a=='-')p=-p,a=getchar();
	while(a>47&&a<58)
	{
		x=(x<<1)+(x<<3)+(a&15);
		a=getchar();
	}
	return x*p;
}
int n;
int main()
{
	scanf("%d",&n);
	printf("%.10lf\n",1.0*(n/2+(n%2))/n);
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(1000000)

MOD = 1000000007

def dfs(par, v):
    val = nColors - 1 if par == 0 else nColors - 2
    for child in edges[v]:
        if child != par:
            ways[child] = max(0, val)
            val -= 1
            dfs(v, child)

nVertices, nColors = map(int, input().split())
edges = [[] for _ in range(nVertices + 1)]
for _ in range(nVertices - 1):
    u, v = map(int, input().split())
    edges[u].append(v)
    edges[v].append(u)

ways = [0] * (nVertices + 1)
ways[1] = nColors
dfs(0, 1)
ret = 1
for w in ways[1:]:
    ret = (ret * w) % MOD
print(ret)

Measured memory_bytes: 88172
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}

const int N=300300;
int cnt[N],ans[N];
ll sum[N];

int judge(ll k,int x){return sum[x]>=1ll*k*x;}

int main()
{
	int n;
	read(n);
	for (int x,i=1;i<=n;i++) read(x),cnt[x]++,sum[cnt[x]]++;
	for (int i=1;i<=n;i++) sum[i]+=sum[i-1];
	int now=0;
	for (int k=n;k>=1;k--)
	{
		while (now<n&&judge(k,now+1)) now++;
		ans[k]=now;
	}
	for (int i=1;i<=n;i++) print(ans[i]);
	Ot();
	return 0;
}









Measured memory_bytes: 7936
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long 
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd long long
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
using namespace std;
ll p[5005];
ll par[5005];
ll c[5005];
ll vis[5005];

int main(){
   boost;
   ll mod=1e14+7;
   ll n,k;
   cin>>n>>k;
   ll ans=-mod;
   for(ll i=1;i<=n;i++)cin>>p[i];

   for(ll i=1;i<=n;i++)cin>>c[i],ans=max(ans,c[i]);
   
   if(ans<=0){
   	  cout<<ans;
   	  return 0;
   }
   
   for(ll i=1;i<=n;i++){
   	    vector<ll> val;
   	    ll s=0;
   	    ll sz=0;
   	    for(ll j=1;j<=n;j++)vis[j]=0;
	
   	    ll j=i;
   	    while(vis[j]==0){
   	    	sz++;
   	    	s+=c[j];
			val.pb(c[j]);
   	    	vis[j]=1;
   	    	j=p[j];
   	    }
   	    
   	    
   	    if(sz==0)continue;
   	    if(s>0){
   	    	ll t_ans=0;
   	    	ll lef=k%sz;
   	        t_ans=s*(k/sz);
   	        ans=max(ans,t_ans);
			for(ll j=0;j<lef;j++){
   	        	t_ans=t_ans+val[j];
   	        	ans=max(ans,t_ans);
			}
			if(lef==0){
			  ll u=k/sz;
			  u--;
			  t_ans=(u*s);	
			  for(ll j=0;j<sz;j++){
   	        	t_ans=t_ans+val[j];
   	        	ans=max(ans,t_ans);
			}
				
			}
   	    }
		else{
		
			ll s=0;
			
			for(ll j=0;j<min(sz,k);j++){
				s=s+val[j];
				ans=max(ans,s);
			}
		
		}
   	    
   	    
   	    
   }
  cout<<ans;
   
}
   
	
 
    


Measured memory_bytes: 3892
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int n,m,p,X,Y,Z,res,b[9][9][9];
int dx[] = {1,0,0,1,1,0,-1,-1, 0,1, 1, 1,-1};
int dy[] = {0,1,0,1,0,1, 1, 0,-1,1, 1,-1, 1};
int dz[] = {0,0,1,0,1,1, 0, 1, 1,1,-1, 1, 1};

int check(int col){
  rep(i,n)rep(j,n)rep(k,n){
    if(b[i][j][k]==col){
      rep(t,13){
	int c=0,tx=i,ty=j,tz=k;
	while(c<m && 0<=tx && tx<n && 0<=ty && ty<n && 0<=tz && tz<n){
	  if(b[tx][ty][tz] == b[i][j][k])c++;
	  else break;
	  tx += dx[t]; ty += dy[t]; tz += dz[t];
	}
	if(c==m)return b[i][j][k];
      }
    }
  }
  return -1;
}

int main(){
  std::ios::sync_with_stdio(false);
  while(cin >> n >> m >> p,n+m+p){
    rep(i,n)rep(j,n)rep(k,n)b[i][j][k] = -1;

    bool f = true;
    rep(i,p){
      cin >> X >> Y;
      if(f){
	X--; Y--;Z=0;
	while(b[X][Y][Z]>=0)Z++;
	b[X][Y][Z] = i&1;
	
	res = check(i&1);
	if(res==0){
	  cout << "Black " << i+1 << endl;
	  f = false;
	}else if(res==1){
	  cout << "White " << i+1 << endl;
	  f = false;
	}
      }
    }
    if(f)cout << "Draw\n";
  }
}

Measured memory_bytes: 1200
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


int main(void){
	int n;
	cin >> n;

	bool y = false;

	for(int i = 0; i < n; i++){
		char tmp;
		cin >> tmp;
		if(tmp == 'Y')y = true;
	}
	if(y){
		cout << "Four" << endl;
	} else {
		cout << "Three" << endl;
	}
}


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

int main() {
    int n;
    cin >> n;
    int b[n];
    rep(i, n) cin >> b[i];

    int ans = b[0] + b[n - 2];
    for (int i = 0; i < n - 2; i++) {
        ans += min(b[i], b[i+1]);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong h, w;

int main() {
    cin >> h >> w;

    if (h == 1 || w == 1) cout << 1 << endl;
    else cout << (h * w + 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX_N 15

void rotate90(int r,int c,int size,int a[MAX_N][MAX_N]){
	int b[MAX_N][MAX_N], i, j;

	for(i = 0;i < size;i++){
		for(j = 0;j < size;j++){
			b[r + i][c + j] = a[r + i][c + j];
		}
	}


	for(i = 0;i < size;i++){
		for(j = 0;j < size;j++){
			b[r + i][c + j] = a[size + r - j - 1][c + i];
		}
	}
	for(i = 0;i < size;i++){
		for(j = 0;j < size;j++){
			a[r + i][c + j] = b[r + i][c + j];
		}
	}
}

void rotate(int r,int c,int size,int angle,int a[MAX_N][MAX_N]){
	int i;
	for(i = 0;i < (angle / 90) % 4;i++){
		rotate90(r,c,size,a);
	}
}


void reversal(int r,int c,int size,int a[MAX_N][MAX_N]){
	int i, j;
	for(i = 0;i < size;i++){
		for(j = 0;j < size;j++){
			if(a[r + i][c + j] == 0){
				a[r + i][c + j] = 1;
			}else{
				a[r + i][c + j] = 0;
			}
		}
	}
}

void left_shift(int r,int n,int a[MAX_N][MAX_N]){
	int j, tmp;
	tmp = a[r][0];
	for(j = 1;j < n;j++){
		a[r][j - 1] = a[r][j];
	}
	a[r][n - 1] = tmp;
}

void right_shift(int r,int n,int a[MAX_N][MAX_N]){
	int j, tmp;
	tmp = a[r][n - 1];
	for(j = n - 2;j >= 0;j--){
		a[r][j + 1] = a[r][j];
	}
	a[r][0] = tmp;
}

void island_reversal(int r,int c,int n,int a[MAX_N][MAX_N]){
	int i, j;
	const int dy[4] = {-1,0,0,1}, dx[4] = {0,-1,1,0};

	int tmp = a[r][c];
	a[r][c] = !a[r][c];
	for(i = 0;i < 4;i++){
		if(0 <= r + dy[i] && r + dy[i] < n && 0 <= c + dx[i] && c + dx[i] < n && tmp == a[r + dy[i]][c + dx[i]]){
			island_reversal(r + dy[i],c + dx[i],n,a);
		}
	}
}

int main(void){
	int a[MAX_N][MAX_N], i, j, n, m, ope, r, c, size,angle;


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

	for(i = 0;i < m;i++){

		scanf("%d",&ope);
		switch(ope){
		case 0:
			scanf("%d%d%d%d",&r,&c,&size,&angle);
			rotate(r - 1,c - 1,size,angle,a);
			break;
		case 1:
			scanf("%d%d%d",&r,&c,&size);
			reversal(r - 1,c - 1,size,a);
			break;
		case 2:
			scanf("%d",&r);
			left_shift(r - 1,n,a);
			break;
		case 3:
			scanf("%d",&r);
			right_shift(r - 1,n,a);
			break;
		case 4:
			scanf("%d%d",&r,&c);
			island_reversal(r - 1,c - 1,n,a);
			break;
		}
	}

	for(i = 0;i < n;i++){
		for(j = 0;j < n;j++){
			if(j != 0){
				printf(" ");
			}
			printf("%d",a[i][j]);
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1052
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N, l[100100], num;

int main () {
        cin >> N;
        fo(i, 1, N+1) cin >> l[i];
        fo(i, 1, N+1) if (l[l[i]] == i) {
                num++;
        }

        cout << num/2 << endl;

        return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    int N;
    scanf("%d",&N);
    int a;
    for(int i=N;i>=0;i--)
    {
        a=(int )sqrt(i);
        if(a*a==i)
        {
            printf("%d",i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()
a = n//k
if k % 2 == 0:
    b = n//(k//2) - a
else:
    b = 0

ans = a + max(a*(a-1)*3,0) + max(a*(a-1)*(a-2),0)
ans += b + max(b*(b-1)*3,0) + max(b*(b-1)*(b-2),0)
print(ans)

Measured memory_bytes: 74976
#include<stdio.h>
int main()
{
    int a, b, d;
    scanf("%d %d",&a,&b);
    d = b - a;
    int sum = 0;
    for(int i = 1;i <= d;i++){
        sum += i;
    }
    printf("%d\n", sum - b);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int main() {
	int a,b;
	cin>>a>>b;
	cout<<a*b-a-b+1<<endl;
    return 0;
}


Measured memory_bytes: 256
S = input()
T = input()

replace_min = len(S) + 1

for i in range(len(S) - len(T) + 1):
    count = 0
    for j in range(len(T)):
        if S[j + i] != T[j]:
            count += 1

    replace_min = min(replace_min, count)

print(replace_min)

Measured memory_bytes: 8980
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
 
#define pb(x) push_back(x)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()
 
#define INF 2123456789
#define IINF 9123456789123456789
 
void use_cio() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

//--------------------------------------------------//
int n, m;
int main() {
    use_cio();
    cin >> n >> m;
    cout << (1LL * n * m - n - m + 1);
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))

def insertSort(A,N):
    for i in range(N):
        v=A[i]
        j= i-1
        while j>=0 and A[j]>v:
            A[j+1]=A[j]
            j-=1
        A[j+1]=v
        print(' '.join(list(map(str,A))))

insertSort(A,N)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  string s;
  cin>>s;
  int n=s.length();
  REP(i,0,n){
    REP(j,i,n){
      string t=s.substr(0,i)+s.substr(j,n-1);
      //DUMP(i,j,a.str());
      if(t == "keyence"){
        cout<<"YES";
        return 0;
      }
    }
  }
  cout<<"NO";

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 100005

ll inv[N], fac[N], finv[N];

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

ll C(ll n, ll k)
{
	if(n < k || n < 0) return 0;
	return fac[n] * finv[n - k] % MOD* finv[k] % MOD;
}

ll gcd(ll a, ll b)
{
	if(b == 0)
		return a;
	return gcd(b, a % b);
}
#define N 100005
int n;
int h[N];
int dp[N];
int dpf(int i)
{
	if(i >= n)
		return 1e9;
	if(i == n - 1)
		return 0;
	if(dp[i] >= 0)
		return dp[i];
	return dp[i] = min(abs(h[i + 1] - h[i]) + dpf(i + 1), abs(h[i + 2] - h[i]) + dpf(i + 2));
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
		dp[i] = -1;
	}
	int ans = dpf(0);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 2560
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main(){
    val (a, b) = readStrings().map{it.toBigDecimal()}
    println((a*b).toBigInteger())
}

Measured memory_bytes: 36684
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    n = I()
    s = S()
    d = defaultdict(int)
    for i in s:
        d[i] += 1
    ans = 1
    for i in d.keys():
        ans *= d[i]+1
        ans %= mod
    print(ans-1)
#B
def B():
    n = I()
    c = IR(n)
    v = [[i+1] for i in range(n-1)]
    v.append([])
    d = defaultdict(deque)
    for i in range(n):
        d[c[i]].append(i)
    for i in d.keys():
        x = None
        while d[i]:
            y = d[i].popleft()
            if x != None and y != x+1:
                v[x].append(y)
            x = y
    path = [0]*(n)
    path[0] = 1
    q = [0]
    for x in range(n-1):
        for y in v[x]:
            path[y] += path[x]
            path[y] %= mod
    print(path[-1])
#C
def C():
    def dfs(ans,l,r,d):
        if r != l+1:
            i = n-1
            c = ans[l]^ans[r]
            while not c&po2[i]:i -= 1
            d[i] = 1
            j = 0
            while d[j] or i == j:j += 1;j %= n
            m = (l+r)//2
            ans[m] = ans[l]^po2[j]
            ans[m+1] = ans[m]^po2[i]
            dfs(ans,l,m,d[:i]+[1]+d[i+1:])
            dfs(ans,m+1,r,d[:i]+[1]+d[i+1:])
    n,a,b = LI()
    po2 = [1]*(n+1)
    for i in range(1,n+1):
        po2[i] = po2[i-1]*2
    k = b^a
    c = 0
    bi = []
    i = 0
    g = [0]*n
    while k > 0:
        if k%2:
            bi.append(i)
            g[i] = 1
        c += k%2
        k//= 2
        i += 1
    f = c
    bi = bi[::-1]
    if not f%2:
        print("NO")
        quit()
    ans = [0]*po2[n]
    ans[0] = a
    ans[po2[n]-1] = b
    d = [0]*n
    dfs(ans,0,po2[n]-1,d)
    print("YES")
    print(*ans)
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 12228
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long long n; cin >> n;
    long long ans = n+1;
    for(long long i = 1; i<=1000000ll; i++) {
        if(i*i > n)
            break;
        if(n%i != 0)
            continue;
        long long x = n/i;
        long long tmp = x-1 + i-1;
        if(ans > tmp)
            ans = tmp;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int h, n;
  cin >> h >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
      cin >> a[i];
  
  int total = accumulate(a.begin(), a.end(), 0);
  
  if (h <= total)
      cout << "Yes" << endl;
  else
      cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 640
N, M = map(int, input().split())
s = set([i for i in range(1, M + 1)])
for i in range(N):
    A = list(map(int, input().split()))
    A = A[1: ]
    for j in range(1, M + 1):
        if j not in A and j in s:
            s.remove(j)

print(len(s))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    ll a, b; cin >> a >> b;
    ll A = (a-1)%4; ll B = b%4;
    ll xorA, xorB;
    if (A == 0) xorA = a-1;
    else if (A == 1) xorA = 1;
    else if (A == 2) xorA = a;
    else if (A == 3) xorA = 0;
    
    if (B == 0) xorB = b;
    else if (B == 1) xorB = 1;
    else if (B == 2) xorB = b+1;
    else if (B == 3) xorB = 0;

    ll ans = xorA^xorB;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;
const int MAXN = (int)3e5+1;

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    int k;
    cin >> s >> k;
    int n = s.length();
    ll dp[102][2][5] = {}; //dp[i][j][k] --> at position i there have been k nonzero digits, j indicates if it is less than s already
    dp[0][0][0] = 1;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<2; j++)
        {
            for(int l=0; l<=k; l++)
            {
                int dig = j ? 9 : (s[i] - '0');
                for(int d = 0; d<=dig; d++)
                {
                    dp[i + 1][j || d < dig][l + (d != 0)] += dp[i][j][l];
                }
            }
        }
    }
    cout << dp[n][0][k] + dp[n][1][k] << "\n";

    return 0;
}



Measured memory_bytes: 256
S = input()

if S[0] == "R":
    if S[1] == "R":
        if S[2] == "R":
            print(3)
            exit()
        else:
            print(2)
            exit()
    else:
        print(1)
        exit()
else:
    if S[1] == "R":
        if S[2] == "R":
            print(2)
            exit()
        else:
            print(1)
            exit()
    else:
        if S[2] == "R":
            print(1)
            exit()
print(0)


Measured memory_bytes: 9068
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

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

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

const ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T binpow( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}


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

	if ( N <= 999 )
	{
		cout << "ABC" << endl;
	}
	else
	{
		cout << "ABD" << endl;
	}

	return ( 0 );
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

class Stack{
private:
	int sp;
	int S[1000];
public:
	Stack(){ sp=0; }
	bool isFull() const{ return (sp==1000); }
	bool isEmpty() const{ return (sp==0); }
	void push(int d);
	void pop();
	int top();
};

void Stack::push(int d){
	if(isFull())
		return;
	S[sp++]=d;
}

void Stack::pop(){
	if(isEmpty())
		return;
	sp--;
}

int Stack::top(){
	if(isEmpty())
		return -1;
	return S[sp-1];
}

int main(){
	Stack S;
	string expr;
	getline(cin,expr);

	istringstream is(expr);

	while(!is.eof()){
		string op;
		is >> op;

		int  tmp1,tmp2;
	
		switch(op[0]){
		case '+':
			tmp1=S.top();	S.pop();
			tmp2=S.top();	S.pop();
			S.push(tmp2+tmp1);
			break;
		case '-':
			tmp1=S.top();	S.pop();
			tmp2=S.top();	S.pop();
			S.push(tmp2-tmp1);
			break;
		case '*':
			tmp1=S.top();	S.pop();
			tmp2=S.top();	S.pop();
			S.push(tmp2*tmp1);
			break;
		default:
			istringstream is2(op);
			is2 >> tmp1;
			S.push(tmp1);
			break;
		}
	}
	cout <<S.top()<<endl;

	return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int sosu[1000005]={0};
main(){
  int n;
  sosu[2]=0;
  sosu[1]=1;
  sosu[0]=1;
  for(int i=3;i<=sqrt(1000000);i+=2){
    if(sosu[i]==0){
      for(int j=i*2;j<=1000000;j+=i){
	sosu[j]=1;
      }
    }
  }
  while(cin>>n,n){
    int l,r;
    l=3;
    r=n-3;
    int cnt=0;
    while(l<=r){
      //cout<<l<<" "<<r<<endl;
      if(!sosu[l]&&!sosu[r]){
	//cout<<"A"<<l<<" "<<r<<endl;
	cnt++;
      }
      r-=2;
      l+=2;
    }
    cout<<cnt<<endl;
  }
}

Measured memory_bytes: 5064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<string> values = {
            "* = ****",
            "* =* ***",
            "* =** **",
            "* =*** *",
            "* =**** ",
            " *= ****",
            " *=* ***",
            " *=** **",
            " *=*** *",
            " *=**** "
    };
    int n, a = 0;
    while(cin >> n){
        if(a++) puts("");
        vector<string> ans(5);
        for (int i = 4; i >= 0; --i) {
            ans[i] = values[n%10];
            n /= 10;
        }
        for (int i = 0; i < ans[0].size(); ++i) {
            for (int j = 0; j < ans.size(); ++j) {
                printf("%c", ans[j][i]);
            }
            puts("");
        }
    }
    return 0;
}


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

int const N = 200 * 1000 + 16;
int const M = 1000*1000*1000 + 7;

int n;
int a[N];

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  cin >> n;
  for(int i = 0; i < n; ++i)
    cin >> a[i];

  sort(a, a+n, greater<int>());
  int x = 0;
  int y = 0;
  for(int i = 1; i < n; ++i) {
    if(a[i] == a[i-1]) {
      if(not x) x = a[i];
      else {
        y = a[i];
        break;
      }
      i++;
    }
  }

  cout << 1ll*x*y << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[100002][3];
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
    IOS;
    ll n; cin>>n;
    ll arr[n+1][3];
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>arr[i][j];
        }
    }
    ll ans = 0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        {
            dp[j][i] = max(dp[(j+1)%3][i-1] + arr[i][j],dp[(j+2)%3][i-1] + arr[i][j]);
        }
    }
    ans = max(dp[0][n],dp[1][n]);
    ans = max(ans , dp[2][n]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3328
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int[]> bi = new List<int[]>();
            bi.Add(Console.ReadLine().Split(' ').Select(int.Parse).ToArray());
            bi.Add(Console.ReadLine().Split(' ').Select(int.Parse).ToArray());
            bi.Add(Console.ReadLine().Split(' ').Select(int.Parse).ToArray());

            bool flag = false;

            int n = int.Parse(Console.ReadLine());

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

                int num = int.Parse(Console.ReadLine());
                
                for (int j = 0; j < 3; j++) 
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if (bi[j][k] == num) 
                        {
                            bi[j][k] = -1;
                        }
                    }
                }
            }

            for (int i = 0; i < 3; i++)
            {
                if (bi[i][0] == -1 && bi[i][1] == -1 && bi[i][2] == -1)
                {
                    flag = true;
                }
            }
 
            for (int i = 0; i < 3; i++)
            {
                if (bi[0][i] == -1 && bi[1][i] == -1 && bi[2][i] == -1)
                {
                    flag = true;
                }
            }

            if (bi[0][0] == -1 && bi[1][1] == -1 && bi[2][2] == -1)
            {
                flag = true;
            }

            if (bi[2][0] == -1 && bi[1][1] == -1 && bi[0][2] == -1)
            {
                flag = true;
            }

            if (flag)
            {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 28324
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
 
int main() {
    ll N, D; cin >> N >> D;
    vector<ll> t(N), F(N);
    for (int i = 0; i < N;i++) { cin >> t[i] >> F[i]; F[i]--; }
    ll ans = 0;
    ll pre_t = 0;
    ll pre_f = 0;
    ll cnt = 0;
    for (int i = 0; i < N;i++) {
        if (abs(F[i] - pre_f) > t[i] - pre_t) {
            pre_f = 0,ans = -1; break;
        }
        if (F[i] + pre_f <= t[i] - pre_t) {
            ans += (cnt * pre_f);
            cnt = 1;
        }
        else {
            ans += (cnt * (t[i] - pre_t));
            cnt++;
            if (cnt > D) { pre_f = 0, ans = -1; break; }
        }
        pre_f = F[i]; pre_t = t[i];
    }
    ans += pre_f*cnt;
    cout << ans << endl;
}

Measured memory_bytes: 4396