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

int main() {
    int W, H, N;
    vector<int> x, y, a;
    cin >> W >> H >> N;
    int width = W;
    int height = H;
    int maxW_l=0, maxW_u=0;
    int maxH_l=0, maxH_u=0;

    for(int i=0; i<N; i++){
        int s1,s2,s3;
        cin >> s1 >> s2 >> s3;
        x.push_back(s1);
        y.push_back(s2);
        a.push_back(s3);
        if(a[i]==1)
        {
            if(maxW_l < x[i]) maxW_l = x[i];
        }else if(a[i]==2)
        {
            if(maxW_u < width-x[i]) maxW_u = width-x[i];
        }else if(a[i]==3)
        {
            if(maxH_l < y[i]) maxH_l = y[i];
        }else
        {
            if(maxH_u < height-y[i]) maxH_u = height-y[i];          
        }
    }
    if((width <= maxW_l + maxW_u) || (height <= maxH_l + maxH_u))
    {
        cout << "0" << endl;
    }else
    {
        cout << (width - (maxW_l+maxW_u)) * (height - (maxH_l + maxH_u)) << endl;
    }
    return 0;
}

Measured memory_bytes: 3544
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static int a,b,c;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            a=sc.nextInt();
            b=sc.nextInt();
            c=sc.nextInt();
            if(a==-1&&b==-1&&c==-1) break;
            if(a==-1||b==-1) System.out.println("F");
            else if(a+b>=80) System.out.println("A");
            else if(a+b>=65) System.out.println("B");
            else if(a+b>=50) System.out.println("C");
            else if(a+b>=30&&c>=50) System.out.println("C");
            else if(a+b>=30) System.out.println("D");
            else System.out.println("F");
        }
        sc.close();
    }
}


Measured memory_bytes: 26580
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
sumA = sum(A)
ans = ['Yes', 'No']
count = 0
for a in A:
    if not a < 1 / (4 * M) * sumA:
        count += 1
print(ans[count < M])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
int32_t main()
{
    int n;
    cin>>n;
    string ans;
    while(n)
    {
        int t=n%26;
        if(t==0)
        {
            t=26;
            n-=1;
        }
        ans+=char(t)+'a'-1;
        n=n/26;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
unittest
{
	assert( [ "5 1", "1 0 0 1 0" ].parse.expand.solve == "1 2 2 1 2" );
	assert( [ "5 2", "1 0 0 1 0" ].parse.expand.solve == "3 3 4 4 3" );
	
	assert( [ "200000 200000", "0".repeat( 200000 ).join( " " ) ].parse.expand.solve == "200000".repeat( 200000 ).join( " " ) );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( nk[ 1 ], as );
}

auto solve( long k, long[] as )
{
	// 電球の光量は毎操作ごとに必ず強くなる かつ 電球の数と同じになったら変化がなくなる
	// a^2ぐらいの勢いで強くなるのでO(N^2)実装でも間に合う
	foreach( i; 0L .. k )
	{
		// いもす法で操作後の電球の光量を計算
		auto ts = new long[ as.length + 1 ];
		foreach( j, a; as )
		{
			ts[ max( 0L,               j.signed - a     ) ]++;
			ts[ min( as.length.signed, j.signed + a + 1 ) ]--;
		}
		auto m = 0L;
		foreach( j, ref a; as )
		{
			ts[ j + 1 ] += ts[ j ];
			a = ts[ j ];
			m += ( a == as.length );
		}
		
		// 全電球の光量が最大になったら打ち切り
		if( m == as.length ) break;
	}
	return as.to!( string[] ).join( " " );
}


Measured memory_bytes: 19976
let NY: [Int] = readLine()!.characters.split(" ").map { Int(String($0))! }
var xRes: Int = -1
var yRes: Int = -1
var zRes: Int = -1

for x in 0...NY[0] {
    for y in 0...NY[0] {
        let z: Int = NY[0] - x - y
        if 0 <= z {
            let otoshidama: Int = 10000*x + 5000*y + 1000*z
            if otoshidama == NY[1] {
                xRes = x
                yRes = y
                zRes = z
            }
        }
    }
}
print(xRes, yRes, zRes)

Measured memory_bytes: 4720
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        xy: [(i64, i64); n],
    }

    let mut xy = xy;
    xy.sort_by(|a, b|
    (a.1 as f64).atan2(a.0 as f64)
   .partial_cmp(&(b.1 as f64).atan2(b.0 as f64)).unwrap()
    );

    let mut ans = 0.0_f64;

    for i in 0..n {
        let mut cur =(0, 0);
        for j in 0..n {
            let j = (i + j) % n;
            cur.0 += xy[j].0;
            cur.1 += xy[j].1;
            ans = ans.max((cur.0 as f64).hypot(cur.1 as f64));
        }
    }


    println!("{:.40}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    int N;
    int A[100];
    cin>>N;
    int evCnt=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]%2==0)evCnt++;
    }
    int ans;
    ans=pow(3,N)-pow(2,evCnt);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll sum = 0;

    rep(i, N.size()){
        sum += N[i] - '0';
    }

    if(sum % 9 == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}


void solve_old(long long K){
    ll res=0;
    for (long long i = 0; i < 10e5; i++) {
        string s=to_string(i);
        ll cnt=0;
        for (long long j = 1; j < s.length(); j++) {
            if(s[j-1]-s[j]<=1) cnt++;
        }
        if(cnt==K) {
            res=i;
            break;
        }
    }
    cout << res << endl;
}

void solve(long long K){
    if(K<=12){
        cout << K << endl;
        return;
    }
    // ll res=1;
    vector<ll> dp(K+10);
    for (long long i = 0; i < 9; i++) {
        dp[i]=i+1;
    }
    ll i=0;
    ll j=9;
    while(j<K){
        ll lsd=dp[i]%10;
        if(lsd-1>=0) dp[j++]=dp[i]*10+lsd-1;
        dp[j++]=dp[i]*10+lsd;
        if(lsd+1<=9) dp[j++]=dp[i]*10+lsd+1;
        i++;
    }
    // if(K<=15) vout(dp);
    cout << dp[K-1] << endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  string S; cin >> S;
  ll ans = 0;
  ll cnt = 0;
  for(int i = 0; i < S.size(); ++i) {
    if(S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C') {
      cnt++;
    } else {
      if(ans < cnt) ans = cnt;
      cnt = 0;
    }
    if(i == S.size() - 1) {
      if(ans < cnt) ans = cnt;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, list(input())))
 
while N != 0:
	digit = 1
	while digit < N // 2:
		digit *= 2
 
	x = []
	for i in range(digit, N):
		x.append(abs(a[i - digit] - a[i]))
 
	a = x
	N -= digit
	if len(x) == 1:
		break
 
print(a[0])

Measured memory_bytes: 21348
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
double dp[3000][3000];
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout << fixed << setprecision(10);
   int n;cin >> n;
   dp[0][0] = 1;
   for(int i=1; i<=n; i++){//i回投げる
      double p; cin >> p;
      for(int j=0; j<=i; j++){//j回表が出る
         dp[j][i-j] = ((j-1)<0 ? 0 : dp[j-1][i-j])*p 
                   +((i-j-1)<0 ? 0 : dp[j][i-j-1])*(1-p);
      }
   }
   double ans = 0;
   for (int i=n/2+1; i<=n; i++)
      ans += dp[i][n-i];
   cout << ans << endl;
}

Measured memory_bytes: 49936
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

ll A,B,K;

ll max(ll a, ll b){
    if(a>b)return a;
    else return b;
}

int main(){
    cin>>A>>B>>K;
    cout<<max(0,A-K)<<" "<<max(0,B-max(0,K-A))<<endl;  
    
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")


int main() {
	int a, b;
	cin >> a >> b;
	if (a != 1 && b != 1)PRI(1);
	if (a != 2 && b != 2)PRI(2);
	if (a != 3 && b != 3)PRI(3);
	return 0;
}

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


int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    int ans = 0;
    rep(i,101){
        if(a <= i && i < b){
            if(c <= i && i < d){
                ans ++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
def checkWays(n,x)
  count = 0
  catch(:stop) do
    n.downto(1) do |n1|
      (n1-1).downto(1) do |n2|
        n3 = x - n1 - n2
        count += 1 if (n3 < n2) && (n3 > 0)
        throw :stop if (n3 > n1)
        break if (n3 > n2)
      end
    end
  end
  puts count
end

while ((n,x = gets.split(" ").map(&:to_i)) != [0,0]) do
  checkWays(n,x)
end

Measured memory_bytes: 8592
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<i64,i64>;

int main(){
    string S;
    cin >> S;
    string ans;
    if(S == "Sunny") ans = "Cloudy";
    else if(S == "Cloudy") ans = "Rainy";
    else if(S == "Rainy") ans = "Sunny";
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a,b,x,y;
    scanf ("%d %d",&a,&b);
    if (1 <= a, b <= 100){
        x=a*b;
        y=2*a+2*b;
        printf ("%d %d\n",x,y);
    }
    return 0;

}



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

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

  vector<int> a(n);
  for(int i=0;i<n;i++)cin >> a[i];
  int MinV = *min_element(a.begin(),a.end());

  vector<int> order = a, p = a;
  sort(order.begin(), order.end());

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(a[i] == order[j])p[i] = j;
    }
  }

  long long ans = 0;
  vector<bool> use(n,0);
  for(int i=0;i<n;i++){
    if(!use[i]){
      int cur = i, minv = 1e8, sum = 0, len = 0;
      do{
	use[cur] = 1;
	minv = min(minv, a[cur]);
	sum += a[cur];
	cur = p[cur];
	len++;
      }while(cur!=i);
      ans += min(sum + minv*(len-2), sum + MinV*len + minv + MinV);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
//#define rep(i,n), for(int i=0;i<n;i++)
using namespace std;

int CX(int A,int B){
    int t=0;
    if(A%B==0){
        t+=A/B;
    }else{
        t++;
        t+=A/B;
    }
    return t;
}

int main(void){

    int N,K;
    cin>>N>>K;
    int tempN = N;
    int data[N];  
    int minplace;
    int i;
    int R,L;
    // for(i=0;i<N;i++){
    //     cin>>data[i];
    //     if(data[i]==1){
    //         minplace=i;
    //         if(i>N/2){//左寄りにする
    //             i = N-i;
    //         }
    //         L=i;
    //         R=N-i-1;
    //     }
    // }
    int ans=1;
    ans+=CX(N-K,K-1);
    // if(minplace<K){
    //     ans++;
    //     N-=K;
    //     //cout << N<< endl;
    //     ans+=CX(N,K-1);
    //     // while(N>0){
    //     //     ans++;
    //     //     N-=(K-1);
    //     // }

    // }else{
    //     // ans++;
    //     // L-=K-1;
    //     // while(L>0){
    //     //     ans++;
    //     //     L-=K-1;
    //     // }
    //     // ans++;
    //     // R-=K-1;
    //     // while(R>0){
    //     //     ans++;
    //     //     R-=K-1;
    //     // }
    //     ans++;
    //     N-=K;
    //     //cout << N<< endl;
    //     ans+=CX(N,K-1);

    // }


    //cout << minplace<<endl;
    cout << ans << endl;


    return 0;
}

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

int main(){
    using namespace std;
    unsigned long n;
    cin >> n;
    vector<unsigned long> dp{1};
    for(unsigned long i = 0; i < n; ++i){
        char c;
        cin >> c;
        if(c == 'U'){
            dp.push_back(dp.back());
            for(unsigned long i = dp.size() - 2; i > 0; --i)dp[i] = dp[i] * i + dp[i - 1];
            dp[0] = 0;
        }else if(c == 'D'){
            for(unsigned long i = 0; i < dp.size(); ++i)dp[i] = dp[i + 1] * (i + 1) * (i + 1) + dp[i] * i;
        }else continue;
        for(auto& i : dp)i %= 1000000007;
    }
    cout << dp[0] << endl;
}


Measured memory_bytes: 3156
using System;
using System.IO.Pipes;
using System.Runtime.InteropServices.ComTypes;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var rgb = input.Split(' ');
            var i = int.Parse(String.Join("", rgb));
            if (i % 4 == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


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

int main() {
  int a,b,x;
  cin >> a >> b;
  if ((a + b) % 2 == 0) {
    x = (a + b) / 2;
  }
  else {
    x = (a + b) / 2 + 1;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

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

  for (int i = 0; i < (int)n.size(); ++i)
  {
    if (n[i] == '1') n[i] = '9';
    else if (n[i] == '9') n[i] = '1';
  }
  cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

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

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

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

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

int main(){

  int n = in();
  int k = in();
  vector<int> a(n);
  REP(i, n){
    a[i] = in();
  }
  vector<int> dp(n + k, INF);
  dp[0] = 0;
  REP(i, n){
    FOR(j, 1, k + 1){
      chmin(dp[i+j], dp[i] + abs(a[i] - a[i+j]));
    }
  }
  cout << dp[n-1] << endl;
  
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  int a[220];
  
  
  for (int i = 0; i < n; i++) cin >> a[i];
  
  int count = 0;
  
  while(true) {
    bool exist_odd = false;
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 != 0) exist_odd = true;
    }
    
    if (exist_odd) break;
    
    for (int i = 0; i < n; i++) {
      a[i] /= 2;
    }  
    
    count++;
  }
  
  cout << count << endl;
}  


Measured memory_bytes: 256
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	int JU=abs(a-b);
	JU--;
	if(JU&1){
		printf("Alice\n");
		
	}
	else{
		printf("Borys\n");
	}
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    char S[N];
    for ( int i = 0; i < N; ++i){
        cin >> S[i];
    }
    int count = 0;
    
    for ( int i = 0; i < N-2; ++ i){
        if ( S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C' ){
            count += 1;
        }
    }
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 256
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True
#for i in range(n):

ans=0

n=I()
a=LI()
x=0
c=1
for i in a:#range(n):
    if i==c:
        x+=1
        c+=1
    
ans=n-x
if c==1:
    ans=-1
print(ans)




Measured memory_bytes: 72268
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int H,W;
  cin >> H >> W;
  vvi d(10,vi(10));
  rep(i,10) {
    rep(j,10) {
      cin >> d[i][j];
    }
  }
  rep(k,10) {
    rep(i,10) {
      rep(j,10) {
        d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
      }
    }
  }
  vi cnt(10,0);
  rep(i,H) {
    rep(j,W) {
      int x;
      cin >> x;
      if(x != -1) {
        cnt[x]++;
      }
    }
  }
  int ans = 0;
  rep(i,10) {
    ans += d[i][1] * cnt[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int a, b, c, d, N;
  cin >> a >> b >> c >> d;
  N = (a + b) - (c + d);
 if (N > 0)
   cout << "Left" << endl;
 else if (N < 0) 
   cout << "Right" << endl;
 else 
    cout << "Balanced" << endl; 
}

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

int n;
int color = -1;
int same = 0;
int ans = 0;

int main() {

    cin >> n;
    while (n--) {
        int a;
        cin >> a;
        if (a == color) {
            same++;
        } else {
            ans += same / 2;
            same = 1;
            color = a;
        }
    }
    ans += same / 2;

    cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int long long

//int N = 123;

bool query(int n) {
    cout << "? " << n << endl;
    fflush(stdout);
    string ans;
    cin >> ans;
    // if((n < N && to_string(n) < to_string(N)) || (n >= N && to_string(n) >= to_string(N))) {
    //     ans = "Y";
    //     cout << ans << endl;
    // } else {
    //     ans = "N";
    //     cout << ans << endl;
    // }
    if(ans == "Y") {
        return true;
    } else {
        return false;
    }
}

void solve() {
    int cnt = 0, l = 0;
	for(int k = 0; k <= 9; ++k) {
        int t = (int)pow(10, k);
        if(query(t)) {
            cnt ++;
        } else {
            l = k;
            break;
        }
    }

    if(cnt == 10) {
        //pow(10, a)の形になると断言できる
        for(int k = 0; k <= 9; ++k) {
            int t = 2 * (int)pow(10, k);
            if(query(t)) {
                cout << "! " << (int)pow(10, k) << endl;
                exit(0);
            }
        }
    } else {
        //二部探索で特定する
        //ふつーに二部探索では特定できない？
        //各桁ごとに二部探索？

        int ng = (int)pow(10, l - 1), ok = (int)pow(10, l) - 1;
        while(ok - ng > 1) {
            int mid = (ok + ng) / 2;
            if(query(10 * mid)) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        cout << "! " << ok << endl;
        exit(0);
        //桁が同じなら文字数で比較すればよいので10倍して比較すればok

        //２つ動かれると厄介なので、どちらかの返答を固定する！！
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 624
/*
  AtCoder Beginner Contest 106
  B - 105

  方針
    1. 全探索
    2. 手計算して列挙

  実装
    今回は方針1を採用する。
    奇数であることに注意すれば、ループの回数を減らせる。
*/

#include<iostream>
using namespace std;

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

  if (N < 3) printf("0\n");
  else {
    int ans = 0;

    for (int i = 3; i <= N; i += 2) {
      int cnt = 0;
      for (int j = 1; j <= i; j += 2) {
        if (i % j == 0) ++cnt;
      }

      if (cnt == 8) ++ans;
    }

    printf("%d\n", ans);
  }
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A1(N),A2(N);
    for (int i = 0; i < N; i++) cin >> A1.at(i);
    for (int i = 0; i < N; i++) cin >> A2.at(i);
    int ans = 0;

    for (int i = 0; i < N; i++) {
        int sum = 0;
        for (int j = 0; j < i + 1; j++) sum += A1.at(j);
        for (int j = i; j < N; j++) sum += A2.at(j);
        ans = max(sum, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define lowbit(x) x&(-x)
using namespace std;
typedef long long ll;
const ll INF=0x3f3f3f3f;
const int N=1e5+10;
const int M=(1<<24)+10;
const ll MOD=1e9+7;
const double E=1e-7;
int main(){
	int x;
	cin >> x;
	if(x>=30)
	cout << "Yes" << endl;
	else
	cout << "No" << endl; 
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<string.h>

#define MAX 500

int main() {

	char W[MAX];
	int i, length, h, m;

	while (1) {

		scanf("%s", W);
			if (W[0] == '-') break;

		scanf("%d", &m);

		length=strlen(W);

		for (i = 0; i < m; i++) {
			scanf("%d", &h);

			strncpy(&W[length], W, h);
			strncpy(W, &W[h], length);

			W[length] = '\0';
		}

		printf("%s\n", W);

		i++;
	}

	return 0;

}



Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll A,B,C,ans;
    cin >> A >> B >> C;
    if(A + B == C)
        ans = B + C;
    else if(A + B < C)
        ans = A + 2*B + 1;
    else 
        ans = B + C;
    
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <map>

using namespace std;


map<string, int> mp;
int main() {
    int n;
    cin>>n;
    for (int i=0;i<n;i++) {
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<mp.size()<<endl;
    return 0;
}


Measured memory_bytes: 18852
#include <cstdio>
#include <vector>
#include <map>
#include <utility>
#include <climits>
using namespace std;

#define FOR(i, a, b) for( int i = (a); i < (b); i++)
#define MAX 100100
#define INF INT_MAX

bool flag = true;

void search(vector<pair<int, int>> G[MAX], int D[MAX], int x, int N, int d) {
	D[x] = d;
	if (G[x].empty()) return;

	auto it = G[x].begin();
	for (; it != G[x].end(); it++) {
		if (D[it->first] == INF) search(G, D, it->first, N, d + it->second);
		else if (D[it->first] != d + it->second) flag = false;
	}
}

int main() {
	int N, M; scanf("%d%d", &N, &M);
	vector<pair<int, int>> G[MAX];
	int D[MAX]; FOR(i, 0, MAX) D[i] = INF;

	FOR(i, 0, M) {
		int l, r, d; scanf("%d%d%d", &l, &r, &d);
		G[l].push_back(make_pair(r, d)); G[r].push_back(make_pair(l, -d));
	}

	FOR(i, 1, N + 1) {
		if (D[i] == INF) search(G, D, i, N, 0);
	}

	if (flag) printf("Yes\n");
	else printf("No\n");

	return 0;
}

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

signed main() {
	int n;
	string s;
	cin >> s;
	int cnt = 0, ans = 0;


	for (int i = 0; i < s.size(); ++i) {
		char c = s[i];
		if (c == 'A' or c == 'T' or c == 'C' or c == 'G') {
			cnt++;
		}
		else {
			ans = max(ans, cnt);
			cnt = 0;
		}
	}

	ans = max(ans, cnt);
	cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    ll m = 1e18;

    ll n = min(X, Y);
    m = min(m, A * (X - n) + B * (Y - n) + 2 * n * C); 
    m = min(m, A * X + B * Y); 
    ll N = max(X, Y);
    m = min(m, 2 * N * C); 
    put(m);

    return 0;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U> bool chmax(T &a, U b) { if (a <= b) {a = b; return 1;} return 0; }
template <class T, class U>  bool chmin(T &a, U b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T>  ostream &operator<<(ostream &os, vector<T> &v) { os << "{"; rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); } os << "}"; return os; }

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

// Union Find
struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<ll> siz;
    
    //最初は全てが根であるとして初期化
    UnionFind(ll N) : par(N), siz(N, 1LL) { 
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    //初期化
    void init(ll N) {   
        par.resize(N);
        siz.assign(N, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < N; i++) par[i] = i; // 初期では親は自分自身
    }

    // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    ll root(ll x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    // 素集合のサイズ
    ll size(ll x){ 
      return siz[root(x)];
    }

    // xとyの木を併合
    bool unite(ll x, ll y) {
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return false; //xとyの根が同じ(=同じ木にある)時はそのまま

        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;     //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        return true;
    }

    // 2つのデータx, yが属する木が同じならtrueを返す
    bool same(ll x, ll y) { 
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

    
int main() {
  ll x=0,y=0,z=0,k,n,m,h,w,ans=0,sum=0,Max=-1,Min=1e9+1;
  bool ok = true;
  string t;
  cin >> n >> m;
  VI a(m),b(m);
  
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  sum = n;  

  rep(i,m){
    UnionFind u(n);
    rep(j,m){
        if(i!=j){
            if(u.unite(a[j],b[j])){
                sum--;
            }
        } 
    }
    if(sum == 2){
        ans++;
    }
    sum = n;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

const int MAX_FACT = 200001;
ll MOD = 1e9 + 7;
ll fact[MAX_FACT], invFact[MAX_FACT], inv[MAX_FACT];

void init() {
  fact[0] = fact[1] = 1;
  invFact[0] = invFact[1] = 1;
  inv[1] = 1;
  for (auto i = 2; i < MAX_FACT; ++i)
  {
    fact[i] = fact[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    invFact[i] = invFact[i - 1] * inv[i] % MOD;
  }
}

ll calcCombination(ll n, ll k) {
  if (n < k) {
    return 0;
  }
  if (n < 0 || k < 0) {
    return 0;
  }
  return fact[n] * (invFact[k] * invFact[n - k] % MOD) % MOD;
}

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  
  init();
  
  auto result = 0LL;
  for (auto i = 1; i < N; ++i) {
    result = (result + i * (N - i) * M % MOD * M % MOD) % MOD;
  }
  
  for (auto i = 1; i < M; ++i)
  {
    result = (result + i * (M - i) * N % MOD * N % MOD) % MOD;
  }
  
  result = (result * calcCombination(N * M - 2, K - 2)) % MOD;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 4992
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Main ans = new Main();
		System.out.println(ans.solve());
	}

	private long solve() {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long [] array = new long[N+1];
		for(int i=1;i<=N;i++){
			array[i] = sc.nextLong();
		}

		long [][] sum = preProcess(array, N);
		long [][] dp = new long[500][500];
		return solve(sum, 1, N, dp);
	}

	private long[][] preProcess(long[] array, int N) {
		long [][] sum = new long[500][500];
		for(int i=1;i<=N;i++){
			for(int j=i;j<=N;j++) {
				sum[i][j] = array[j] + ((i==j) ? 0 : sum[i][j-1]);
			}
		}
		return sum;
	}

	private long solve(long[][] sum, int i, int j, long[][] dp) {
		if (i==j) return 0;
		if (dp[i][j] != 0) return dp[i][j];
		long answer = (long) 1e14+7;
		for(int k=i;k<j;k++) {
			long currAns = sum[i][j] + solve(sum, i, k, dp) + solve(sum, k+1, j, dp);
			answer = Math.min(currAns, answer);
		}
		dp[i][j] = answer;
		return answer;
	}

}


Measured memory_bytes: 41556
#include<iostream>
using namespace std;
int a,b,n;
int main(){
	cin>>a>>b;
	if(b==100)n=1000;
	if(b>=10&&b<100)n=100;
	if(b<10)n=10;
	a=a*n+b;
	for(int i=1;i*i<=a;i++)if(i*i==a){cout<<"Yes"<<endl;return 0;}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <typeinfo>
#include <cstring>
#include <utility>
#include <vector>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;


int main() {
    unsigned int x, y, z;
    cin >> x >> y >> z;

    cout << z << " " << x << " " << y << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

vector<vector<ll>>a(26);
int main() {
	string s,t;
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		ll now=s[i]-'a';
		a[now].push_back(i+1);
	}
	ll ans=0,now=0;
	bool out =false;
	for(int i=0;i<t.size();i++){
		ll sear=t[i]-'a';
		bool ch=false;
		auto Iter1 = upper_bound(a.at(sear).begin(),a.at(sear).end(), now);
		ll res =Iter1 -a[sear].begin();
		if(res!=a[sear].size()){
		    ll fi =a[sear][res];
				ans+=fi-now;
				now=fi;
				ch=true;
				out =false;
		}
		if(out){
			cout << -1;
			return 0;
		}
		if(ch!=true){
			i--;
			ans+=s.size()-now;
			now=0;
			out =true;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1724
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(X: int):
    a = 0
    b = 0
    while True:
        for x in [1, -1]:
            tmp = X + (x * b) ** 5
            if tmp < 0:
                continue
            t = int(tmp ** (1 / 5))
            if t ** 5 == tmp:
                print(t, x * b)
                return
        b += 1
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 62464
def Q(n,N):
    n = int(n)
    if (n<=N and str(n)<=str(N)) or (n>N and str(n)>str(N)):
        return "Y"
    else:
        return "N"
    
    
def main():
    import sys
    
    ans = ""
 
    #N = 5
    print("? "+"1"+"0"*10)
    sys.stdout.flush()
    A = input()
    if A=="Y":
        n = 1
        print("? "+"9"*n)
        sys.stdout.flush()
        A = input()
        while A == "N":
            n+=1
            print("? "+"9"*n)
            sys.stdout.flush()
            A = input()
        print("! "+str(10**(n-1)))
    else:
        l = 0
        r = 10
        S = [""]*11
        S[0] ="Y"
        S[10] ="N"
        while 1:
            m = (l+r)//2
            print("? "+str(10**m))
            sys.stdout.flush()
            A = input()
            if A=="Y":
                if S[m+1]=="N":
                    K = m+1
                    break
                S[m] = "Y"
                l = m
            else:
                if S[m-1]=="Y":
                    K = m
                    break
                S[m] = "N"
                r = m
                
        l = 1
        r = 9
        S = [""]*10
        S[9] ="Y"
        ashi = "9"*10
        print("? "+ans + str(1) + ashi)
        sys.stdout.flush()
        A = input()
        if A=="Y":
            ans += "1"
        else:
            S[1] = "N"
            while 1:
                m = (l+r)//2
                print("? "+ans + str(m) + ashi)
                sys.stdout.flush()
                A = input()
                if A=="Y":
                    if S[m-1]=="N":
                        ans += str(m)
                        break
                    S[m] = "Y"
                    r = m
                else:
                    if S[m+1]=="Y":
                        ans += str(m+1)
                        break
                    S[m] = "N"
                    l = m
            
        for i in range(K-1):
            ashi = "9"*(10-i)
            l = 0
            r = 9
            S = [""]*10
            S[9]= "Y"
            print("? " + ans + str(0) + ashi)
            sys.stdout.flush()
            A = input()
            if A=="Y":
                ans += "0"
            else:
                S[0] = "N"
                while 1:
                    m = (l+r)//2
                    print("? " + ans + str(m) + ashi)
                    sys.stdout.flush()
                    A = input()
                    if A=="Y":
                        if S[m-1]=="N":
                            ans += str(m)
                            break
                        S[m] = "Y"
                        r = m
                    else:
                        if S[m+1]=="Y":
                            ans += str(m+1)
                            break
                        S[m] = "N"
                        l = m
        print("! " + ans)
        
    
    
main()

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

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

using namespace std;

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	vector<double> sum(n+1);
	rep(i,n) sum[i+1]=sum[i]+(a[i]+1)/2.0;

	double ans=0;
	rep(i,n-k+1) ans=max(ans,sum[i+k]-sum[i]);
	printf("%.9f\n",ans);

	return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    int ans = 0;

    for(int i = 1; i <= 3; i++){
        if(a == i || b == i) continue;
        else{
            ans = i;
            break;
        }
    }   

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


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>
using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    if ((a+b)%2==1) {
        cout << "IMPOSSIBLE" << endl;
    }
    else {
        cout << abs((a+b)/2) << endl;
    }
}


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

A.sort()
cnt = [0] * (A[-1]+1)

for a in A:
  for i in range(a, A[-1]+1, a):
    cnt[i] += 1

ans = 0
for a in A:
  if cnt[a] == 1:
    ans += 1

print(ans)

Measured memory_bytes: 32308
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main() {
    string s;
    cin >> s;
    int del=0,ans=s.size()/2;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'S') del++;
        else if(del != 0){
            ans--;
            del--;
        }
    }
    cout << 2*ans << endl;
}

Measured memory_bytes: 640
import java.util.*;

/**
 * @author masayamatu
 * 
 */
public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] A= new int[n];
    double[] B = new double[n];
    double sum = 0;
    double ans = 0;
    for(int i = 0; i < n; i++) {
      A[i] = sc.nextInt();
      B[i]= (double)1/A[i];
      sum += B[i];
    }
    
    ans = 1/sum;
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
import java.util.*;
import java.math.*;
public class Main{
        public static void main(String args[])
        {

            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            for(int i=1;i<=9;i++){
                int x = n/i;
                int y = n%i;
                if(x<=9 && y==0){
                System.out.println("Yes");
                return;
                }
            }
            System.out.println("No");
        }
}


Measured memory_bytes: 22996