akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

int main(){
    int n,c,k;
    int t[100010];
    cin>>n>>c>>k;
    REP(i,n) cin>>t[i];
    sort(t,t+n);
    int i=0;
    int cnt=0;
    while(i<n){
        for(int j=i;j<n;j++){
            if(t[i]+k<t[j] || j-i+1>c) {
                cnt++;
                i=j;
                break;
            }
            if(j==n-1){
                i=n;
                cnt++;
                break;
            }
        }
    }
        cout<<cnt<<endl;
    
    return 0;
}

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

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

    string a;
    cin >> a;
    if (a == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 3488
<?php

while (true) {
    $dataCount = trim(fgets(STDIN));
    if ($dataCount == 0) { return; }
    
    $dataSet = [];
    for ($i = 0; $i < $dataCount; $i++) {
        list($employeeNum, $ratio, $sale) = explode(' ', trim(fgets(STDIN)));
        if (empty($dataSet[$employeeNum])) {
            $dataSet[$employeeNum] = $ratio * $sale;
        } else {
            $dataSet[$employeeNum] += $ratio * $sale;
        }
    }
    
    $result = [];
    foreach ($dataSet as $key => $value) {
        if ($value >= 1000000) {
            $result[] = $key;
        }
    }
    
    if (empty($result)) {
        $result[] = 'NA';
    }
    
    echo implode(PHP_EOL, $result), PHP_EOL;
}

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

using namespace std;
typedef long long ll;

int main() {
  ll N; cin >> N;
  vector<ll> W(N);
  ll sum = 0;
  for (ll j=0; j < N; ++j){
    cin >> W[j];
    sum += W[j];
  }
  ll ans = 100000001;
  ll acc = 0;
  for (ll j=0; j < N; ++j) {
    acc += W[j];
    ans = min(ans, abs((sum-acc)-acc));
  }
  cout << ans << endl;
  return 0;
}


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

using ll = long long;
const int INF = 1e9 + 1;

int main() {

	string s, t;
	cin >> s >> t;
	cout << t << s << endl;

	return 0;
}

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

int main(){
  string S, T;
  cin >> S;
  if(S[0]=='S'){
    T="Cloudy";
  }
  if(S[0]=='C'){
    T="Rainy";
  }
  if(S[0]=='R'){
    T="Sunny";
  }
  cout << T << endl;
}

Measured memory_bytes: 256
main :: IO ()
main = do
    [x1,y1,x2,y2] <- map read . words <$> getLine :: IO [Int]
    let dx = x2 - x1
        dy = y2 - y1
        x3 = x2 - dy
        y3 = y2 + dx
        x4 = x3 - dx
        y4 = y3 - dy
    putStrLn . unwords . map show $ [x3, y3, x4, y4]


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int add=(a+b);
    if(add%2==0)
    {
        cout<<add/2<<endl;
    }
    else
    {
        cout<<"IMPOSSIBLE"<<endl;
    }


}


Measured memory_bytes: 3636
n = list(input())
s = 0
for a in n:
    s += int(a)

if len(n) >= 2:
    if int(n[0]) >= 2:
        print(max(s, (len(n)-1)*9+int(n[0])-1))
    else:
        print(max(s, (len(n)-1)*9))
else:
    print(int(n[0]))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int N, C, opt = INF, per[5], cst[35][35];
bool used[35];
int grp[5][35];

int main(){
  FAST_IO

  cin >> N >> C;

  for(int r = 1; r <= C; ++r){
    for(int c = 1; c <= C; ++c){
      cin >> cst[r][c];
    }
  }

  for(int r = 1; r <= N; ++r){
    for(int c = 1, x; c <= N; ++c){
      cin >> x;
      grp[(r + c) % 3][x]++;
    }
  }

  for(int o = 1; o <= C; ++o){
    for(int t = 1; t <= C; ++t){
      for(int th = 1, cost; th <= C; ++th){
        if(o == t || t == th || o == th) continue;
        per[0] = o, per[1] = t, per[2] = th;
        cost = 0;
        for(int g = 0; g < 3; ++g){
          for(int c = 1; c <= C; ++c){
            cost += grp[g][c] * cst[c][per[g]];
          }
        }

        min_self(opt, cost);
      }
    }
  }

  cout << opt << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=3;i++)
	{
		if(i!=m&&i!=n)
		{
			cout<<i;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String[] c = br.readLine().split(" ");

		Card cb[];
		cb = new Card[n];
		for (int i = 0; i < n; i++) {
			cb[i] = new Card(c[i].charAt(0), Character.getNumericValue(c[i].charAt(1)));
		}

		Card cs[];
		cs = cb.clone();

		cb = bubble(cb, n);
		cs = selection(cs, n);

		for (int i = 0; i < n; i++) {
			System.out.print(cb[i].suit + String.valueOf(cb[i].value) + (i != n - 1 ? " " : ""));
		}
		System.out.println("\nStable");
		for (int i = 0; i < n; i++) {
			System.out.print(cs[i].suit + String.valueOf(cs[i].value) + (i != n - 1 ? " " : ""));
		}
		if (isStable(cb, cs)) {
			System.out.println("\nStable");
		} else {
			System.out.println("\nNot stable");
		}
	}

	private static Card[] bubble(Card[] c, int n) {
		Card t;
		boolean flag = true;

		while(flag) {
			flag = false;

			for (int i = 0; i < n - 1; i++) {
				if (c[i].value > c[i + 1].value) {
					t = c[i];
					c[i] = c[i + 1];
					c[i + 1] = t;
					flag = true;
				}
			}
		}

		return c;
	}

	private static Card[] selection(Card[] c, int n) {
		Card t;

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

			for (int j = i + 1; j < n; j++) {
				if (c[j].value < c[minj].value) {
					minj = j;
				}
			}

			if (minj != i) {
				t = c[i];
				c[i] = c[minj];
				c[minj] = t;
			}
		}

		return c;
	}

	private static boolean isStable(Card[] c1, Card[] c2) {
		for (int i = 0; i < c1.length; i++) {
			if (c1[i].suit != c2[i].suit) {
				return false;
			}
		}

		return true;
	}
}

final class Card {
	public char suit;
	public int value;

	public Card(char suit, int value) {
		this.suit = suit;
		this.value = value;
	}
}


Measured memory_bytes: 24500
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<math.h>
using namespace std;

int main() {
	int N;
	int a[100009];
	cin >> N;
	a[0] = 0;
	int b[100009];
	long sum=0;
	a[N + 1] = 0;
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
		b[i] = abs(a[i] - a[i - 1]);
		sum += b[i];
	}
	b[N+1] = abs(a[N+1] - a[N]);
	sum += b[N+1];
	int cs = sum;
	for (int i = 1; i <= N; i++) {
		cout << (cs - b[i]-b[i+1]+abs(a[i-1]-a[i+1]) )<< endl;
		cs = sum;
	}
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

ll dp[101][101][303];

int n,w;
int g[101],v[101];

ll rek(int cur, int left, int wlef) {
    if(cur == n) {
        return 0;
    }
    if(dp[cur][left][wlef] == -1) {
        ll rez = 0;
        if(left == 0) {
            rez = rek(cur + 1, left, wlef);
        }
        else {
            if(wlef >= g[cur])
                rez = v[cur] + rek(cur + 1, left - 1, wlef - g[cur]);
            rez = max(rez, rek(cur + 1, left, wlef));
        }
        dp[cur][left][wlef] = rez;
    }
    return dp[cur][left][wlef];
}

int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n>>w;
    for(int ctr1 = 0;ctr1 < n; ctr1++)
        cin>>g[ctr1]>>v[ctr1];

    int mi = min(w / (g[0] + 3), 100);
    int ma = min(w / g[0], 100);

    ll min_weight = g[0];

    for(int ctr1 = 0; ctr1 < n; ctr1++)
        g[ctr1] -= min_weight;

    ll rez = 0;

    for(int ctr1 = mi; ctr1 <= ma; ctr1++) {
        rez = max(rez, rek(0, ctr1, min(w - ctr1*min_weight, 300LL)));
    }
    cout<<rez;
    return 0;
}


Measured memory_bytes: 24448
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    string st="", en="";
    bool rev=false;
    string S;
    cin>>S;
    ll Q;
    ll f, t;
    string chin;
    cin>>Q;
    rep(i, Q){
        cin>>t;
        if(t==1){
            if(rev==false) rev=true;
            else rev=false;
        }
        else{
            cin>>f;
            if(rev==true){
                if(f==1) f=2;
                else f=1;
            }
            cin>>chin;
            if(f==1) st+=chin;
            else en+=chin;
        }
    }
    if(rev==true){
        string Sb=S, enb=en;
        rep(i, S.size()) S[i]=Sb[S.size()-i-1];
        rep(i, en.size()) en[i]=enb[en.size()-i-1];
        cout<<en+S+st<<endl;
    }
    else{
        string stb=st;
        rep(i, st.size()) st[i]=stb[st.size()-i-1];
        cout<<st+S+en<<endl;
    }
    return 0;
}


Measured memory_bytes: 1564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

int main() {
    int N; cin >> N;
    int sum = 0;
    int index;

    rep1(i,N+2) {
      sum += i;
      if(sum >= N) { index = i; break;  }
    }
    if(sum == N) rep1(i, index + 1) cout << i << endl;
    else {
      rep1(i, index + 1) {
        if(i != sum - N ) cout << i << endl;
      }
    }
    return 0;
}


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

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

using namespace std;

int main(){
  int n;cin>>n;
  vector<ll>a(n), b(n), d;
  ll suma=0, sumb=0, result=0, remain=0;
  rep(i,n){
    cin>>a[i];
    suma+=a[i];
  }
  rep(i,n){
    cin>>b[i];
    sumb+=b[i];
    ll t=a[i]-b[i];
    remain+=t;
    if(t<0) result++;
    else if(t>0) d.push_back(t);
  }

  if(remain<0){
    cout<<-1<<endl;
    return 0;
  }

  sort(d.begin(), d.end());

//cout<<result<<endl;
  rep(i,d.size()){
//cout<<result<<':'<<d[i]<<'|'<<remain<<endl;
    if(d[i]<=remain){
      remain -= d[i];
    }else{
      result++;
    }
  }

  cout<<result;

  return 0;
}


Measured memory_bytes: 2428
#include<stdio.h>
#include<stdlib.h>
#define N 100005

typedef struct pp{
  char name[100];
  int t;
}P;

void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(P);
P dequeue(void);

int TIME=0;

P Q[N+1];
int head,tail,n;

int main(){
  int elaps=0,c;
  int i,q;
  P u;
  initialize();
  scanf("%d%d",&n,&q);//プロセス数とクオンタムの入力
  for(i=1;i<=n;i++){
    scanf("%s",u.name);
    scanf("%d",&u.t);
    enqueue(u);
  }
  
  while(isEmpty()!=1){
    u=dequeue();
      if (u.t<=q){
	TIME=TIME+u.t;
	printf("%s %d\n",u.name,TIME);

      }
      
      else{
	TIME=TIME+q;
	u.t=u.t-q;
	enqueue(u);
      }
      
    }
    
  
  
  return 0;
}

void initialize(){
  head=1;
  tail=1;
}

int isEmpty(){
  if(head==tail)
    return 1;
  else return 0;
}

int isFull(){
  if(head==(tail+1)%N)
    return 1;
  else return 0;
}

void enqueue(P x){
  if(isFull()==1){
    printf("Queue is Full\n");
    exit(1);
  }
  Q[tail]=x;
  if((tail+1)==N)
    tail=1;
  else tail++;
}

P dequeue(){
  P x;
  if (isEmpty()==1){
    printf("Queue is Empty\n");
    exit(2);
  }
  x=Q[head];
  if((head+1)==N)
    head=1;
  else head++;
  return x;
}



Measured memory_bytes: 11856
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    int num;
    int cnt=1;
    while(1){
    //0?????\?????????????????§??\???????¶???????    
        scanf("%d",&num);
        if (num==0)break;
        printf("Case %d: %d\n",cnt,num);
        cnt++;
    }
return 0;
}

Measured memory_bytes: 600
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a<=8 && b<=8 && a+b<=16)
            System.out.println("Yay!");
        else
            System.out.println(":(");
	}
}


Measured memory_bytes: 27096
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <set>

using namespace std;
void input(set<int> &);
void output(set<int> &);

int main()
{
    set<int> A, B;
    input(A);
    input(B);

    // set<int>::iterator it = B.begin();
    // while (it != B.end())
    // {
    //     if (A.find(*it) == A.end())
    //     {
    //         A.insert(*it);
    //     }
    //     it++;
    // }
    // output(A);


    //法2
    set<int> C;
    set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(C, C.begin()));
    output(C);
 
}


void input(set<int> & A)
{
    int n;
    cin >> n;

    int a;
    while (n--)
    {
        cin >> a;
        A.insert(a);
    }
}

void output(set<int> & A)
{
    set<int>::iterator it = A.begin();
    while (it != A.end())
    {
        cout << *it << endl;
        it++;
    }
}


Measured memory_bytes: 40572
#include <iostream>
#include <vector>
#include <list>
#include<utility>
#include <new>
#include <string>
#include<cmath>
#include<unordered_set>
#include<iomanip>
#include <stack>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll =  long long int;
#define mod 1000000007
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
int main()
{  int h,w;
cin>>h>>w;
vector<vector<char>>a(h,vector<char>(w));
loop(i,0,h){
loop(j,0,w){
    cin>>a[i][j];
}
}
vector<vector<int>>dp(h,vector<int>(w,0));
loop(i,0,h){
loop(j,0,w){
if(a[i][j]=='#'){
    dp[i][j]=0;
}else{
    if(i==0&&j==0){
        dp[0][0]=1;
    }else if(i==0){
        dp[0][j]=dp[0][j-1];
    }else if(j==0){
    dp[i][0]=dp[i-1][0];
    }else{
        dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
}
}
}
}
cout<<dp[h-1][w-1];

     return 0;
}


Measured memory_bytes: 8448
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
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();}
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;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N;
  cin>>N;
  ll A[N],B[N],ans=0,cnt=0,mn=INF;
  bool CAN=true;
  REP(i,N){
    cin>>A[i]>>B[i];
    if(A[i]>B[i]) chmin(mn,B[i]);
    if(A[i]!=B[i]) CAN=false;
    cnt+=A[i];
  }
  if(CAN){
    co(0);
    return 0;
  }
  ans=cnt-mn;
  cout<<ans<<endl;
  return 0;
}

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


Measured memory_bytes: 3628
//HovalHaq!
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxN = 1 << 13, maxLg = 45;
int Nxt[maxN][maxLg], Sum[maxN][maxLg], Opt[maxN][maxLg], Ans[maxN][maxLg];

int32_t main() {
	//Input, bases
	int n, k; cin >> n >> k;
	for(int i = 0; i < n; i++) {
		cin >> Nxt[i][0];
		Nxt[i][0]--;
	}
	for(int i = 0; i < n; i++) {
		cin >> Sum[i][0];
		Opt[i][0] = Sum[i][0];
	}
	vector<int> Bits;
	for(int i = 0; i < maxLg; i++)
		if((k >> i) & 1) Bits.push_back(i);

	for(int i = 1; i < maxLg; i++)
		for(int j = 0; j < n; j++) {
			Nxt[j][i] = Nxt[Nxt[j][i - 1]][i - 1];
			Sum[j][i] = Sum[Nxt[j][i - 1]][i - 1] + Sum[j][i - 1];
			Opt[j][i] = max(Opt[j][i - 1], Sum[j][i - 1] + Opt[Nxt[j][i - 1]][i - 1]);
		}


//	for(int i = 0; i < maxLg; i++) {
//		for(int j = 0; j < n; j++)
//			cout << Nxt[j][i] << " ";
//		cout << "\n";
//	}

	for(int i = 0; i < Bits.size(); i++)
		for(int j = 0; j < n; j++)
			Ans[j][i + 1] = max(Opt[j][Bits[i]], Sum[j][Bits[i]] + Ans[Nxt[j][Bits[i]]][i]);
	int X = Ans[0][Bits.size()];
	for(int i = 1; i < n; i++) X = max(X, Ans[i][Bits.size()]);
	cout << X;
}


Measured memory_bytes: 10644
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A,B;
    cin >> A >> B;
    cout << "100 100" << endl;
    rep(i,50){
        rep(j,100){
          	if(A>1&&i%2==0&&(i+j)%2==0){
          		A--;
                cout << '.';
            }
            else{
                cout << '#';
            }
        }
        cout << endl;
    }
    rep(i,50){
        rep(j,100){
            if(B>1&&i%2==1&&(i+j)%2==0){
                B--;
                cout << '#';
            }
            else{
                cout << '.';
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int a;
  int ans = 0;
  cin>>n;
  for (int i=0;i<n;i++){
    cin>>a;
    while(a%2==0){
      ans += 1;
      a/=2;
    }
  }
  cout<<ans<<endl;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N;
    cin >> N;
    vector<lint> a(N, 0);
    rep(i, N) cin >> a[i];

    vector<lint> mi(0);

    for (int i = 0; i < N; i++) {
        int idx = lower_bound(mi.begin(), mi.end(), a[i]) - mi.begin();
        // dump(mi);
        // d(idx);
        if (idx == mi.size())
            mi.push_back(a[i]);
        else
            mi[idx] = a[i];
    }

    // dump(mi);
    cout << mi.size() << endl;

    return 0;
}


Measured memory_bytes: 4588
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
ans=[]
for i in range(h-1):
  for j in range(w):
    if a[i][j]%2==1:
      a[i+1][j]+=1
      ans.append([i+1,j+1,i+2,j+1])
for i in range(w-1):
  if a[h-1][i]%2==1:
    a[h-1][i+1]+=1
    ans.append([h,i+1,h,i+2])
print(len(ans))
for m in ans:
  print(*m)
  


Measured memory_bytes: 32420
num = int( input() )
for j in range( num ) :
    inputed = list(map(int, input().split()))
    maxIndex = inputed.index( max(inputed) )
    judger = 0;
    for k in range( 3 ) :
        if( maxIndex != k ) :
            judger += inputed[ k ] ** 2
    if judger == ( inputed[ maxIndex ] ** 2 ) :
        print("YES")
    else :
        print("NO")

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

const int MAX_N = 10010;
typedef unsigned long long ull;
typedef long long ll;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    ll A, B, C;
    cin >> A >> B >> C;
    if(A==B && B==C){
        if(A%2==1){
            cout << 0 << endl;
        }else{
            cout << -1 << endl;
        }
    }else{
        ll res = 0;
        while(A%2!=1 && B%2!=1 && C%2!=1){
            res++;
            ll pA = A;
            ll pB = B;
            ll pC = C;
            A = (pB+pC)/2;
            B = (pC+pA)/2;
            C = (pA+pB)/2;
        }
        cout << res << endl;
    }
    return 0;
}

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

using namespace std;
char s1[16],s2[16]={'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'};
int ans;
int main()
{
	cin>>s1;
	for(int i=0;i<16;i++)
	{
		if(s1[i] != s2[i]) ans++;
	}
	cout<<ans<<endl; 
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static int gcd(int x, int y) {
		if (y == 0) {
			return x;
		}
		return gcd(y, x % y);
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int y = in.nextInt();
		System.out.println(gcd(x, y));
		in.close();
	}
}


Measured memory_bytes: 26340
#include <algorithm>
#include <iostream>
 
using namespace std;
 /* 1000000000000 1000000000000 1099511627775
 */ 
int main(int argc, char** argv) {
  long long h;
  cin >> h;

  long long cur = h;
  long long times = 0;
  long long n = 1;
  while (cur > 0) {
    times += n;
    if (cur > 1) {
      cur >>= 1;
      n *= 2;
    } else {
      break;
    }
  }
    
  cout << times << "\n";
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
  
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
  
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
  
using namespace std;
//using namespace __gnu_pbds;
         
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using pld = pair <ld, ld>;
 
/*
const ll MAX_MEM = 5e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
 
*/
 
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
         
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
         
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
         
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
         
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("circlecover.in", "r", stdin);
    //freopen("circlecover.out", "w", stdout);
}
 
signed main()
{
    Start();
    int n;
    cin >> n;
    vector <int> a(2 * n);
    cin >> a;
    sort(all(a));
    int ans = 0;
    for (int i = 0; i < 2 * n; i += 2)
        ans += a[i];
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
suits = ('S', 'H', 'C', 'D')
cards = dict()
for s in suits:
    cards[s] = [False] * 13

n = int(input())
for i in range(n):
    suit, rank = input().split()
    cards[suit][int(rank) - 1] = True

for s in suits:
    for i in range(13):
        if cards[s][i] == False:
            print(s, i+1)




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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

void solve(){
    ll n;
    cin >> n;
    string s = "";
    rep(i, n){
    	ll c = i+1;
    	s.pb(c+'0');
    }
    sort(all(s));
    map < string , ll > mpp;
    ll j = 1;
    do{
    	mpp[s] = j;
    	j++;
    }while(next_permutation(all(s)));
    string a, b;
    char x;
    rep(i, n){
    	cin >> x;
    	a.pb(x);
    }
    rep(i, n){
    	cin >> x;
    	b.pb(x);
    }
    //cout << a << " " << b;
    cout << abs(mpp[a] - mpp[b]) << endl;
}

int main(){
    IOS;
    //io_set();
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        solve();
    }
    return 0;
} 

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
long long a[100010];
int main()
{
	int n,i;
	long long ans=1;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		if(!a[i])
		{
			cout<<0;
			return 0;
		}
	}
	for(i=0;i<n;i++)
	{
		if(1000000000000000000ll/ans<a[i])
		{
			cout<<-1;
			return 0;
		}
		ans*=a[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4376
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
using namespace std;
int main() {
	int n;
	int a[100010];
	int co = 0, ans = 0;
	cin >> n;
	for (int b = 0; b < n; b++) {
		cin >> a[b];
	}
	sort(a, a + n);
	for (int i = 0; i < n-1; i++) {
		if (a[i] == a[i + 1]) {
			co++;
		}
		else {
			if (co % 2 == 0) {
				ans++;
			}
			co = 0;
		}
	}
	if (co % 2 == 0) {
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define MP make_pair
#define all(o) (o).begin(), (o).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define fr(i,n) for(lli i=0;i<n;++i)
#define rep(i,a,b) for(lli i=a;i<=b;++i)
#define per(i,a,b) for(lli i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b))) 
#define sz(x) (lli)(x).size()
#define endl '\n'
typedef long long lli;        typedef long double ld;
typedef pair<lli,lli> ii;     typedef vector<lli> vi;
typedef vector<ii> vii;       typedef vector<vi> graph;
long long MOD=1000000007;     long double EPS=1e-9;
#define debarr(a,n) cout<<#a<<" : ";for(int i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debmat(mat,row,col) cout<<#mat<<" :\n";for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
lli binpow(lli b,lli p,lli mod){lli ans=1;b%=mod;for(;p;p>>=1){if(p&1)ans=ans*b%mod;b=b*b%mod;}return ans;}

void pre(){

}
lli dp[(1<<16)];
lli final[(1<<16)];
void solve(){
	lli n;
	cin>>n;
	lli arr[n][n];
	fr(i,n)fr(j,n)cin>>arr[i][j];
	rep(mask,0,((1<<n)-1)){
		dp[mask]=0;
		for(int i=0;i<n;i++){
			if(mask&(1<<i)){
				for(int j=i+1;j<n;j++){
					if(mask&(1<<j)){
						dp[mask]+=arr[i][j];
					}
				}
			}
		}
	}	
	final[0]=0;
	rep(mask,1,(1<<n)-1){
		for(int sub=mask;sub;sub=mask&(sub-1)){
			remax(final[mask],final[mask^sub]+dp[sub]);
		}
	}
	cout<<final[(1<<n)-1]<<endl;
}

signed main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
	pre();lli t=1;//cin>>t;
	for(lli i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

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


Measured memory_bytes: 128
import math
a, b, x = map(int, input().split())

if 2*x/a/b <= a:
    z = 2*x/a/b
    d = math.degrees(math.atan(b/z))
else:
    y = 2*x/(a**2) -b
    d = math.degrees(math.atan((b-y)/a))
print(d)

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

int main()
{
	int n;
	while(cin >> n){
	double ans = 0;
	int t = n / 2;
	if(n % 2 == 1){
		ans = 1.00 * (t + 1.00) / n;
	}
	else{
		ans = 1.00 * t / n;
	}
	printf("%.6lf\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

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

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

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

template <typename T>
T gcd(T a, T b) {
  if(b == 0) return a;
  else return gcd(b,a%b);
}



int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

// struct UnionFind {
//   vector<int> par;

//   UnionFind(int n) {
//     par.resize(n,-1); 
//   }

//   int root(int x) {
//     if(par[x] < 0) return x;
//     else return par[x] = root(par[x]);
//   }

//   bool issame(int x, int y) {
//     return root(x) == root(y);
//   }

//   bool merge(int x, int y) {
//     x = root(x); y = root(y);
//     if(x == y) return false;
//     if(par[x] > par[y]) swap(x,y);
//     par[x] += par[y];
//     par[y] = x;
//     return true;
//   }
  
//   int size(int x) {
//     return -par[root(x)];
//   }
// };
  
int main() {
  string s,t;
  cin >> s >> t;
  int N = s.size();
  bool f = false;
  if(t.substr(0,N) == s) f =true;
  cans(f);
    
}














Measured memory_bytes: 3132
function Main(input) {
  const N = parseInt(input.split('\n')[0])
  const A = input.split('\n')[1].split(' ').map(Number)
  let result = 0;

  for (i=0;i<N-1;i++){
    if(A[i] >= A[i+1]) {
      result = result + A[i]-A[i+1]
      A[i+1] = A[i]} 
  }
  console.log(result)
  }

  Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

bool prime(ll x)
{
    if(x <= 1) return false;
    ll i;
    for(i = 2;i*i <= x;++i){
        if(x%i == 0) return false;
    }
    return true;
}

int main()
{
    ll i,j;
    ll x;
    cin >> x;
    for(i = x;i <= 1e5+3;++i){
        if(prime(i)){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

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

int main(){
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int sum=0,cnt=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                sum=500*i+100*j+50*k;
                if(sum==x) cnt++;
                else continue;
            }
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int x,y;


    cin>>x>>y;
    if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12))
        cout<<"Yes"<<endl;
    else if ((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11))
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
A = []
for _ in range(N):
    A.append([int(x) for x in input().split()])
A = sorted(A)
cnt = 0
for i in A:
    cnt += i[1]
    if cnt >= K:
        print(i[0])
        sys.exit()

Measured memory_bytes: 22408
import sys
sys.setrecursionlimit(500000)
n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(lambda x: int(x)-1, input().split())
    G[x].append(y)

# iを始点としたときの有効パスの最大長さ
dp = [-1] * n
 
def rec(s):
    if dp[s] != -1:
        return dp[s]

    ret = 0
    for ns in G[s]:
        ret = max(ret, rec(ns)+1)
    dp[s] = ret
    return ret

ml = 0    
for i in range(n):
    ml = max(ml, rec(i))
print(ml)

Measured memory_bytes: 59056
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

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

    vector<vector<int>> dp(n+1, vector<int>(h+10001, inf));
    for(int i=0; i<=n; i++) dp[i][0] = 0;

    for(int i=0; i<n; i++){
        for(int j=0; j<=h+10000; j++){
            chmin(dp[i+1][j], dp[i][j]);
            if(j - a[i] >= 0) chmin(dp[i+1][j], dp[i+1][j - a[i]] + b[i]);
        }
    }

    int ans = inf;
    for(int i=h; i<=h+10000; i++) chmin(ans, dp[n][i]);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 78592
(N, ) = [int(n) for n in input().split()]

F = [0 for _ in range(N)]

for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            val = x * x + y * y + z * z + x * y + y * z + z * x
            if val <= N:
                F[val-1] += 1
for f in F:
    print(f)
    



Measured memory_bytes: 9428
n = int(input())
a, b = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
key1 = 0
key2 = n-1
for i in range(n):
    if p[i] > a:
        key1 = i-1
        break
for i in range(key1+1,n):
    if p[i] > b:
        key2 = i-1
        break
print(min(key1+1,key2-key1,len(p)-1-key2))

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; string s; cin>>n>>s;
  
  ll l=0;
  rep(i,n){
    if(s[i]=='(') l++;
    else{
      if(l>0) l--;
    }
  }
  s+=string(l,')');
  n=s.size();
  
  ll r=0;
  rrep(i,n){
    if(s[i]==')') r++;
    else{
      if(r>0) r--;
    }
  }
  s=string(r,'(')+s;
  cout<<s<<endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int n, q, s, t;

inline ll foehn(ll a){
    return a > 0 ? -s*a : t*(-a);
}

int main(){
    scanf("%d %d %d %d", &n, &q, &s, &t);
    vector<ll> a(n+1, 0), d(n+1, 0);
    ll ans = 0;
    scanf("%lld", a.begin());
    for(int i = 1; i <= n; i++){
        scanf("%lld", a.begin()+i);
        d[i] = a[i] - a[i-1];
        ans += foehn(d[i]);
    }
    int l, r, x;
    while(q-- > 0){
        scanf("%d %d %d", &l, &r, &x);
        ll bef = foehn(d[l]);
        d[l] += x;
        ll aft = foehn(d[l]);
        ans += aft-bef;
        if(r < n){
            bef = foehn(d[r+1]);
            d[r+1] -= x;
            aft = foehn(d[r+1]);
            ans += aft-bef;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 5992
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

A,B = map(int,S().split())

if A<=9 and B<=9:
    print(A*B)
else:
    print(-1)

Measured memory_bytes: 61876
import bisect

N,Q =  map(int, input().split())
S = input()

start = []
# end = []

for i in range(N-1):
	if S[i] == "A" and S[i+1] == "C":
		start.append(i)
#		end.append(i+1)

length = len(start)
for _ in range(Q):
	left, right = map(int, input().split())
	left -= 1
	right -= 1

	if length == 0:
		print(0)
	else:
		# startの中で、left以上であるものの最小インデックス

		l1 = bisect.bisect_left(start, left)
#		r1 = bisect.bisect_right(end, right) - 1
		r1 = bisect.bisect_right(start, right-1) - 1

		print (r1-l1+1)

'''

	r = length
	l = 0
	c = int((r+l)//2)
	while(l<r):

		if start[c] >= left:
			r = c
			c = int((r+l)//2)
		else:
			l = c
			c = int((r+l)//2)

	X1 = c

	# endの中で、right以下であるものの最大インデックス
	r = length
	l = 0
	c = int((r+l)//2)
	while(l<r):

		if end[c] > right:
			r = c
			c = int((r+l)//2)
		else:
			l = c
			c = int((r+l)//2)

	X2 = c

	print(X2-X1+1)
'''

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

bool ismonth(int n) {
    return 1 <= n && n <= 12;
}

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

    string S; cin >> S;
    int h = (S[0] - '0') * 10 + S[1] - '0';
    int l = (S[2] - '0') * 10 + S[3] - '0';

    if (!ismonth(h) && ismonth(l)) {
        cout << "YYMM" <<endl;
    } else if (ismonth(h) && !ismonth(l)) {
        cout << "MMYY" << endl;
    } else if (ismonth(h) && ismonth(l)) {
        cout << "AMBIGUOUS" << endl;
    } else {
        cout << "NA" << endl;
    }
}


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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

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

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
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();
}

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

int N;
string s;

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

  cin >> N >> s;

  string tmp = "";
  tmp += s[0];
  for (int i = 1; i < N; i++) {
    if (tmp.back() != s[i]) tmp += s[i];
  }

  cout << tmp.size() << endl;

  return 0;
}

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

int main(){
    ios::sync_with_stdio(false);    cin.tie(NULL);  cout.tie(NULL);
    int n, k;   cin >> n >> k;  
    int bak=0;  vector<int> vec(n);
    for(int i=0;n>i;i++){
        cin >> vec[i];  bak=__gcd(bak, vec[i]);
    }
    for(int i=0;n>i;i++){
        if(vec[i]>=k and !((vec[i]-k)%bak)){
            cout << "POSSIBLE"; return 0;
        }
    }
    cout << "IMPOSSIBLE";
}

Measured memory_bytes: 640