akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

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

/*（๑•﹏•๑｀) */

int main() {
    int A,B,C; cin >> A >> B >> C;
    if (A > B) swap(A,B);
    if ((A <= C) and (C <= B)) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 256
n,m = map(int,input().split())
displace = {}
for _ in range(m):
    displace[int(input())] = 1
dp = {0:1}
if 1 in displace:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2,n+1):
    next_case = 0
    if i not in displace:
        next_case += dp[i-1]+dp[i-2]
    dp[i] = next_case%1000000007
print(dp[n])

Measured memory_bytes: 27360
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n = readint;
    writeln(n / 3);
}


Measured memory_bytes: 256
using AtCoderBeginnerContest121.Questions;
using AtCoderBeginnerContest121.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest121.Questions
{
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var HW = inputStream.ReadIntArray();
            var hw = inputStream.ReadIntArray();
            yield return (HW[0] - hw[0]) * (HW[1] - hw[1]);
        }
    }
}


namespace AtCoderBeginnerContest121
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest121.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest121.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=1000009;
vector<int>prime;
vector<int>pri,power;
bool sv[M+10];
void sieve()
{   prime.push_back(2);
     int i,j;
     for(i=4;i<=M;i=i+2)
    {
           sv[i]=1;
    }
    for(i=3;i*i<=M;i=i+2)
    {
        if(sv[i]==0)
        {
              for(j=i*i;j<=M;j=j+2*i)
              {
                  sv[j]=1;
              }
        }
    }
    for(i=3;i<M;i=i+2)
    {
        if(sv[i]==0)
        {
            prime.push_back(i);
        }
    }
}
 void  prime_factorization( int n)
 {
      int temp2=n,temp=0,cnt=0;
     pri.clear();
     power.clear();
      temp=sqrt(n);
    int sz=prime.size();
    for(int i=0;prime[i]<=temp && i<sz;i++)
    {    cnt=0;
        while(1)
        {   if(temp2%prime[i]==0){
            temp2=temp2/prime[i];
            cnt++;
            }
            else
            {   if(cnt>0)
                  {
                      pri.push_back(prime[i]);
                      power.push_back(cnt);
                  }
                  cnt=0;
                break;
            }
        }
        if(temp2==1){break;}
    }
     if(temp2>1)
     {

         pri.push_back(temp2);
         power.push_back(1);
     }
 }
 main()

{
    fast
    sieve();
    int n;
    cin>>n;
    prime_factorization(n);
    int sz=power.size();
    int ses=0;
    f(i,0,sz-1)
    {
        int p=power[i];
        int j=1;
        while(1)
        {
           if(p>=j)
           {
               p-=j;
               ses++;
               j++;
           }
           else break;
        }
    }
    cout<<ses<<endl;
    return 0;

}





































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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 100010;

int N, M;
bool us[MN];
vi g[MN];

int main() {
	scanf("%d %d", &N, &M);

	rep(i, M) {
		int a, b;
		scanf("%d %d", &a, &b);
		--a; --b;
		g[a].pb(b); g[b].pb(a);
	}

	deque<int> deq = {0};
	us[0] = 1;

	while (true) {
		int s = deq[0], t = deq[(int)deq.size() - 1];

		bool upd = 0;
		for (int to : g[s]) {
			if (!us[to]) {
				upd = 1;
				deq.push_front(to);
				us[to] = 1;
				break;
			}
		}

		if (upd) continue;
		for (int to : g[t]) {
			if (!us[to]) {
				upd = 1;
				deq.push_back(to);
				us[to] = 1;
				break;
			}
		}
		if (!upd) {
			break;
		}
	}

	cout << deq.size() << endl;
	rep(i, deq.size()) {
		printf("%d%c", deq[i] + 1, i + 1 == deq.size() ? '\n' : ' ');
	}

	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto&& i : a){
        cin >> i;
    }
    for(int i = n - 1; i > 0; i--){
        if(a[i] - a[i - 1] < -1){
            cout << "No\n";
            return 0;
        }
        else if(a[i] - a[i - 1] == -1){
            a[i - 1]--;
        }
    }
    cout << "Yes\n";
}

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

int main() {
  int A , B , X;
  cin >> A >> B >> X;
  if(X < A){
    cout << "NO" << endl;
  }
  else if(X - A <= B){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin >> n&&n){
    ll a,b,A=0,B=0;
    rep(i,n){
      cin >> a >> b;
      if(a > b){
        A += a+b;
      }
      else if(a < b){
        B += a+b;
      }
      else{
        A += a;
        B += b;
      }
    }
    cout << A << " " << B << endl;
  }
  return 0;
}

Measured memory_bytes: 3116
#include<stdio.h>

#define DAYOFWEEK 7
char *day[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main(){
  char s[4];
  int i;
  
  scanf("%s", s);
  for(i=0; i<DAYOFWEEK; i++){
    if(strcmp(s, day[i]) == 0){
      break;
    }
  }
  
  printf("%d", DAYOFWEEK-i);
}


Measured memory_bytes: 128
n = int(input())
p = list(map(int, input().split()))
q = sorted(p)

count = 0
f = True
for i in range(n):
    if p[i]!=q[i]:
        count+=1
    if count > 2:
        print('NO')
        f = False
        break
if f:
    print('YES')


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		int period = Integer.parseInt(new BufferedReader(new InputStreamReader(System.in), 64).readLine());
		int val = 100;//壱百千円
		for (; 0 < period; period--) {
			val = val * 105 % 100 == 0 ? (int) (val * 1.05) : (int) (val * 1.05) + 1;
		}
		System.out.println(val * 1000);
	}
}

Measured memory_bytes: 15008
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        int[] WHxyr = cin.ArrayInt(5,0);
        if(WHxyr[2]-WHxyr[4]>=0&&WHxyr[2]+WHxyr[4]<=WHxyr[0]&&WHxyr[3]-WHxyr[4]>=0&&WHxyr[3]+WHxyr[4]<=WHxyr[1])Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }


}



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);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

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

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

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


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 17920
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	long long a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;

	bool ok = abs(b - a) <= t * (v - w);
	cout << (ok ? "YES": "NO") << endl;
	return 0;
}


Measured memory_bytes: 3096
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

class TVertex
{
    int FIndex;
    std::vector<TVertex*> FList;
    int FDistance;

public:
    TVertex(int Index)
     : FIndex(Index), FDistance(-1)
    {}
    void AddPath(TVertex* Vertex)
    {
        FList.push_back(Vertex);
    }
    void PrintDistance(std::ostream& out)const
    {
        out << FIndex << " " << FDistance << std::endl;
    }
    void BreadthFirstSearch(int Distance)
    {
        if(FDistance <= Distance && FDistance != -1) return;
        FDistance = Distance++;
        for(std::vector<TVertex*>::iterator It = FList.begin(); It != FList.end(); ++It){
            TVertex* V = *It;
            V->BreadthFirstSearch(Distance);
        }
    }
};
class TGraph
{
    std::vector<TVertex*> FTable;
    void Init(int n)
    {
        assert(n > 0);
        FTable.resize(n);
        for(int i = 0; i < n; ++i){
            FTable[i] = new TVertex(i);
        }
    }
public:
    TGraph(int n)
    {
        Init(n+1);
    }
    
    void SetupVertex(std::istream& in)
    {
        int Index;
        in >> Index;
        assert(Index >= 1);
        assert(Index <= FTable.size());
        int k;
        in >> k;
        for(int i = 0; i < k; ++i){
            int v;
            in >> v;
            FTable[Index]->AddPath(FTable[v]);
        }
    }
    void BreadthFirstSearch()
    {
        FTable[1]->BreadthFirstSearch(0);
    }
    void PrintDistance(std::ostream& out)
    {
        for(int i = 1; i < FTable.size(); ++i){
            FTable[i]->PrintDistance(out);
        }
    }
};

int main()
{
    int n;
    std::cin >> n;
    TGraph Graph(n);
    for(int i = 0; i < n; ++i){
        Graph.SetupVertex(std::cin);
    }
    Graph.BreadthFirstSearch();
    Graph.PrintDistance(std::cout);
    return 0;
    
}

Measured memory_bytes: 3132
#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 FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main(){
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a(x),b(y),c(z);
    rep(i,x) cin>>a[i];
    rep(i,y) cin>>b[i];
    rep(i,z) cin>>c[i];
    
    vector<ll> ab(x*y);
    rep(i,x) rep(j,y) ab[i*y+j]=(a[i]+b[j]);
    sort(all(ab));
    reverse(all(ab));
    
    vector<ll> abc(k*z);
    rep(i,min(x*y,k)) rep(j,z) abc[i*z+j]=(ab[i]+c[j]);
    sort(all(abc));
    reverse(all(abc));
    
    rep(i,k) cout<<abc[i]<<endl;
}


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

// const int MAX = 1e9 + 10;
// const int MOD = 1e9 + 7;
const int MOD = 1000000007;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;


mint com(int N, int K){
    mint x = 1;
    K = min(K, N - K);
    REP(k, K) {
        x *= (N - k);
        x /= (k + 1);
    }
    return x;
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;

    mint x = modpow((mint)2, n) - 1;
    x -= com(n, a) + com(n, b);

    cout << x << endl;
} 

Measured memory_bytes: 256
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from collections import Counter
inf = 10**10
from functools import reduce

s = input()
ans = len(s)
for i in set(s):
    t = s.split(i)
    c = 0
    for j in t:
        c = max(c,len(j))
    ans = min(ans,c)
print(ans)

Measured memory_bytes: 38256
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
#include <cstdio>
#include <stack>
#include <list>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;
template <class T> T gcd(T n, T m){return m ? gcd(m, n%m):n;}

int main(){
    int n;cin>>n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if (i*j == n){cout << "Yes" << endl;return 0;}
        }
    }
    cout << "No" << endl;
}


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

using namespace std;

int pow(int x, int y) {
    if (y == 0) return 0;
    else return (int) pow((float) x, (float) y);
}

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

    int dp[N + 1];
    dp[0] = 0;

    for (int i = 1; i <= N; ++i) {
        int res = 1000000000;
        for (int j = 1; i - pow(9, j) >= 0; ++j) {
            res = min(res, dp[i - pow(9, j)] + 1);
        }

        for (int j = 1; i - pow(6, j) >= 0; ++j) {
            res = min(res, dp[i - pow(6, j)] + 1);
        }

        res = min(res, i);

        dp[i] = res;
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
int u[100005], v[100005];
int asc(const void* x, const void* y)
{
	if (u[*(int*)x] > u[*(int*)y])return 1;
	if (u[*(int*)x] < u[*(int*)y])return -1;
	if (v[*(int*)x] > v[*(int*)y])return 1;
	if (v[*(int*)x] < v[*(int*)y])return -1;
	return 0;
}
int p[100005][3];
int h[1000006], l;
void f1(int n)
{
	h[l] = n;
	int now = l;
	l++;
	while (now > 0)
	{
		if (p[h[now] / 3][h[now] % 3] < p[h[(now - 1) / 2] / 3][h[(now - 1) / 2] % 3])
		{
			int f = h[now];
			h[now] = h[(now - 1) / 2];
			h[(now - 1) / 2] = f;
		}
		now = (now - 1) / 2;
	}
	return;
}
int f2()
{
	int res = h[0];
	l--;
	h[0] = h[l];
	int now = 0;
	for (;;)
	{
		if (2 * now + 2 < l)
		{
			if (p[h[2 * now + 1] / 3][h[2 * now + 1] % 3] > p[h[2 * now + 2] / 3][h[2 * now + 2] % 3])
			{
				if (p[h[2 * now + 2] / 3][h[2 * now + 2] % 3] < p[h[now] / 3][h[now] % 3])
				{
					int f = h[now];
					h[now] = h[2 * now + 2];
					h[2 * now + 2] = f;
				}
				now = 2 * now + 2;
			}
			else
			{
				if (p[h[2 * now + 1] / 3][h[2 * now + 1] % 3] < p[h[now] / 3][h[now] % 3])
				{
					int f = h[now];
					h[now] = h[2 * now + 1];
					h[2 * now + 1] = f;
				}
				now = 2 * now + 1;
			}
		}
		else if (2 * now + 1 < l)
		{
			if (p[h[2 * now + 1] / 3][h[2 * now + 1] % 3] < p[h[now] / 3][h[now] % 3])
			{
				int f = h[now];
				h[now] = h[2 * now + 1];
				h[2 * now + 1] = f;
			}
			now = 2 * now + 1;
		}
		else
			break;
	}
	return res;
}
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i, j;
	for (i = 0; i < m; i++)
	{
		scanf("%d %d", &u[i], &v[i]);
		u[i]--;
		v[i]--;
	}
	int s, t;
	scanf("%d %d", &s, &t);
	s--;
	t--;
	if (m == 0)
	{
		printf("-1\n");
		return 0;
	}
	int c[100005];
	for (i = 0; i < m; i++)
		c[i] = i;
	qsort(c, m, sizeof(int), asc);
	int visited[100005][3];
	for (i = 0; i < n; i++)
		visited[i][0] = visited[i][1] = visited[i][2] = 0;
	for (i = 0; i < n; i++)
		p[i][0] = p[i][1] = p[i][2] = 1000000009;
	l = 0;
	f1(3 * s);
	p[s][0] = 0;
	int min, mid, max;
	int a, b;
	while (l > 0)
	{
		a = f2();
		b = a % 3;
		a /= 3;
		if (visited[a][b] > 0)
			continue;
		visited[a][b] = 1;
		min = 0;
		max = m;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (u[c[mid]] < a)
				min = mid;
			else
				max = mid;
		}
		if (u[c[min]] < a)
			min++;
		if (min < m)
		{
			while (u[c[min]] == a)
			{
				if (p[v[c[min]]][(b + 1) % 3] > p[a][b] + 1)
				{
					p[v[c[min]]][(b + 1) % 3] = p[a][b] + 1;
					f1(3 * v[c[min]] + (b + 1) % 3);
				}
				min++;
				if (min == m)
					break;
			}
		}
	}
	if (p[t][0] > 10000007)
		printf("-1\n");
	else
		printf("%d\n", p[t][0] / 3);
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  int diff = b - a;
  int tallb = diff * (diff + 1) / 2;
  int ans = tallb - b;

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


Measured memory_bytes: 256
module Main where

import Data.Functor

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  { [w,h,x,y,r] <- getInts
  ; putStrLn (check(w,h,x,y,r))
  }

check :: (Int,Int,Int,Int,Int) -> String
check (w,h,x,y,r)
  | x < r     = "No"
  | y < r     = "No"
  | x > w-r   = "No"
  | y > h-r   = "No"
  | otherwise = "Yes"

check' :: (Int,Int,Int,Int,Int) -> String
check' (w,h,x,y,r)
  | r <= x && x <= w - r && r <= y && y <= h - r = "Yes"
  |otherwise                                     = "No"

Measured memory_bytes: 3684
/*      Welcome to my Code      */

#include <bits/stdc++.h>
#define ll                      long long int
#define i(a,n)                  int a=n;
#define l(a,n)                  ll a=n;
#define d(a,n)                  double a=n;
#define s(a)                    string a;
#define c(a)                    ll a; cin>>a;a
#define cd(a)                   double a; cin>>a;
#define cs(a)                   string a; cin>>a;
#define ci(a)                   cin>>a
#define co(a)                   cout<<a
#define cos(a)                  cout<<a<<" "
#define con(a)                  cout<<a<<endl
#define yes                     cout<<"YES"<<endl
#define no                      cout<<"NO"<<endl
#define nl                      cout<<endl
#define ca(arr,n)               for(ll i=0;i<n;i++) cin>>arr[i]
#define caa(arr,n)              c(n); ll arr[n]; for(ll i=0;i<n;i++) cin>>arr[i];
#define f0(i,a,n)               for(ll i=a;i>=n;i--)
#define f(i,n)                  for(ll i=0;i<n;i++)
#define f1(i,a,n)               for(ll i=a;i<n;i++)
#define lcm(a,b)                (a*b)/__gcd(a,b)
#define T                       ll t=1; cin>>t; while(t--)
#define sr(a,n)                 sort(a,a+n)
#define rv(a,n)                 reverse(a,a+n)
#define fast                    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ret(x)                  return cout<<x,0;

using namespace std;

int main()
{
    fast;
    c(n);
    ll a[n],ans=0;
    ca(a,n);
    ll fmax=a[0];
    f(i,n)
    {
        if(fmax>a[i]) ans+=fmax-a[i];
        if(fmax<a[i]) fmax=a[i];
    }
    con(ans);
    return 0;
}

/*It's not who I am underneath, but what I do that defines me

MMMMMMMMMMMMMMMMMMMMM.                             MMMMMMMMMMMMMMMMMMMMM
 `MMMMMMMMMMMMMMMMMMMM           M\  /M           MMMMMMMMMMMMMMMMMMMM'
   `MMMMMMMMMMMMMMMMMMM          MMMMMM          MMMMMMMMMMMMMMMMMMM'
     MMMMMMMMMMMMMMMMMMM-_______MMMMMMMM_______-MMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
     .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM.
    MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
                   `MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
                          `MMMMMMMMMMMMMMMMMM'
                              `MMMMMMMMMM'
                                 MMMMMM
                                  MMMM
                                   MM
*/


Measured memory_bytes: 5196
#[allow(non_snake_case)]
fn main() {
    let stdin = std::io::stdin();
    let mut stdin = my::io::InputReader::new(stdin.lock());

    let N: usize = stdin.read();
    let M: usize = stdin.read();
    let mut count = vec![0; N];
    for _ in 0..M {
        let a = stdin.read::<usize>() - 1;
        let b = stdin.read::<usize>() - 1;
        count[a] += 1;
        count[b] += 1;
    }
    if count.iter().all(|&c| c % 2 == 0) {
        println!("YES");
    } else {
        println!("NO");
    }
}

#[allow(unused_must_use)]
mod my {
    pub mod io {
        use std::io::{BufRead, ErrorKind, Result};
        use std::str::{FromStr, from_utf8};
        use std::fmt::Debug;

        pub fn read_word<R: BufRead>(r: &mut R, buf: &mut Vec<u8>)
                                              -> Result<usize> {
            let mut read = 0;
            loop {
                let (done, used) = {
                    let available = match r.fill_buf() {
                        Ok(n) => n,
                        Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
                        Err(e) => return Err(e)
                    };
                    match available.iter().position(|&x| x == b'\n' || x == b' ') {
                        Some(i) => {
                            buf.extend_from_slice(&available[..i]);
                            (true, i + 1)
                        }
                        None => {
                            buf.extend_from_slice(available);
                            (false, available.len())
                        }
                    }
                };
                r.consume(used);
                read += used;
                if done || used == 0 {
                    return Ok(read);
                }
            }
        }

        pub struct InputReader<R: BufRead> {
            reader: R,
            buf: Vec<u8>,
        }

        impl<R: BufRead> InputReader<R> {
            pub fn new(reader: R) -> InputReader<R> {
                InputReader {
                    reader: reader,
                    buf: Vec::<u8>::new(),
                }
            }

            pub fn read_word(&mut self) {
                read_word(&mut self.reader, &mut self.buf);
            }
            
            pub fn read<T>(&mut self) -> T
                where T: FromStr,
                      T::Err: Debug
            {
                self.buf.clear();
                self.read_word();
                from_utf8(&self.buf).unwrap().trim().parse().unwrap()
            }
        }
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
#define MAXX 200010
 
#define PI   3.14159265358979323846264338327950
 
#define PB push_back 
#define F first
#define S second
 
#define ll 	long long
 
#define mod  1000000007
 
 
 
int main()
{
	FAST;
	char a[5][5];
	for(ll i = 0; i < 3; i++){
		for(ll j = 0; j < 3; j ++){
			cin >> a[i][j];
		}
	}
	cout << a[0][0] << a[1][1] << a[2][2];
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, ans = 1000, b = 0;
  char s[200], t[200];
  scanf("%s", s);
  scanf("%s", t);
  n = strlen(s);
  for(i = 0; i < n; ++i) {
    char a[200];
    a[n] = 0;
    for(j = 0; j < n; ++j) {
      a[(i + j) % n] = s[j];
    }
    if(!strcmp(a, t)) b = 1;
  }
  if(b) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++) cin >> a[i];
    int c=1;
    int ans=0;
    for(int i=0;i<N-1;i++){
        if(a[i]==a[i+1]) c++;
        else{
            ans+=c/2;
            c=1;
            continue;
        }
        if(i==N-2) ans+=c/2; 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ins insert
#define sz(x) (long long)x.size()
typedef long long ll;
typedef long double ld;
const int N = 100005;
const ld pi = 3.141592653;
const ll MOD = 1000000007;

using namespace std;

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

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int T = 1;
        //cin>>T;
        while(T--)
        {
                int h, w, i, j, k, l, q, ans=0, cnt=0;
                char ma[7][7];
                cin>>h>>w>>k;
                for(i=0; i<h; i++)
                {
                        for(j=0; j<w; j++) 
                        {
                                cin>>ma[i][j];
                                if(ma[i][j]=='#') cnt++;
                        }
                }
                for(i=0; i < (1<<h); i++)
                {
                        for(j=0; j < (1<<w); j++)
                        {
                                set<pair<int, int> > s;
                                vector<int> r, c;
                                for(l=0; l<h; l++){
                                        if(i & (1<<l)) r.pb(l); 
                                }
                                for(l=0; l<w; l++){
                                        if(j & (1<<l)) c.pb(l);
                                }
                                for(l=0; l<sz(r); l++){
                                        for(q=0; q<w; q++){
                                                if(ma[r[l]][q]=='#') s.ins({r[l], q});
                                        }
                                }
                                for(l=0; l<sz(c); l++){
                                        for(q=0; q<h; q++){
                                                if(ma[q][c[l]]=='#') s.ins({q, c[l]});
                                        }
                                }
                                if(sz(s)+k==cnt) ans++;
                        }
                }
                cout<<ans;
        }
        return 0;
}

Measured memory_bytes: 3540
N = int(input())

W = [[-1]*N for _ in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = [int(z) for z in input().split()]
        x -= 1
        W[i][x] = y

M = 0
for b in range(2**N):

    d = [0] * N
    for i in range(N):
        if (b >> i) & 1:
            d[i] = 1
    
    ok = True
    for i in range(N):
        if d[i] == 1:
            for j in range(N):
                if W[i][j] == -1:
                    continue
                if W[i][j] != d[j]:
                    ok =False

    if ok == True:
        M = max(M, sum(d))

print(M)

Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int64_t N, M, K;
    cin >> N >> M >> K;
    vector<int64_t> A(N+1), B(M+1);
    for(int i=1; i<=N; i++) {
        cin >> A[i];
    }
    for(int j=1; j<=M; j++) {
        cin >> B[j];
    }

    int64_t ans = 0;
    partial_sum(A.begin(), A.end(), A.begin());
    partial_sum(B.begin(), B.end(), B.begin());

    for(int i=0; i<=N; i++) {
        if(A[i] > K) continue;
        ans = max(ans, i + distance(B.begin(), upper_bound(B.begin(), B.end(), K-A[i])));
    }

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


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

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

int MOD=1e9+7;
ll INF=1e18;

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

ll mod_pow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = mod_pow(a, b/2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * mod_pow(a, b-1)) % MOD;
    }
}

ll comb(int n, int k){
    ll mother=1, child=1;
    for(int i=0; i<k; i++){
        child *= (n-i);
        mother *= (k-i);
        child %= MOD;
        mother %= MOD;
    }
    return child * mod_pow(mother, MOD-2) % MOD;
}

int main(){
    int n, m; cin>>n>>m;
    ll ans=1;
    for(int i=2; i*i<=m; i++){
        int cnt=0;
        while(m % i == 0){
            m /= i;
            cnt++;
        }
        ans *= comb(n-1+cnt, cnt);
        ans %= MOD;
    }
    
    if(m != 1){
        ans *= n;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
s = input() + '#'

num = [0]
for i in range(1, n + 1):
    if s[i - 1] != s[i]:
        num.append(i)

ans, lennum = num[1], len(num)
for i in range((s[0] == '1') + 1, lennum, 2):
    r, l = max(i - 2, 0), min(i + 2 * k - 1, lennum - 1)
    ans = max(ans, num[l] - num[r])
print(ans)


Measured memory_bytes: 79060
import fractions
import math

a,b = map(int,input().split())

g = fractions.gcd(a,b)
ans = 0
sqrtg = math.ceil(math.sqrt(g))
for i in range(2,sqrtg):
    #割り切れるなら割り切れなくなるまでiで割り続ける
    if (g%i == 0):
        ans += 1
        while (g % i == 0):
            g //= i
            
if (g != 1):
    ans += 1
print(ans+1)

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

void swap(int &a, int &b){
	int temp;
	temp = a;
	a = b;
	b = temp;
}

int main(){
	int n, count, min;
	cin>>n;
	int array[n];
	for(int i=0;i<n;i++) 
	{
		int input;
		cin>>input;
		array[i] = input;
	}
	for(int i=0;i<n;i++)
	{
		min = i;
		for(int j=i;j<n;j++)
		{
			if(array[j]<array[min])
			{
				min = j;
			}			
		}
		if(array[i]!=array[min])
		{
			swap(array[i], array[min]);
			count++;			
		}
	}
	for(int i=0; i<n; i++)
	{
		if(i!=0) cout<<" ";
		cout<<array[i];
	}
	
	cout<<endl<<count<<endl;
	return 0;
}

Measured memory_bytes: 1160
import scala.collection.mutable
import scala.io.StdIn.{readInt, readLine}

case class Tree(id: Int, left: Option[Int], right: Option[Int])
case class Node(
    id: Int,
    parent: Option[Int],
    sibling: Option[Int],
    degree: Int,
    depth: Int,
    height: Int
)

object Main extends App {
  import Solver.solve

  val n     = readInt()
  val lines = Iterator.fill(n)(readLine())

  val xs = solve(lines, n)

  xs.foreach {
    case Node(id, parent, sibling, degree, depth, height) =>
      val p        = parent.getOrElse(-1)
      val sib      = sibling.getOrElse(-1)
      val typeName =
        if (p == -1) "root"
        else if (degree == 0) "leaf"
        else "internal node"

      println(
        s"node $id: parent = $p, sibling = $sib, degree = $degree, depth = $depth, height = $height, $typeName"
      )
  }
}

object Solver {
  def solve(lines: Iterator[String], n: Int): Array[Node] = {

    val (trees, siblings, rootId) = {
      val trees       = mutable.Map.empty[Int, Tree]
      val siblings    = mutable.Map.empty[Int, Int]
      val allChildren = mutable.Set(0 until n: _*)

      for {
        line           <- lines
        Array(id, l, r) = line.split(' ').map { _.toInt }
      } {
        val left = if (l != -1) {
          siblings(l) = r
          allChildren -= l
          Some(l)
        } else None

        val right = if (r != -1) {
          siblings(r) = l
          allChildren -= r
          Some(r)
        } else None

        trees(id) = Tree(id, left, right)
      }

      val rootId = allChildren.head
      (trees, siblings, rootId)
    }

    val xs = new Array[Node](n)
    val hs = mutable.Map.empty[Int, Int]

    def getHeight(id: Int): Int =
      if (hs.contains(id)) hs(id)
      else {
        val Tree(_, left, right) = trees(id)

        val children = Seq(left, right).flatten

        val h =
          if (children.isEmpty) 0
          else children.map { getHeight(_) + 1 }.max

        hs(id) = h
        h
      }

    def setDepth(id: Int, parent: Option[Int], depth: Int): Unit = {
      val Tree(_, left, right) = trees(id)

      val children = Seq(left, right).flatten
      val degree   = children.length
      val sibling  = siblings.get(id)
      val height   = getHeight(id)
      xs(id) = Node(id, parent, sibling, degree, depth, height)

      val p = Some(id)
      val d = depth + 1
      for (childNodeId <- children) {
        setDepth(childNodeId, p, d)
      }
    }

    setDepth(rootId, None, 0)

    xs
  }
}



Measured memory_bytes: 44360
use std::cmp::{max, min};

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, a, b, c) = scan!(usize, usize, usize, usize);
    let vs = scan!(usize; n);

    let mut ans = 1 << 30;
    for mut i in 0..4usize.pow(n as u32) {
        let mut tmp = 0;
        let (mut x, mut y, mut z) = (0, 0, 0);
        for &v in vs.iter() {
            match i % 4 {
                0 => {}
                1 => {
                    if x != 0 {
                        tmp += 10
                    }
                    x += v
                }
                2 => {
                    if y != 0 {
                        tmp += 10
                    }
                    y += v
                }
                3 => {
                    if z != 0 {
                        tmp += 10
                    }
                    z += v
                }
                _ => (),
            }
            i /= 4;
        }

        if x == 0 || y == 0 || z == 0 {
            continue;
        }

        tmp += max(a, x) - min(a, x) + max(b, y) - min(b, y) + max(c, z) - min(c, z);
        ans = min(ans, tmp)
    }
    println!("{}", ans)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  string s, t; cin >> s >> t;
  int m = s.size();
  s += s;

  VV lc(26, V());
  rep(i, 2*m) {
    int x = s[i] - 'a';
    lc[x].push_back(i);
  }

  int i = -1;
  ll ans = 0;
  for (auto c : t) {
    int x = c - 'a';
    if (lc[x].size() == 0) {
      cout << -1 << "\n";
      return 0;
    }
    i = *lower_bound(all(lc[x]), i+1);
    if (i >= m) {
      ans += m;
      i -= m;
    }
  }
  ans += i+1;
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4744
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
using namespace std;

int main() {
        int n, d, x;
        scanf("%d%d%d", &n, &d, &x);
        int ans = 0;
        for (int i = 0; i < n; i ++) {
                int a;
                scanf("%d", &a);
                ans += (d - 1) / a + 1;
        }
        printf("%d\n", ans + x);
        return 0;
}



Measured memory_bytes: 256
N=int(input())
X=[0]*N
Y=[0]*N
H=[0]*N
import sys
for i in range(N):
    X[i],Y[i],H[i]=map(int,input().split())
for x in range(100+1):
    for y in range(100+1):
        for i in range(0,N):
            
            if H[i]>0:
                assume_h = H[i] + abs(x-X[i]) + abs(y-Y[i])
                target = i
                break
                
        for i in range(N):
            #print(x,y,i)
            #print(H[i] + abs(x-X[i]) + abs(y-Y[i]))
            if H[i]  != max(assume_h - abs(x-X[i]) - abs(y-Y[i]), 0):
                break
        else:
            print(x,y,assume_h)
            sys.exit()

Measured memory_bytes: 42860