akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n, m;
	cin>>n>>m;
	map<int,ll> ma;
	ma[0] = 1;
	int a;
	ll res = 0;
	ll su = 0;
	while(n--)
	{
		cin>>a;
		su = (su + a) % m;
		res += ma[su];
		ma[su]++;
	}
	cout<<res<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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

using namespace std;

int yen[] = {1,6,36,216,1296,7776,46656,9,81,729,6561,59049};

const int N = 100005; 
int dp[N];

void solve() {
    int n; cin >> n;
    memset(dp, 0x3f, sizeof dp);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int x: yen) {
            if (i < x) continue;
            dp[i] = min(dp[i], dp[i-x]+1);
        }
    }
    cout << dp[n];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 640
#include<iostream>
    #include<cstdlib>
    #include<math.h>
    #include<set>
    using namespace std ;
    int main(){
        int X,A,B;
        cin>>X>>A>>B;
        X=X-A;
        while(X>=B)X=X-B;
        cout<<X<<endl;
        return 0 ;
    }

Measured memory_bytes: 256
//#define DEBUG
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))

#define fi first
#define sc second 
#define pb push_back


#ifdef DEBUG
    #define dbg(s) {s;}
    #define PRELUDE
#endif

#ifndef DEBUG 
    #define PRELUDE { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define dbg(s)
    #define endl "\n"
#endif

#define int ll
#define i32 int32_t

#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).

#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;

// To remove randomization use 0 below:
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int x) { // from [0, n-1]
    return uniform_int_distribution<int>(0, x - 1)(rng);
}

inline ld rf() { // from [0, 1]
    return uniform_real_distribution<ld>(0, 1)(rng);
}

ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 

const ll mod = 1e9 + 7;

ll modexp(ll x, ll ex) {
    x = x%mod;
    ex = ex % (mod-1);
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}

const int maxn = 1e5 + 7;

const ll inf = 1e9 + 7;

int ans[maxn][3];
int h[maxn][3];

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

    for(int i=1;i<=n;i++)
        cin>>h[i][0]>>h[i][1]>>h[i][2];
    ans[1][0] = h[1][0];
    ans[1][1] = h[1][1];
    ans[1][2] = h[1][2];

    for(int i=2;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        {
            ans[i][j] = h[i][j];
            for(int k=0;k<3;k++)
            {
                if(j==k)
                    continue;
                ans[i][j] = max(ans[i][j], ans[i-1][k] + h[i][j]);
            }
        }
    }
    int z = max(ans[n][0],ans[n][1]);
    z = max(z,ans[n][2]);
    cout<<z<<endl;
}

i32 main() {
    //freopen("<file>.in", "r", stdin);
    //freopen("<file>.out", "w", stdout);
    
    PRELUDE;
    int t = 1;
    //cin>>t;
    while(t--)
        solve();
}


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

L=[[h,i,N-h-i]for h in range(N+1) for i in range(N+1) if h*1000+i*5000+(N-h-i)*10000==Y and (N-h-i)>=0]

if len(L)>0:
  print(L[0][2],end=" ")
  print(L[0][1],end=" ")  
  print(L[0][0])
else:
  print("-1 -1 -1")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int a = 0, b = 0, c = 0, d = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(i&1)
        {
            if(s[i] == '0')a++;
            else b++;
        }
        else
        {
            if(s[i] == '0')c++;
            else d++;
        }
    }
    cout<<min(a + d, b + c)<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(){
  char S[3];
  char T[3];
  scanf("%s", S);
  scanf("%s", T);
 
  int c= 0;
  int i;
 
  for (i = 0; i < 3; i++) {
    if (S[i] == T[i]) {
     c++;
    }
  }
  printf("%d", c);
 
 

return 0;
}

Measured memory_bytes: 128
#coding: utf-8
import math

n,m = map(int,raw_input().split())

a = []
root_m = int(math.sqrt(m)) + 1
for i in range(1,root_m):
    if m%i == 0:
        a.append(m/i)
        if i >= n:
            print m/i
            exit()
for i in reversed(a):
    if m%i == 0:
        if i >= n:
            print m/i
            exit()
print "1"



Measured memory_bytes: 3588
#include <cstdio>

int cnt[55][26];
int sz[26];
char s[55];

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%s", s);
        for (int j = 0; s[j]; ++j)
            ++cnt[i][s[j] - 'a'];
    }
    for (int i = 0; i < 26; ++i)
        sz[i] = cnt[0][i];
    for (int i = 1; i < n; ++i)
        for (int j = 0; j < 26; ++j)
            if (sz[j] > cnt[i][j])
                sz[j] = cnt[i][j];
    for (int i = 0; i < 26; ++i)
        for (int j = 0; j < sz[i]; ++j)
            putchar('a' + i);
    puts("");
    return 0;
}

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

const int INF = 1001001001;

int main(){
  int N, K;
  cin >> N >> K;
  int h[N];
  rep(i,0,N) cin >> h[i];

  int dp[N];
  rep(i,0,N) dp[i] = INF;
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);

  rep(i,2,N){
    rep(k,1,K+1) if(i-k>=0) dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]));
  }

  cout << dp[N-1] << endl;

  return 0;
}

Measured memory_bytes: 1024
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var n2 = int.Parse(line[1]);
        var sta = new int[n, n2];
        var p = new int[n];
        for (int i = 0; i < n2; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var c = int.Parse(line[0]);
            var c2 = int.Parse(line[1]);
            if (c == 0)
            {
                var c3 = int.Parse(line[2]);
                sta[c2, p[c2]++] = c3;
            }
            else if (c == 1 && p[c2] > 0) Console.WriteLine(sta[c2, p[c2] - 1]);
            else if (p[c2] > 0) p[c2]--;
        }
    }
}


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

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

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

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { for (auto& _e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }

int main(void) {
	int N, K;
	cin >> N >> K;
	vector<int> l(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> l[i];
	}
	sort(ALL(l));
	reverse(ALL(l));
	int sum = 0;
	for (size_t i = 0; i < K; i++)
	{
		sum += l[i];
	}
	cout << sum << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  int mini = 200001;
  int c = 0;
  for (int i = 0; i < N; i++) {
    if (mini > a.at(i)) {
      mini = a.at(i);
      c++;
    }
  }
  cout << c <<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,m,k;
    cin >> n >> m;
    vector<int> f(m);
    for (int i=0;i<n;i++) {
        cin >> k;
        int a;
        for (int j=0;j<k;j++) {
            cin >> a;
            f[a-1]++;
        }
    }
    int ans=0;
    for (int l=0;l<m;l++) {
        if (f[l]==n) ans++;
    }
    cout << ans << endl;
}

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

int main()
{
	string S;
	cin >> S;

	if (S == "SUN")
	{
		cout << 7 << endl;
		return 0;
	}
	else if (S == "MON")
	{
		cout << 6 << endl;
		return 0;
	}
	else if (S == "TUE")
	{
		cout << 5 << endl;
		return 0;
	}
	else if (S == "WED")
	{
		cout << 4 << endl;
		return 0;
	}
	else if (S == "THU")
	{
		cout << 3 << endl;
		return 0;
	}
	else if (S == "FRI")
	{
		cout << 2 << endl;
		return 0;
	}
	else if (S == "SAT")
	{
		cout << 1 << endl;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int N = sc.nextInt();
        int[] W = new int[N];
        int ssum = 0;
        int ssum2 = 0;
        int ssumb = 0;

        for(int i=0; i<N; i++){
            W[i] = sc.nextInt();
            ssum += W[i];
        }
        for(int i=0; i<N; i++){
            if(ssum2>=ssum/2){
                break;
            }
            ssum2 += W[i];
        }
        for(int i=N-1; i>=0; i--){
            if(ssumb>=ssum/2){
                break;
            }
            ssumb += W[i];
        }
        if(ssum2<=ssumb){
            System.out.println(2*ssum2-ssum);
        }
        else if(ssumb<ssum2){
            System.out.println(2*ssumb-ssum);
        }
    }
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  string s;cin>>s;
  ll n=s.size();
  res=n;
  rep(i,0,n-1){
    if(s[i]!=s[i+1]){
      ll x=max(n-i-1,i+1);
      chmin(res,x);
    }
  }
  cout<<res<<endl;
   return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int lg[N];
int val[20][N];
int p[N];
int n;

int query(int l,int r){
	if(l&1^1) l=l/2,r=r/2;
	else l=n/2+l/2,r=n/2+(r-1)/2;
	int d=lg[r-l+1];
	return p[val[d][r]] < p[val[d][l+(1<<d)-1]] ? val[d][r]:val[d][l+(1<<d)-1];
}

struct msg{
	int l,r,x,y;
	bool operator <(const msg &b)const{
		return p[x]==p[b.x]? p[y] > p[b.y] : p[x] > p[b.x] ;
	}
};
priority_queue<msg> pq;
void add(int l,int r){
	int x=query(l,r);
	int y=query(x+1,r);
	pq.push((msg){l,r,x,y});
}
int main(){
	scanf("%d",&n);
	memset(val,0x3f,sizeof val);
	for(int i=0,t;i<n;i++) scanf("%d",&p[i]);
	
	for(int i=0;i<n;i++)
		val[0][i/2+(n/2)*(i%2)]=i,lg[i]=i<2? 0:lg[i>>1]+1;
	for(int i=1;i<20;i++)
		for(int j=(1<<i)-1,hf=(1<<(i-1));j<n;j++)
			val[i][j]=p[val[i-1][j]] < p[val[i-1][j-hf]] ? val[i-1][j]:val[i-1][j-hf];
	
	add(0,n-1);
	while(!pq.empty()){
		msg v=pq.top();pq.pop();
		printf("%d %d ",p[v.x],p[v.y]);
		if(v.l<v.x) add(v.l,v.x-1);
		if(v.x+1<v.y) add(v.x+1,v.y-1);
		if(v.y<v.r) add(v.y+1,v.r); 
	}
	return 0;
} 

Measured memory_bytes: 19444
/*
P135
AOJ 0189 Convenient Location
*/

#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
#include <cmath>

using namespace std;

const int MAXN = 15;

int d[MAXN][MAXN];
int M, N;

bool read()
{
    scanf("%d", &M);
    if(M==0) return false;
    for(int i=0; i<=10; i++){
        for(int j=0; j<=10; j++)
        {
            d[i][j] = 1<<20;
        }
        d[i][i] = 0;
    }
    N = 0;
    int s, e, m;
    for(int i=0; i<M; ++i){
        scanf("%d%d%d", &s, &e, &m);
        d[s][e] = m;
        d[e][s] = m;
        N = max(N, s);
        N = max(N, e);
    }
    return true;
}

void floyd(int n)
{
    for(int k=0; k<n; ++k)
    for(int i=0; i<n; ++i)
    for(int j=0; j<n; ++j)
    {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
}
void solve()
{
    floyd(N+1);
    int dmin = 1<<20, idx = 0;
    for(int i=0; i<N; ++i){
        int dis = 0;
        for(int j=0; j<=N; ++j)
            dis += d[i][j];
        if(dis < dmin) dmin = dis, idx = i;
    }
    printf("%d %d\n", idx, dmin);

}

int main()
{
    while(read()){
        solve();
    }
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  ll w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;
  auto in_f = [&](ll xi, ll yi) {
    return 0 <= xi && xi <= w && 0 <= yi && yi <= h;
  };
  Yes(in_f(x + r, y) && in_f(x - r, y) && in_f(x, y + r) && in_f(x, y - r));
  return 0;
}



Measured memory_bytes: 3216
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] ab = scanner.nextLine().split(" ", 2);
        int a = Integer.parseInt(ab[0]);
        int b = Integer.parseInt(ab[1]);
        System.out.println((a + b) % 24);
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
int modn = 1000000000 + 7;

int main(void)
{
    int H, W;
    cin >> H >> W;

    vector<vector<bool>> mm(H, vector<bool>(W,false));
    vector<vector<int>> cost(H, vector<int>(W,0));

    for(int i = 0; i < H; ++i)
    {
        for(int j = 0; j < W; ++j)
        {
            char tmp;
            cin >> tmp;

            if(tmp == '.') mm.at(i).at(j) = true;
            else mm.at(i).at(j) = false;
        }
    }

    cost.at(0).at(0) = 1;
    for(int i = 0; i < H; ++i)
    {
        for(int j = 0; j < W; ++j)
        {
            if(i+1 < H && mm.at(i+1).at(j)) cost.at(i+1).at(j) = (cost.at(i+1).at(j) + cost.at(i).at(j)) % modn;
            if(j+1 < W && mm.at(i).at(j+1)) cost.at(i).at(j+1) = (cost.at(i).at(j+1) + cost.at(i).at(j)) % modn;
        }
    }

    cout << cost.at(H-1).at(W-1) << endl;



    return 0;
}



Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main()
{
	char s1,s2,s3;

	scanf("%c",&s1);
	scanf("%c",&s2);
	scanf("%c",&s3);



	int x = 0;

	if (s1 == '1') {
		x++;
	}

	if (s2 == '1') {
		x++;
	}

	if (s3 == '1') {
		x++;
	}

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

}


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MOD = 1e9 + 7;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int xa = min(a, k);
    k -= xa;
    int xb = min(b, k);
    k-= xb;
    int xc = k;
    int ans = xa - xc;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define int long long

//	TIME COMPLEXITY = O(N * logM)

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	
	int n,m,k;
	cin >> n >> m >> k;
	int A[n+1], B[m+1];
	A[0] = B[0] = 0;
	for(int i=1;i<=n;i++) cin >> A[i];
	for(int j=1;j<=m;j++) cin >> B[j];

	int pref[m+1];
	pref[0]=0;
	for(int i=1;i<=m;i++) pref[i] = pref[i-1] + B[i];

	int ans=0;
	int current=0;

	for(int a=0 ; a<=n && current<=k ;a++){
		current+=A[a];
		if(current > k) break;

		int left=0, right=m, temp=0;
		while(left <= right){
			int mid = (left+right)/2;

			if(current + pref[mid]<=k){
				temp = mid;
				left = mid+1;
			}
			else{
				right = mid-1;
			}
		}

		// if(a+temp > ans) cout << "max update at a=" << a << " current=" << current << " mid=" << temp << endl;
		ans = max(ans , a+temp);
		
	}

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


Measured memory_bytes: 8316
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
using namespace std;
struct point{ int x,y,use; }a[105],b[105];
string s;
int N,M,chk,dap;
int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++) scanf("%d %d",&a[i].x,&a[i].y);
    for(int j=0;j<N;j++) scanf("%d %d",&b[j].x,&b[j].y);
    sort(a,a+N,[&](point aa, point bb){ if(aa.x!=bb.x) return aa.x>bb.x; else return aa.y>bb.y; });
    sort(b,b+N,[&](point aa, point bb){ if(aa.x!=bb.x) return aa.x>bb.x; else return aa.y>bb.y; });
    for(int i=0;i<N;i++)
    {
        int miniy=1005,jum=-1;
        point red=a[i];
        for(int j=0;j<N;j++)
        {
            point blue=b[j];
            if(blue.use==1) continue;
            if(red.x<blue.x && red.y<blue.y && miniy>blue.y )
            {
                miniy = blue.y;
                jum = j;
            }
        }
        if(jum==-1) continue;
        else b[jum].use=1,dap++;
    }
    printf("%d",dap);
}


Measured memory_bytes: 256
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cassert>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int n,k;

int main()
{
    scanf("%d%d",&n,&k);
    if(n%k==0) puts("0");
    else puts("1");
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct node{
	int pri;
	int a[18];
} st[18]; 
const int maxn=1e9;
int b[18];
int main()
{
	int n,m,x;
	cin>>n>>m>>x;
	for(int i=0;i<n;i++)
	{
		cin>>st[i].pri;
		for(int j=0;j<m;j++)
		{
			cin>>st[i].a[j];
		}
	}
	int ans=maxn;
	for(int i=0;i<(1<<n);i++)
	{
		int sum=0;
		memset(b,0,sizeof(b));
		int flag=1;
		for(int j=0;j<n;j++)
		{
			if((i>>j)&1)
			{
				sum+=st[j].pri;
				for(int k=0;k<m;k++)
				{
					b[k]+=st[j].a[k];
				}
			}
		}
		for(int k=0;k<m;k++)
		{
			if(b[k]<x)
			{
				flag=0;
			}
		}
		if(flag) ans=min(ans,sum);
	}
	if(ans==maxn) cout<<"-1"<<"\n";
	else cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3600
m,k = map(int,input().split())
if k == 0:
    l = [i // 2 for i in range(2 ** (m + 1))]
    print(*l)
    exit()

if m == 0:
    if k == 0:
        print(0, 0)
    else:
        print(-1)
    exit()

if m == 1:
    if k == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
    exit()

if not 0 <= k < 2 ** m:
    print(-1)
    exit()

l = [0]
for i in range(2 ** (m - 1) - 1):
    l.append(2 ** (m - 1) - i)
for i in range(2 ** (m - 1)):
    l.append(i + 1)
for i in range(2 ** m):
    if i == 0:
        l.append(0)
    elif i == 2 ** (m - 1):
        l.append(l[i])
    else:
        l.append(l[i] + 2 ** (m - 1) - 1)

if k == 1:
    print(*l)
    exit()

for i in range(len(l)):
    if l[i] == 1:
        l[i] = k
    elif l[i] == k:
        l[i] = 1
print(*l)

Measured memory_bytes: 19476
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define all(v) v.begin(),v.end()
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*
2d pointer array
int **dp;
in main function
int row,col;
dp=new int*[n];
rep(i,n)dp[i]=new int[m]
*/
int32_t main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  fastio
  int n,k,q;
  cin>>n>>k>>q;
  map<int,int>m;
  rep(i,q)
  {
    int a;
    cin>>a;
    m[a]++;
  }
  repre(i,1,n){
    if(k-q+m[i]>0)cout<<"Yes\n";
    else cout<<"No\n";
  }

  return 0;
}


Measured memory_bytes: 6912
#include <stdio.h>

int main(){
  int A,B,C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  int turn=1;
  while(A>0 && C>0){
    if(turn==1){
      
      C=C-B;
    }else if(turn==-1){
      
      A=A-D;
    }
    turn=-turn;
  }
  
  if(A>0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1660
/*
g++ -std=c++14 -o2 -Wall exawizards2019B.cpp -o .\out\exawizards2019B.out
.\out\exawizards2019B.out
*/

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

typedef long long ll;

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  int n;
  cin >> n;
  cin >> s;
  int r = 0;
  int b = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'R') ++r;
    else ++b;
  }
  if (r > b) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 100000000;
typedef pair<char, int> P;



int main() {
	string S;
	cin >> S;
	string alpha = "abcdefghijklmnopqrstuvwxyz";
	vector<P> vec(26);
	rep(i,26) {
		vec.at(i).first = alpha.at(i);
		vec.at(i).second = 1;
	}
	rep(i, S.size()) {
		rep(j, 26) {
			if (S.at(i)==vec.at(j).first)
			{
				vec.at(j).second = 0;
				break;
			}
		}
	}
	rep(i, 26) {
		if (vec.at(i).second)
		{
			cout << vec.at(i).first << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

Measured memory_bytes: 3700
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int m = sc.nextInt();



		ArrayList<Integer> ss = new ArrayList<>();
		ArrayList<Integer> tt = new ArrayList<>();

		for(int i=0;i<m;i++) {
			ss.add(sc.nextInt());
			tt.add(sc.nextInt());
		}

		int[][] st = new int[n+1][n];

		for(int i=1;i<n+1;i++) {
			int counter =0;
			for(int j=0;j<ss.size();j++) {
				if(ss.get(j)==i) {
					counter++;
					st[i][counter]=tt.get(j);
				}
			}
			st[i][0]=counter;
		}

		double[] p = new double[n+1];

		double min =700;

		for(int i =1;i<n;i++) {//どこからの枝を狩るか

			for(int j =0;j<n+1;j++) {
				p[j]=0;
			}
			for(int j=n-1;j>0;j--) {//動的計画法

				double max = 0;
				int maxIndex = -1;
				if(i==j&&st[j][0]!=1) {//


					for(int k=1;k<st[j][0]+1;k++) {
						if(p[st[j][k]]>max) {
							max = p[st[j][k]];
							maxIndex = k;
						}
					}

				}

				for(int k=1;k<st[j][0]+1;k++) {
					if(maxIndex==-1) {
						if(k!=maxIndex)p[j]+=(p[st[j][k]]+1.0)*(1.0/st[j][0]);
					}else {
						if(k!=maxIndex)p[j]+=(p[st[j][k]]+1.0)*(1.0/(st[j][0]-1));
					}
				}

			}
			if(min>p[1])min=p[1];
		}




		//String s = sc.next();

		//String[] ss = s.split("");

		//int[] a = new int[n];


		double ans = min;

		System.out.println(ans);

		/*
		TreeMap<Integer,Integer> treeMap = new TreeMap<>();//sorted no duplication
		treeMap.put(b[n], n);
		*/

	}

}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 98544
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

long long arr[200010];

bool cmp(long long a, long long b) {
    return a > b;
}

int main() {
    int n;
    cin >> n;
    for(int i = 1;i <= n;i ++) {
        scanf("%lld", &arr[i]);
    }
    sort(arr + 1, arr + 1 + n, cmp);
    int cnt = n - 2;
    long long ans = arr[1];
    for(int i = 2;;i ++) {
        for(int j = 1;j <= 2;j ++) {
            if(cnt > 0) {
                ans += arr[i];
                cnt --;
            }
            else {
                cout << ans << endl;
                return 0;
            }
        }
    }
}

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

int main(){
    int N, count, MAXcount;
    count = 1;
    MAXcount  = 1;
    cin >> N;

    for (int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        if (tmp == 1){
            count++;
            MAXcount = max(MAXcount, count);
        } else {
            count = 1;
        }
    }

    cout << MAXcount << endl;
}


Measured memory_bytes: 3104
package main

import "fmt"

func main() {
	var N, L int
	fmt.Scan(&N, &L)

	sum := 0
	min := 1000
	for i := 0; i < N; i++ {
		v := L + i
		sum += v

		if min < 0 {
			min *= -1
		}
		if v < min {
			min = v
		}
	}

	fmt.Println(sum - min)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0}; 
using P = pair<int, int>;
const double pi = acos(-1.0);

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  int ans=0;
  int tmp;
  
  rep(i,n){cin>>a[i];}
  sort(all(a));
  vector<int>cnt(100001);
  rep(i,n){cnt[a[i]]++;}
  tmp=0;
  Rep(i,1,cnt.size()-1){
    tmp=cnt[i-1]+cnt[i]+cnt[i+1];
    ans=max(tmp,ans);
  }
  
  cout<<ans<<endl;
  
    
    
  return 0;
}


Measured memory_bytes: 3984
N=int(input())
W=list(map(int,input().split()))
s=0
total=sum(W)
ww=0
for w in W:
    if abs(total-2*s)<= abs(total-2*(s+w)):
        ww=w
        break
    s+=w
print(min(abs(total-2*s), abs(total-2*(s+ww))))

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int n; cin >> n;
    vector<string> S(n); REP(i,n) cin >> S[i];
    int u[n][26]; REP(j,n)REP(i,26) u[j][i] = 0;

    REP(i,n){
        for(char c : S[i]) u[i][c-'a']++;
    }

    int uu[26]; REP(i,26) uu[i] = INT_INF;
    REP(i,26){
        REP(j,n) chmin(uu[i], u[j][i]);
    }

    string ans = "";
    REP(i,26) ans += string(uu[i], 'a'+i);
    cout << ans << en;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int result = 0;
        for(int i = 0; i < N; i++){
            int A = sc.nextInt();
            if(K <= A){
                result++;
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 47788
#include <stdio.h>
int main(void){
  int g,p,i,pm;
  char s[100001];
  scanf("%s",s);
  for (i=0;s[i];i++){
    if (s[i]=='g') g++;
    else p++;
  }
  pm=((g+p)%2)? (g+p-1)/2:(g+p)/2;
  printf("%d\n",pm-p);
  return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

int main(){
  int y,m,d;
  char a,b;
  cin>>y>>a>>m>>b>>d;
  
  if(y<2019) cout<<"Heisei"<<endl;
  else if(y>2019) cout<<"TBD"<<endl;
  else if(m<=4) cout<<"Heisei"<<endl;
  else cout<<"TBD"<<endl;

  return 0;
}

Measured memory_bytes: 3428
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
#define N 8

int board[N][N];
vector< pair<int,int> > queen;
vector< pair<int,int> > sol_queen;

bool check(int k, int x, int y)
{
  for(int i=0;i<k;i++)
  {
    int tx = queen[i].first;
    int ty = queen[i].second;
    if(x == tx) return false;
    if(y == ty) return false;
    if((x-tx)*(x-tx) == (y-ty)*(y-ty)) return false;
  }
  return true;
}

/*
void printQueen() {
  for(int i=0;i<N;i++) {
    printf("%d : (%d,%d)\n",i,queen[i].first,queen[i].second);
  }
}
*/

void setQueen(int k,bool is_solution) {
  if(k == N && !is_solution) {
    is_solution = true;
    sol_queen = queen;
    return;
  }
  for(int i=0;i<N;i++) {
    for(int j=0;j<N;j++) {
      if(check(k,i,j)) {
        queen[k] = make_pair(i,j);
        setQueen(k+1,is_solution);
      }
    }
  }
}

int main() {
  // initialize
  queen.resize(N,make_pair(-1,-1));

  int k,r,c;
  scanf("%d",&k);
  for(int i=0;i<k;i++) {
    scanf("%d %d",&r,&c);
    queen[i] = make_pair(r,c);
  }

  setQueen(k,false);

  for(int k=0;k<N;k++) {
    board[sol_queen[k].first][sol_queen[k].second] = 1;
  }
  for(int i=0;i<N;i++) {
    for(int j=0;j<N;j++) {
      if(board[i][j] == 0)
        printf(".");
      else
        printf("Q");
    }
    printf("\n");
  }
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  string s; cin >> s;
  int N = (int)s.size();
  int a = 0, b = 0;
  REP(i, N) {
    if (s[i] == '0') a++; else b++;
  }
  cout << 2 * min(a, b) << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <queue>
#include <vector>
const int MAXN = 1005;
const int NOPE = -1;
typedef std::vector<int> vin;
int  dist[MAXN];
bool seen[MAXN];
vin G[MAXN];
int M, N;
int a, b;

struct State {
  int sink;
  int size;
  int upper[MAXN];

  void display() {
    printf("%d\n", size + 1);
    int cur = sink;
    while (cur != NOPE) {
      printf("%d\n", cur);
      cur = upper[cur];
    }
  }

  void reset() {
    sink = NOPE;
    size = NOPE;
    for (int i = 1; i <= N; ++i) {
      upper[i] = NOPE;
    }
  }
} best, S;

void reset() {
  for (int i = 1; i <= N; ++i) {
    dist[i] = NOPE;
    seen[i] = false;
  }
  S.reset();
}

void bfs(int src) {
  reset();
  std::queue<int> Q;
  dist[src] = 0;
  seen[src] = true;
  Q.push(src);

  while (!Q.empty()) {
    int cur = Q.front();
    Q.pop();
    for (int nxt: G[cur]) {
      if (nxt == src) {
        if ((S.sink == NOPE) ||
            (dist[cur] < S.size)) {
          S.sink = cur;
          S.size = dist[cur];
        } // Shortest cycle at "src"
      }
      if (seen[nxt]) continue;
      dist[nxt] = dist[cur] + 1;
      seen[nxt] = true;
      S.upper[nxt] = cur;
      Q.push(nxt);
    }
  }
}

void solve() {
  best.reset();
  for (int i = 1; i <= N; ++i) {
    bfs(i);
    if (S.sink == NOPE) continue;
    if ((best.sink == NOPE) || (S.size < best.size)) {
      best = S;
    } // Shortest cycle.
  }
}

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; ++i) {
    scanf(" %d%d", &a, &b);
    G[a].push_back(b);
  }
  solve();
  if (best.sink != NOPE) {
    best.display();
  } else {
    puts("-1");
  }
  return 0;
}

Measured memory_bytes: 256
// C - Bugged
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

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

	int MAX = 0;
	vi S(N+1);
	for(int i=1; i<=N; ++i){
		cin>>S[i];
		MAX += S[i];
	}

	vi dp(MAX+1, false);
	dp[0] = true;
	for(int i=1; i<=N; ++i){
		int s = S[i];
		for(int j=MAX; j>=s; --j){
			if(dp[j-s]){
				dp[j] = true;
			}
		}
	}

	int ans = 0;
	for(int j=MAX; j>=0; --j){
		if(dp[j] && j%10){
			ans = j;
			break;
		}
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)

signed main() {
  ll n,k; cin >> n >> k;
  vector<ll> p(n), c(n);
  rep(i,n) {cin >> p[i]; p[i]--;}
  rep(i,n) cin >> c[i];

  vector<int> loopsize(n);
  vector<ll> loopvalue(n);
  vector<vector<ll>> a(n, vector<ll>(n, 0));

  rep(i,n) {
    ll current = i;
    ll ss = 0;
    ll val = 0;
    rep(j,n) {
      ss++;
      ll pnext = p[current];
      val += c[pnext];
      current = pnext;
      if(current==i) {
        loopsize[i] = ss;
        loopvalue[i] = val;
        break;
      }
    }
  }

  rep(i,n) {
    ll current = i;
    rep(j,n) {
      ll pnext = p[current];
      a[i][j] = c[pnext] + (j>0 ? a[i][j-1] : 0);
      current = pnext;
      if(current==i) break;
    }
  }

  ll ans = -1000000000;
  rep(i,n) {
    if(loopvalue[i] <= 0) {
      rep(j,loopsize[i]) ans = max(ans, a[i][j]);
    }
    else {
      ll loops = k / loopsize[i];

      ll base = loops * loopvalue[i];
      ans = max(ans, base);
      rep(j,k%loopsize[i]) ans = max(ans, base+a[i][j]);

      ll base2 = (loops-1) * loopvalue[i];
      rep(j,n) ans = max(ans, base2+a[i][j]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 198872
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

typedef vector<vector<int>> Graph;
void add_edge(Graph& g, int from, int to, bool isDirected) {
	g[from].push_back(to);
	if (!isDirected) g[to].push_back(from);
}

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

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

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

	int h,w,m; cin >> h >> w >> m;

	vector<int> a(h,0),b(w,0);
	map<int,int> mp;
	rep(_i, m) {
	  int i,j; cin >> i >> j;
		i--; j--;
		a[i]++; b[j]++;
		mp[i*w+j]++;
	}
	int maxa = 0, maxb = 0;
	vector<int> ixa, ixb;
	rep(i, h) if (chmax(maxa, a[i])) { 
	  ixa.clear(); 
	  ixa.push_back(i);
	}
	else if (maxa == a[i]) ixa.push_back(i);

	rep(i, w) if (chmax(maxb, b[i])) { 
		ixb.clear();
		ixb.push_back(i);
	}
	else if (maxb == b[i]) ixb.push_back(i);

	//debug(ixa) 
	//debug(ixb)

	if (ixa.size()*ixb.size() > m) cout << maxa + maxb << endl;
	else {
		for (int c : ixa) for (int d : ixb) {
			if (mp[c * w + d] == 0) {
			  //cerr << "bomb : " << c << "," << d << endl;
				cout << maxa + maxb << endl;
				return 0;
			}
		}

		cout << maxa + maxb - 1 << endl;
	}
}



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

int main()
{
    std::string Sa, Sb, Sc;
    
    std::cin >> Sa >> Sb >> Sc;
    
    char key = Sa[0];
    bool flag = true;
    Sa.erase(Sa.begin());

    while (flag) {

        switch (key) {
            case 'a':
                if (Sa.empty()) {
                    std::cout << "A";
                    flag = false; 
                } else {
                    key = Sa[0];
                    Sa.erase(Sa.begin());
                }
                break;

            case 'b':
                if (Sb.empty()) {
                    std::cout << "B";
                    flag = false;
                } else {
                    key = Sb[0];
                    Sb.erase(Sb.begin());
                }
                break;

            case 'c':
                if (Sc.empty()) {
                    std::cout << "C";
                    flag = false;
                } else {
                    key = Sc[0];
                    Sc.erase(Sc.begin());
                }
                break;

            default:
                break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    int n,k ;
    scanf ("%d%d",&n,&k) ;
    int ans=k ;
    for (int i=1; i<n; i++){
        ans*=(k-1);
    }
    printf ("%d\n",ans);
    return 0 ;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  string s;
  cin>>s;
  string ans;
  for(char c:s){
    if(c=='1') ans.push_back('1');
    else if(c=='0') ans.push_back('0');
    else if(ans.size()>0) ans.pop_back();
  }
  cout<<ans<<endl;
  
  return 0;
}

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

int main(){
    ll n,m,d;
    cin >> n >> m >> d;
    ll cnt = 0;
    cnt = d + 2 * (n-d - d - 1 + 1) + (n-(n-d));
    if(d == 0) cnt = d + (n-d - d - 1 + 1) + (n-(n-d));

    double ans = cnt * (m-1) / (double)n / (double)n;
    cout << Double(ans)<< endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,x,N,M,a[1000],b,c[1000];
  scanf("%d%d",&N,&M);
  //syokika
  for(i=0;i<1000;i++){
    c[i]=0;
  }
  //
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<M;i++){
    scanf("%d",&b);
    for(j=0;j<N;j++){
      if(a[j]<=b){
	c[j]++;
	break;
      }
    }
  }
  x=0;
  for(i=0;i<M;i++){
    if(c[x]<c[i])x=i;
  }
  printf("%d\n",x+1);
  return 0;
}

Measured memory_bytes: 1032
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define iter vector<int>::iterator
#define mod 998244353



int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;

    int h[n];
    int dp[n];

    for(int i=0;i<n;i++)
    {
    	cin>>h[i];
    }
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);

    for(int i=2;i<n;i++)
    {
    	dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }
    
    cout<<dp[n-1]<<"\n";
    
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
    int a,b,c,tmp;
    scanf("%d %d %d", &a, &b, &c);
    if (a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    if (a > c) {
        tmp = a;
        a = c;
        c = tmp;
    }
    if (b > c) {
        tmp = b;
        b = c;
        c = tmp;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}

Measured memory_bytes: 596