akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Pipes;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Runtime.InteropServices.ComTypes;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Security.Cryptography.X509Certificates;

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        void Omame()
        {
            cin = new Scanner();
            long R = cin.nextLong();
            Console.WriteLine(R * Math.PI * 2);
        }

    }
}
	

Measured memory_bytes: 27716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        long[] a = sc.LongArray();

        Dictionary<long, long> dic = new Dictionary<long, long>();
        for (long i = 0; i < n; i++)
        {
            long num = a[i] - i;
            if (!dic.ContainsKey(num))
            {
                dic.Add(num, 1);
            }
            else
            {
                dic[num]++;
            }
        }

        long answer = 0;

        for (long i = 0; i < n - 1; i++)
        {
            long target = 0 - (a[i] - i + 2 * i);
            if (dic.ContainsKey(target))
            {
                answer += dic[target];
            }
            dic[a[i] - i]--;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 57484
#include <bits/stdc++.h>
using namespace std;
int main(){
	char x;
	cin>>x;
	if(x=='A'){
		cout<<"T"<<endl;
	}
	else if(x=='T'){
		cout<<"A"<<endl;
	}
	else if(x=='G'){
		cout<<"C"<<endl;
	}
	else cout<<"G"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;


int main()
{

	int i,n;
	float cx,cy,dx,dy,dist;
	float x1,x2,x3,y1,y2,y3,a1,b1,c1,a2,b2,c2;
	cin >> n;
	for( int i = 0; i < n; i++ ) {
		cin >>x1 >> y1 >> x2 >> y2 >> x3 >> y3;
			
		a1 = 2*(x2-x1);
		b1 = 2*(y2-y1);
		c1 = x1*x1 - x2*x2 + y1*y1- y2*y2;
		a2 = 2*(x3-x1);
		b2 = 2*(y3-y1);
		c2 = x1*x1-x3*x3+y1*y1-y3*y3;
		cx = (b1*c2-b2*c1)/(a1*b2-a2*b1);
		cy = (c1*a2-c2*a1)/(a1*b2-a2*b1);

		dx = cx - x1;
		dy = cy - y1;
		dist = sqrt( dx*dx + dy*dy );
		
		printf("%.3f %.3f %.3f\n",cx,cy,dist);
	}


	return 0;
}

Measured memory_bytes: 0
//06
#include<iostream>
#include<queue>

using namespace std;

enum E{
  cr,gl,dc
};

struct DE{
  int d;
  E e;
  bool operator<(DE a)const{
    if(d!=a.d){
      return d>a.d;
    }else{
      e<a.e;
    }
  }
};

int main(){
  int n,k,t,u,v,l;
  cin>>n>>k>>t>>u>>v>>l;
  priority_queue<DE> que;
  while(n--){
    DE d={0,cr};
    cin>>d.d;
    que.push(d);
  }
  DE g={l,gl};
  que.push(g);
  int cc=0;
  double ct=0;
  int cp=0;
  bool ac=false;
  int dcc=0;
  for(;;){
    DE c=que.top();
    que.pop();
    ct+=(c.d-cp)*1./(ac?v:u);
    cp=c.d;
    if(c.e==gl){
      break;
    }else if(c.e==cr){
      if(cc<k){
	cc++;
      }else{
	DE nd={cp+v*t,dc};
	que.push(nd);
	dcc++;
      }
    }else{
      dcc--;
      ac=dcc;
    }
    if(!ac&&cc){
      cc--;
      ac=true;
      DE nd={cp+v*t,dc};
      que.push(nd);
      dcc++;
    }
  }
  cout<<fixed<<ct<<endl;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rsort(x) sort(x.rbegin(), x.rend())
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define fio(x) ios::sync_with_stdio(x), cin.tie(x), cout.tie(x);
#define znit(x) memset(x, 0, sizeof(x))
#define mnit(x) memset(x, -1, sizeof(x))
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<pair<int, int>, int> piii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db EPS = 1e-7;

const ll mod = 1e9 + 7;
const ll mod2 = 1e9 + 9;
ll mypow(ll x, ll y, ll p){ll ret = 1;while(y){if(y & 1) ret = (ret * x) % p;x = (x * x) % p; y /= 2;}return ret;}
ll inv(ll x, ll p){return mypow(x, p - 2, p);}
ll gcd(ll x, ll y){return y ? gcd(y, x % y) : x;}

const int MAX = 2e5 + 3;

int N, M, Q;
vector<int> chk[505];

int main(){
	scanf("%d %d %d", &N, &M, &Q);
	for(int i = 0; i < M; i++){
		int l, r;
		scanf("%d %d", &l, &r);
		chk[l].push_back(r);
	}
	for(int i = 1; i <= N; i++)
		sort(chk[i].begin(), chk[i].end());
	for(int i = 0; i < Q; i++){
		int l, r;
		scanf("%d %d", &l, &r);
		int ans = 0;
		for(int j = l; j <= r; j++){
			ans += upper_bound(chk[j].begin(), chk[j].end(), r) - chk[j].begin();
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2176
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;



int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    int x;
    
    for (int i=0; i<S.size(); i++) {
        x = ( S[i] - 'A' + N ) % 26;
        S[i] = x + 'A';
    }
    
    cout << S << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 1LL << 60;
constexpr int inf = 1 << 30;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N), CB(N), CC(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> B[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> C[i];
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll ans = 0LL;
    for (int i = 0; i < N; ++i) {
        int ia = upper_bound(A.begin(), A.end(), B[i] - 1) - A.begin();
        int ic = lower_bound(C.begin(), C.end(), B[i] + 1) - C.begin();
        ans += (ll)ia * (ll)(N - ic);
    }

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

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n;
int g[16][16];
int bit_counter(int x){
    if(x==0) return 0;
    return bit_counter(x>>1)+(x&1);
}
int main(){
    for(int i=0;i< 16;i++){
        for(int j=0;j<16;j++){
            g[i][j]=-1;
        }
    }
    cin>>n;
    for(int i=0;i<n;i++){
        int m;
        cin>>m;
        for(int j=0;j<m;j++){
            int a,x;
            cin>>a>>x;
            a--;
            g[i][a]=x;
        }
    }
    int ans=0;
    rep(i,1<<n){
        vector<int> d(n);
        rep(j,n){
            if(i>>j&1){
                d[j]=1;
            }
        }
        bool ok=1;
        rep(j,n){
            if(d[j]){
                rep(k,n){
                    if(g[j][k]==-1) continue;
                    if(g[j][k]!=d[k]) ok=0;
                }
            }
        }
        if(ok) ans=max(ans,bit_counter(i));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in);) {
			
			double x1 = sc.nextDouble();
			double y1 = sc.nextDouble();
			double x2 = sc.nextDouble();
			double y2 = sc.nextDouble();
			
			double distance = Math.sqrt((x2- x1) * (x2- x1) + (y2 - y1) * (y2 - y1));
			
			System.out.format("%.6f\n", distance);
		}
	}
}


Measured memory_bytes: 28284
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, m, h, w, x, y, sum, k, q;
ll A, B;

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

  cin >> A >> B >> m;
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  ans = LINF;
  rep(i, m) {
    cin >> x >> y >> c;
    x--;
    y--;
    ans = min(ans, a[x] + b[y] - c);
  }
  sort(a, a + A);
  sort(b, b + B);
  ans = min(ans, a[0] + b[0]);
  Cout(ans);
  return 0;
}

Measured memory_bytes: 5120
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d, e, k int
	var ans string
	fmt.Scan(&a, &b, &c, &d, &e, &k)

	if e-a <= k {
		ans = "Yay!"
	} else {
		ans = ":("
	}

	fmt.Println(ans)
}

Measured memory_bytes: 512
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx,tune=native")
#include "bits/stdc++.h"
using namespace std;
const int maxn = 15;
long long cost[1<<maxn][maxn];
long long g[maxn][maxn];
long long f[1<<maxn][maxn];
int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    for(int e = 0; e < m; e++){
        int u, v, w;
        scanf("%d %d %d", &u, &v, &w); u--; v--;
        g[u][v] = w;
        g[v][u] = w;
    }
    for(int i = 0; i < 1<<n; i++){
        for(int j = 0; j < n; j++){
            cost[i][j] = 0;
            for(int h = 0; h < n; h++){
                if(i&(1<<h)) cost[i][j] += g[h][j];
            }
        }
    }
    const long long inf = 1ll<<60;
    for(int i = 0; i < 1<<n; i++)
        for(int j = 0; j < n; j++)
            f[i][j] = inf;
    f[1][0] = 0;
    for(int i = 1; i < 1<<n; i++){
        for(int j = 0; j < n; j++){
            if(f[i][j] == inf) continue;
            if(!(i&(1<<j))) continue;
            for(int u = 0; u < n; u++)
                if(i&(1<<u));
                else if(g[j][u])
                    f[i|(1<<u)][u] = min(f[i|(1<<u)][u], f[i][j] + cost[i^(1<<j)][u]);
            int smask = ((1<<n) - 1) ^ i;
            for(int v = smask; v ; v = smask & (v - 1)){
                assert((i&v) == 0);
                long long add = 0;
                for(int u = 0; u < n; u++) if((i & (1<<u)) && u != j)
                    add += cost[v][u];
                f[i|v][j] = min(f[i|v][j], f[i][j] + add);
            }
        }
    }
    printf("%lld\n", f[(1<<n)-1][n-1]);
    // cout << clock()/(1.0 * CLOCKS_PER_SEC) << endl;
    return 0;
}


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

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

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

int main() {
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<vector<char>> v(n+2, vector<char>(n+2, 'X'));
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                v[i+1][j+1] = ' ';
            }
        }
        array<int, 4> dy{-1, 0, 1, 0}, dx{0, 1, 0, -1};
        int y = n, x = 1;

        for (int i = 0, dir = 0, a = 0; i < 2*n*n; ++i) {
            v[y][x] = '#';
            if(v[y+dy[dir]][x+dx[dir]] != ' ') dir = (dir+1)&3;
            else if(v[y+dy[dir]*2][x+dx[dir]*2] == '#') dir = (dir+1)&3;
            else {
                y += dy[dir];
                x += dx[dir];
            }
        }
        if(!(n&1)) v[n/2+1][n/2+1] = ' ';
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                cout << v[i+1][j+1];
            }
            puts("");
        }
        if(t) puts("");
    }
    return 0;
}


Measured memory_bytes: 3052
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
#include <algorithm>
using namespace std;

string S;
size_t cur=0;
int digit(){
	int n=S[cur++]-'0';
	return n;
}

int number(){
	int n=digit();
	while(isdigit(S[cur])){
		n=n*10+digit();
	}
	return n;
}

int term(){
	vector<int> list;
	int ans=0;
	while(S[cur]!=']'){
		if(S[cur]=='[')
			cur++,list.push_back(term());
		else if(isdigit(S[cur]))
			list.push_back(number());
		else if(cur==S.size())
			return list[0];
	}
	if(S[cur]==']'){
		cur++;
		sort(list.begin(),list.end());
		if(list.size()==1){
			ans+=(list[0]/2+1);
		}else{
			int n=(list.size()/2+1);
			for(int i=0;i<n;i++)
				ans+=list[i];
		}
	}
//	cout << ans << endl;
	return ans;
}

int main(void){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> S;
		cur=0;
		int ans=term();
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1276
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  a = make_divisors(n)
  ans = n-1
  for a1 in a:
    a2 = n//a1
    ans = min(ans,a1+a2-2)
  print(ans)
solve()

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

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

const int MAX = 22;
int N;
int P[MAX];

bool check(int n) {
    bool ans = false;
    ans |= P[n] > P[n+1] && P[n+1] > P[n+2];
    ans |= P[n] < P[n+1] && P[n+1] < P[n+2];
    return ans;
}

int main() {
    cin >> N;
    REP (i, N) cin >> P[i];
    int ans = 0;
    REP (i, N-2) {
        if (check(i)) ans++;
    }
    cout << ans << endl;
}

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

persons = [input() for i in range(N)]

cnt = [0 for i in range(M)]

for i_person in persons:
    l = list(map(int, i_person.split(" ")))
    

    for f in l[1:]:

        cnt[f-1] += 1

print(sum(list(map(lambda x:x==N, cnt))))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;


int main() {

    int i=0;
    long long int H,W;
    cin >> H >> W;
    if(H==1||W==1){
        cout << 1 << endl;
        return 0;
    }

    if((H*W)%2==0){
        cout << H*W/2 << endl;
    }else{
        cout << H*W/2+1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
a = input()
if a[-1] == '2' or a[-1] == '4' or a[-1] == '5' or a[-1] == '7' or a[-1] == '9':
  print('hon')
elif a[-1] == '0' or a[-1] == '1' or a[-1] == '6' or a[-1] == '8':
  print('pon')
else:
  print('bon')
  

Measured memory_bytes: 9104
def calc_simultaneeous(args)
  x = y = 0
  args.each_cons(6) do |a, b, c, d, e, f|
    y = (f - d * c / a) / (e - (d * b / a))
    x = (c - b * y) / a
  end
  "%.3f %.3f"%[x, y]
end

while input = gets
  puts calc_simultaneeous(input.chomp.split(' ').map! { |elm| elm.to_f })
end

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

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

    ll N, K;
    cin >> N >> K;
    vl P(N), C(N);
    REP(i, N) cin >> P[i];
    REP(i, N) P[i]--;
    REP(i, N) cin >> C[i];

    vector<bool> check(N, false);
    vvl G;
    REP(i, N){
        if(check[i]) continue;
        ll now = i;
        vl tmp;
        while(1){
            if(check[now]) break;
            check[now] = true;
            tmp.push_back(C[now]);
            now = P[now];
        }
        G.push_back(tmp);
    }

    //cout << G << endl;

    ll INF = (1ll<<60);
    ll res = -INF;

    REP(t, G.size()){
        vl A;
        for(auto  x: G[t]) A.push_back(x);
        for(auto  x: G[t]) A.push_back(x);
        ll n = A.size();
        vl S(n+1, 0);
        REP(i, n) S[i+1] = S[i] + A[i];
        ll len = min(n/2, K);

        vl ma(len+1, -INF);
        REP(i, n+1){
            REP(j, n+1){
                if(i<j and j-i<=len){
                    chmax(ma[j-i], S[j]-S[i]);
                }
            }
        }
        //dump(ma)

        ll sum = S[n/2];
        for(ll i=1;i<=len;i++){
            ll tmp = ma[i];
            if(sum>0 and K>=i){
                tmp += (K-i)/(n/2) * sum;
            }
            chmax(res, tmp);
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3812
#include <iostream>
using namespace std;
int main()
{
	int d, r;
	while (1)
	{
		cin>>d>>r;
		if (d ==0 && r == 0)
			break;
		else
		{
			for (int i =0; i < d;i++)
			{
				for (int j=0;j <r;j++)
				{
					if (i % 2 == 0)
					{
						if ( j % 2 == 0)
							cout<<"#";
						else
							cout<<".";
					}
					else
					{
						if ( j % 2 == 0)
							cout<<".";
						else
							cout<<"#";
					}

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

Measured memory_bytes: 3080
#include <stdio.h>
int main(){
  int a,b;
  scanf("%d %d", &a, &b);
  
  if(a<b){printf("a < b\n");}
  else if(a>b){printf("a > b\n");}
  else if(a==b){printf("a == b\n");}
  return 0;
}

  

Measured memory_bytes: 580
n = int(input())
a = [int(x) for x in input().split()]

for i in range(n):
    cnt = 0
    while a[i] % 2 == 0:
        a[i] //= 2
        cnt += 1
    if i == 0:
        min_cnt = cnt
    elif min_cnt > cnt:
        min_cnt = cnt
print(min_cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
  cin>>S;
  int N=S.size();
  string ans="Yes";
  for(int i=0;i<N;i++){
  if(i%2==0){
  if(S.at(i)=='L'){ans="No"; break;}
  }else{
  if(S.at(i)=='R'){ans="No"; break;}
  }
  
  }cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using pii = pair<int, int>;

pii merge(pii p1, pii p2) {
	int x = max(p1.first, p2.first);
	int y = min(p1.second, p2.second);
	if (x > y) y = x;
	return pii(x, y);
}

int count(pii p) {
	return p.second - p.first;
}

int main() {
	int N; cin >> N;
	vector<pii> LR(N);
	for (int i = 0; i < N; ++i)
		cin >> LR[i].first >> LR[i].second;
	for (int i = 0; i < N; ++i)
		++LR[i].second;
	sort(LR.begin(), LR.end());

	vector<pii> from_front(N + 1), from_back(N + 1);
	from_front[1] = LR[0];
	for (int i = 2; i <= N; ++i)
		from_front[i] = merge(from_front[i - 1], LR[i - 1]);
	from_back[1] = LR[N - 1];
	for (int i = 2; i <= N; ++i)
		from_back[i] = merge(from_back[i - 1], LR[N - i]);

	int res = 0;
	for (int i = 1; i <= N - 1; ++i) {
		// 前からi個出題
		int tmp = count(from_front[i]);
		// 後ろからN-i個出題
		tmp += count(from_back[N - i]);
		res = max(res, tmp);
	}

	for (int i = 0; i < N; ++i) {
		pii others(-1, (1 << 30));
		if (i > 0) others = merge(others, from_front[i]);
		if (i < N - 1) others = merge(others, from_back[N - i - 1]);
		int tmp = count(LR[i]);
		tmp += count(others);
		res = max(res, tmp);
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2560
L = int(input())
N = len(bin(L)) - 2 #N: Lの2進法での桁数
nodes = []
for i in range(N - 1):
    u1, v1, w1 = i + 1, i + 2, 0
    u2, v2, w2 = i + 1, i + 2, (1 << i)
    nodes.append([u1, v1, w1])
    nodes.append([u2, v2, w2])
for i in range(1, N):
    if (L >> (i - 1)) & 1 == 1:
        u, v, w = i, N, (L >> i ) << i
        nodes.append([u, v, w])
M = len(nodes)
print(N, M)
for i in range(M):
    u, v, w = nodes[i]
    print(u, v, w)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
#include<limits.h>
using namespace std;

int n;

int main(){
	scanf("%d",&n);
	printf("%d\n",(n-2)*180);
	return 0;
}

/*
数据不清空，爆零两行泪
读题不认真，爆零两行泪
分析不仔细，爆零两行泪
建树不构造，爆零两行泪
变量不统一，爆零两行泪
边界不算清，爆零两行泪
数组不开大，爆零两行泪
*/

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

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

int main() {
    string s,t,u;
    cin >> s >> t;

    int a,b;
    cin >> a >> b;

    cin >> u;

    if(u == s) a--;
    else b--;
    
    print(a);
    print(b);

}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int s,t,f,g;
  scanf("%d",&s);
  t=s%100;
  s/=100;
  if(0<s&&s<13)f=1;
  else f=0;
  if(0<t&&t<13)g=1;
  else g=0;
  if(f){
    if(g)puts("AMBIGUOUS");
    else puts("MMYY");
  }else{
    if(g)puts("YYMM");
    else puts("NA");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}


int main(){
    ll n,m;
    cin>>n>>m;
    if(n == 1 || m == 1){
        cout<<1<<endl;
        return 0;
    }
    if(n*m % 2 == 0)cout<<(n*m)/2<<endl;
    else cout<<((n*m)/2)+1<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){

   int N;
   
   scanf("%d",&N);
   
   int i,sum,max;
   int L[N];
   
   sum = 0;
   for(i = 0;i < N;i++){
      scanf("%d",&L[i]);
      sum = sum + L[i];
      if(i == 0 || max <= L[i]){
         max = L[i];
      }
   }
   
   if(max < sum - max){
      printf("Yes\n");
   }
   else {
      printf("No\n");
   }
   
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
#define vi vector<int>
#define vvi vector<vector<int> > 
#define vl vector<long long>
#define vpi vector<pair<int,int> >
#define ll long long 
#define all(x) x.begin(),x.end()
#define vpl vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
// #define mod 998244353
#define mod 1000000007
#define MAXN  1000001
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)



void solve()
{
    ll a,b;
    char c;
    int d;
    cin>>a>>b>>c>>d;
    ll ans = a*100*b+a*d;
    cout<<ans/100<<endl;
}


int main()
{
    fast;
    int t;
    t = 1;
    // cin>>t;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 3652
// C - Ordinary Beauty

// 「和の期待値は期待値の和」 を用いた解法

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	double n, m, d;
	cin >> n >> m >> d;

	double ans;

	if (d == 0) {
		ans = n / (n * n) * (m - 1);
	} else {
		ans = 2 * (n - d) / (n * n) * (m - 1);
	}

	cout << fixed << setprecision(10);
	cout << ans << endl;

	return 0;
}


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

int main() {
  int ar[4];
  for(int i = 0; i < 4; i++){
    cin >> ar[i];
  }
  sort(ar, ar+4);
  if(ar[0] == 1 && ar[1] == 4 && ar[2] == 7 && ar[3] == 9){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

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

int main() {
	long long N, W, INF, maxValue;
	cin >> N >> W;
	INF = 1000000000000000;
	maxValue = 0;
	vector<vector<long long>> Items(N, vector<long long>(2));
	for (int i = 0; i < N; i++) {
		cin >> Items[i][0] >> Items[i][1];
		maxValue = max(maxValue, Items[i][1]);
	}
	maxValue *= N;
	vector<vector<long long>> Knap(N, vector<long long>(maxValue + 1, INF));
	Knap[0][0] = 0;
	Knap[0][Items[0][1]] = Items[0][0];
	for (int i = 0; i < N - 1; i++) {
		for (long long v = 0; v <= maxValue; v++) {
			Knap[i + 1][v] = min(Knap[i + 1][v], Knap[i][v]);
			if (v + Items[i + 1][1] <= maxValue) {
				Knap[i + 1][v + Items[i + 1][1]] = min(Knap[i + 1][v + Items[i + 1][1]], Knap[i][v] + Items[i + 1][0]);
			}
		}
	}

	long long maxTotalValue = 0;
	for (int v = 0; v <= maxValue; v++) {
		if (Knap[N - 1][v] <= W) maxTotalValue = v;
	}
	cout << maxTotalValue << endl;
}

Measured memory_bytes: 79488
from collections import defaultdict
n = int(input())
tree = dict()
graph = defaultdict(list)

for i in range(n-1):
    a,b,c = (int(x) for x in input().split())
    tree[a,b] = c
    tree[b,a] = c
    graph[a].append(b)
    graph[b].append(a)

q, k = (int(x) for x in input().split())

dist = dict()
stack = [k,]
visited = [False for _ in range(n+1)]
dist[k] = 0
visited[k] = True

while stack:
    new_stack = []
    for node in stack:
        for next_node in graph[node]:
            if not visited[next_node]:
                visited[next_node]  = True
                dist[next_node] = dist[node] + tree[node, next_node]
                new_stack.append(next_node)
    stack = new_stack

for _ in range(q):
    x, y = (int(x) for x in input().split())
    print(dist[x] + dist[y])


Measured memory_bytes: 125400
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define pb push_back
map<ll,ll>mp;

    ll t,s,i,e,o=0,n,ans;
int main(){
    fast;
    cin>>n;
    ll a[n+5],b[n+5],c[n+5];
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    for(i=1;i<=n;i++)cin>>b[i];
    for(i=1;i<n;i++)cin>>c[i];
    for(i=1;i<=n;i++){
        ans+=b[a[i]];
    }
    for(i=1;i<n;i++){
        if(a[i]+1==a[i+1])ans+=c[a[i]];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

inpt = input().rstrip()

diff = 999
ans = 0
for i in range(len(inpt)):
    num = inpt[i:i+3]
    if len(num) < 3:
        break
    n = int(num)
    d = abs(753-n)
    if d < diff:
        ans = n
        diff = d

print(diff)

Measured memory_bytes: 3060
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//228
	int d;
	cin>>d;
	switch(d) {
		case 22:
			cout<<"Christmas Eve Eve Eve";
			break;
		case 23:
			cout<<"Christmas Eve Eve";
			break;
		case 24:
			cout<<"Christmas Eve";
			break;
		case 25:
			cout<<"Christmas";
			break;
	}
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int combination2(int a) {
    int ans = 1;
    ans *= a; ans *= (a-1); ans /= 2;
    return ans;
}

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

    // nが1以下のとき
    // -> mから2個選ぶのみ
    if(n < 2) {
        cout << combination2(m) << endl;
    }

    // mが1以下のとき
    // -> nから2個選ぶのみ
    else if(m < 2) {
        cout << combination2(n) << endl;
    }

    else {
        cout << combination2(n) + combination2(m) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#define rep(i, n) for (int i = 1; i <= n; i++)
using namespace std;
long long N;
int main(){
  scanf("%d", &N);

  int n, h;
  long w = 1;
/*  if (N % 2 == 0) {
    h = N / 2;
    n = N;
    w = N;
    printf("%d %d %d\n", h, n, w);
  }else {*/
    rep(h, 3500) {
      rep(n, 3500) {
        if (4 * n * h - N * n - N * h != 0){
          w = N * n * h / (4 * n * h - N * n - N * h);
          if (w > 0 && (N * n * h) % (4 * n * h - N * n - N * h) == 0) {
            printf("%d %d %d\n", h, n, w);
            return 0;
          }
        }
      }

  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	long long A, P;

	cin >> A >> P;

	cout << ((A * 3) + P) / 2 << endl;

	return 0;
}

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

using namespace std;

using int64 = long long;


int main() {
  int N, Q;
  cin >> N >> Q;
  vector< int > A(N);
  const int SQ = 333;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    --A[i];
  }
  vector< int > pending;
  for(int i = 0; i < Q; i++) {
    int q;
    cin >> q;
    --q;
    pending.emplace_back(q);
    if(i % SQ == SQ - 1 || i + 1 == Q) {

      vector< int > used(N);
      for(auto &p : pending) used[p] = true;
      vector< int > type(N);

      int ptr = -1;
      bool prev = true;
      for(int j = 0; j < N; j++) {
        if(used[A[j]]) {
          ++ptr;
          prev = true;
        } else if(prev) {
          ++ptr;
          prev = false;
        }
        type[A[j]] = ptr;
      }
      ++ptr;
      vector< vector< int > > lis(ptr);
      for(int j = 0; j < N; j++) {
        lis[type[A[j]]].emplace_back(A[j]);
      }
      
      vector< int > now(ptr);
      iota(begin(now), end(now), 0);

      for(auto &p : pending) {
        vector< int > nxt(ptr);
        for(int j = 0; j < ptr; j++) {
          if(now[j] == type[p]) {

            int uku = 0;
            for(int k = j + 1; k < ptr; k++) {
              nxt[uku++] = now[k];
            }
            nxt[uku++] = now[j];
            for(int k = 0; k < j; k++) {
              nxt[uku++] = now[k];
            }
            now = nxt;
            break;
          }
        }
      }

      vector< int > B(N);
      int uku = 0;
      for(int j = 0; j < ptr; j++) {
        for(auto &k : lis[now[j]]) B[uku++] = k;
      }
      A = B;
      pending.clear();
    }
  }


  for(int i = 0; i < N; i++) {
    if(i > 0) cout << " ";
    cout << A[i] + 1;
  }
  cout << endl;

}


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

int main() {
  string s;
  cin >> s;
  ll n = s.size();

  ll ans = 0;
  rep(i, 1<<n-1){
    ll tsum = 0;
    ll t = s[0] - '0';
    rep(j, n - 1) {
      if (i & 1 << j) {
        tsum += t;
        t = 0;
      }
      t = t * 10 + s[j + 1] - '0';
    }
    tsum += t;
    ans += tsum;
  }


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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,b,c,d;cin >> n >> a >> b >> c >> d;
    b-=a;
    vector<ll> l(n+1),r(n+1);
    l[0]=-(n-1)*d,r[0]=-(n-1)*c;
    REP(i,n){
        l[i+1]=l[i]+c+d;
        r[i+1]=r[i]+c+d;
    }
    REP(i,n+1){
        if(l[i]<=b&&b<=r[i]){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 11024
let mod = 1_000_000_007

let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let K = input[1]

func sum(_ first: Int, _ last: Int, _ count: Int) -> Int {
    (first + last) * count / 2
}

var result = 0
for i in K ... N + 1 {
    let min = sum(0, i - 1, i)
    let max = sum(N - i + 1, N, i)
    result += max - min + 1
    result %= mod
}

print(result)


Measured memory_bytes: 8168
n, k = map(int, input().split())
d = list(map(str, input().split()))
"""
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(k):
    for j in range(len(l)):
        if d[i] == l[j]:
            l.pop(j)
            break
"""
while True:
    tmp = list(str(n))
    flag = True
    for i in range(len(d)):
        if d[i] in tmp:
            flag = False
            break
    if flag:
        break
    n += 1
print(n)

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

int main(){

	std::string  str;
	while (std::cin >> str){
		if (str == "0")break;

		int a = 0, b = 0;
		for (int i = 0; i < str.size() - 1; i++){
			if (str[i + 1] == 'A')a++;
			else b++;
		}

		a>b ? a++ : b++;
		std::cout << a << " " << b << std::endl;

	}

	return 0;
}

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

arg=[0]*(100005)
for a in A:
    arg[a]+=1
ans=sum(A)
for _ in range(Q):
    a,b=map(int,input().split())
    ans+=arg[a]*(b-a)
    print(ans)
    arg[b]+=arg[a]
    arg[a]=0


Measured memory_bytes: 20916
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  using ll = long long;
  ll a,b,n;
  cin>>a>>b>>n;
  ll x=min(n,b-1);
  cout<<(a*x/b)-a*(x/b)<<newl;
  return 0;
}


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

int main () {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    for (int i = 0; i < K; i++) {
        if (!(B > A)) {
            B *= 2;
        }
        else if (!(C > B)) {
            C *= 2;
        }
    }
    if (C > B && B > A) {
        puts("Yes");
    }
    else {
        puts("No");
    }
}

Measured memory_bytes: 3620
n,m = map(int, input().split())

ac = [0]*(n+1)
wa = [0]*(n+1)


for i in range(m):
	p, s = input().split()
	p = int(p)
    
	if s== "AC":
		ac[p] = 1
	else:
		if ac[p]==0:
			wa[p]+=1

for i in range(n+1):
	if ac[i]==0:
		wa[i]=0
        
print(sum(ac),sum(wa))


Measured memory_bytes: 4596
#E問題
import math
import bisect
from collections import defaultdict

S = list(str(input()))
T = list(str(input()))

index = defaultdict(list)
for i,s in enumerate(S):
    index[s].append(i)

flag = 0
x = -1
loop = 0
for t in T:
    tindl = index[t]
    if len(tindl) == 0:
        print(-1)
        flag = 1
        break
    j = bisect.bisect(tindl,x)
    if j == len(tindl):
        loop+=1
        x = tindl[0]
    else:
        x = tindl[j]


if flag == 0:
    print(loop*len(S)+x+1)

Measured memory_bytes: 9308
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,s,e) for(ll i=s;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1000000007;
const ll INF = 1000000009;
ll i;

int main(){
    string S;
    cin>>S;
    rep(i,0,5)cout<<S.at(i);
    cout<<" ";
    rep(i,6,13)cout<<S.at(i);
    cout<<" ";
    rep(i,14,19)cout<<S.at(i);
    cout<<endl;
}



Measured memory_bytes: 256
n, m = gets.split.map &:to_i
data = m.times.map{|i| p, y = gets.split.map(&:to_i); [i, p, y]}
h = Array.new(n+1){[]}
data.each{|a|
    h[a[1]] << a
}
d = []
h.each{|b|
    x = 1
    b.sort_by{|a| a[2]}.each{|i, p, y|
        d << [i, p, x]
        x += 1
    }
}
d.sort.each{|i, p, x|
    puts "%06d%06d" % [p, x]
}

Measured memory_bytes: 44200
def breathSerch(P,N):
    n=len(P)-1
    m=1
    QQ=[N[1]]
    while(QQ != []):
        R=[]
        for Q in QQ:
            for i in range(1,n+1):
                if Q[i]==1 and P[i]==-1:
                    P[i]=m
                    R.append(N[i])
        QQ = R
        m=m+1
    
n = int(input())
A = [[0 for j in range(n+1)] for i in range(n+1)]


for i in range(n):
    vec = input().split()
    u = int(vec[0])
    k = int(vec[1])
    nodes = vec[2:]
    for i in range(int(k)):
        v = int(nodes[i])
        A[u][v] = 1

P=[-1 for i in range(n+1)]
P[1]=0
breathSerch(P,A)
for i in range(1,n+1):
    print(i,P[i])

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    int A,B,C,K; cin >>A>>B>>C>>K;
    int t=0;
    for(;t<=K;){
        if(A>=B) {
            B*=2;
            t++;
            continue;
        }
        if(B>=C){
            C*=2;
            t++;
            continue;
        }
        if(A<B && B<C){
            A2;
            return 0;
        }
        t++;
    }
    A1;
    return 0;
}

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

using namespace std;

int n,i,j,cnt[3];

int main(){
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		int x;
		scanf("%d", &x);
		
		if(x % 4 == 0)
		cnt[2]++;
		else if(x % 2 == 0)
		cnt[1]++;
		else
		cnt[0]++;
	}
	
	if(cnt[0] - 1 == cnt[2]){
		if(cnt[1] == 0)
		return 0 * printf("Yes\n");
		return 0 * printf("No\n");
	}
	
	if(cnt[0] <= cnt[2])
	return 0 * printf("Yes\n");
	
	return 0 * printf("No\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long// long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int to,cost;};
typedef long long ll;

int ans,ans2;

signed main(){

    int n;
    pair<int,int> p[11111];
    cin>>n;
    rep(i,n)cin>>p[i].first>>p[i].second;
    sort(p,p+n);
    int a,b;
    rep(i,n){
        rep(j,n){
            int co=0;
            if(i==j)continue;
            int num=p[j].first-p[i].first;
            int num2=p[j].second-p[i].second;
            rep(k,n){
                rep(l,n){
                    if(p[l].first-p[k].first==num && p[l].second-p[k].second==num2){
                        co++;
                    }
                }
            }
            //ans=std::max(ans,co);
            if(ans<=co){
                ans=co;
                //DEB(num)END DEB(num2)END
                a=num,b=num2;
            }
        }
    }
    cout<<n-ans<<endl;
   //cout<<a<<" "<<b;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int bamboom[9],A,B,C,n;
int dfs(int l,int a,int b,int c)
{
	if(l==n)
	{
		if(a==0||b==0||c==0)
			return 8001;
		return abs(A-a)+abs(B-b)+abs(C-c);
	}
	int r1=dfs(l+1,bamboom[l+1]+a,b,c)+10;
	int r2=dfs(l+1,a,bamboom[l+1]+b,c)+10;
	int r3=dfs(l+1,a,b,bamboom[l+1]+c)+10;
	int r4=dfs(l+1,a,b,c);
	return min(min(r1,r2),min(r3,r4));
}
int main()
{
	scanf("%d %d %d %d",&n,&A,&B,&C);
	for(int i=1;i<=n;i++)
		scanf("%d",&bamboom[i]);
	printf("%d",dfs(0,0,0,0)-30);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/




signed main() {
	int a; cin >> a;
	cout << a * a * a << endl;
}

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

int main(){
  int N,cnt=1,cnt2=-1;
  cin >> N;
  int a[N];
  for(int i=0;i<N;i++)
    cin >> a[i];
  int b = a[0];
  for(int i=0;i<N;i++){
    if(b==2){
      cnt2=cnt;
      break;
    }
    b = a[b-1];
    cnt++;
  }
  cout << cnt2 << endl;
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	ac := a * c
	ad := a * d
	bc := b * c
	bd := b * d
	s := []int{ad, bc, bd}
	tmp := ac
	for _, v := range s {
		if tmp < v {
			tmp = v
		}
	}
	fmt.Println(tmp)
}

Measured memory_bytes: 1772
N = int(input())
numlist = list(map(int,input().split()))

numlist.sort()

num1 = N // 2
num2 = N // 2 + 1


if numlist[num2-1] == numlist[num1-1]:
    print(0)
else:
    print(numlist[num2-1]-numlist[num1-1])

Measured memory_bytes: 14396