akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    long long int n,m,l,num,sum;
    scanf("%d %d %d",&n,&m,&l);
    int arr1[n][m];
    int arr2[m][l];
    long long int arr3[n][l];
    for (int i=0;i<n;i++){
        for (int j=0;j<m;j++){
            scanf("%lld",&num);
            arr1[i][j]=num;
        }
    }
    for (int i=0;i<m;i++){
        for (int j=0;j<l;j++){
            scanf("%lld",&num);
            arr2[i][j]=num;
        }
    }
    for(int i=0;i<l;i++){
        for (int j=0;j<n;j++){
            sum=0;
            for (int k=0;k<m;k++){
                sum+=arr1[j][k]*arr2[k][i];
            }
            arr3[j][i]=sum;

        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            if(j<l-1){printf("%lld ",arr3[i][j]);}
            if(j==l-1){printf("%lld\n",arr3[i][j]);}
        }
    }
    //printf("%d %d",arr3[0][0],arr3[1][2]);
    return 0;
}



Measured memory_bytes: 3360
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	
	final int N = 8;
	//matrix
	int[] row = new int[N];
	boolean[] col = new boolean[N];
	boolean[] dpos = new boolean[2*N-1];
	boolean[] dneg = new boolean[2*N-1];
	
	//input
	int k, r, c;
	
	public void input() {
		Arrays.fill(row, -1);
		k = sc.nextInt();
		for(int i=0; i<k; i++) {
			r = sc.nextInt();
			c = sc.nextInt();
			row[r] = c;
			col[c] = dpos[r+c] = dneg[r-c+N-1] = true;
		}
		recursive(0);
	}
	
	public void recursive(int i) {
		if(i == N) {
			output();
			return;
		}
		if(row[i] != -1) {
			recursive(i+1);
		}
		for(int j=0; j<N; j++) {
			if(row[i] !=-1 || col[j] || dpos[i+j] || dneg[i-j+N-1]) {
				continue;
			}
			row[i] = j;
			col[j] = dpos[i+j] = dneg[i-j+N-1] = true;
			recursive(i+1);
			row[i] = -1;
			col[j] = dpos[i+j] = dneg[i-j+N-1] = false;
		}
	}
	
	public void output() {
		for(int i=0; i<N; i++) {
			for(int j=0; j<N; j++) {
				if(row[i] == j) {
					System.out.print("Q");
				}else {
					System.out.print(".");
				}
			}
			System.out.println();
		}
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
	}
}



Measured memory_bytes: 26216
N,K = map(int,input().split())
h = []
for i in range(N):
  h.append(int(input()))
h.sort()
minh = h[K-1] - h[0]
for i in range(1,N-K+1):
  if minh>h[i+K-1]-h[i]:
    minh = h[i+K-1]-h[i]
  if minh == 0:
    print(0)
    exit()
print(minh)

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main(){
  int N; cin>>N;
  cout<<pow(N,3)<<endl;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


signed main(){
    int N;
    cin >> N;
    int i = 1, cnt = 0;
    while(i <= N){
        if(i < 10) cnt++;
        else if(100 <= i && i < 1000) cnt++;
        else if(10000 <= i && i < 100000) cnt++;
        i++;
    }
    PRINT(cnt);
    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<cstdio>
#include<cassert>
#include<sstream>
#include<set>

#define int long long int

using namespace std;

signed main(){
    int x; cin >> x;
    int s = 100, cnt = 0;
    while(s < x){
        cnt++;
        s = s + s / 100;
    }
    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define rev(a,b,c) for(int a=b;a>=c;a--)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define end end()
#define vec vector<ll>
#define se set<ll>
#define mults multiset<ll>
#define F first
#define S second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b
#define get(a) cin>>a
#define nextl cout<<endl
const ll mod = 1000000007;
const ll maxn = 500005;
const ll mm = 1e+18;
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}
ll ncr(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j] + C[j-1])%mod;
    }
    return C[k];
}
void solve()
{
    int n;
    get(n);
    string s;
    get(s);
    int ans=1;
    rep0(i,n-1){
        if(s[i]==s[i+1]) continue;
        else ans++;
    }
    //if(s[n-2]!=s[n-1]) ans++;
    pr(ans);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
       // nextl;
    }
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
int main(){
	int n,cur_min,cur,max_profit=-1024*1024*1024*2;
	scanf("%d%d",&n,&cur);
	cur_min=cur;
	for(int i=1;i<n;i++){
		scanf("%d",&cur);
		if(max_profit<cur-cur_min)max_profit=cur-cur_min;
		if(cur_min>cur)cur_min=cur;
	}
	printf("%d\n",max_profit);
}


Measured memory_bytes: 2756
# AtCoder Grand Contest 041
# A - Table Tennis Training

def f(A,B,n) :
    judge=B-A

    if judge%2==0 :
        n+=judge//2
        return(n)

    else :
        if abs(A-1) < abs(N-B) :
            if A==1 :
                A=A
                B-=1
                n+=1
            else:
                B-=A-1
                n+=A-1
                A-=A-1
            return f(A,B,n)
        else :
            if B==N :
                B=B
                A+=1
                n+=1
            else :
                A+=abs(N-B)
                n+=abs(N-B)
                B+=abs(N-B)
            return f(A,B,n)

N,A,B=map(int,input().split())
print(f(A,B,0))

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

int a[200010];
deque<int> dq,dq2;

signed main(){

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

  sort(a,a+n);
  dq.push_back(a[0]);
  int right = n-1,left = 1;
  int cnt = 1;
  for(int i = 0; i < n; i++){
    if((i&1) == 0){
      dq.push_front(a[right--]);
      cnt++; if(cnt == n) break;
      dq.push_back(a[right--]);
      cnt++; if(cnt == n) break;
    }
    else {
      dq.push_front(a[left++]);
      cnt++; if(cnt == n) break;
      dq.push_back(a[left++]);
      cnt++; if(cnt == n) break;
    }
  }

  dq2.push_back(a[n-1]);
  right = n-2,left = 0;
  cnt = 1;
  for(int i = 0; i < n; i++){
    if((i&1) == 1){
      dq2.push_front(a[right--]);
      cnt++; if(cnt == n) break;
      dq2.push_back(a[right--]);
      cnt++; if(cnt == n) break;
    }
    else {
      dq2.push_front(a[left++]);
      cnt++; if(cnt == n) break;
      dq2.push_back(a[left++]);
      cnt++; if(cnt == n) break;
    }
  }
  int ans = 0,ans2 = 0;
  for(int i = 0; i < n-1; i++){
    //cout << dq[i] << " ";
    ans += abs(dq[i+1]-dq[i]);
    ans2 += abs(dq2[i+1]-dq2[i]);
  }
  cout << max(ans,ans2) << endl;

  return 0;
}


Measured memory_bytes: 2688
k = int(input())
l = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
print(l[k-1])

Measured memory_bytes: 9380
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node {
  int key;
  struct Node *right,*left,*parent;
};

struct Node *root,*NIL;

struct Node *find(struct Node *u,int k){
  while( u!= NIL && k!=u->key){
    if(k<u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z =(struct Node*) malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if( z-> key < x-> key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;
  if( y == NIL){
    root = z;
  }
  else{
    if(z->key < y-> key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}

void inorder( struct Node *u){
  if(u == NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
    if(u == NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
  int n,i,x;
  char com[6];
  scanf("%d", &n);

  for(i = 0;i<n;i++){
    scanf("%s",com);
    if(com[0] == 'f'){
      scanf("%d", &x);
      struct Node *t = find(root,x);
      if(t!= NIL)printf("yes\n");
      else printf("no\n");
    }else if(strcmp(com,"insert") == 0){
      scanf("%d",&x);
      insert(x);
    }
    else if( strcmp(com,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 19364
def main():
    k = int(input())
    gcds = list(sorted([gcd(i, j) for i in range(1, k+1) for j in range(1, k+1)]))
    j = 0
    s = list(sorted(list(set(gcds))))
    m = k**2-1
    gcdss = [0]*len(s)
    flag = False
    for i, l in enumerate(s):
        while gcds[j] == l:
            gcdss[i] += 1
            if j == m:
                flag = True
                break
            j += 1
        if flag:
            break
    ans = sum([gcd(i, p)*n for i in range(1, k+1) for p, n in zip(s, gcdss)])
    print(ans)
            
    
def gcd(a, b):
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    else:
        return gcd(b, a%b)


if __name__ == "__main__":
    main()


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

int main()
{
	int n;
	string s;
	cin >> n >> s;
	int mx = 0;
	for( int i = 1; i < s.length()-1; i++ ) {
		int* score = (int *)malloc( s.length()*sizeof(int) );
		memset( score, 0, s.length()*sizeof(int) );
		
		int nc = 0;
		int j = 0;
		for( ; j < i; j++ ) {
			*(score+(s[j]-'a')) = 1;
		}
		for( ; j < s.length(); j++ ) {
			if( *(score+(s[j]-'a')) == 1 ) {
				*(score+(s[j]-'a')) = 2;
				nc++;
			}
		}
		free( score );
		if( mx < nc ) mx = nc;
	}
	cout << mx << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long int
#define lld double
#define vi vector<int>
#define pii pair<int,int>
#define piii pair<pii, ll>
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define ppb pop_back
#define d0(x) cout<<x<<" "
#define d1(x) cout<<x<<"\n"
#define d2(x,y) cout<<x<<" "<<y<<"\n"
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"
#define d5(x,y,z,w,s) cout<<x<<" "<<y<<" "<<z<<" "<<w<<" "<<s<<endl
using namespace std;
const ll mod = 1e9+7;
 

void init();
void solve(int T);
int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio ( false );cin.tie(0);cout.tie(0);
    int t1=1;
    init();
    //cin>>t1;
    for(int T=1;T<=t1;T++)
    {
        solve(T);
    }
}



void init()
{

}

ll po(ll a,ll m)
{
    if(m==0)return 1;
    ll x = po(a,m/2);
    x = (x*x)%mod;
    return m&1?(x*a)%mod:x;
}


ll N,K;ll inv[400001],fct[400001];

ll C(ll n, ll r)
{
    ll ret = (inv[r]*inv[n-r])%mod;
    return (ret*fct[n])%mod;
}



void solve(int T)
{
    cin>>N>>K;

    inv[0]=1;fct[0]=1;

    for(ll i=1;i<=2*N;i++)
    {
        inv[i] = (inv[i-1]*po(i,mod-2))%mod;
        fct[i] = (i*fct[i-1])%mod;
    }

    ll ans = 0;
    for(ll x = max(1LL,N-K);x<=N;x++)
    {
        ans = (ans+C(N,x)*C(N-1,x-1))%mod;
    }

    d1(ans);
}



Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

const ll MAX = 510010;
const ll MOD = 1000000007;
vector<ll> fac(MAX), finv(MAX), inv(MAX);
bool init_called = false;
//=============modinv============================
void COMinit() {
  init_called = true;
  fac.at(0) = 1;
  fac.at(1) = 1;
  finv.at(0) = 1;
  finv.at(1) = 1;
  inv.at(1) = 1;
  for (ll i = 2; i < MAX; i++){
    fac.at(i) = fac.at(i - 1) * i % MOD;
    inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inv.at(i) % MOD;
  }
}

ll COM(ll n, ll k){
  if (!init_called) {
    COMinit();
  }
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac.at(n) * (finv.at(k) * finv.at(n - k) % MOD) % MOD;
}
//=================================================


ll N, K;

int main()
{
  cin >> N >> K;
  ll M = COM(N + N - 1, N - 1);
  if (K >= N - 1) {
    cout << M << endl;
    return 0;
  }
  ll ans = 1;
  for (ll i = 1; i <= K; ++i) {
    ans = (ans + COM(N, i) * COM(N - 1, i) % MOD) % MOD;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
const double pi = 3.141592653589793;
int main(){
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++){
        if(i%d==0){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3620
import math
a, b, h, m = (int(x) for x in input().split())
min = h * 60 + m
angle1 = ((360 / 720) * min) * (math.pi / 180)
angle2 = ((360 / 60) * m) * (math.pi / 180)
angle = abs(angle1 - angle2)
length = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(angle))
print(length)

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

int main() {
  string n; cin >>n;
  int t = 0;
  for (int i : n) {
    t += (i-48); // magic number 0 -> 48
  }
  cout << ( (t%9==0) ? "Yes" : "No" ) << endl;
  return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll X, Y;
    cin>>X>>Y;
    ll count=1;
    while(true){
        if(X*2>Y) break;
        else{
            X*=2;
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}


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

int main(){
    int n; string s; cin >> n >> s;
    vector<vector<int>> dp(n,vector<int>(n,0));
    if(s[n-2] == s[n-1]) dp[n-2][n-1] = 1;
    for(int i = n - 2; i >= 0; i--){
        for(int j = n - 1; j > i; j--){
            if(s[i] != s[j]) continue;
            else if(j == n-1) dp[i][j] = 1;
            else dp[i][j] = dp[i+1][j+1] + 1;
        }
    }
    int ans = 0;
    rep(i,n) rep(j,n){
        if(dp[i][j] > ans && i + dp[i][j] - 1 < j) ans = dp[i][j];
    }
    cout << ans << endl;
}

Measured memory_bytes: 98176
num, time = gets.split.map(&:to_i)
time -= 1
foods = []
num.times { foods << gets.split.map(&:to_i) }
foods.sort!

# 許容重量ごとの価値の最大値を格納するdp（順次更新）
dp = Array.new(time + 1, 0)

ans = []

# 1個目からnum個目までの品物を、ナップサックに入れるべきか順番に確認する
1.upto(num) do |n|
  # n個目の時間をtmp_time、価値をtmp_valueとする
  tmp_time, tmp_value = foods[n - 1]
  # n個目を最後に食べたと仮定した時の総価値を保存
  ans << dp[time] + tmp_value
  # 許容時間がtimeからtmp_timeまでの場合を、順番に確認する
  # （許容時間がtmp_time未満の場合、ナップサックに入れることはできないため確認の必要なし）
  # なお、uptoを用いて逆向きに確認すると、ループ中に既に更新した数値を参照してしまうため、正常に動作しない
  time.downto(tmp_time) do |t_accepted|
    # 「許容時間がtmp_time分少ない時の価値 + tmp_value」が「現在格納されている値」よりも大きければ格納する
    if dp[t_accepted] < dp[t_accepted - tmp_time] + tmp_value
      dp[t_accepted] = dp[t_accepted - tmp_time] + tmp_value
    end
  end
end

# 最大値を出力する
puts ans.max


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

int main() {
    char c;
    cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
#define allsortg(v)sort(v.begin(),v.end(),greater<int>());
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int x, a, b;
	cin >> x >> a >> b;
	cout << (abs(x - a) < abs(x - b) ? "A" : "B") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define maxn 100005
#define ll long long
using namespace std;
char s[maxn*2];
int last[maxn*2][26],v[26];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for (int i=1;i<=n;i++)
	s[i+n]=s[i];
	for (int i=2*n;i>=0;i--){
		for (int j=0;j<26;j++)
		last[i][j]=v[j];
		if (i)v[s[i]-'a']=i;
	}
	scanf("%s",s+1);
	int m=strlen(s+1);
	int now=last[0][s[1]-'a'];
	ll ans=now;
	for (int i=2;i<=m;i++){
		if (!now) return printf("-1\n"),0;
		ans+=last[now][s[i]-'a']-now;
		now=last[now][s[i]-'a'];
		if (now>n) now-=n;
	}
	if (!now) ans=-1;
	printf("%lld\n",ans);
	return 0; 
} 

Measured memory_bytes: 20608
# encoding: utf-8
N = int(input())
a = list(map(int, input().split()))

a.sort()

ans = 0
for i, ai in enumerate(a):
    # init
    if i == 0:
        view = ai
        cnt = 0
    elif ai > view:
        if cnt > view: ans += cnt - view
        elif cnt < view: ans += cnt
        view = ai
        cnt = 0
    # count up
    cnt += 1
else:
    if cnt > view: ans += (cnt - view)
    elif cnt < view: ans += cnt

print(ans)


Measured memory_bytes: 14688
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = a; i < b + 1; i++){
    if (i < a + c || i > b - c)
      cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    ll ans = LINF;
    rep(i, 100005) {
        ll cost = c*i*2;
        cost += max(0, x-i)*a;
        cost += max(0, y-i)*b;
        ans = min(ans, cost);
    }

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

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		String[] s = new String[3];
		for (int i=0; i<3; i++) {
			s[i] = in.next();
		}

		int t = 0;
		int[] i = new int[3];
		String ans = "ABC";

		while (true) {
			if (i[t] == s[t].length()) {
				out.println(ans.charAt(t));
				break;
			}
			int nt = s[t].charAt(i[t]) - 'a';
			i[t]++;
			t = nt;
		}
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

using namespace std;

#define NMAX 1000

int main(){

	int n;
	string s[NMAX];
	int num[NMAX];

	while(1){

		cin>>n;
		if(n==0) break;

		for(int i=0;i<n;i++){
			cin>>s[i];
			num[i]=0;
			for(int j=0;j<s[i].size();j++){
				if(s[i][j]!='.') break;
				num[i]++;
			}
		}

		for(int i=0;i<n;i++){
			for(int j=0;j<num[i];j++){
				if(j+1==num[i]) s[i][j]='+';
				else{
					s[i][j]=' ';
					for(int k=i+1;k<n;k++){
						if(j+1==num[k]){
							s[i][j]='|';
							break;
						}
						if(j+1>num[k]||k==n-1) break;
					}
				}
			}
		}

		for(int i=0;i<n;i++){
			cout<<s[i]<<endl;
		}

	}
	return 0;
}

Measured memory_bytes: 1984
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  string S;
  cin>>S;
  
  if(S.size()==2){
    cout<<S<<endl;
  }
  else{
    reverse(S.begin(),S.end());
    cout<<S<<endl;
  }
}

Measured memory_bytes: 3568
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if ((x-r<0 || x+r>W)||(y-r<0||y+r>H)) {
		printf("No\n");
	}else if((x-r>=0&&x+r<=W)||(y-r>=0&&y+r<=H)) {
		printf("Yes\n");
	}
}

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

using namespace std;

const int N = 111;

int n, k;
int a[N];

int main() {
    if (fopen("A.inp", "r"))
    freopen("A.inp", "r", stdin),
    freopen("A.out", "w", stdout);
    cin >> n >> k;
    while (k--) {
        int x; cin >> x;
        while (x--) {
            int y; cin >> y;
            a[y]++;
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i++)
        res += a[i] == 0;
    cout << res;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using P = pair<int, int>;
using MATRIX = vector< vector<ll> >;
 
int N;
int a[1000000];
int b[1000001] = {0};
vector<int> v[1000001];

int prm[1000001];
void Eratosthenes(int N) {
  vector<bool> is_prime(N + 1);
  for(int i = 0; i<= N; i++) {
    is_prime[i] = true;
  }
  prm[1] = 1;
  for(int i = 2; i <= N; i++) {
    if(is_prime[i]) {
      prm[i] = i;
      for(int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
        prm[j] = i;
      }
    }
  }
}

int main() {
  cin >> N;
  int M = 0;
  rep(i, N) {
    cin >> a[i];
    M = max(M, a[i]);
  }
  Eratosthenes(M);
  // rep(i, M+1) {
  //   cout << prm[i] << " ";
  // }
  // cout << endl;

  bool f = false;
  rep(i, N) {
    int x = a[i];
     while(x != 1) {
      if(prm[x] != prm[x / prm[x]]) {
        b[prm[x]]++;
        if(b[prm[x]] >= 2) {
          f = true;
        }
        if(b[prm[x]] == N) {
          cout << "not coprime" << endl;
          return 0;
        }
      }
      x /= prm[x];
    }
  }
  if(f) cout << "setwise coprime" << endl;
  else cout << "pairwise coprime" << endl;
  return 0;
}

Measured memory_bytes: 38788
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


bool cmp(pair<int,int>p,pair<int,int>q) {
    // return p.first>q.first;//descending by first
    // return p.first<q.first;//ascending by first
    // return p.second>q.second;//descending by second
    return p.second<q.second;//ascending by second
}

// bool cmp(int p,int q) {
    // return p>q;//descending
    // return p<q;//ascending
// }


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    string s;
    cin>>s;
    int n=s.size();
    f1(i,n) {
        cout<<"x";
    }
    en
    
    // ()?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3632
#ABC084D
def main():
    import sys
    Q = int(sys.stdin.readline())
    LR = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]
    #print(LR)
    
    def calc(N):
        import math
        for i in range(3, int(math.sqrt(N))+1):
            while N % i==0:
                N =N//i
                return 0
        else:
            num = (N+1)//2
            #if num ==2:
                #return N
            for j in range(2, int(math.sqrt(num)+1)):
                while num % j==0:
                    num = num//j
                    return 0
            else:
                return N
    
     
    L = []
    for i in range(3, 10**5+1, 2):
        tmp = calc(i)
        if tmp !=0:
            L+=[tmp]
    #print(L)
    import bisect
    
    for row in LR:
        l = bisect.bisect_left(L, row[0])
        r = bisect.bisect_right(L, row[1])
        print(r-l)

if __name__=='__main__':
    main()

Measured memory_bytes: 17388
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto a=readln.split.to!(int[]);

  auto freq=new int[](n+1);
  int cnt=0;
  foreach(e; a){
    if(e>n) cnt++;
    else freq[e]++;
  }
  for(int i=1; i<=n; i++){
    if(i<freq[i]) cnt+=(freq[i]-i);
    else if(i>freq[i]) cnt+=freq[i];
  }

  writeln(cnt);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) stderr.write(e, " ");
  stderr.writeln();
}

Measured memory_bytes: 4432
use strict;
use warnings;
use 5.010;

use Data::Dumper;

my $line = <STDIN>;
chomp($line);

my ($n, $k) = split(/ /, $line);

my $h = read_split();


my $ok  = 0;
for my $height (@$h) {
    $ok++ if $height >= $k;
}
say $ok;



sub read_split {
    my $line    = <STDIN>;
    chomp($line);
    return [split(/ /, $line)];
}


Measured memory_bytes: 19456
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct X{
  char suit;
  int value;
};

struct X L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct X A[], int n, int left, int mid, int right ){
  int i,j,k;
  int n1 = mid -left,n2 = right - mid;
  for( i = 0 ; i < n1 ; i++ )L[i] = A[left + i];
  for( i = 0 ; i < n2 ; i++ )R[i] = A[mid + i];

  L[n1].value = SENTINEL;
  R[n2].value = SENTINEL;
  i = 0;
  j = 0;
  for( k = left ; k < right ; k++ ){
    if( L[i].value <= R[j].value ){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
    }
  }
}

void mergeSort( struct X A[], int n, int left, int right ){
  int mid;
  if( left + 1 < right ){
    mid = ( right + left ) / 2;
    mergeSort( A, n, left, mid );
    mergeSort( A, n, mid ,right );
    merge( A, n, left, mid, right );
  }
}

int partition( struct X A[], int n, int p, int r ){
  int i,j;
  struct X t,x;
  x = A[r];
  i = p - 1;
  for( j = p ; j < r ; j++ ){
    if(A[j].value <= x.value ){
      i++;
      t = A[i];
      A[i]= A[j];
      A[j] = t;
    }
  }
  t = A[i + 1];
  A[i + 1] = A[r];
  A[r] = t;

  return i + 1;
}

void quick( struct X A[], int n, int p, int r ){
  int q;
  if ( p < r){
    q = partition( A, n, p, r );
    quick( A, n, p, q - 1 );
    quick( A, n, q + 1, r );
  }
}

int main( void ){
  int n, i, a;
  struct X A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d",&n);

  for( i = 0 ; i < n ; i++ ){
    scanf("%s %d", S, &a);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = a;
  }
  mergeSort( A, n, 0, n );
  quick( B, n, 0, n - 1 );

  for( i = 0 ; i < n ; i++ ){
    if ( A[i].suit != B[i].suit )stable = 0;
  }

  if( stable == 1 )printf("Stable\n");
  else printf("Not stable\n");
  for( i = 0 ; i < n ; i++ ){
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}

Measured memory_bytes: 2952
#include<iostream>
#include<climits>
#include<cassert>
#include<algorithm>
#include<cassert>
#include<map>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

typedef long long ll;
typedef pair<ll,ll> pll;
const int N = 300000;
//bit1ÍaAbit2ÍÂð¦é
ll bit1[N+1],bit2[N+1];

//0©çiÜÅÌaðæ¾·é
ll sum(int i,ll *bit){
  ll s = 0;
  while(i > 0){
    s += bit[i];
    i -= i&-i;
  }
  return s;
}

//iÔÚÌlÉxðÁ¦é
void add(int n,int i,int x,ll *bit){
  while(i <= n){
    bit[i] += x;
    i += i&-i;
  }
}

/*
void test(){
  int n = 10000;
  int a[n];
  rep(i,n)bit1[i] = 0;
  rep(i,n)a[i] = rand()%100,add(n,i+1,a[i],bit1);
  rep(i,n){
    int sum1 = 0;
    rep(j,i+1)sum1 += a[j];
    cout << sum1 <<" " << sum(i+1,bit1) << endl;
    assert(sum1 == sum(i+1,bit1));
  }
 
}
*/

class st{
public:
  ll a,b;
  int index;
};


/*
  úoÊðîÉµÄ\[g·éBúoÊª¬³¢ûðDæ·é
  úoÊª¯¶ÍeÊª¬³¢ûðDæ·éi½ªÇ¿çÅà¢¢)
*/
bool cmp1(const st & in1,const st & in2){
  if (in1.a != in2.a)return in1.a < in2.a; 
  return in1.b < in2.b;
}

/*
  eÊðîÉ\[gB¬³¢ûðDæ·é
  eÊª¯¶ÈçúoÊªå«¢É\[g·é
 */
bool cmp2(const st & in1,const st & in2){
  if (in1.b != in2.b)return in1.b < in2.b;
  return in1.a > in2.a;
}

/*n <= 20*/
int bf(int n,vector<st> &in){
  int ans = 0;
  rep(i,(1<<n)){
    ll minb=INT_MAX;
    ll suma=0;
    int num = __builtin_popcount(i);
    rep(j,n){
      if ((1<<j&i) == 0)continue;
      minb = min(minb,in[j].b);
      suma += in[j].a;
    }
    if (num != 0 && suma <= minb * num){//ñªTõÌãÀðã°é
      ans = max(ans,num);
    }
  }
  return ans;
}

main(){
  int n;
  bit1[0] = 0;bit2[0] = 0;
  while(cin>>n && n){
    vector<st> in(n);
    rep(i,n){
      cin>>in[i].a>>in[i].b;
      bit1[i+1] = bit2[i+1] = 0;
    }
    sort(in.begin(),in.end(),cmp1);
    //úoÊ¸ÌÝÏaðvZµÄ¨­
    rep(i,in.size()){
      add(n,i+1,in[i].a,bit1);
      add(n,i+1,1,bit2);
      in[i].index = i;
    }

    /*
      eÊÌÅ¬lðßÅ¿·éB
      úoÊiÆ»Ì½ÏjÍP²Á·éæ¤É\[gµÄaðÆÁÄ¨¢½ÌÅAQªTõãÀðßé
    */
    sort(in.begin(),in.end(),cmp2);
    int ans = 0;
    rep(i,in.size()){
      int l = 1,r = n;
      int tmp = 0;
      while(l <= r){
	int mid = (l+r)/2;
	ll tsum = sum(mid,bit1);
	ll tnum = sum(mid,bit2);
	if (tsum <= in[i].b * tnum){//ñªTõÌãÀðã°é
	  tmp = max(tmp,(int)tnum);
	  l = mid+1;
	}else {//ñªTõÌãÀðº°é
	  r = mid-1;
	}
      }
      ans = max(ans,tmp);
      /*
	iÔÚÌEBXðbit©ç¸ç·
       */
      add(n,in[i].index+1,-in[i].a,bit1);
      add(n,in[i].index+1,      -1,bit2);
    }
    cout << ans << endl;
    /*
    int tmp = bf(n,in);
    if (ans != tmp){
      rep(i,n){
	cout << in[i].a <<" " << in[i].b << endl;
      }
      cout << ans <<" "<< tmp << endl;
      assert(false);
      }
    */
  }
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,tax1,tax2;
  cin>>a>>b;
  for(int i=0;i<1500;i++){
    tax1=i*0.08;
    tax2=i*0.1;
    if(tax1==a&&tax2==b){
      cout<<i;
      break;
      }
    if(i==1499){
      cout<<"-1"<<endl;
      }
    }
  return 0;
  }



Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    S = input()
    T = input()
    ans = 0
    for i in range(3):
        ans += S[i] == T[i]
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
n,m=map(int,input().split())
ans=[0]*m
ansnum=0
for i in range(n):
    list1=list(map(int,input().split()))
    for j in range(list1[0]):
        ans[list1[j+1]-1]+=1
for i in range(m):
    if ans[i]==n:
        ansnum+=1
print(ansnum)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int n;
    cin>>n;
    Vi d(n);
    REP(i,0,n) cin>>d[i];
 
    d.pb(0);
    d.pb(24);
    sort(ALL(d));
 
    REP(i,1,n+1){
        if(i%2==1){
            d[i] = 24-d[i];
        }
    }
    sort(ALL(d));
 
    int ans=INF;
    REP(i,1,n+2){
        chmin(ans,d[i]-d[i-1]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/*
 * 	The way if it's all predetermined
 * 		And the way i should go all my life
 * 			I swear to go wherever will be
 * 				'Cause there'll be something to see and to find
 */
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=2e18;
const int infi=1e9;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}


int powm(int a, int b) {
	a%=mod;
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		b>>=1;
		a=(a*a)%mod;
	}
	return res;
}

void solve() {
//	int n,a,b,c,d;
//	cin>>n>>a>>b>>c>>d;
//	string s;
//	cin>>s;
//	for(int i=a-1; i+1<c; i++) {
//		if(s[i]=='#'&&s[i+1]=='#') {
//			cout<<"No"<<endl;
//			return;
//		}
//	}
//	for(int i=b-1; i+1<d; i++) {
//		if(s[i]=='#'&&s[i+1]=='#') {
//			cout<<"No"<<endl;
//			return;
//		}
//	}
//	if(a>b) {
//		swap(a,b);
//		swap(c,d);
//	}
	string s;
	cin>>s;
	int ans=0,n=sz(s),cnt=0;
	for(int i=n-1; i>=0; i--) {
		if(s[i]=='A') {
			ans+=cnt;
		} else if(i>0&&s[i]=='C'&&s[i-1]=='B') {
			cnt++;
			i--;
		} else
			cnt=0;
	}
	cout<<ans<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 720
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = sc.nextInt();
		int k = sc.nextInt();
		Integer[] l = new Integer[n];
		int sum = 0;

		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
		}
		Arrays.sort(l, Collections.reverseOrder());

		for (int i = 0; i < k; i++) {
			sum += l[i];
		}

		System.out.println(sum);

	}
}

Measured memory_bytes: 21968
N = int(input())
A = [int(input()) for _ in range(N)]

if A[0] != 0:
  print(-1)
  exit()
  
ans = []
l = 0
for i in range(1, N):
  if A[i] > A[i - 1] + 1:
    print(-1)
    exit()
    
  if A[i] == A[i - 1] + 1:
    l = A[i]
  else:
    ans.append(l)
    l = A[i]
ans.append(l)
print(sum(ans))

Measured memory_bytes: 12456
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b;
    cin >> a >> b;
    
    if(a < b){
        cout << "a < b" << endl;
    }
    else if(a > b){
    cout << "a > b" << endl;
    }
    else{
        cout << "a == b" << endl;
    }
    
}



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
#include <cstdio>
using namespace std;


int main(void) {
	string S;
	cin >> S;
	int t;
	cin >> t;

	for (int i = 0; i < S.size(); i += t) {
		cout << S[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

int n, k, s;

vector<int> geta() {
	vector<int> a;
	int ss = s + 1;
	if (s == 1000000000) {
		ss = s - 1;
	}
	for (int i = 0; i < k; ++i) {
		a.push_back(s);
	}
	for (int i = k; i < n; ++i) {
		a.push_back(ss);
	}

	/*

	int res = 0;
	int *S = new int[n + 1];
	S[0] = 0;
	for (int i = 1; i <= n; ++i) {
		S[i] = S[i - 1] + a[i - 1];
	}
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j < i; ++j) {
			if (S[i] - S[j] == s) {
				++res;
			}
		}
	}
	cout << "res = " << res << endl;
	cout << (res == k) << endl;*/

	return a;
}
void print(vector<int> &a) {
	// vector<int> a;
	// a.clear();
	// a[0] = S[0];
	// for (int i = 1; i < S.size(); ++i) {
		// a[i] = S[i] - S[i - 1];
	// }
	for (int i = 0; i < a.size() - 1; ++i) {
		printf("%d ", a[i]);
	}
	printf("%d\n", a[n - 1]);
}
int main() {
	scanf("%d%d%d", &n, &k, &s);
	vector<int> a = geta();
	print(a);
	return 0;
}

Measured memory_bytes: 1784
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll x, y; cin >> x >> y;
  ll l = 2 * x;
  ll r = 4 * x;
  if(y >= l and y <= r and y % 2 == 0){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;

}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 100005
#define mid(l,r) l+(r-l)/2
using namespace std;
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(a>b)swap(a,b);if(!a)return b;return gcd(b%a,a);}
int n;
vector<pll>ed[N];
int vis[N];
void dfs(int i,int p,int c,int d){
	if(d%2)vis[i]=1-c;
	else vis[i]=c;
	for(pll j:ed[i]){
		if(j.fi==p)continue;
		dfs(j.fi,i,vis[i],j.se);
	}
}
void solve(){
	cin>>n;
	rep(i,n-1){
		ll u,v,w;
		cin>>u>>v>>w;
		ed[u].pb(pll(v,w));
		ed[v].pb(pll(u,w));
	}
	dfs(1,0,0,0);
	rep(i,n)cout<<vis[i+1]<<"\n";
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

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

int main(){
  int N, X, T;
  cin >> N >> X >> T;

  int time = 0;
  if (N%X == 0){
	time = T * (N/X);
  }
  else{
    time = T * ((N/X)+1);
  }
  cout << time << endl;
  return 0;
}

Measured memory_bytes: 3572