akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
#define ll              long long int
#define vll             vector<ll>
#define vs              vector <string>                                    
#define mll             map<ll,ll>
#define pll             pair<ll, ll>
#define vpll            vector < pair<ll,ll> >
#define itr             vll::iterator
#define all(c)          c.begin(),c.end()
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define pb              push_back
#define mb              make_pair
#define ff              first
#define ss              second
#define max3(a,b,c)     max(max(a,b),c)                                    
#define min3(a,b,c)     min(min(a,b),c)  
#define mod             1000000007
#define inf             1000000000000000001
#define from(i, n)      for(__typeof(n) i = 0; i <  n; ++i)
#define fromj(i, j, n)  for(__typeof(n) i = j; i <  n; ++i)
#define printv(v)       from(i,v.size())cout<<v[i]<<" ";cout<<"\n";
#define w(x)            int x; cin>>x; while(x--)
 
using namespace std;
using namespace __gnu_pbds; 
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}
 
bool func(const pll &a, const pll &b){
    if(a.ss==b.ss)return a.ff<b.ff;
    return a.ss < b.ss;
}
typedef tree<int, null_type, less<int >, rb_tree_tag, 
             tree_order_statistics_node_update> pbds; 
long long solve(vector<vll>&dp,long long subset,int num,vector<vector<bool> >&compat){
	if(num == compat.size()+1){
		if(subset==0)return 1;
		else return 0;
	}
	if(dp[num][subset]!=-1)return dp[num][subset];
	long long ans=0;
    for(int k=1;k<compat.size()+1;k++){
    	if(subset&(1<<(k-1)) && compat[num-1][k-1]){
    		ans=(ans+solve(dp,subset^(1<<(k-1)),num+1,compat))%mod;
    	}
    }
    dp[num][subset]=ans;
    return ans;
}
int main(){
    c_p_c();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    vector<vector<bool> > compat(n,vector<bool>(n,0));
    for(int i=0;i<n;i++){
    	for(int j=0;j<n;j++){
    		bool temp;
    		cin>>temp;
    		compat[i][j]=temp;
    		//cout<<compat[i][j]<<" ";
    	}	
    	//cout<<"\n";
    }
    vector<vll> dp(n+1,vll(1<<n,-1));
    //memset(dp,0,sizeof(dp));
    cout<<solve(dp,(1<<n)-1,1,compat);
}    

Measured memory_bytes: 380172
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
long long a[200010];
int main(){
	long long n,k;
	cin>>n>>k;
	long long cnt=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		cnt+=a[i];
	}
	sort(a,a+n);
	reverse(a,a+n);
	for(int i=0;i<k;i++){
		cnt-=a[i];
	}
	cout<<cnt<<endl;
	return 0;
}

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

struct pattern_t {
    int w;
    int h;
    char *pat;
    pattern_t( const int _w, const int _h, const char *_pat ){
        w = _w;
        h = _h;
        pat = new char[w*h];
        for( int i=0; i<w*h; i++ ){
            pat[i] = _pat[i];
        }
    }
    ~pattern_t(){
        if( pat ){
            delete[] pat;
            pat = 0;
        }
    }
};

int main(){
    pattern_t patA(2,2,"1111"),
              patB(1,4,"1111"),
              patC(4,1,"1111"),
              patD(2,3,"011110"),
              patE(3,2,"110011"),
              patF(2,3,"101101"),
              patG(3,2,"011110");
    pattern_t *patterns[7] = {&patA, &patB, &patC, &patD, &patE, &patF, &patG};
    char field[8][8];
    while(1){
        for( int i=0; i<8; i++ ){
            string in;
            if(!(cin >> in))   return 0;
            for( int j=0; j<8; j++ ){
                field[i][j] = in[j];
            }
        }
        for( int sy=0; sy<8; sy++ ){
            for( int sx=0; sx<8; sx++ ){
                for( int p=0; p<7; p++ ){
                    pattern_t *pt = patterns[p];
                    if( sy+pt->h > 8 || sx+pt->w > 8 )
                        continue;
                    bool miss = false;
                    for( int dy=0; dy<pt->h; dy++ ){
                        for( int dx=0; dx<pt->w; dx++ ){
                            if( pt->pat[dy*pt->w+dx] != field[sy+dy][sx+dx] ){
                                miss = true;
                                break;
                            }
                        }
                        if( miss )  break;
                    }
                    if( !miss ){
                        cout << (char)('A'+p) << endl;
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1180
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int n;
  cin >> n;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (i * j == n) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
ll t[3][3];
ll a[N];
vector <int> b;
map <int,int> mp;
int32_t main(){
    ll n;
    cin >> n;
    for (int i=1;i<=n;i++){
        ll x;
        cin >> x;
        a[i]=x;
        b.pb(x);
    }
    sort(b.begin(),b.end());
    for (int i=0;i<b.size();i++){
        mp[b[i]]=i+1;
    }
    for (int i=1;i<=n;i++){
        a[i]=mp[a[i]];
        if (a[i]%2!=i%2){
            t[a[i]%2][i%2]++;
        }
    }
   // ll cnt=0;
    ll ans=0;
    for (int i=0;i<2;i++){
        for (int j=i+1;j<2;j++){
            ll z=min(t[i][j],t[j][i]);
            t[i][j]-=z;
            t[j][i]-=z;
    //        cnt+=t[i][j]+t[j][i];
            ans+=z;
        }
    }
  //  ans+=2*cnt/3;
    cout << ans << endl;


}


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

int main() {
  long long Q, H, S, D, N; cin>>Q>>H>>S>>D>>N;
  long long setQ=8*Q;
  long long setH=4*H;
  long long setS=2*S; //2Lごとの比較
  long long min1=min({setQ, setH, setS, D});
  if(min1!=D) cout<<(N*min1)/2<<endl;
  else{
    long long min2=min({setQ, setH, setS});
    long long n=N%2;
    cout<<((N-n)/2)*D+n*min2/2; 
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
#define fs first
#define re resize
#define sc second
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,n) FOR(i,0,n-1)
#define ins insert
#define mod 1000000007
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif
#define endl "\n"
void fastIO(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif   
}
ll modexpo(ll a , ll b){
    if(a==0)return 0;
    if(a==1 or b==0)return 1;
    if(b==1)return a;
    if(b&1) return (a%mod*modexpo(a,b-1)%mod)%mod;
    return modexpo(a%mod * a%mod  ,  b/2 ) % mod;
}
void printv(vll v){
    for(auto&x:v) {
        cout<<x<<" ";
    }
    cout<<endl;
}
string to_string1(ll x){stringstream ss; ss<<x; return ss.str();}
ll to_integer(string s){stringstream ss(s); ll x; ss>>x; return x;}
#define tp9 1000000000 
const ll N = 1e12 + 5;
ld pi = 3.1415926535;
void printYes() {
    cout << "Yes\n";
}
void printNo() {
    cout << "No\n";
}
ll t , n , p ;
string s;

ll solve(ll n) {
    ll ans = 0 ;
    map<ll,ll>mp;
    while(n%2==0) {
        mp[2]++;
        n>>=1;
    }
    for(ll i = 3 ; i*i <= n ; i ++) {
        while(n%i==0){
            mp[i]++;
            n/=i;
        }
    }
    if(n>2) {
        mp[n]++;
    }
    for(auto p : mp) {
        ll j = p.sc, i = 1 ;
        while((i*(i+1)/2)<=j){
            i++;
        }
        ans+=i-1;
    }
    return ans;
}

int main (){
    ll n ; 
    while(cin >> n) 
    cout<<solve(n)<<endl;
    return 0; 
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    ll num = n-1;
    set<ll> st2;
    set<ll> st;
    for (ll i = 1; i * i <= num; i++)
    {
        if(num%i==0){
            st2.insert(i);
            st2.insert(num/i);
            if(i>1)ans++;
            if(i*i != num)ans++;
        }
    }
    st2.erase(1);
    num = n;
    for (ll i = 1; i * i <= num; i++)
    {
        if (num % i == 0)
        {
            st.insert(i);
            st.insert(num / i);
        }
    }
    st.erase(1);
    for(auto e: st){
        num = n;
        while(num%e==0){
            num /= e;
        }
        if(num%e==1 && st2.find(e) == st2.end()){
            ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
constexpr int INF = 1000000000;

int main() {
	int n, m, x; scanf("%d %d %d", &n, &m, &x);
	vector<int> cost(n);
	vector<vector<int>> expand(n, vector<int>(m));
	for (int i = 0; i < n; ++i) {
		scanf("%d", &cost[i]);
		for (int j = 0; j < m; ++j) scanf("%d", &expand[i][j]);
	}
	int ans = INF;
	for (int mask = 0; mask < (1 << n); ++mask) {
		vector<int> pagkakaintindi(m);
		int halaga = 0;
		for (int i = 0; i < n; ++i) {
			if ((mask & (1 << i)) == 0) continue;
			for (int j = 0; j < m; ++j) pagkakaintindi[j] += expand[i][j];
			halaga += cost[i];	
		}
		bool bigBrain = true;
		for (int j = 0; j < m; ++j) {
//			printf("mask %d und %d %d\n", mask, j, pagkakaintindi[j]);
			if (pagkakaintindi[j] < x) bigBrain = false;
//			else printf("big brain maintained\n");
		}
//		if (bigBrain) printf("mask %d big brain\n", mask);
		if (bigBrain) ans = min(ans, halaga);
	}
	if (ans == INF) printf("-1\n");
	else printf("%d\n", ans);
	return 0;
}


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

void chmax (int &a, int b) {
    if (a < b) a = b;
}

int main() {
    int n, k;
    cin >> n >> k;
    const int d = 2 * k;
    vector<vector<int>> b(d + 1, vector<int>(d + 1, 0));
    vector<vector<int>> w(d + 1, vector<int>(d + 1, 0));
    
    for (int _ = 0; _ < n; _++) {
        int i, j;
        char c;
        cin >> i >> j >> c;
        i %= d;
        j %= d;
        if (c == 'W') b[i][j]++;
        else w[i][j]++;
    }
    
    vector<vector<int>> sb(d + 1, vector<int>(d + 1, 0));
    vector<vector<int>> sw(d + 1, vector<int>(d + 1, 0));
    for (int i = 0; i < d; i++) for (int j = 0; j < d; j++) {
        sb[i + 1][j + 1] = sb[i][j + 1] + sb[i + 1][j] - sb[i][j] + b[i][j];
        sw[i + 1][j + 1] = sw[i][j + 1] + sw[i + 1][j] - sw[i][j] + w[i][j];
    }
    
    // [x2, x1), [y2, y1)
    auto bl = [&] (int x2, int y2, int x1, int y1) -> int {
        return sb[x1][y1] - sb[x1][y2] - sb[x2][y1] + sb[x2][y2];
    };
    auto wh = [&] (int x1, int y1, int x2, int y2) -> int {
        return sw[x1][y1] - sw[x1][y2] - sw[x2][y1] + sw[x2][y2];
    };
    
    int ans = 0;
    for (int i = 0; i + k <= d; i++) for (int j = 0; j + k <= d; j++) {
        int black = bl(0, 0, i, j) + bl(i, j, i + k, j + k) + bl(i + k, j + k, d, d) + bl(i + k, 0, d, j) + bl(0, j + k, i, d);
        int white = wh(i, 0, i + k, j) + wh(i + k, j, d, j + k) + wh(i, j + k, i + k, d) + wh(0, j, i, j + k);
        chmax(ans, black + white);
        chmax(ans, n - (black + white));
    }
    
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 63104
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ld D,T,S;
    cin >> D >> T >> S;

    yesno(D/S <= T);
}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3696
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
vector<int> prime={2};
vector<int> ans;

int main(){
	cin>>n;
	for(int i=3;i<=55555;i++){
		
		for(int j=0;j<prime.size();j++){
			if(i%prime[j]==0)break;
			if(j==prime.size()-1){
				prime.push_back(i);
				break;
			}
		}
	}
	
	for(int i=0;i<prime.size();i++){
		if(prime[i]%5==1)
		ans.push_back(prime[i]);
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}
	

Measured memory_bytes: 384
#include<iostream>
#include <cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

////Nayeem Shahriar Joy,Applied Physics &Electronic Engineering,University of Rajshahi.

int main(){
	int  s=100000;

	int n;
	scanf("%d",&n);


	for(;n--;){
		if(int(s*1.05)%1000==0){
			s=int(s*1.05);
		}else{
			s= int(s*1.05) + (1000- int(s*1.05) % 1000);
		}
	}
	printf("%d\n",s);

	return 0;
}

Measured memory_bytes: 3172
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] d = new int[N];
        HashSet<Integer> set = new HashSet<>();
        for(int i = 0; i < N; i++){
            int a = scan.nextInt();
            set.add(a);
        }
        System.out.println(set.size());
    }
}


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

# define ll long long 
# define VI vector<int>
# define VLL vector<ll>
# define PII pair<int,int> 
#define mp make_pair
#define pb push_back
# define PI acos(-1)
# define double long double
const int MxN = 10005 ; 
# define FOR(i,a,b) for(int i = a ; i < b ; ++i)
# define RFOR(i,a,b) for(int i = a ; i >= b ; --i)

/* VARIABLES */
ll n ; 
/* END OF VARIABLES */

int dig(ll n) {
	int ans = 0 ;
	while(n) {
		n = n / 10 ; 
		ans++;
	}
	return ans ; 
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
	int ans = 1e9 ; 
	cin >> n ; 
	FOR(i,1,sqrt(n)+1) {
		if(n%i == 0) 
			ans = min(ans,dig(max((ll)i,(ll)n/i))) ; 
	} 
	cout << ans ; 
	return 0 ; 
}



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

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

using namespace std;

template <typename T, T Op (T, T), T Unit = T()>
class SegmentTree {
 public:
  SegmentTree(int size) {
    int two = 1;
    while (two < size) {
      two <<= 1;
    }
    v_.resize(two * 2 - 1, Unit);
  }
  void Set(int i, T v) {
    int index = v_.size() / 2 + i;
    while (true) {
      v_[index] = v;
      if (index == 0) break;
      v = Op(v, v_[index + (index % 2 == 0 ? -1 : 1)]);
      index = (index - 1) / 2;
    }
  }
  T Get(int i) const { return Aggregate(i, i + 1); }
  T Aggregate(int begin, int end) const {
    return aggregate(begin, end, 0, (v_.size() + 1) / 2, 0);
  }

 private:
  T aggregate(int begin, int end, int cbegin, int cend, int index) const {
    if (begin <= cbegin && cend <= end) {
      return v_[index];
    }
    if (cend <= begin || end <= cbegin) {
      return Unit;
    }
    int cmid = (cbegin + cend) / 2;
    return Op(aggregate(begin, end, cbegin, cmid, index * 2 + 1),
              aggregate(begin, end, cmid, cend, index * 2 + 2));
  }
  std::vector<T> v_;
};

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

int Gcd(int a, int b) {
  if (a == 0) return b;
  if (b == 0) return a;
  assert(a != 0 && b != 0);
  return gcd(a, b);
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];

  SegmentTree<int, Gcd> t(N);
  REP(i, N) {
    t.Set(i, A[i]);
  }

  int ans = 0;
  REP(i, N) {
    ans = max(ans, Gcd(t.Aggregate(0, i), t.Aggregate(i + 1, N)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int stack[1000];
int kazu;

void push(int j){
  stack[++kazu] = j;
}
int pop(){
  kazu--;
  return stack[kazu+1];
}

int main(){
  int l,n;
  kazu = 0;
  char s[100];
  while( scanf("%s", s)!=EOF){
    if(s[0] == '+'){
      l =pop();
      n =pop();
      push(l+n);
    }
    else if(s[0]=='-'){
      n = pop();
      l = pop();
      push(l-n);
    }
    else if(s[0]=='*'){
      l = pop();
      n = pop();
      push(l*n);
    }
    else{
      push(atoi(s));
    }
  }
  printf("%d\n", pop());
  return 0;
}



Measured memory_bytes: 2088
import sys
# input = sys.stdin.readline

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort(key=lambda x: x[0])

ans = 0
cnt = 0
for i, (Ai, Bi) in enumerate(AB):
    if cnt + Bi >= M:
        ans += Ai * (M - cnt)
        break
    else:
        cnt += Bi
        ans += Ai * Bi

print(ans)

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

typedef long long ll;

using namespace std;

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


int main(){
    int N,K;
    ll money=2e10;
    cin >> N >> K;
    int height[N];
    rep(i,N) cin >> height[i];
    for(int bit = 0;bit < 1 << N;bit++){
        int max_b = height[0];
        int count = 1;
        ll temp = 0;
        for(int build = 1;build < N;build++){
            if(max_b < height[build]) {
                count++;
                max_b = height[build];
            }
            else{
                if(bit & (1 << build)){
                    temp += max_b-height[build]+1;
                    count++;
                    max_b++;
                } 
            }
        }
        if(count >= K) money = min(money,temp);
    }
    cout << money << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define FASTIO() cin.tie(0),ios::sync_with_stdio(0);
#define dbg(x) cout<<#x<<": "<<x<<endl


int main() {
    string s; cin >> s;
    int n = s.size();
    if (s.front() == s.back()) {
        cout << (n & 1 ? "Second" : "First") << endl;
    }
    else {
        cout << (n & 1 ? "First" : "Second") << endl;
    }

    return 0;
}


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n:i64,
        a:[i64; n],
    }
    let mut v = vec![0; 13];
    for i in a {
        v[(i/400) as usize]+=1;
    }
    let mut mn = 0;
    let mut mx = 0;
    for i in 0..13 {
        if v[i]>=1 && i<=7 {
            mn+=1;
            mx+=1;
        }
        if v[i]>=1 && i>=8 {
            mx+=v[i];
        }
    }
    if mn==0 {
        mn=1;
    }
    println!("{} {}", mn, mx);
}

Measured memory_bytes: 4352
#include <iostream>

using namespace std;

const int MAX_P = 10020;
bool prime[MAX_P];

void init()
{
    for (int i = 0; i < MAX_P; i++)
        prime[i] = true;
    prime[0] = prime[1] = false;

    for (int i = 2; i * i < MAX_P; i++)
        if (prime[i]) 
            for (int j = 2 * i; j < MAX_P; j += i)
                prime[j] = false;
}


int main()
{
    init();

    int n;
    while (cin >> n) {
        while (n - 2 >= 0) {
            if (prime[n] && prime[n - 2]) {
                cout << n - 2 << " " << n << endl;
                break;
            }
            n--;
        }
    }

    return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <algorithm>
#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() {
    string s, t;
    cin >> s >> t;
    t.pop_back();
    if(s == t) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
 
ll powmod(ll x, ll y){
    ll res = 1;
    for(ll i=0;i<y;i++){
        res = res*x%mod;
    }
    return res;
 
}
 
 
int main(){    
    ll n;
    cin >> n;
    ll ans=powmod(10,n)-powmod(9,n)-powmod(9,n)+powmod(8,n);
    ans%=mod;
    ans=(ans+mod)%mod;
    cout << ans ;
 
 
}

Measured memory_bytes: 3604
from fractions import gcd
from collections import Counter
A, B = map(int, input().split())
F = gcd(A, B)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

C = Counter(prime_factorize(F))

print(len(C)+1)


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

int nott(int X){
   if(X == 0) return 2;
   if(X == 1) return 1;
   return 0;
}

int andd(int X, int Y){
   if(X == 0) return 0;
   if(X == 1){
      if(Y == 0) return 0;
      return 1;
   }
   return Y;
}

int orr(int X, int Y){
   if(X == 0) return Y;
   if(X == 1){
      if(Y == 0) return 1;
      return Y;
   }
   return 2;
}

bool isNum(char c){
   if(c == '0' || c == '1' || c == '2' || c == 'P' || c == 'Q' || c == 'R') return true;
   return false;
}

int charToInt(char c){
   if(c == '0') return 0;
   if(c == '1') return 1;
   return 2;
}

//逆ポーランド記法に変換
string fix(string str){
   string result = "";
   stack<int> st;
   for(char c : str){
      if(isNum(c)){
         result += c;
      }else{
         if(c == ')'){
            while(st.top() != '('){
               result += st.top();
               st.pop();
            }
            st.pop();
         }else{
            if(c == '('){
               st.push(c);
            }else{
               while(!st.empty()){
                  if(st.top() == '-' && c != '-'){
                     result += st.top();
                     st.pop();
                  }else{
                     break;
                  }
               }
               st.push(c);
            }
         }
      }
   }
   while(!st.empty()){
      result += st.top();
      st.pop();
   }

   return result;
}

int main(){
   string str;
   while(cin>>str, str != "."){
      //逆ポーランド記法に変換
      str = fix(str);
      int count = 0;
      for(int p=0; p<3; p++){
         for(int q=0; q<3; q++){
            for(int r=0; r<3; r++){
               stack<int> st;
               for(char c : str){
                  if(c == 'P'){
                     st.push(p);
                  }else if(c == 'Q'){
                     st.push(q);
                  }else if(c == 'R'){
                     st.push(r);
                  }else if(c == '-'){
                     int a = st.top();
                     st.pop();
                     st.push(nott(a));
                  }else if(c == '+'){
                     int a = st.top();
                     st.pop();
                     int b = st.top();
                     st.pop();
                     st.push(orr(a, b));
                  }else if(c == '*'){
                     int a = st.top();
                     st.pop();
                     int b = st.top();
                     st.pop();
                     st.push(andd(a, b));
                  }else{
                     st.push(charToInt(c));
                  }
               }
               if(st.top() == 2) count++;
            }
         }
      }
      cout << count << endl;
   }
}



Measured memory_bytes: 3048
#include <stdio.h>
int main(void){
    int a,b,x;
    scanf("%d%d%d",&a,&b,&x);
    if(a==x) {printf("YES"); return 0;}
    else if(a>x||a+b<x) {printf("NO"); return 0;}
    else if(a<x){
        if(a+b>=x) printf("YES"); return 0;
    }
    else printf("NO");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

  int n,k;
  while(cin >> n >> k) {
    if(n+k == 0) break;
    vector<int> seq(n);
    for(int i=0;i<n;i++) {
      cin >> seq[i];
    }
    int wa = 0;
    for(int i=0;i<k;i++) {
      wa += seq[i];
    }
    int st = 0;
    int now = wa;
    for(int en=k;en<n;en++) {
      now = now - seq[st] + seq[en];
      st++;
      wa = max(wa,now);
    }
    cout << wa << endl;
  }
}

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

int main(){
    long num = 0;
    long i = 0;
    long total = 0;
    int t, n;
    char a;
    while (cin >> t >> a >> n){
	num += n;
	total += n*t;
	i++;
    }
    cout << total << endl;
    cout << int(num / double(i) + 0.5) << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

static const int lim = 1<<15+1;

int main(){
	
	int dp[lim]={0};
	int n, k;
	
	for(int a=0; a*a<lim; ++a){
	for(int b=a; b*b<lim; ++b){
	for(int c=b; c*c<lim; ++c){
	for(int d=c; d*d<lim; ++d){
	
		k = a*a+b*b+c*c+d*d;
		
		if(k<lim)
			dp[k]++;
	}}}}
	
	while(cin >> n, n){
		cout << dp[n] << endl;
	}
		
	return 0;
		
}

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

signed main(){
  string S;
  cin>>S;
  int A=0,B=0;
  rep(i,S.size()){
    if(S[i]=='0')A+=1;
    else B+=1;
  }
  cout<<2*min(A,B)<<endl;
}

Measured memory_bytes: 512
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using psi = pair<string, int>;

bool orig_sort(pair<psi, int> lhs, pair<psi, int> rhs)
{
  if (lhs.first.first == rhs.first.first)
    return lhs.first.second > rhs.first.second;
  else
    return lhs.first.first < rhs.first.first;
}

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

  vector<pair<psi, int>> vpss;
  REP(i, N)
  {
    psi t;
    cin >> t.first >> t.second;
    vpss.push_back(make_pair(t, i + 1));
  }

  sort(ALL(vpss), orig_sort);

  for (auto &p : vpss)
  {
    cout << p.second << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
str1 = list(input())
q = int(input())

for i in range(q):
	order = [str(x) for x in input().split()]
	if order[0] == 'replace':
		str1[int(order[1]):int(order[2])+1] = list(order[3]) 
		#print(str1)
	elif order[0] == 'reverse':
		str2 = str1[int(order[1]):int(order[2])+1]
		str1[int(order[1]):int(order[2])+1] = reversed(str2)
			
	else: #print
		print(*str1[int(order[1]):int(order[2])+1], sep='')

Measured memory_bytes: 7792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n, k, ans = 0;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }
    ans = (n - 1) / (k - 1);
    if((n - 1) % (k - 1) != 0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	using T = tuple<int, int, int>;
	for (int n; cin >> n&&n;) {
		set<T> st;
		st.emplace(-INF, 0, -1);
		while (n--) {
			char com; cin >> com;
			if (com == 'W') {
				int l, s; cin >> l >> s;
				for (auto c = st.begin(); c != st.end(); c++) {
					int ca, cb, cc, na, nb, nc;
					tie(ca, cb, cc) = *c;
					if (next(c) == st.end()) {
						st.emplace(cb, cb + s, l);
						break;
					}
					tie(na, nb, nc) = *next(c);
					if (cb == na)
						continue;
					int d = min(s, na - cb);
					c = st.emplace(cb, cb + d, l).first;
					s -= d;
					if (s == 0)
						break;
				}
			}
			else if (com == 'D') {
				int l; cin >> l;
				for (auto it = st.begin(); it != st.end();) {
					if (get<2>(*it) == l)
						it = st.erase(it);
					else
						it++;
				}
			}
			else if (com == 'R') {
				int p; cin >> p;
				auto upper = st.upper_bound(T(p, INF, INF));
				int a, b, c;
				tie(a, b, c) = *prev(upper);
				if (b <= p)
					cout << -1 << endl;
				else
					cout << c << endl;
			}
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  ll N,M;cin>>N>>M;
  priority_queue<ll,vector<ll>,greater<ll>> AS;
  REP(i,N) {
    ll a;cin>>a;
    AS.push(a);
  }

  priority_queue<ll> CS;
  vector<P> tmp;
  REP(i,M) {
    ll B,C;cin>>B>>C;
    tmp.push_back({C,B});
  }
  sort(ALL(tmp),greater<P>());
  REP(i,M) {
    ll B = tmp[i].second, C = tmp[i].first;
    REP(b,B) {
      CS.push(C);
      if (CS.size()==N) break;
    }
    if (CS.size()==N) break;
  }
  while (CS.size()<N) CS.push(0);

  // 基本的にはBの数より小さいものを全て可能な限り入れ替える
  while (!CS.empty()) {
    if (AS.top()>CS.top()) break;
    AS.pop();
    AS.push(CS.top());
    CS.pop();
  }

  ll ans = 0;
  while (!AS.empty()) {
    ans += AS.top();
    AS.pop();
  }
  OUT(ans);

  return 0;
}

Measured memory_bytes: 4464
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1e9 - 7;
int n,k;
vector<int> h, dp;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	h = vector<int>(n );
	dp = vector<int>(n + 1);
	for(auto &it : h) cin >> it;
	for(int i=1 ; i<=n ; i++){
		dp[i] = INF;
		for(int j = 1 ; j <= k ; j++){
			if( i - j >= 0){
				dp[i] = min(dp[i],dp[i - j] + abs(h[i] - h[i - j]));
			}
		}
	}
	cout << dp[n - 1] <<"\n";
	

	return 0;
}


Measured memory_bytes: 3676
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int d,n;
  cin>>d>>n;
  int ans=0;
  if(n!=100){
    if(d==0)  ans=n;
    if(d==1)  ans=100*n;
    if(d==2)  ans=10000*n;
  }else{
    if(d==0)  ans=n+1;
    if(d==1)  ans=100*(n+1);
    if(d==2)  ans=10000*(n+1);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
    int x,a;
    cin>>x>>a;
    if(x<a)cout<<0<<endl;
    else cout<<10<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MOD 1000000007
int modpow(int a, int b) {
	if (b == 0)return 1;
	if (b == 1)return a;
	if (b % 2)return modpow(a, b - 1) * a % MOD;
	return modpow(a, b / 2) * modpow(a, b / 2) % MOD;
}
signed main() {
	int a, b;
	cin >> a >> b;
	cout << modpow(a, b) << endl;
	return 0;
}


Measured memory_bytes: 3080
#include<stdio.h>
 #include<string.h>
 int main()
{
 int n, i, a=0, b=0;
 scanf("%d", &n);
 char s1[n], s2[n];
 for(i=0;
i<n;
i++)
{
 scanf("%s %s", s1, s2);
 if ( strcmp(s1, s2) == 0 )
{
 a++;
 b++;
 }
 else if ( strcmp(s1, s2) > 0 ) a=a+3;
 else if ( strcmp(s1, s2) < 0 ) b=b+3;
 }
 printf("%d %d\n", a, b);
 return 0;
 } 


Measured memory_bytes: 2084
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 505;

int n, k, sum, ans;
int a[maxn];
vector < int > d;

signed main () {
    scanf("%lld %lld", &n, &k);
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &a[i]);
        sum += a[i];
    }
    for (int i = 1; i * i <= sum; ++i) {
        if (sum % i == 0) {
            d.push_back(i);
            d.push_back(sum / i);
        }
    }
    for (int x: d) {
        vector < int > b;
        int add = 0, rm = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i] % x) {
                b.push_back(a[i] % x);
                add += x - b.back();
            }
        }
        sort(b.begin(), b.end());
        int cur = add;
        for (int i = 0; i < b.size(); ++i) {
            rm += b[i];
            add -= x - b[i];
            cur = min(cur, max(rm, add));
        }
        if (cur <= k)
            ans = max(x, ans);
    }
    printf("%lld\n", ans);
}


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

int main() {
  int N, p;
  cin >> N;
  
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  p = 1;
  for (int i = 0; i < N; i++) {
    p = a.at(p - 1);
    
    if (p == 2) {
      cout << i + 1 << endl;
      break;
    }
    
    else if (i == N - 1) {
      cout << "-1" << endl;
      break;
    }
    
    else {
      continue;
    }

  }
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   int x, t;
   cin >> x >> t;

   if (x >= t)
   {
      cout << x - t << endl;
   }
   else
   {
      cout << 0 << endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;


int v,e;
vector<int> edge[100000];
string a;
set<char> able[100000];

int main(){
	cin>>v>>e;
	rep(i,v){
		rep(j,26)able[i].insert('a'+j);
	}
	rep(i,v){
		char c;
		cin>>c;
		a+=c;
	}
	rep(i,e){
		int s,t;
		cin>>s>>t;
		edge[s].push_back(t);
		edge[t].push_back(s);
	}
	rep(i,v){
		if(a[i]=='?')continue;
		rep(j,edge[i].size()){
			able[edge[i][j]].erase(a[i]);
		}
	}
	rep(i,v){
		if(a[i]!='?')continue;
		char c=*able[i].begin();
		a[i]=c;
		rep(j,edge[i].size()){
			able[edge[i][j]].erase(c);
		}
	}
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 134660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,i,x=0;
  string S;
  
  cin >> A >> B >> S;
  
  for(i=0; i <= A+B; i++){
  	if(i == A){
    	if(S[i] == '-'){
          x++;
        }
    }else{
    	if(S[i] == '0' || S[i] == '1' || S[i] == '2' || S[i] == '3' || S[i] == '4' || S[i] == '5' || S[i] == '6' || S[i] == '7' || S[i] == '8' || S[i] == '9'){

        }else{
        	x = -100;
        }
    }
  }
  if(S.size() == A+B+1){
  	x++;
  }
  
  if(A >= 0 && A <= 5){
    if(B >= 0 && B <= 5){
 	 if(x == 2){
  		cout << "Yes" << endl;
     }else{
     	cout << "No" << endl;
     }
    }else{
    	cout << "No" << endl;
    }
  }else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {
    let n:usize = read();
    let s:String = read();
    let ans = if s[0..n/2] == s[n/2..n] {"Yes"} else {"No"};
    println!("{}", ans);
}

Measured memory_bytes: 2124
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] A = new int[N];
		
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		
		Arrays.sort(A);
		
		long x = 0;
		long y = 0;
		
		for(int i = N - 1; i >= 1; i--) {
			if(A[i] == A[i - 1]) {
				if(x == 0) {
					x = A[i];
					i--;
				} else {
					y = A[i];
					break;
				}
			}
		}
		long S = x * y;
		System.out.println(S);
	}
}


Measured memory_bytes: 49912
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (a).size()


using namespace std;

const ll N = 1e5;
const ll big = 1e18;
const ll block = 800;
const ll mod = 1e6;
ll n, k;
ll p[N];
ll c[N];
ll ans = -big;

int main() {
	cin >> n >> k;
	for(int j = 1; j <= n; j++) 
		cin >> p[j];
	for(int j = 1; j <= n; j++) 
		cin >> c[j];
	for(int i = 1; i <= n; i++) {
		vector<ll> sum = {c[p[i]]};
		ll sz = 1;
		ll j = p[i], sub = c[j];
		while(j != i) {
			sub += c[p[j]];
			sum.pb(sub);
			j = p[j];
			sz++;
		}
		ll st = 1;
		for(auto u : sum) {
			if(st <= k) {
				ll f = k - st;
				f /= sz;
				ans = max({u, u + sub * f, ans});
			}
			st++;
		}
	}
	cout << ans << '\n';
		
}

/*

*/



Measured memory_bytes: 3780
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=3e5+5,mod=998244353;
int ans=1,n,cnt[3];
char s[N];

signed main(){
	read(n);
	scanf("%s",s+1);
	for(int i=1;i<=n*3;i++){
		int x=s[i]=='R'?0:s[i]=='G'?1:2,cur=1e9;
		for(int i:{0,1,2}) if(cnt[i]>cnt[x]) cur=min(cur,cnt[i]-cnt[x]);
		if(cur<1e9) ans=1ll*ans*cur%mod;
		cnt[x]++;
		cur=min({cnt[0],cnt[1],cnt[2]});
		for(int i:{0,1,2}) cnt[i]-=cur;
	}
	for(int i=1;i<=n;i++) ans=1ll*ans*i%mod;
	write(ans);
}

Measured memory_bytes: 3976
A = int(input())
B = int(input())
C = int(input())
X = int(input())

c = 0

for i in range(A + 1):
	for j in range(B + 1):
		for k in range(C + 1):
			if 500 * i + 100 * j + 50 * k == X:
				c += 1

print(c)

Measured memory_bytes: 2940
// Problem : G - Longest Path
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_g
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// It's something that is not good
// & i'm trying right just nothing
// dont't know what god is upto
// but i shall tryna make it come.
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define el "\n"
ll dp[2000000];
void dfs(vector<ll> graph[],ll start,vector<ll> &visit,ll &ans){
	visit[start]=1;
	
	for(auto child:graph[start]){
		//dp[child]=max(dp[child],dp[start]+1);
		
		if(!visit[child]){
			//dp[child]=dp[start]+1;
		 dfs(graph,child,visit,ans);
		// cout<<"HERE"<<endl;
		 }
		
	}
	for(auto child:graph[start]){
	 	dp[start]=max(dp[start],dp[child]+1);
	 	ans=max(ans,dp[start]);
	 	}
}
ll tests=1;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
   // cin>>tests;
    while(tests--){
        ll n; cin>>n; ll m; cin>>m;
        vector<ll> graph[n];
        for(int i=0;i<m;i++){
        	ll x,y; cin>>x>>y; --x; --y;
        	graph[x].push_back(y);
        	//graph[y].push_back(x);
        }
        vector<ll> visit(n,0);
        ll ans=-INT_MAX;
        for(int i=0;i<n;i++){
        	if(!visit[i]){
        		dp[i]=0;
        	 dfs(graph,i,visit,ans);
        	 }
        }
        
       // for(int i=0;i<n;i++) ans=max(ans,dp[i]);
        cout<<ans<<el;
        
    }
}

Measured memory_bytes: 13648
def main():
    l = input().strip().split(" ")
    n = int(l[0])
    k = int(l[1])

    h = input().strip().split(" ", n)

    count = 0
    for x in h:
        x = int(x)
        if x >= k:
            count += 1

    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9988
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,x[100][3],y[100],a,b,c,d,flg;
	int i,k;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		x[i][0]=0; x[i][1]=0; x[i][2]=0; y[i]=i;
	}
	for(i=0;i<n*(n-1)/2;i++){
		scanf("%d %d %d %d",&a,&b,&c,&d);
		a--; b--;
		if(c>d){
			x[a][0]++; x[b][1]++;
		}
		else if(c<d){
			x[a][1]++; x[b][0]++;
		}
		else{
			x[a][2]++; x[b][2]++;
		}

	}
	for(i=0;i<n;i++){
		x[i][0]=x[i][0]*3+x[i][2];
	}
	for(i=0;i<n-1;i++){
		for(k=i+1;k<n;k++){
			if(x[i][0]<x[k][0]){
				swap(x[i][0],x[k][0]); swap(y[i],y[k]);
			}
		}
	}
	k=1;
	for(i=0;i<n;i++){
		x[i][1]=k; k++;
		if(x[i][0]==x[i-1][0]) x[i][1]=x[i-1][1];
	}
	for(i=0;i<n-1;i++){
		for(k=i+1;k<n;k++){
			if(y[i]>y[k]){
				swap(y[i],y[k]); swap(x[i][1],x[k][1]); swap(x[i][0],x[k][0]);
			}
		}
	}
	for(i=0;i<n;i++) printf("%d\n",x[i][1]);
	return 0;
}

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

int main() {
    char a, b;
    cin >> a >> b;
    if(a == 'H'){
        if(b == 'H'){
            cout << 'H' << endl;
        }else{
            cout << 'D' << endl;
        }
    }else{
        if(b == 'H'){
            cout << 'D' << endl;
        }else{
            cout << 'H' << endl;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <stack>
#include <map>
using namespace std;

int R,C,N;

int getpos(int x, int y)
{
	if (x == 0) return y;
	if (y == C) return C + x;
	if (x == R) return R + C * 2 - y;
	if (y == 0) return (R + C) * 2 - x;
	return -1;
}

int main()
{
	scanf ("%d %d %d",&R,&C,&N);
	map<int, int> p;
	for (int i=0;i<N;i++){
		int x1,y1,x2,y2;
		scanf ("%d %d %d %d",&x1,&y1,&x2,&y2);
		int p1 = getpos(x1,y1);
		int p2 = getpos(x2,y2);
		if (p1 >= 0 && p2 >= 0){
			p[p1] = i;
			p[p2] = i;
		}
	}

	stack<int> s;
	for (auto &v : p){
		if (s.empty() || s.top() != v.second) s.push(v.second);
		else s.pop();
	}

	puts(s.empty() ? "YES":"NO");

	return 0;
}

Measured memory_bytes: 9984
#include <stdio.h> 

int main(void)
{	
	int n, x, i, j, k, kumi = 0;

	while(1)
	{
		scanf("%d %d",&n, &x);

		if((n == 0) && (x == 0))
		{
			break;
		}
		
		for(i=1; i<=n; i++)
		{
			for(j=i+1; j<=n; j++)
			{
				for(k=j+1; k<=n; k++)
				{
					if(x == (i+j+k) && (i != j) && (i != k) && (j != k))
					{
						kumi++;
					}
				}
			}
		}

		printf("%d\n",kumi);

		kumi = 0;
	}

	return 0;
}

Measured memory_bytes: 600
using System;
using System.Linq;

class P{
  static void Main(){
    
    int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int N = n[0];
    int K = n[1];
    int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
    
    int tmp = 0, ans = int.MaxValue;
    for(int i = 0; i <= N - K; i++){
      tmp = Math.Min(Math.Abs(x[i]) + Math.Abs(x[i + K - 1] - x[i]), Math.Abs(x[i + K - 1]) + Math.Abs(x[i + K - 1] - x[i]));
      ans = Math.Min(ans, tmp);
    }
    
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 23008
#include <iostream>
using namespace std;
int main()
{
    long long i,j,a,b,c=0,l=0,t,x,y,n;
    cin>>n;
    long long A[n];
    for(i=0;i<n;i++)
    cin>>A[i];
    for(i=0;i<n-1;i++)
    {
      if(A[i]>A[i+1])
      {
          c+=(A[i]-A[i+1]);
          A[i+1]=A[i];
      }
    }
cout<<c<<endl;
 return 0;
}


Measured memory_bytes: 5188