akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}

	public int[][] jump = new int[][]{
		{-1, -2}, {0, -2}, {1, -2},
		{-2, -1}, {2, -1},
		{-2, 0}, {2, 0},
		{-2, 1}, {2, 1},
		{-1, 2}, {0, 2}, {1, 2}
	};

	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while((line = in.readLine()) != null){
			List<Point> que = new ArrayList<Point>();
			List<Integer> step = new ArrayList<Integer>();
			String[] tmp = line.split(" ");
			int ix = Integer.parseInt(tmp[0]);
			int iy = Integer.parseInt(tmp[1]);
			if(ix==0 && iy==0) break;
			Point init = new Point(ix, iy);

			line = in.readLine();
			int n = Integer.parseInt(line);
			Point[] sp = new Point[n];
			line = in.readLine();
			tmp = line.split(" ");
			for(int i=0; i<n; i++){
				int xx = Integer.parseInt(tmp[2*i]);
				int yy = Integer.parseInt(tmp[2*i+1]);
				sp[i] = new Point(xx, yy);
			}


			int ok = 0;
			que.add(init);
			step.add(0);
			while(que.size() != 0){
				Point p = que.get(0);
				que.remove(0);
				int s = step.get(0);
				step.remove(0);

				if(s==sp.length){
					ok = 1;
					break;
				}

				for(int i=0; i<12; i++){
					int x = p.x + jump[i][0];
					int y = p.y + jump[i][1];
					if(x>=0 && y>=0 && x<10 && y<10){
						if(x >= sp[s].x-1 && x <=sp[s].x+1 && y >= sp[s].y-1 && y <= sp[s].y+1){
							que.add(new Point(x, y));
							step.add(s+1);
						}
					}
				}
			}

			if(ok==1){
				System.out.println("OK");
			}else{
				System.out.println("NA");
			}
		}
	}
}

class Point{
	int x;
	int y;
	public Point(int x, int y){
		this.x = x;
		this.y = y;
	}
}

Measured memory_bytes: 9668
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,c = m()

time = [[0 for i in range(31)] for j in range(10**5+2)]

popopo = [[] for i in range(30)]

for i in range(n):
    s,t,c = m()
    popopo[c-1].append([s,t])


for i in range(30):
    popopo[i].sort()
    
for i in range(30):
    for j in range(len(popopo[i])):
        s,t = popopo[i][j]
        if time[s][i+1] == 0:
            time[t][i+1] = 1
            time[s-1][0] += 1
            time[t][0] -= 1
        else:
            time[t][i+1] = 1
            time[s][0] += 1
            time[t][0] -= 1

ma = time[0][0]
for i in range(1,10**5+2):
    time[i][0] += time[i-1][0]
    ma = max(ma,time[i][0])
print(ma)




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

int main() {

    int w;
    cin >> w;

    string res;
    while ( w > 0 ) {
	switch ( w%3 ) {
	case 0:
	    res = '0' + res;
	    break;
	case 1:
	    res = '+' + res;
	    break;
	case 2:
	    res = '-' + res;
	    ++w;
	    break;
	}
	w /= 3;
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std ; 
int main()
{
int n ; cin >> n ;
int flag = 0 ; 
for(int i = 0 ; i < 3 ; i++)
{
int temp = n % 10 ; 
if(temp == 7)
flag =1 ; 
 
n = n/10 ; 
}
if(flag) 
cout << "Yes" ; 
else 
cout << "No" ; 
 
}

Measured memory_bytes: 3568
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    
    for (int i = 1; i <= n; i++) {
        int x = i;
        if (x % 3 == 0) {
            cout << " " << i;
            continue;
        }
        while (x) {
            if (x % 10 == 3) {
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
template<class T>using vv = vector<vector<T>>;
using vvi = vv<int>;
using vvl = vv<long long>;

#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
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;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif


int N, M, Q;
vi A, B, C, D;
int dfs(vi& v) {
  if (v.size() == N) {
    int ans = 0;
    rep(i, Q) {
      if (v[B[i]] - v[A[i]] == C[i])
        ans += D[i];
    }
    return ans;
  }
  int ans = 0;
  rep(i, M+1) {
    if (i < v.back())
      continue;
    v.push_back(i);
    chmax(ans, dfs(v));
    v.pop_back();
  }
  return ans;
}

int main() {
  in(N);
  in(M);
  in(Q);

  A.resize(Q), B.resize(Q), C.resize(Q), D.resize(Q);
  rep(i, Q) {
    cin >> A[i];
    cin >> B[i];
    cin >> C[i];
    cin >> D[i];
    --A[i], --B[i];
  }

  vv<int> dp(N, vi(M+1, 0));

  vi v;
  v.push_back(1);
  cout << dfs(v) << endl;

  return 0;
}


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

int main() {
	stringstream ss; int n; ss << "ai1333" << flush; cin >> n;
	for (int i = 0; i < n / 100; i++) ss << "3" << flush;
	cout << ss.str() << endl;
	return 0;
}


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

int main(){
	int s,w;
	cin >> s >> w;
	if(w >= s){
		cout << "unsafe" << endl;
	}else{
		cout << "safe" << endl;
	}
    return 0;
}



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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  i64 n, k;
  cin >> n >> k;
  i64 ans = n * n;
  if (k == 0) {
    cout << ans << endl;
    return 0;
  }
  ans -= n * k;
  ans -= (k - 1) * (n - k);
  repi(b, k + 1, n + 1) {
    i64 c = (n - k + 1) / b;
    ans -= c * k + max(0ll, n - b * (c + 1) + 1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include  <stdio.h>
int main(void){
int n,a,b;

/*printf("N");*/ scanf("%d",&n);
/*printf("A");*/ scanf("%d",&a);
/*printf("B");*/ scanf("%d",&b);

int z;
z=n*a;
if(z<b){
  printf("%d \n",z);
}else{
  printf("%d \n",b);
}
return 0;
}


Measured memory_bytes: 128
n=int(input())
count = 0
i = 1
while i <= n:
    if i < 10:
        count+=1
    elif 10**2 <= i and i < 10**3:
        count+=1
    elif 10**4 <= i and i < 10**5:
        count+=1
    i = i+1
print(count)

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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 long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    ll ans = -(ll)INF*INF;
    chmax(ans, (ll)a * c);
    chmax(ans, (ll)a * d);
    chmax(ans, (ll)b * c);
    chmax(ans, (ll)b * d);
    cout << ans << endl;
}

Measured memory_bytes: 3632
n = int(input())
for _ in range(n):
    data = list(map(int, input().split()))
    B, C = 0, 0
    flag = True
    for d in data:
        if B < d:
            B = d
        elif C < d:
            C = d
        else:
            print("NO")
            flag = False
            break
    if flag:
        print("YES")


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

using ui = unsigned int;
using ll = long long;
using ull = unsigned long long;
using str = string;
using bl = bool;
using ch = char;

template<class T> using v = vector<T>;
template<class T> using uset = unordered_set<T>;
template<class T1, class T2> using umap = unordered_map<T1, T2>;

template<class T> void pd(T x)
{
    cout << x << " ";
}
template<class T> void pl(T x)
{
    cout << x << endl;
}

#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define sz(x) ((int)(x).size())
#define ph push_back
#define pp pop_back
#define mp make_pair
#define rep(i, a) for(int i = 0; i < (int)a; ++i)
#define repd(i, a) for(int i = (int)a; i >= 0; --i)
#define REP(i, a, b) for(int i = a; i < (int)b; ++i)
#define REPD(i, a, b) for(int i = (int)a; i >= b; --i)
#define fore(i, a) for(auto& i : a)
#define FORE(i, a) for(auto i : a)

// -----



int main()
{
    ll x;
    cin >> x;
    
    REPD(a, 119, -118)
    {
        REPD(b, 119, -118)
        {
            ll A = pow(a, 5), B = pow(b, 5);
            if(A - B == x)
            {
                pd(a);
                pl(b);
                return 0;
            }
        }
    }
}


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

int main(){
	string n;
	getline(cin, n);
	for (int i = 0; i < n.size(); i++){
		if (n[i] == 'p'){
			if (n[i + 1] == 'e'){
				if (n[i + 2] == 'a'){
					if (n[i + 3] == 'c'){
						if (n[i + 4] == 'h'){
							n[i] = 'a';
							n[i + 1] = 'p';
							n[i + 2] = 'p';
							n[i + 3] = 'l';
							n[i + 4] = 'e';
							continue;
						}
					}
				}
			}
		}
		if (n[i] == 'a'){
			if (n[i + 1] == 'p'){
				if (n[i + 2] == 'p'){
					if (n[i + 3] == 'l'){
						if (n[i + 4] == 'e'){
							n[i] = 'p';
							n[i + 1] = 'e';
							n[i + 2] = 'a';
							n[i + 3] = 'c';
							n[i + 4] = 'h';
						}
					}
				}
			}
		}
	}
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 3128
#include<stdio.h>

void swap(long long int* a, long long int* b){
    long long int c=*a;
    *a=*b;
    *b=c;
}

int main(){
    long long int n, a, b;
    scanf("%lld %lld %lld", &n, &a, &b);
    if(b < a){
        swap(&a, &b);
    }
    if(a == b){
        printf("0");
    }else if((b-a)%2 == 1){
        long long int ans = 0;
        long long int ax = a-1;
        long long int by = n-b;
        if(ax < by){
            ans += ax;
            ans++;
            ans += ((b-1) - (ax + 1))/2;
        }else{
            ans += by;
            ans++;
            ans += ((n-a) - (by + 1))/2;
        }
        printf("%lld", ans);
    }else{
        printf("%lld", (b-a)/2);
    }

    return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).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; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    vector<int> a(N);
    rep(i, N) cin >> a[i];

    sort(all(a));
    reverse(all(a));

    int alice = 0, bob = 0;
    rep(i, N) {
        if (i % 2 == 0) alice += a[i];
        else bob += a[i];
    }

    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main() {
    int A,B,C,X,i,j,n=0;
    scanf("%d\n%d\n%d\n%d",&A,&B,&C,&X);
    int Xa,Xb,Xc;
    Xa = X/500;
    for (i=0; i <= A && i <= Xa; i++) { //まず500円玉の枚数決める
        Xb = (X - 500*i) / 100;
        for (j=0; j <= B && j <= Xb; j++) {
            Xc = (X - 500*i - 100*j) / 50;
            if (C >= Xc) {
                n += 1;
            }
        }
    }
    printf("%d\n",n);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int square[105][105];
int arr[10005];
bool visited[105][105];
int n,m;
int q;
void DFS(int x,int y,int color)
{
    if(x < 0 || x >= n || y < 0 || y >= m || color > q)
        return;

    if(square[x][y] == 0)
     {
         if(arr[color] > 0)
         {
             square[x][y] = color;
             arr[color]--;
         } else {
            DFS(x,y,color + 1);
         }
     } else return;
    DFS(x,y + 1,color);
    DFS(x + 1,y,color);
    DFS(x,y - 1,color);
    DFS(x - 1,y,color);
    return;
}
int main()
{
    cin >> n >> m >> q;
    for(int i = 1;i <= q;i++)
        cin >> arr[i];

    DFS(0,0,1);
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
            printf("%d ",square[i][j]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 2147483647
typedef long long ll;
using namespace std;
#define N (1<<17)

class RMQ{
private:
    int dat[N*2];
    int dfs(int l,int r,int a,int b,int k){
	if(l<=a&&b<=r)return dat[k];
	if(b<=l||r<=a)return mod;
	int m=(a+b)/2;
	int vl=dfs(l,r,a,m,k*2+1);
	int vr=dfs(l,r,m,b,k*2+2);
	return min(vl,vr);
    }
    
public:
    void Init(){
	fill(dat,dat+N*2,mod);
    }
    void Update(int i,int x){
	i+=N-1;
	dat[i]=x;
	while(i){
	    i=(i-1)/2;
	    dat[i]=min(dat[i*2+1],dat[i*2+2]);
	}
    }
    int Query(int l,int r){
	return dfs(l,r,0,N,0);
    }
};

int main(){
    int n,q;
    cin>>n>>q;
    RMQ rmq;
    rmq.Init();
    while(q--){
	int a,b,c;cin>>c>>a>>b;
	if(c==0){
	    rmq.Update(a,b);
	}
	if(c==1){
	    cout<<rmq.Query(a,b+1)<<endl;
	}
    }
    return 0;
}



Measured memory_bytes: 4140
// ABC156_B
#include <algorithm>
#include <bitset>  // static_cast<std::bitset<8>>
#include <cctype>  // std::isdigit()
#include <climits>  // INT_MIN
#include <cmath>
#include <cstring>  // std::memset
#include <functional>  // std::greater<T>()
#include <iomanip>
#include <iostream>
#include <iterator>
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <sstream>  // std::stringstream
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>  // std::swap()
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;
#define rep(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define rep1(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define repr(i, n) for (ll i=n-1; i >= 0; i++)  // n-1 ~ 0
#define all(vec) (vec).begin(), (vec).end()
#define sum(vec) accumulate(all(vec), 0LL)  // 0 は初期値
#define min_vec(vec) min_element(all(vec))  // iterator: * を先頭につける
#define max_vec(vec) max_element(all(vec))  // iterator: * を先頭につける
#define idx(vec, element_iter) distance((vec).begin(), element_iter)
const ll INF = 1LL<<60;  // 10^18（const int inf = 1<<29;）
const double PI = acos(-1);

ull Decimal2BinaryStr(ull n, ull K) {
    // 10^18(long long) 程度にしか使えないので注意
    if (n == 0 || n == 1) return 1;
    ull res = 0, cnt = 0;
    while (n != 0) {
        res += (n%K)*(ull)pow(10, cnt);  // 10進数で数字をつくる
        n /= K;
        cnt++;
    }
    return cnt;
}
// 10011 00010 01011 01000 0000

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    // input(sunippets: inpv, inpn, inps)
    ull N, M;
    cin >> N >> M;
    
    // calculation
    ull res = Decimal2BinaryStr(N, M);
    cout << res << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void){
  int a, b, c, i, count = 0;

  scanf("%d %d %d", &a, &b, &c);

  for (i = a; i <= b; i++) {
    if (c % i == 0) {
      count++;
    }
  }

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

  return 0;
}

Measured memory_bytes: 1848
import System.IO
import Control.Monad
import Data.Function
main = do
  fix $ \loop -> do
    eof <- isEOF
    unless eof $ do
      n <- readLn
      print $ length [()| x <- [0..9]
                          , y <- [0..9]
                          , z <- [0..9]
                          , w <- [0..9]
                          , x + y + z + w == n]
      loop

Measured memory_bytes: 4196
n = int(input())
cnt = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
 
for _ in range(n):
  b, f, r, v = map(int, input().split())
  cnt[b-1][f-1][r-1] += v
 
for i in range(4):
  for j in range(3):
    print(' '+' '.join(map(str, cnt[i][j])))
 
  if i != 3:
    print('#'*20)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>


using namespace std;

int main() {
	int n;
	cin >> n;
	
	vector<int> p(n,0);
	
	for (int i = 0; i < n; i++) {
		cin >> p.at(i);
	}
	
	int ans = 0;
	
	for (int i = 0; i < n-2; i++) {
		if((p.at(i+2) > p.at(i+1) && p.at(i+1) > p.at(i)) || (p.at(i+2) < p.at(i+1) && p.at(i+1) < p.at(i))) {
			ans++;
		}
	}
	
	cout << ans << endl;
	


	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
string s;
int main() {
  cin>>s;
  int len=s.length();
  for(int i=0;i<=len;++i) {
    if(s[i]=='C') {
      for(int j=i;j<=len;++j) {
        if(s[j]=='F') {
          printf("Yes\n");
          return 0;
        }
      }
    }
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 256
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);

#ifdef BUGGY
	bool DEBUG = 1;
#endif
#ifndef BUGGY
	bool DEBUG = 0;
#endif

map<char, char> mp[2];

// pair<int, char> getVal(char a, char b) {
// 	if (mp.find(a) == mp.end() && mp.find(b) == mp.end()) {
// 		mp[a] = b;
// 		mp[b] = a;
// 		return make_pair(1, b);
// 	} else if (mp.find(a) || mp.)else {
// 		if (mp[a] != b)
// 		{
// 			return make_pair(0, b);
// 		} else {
// 			return make_pair(1, b);
// 		}
// 	}
// }

string S[2];

int main()
{
	cin >> S[0] >> S[1];

	int limit = S[0].size();

	int ans = 1;

	for (int i = 0; i < limit; i++) {
		// adj[S[0] - 'a'].push_back(S[1] - 'a' + 26);
		// adj[S[1] - 'a' + 26].push_back(S[0] - 'a');

		if (mp[0].find(S[0][i]) == mp[0].end()) {
			mp[0][S[0][i]] = S[1][i];
		} else {
			if (mp[0][S[0][i]] != S[1][i]) {
				ans = 0;
			}
		}

		if (mp[1].find(S[1][i]) == mp[1].end()) {
			mp[1][S[1][i]] = S[0][i];
		} else {
			if (mp[1][S[1][i]] != S[0][i]) {
				ans = 0;
			}
		}
	}

	if(ans) {
		printf("Yes\n");
	} else{
		printf("No\n");
	}

	return 0;
}
/*
	Powered by Buggy Plugin
*/

Measured memory_bytes: 776
n,k=map(int,input().split())
x=[0]
for xi in input().split():
    xi=int(xi)
    if xi==0:
        k-=1
    else:
        x.append(xi)
x.sort()
ans=float("INF")
zero=x.index(0)
for i in range(max(0,zero-k-1),min(zero+1,n-k+1)):
    if x[i+k]<0 or x[i]>0:
        continue
    jogen=abs(x[i+k])
    kagen=abs(x[i])
    ans=min(ans,jogen*2+kagen,kagen*2+jogen)
print(ans)


Measured memory_bytes: 62576
def b_flog2(N, K, H):
    """
    Aと同じ設定だが、足場はK個先まで移動できる
    """
    dp = [float('inf')] * N  # dp[i]: i番(0-based)の柱に到達するときの最小コスト
    dp[0] = 0
    # K本前までの柱のどれから来るのが最もコストが小さいか？
    for i in range(1, N):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))
    return dp[N - 1]

N, K = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
print(b_flog2(N, K, H))

Measured memory_bytes: 13928
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		int i, n;
		try (Scanner sc = new Scanner(System.in)) {
			n = sc.nextInt();
			List<Pairs> list = new ArrayList<>();
			for(i = 0; i < n; i++) {
				Pairs pairs = new Pairs(sc.nextInt(),sc.nextInt());
				list.add(pairs);
			}
			Comparator<Pairs> comparator =
					Comparator.comparing(Pairs::getx)
					.thenComparing(Pairs::gety);
			list.stream().sorted(comparator)
			.forEach(a -> System.out.println(a.getx() + " " + a.gety()));
		}
	}
}
class Pairs{
	private int x, y;
	public Pairs(int x, int y) {
		this.x = x;
		this.y = y;
	}
	public int getx() {
		return this.x;
	}
	public int gety() {
		return this.y;
	}
}


Measured memory_bytes: 109184
n,m = parse.(split(readline()))
a = ones(Int,n+10)
f = zeros(Int,n+10)
for i in 1:m
  a[parse(Int, readline())]=0
end
f[1]=1
for i in 1:(n+1)
  f[i]%=1000000007
  f[i+1]+=f[i]*a[i]
  f[i+2]+=f[i]*a[i+1]
end
println(f[n+1])


Measured memory_bytes: 148092
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <sstream>

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

using namespace std;
typedef long long ll;

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

    rep(i,n) {
        string s;
        cin >> s;

        set<string> st;
        st.insert(s);

        REP(j,1,s.size()){ 
            stringstream ss;
            rep(k,j) {
                ss << s[k];
            }
            string res = ss.str();

            stringstream ss2;
            REP(k,j,s.size()) {
                ss2 << s[k];
            }

            string res2 = ss2.str();

            string t = res;
            reverse(res.begin(),res.end());
            string t2 = res2;
            reverse(res2.begin(),res2.end());

            st.insert(t+t2);
            st.insert(t2+t);

            st.insert(t+res2);
            st.insert(res2+t);

            st.insert(res+t2);
            st.insert(t2+res);

            st.insert(res+res2);
            st.insert(res2+res);
        }

        cout << st.size() << endl;
    }

    return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <set>
using namespace std;
using T=tuple<int,int,int>;//i,r=0/l=1,i
int main(){
    int n,w,d;
    cin>>n>>w>>d;
    vector<T> V;
    for(int i=0;i<n;i++){
        int x,y; char dir;
        cin>>x>>y>>dir;
        if(dir=='N'){
            //left
            if(x+y<=d){
                V.emplace_back(2*w+2*d-(x+y),1,i);
            }else{
                V.emplace_back(2*w+d-(x+y-d),1,i);
            }
            //right
            if(y+w-x<=d){
                V.emplace_back(w+(y+w-x),0,i);
            }else{
                V.emplace_back(2*w+d-(x+d-y),0,i);
            }
        }else if(dir=='S'){
            //left
            if(x+y-w>=0){
                V.emplace_back(w+(x+y-w),1,i);
            }else{
                V.emplace_back(x+y,1,i);
            }
            //right
            if(y-x>=0){
                V.emplace_back(2*w+2*d-(y-x),0,i);
            }else{
                V.emplace_back(x-y,0,i);
            }
        }else if(dir=='E'){
            //left
            if(y+w-x<=d){
                V.emplace_back(w+(y+w-x),1,i);
            }else{
                V.emplace_back(2*w+d-(x+d-y),1,i);
            }           
            //right
            if(x+y-w>=0){
                V.emplace_back(w+(x+y-w),0,i);
            }else{
                V.emplace_back(x+y,0,i);
            }
        }else if(dir=='W'){
            //left
            if(y-x>=0){
                V.emplace_back(2*w+2*d-(y-x),1,i);
            }else{
                V.emplace_back(x-y,1,i);
            }
            //right
            if(x+y<=d){
                V.emplace_back(2*w+2*d-(x+y),0,i);
            }else{
                V.emplace_back(2*w+d-(x+y-d),0,i);
            }
        }
    }
    for(int i=0;i<2*n;i++){
        int a,b,c; tie(a,b,c)=V[i];
        V.emplace_back(a+2*w+2*d,b,c);
        V.emplace_back(a+4*w+4*d,b,c);
    }
    sort(V.begin(),V.end());
    /*
    for(auto v:V){
        int a,b,c; tie(a,b,c)=v;
        cout<<a<<' '<<b<<' '<<c<<endl;
    }*/
    int best = n+1;
    for(int j=0;j<2*n;j++){
        set<int> S;
        vector<int> Sta(n);//0:not covered, 1:covered
        int ans = 0;
        for(int i=j;i<j+2*n;i++){
            int loc,id,lr; tie(loc,lr,id)=V[i];
            if(lr==0){//r
                //S[id]=1;
                S.insert(id);
            }else{//l
                S.erase(id);
            }
        }
        for(int i=j+2*n;i<j+4*n;i++){
            int loc,id,lr; tie(loc,lr,id)=V[i];
            if(lr==0){//r
                //cout<<loc<<' '<<id<<endl;
                if(Sta[id]==0){
                    S.insert(id);
                }
            }else{//l
                if(S.count(id)){
                    ans++;
                    for(auto &s:S){
                        Sta[s]=1;
                    }
                    S.clear();
                }
            }
        }
        //cout<<ans<<endl;
        best=min(ans,best);
    }
    cout<<best<<endl;
    return 0;
}

Measured memory_bytes: 3252
from sys import stdin


def get_result(data):
    N, A = data[0], data[1]
    return 'YES' if len(set(A)) == N[0] else 'NO'

if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


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

int main(void){
  int N, slimes = 0;
  string s;
  char color = '?';
  cin >> N >> s;
  for(int i = 0; i < (int)s.length(); i++){
    if(s[i] != color){
      slimes++;
      color = s[i];
    }
  }
  cout << slimes << endl;
  return 0;
};


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
#define str(n) to_string(n)
#define int(w) stoi(w)
#define len(l) l.size()
#define append(l,i) l.push_back(i)
int main() {
    map<long long,long long> d;
    long long n,k;
    cin>>n>>k;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        if (d.count(a)){
            d[a]+=b;
        }
        else{
            d[a]=b;
        }
    }
    vector<pair<long long,long long>> dd;
    for (auto x: d){
        pair<long long,long long> d1=make_pair(x.first,x.second);
        dd.push_back(d1);
    }
    sort(all(dd));
    long long lim=0;
    int num=0;
    long long index=0;
    while (lim<k){
        lim+=dd.at(num).second;
        if (lim>=k){
index=dd.at(num).first;
        }
        num+=1;

    }
    cout<<index<<endl;


    return 0;
}

Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){


    string t;
    cin >> t;
    for(int i = 0; i < t.size(); i++){
        if(t[i] == '?'){
            t[i] = 'D';
        }
    }

    cout << t << endl;
    return 0;

}


Measured memory_bytes: 3752
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
import Data.Foldable (toList)
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readTuple4 :: IO (Int, Int, Int, Int)
readTuple4 = do
    [a, b, c, d] <- readInts
    return (a, b, c, d)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

data Query = Reverse | AddFirst Char | AddLast Char

solve :: String -> [Query] -> String
solve first queries = if isReversed then reverse $ toList s else toList s where
  firstS = Seq.fromList first
  go (isReversed, s) Reverse = (not isReversed, s)
  go (False, s) (AddFirst c) = (False, c Seq.<| s)
  go (False, s) (AddLast c) = (False, s Seq.|> c)
  go (True, s) (AddFirst c) = (True, s Seq.|> c)
  go (True, s) (AddLast c) = (True, c Seq.<| s)
  (isReversed, s) = foldl' go (False, firstS) queries


main :: IO ()
main = do
  first <- getLine
  q <- readInt
  queries <- replicateM q $ do
    w <- BC.getLine
    if w == "1" then
      pure Reverse
    else do
      let 
        [_, a, b] = BC.words w
        c = head $ BC.unpack b
      pure $ if a == "1" then AddFirst c else AddLast c
  putStrLn $ solve first queries




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

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

    for (int i = 0; i * 7 <= n; i++) {
        if ((n - i * 7) % 4 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
	int N,i,t,x,y,flag;
	flag = 0;
	cin >> N;
	for (i = 0;i < N;i++) {
		cin >> t >> x >> y;
		if (t % 2 == 0 && abs(x + y) % 2 == 0 && t >= abs(x) + abs(y)){}
		else if (t % 2 == 1 && abs(x + y) % 2 == 1 && t >= abs(x) + abs(y)) {}
		else {
			flag = 1;
		}
	}
	if (flag == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

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

using namespace std;

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

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

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<int>;
using vvi = vc<vi>;

using ll = long long;

string Reverse(int a, int b, const string& str) {
    auto reversed = str;
    FOR(i, a, b + 1) reversed[i] = str[a + b - i];
    return reversed;
}

string Replace(int a, int b, const string& pre_str, const string& in_str) {
    const int size_in = in_str.size();
    auto replaced = pre_str;

    REP(i, size_in) replaced[i + a] = in_str[i];
    return replaced;
}

void Print(int a, int b, const string& str){
    cout << str.substr(a, b - a + 1) << "\n";
}

int main() {
    string str;
    int    n;
    cin >> str >> n;

    REP(i, n) {
        string command;
        int a, b;
        cin >> command >> a >> b;
        if (command == "replace") {
            string in_str;
            cin >> in_str;
            str = Replace(a, b, str, in_str);
        } else if (command == "reverse"){
            str = Reverse(a, b, str);
        } else {
            Print(a, b, str);
        }
    }
    return 0;
}



Measured memory_bytes: 3184
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b, c = MAP()

if c-a-b > 0 and 4*a*b < (c-a-b)**2:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 13668
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A,B,C,D,E,F,G,H,K,L,M,N,P,Q,R,W,X,Y,Z;
string S,T;

int main(){
  cin >> N >> M;
  cout << (N*(N-1)+M*(M-1))/2 << endl;
}


Measured memory_bytes: 256
def knapsack1(N,W,weight,value):
    inf = float("inf")
    DP = [[-inf]*(W+1) for i in range(N+1)]
    for i in range(W+1): DP[0][i]=0

    for i in range(N):
        for j in range(W+1):
            if j-weight[i] >= 0:
                DP[i+1][j] = chmax(DP[i][j],DP[i][j-weight[i]]+value[i])
            else:
                DP[i+1][j] = chmax(DP[i+1][j],DP[i][j])
    return DP[N][W] 

def chmax(a,b):
    if a > b:
        return a
    else:
        return b

if __name__ == '__main__':
    N,W = map(int,input().split())
    weight = [0]*N
    value = [0]*N
    #print(weight,value)
    for i in range(N):   
        lst = list(map(int,input().split()))
        #print(lst)
        weight[i] = lst[0]
        value[i] = lst[1]
        #max_w += lst[0]
    #print(weight,value)
    ans = knapsack1(N,W,weight,value)
    print(ans)
    #print(max(max(ans)))
    #print(max(ans[-1]))
    

Measured memory_bytes: 296552
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;

int n, k, m, l, r, md, x, a[N], d[N];
int main()
{
	int i;
	cin >> n >> k >> m;
	for (i = 1; i <= n; i++) {
		scanf ("%d", &a[i]);
	}
	sort(a + 1, a + n + 1);
	for (i = 1; i <= n; i++) {
		l = max(i - k + 1, 1);
		r = i + 1;
		while (l < r) {
			md = (l + r) / 2;
			if (a[md] + m < a[i]) {
				l = md + 1;
			} else {
				r = md;
				x = md;
			}
		}
		d[i] = d[x - 1] + 1;
	}
	cout << d[n];
    return 0;
}


Measured memory_bytes: 1024
from collections import deque
from sys import stdin
L = stdin.readline().rstrip().split()
d = deque()
for s in L:
    if s.isdigit():
        d.append(int(s))
    else:
        a = d.pop()
        b = d.pop()
        if s == '+':
            d.append(b+a)
        elif s == '-':
            d.append(b-a)
        elif s == '*':
            d.append(b*a)
print(d[0])


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

using namespace std;

typedef long long ll;

ll n, ans;
ll a[2200];

ll binary_search(ll x, ll j)
{
  ll l = 0, r = n, mid;  
  while (l < r) {
    mid = (l + r) / 2;
    if (a[mid] >= x)
      r = mid;
    else
      l = mid + 1;
  }
  return l-j-1;
}

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

  for (int i = 0; i < n-1; i++) {
    for (int j = i+1; j < n; j++) {
      ans += binary_search(a[i]+a[j], j);
    }
  }
  
  cout << ans << endl;
  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++)
#define _GLIBCXX_DEBUG

int main() {
  int n,p=1,ans=0;
  cin>>n;
  vector<int>vec(n);
  rep(i,n){
    int a;
    cin>>a;
    vec.at(i)=a;
  }
  while (p!=2) {
    p=vec.at(p-1);
    ans+=1;
    if (ans>n) {
      ans=-1;
      break;
    }
  }
  cout<<ans<<endl;    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
int main(){
    int n;
    cin>>n;
    int v[n],c[n],ans=0;
    rep(i,0,n)cin>>v[i];
    rep(i,0,n){
        cin>>c[i];
        int t=v[i]-c[i];
        if(t>0)ans+=t;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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, k;
vector<int> p, c;

void solve() {
	cin >> n >> k;
    p.resize(n), c.resize(n);
    bool check = 0;
    rep(i, n) cin >> p[i], -- p[i];
    rep(i, n) {
        cin >> c[i];
        if(c[i] >= 0) check = 1;
    }
    if(!check) {
        cout << *max_element(all(c)) << endl;
        return;
    }
    static int to[40][5050], sum[40][5050], msum[40][5050];
    rep(i, n) {
        to[0][i] = p[i];
        sum[0][i] = c[p[i]];
        msum[0][i] = (c[p[i]] >= 0 ? c[p[i]] : 0);
    }
    rep(j, 39) {
        rep(i, n) {
            to[j + 1][i] = to[j][to[j][i]];
            sum[j + 1][i] = sum[j][to[j][i]] + sum[j][i];
            msum[j + 1][i] = max({sum[j + 1][i], sum[j][i] + msum[j][to[j][i]], msum[j][i]});
        }
    }
    vector<int> res0(n, 0), res1(n, 0), cur(n);
    iota(all(cur), 0);
    int ans = -INF;
    per(j, 35) {
        rep(i, n) {
            if(k & (1LL<<j)) {
                res1[i] = max({res0[i] + sum[j][cur[i]], res0[i] + msum[j][cur[i]]});
                res0[i] = res0[i] + sum[j][cur[i]];
                chmax(ans, res0[i]);
                chmax(ans, res1[i]);
                cur[i] = to[j][cur[i]];
            }
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 8492
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, M; cin >> N >> M;
	vector<int>H(N);
	rep(i, 0, N)cin >> H[i];
	Graph G(N);
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = 0;
	rep(i, 0, N) {
		bool is = true;
		for (auto p : G[i]) {
			if (H[i] <= H[p])is = false;
		}
		if (is)++ans;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 8744
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
 
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e4 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	double l;
	cin >> l;
	cout << fixed << setprecision(15) << (l/3) * (l/3) * (l/3);
	
}



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

void Main()
{
    int n, a;
    unordered_map<int, long> m1, m2;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        m1[i+a]++;
        m2[i-a]++;
    }
    long sum = 0;
    for (auto i: m1)
    {
        sum += i.second * m2[i.first];
    }

    cout << sum << endl;
    
    // j - i = a[j] + a[i]
    // j - a[j] = i + a[i]
}

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


Measured memory_bytes: 26336
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){
    ll H, W;
    cin >> H >> W;
    vector<ll > cnH(W, 0);
    vector<string> input;

    for(ll i = 0; i < H; i++){
        string s = "";
        ll cnW = 0;
        for(ll j = 0; j < W; j++){
            char t; cin >> t;
            if(t == '.'){
                cnW++;
                cnH[j]++; 
            } 
            s+=t;
        }
        if(cnW != W){
            input.push_back(s);
        }
    }

    for(ll i = 0; i < input.size(); i++){
        for(ll j = 0; j < W; j++){
            if(cnH[j] != H){
                cout << input[i][j];
            } 
        }
        cout << endl;
    }

}

Measured memory_bytes: 256
#include<stdio.h>
void BubbleSort(int *,int );
int main(){
  int A[100];
  int  N;
  int i;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  BubbleSort(A,N);
  return 0;
}

void BubbleSort(int *A,int N){
  int j,flag=1,temp,cnt=0;
  while(flag){
    flag=0;
    for(j=N-1;j>0;j--){
      if(A[j]<A[j-1]){
	temp=A[j];
	A[j]=A[j-1];
	A[j-1]=temp;
	cnt++;
	flag=1;
      }
    }
  }
  for(j=0;j<N;j++){
    if(j==N-1)printf("%d\n",A[j]);
    else printf("%d ",A[j]);
}
printf("%d\n",cnt);
}

Measured memory_bytes: 600