akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

    ll d1 = n % 10;
    n /= 10;
    ll d2 = n % 10;
    n /= 10;
    ll d3 = n % 10;
    n /= 10;
    ll d4 = n % 10;

    ll x = d4 * 10 + d3;
    ll y = d2 * 10 + d1;

    if (0 <= x and x <= 99 and 1 <= y and y <= 12) {
        if (1 <= x and x <= 12) {
            cout << "AMBIGUOUS" << endl;
        } else {
            cout << "YYMM" << endl;
        }
    } else if (0 <= y and y <= 99 and 1 <= x and x <= 12) {
        if (1 <= y and y <= 12) {
            cout << "AMBIGOUS" << endl;
        } else {
            cout << "MMYY" << endl;
        }
    } else {
        cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

// Mod int
// cf. https://www.youtube.com/watch?v=1Z6ofKN03_Y
struct mint {
  ll x;
  mint(ll x = 0) : x((x + MOD) % MOD) {}
  mint& operator+= (const mint a) {
    if ((x += a.x) >= MOD) x %= MOD;
    return *this;
  }
  mint operator+ (const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint& operator-= (const mint a) {
    if ((x += MOD - a.x) >= MOD) x %= MOD;
    return *this;
  }
  mint operator- (const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint& operator*= (const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator* (const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) { return 1; }
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/= (const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/ (const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

const ll MAX_N = 1005;
// dp[i][j] .. number at (i-1,j-1)
mint dp[MAX_N][MAX_N];

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll h, w;
  cin >> h >> w;
  vector<string> a(h);
  rep(r, h) {
    cin >> a[r];
  }

  // Initialize
  dp[0][1] = 1; // This is used for dp[1][1]
  rep(r, h) rep(c, w) {
    if (a[r][c] != '#') {
      dp[r+1][c+1] += dp[r][c+1];
      dp[r+1][c+1] += dp[r+1][c];
    }
  }
  cout << dp[h][w].x << endl;
}


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

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

    map<int, int> mp;
    rep(i,n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    stack<P> bars;
    for (auto m : mp) {
        if (m.second >= 2) bars.push(m);
    }
    vector<ll> hw(2);
    rep(i,2) {
        if (bars.empty()) break;
        P bar = bars.top();
        bars.pop();
        hw.at(i) = bar.first;
        bar.second -= 2;
        if (2 <= bar.second) bars.push(bar);
    }

    cout << hw.at(0) * hw.at(1) << endl;
    return 0;
}

Measured memory_bytes: 8284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	string S;
	cin >> S;

	char C[26] = {};
	rep(i, 4) C[S[i] - 'A']++;

	bool OK = true;
	rep(i, 26) if (C[i] == 1 || C[i] == 3 || C[i] == 4) OK = false;

	if (OK) co("Yes");
	else co("No");

	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
using namespace std;

int vs[100000+10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
  }
  int res = 0;
  REP(i, n) {
    if(vs[i] == i+1) {
      ++res;
      swap(vs[i], vs[i+1]);
    }
  }
  printf("%d\n", res);
 
  return 0;
}


Measured memory_bytes: 640
def readinput():
    n,m=map(int,input().split())
    sc=[]
    for _ in range(m):
        s,c=map(int,input().split())
        sc.append((s,c))
    return n,m,sc

def main(n,m,sc):
    ans=[-1]*n
    for s,c in sc:
        if ans[s-1]==-1:
            ans[s-1]=c
        else:
            if ans[s-1]!=c:
                return -1
    if ans[0]==0:
        if n==1:
            return 0
        else:
            return -1
    elif ans[0]==-1:
        if n==1:
            ans[0]=0
        else:
            ans[0]=1
    for i in range(1,n):
        if ans[i]==-1:
            ans[i]=0
    sum=0
    for i in range(n):
        sum*=10
        sum+=ans[i]
    return sum

if __name__=='__main__':
    n,m,sc=readinput()
    ans=main(n,m,sc)
    print(ans)


Measured memory_bytes: 9244
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

long long gcd(long long x,long long y){
    return y>0?gcd(y,x%y):x;
}

int main(){
    int n; cin>>n;
    int a[n+2]; rep(i,n) cin>>a[i+1];
    int l[n+2]={};
    for(int i=1;i<=n;i++){
        l[i]=gcd(a[i],l[i-1]);
    }
    int r[n+2]={};
    for(int i=n;i>=0;i--){
        r[i]=gcd(a[i],r[i+1]);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,(int)gcd(l[i-1],r[i+1]));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
// AOJ 2182: Eleven Lover
// 2017.9.20 bal4u@uu
// 2017.11.22

#include <stdio.h>
#include <string.h>

char a[80005];
int dp[2][11];
int t[11][10];

int main()
{
	int i, d, k1, k2, ans;
	char *p;

	for (i = 0; i < 11; i++) for (d = 0; d < 10; d++) t[i][d] = (10*i+d) % 11;
	while (fgets(a, 80005, stdin) && *a != '0') {
		memset(dp, 0, sizeof(dp)); ans = 0;
		for (k1 = 0, k2 = 1, p = a; *p >= ' '; k1 = k2, k2 = !k2) {
			for (i = 0; i < 11; i++) dp[k2][i] = 0;
			d = *p++ & 0xf;
			for (i = 0; i < 11; i++) dp[k2][t[i][d]] += dp[k1][i]; 
			ans += dp[k2][0];
			if (d > 0) dp[k2][d]++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=998244353;
const ll INF=1e18;

int N;
int a[3030];
int dp[3030][3030];

int solve(int l,int r,int turn){
    if(dp[l][r]!=-1)return dp[l][r];
    if(turn==N+1)return 0;
    int ans;
    if(turn%2){
        ans=max(solve(l+1,r,turn+1)+a[l],solve(l,r-1,turn+1)+a[r]);
    }else{
        ans=min(solve(l+1,r,turn+1)-a[l],solve(l,r-1,turn+1)-a[r]);
    }
    dp[l][r]=ans;
    return ans;
}

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    cin>>N;
    rep(i,0,N){
        cin>>a[i];
    }
    rep(i,0,3030)rep(j,0,3030)dp[i][j]=-1;
    cout<<solve(0,N-1,1)<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}

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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int a, b, c, d;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> a >> b >> c >> d;
    int cnt = 0;
    bool flag = true;
    while (true) {
        if (!cnt) {
            cnt = 1;
            c -= b;
            if (c <= 0) break;
            flag = false;
        } else {
            cnt = 0;
            a -= d;
            if (a <= 0) break;
            flag = true;
        }
    }
    cout << (flag ? "Yes":"No") << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3652
n=input().split(" ")
a=int(n[0])
b=int(n[1])
total=0

if a>b:
    total+=a
    a=a-1
elif a<=b:
    total+=b
    b=b-1
if a>b:
    total+=a
    a=a-1
elif a<=b:
    total+=b
    b=b-1

print(total)

Measured memory_bytes: 3064
import std.stdio, std.format, std.string, std.algorithm;

int calc( int r, int v ) {
  return v * ( 100 + r ) / 100;
}

void main()
{
  immutable int NONE = -1;
  auto table = new int[][]( 100, 1000 );
  foreach ( ary; table ) {
	ary[] = NONE;
  }
  foreach ( r; 1 .. 100 ) {
	int before = 1;
	while ( true ) {
	  immutable int after = calc( r, before );
	  if ( after < 1000 ) {
		table[ r ][ after ] = before;
	  } else {
		break;
	  }
	  before++;
	}
  }
  
  while ( true ) {
	int x, y, n;
	string input = strip( readln() );
	formattedRead( input, "%d %d %d", &x, &y, &n );
	if ( x == 0 && y == 0 && n == 0 ) break;

	int ans = -1;
	foreach ( i; 1 .. n ) {
	  if ( table[ x ][ i ] != NONE &&
		   table[ x ][ n - i ] != NONE ) {
		ans = max( ans, calc( y, table[ x ][ i ] ) + calc( y, table[ x ][ n - i ] ) );		
	  }
	}
	writeln( ans );
  }    
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()



int main() {
    int n;
    map<string, ll> mp;
    cin >> n;
    REP(i,n) {
        string s;
        cin >> s;
        SORT(s);
        mp[s]++;
    }
    ll ans = 0;
    for(auto p : mp){
        ans += p.second*(p.second-1)/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	
	int cont = 0; 
	if(s[0] == t[0]) cont++;
	if(s[1] == t[1]) cont++;
	if(s[2] == t[2]) cont++;
	cout << cont;
	
	return 0;
}

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

d = {}
for i in range(1, N + 1):
    s, p = input().split()
    p = int(p)
    if s not in d:
        d[s] = [(p, i)]
    else:
        d[s].append((p, i))

sorted_d = sorted(d.items(), key=lambda x: x[0])
for s, pi in sorted_d:
    if len(pi) == 1:
        print(pi[0][1])
    else:
        pi.sort(key=lambda x: x[0], reverse=True)
        for p, i in pi:
            print(i)


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ret = b[a[0]-1]
for i,j in zip(a,a[1::]):
    ret += b[j-1]
    if j - i == 1:
        ret += c[j-2]
print(ret)

Measured memory_bytes: 3064
#include <stdio.h>
int main(){
	int N, K;
	scanf("%d %d", &N, &K);
	int arr[N];
	for (int i = 0; i< N ;i++){
	scanf("%d", &arr[i]);

	if (i >= K){
		if (arr[i] > arr[i - K] ){
	    printf("Yes\n");
		}
		else {
		    printf("No\n");
		}
	}
}
	return 0;
}

Measured memory_bytes: 2424
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = s.size() + 1;
	vector<ll> a(n);
	rep(i,n-1)if(s[i]=='<')a[i+1] = max(a[i+1],a[i]+1LL);
	for(int i=n-1;i>=0;i--)if(s[i]=='>')a[i] = max(a[i],a[i+1]+1LL);
	cout<<accumulate(ALL(a),0LL)<<endl;
}

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

int	main()
{
	int	N;
	cin >> N;
	vector<int>	A_vec(N);
	for (int i = 0; i < N; ++i)
		cin >> A_vec.at(i);
	map<int, int64_t>	B_map, C_map;	
	int	B, C;
	for (int i = 0; i < N; ++i) {
		B = i - A_vec.at(i);
		C = i + A_vec.at(i);
		if (B_map.count(B))
			++B_map.at(B);
		else
			B_map[B] = 1;
		if (C_map.count(C))
			++C_map.at(C);
		else
			C_map[C] = 1;
	}
	int64_t	cnt = 0;
	for (auto pr : B_map) {
		B = pr.first;
		if (!C_map.count(B))
			continue;
		cnt += pr.second * C_map.at(B);
	}
	cout << cnt << endl;
}


Measured memory_bytes: 27156
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int rooms[4][3][10];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        rooms[--b][--f][--r] += v;
    }
    for (int i = 0; i < 4; i++) {
        if (i > 0) {
            cout << string(20, '#') << endl;
        }
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                cout << " " << rooms[i][j][k];
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 1200
N,*H=map(int,open(0).read().split())
H[0]-=1
def main():
    for i in range(1,N):
        if H[i-1]<H[i]:
            H[i]-=1
        elif H[i-1]==H[i]:
            continue
        else:
            return 'No'
    return 'Yes'
print(main())

Measured memory_bytes: 19976
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const long long INF = 1LL << 60; 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
  int K, N; cin >> K >> N;
  if(500*K >= N) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#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 ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    int n;
    cin >> n;
    REP(i, n) {
        string s;
        cin >> s;
        if (s.length() == 1) {
            cout << 1 << endl;
        } else {
            set<string> S;
            FOR(i, 1, s.length()) {
                string a = string(s.begin(), s.begin()+i);
                string b = string(s.begin()+i, s.end());
                S.insert(a + b);
                S.insert(b + a);
                reverse(ALL(a));
                S.insert(a + b);
                S.insert(b + a);
                reverse(ALL(b));
                S.insert(a + b);
                S.insert(b + a);
                reverse(ALL(a));
                S.insert(a + b);
                S.insert(b + a);
            }
            cout << S.size() << endl;
        }
    }
}

Measured memory_bytes: 3244
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int K,A,B;
    cin >> K >> A >> B;
    for(int i = A; i <= B; i++) {
        if(i%K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

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


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

#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 MP make_pair
#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()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
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 long long MOD = 1e9 + 7;
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;
}

///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    bool ok = true;
	int N;
	cin >> N;
	vector<int> A(N);
	REP(i,N){
		cin >> A[i];
	}

	ll all = 1;
	FORq(i,1,N){
		all *= 3;
	}

	ll minus = 1;
	REP(i,N){
		if (A[i] % 2 == 0) minus *= 2;
	}

	cout << all - minus << endl;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n, t, a);
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  int ans;
  double mini = 1e20;
  rep(i, n) if (double d = abs(a - (t - h[i] * 0.006)); d < mini) {
    mini = d;
    ans = i;
  }
  out(ans + 1);
}


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


#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define print(x) cout << x << endl;
typedef long long ll;

constexpr ll INF = 1'010'000'000'000'000'017LL;\
constexpr ll MOD = 1'000'000'007LL;\
constexpr double EPS = 1e-12;\
constexpr double PI = 3.14159265358979323846;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) {
        cin >> A[i];
    }
    map<ll, ll> m;
    REP(i, N) {
        m[A[i]]++;
    }
    ll sum = 0;
    for(pair<ll, ll> p : m) {
        sum += (p.second * (p.second - 1)) / 2;
    }
    REP(i, N) {
        if (m[A[i]] - 1 < 2) {
            print(sum - (m[A[i]] * (m[A[i]]-1)/2));
        } else {
            print(sum + 1 - m[A[i]]);
        }
    }
    return 0;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
  vector<int> A(4);
  rep(i, 4){
  cin >> A[i];
  }
  sort(ALL(A));
  if(A[0]==1&&A[1]==4){
    if(A[2]==7&&A[3]==9){
    cout << "YES" << endl;
      return 0;
    }
  }
  cout <<"NO" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            List<long> lstVal = new List<long>();
            sS = System.Console.ReadLine().Trim().Split(' ');
            for (int i = 0; i < sS.Length; i++) { lstVal.Add(long.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            long iBak = lstVal[0];
            long iCus = 1000;
            for (int i = 1; i < lstVal.Count; i++)
            {
                if (iBak < lstVal[i])
                {
                    long iKab = iCus / iBak;
                    long iZan = iCus % iBak;
                    iCus = iKab * lstVal[i] + iZan;
                }
                iBak = lstVal[i];
            }

            // 出力
            System.Console.WriteLine("{0}", iCus.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 27832
L,R = (int(i) for i in input().split())
 
l = L % 2019
r = R % 2019


if R-L > 2019 :
    print(0)
elif r <= l :
    print(0)

else:
    MOD = 2019
    N = r - l
    A = []
    for i in range(l,r+1):
        A.append(i)
    #print(A)
    for i in range(N):
        for k in range(i+1,N+1):
            X = (A[i] * A[k]) % 2019
            if X < MOD:
                MOD = X
        
    print(MOD)
    

Measured memory_bytes: 3064
#include <stdio.h>

int main()

{
long long int m[1000000];

long long int sum =0,q;
int x,i,p,z,o;
scanf("%d %d",&x,&o);

for(i=0;i<x;i++)
{
scanf("%lld",&m[i]);

sum=sum+m[i];

}


q=1000000;
for(i=0;i<x;i++)
{
if(m[i]<q)
{
q=m[i];
}
}

if(o==sum)
{
printf("%d",x);
}
else if(o!=sum)
{
p=o-sum;

z=p/q;

printf("%d",z+x);
}

return 0;
}  

Measured memory_bytes: 1740
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define repd(i,x,y) for(int i=x; i>=y; --i)

using namespace std;
const int N=1<<18,mod=998244353;
typedef long long LL;
const LL inv2=(mod+1)/2;
int n;
LL tot,p[N],f[N],_f[N];
LL L[N],R[N],_L[N],_R[N],ans[N];

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

LL getmi(LL a,LL x)
{
    LL rt=1;
    while(x)
    {
        if(x&1) rt=rt*a%mod;
        a=a*a%mod,x>>=1;
    }
    return rt;
}

void FWT(LL a[],int n)
{
    for(int i=1; i<n; i<<=1)
        for(int j=0; j<n; j+=i<<1)
            rep(k,0,i-1)
            {
                LL x=a[j+k],y=a[i+j+k];
                a[j+k]=(x+y)%mod,a[i+j+k]=(x-y)%mod;
            }
}

void IFWT(LL a[],int n)
{
    for(int i=1; i<n; i<<=1)
        for(int j=0; j<n; j+=i<<1)
            rep(k,0,i-1)
            {
                LL x=a[j+k],y=a[i+j+k];
                a[j+k]=inv2*(x+y)%mod;
                a[i+j+k]=inv2*(x-y)%mod;
            }
}

int main()
{
	n=getint();
	rep(i,0,(1<<n)-1) tot+=(p[i]=getint());
	tot=getmi(tot,mod-2);
	rep(i,0,(1<<n)-1) p[i]=p[i]*tot%mod;
	FWT(p,1<<n);

	rep(i,0,(1<<n)-1) L[i]=R[i]=1-p[i];
	rep(i,1,(1<<n)-1) L[i]=L[i]*L[i-1]%mod;
	repd(i,(1<<n)-2,0) R[i]=R[i]*R[i+1]%mod;

	rep(i,0,(1<<n)-1)
	{
		LL x=1;
		if(i>0) x=L[i-1],_L[i]=_L[i-1]*(1-p[i])%mod;
		_L[i]=(_L[i]+x*(-p[i]))%mod;
	}

	repd(i,(1<<n)-1,0)
	{
		LL x=1;
		if(i<(1<<n)-1) x=R[i+1],_R[i]=_R[i+1]*(1-p[i])%mod;
		_R[i]=(_R[i]+x*(-p[i]))%mod;
	}

	rep(i,0,(1<<n)-1)
	{
		LL l=i>0?L[i-1]:1;
		LL _l=i>0?_L[i-1]:0;
		LL r=i<(1<<n)-1?R[i+1]:1;
		LL _r=i<(1<<n)-1?_R[i+1]:0;
		f[i]=l*r%mod,_f[i]=(l*_r+_l*r)%mod;
	}
	
	IFWT(f,1<<n),IFWT(_f,1<<n);
	rep(i,0,(1<<n)-1)
	{
		LL x=(_f[i]*f[0]-f[i]*_f[0])%mod;
		LL y=getmi(f[0]*f[0]%mod,mod-2);
		ans[i]=(x*y%mod+mod)%mod;
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 19072
using System;

namespace A
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			var input = Console.ReadLine();
			Console.WriteLine(input.Length == 2
				                  ? input
				                  : input.Substring(2) + input.Substring(1, 1) + input.Substring(0, 1));
		}
	}
}

Measured memory_bytes: 11092
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] d = new int[n];
			IntStream.range(0, n).forEach(i -> d[i] = scanner.nextInt());
			System.out.println(
					IntStream.range(0, n - 1).map(i -> IntStream.range(i + 1, n).map(j -> d[i] * d[j]).sum()).sum());
		}
	}
}


Measured memory_bytes: 28628
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pii(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int main()
{   ios;
    int n,k;cin>>n>>k;
    priority_queue<int>p;
    f(i,0,n)
    {  
        int x;cin>>x;
        p.push(x);
    }
    while(k--)
    {
        int x=p.top();
        p.pop();
        p.push(x/2);
    }
    ll sum=0;
    while(!p.empty())
     { sum+=p.top();
       p.pop();
     }
         cout<<sum;
     
     }

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 2e9;

int main()
{
    string s;
    cin >> s;
    string ans = s.substr(0, 4) + ' ' + s.substr(4, 8);
    cout << ans << endl;
}

Measured memory_bytes: 384
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
Y,Z=0,0
V,W=0,0
T,U=0,0
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  Y,Z=-1,-10**20
  V,W=Y,Z
  T,U=V,W
  for j in range(26):
    if Y==-1:
      Y,Z=0,X[0]+S[i][0]
    if Z<X[j]+S[i][j]:
      T,U=V,W
      V,W=Y,Z
      Y,Z=j,X[j]+S[i][j]
    elif W<X[j]+S[i][j]:
      T,U=V,W
      V,W=j,X[j]+S[i][j]
    elif T<X[j]+S[i][j]:
      T,U=j,X[j]+S[i][j]
  XX[Y]-=X[Y]
  X[Y]=0
  P.append([Y,V,T])
  if randrange(0,50)==0:
    P[i][1]=randrange(0,26)
  if randrange(0,5)==0:
    P[i][2]=randrange(0,26)
  P[i]=tuple(P[i])
SCORE=0
X=[0]*26
for i in range(D):
  SCORE+=S[i][P[i][0]]
  for j in range(26):
    X[j]+=C[j]
  X[P[i][0]]=0
  SCORE-=sum(X)
SCORE2=0
YY=[]
for i in range(D):
  for k in range(2):
    d,q=i,P[i][k+1]
    SCORE2=SCORE
    YY=XX[:]
    SCORE2-=S[d][P[d][0]]
    SCORE2+=S[d][q]
    for j in range(26):
      X[j]=0
    YY[P[d][0]],YY[q]=0,0
    for j in range(D):
      if j==d:
        Z=q
      else:
        Z=P[j][0]
      X[P[d][0]]+=C[P[d][0]]
      X[q]+=C[q]
      X[Z]=0
      YY[P[d][0]]+=X[P[d][0]]
      YY[q]+=X[q]
    if SCORE2-sum(YY)>SCORE-sum(XX):
      z=[P[i][k+1]]
      for l in range(3):
        if l!=k:
          z.append(P[i][l])
      P[i]=tuple(z)
      XX=YY[:]
      SCORE=SCORE2
for i in range(D):
  print(P[i][0]+1)

Measured memory_bytes: 79756
#include <bits/stdc++.h>
using namespace std;
#define D double
#define ll long long int
#define f(i,a,b) for(int i=a;i<b;i++)
#define MEM(a,val) memset(a,val,sizeof(a))

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
   
    string s;	cin>>s;
    (s[2]==s[3] && s[4]==s[5])?cout<<"Yes":cout<<"No";
}


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

using namespace std;
using ll = long long;
using vi = vector<int>;

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

vi dp(int* v, int* w, int n, int k) {
    vi table(k+1);
    REP(i, k+1) {
        table[i] = 0;
    }
    REP(i, n) {
        for (int j = k; j >= w[i]; j--) {
            table[j]= max(table[j], table[j-w[i]] + v[i]);
        }
    }
    return table;
}

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

    int n, k; cin >> n >> k;
    int v[n], w[n];
    REP(i, n) {
        cin >> v[i] >> w[i];
    }

    // a に含まれる n 個の値で k を作ったときの最大値は何か
    vi table = dp(v, w, n, k);

    int mm = 0;
    REP(i, k+1) {
        if (table[i] > mm) mm = table[i];
    }
    cout << mm << "\n";
}


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

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie();cout.tie();
    int n,m,b,x=0,y,z,i,j=0,k=0,p;
    cin>>n>>m;
    vector<int>a(n);

    vector<pair<int,int>> pa(m);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        //cout<<mp[a[i]]<<endl;
    }
    sort(a.begin(),a.end());
    for(i=0;i<m;i++)
    {
        cin>>pa[i].second>>pa[i].first;
    }
    sort(pa.rbegin(),pa.rend());
    j=0;
    i=0;
    while(a[i]<pa[j].first && i<n && j<m)
    {
        a[i]=pa[j].first;
        i++;
        if(pa[j].second>1)
        {
            pa[j].second--;
        }
        else
        {
            j++;
        }

    }
    long long sum=0;
    for(i=0;i<n;i++)
    {
        sum+=1LL*a[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 1408
<?php
  $N=+fgets(STDIN);
  $a=explode(" ",fgets(STDIN));
  $c=0;
  for($i=0;$i<$N;$i++)$c+=$a[$i]%2==0&&$a[$i]%3!=0&&$a[$i]%5!=0;
  echo $c?DENIED:APPROVED;

Measured memory_bytes: 3828
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}

#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back

void solve(){
    int n;
    cin >> n;
    vll A(n);
    cin >> A;
    const ll modu = 1e9 + 7;
    ll sum = 0;
    for (int i = 0; i < n; ++i) sum += A[i];
    sum %= modu;
    ll ans = (sum * sum) % modu;
    sum = 0;
    for (int i = 0; i < n; ++i) sum += A[i] * A[i], sum %= modu;
    ans -= sum;
    ans += modu;
    ans %= modu;
    ans *= ((1 + modu) / 2);
    ans %= modu;
    cout << ans << END; 
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4780
#include <cstdio>
typedef long long ll;
int main()
{
     ll n, a ,b;
    scanf("%lld%lld%lld", &n, &a, &b);
    ll ans=0;
    if (a>b) ans =0;
    else if (n==1 && a < b) ans=0;
    else if (n<=2) ans=1;
    else
    {
        ll l = (n-2)*a, r =(n-2)*b;
        ans=r-l+1;
     }
     printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define MAXN 200005
using namespace std;
int a[MAXN],b[MAXN];
pair<int,int> c[MAXN];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        c[i]=make_pair(b[i],a[i]);
    }
    sort(c,c+n);
    int t=0;int flag=0;
    for(int i=0;i<n;i++)
    {
        int l=c[i].first;
        int r=c[i].second;
        t+=r;
        if(t>l)
        {
            flag=1;
            break;
        }
    }
    if(flag)
        cout<<"No";
    else
        cout<<"Yes";
    return 0;

}


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

#define ll long long

int main(){
	ll n, m;
	cin >> n >> m;
	ll ans = 0;
	multiset<ll> s;
	for(ll i =0;i<n;i++) {
		ll x;
		cin >> x;
		s.insert(-x);	
	}
	
	for(ll times=0; times<m; times++){
		ll largest = *s.begin();	
		largest = -largest;
		largest = largest/2;
		s.erase(s.begin());
		s.insert(-largest);
	}
	
	for(auto i: s) { ans += i; }
	cout << -ans << "\n";
	
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
int main()
{
  int n;
  std::cin >> n;
  for(int i = 0; i < n; i++)
  { 
    int x, y, p, b, v;
    std::cin >> x >> y >> b >> p;
    
    v = x * b + y * p;

    b = std::max(b, 5); 
    p = std::max(p, 2);
    v = std::min(v, (int)((x * b + y * p) * 0.8));
    
    std::cout << v << std::endl;
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;

vector<int> alf[26];
void solve() {
	string s, t; cin >> s >> t;
	int n = s.length();
	rep(i, n) {
		alf[s[i] - 'a'].push_back(i);
	}
	int ans = 1; int loc = 0;
	int m = t.length();
	rep(i, 26) {
		int len = alf[i].size();
		rep(j, len) {
			alf[i].push_back(alf[i][j]+n);
		}
	}
	rep(i, m) {
		int z = t[i] - 'a';
		if (alf[z].empty()) {
			cout << -1 << endl; return;
		}
		int id = lower_bound(alf[z].begin(), alf[z].end(), loc) - alf[z].begin();
		int nex = alf[z][id];
		if (nex >= n) {
			ans++; nex = nex - n+1;
			if (nex == n) {
				ans++; nex = 0;
			}
		}
		else {
			nex++;
			if (nex == n) {
				ans++; nex = 0;
			}
		}
		loc = nex;
	}
	cout << (ll)(ans-1)*n+loc << endl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//init();
	solve();

	//cout << "finish" << endl;
	//stop
	return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a > b + b) {
	    cout << a - 2 * b << "\n";
	}
    else {
        cout << "0" << "\n";
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    int h,w,k;
    cin >> h >> w >> k;
    char f[h][w];
    int ans[h][w];
    bool check[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> f[i][j];
            check[i][j] = false;
            ans[i][j] = 0;
        }
    }
    int cnt = 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(f[i][j] == '#'){
                int t = 1;
                ans[i][j] = cnt;
                if(j+t < w){
                    while(f[i][j+t] == '.' && j+t < w){
                        ans[i][j+t] = cnt;
                        t++;
                        
                    }
                }
                cnt++;
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(ans[i][j] == 0){
                int t = 0;
                bool found = false;
                while(true){
                    if(ans[i][j+t] != 0){
                        found = true;
                        break;
                    }
                    if(j+t == w-1){
                        break;
                    }
                    t++;
                }
                if(found){
                    for(int k = 0; k < t; k++){
                        ans[i][k] = ans[i][t];
                    }
                }else{
                    continue;
                }
            }
        }
    }

    for(int j = 0; j < w; j++){
        for(int i = 0; i < h; i++){
            if(ans[i][j] == 0){
                int t = 0;
                while(true){
                    if(i+t == h-1){
                        break;
                    }
                    if(ans[i+t][j] != 0){
                        break;
                    }
                    t++;
                }
                for(int k = 0; k < t; k++){
                    ans[i+k][j] = ans[i+t][j];
                }
            }
        }
    }

    for(int j = 0; j < w; j++){
        for(int i = h-1; i >= 0; i--){
            if(ans[i][j] == 0){
                int t = 0;
                while(true){
                    if(i - t == 0){
                        break;
                    }
                    if(ans[i-t][j] != 0){
                        break;
                    }
                    t++;
                }
                for(int k = 0; k < t; k++){
                    ans[i-k][j] = ans[i-t][j];
                }
            }
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << ans[i][j] << ' ';
        }
        cout << endl;
    }
}

Measured memory_bytes: 1280
#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 <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    ll n;
    string s;
    cin >> n >> s;
    vector<char> x;
    for (ll i=0;i<n;i++){
        x.push_back(s[i]);
    }
    ll c=0;
    for (ll i=0;i<n;i++){
        if (s[i]=='('){
            c++;
        }else{
            if(c!=0)c--;
            else x.insert(x.begin(),'(');
        }
    }
    for (ll i=0;i<c;i++){
        x.push_back(')');
    }
    for (ll i=0;i<x.size();i++){
        cout << x[i];
    }
    cout << endl;
    return 0;
}




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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"

using ld = long double;
using ll = long long;

inline ll addm(ll __a, ll __b, ll __m);
inline ll subm(ll __a, ll __b, ll __m);
inline ll mulm(ll __a, ll __b, ll __m);
ll powm(ll __a, ll __b, ll __m);
ll inv(ll __x, ll __m);
// }}}

const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9+7;

const int N = 100500;
int h[N], r[N];
void solve()
{
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        if (i) r[i] = INF;
        if (i) r[i] = min(r[i], r[i-1] + abs(h[i-1]-h[i]));
        if (i > 1) r[i] = min(r[i], r[i-2] + abs(h[i-2]-h[i]));
    }
    cout << r[n-1] << endl;
}

// main {{{
int main()
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}

inline ll addm(ll __a, ll __b, ll __m = MOD) {
    return ((__a+__b)%__m);
}
inline ll subm(ll __a, ll __b, ll __m = MOD) {
    return (((__a-__b)%__m+__m)%__m);
}
inline ll mulm(ll __a, ll __b, ll __m = MOD) {
    return ((__a*__b)%__m);
}
ll powm(ll __a, ll __b, ll __m = MOD) {
    ll ret = (!__b) ? 1 : powm(__a, __b/2, __m);
    return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b%2) ? __a : 1, __m);
}
ll inv(ll __x, ll __m = MOD) {
    return powm(__x, __m-2, __m);
}
// }}}


Measured memory_bytes: 1024
import sys

N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)

t = sum(A) / (4*M)

if t.is_integer():
    t = sum(A) // (4*M)

for i in range(M):
    if A[i] < t:
        print("No")
        sys.exit()

print("Yes")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

ll df(ll a, ll b)
{
    if (b < 0) a = -a, b = -b;
    return a / b - (a % b < 0);
}

ll dc(ll a, ll b)
{
    if (b < 0) a = -a, b = -b;
    return a / b + (a % b > 0);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, a;
    cin >> h >> a;
    cout << dc(h, a);
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] d = new int[n];

		// 整数の入力
		for(int i=0;i<n;i++)
			d[i] = sc.nextInt();

		Arrays.sort(d);

		// 出力
		System.out.println(d[n/2]-d[n/2-1]);
	}
}

Measured memory_bytes: 49956