akhauriyash/Code-Regression huggingface dataset:
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
 #include <queue>
 #include <vector>
 #include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
////////////////いろいろあるよ//////////////////////////////////
int main(){
  char a,b,c;
  cin >> a >> b >> c;
  if(a=='7'||b=='7'||c=='7')cout << "Yes" << endl;
  else cout << "No" << endl;
  

}


Measured memory_bytes: 3632
n  = gets.to_i
a = gets.split(' ').map(&:to_i)
flag = 0
count = 0
a.each do |init_stat|
	flag = 1 if init_stat.to_i.odd?	
end
while(flag == 0)
	n.times do |j|
		a[j] = a[j]	/ 2	
	end
	a.each do |i|
		flag = 1 if i.to_i.odd?	
	end
	count += 1
end
puts count

Measured memory_bytes: 1788
fun main(arg: Array<String>) {
    val MOD = 998244353L
    val N = readLine()!!.toInt()
    val S = readLine()!!
    fun sa(A: Long, B: Long, C: Long): Long {
        val min = Math.min(B, C)
        val max = Math.max(B, C)
        return if (A <= min) min - A else if (A <= max) max - A else 0
    }
    var ans = 1L
    var cntA = 0L
    var cntB = 0L
    var cntC = 0L
    for (ch in S) {
        val r: Long
        if (ch == 'R') {
            r = sa(++cntA, cntB, cntC)
        } else if (ch == 'G') {
            r = sa(++cntB, cntA, cntC)
        } else {
            r = sa(++cntC, cntA, cntB)
        }
        ans = ans * (r + 1) % MOD
    }
    for (n in 1..N) ans = ans * n % MOD
    println(ans)
}


Measured memory_bytes: 36572
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n;
    cin >> n;
    int l,r;
    ll ans = 0;
    rep(i, n)
    {
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	ll x;
	cin >> x;
	ll ans = (x/11)*2;
	ll amari = x % 11;
	if(amari > 0 && amari <= 6) ans++;
	else if(amari > 0)ans += 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# 最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


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


N, M = map(int, input().split())
A = list(map(int, input().split()))
cnt = [0] * N
for i in range(N):
    a = A[i]
    while a % 2 == 0:
        a = a // 2
        cnt[i] += 1
if len(set(cnt)) != 1:
    print(0)
    exit()

x = A[0] // 2
for a in A[1:]:
    x = lcm(x, a // 2)
ans = M // x
print(ans - ans // 2)

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

int main() {
  int n;
  std::cin >> n;
  std::vector<int> b(n);
  std::vector<int> ans(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> b[i];
    --b[i];
  }
  for (int i = 0; i < n; ++i) {
    int upd = -1;
    for (int j = 0, p = 0; j < n; ++j) {
      if (b[j] < 0) continue;
	++p;
      if (b[j] == p - 1 && b[j] <= n - 1 - i) {
	upd = j;
      }
    }
    if (upd == -1) {
      std::cout << -1 << std::endl;
      return 0;
    } else {
      ans[n - 1 - i] = b[upd];
      b[upd] = -1;
    }
  }
  for (int i = 0; i < n; ++i) {
    std::cout << ans[i] + 1 << std::endl;
  }
  return 0;
}
 


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a[101]={100001},b[100],i,sum,bb;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d",&b[i]);
	}
	for(i=1;i<=n;i++){
		a[i]=100001;
	}
	for(i=1;i<n;i++){
		if(a[i]>b[i]){
			a[i]=b[i];
		}
		if(a[i+1]>b[i]){
			a[i+1]=b[i];
		}
	}
	sum=0;
	for(i=1;i<=n;i++){
		sum+=a[i];
	}
	printf("%d\n",sum);
	return 0;
}

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


int main(){

set<int>s;
s.insert( 1 );
s.insert( 3 );
s.insert( 5 );
s.insert( 7 );
s.insert( 8 );
s.insert( 10 );
s.insert( 12 );

int x,y;
cin>>x>>y;
if( s.find(x)!=s.end() && s.find(y)!=s.end() ){
    cout<<"Yes"<<endl;
    return 0;
    }

s.clear();
s.insert( 4 );
s.insert( 6 );
s.insert( 9 );
s.insert( 11 );
if( s.find(x)!=s.end() && s.find(y)!=s.end() ){
    cout<<"Yes"<<endl;
    return 0;
    }

cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll t; cin >> t;
    while(t--){
    	ll n; cin >> n;
    	ll k[n], l[n], r[n]; zep(i, 0, n)cin >> k[i] >> l[i] >> r[i];
    	
    	ll ans = 0, rb = n;
    	
    	map<ll, vector<ll>> mpr;
    	zep(i, 0, n){
    		if(l[i] < r[i]){
    			if(mpr.find(k[i]) == mpr.end())mpr[k[i]] = {};
    			mpr[k[i]].push_back(i);
    		}
    	}
 
		priority_queue<P> q;
		rep(i, 1, n){
			if(mpr.find(i - 1) != mpr.end()){
				auto v = mpr[i - 1];
				zep(j, 0, v.size())q.push(P(r[v[j]] - l[v[j]], v[j]));
			}
			
			if(!q.empty()){
				//print(q.top().second)
    			ans += r[q.top().second];
    			q.pop();
    			rb--;
    		}
		}
		
		if(mpr.find(n) != mpr.end()){
			auto v = mpr[n];
			zep(j, 0, v.size())q.push(P(r[v[j]] - l[v[j]], v[j]));
		}
		
		while(!q.empty()){
			//print(q.top().second)
    		ans += l[q.top().second];
    		q.pop();
    	}
 
    	map<ll, vector<ll>> mpl;
    	zep(i, 0, n){
    		if(l[i] > r[i]){
    			if(mpl.find(k[i]) == mpl.end())mpl[k[i]] = {};
    			mpl[k[i]].push_back(i);
    		}
    	}
    	
    	rrep(i, n, rb + 1){
    		if(mpl.find(i) != mpl.end()){
				auto v = mpl[i];
				zep(j, 0, v.size()){
					q.push(P(l[v[j]] - r[v[j]], v[j]));	
				}
			}
    	}
    	
    	rrep(i, rb, 1){
    		if(mpl.find(i) != mpl.end()){
				auto v = mpl[i];
				zep(j, 0, v.size()){
					q.push(P(l[v[j]] - r[v[j]], v[j]));	
				}
			}
    		
    		if(!q.empty()){
    			//print(q.top().second)
    			ans += l[q.top().second];
    			q.pop();
    		}
    	}
    	
    	while(!q.empty()){
    		//print(q.top().second)
    		ans += r[q.top().second];
    		q.pop();
    	}
    	
    	zep(i, 0, n)if(l[i] == r[i])ans += l[i];
    	
    	print(ans)
    }
    
    return 0;
}

Measured memory_bytes: 25996
#include<iostream>
#include<climits>

using namespace std;

int main(){
    long n;
    cin >> n;
    long min_cap = LONG_MAX;
    for (int i  = 0; i < 5; i++){
        long a;
        cin >> a;
        min_cap = min(min_cap, a);
    }
    cout << 4 + (n + min_cap - 1)/min_cap << endl;
}

Measured memory_bytes: 888
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

  as := map[int]bool{}
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		as[a] = !as[a]
	}

	ans := 0
	for _, b := range as {
		if b {
			ans++
		}
	}

	fmt.Print(ans)
}


Measured memory_bytes: 6912
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){


string S,A;
cin >> S;

if( S[0] == 'S'){
	cout << "Cloudy";
}
else if(S[0] == 'C'){
	cout << "Rainy";
}
else{
	cout << "Sunny";
}






	return 0;

}



Measured memory_bytes: 3452
from collections import deque
N,ppl,oni = map(int,input().split())
ppl -= 1
oni -= 1
AB = [ []for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    AB[a-1].append(b-1)
    AB[b-1].append(a-1)

def dfs(start):
    dist = [-1 for i in range(N)]
    dist[start] = 0
    que = deque()
    que.append(start)
    while que:
        q = que.popleft()
        for nextr in AB[q]:
            if dist[nextr] == -1:
                dist[nextr] = dist[q] +1
                que.append(nextr)
    return dist
    
if len(AB[ppl]) == 1 and oni in AB[ppl]:
    print(0)
else:
    ppldist = dfs(ppl)
    onidist = dfs(oni)
    maxa = max(onidist)
    ans = 0
    for i in range(N):
        if ppldist[i] < onidist[i]:
            ans = max(ans,onidist[i]-1)
    print(ans)

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

int main()
{
    char word[1003];
    int word_num = 0;

    scanf("%s", word);

    word_num = strlen(word);

    if (word[word_num - 1] == 's')
    {
        strcat(word, "es");
    } else {
        strcat(word, "s");
    }

    printf("%s", word);

    return 0;
}

Measured memory_bytes: 1736
def resolve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    import bisect
    import collections
    colormax = collections.deque([A[0]])
    for i in range(1, N):
        idx = bisect.bisect_left(colormax, A[i])
        if idx == 0:
            colormax.appendleft(A[i])
        else:
            colormax[idx-1] = A[i]
    print(len(colormax))



if '__main__' == __name__:
    resolve()

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

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

const int mx=15;
bool conn[mx][mx];

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,m; cin>>n>>m;
	for (int i=0; i<m; i++) {
		int x,y; cin>>x>>y;
		conn[x][y]=conn[y][x]=true;
	}
	vector<int> p(n);
	for (int i=1; i<=n; i++)
		p[i-1]=i;
	int ret=0;
	do {
		bool ok=p[0]==1;
		for (int i=1; i<n; i++)
			if(!conn[p[i-1]][p[i]])
				ok=false;
		if(ok) ret++;
	} while(next_permutation(p.begin(),p.end()));
	cout<<ret<<"\n";
	return 0;
}

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

const int MAX_N = 100010;
const int inf = 1000000000;
int N;
int h[MAX_N];

vector<int> dp(MAX_N, inf);

int rec(int x) {
  if (dp[x] != inf) return dp[x];
  int res;
  if (x == 0) res = 0;
  else if (x == 1) res = abs(h[1] - h[0]);
  else {
    res = min((rec(x-2) + abs(h[x] - h[x-2])), (rec(x-1) + abs(h[x] - h[x-1])));
  }
  return dp[x] = res;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> h[i];
  cout << rec(N-1) << endl;
}


Measured memory_bytes: 5760
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func solve(s string, t string, a int64, b int64, u string) (int64, int64) {
	if u == s {
		a -= 1
	} else {
		b -= 1
	}
	return a, b
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	s := next()
	t := next()
	a := nextInt()
	b := nextInt()
	u := next()
	resA, resB := solve(s, t, a, b, u)
	fmt.Fprintln(out, resA, resB)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes(n int64) []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
void solve(){
    int n;
    cin>>n;
    string str;
    set<string>s;
    for(int i=0;i<n;i++){
        cin>>str;
        s.insert(str);
    }
    cout<<s.size();
}
int  main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 19216
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

const int maxn = 2e5 + 5;
int cnta[maxn], cntb[maxn], a, ya[maxn];

struct Zip {
	int id, num;
	
	Zip(int id=0, int num=0) : id(id), num(num) {}
	
	bool operator<(Zip op) {
		return num > op.num;
	}
};

vector<Zip> za;
queue<Zip> Q;
vector<int> c;

int main() {
	int n;
	cin >> n;
	memset(cnta, 0, sizeof(cnta));
	memset(cntb, 0, sizeof(cntb));
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a);
		cnta[a]++;
		ya[i] = a;
	}
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a);
		cntb[a]++;
	}
	bool flag = true;
	for (int i = 1; i <= n; ++i) {
		if (cnta[i]) za.push_back(Zip(i, cnta[i]));
		if (cntb[i]) Q.push(Zip(i, cntb[i]));
		if (cnta[i] + cntb[i] > n) {
			flag = false;
			break;
		}
	}
	if (!flag) {
		printf("No\n");
		return 0;
	}
	Zip x = Q.front(); Q.pop();
	for (int i = 0; i < za.size(); ++i) {
		if (x.id == za[i].id || x.num == 0) {
			if (x.num) Q.push(x);
			x = Q.front(); Q.pop();
		}
		while (za[i].num) {
			if (x.id == za[i].id) {
				Q.push(x);
				x = Q.front(); Q.pop();
			}
			za[i].num--;
			x.num--;
			c.push_back(x.id);
			if (x.num == 0) {
				x = Q.front();
				Q.pop();
			}
		}
	}
	printf("Yes\n");
	for (int L = 0, R = n-1; L < R; --R) {
		if (ya[R] == c[R]) {
			while (c[L] == ya[R]) L++;
			swap(c[L], c[R]);
		}
	}
	for (int i = 0; i < n; ++i)
		printf("%d ", c[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 10680
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
string s;
int main(){
    cin>>s;
    if(s[0]=='A'){a=1;s[0]='a';}
    for(int i=2;i<s.length()-1;i++){
        if(s[i]=='C'){b=1;s[i]='c';break;}
    }
    for(int i=0;i<s.length();i++){
        if(s[i]>='A'&&s[i]<='Z'){c=1;}
    }
    if(a==1&&b==1&&c==0){
        cout<<"AC"<<endl;
    }else {
        cout<<"WA"<<endl;
    }


}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

#[allow(dead_code)]
fn solve(W: usize, H: usize, ps: &[(usize, usize, usize)]) -> usize {
    let mut g = vec![vec![1; H]; W];
    for &(pw, ph, pa) in ps {
        match pa {
            1 => {
                for w in 0..pw {
                    for h in 0..H {
                        g[w][h] = 0;
                    }
                }
            },
            2 => {
                for w in pw..W {
                    for h in 0..H {
                        g[w][h] = 0;
                    }
                }
            }
            3 => {
                for w in 0..W {
                    for h in 0..ph {
                        g[w][h] = 0;
                    }
                }

            },
            4 => {
                for w in 0..W {
                    for h in ph..H {
                        g[w][h] = 0;
                    }
                }
            }
            _ => panic!()
        }
    }
    let mut res = 0;
    for w in 0..W {
        for h in 0..H {
            if g[w][h] == 1 {
                res += 1;
            }
        }
    }
    res
}



fn main() {
    input! {
    W: usize,
    H: usize,
    N: usize,
    ps: [(usize, usize, usize); N],
    };

    println!("{}", solve(W, H, &ps));
}


Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<functional>
#include<cstring>
using namespace std;
int dp[114514],tensu[114],sum=0;
int main(void)
{
	int i,j,k,n,youso=0;
	cin>>n;
	for(i=0;i<n;i++) {
		cin>>tensu[i];
	}
	for(i=0;i<n;i++) dp[i]=0;
	dp[0]=1;
	for(i=0;i<n;i++) {
		for(j=10000;j>=0;j--) {
			if(j-tensu[i]>=0&&dp[j-tensu[i]]==1) {
				dp[j]=1;
			}
		}
	}
	int mx=0;
	for(i=0;i<=10000;i++) {
		if(i%10!=0&&dp[i]==1) {
			mx=max(mx,i);
		}
	}
	/*for(i=0;i<=100;i++) {
		cout<<i<<":"<<dp[i]<<" ";
	}*/
	cout<<mx<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin >>a>>b>>c;
	for(int i=1;i<=b;i++)
		if(a*i%b==c){
			cout << "YES" << endl;
			goto OUT;
		}
	cout << "NO" << endl;
	OUT:;
}


Measured memory_bytes: 256
// 154 B

#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include<algorithm>

using namespace std;

int main(){
    long int n, tmp;
    cin >> n;
    vector<int> v(n, 0), num_list(n, 0);
    for(long int i=1; i<n; i++){
        cin >> tmp;
        v.at(i) = tmp;
    }
    for(long int i=1; i<n; i++){
        num_list.at(v.at(i)-1)++; 
    }
    for(long int i=0; i<n; i++){
        cout << num_list.at(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 4792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define Rep(i,a,n) for(int i = a;i<n;i++)
#define ll long long  
const long long MOD = 1000000007LL;
ll zyubeki(int n){
    ll a= 1;
    rep(i,n){
        a = a*10;
    }
    return a;
}
bool sitihantei(long long n){
    bool fl1,fl2,fl3;
    fl1 = fl2 = fl3 = false;
    while(n!=0){
        if(n%10 == 3){
            fl1 = true;
            n = n/10;
        }
        else if(n%10 == 5){
            fl2 = true;
            n = n/10;
        }
        else {
            fl3 = true;
            n = n/10;
        }
    }
    if(fl1 && fl2 && fl3){
        return true;
    }
    else{
        return false;
    }
}
int main(){
    ll n;
    cin >> n;
    vector<ll> siti = {3,5,7};
    ll t;
    int ans = 0;
    rep(i,10){
        t = siti.size();
        rep(j,t){
            if(siti[j] > zyubeki(i) ){
                siti.push_back(siti[j]*10+3);
                siti.push_back(siti[j]*10+5);
                siti.push_back(siti[j]*10+7);
            }
        }
    }
    rep(i,pow(3,10)){
        if(siti[i] > n){
            break;
        }
        else{
            if(sitihantei(siti[i])){
                ans++;
            }
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	ll a = 0, b = 0, c = 0;
	string s; cin >> s;
	ll cnt = 1;
	for( char t : s ){
		if( t == 'A' ) a += cnt;
		else if( t == 'B' ) b += a;
		else if( t == 'C' ) c += b;
		else {
			c = 3*c + b;
			b = 3*b + a;
			a = 3*a + cnt;
			cnt *= 3;
		}
		a %= mod; b %= mod; c %= mod; cnt %= mod;
	}
	cout << c << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int a,b; 
int main(){
	a=read(),b=read();
	cout<<max(a+b,max(a-b,a*b))<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int count=0;
		long min=Long.MAX_VALUE;
		long sum=0;
		for(int i = 0; i<n; i++){
			long a = sc.nextLong();
			if(a<0){
				count++;
				a=-a;
				sum+=a;
			}else{
				sum+=a;
			}
			if(min>a){
				min=a;
			}
		}
		if(count%2==1){
			System.out.println(sum-2*min);
		}else{
			System.out.println(sum);
		}
	}
}


Measured memory_bytes: 48392
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		
		// 計算
		int result = 0;
		result = (x-z)/(y+z);
		
		// 出力
		System.out.println(result);
	}
}




Measured memory_bytes: 21844
#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 sz(x) (int)(x).size()
#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 newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
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;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

map<ll,int> Pfact(ll num) {
    map<ll,int> res;
    for (ll i = 2; i * i <= num; i++) {
        int cnt = 0;
        while (num % i == 0) {
            cnt++;
            num /= i;
        }
        if (cnt) res[i] = cnt;
    }
    if (num != 1) res[num] = 1;
    return res;
}
  
int main() {
  ll N;
  cin >> N;
  auto r = Pfact(N);
  int ans = 0;
  for(auto p:r) {
    int cnt=0;
    while(cnt*(cnt+1)/2<=p.second) cnt++;
    cnt--;
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,p=0;
    cin>>n;
    string a;
    cin>>a;
    for(int i=0;i<n-2;i++){
        if(a[i]=='A' && a[i+1]=='B' and a[i+2]=='C')p++;
    }
    cout<<p;
}

Measured memory_bytes: 256
n=int(input())
s=list(input())
cnt=s[1:].count("E")
e_cnt=[0]*(n+1)
w_cnt=[0]*(n+1)
e_cnt[0]=cnt
for i in range(n):
    w_cnt[i+1]=w_cnt[i]+(s[i]=="W")#Wの数を累積和でとる
for i in range(1,n):
    e_cnt[i]=e_cnt[i-1]-(s[i]=="E")#Eの数を累積和でとる
ans=float("inf")
for i in range(n):
    ans=min(ans,w_cnt[i]+e_cnt[i])
print(ans)


Measured memory_bytes: 29328
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,X,G;cin>>N>>X;int x[N];
  for(int i=0;i<N;i++){
    cin>>x[i];x[i]=abs(x[i]-X);
  }
  G=x[0];
  for(int i=1;i<N;i++)G=__gcd(G,x[i]);
  cout<<G<<endl;
}

Measured memory_bytes: 640
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: u32 = read(&mut stdin_lock, &mut buf, b' ');
    let m: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut mv = vec![0u32; m];
    for i in 0..m {
        let k: usize = read(&mut stdin_lock, &mut buf, b' ');
        let mut bits = 0;
        for _ in 0..k - 1 {
            bits |= 1 << (read::<u16>(&mut stdin_lock, &mut buf, b' ') - 1);
        }
        bits |= 1 << (read::<u16>(&mut stdin_lock, &mut buf, b'\n') - 1);
        mv[i] = bits;
    }
    let mut pv = vec![0u32; m];
    for i in 0..m - 1 {
        pv[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    pv[m - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    let ans = (0..2u32.pow(n))
        .filter(|i| (0..m).all(|j| ((mv[j] & i).count_ones() % 2) == pv[j]))
        .count();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cmath>
#include<cstring>
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
//_builtin_popcount
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)

#define gap cout<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
const double pi=3.141592653589793238;
const double multi=(double)180/pi;
double tan_inv(double p,double b){
	double tmp;
	tmp=p/b;
	tmp=atan(tmp);
	tmp=tmp*multi;
	return tmp;
}

int main(){
	
	double a,b,x;
	cin>>a>>b>>x;
	double h=b;
	double ans;
	double tmp1=(double)(a*a*b)/(double)2;
    if(tmp1>=x){
    	double xi=(double)2*x/(h*a);
    	ans=tan_inv(h,xi);
    }
    else{
    	double hi=(double)2*x/(a*a)-(double)h;
    	 ans=tan_inv(h-hi,a);
    	 

    }

    cout<<setprecision(11);
    cout<<ans<<endl;
}

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

#define ll long long
#define ld long double

int n, k;
int a[100001];
int dp[100001];

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    cin >> n >> k;
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++) dp[i] = INT_MAX / 2;
    dp[0] = 0;
    for(int i=0;i<n;i++) {
        for(int j=1;j<=k;j++) {
            if(i >= n - j) continue;
            dp[i+j] = min(dp[i+j], dp[i] + abs(a[i+j] - a[i]));
        }
    }
    cout << dp[n-1] << '\n';
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

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

    sort(a.begin(), a.end());

    for (int i = n - 1; i > 0; i--) {
        if (a[i] == a[i - 1]) {
            for (int j = i - 2; j > 0; j--) {
                if (a[j] == a[j - 1]) {
                    cout << (int64_t)a[i] * a[j] << endl;
                    quick_exit(0);
                }
            }
        }
    }

    cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

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

 for (int i = 0; i < k; ++i)
 {
  if(i%2==0){
   if(a%2!=0 && i!=k-1){
    a--;
  }
    a=a/2;
    b+=a;
  }else{
  if(b%2!=0 && i!=k-1){
    b--;
  }
    b=b/2;
    a+=b;
  }
}
cout<<a<<" "<<b<<endl;
return 0;
}   

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

char ch;
string A = "abcdefghijklmnopqrstuvwxyz";

signed main(){
    cin >> ch;
    for(int i=0;i<26;i++) {
        if(ch==A[i]) cout << A[i+1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
//
//  main.cpp
//  A - Kaiden
//
//  Created by wenhan on 2017/11/26.
//  Copyright © 2017年 wenhan. All rights reserved.
//

#include <iostream>
#include <cmath>
using namespace std;
int main() {
    long long k,a,b;
    cin>>k>>a>>b;
    if(k==0)
        cout<<0<<endl;
    else if(a<=b&&k-a>0)
        cout<<-1<<endl;
    else{
         long long s,t=1;
        if(k-a>0){
            s=k-a;
            t+=2*(s/(a-b));
            if(s%(a-b)!=0)
                t+=2;
        }
        cout<<t<<endl;
    }
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


Measured memory_bytes: 256
/* Sort I - Selection Sort */

#include <stdio.h>

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

  int a[N];
  for ( i = 0; i < N; i++ )
    scanf( "%d", &a[i] );

  int swapCount = 0;
  for ( i = 0; i < N; i++ ) {
    int mini = i;
    for ( j = i; j < N; j++ )
      if ( a[j] < a[mini] )
        mini = j;
    if ( i != mini ) {
      int tmp;
      tmp = a[i];
      a[i] = a[mini];
      a[mini] = tmp;
      swapCount++;
    }
  }

  for( i = 0; i < N - 1; i++ )
    printf( "%d ", a[i] );
  printf( "%d\n", a[N - 1] );
  printf( "%d\n", swapCount );

  return 0;
}

Measured memory_bytes: 600
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    H, W = Scanner.map_int()
    S = Scanner.string_list(H)
    dp = [[0 for _ in range(W)] for _ in range(H)]
    if S[0][0] == '#':
        dp[0][0] = 1
    for w in range(W - 1):
        dp[0][w + 1] = dp[0][w] + (S[0][w + 1] != S[0][w])
    for h in range(H - 1):
        dp[h + 1][0] = dp[h][0] + (S[h + 1][0] != S[h][0])
    for h in range(H - 1):
        for w in range(W - 1):
            s = dp[h][w + 1] + (S[h + 1][w + 1] != S[h][w + 1])
            t = dp[h + 1][w] + (S[h + 1][w + 1] != S[h + 1][w])
            dp[h + 1][w + 1] = min(s, t)

    print(Math.round_up(dp[H - 1][W - 1], 2))


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 5272
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long w = sc.nextInt();
        long h = sc.nextInt();
        long x = sc.nextInt();
        long y = sc.nextInt();
        System.out.print(((w*h)/2d)+" ");
        if (w==2*x&&h==2*y)System.out.println(1);
        else System.out.println(0);
    }
}


Measured memory_bytes: 38360
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const ll MOD=998244353;

int N;
int D[100005];
void input(){
    cin>>N;
    rep(i,N)cin>>D[i];
}

ll ct[100005];
void solve(){
    bool nz=true;
    rep1(i,N-1)if(D[i]==0)nz=false;

    if(D[0]!=0)cout<<0<<endl;
    else if(!nz)cout<<0<<endl;
    else{
        ll ans=1;
        int mx=0;
        rep1(i,N-1)mx=max(mx, D[i]);
        rep(i,N)ct[D[i]]++;
        rep1(i,mx){
            rep(_,ct[i])ans=(ans*ct[i-1])%MOD;
        }
        cout<<ans<<endl;
    }
}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 1408
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

long MOD = 10^^9+7;

void main()
{
    auto hw = readln.split.to!(int[]);
    auto H = hw[0];
    auto W = hw[1];

    wchar[][] MAP;
    long[][] MEMO;
    MAP.length = H;
    MEMO.length = H;
    foreach (i; 0..H) {
        MAP[i] = readln.chomp.to!(wchar[]);
        MEMO[i].length = W;
        MEMO[i][] = -1;
    }

    long solve(int x, int y) {
        if (x < 0 || x >= W || y < 0 || y >= H) return 0;
        if (x == W-1 && y == H-1) return 1;
        if (MAP[y][x] == '#') return 0;
        if (MEMO[y][x] != -1) return MEMO[y][x];
        return MEMO[y][x] = (solve(x+1, y) + solve(x, y+1)) % MOD;
    }

    writeln(solve(0, 0));
}

Measured memory_bytes: 15612
main(q){
	for(;scanf("%d",&q),~q;){
		double x=q/2.0;
		while(fabs(x*x*x-q)>q*1e-5)	x-=(x*x*x-q)/(3*x*x);
		printf("%f\n",x);
	}
	exit(0);
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<long long> v(N);
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }
    long long ans = 0;
    for (int i = 0; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            int num = i + (N - j);
            if (num > K) continue;
            int cnt = K;
            priority_queue<int, vector<int>, greater<int>> que;
            for (int r = 0; r < i; r++) {
                que.push(v[r]);
                cnt--;
            }
            for (int l = j; l < N; l++) {
                que.push(v[l]);
                cnt--;
            }
            long long sum = 0;
            for (int k = 0; k < cnt; k++) {
                if (!que.empty() && que.top() < 0) {
                    que.pop();
                }
            }
            while (!que.empty()) {
                sum += que.top();
                que.pop();
            }
            ans = max(sum, ans);
        }
    }
    if (K >= N) {
        long long sum = accumulate(v.begin(), v.end(), 0);
        sort(v.begin(), v.end());
        for (int i = 0; i < K - N && i < N; i++) {
            if (v[i] < 0) sum += abs(v[i]);
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

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

    ll sum = 0;
    int x = 1e4;
    bool y;
    REP(i,N){
        sum += L+i;
        if(x > abs(L+i)){
            x = abs(L+i);
            if(L+i >= 0){
                y = true;
            }
            else{
                y = false;
            }
        }
    }

    ll ans = 0;
    if(y){
        ans = sum - x;
    }
    else{
        ans = sum + x;
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
//typedef pair<int, int> P;

int main()
{
    string a;
    cin>>a;
    int n=a.size();
    ll cnt=1;
    vector<int>al(26);
    rep(i,n){
        int t=a[i]-'a';
        al[t]++;
    }
    ll sum=accumulate(all(al),0);
    rep(i,n){
        int t=a[i]-'a';
        sum--;
        al[t]--;
        cnt+=sum-al[t];
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		char[] charArray = str.toCharArray();
		for(int i=str.length()-1;i>=0;i--) {
			System.out.print(charArray[i]+"");
		}
		System.out.println();
	}

}


Measured memory_bytes: 26012
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

string sa, sb;
int i = 0, w = 0; 
long long ans = 0;

int main()
{
	
	ios::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  
  cin >> sa >> sb;
  int len = sa.length();
  while (sb.length() != 0)
  {
  	char c = sb[w]; w++; 
  	string slq = sa.substr(i);
  	string slh = sa.substr(0, i);
  	int posq = slq.find(c);
  	int posh = slh.find(c);
  	if (posq != -1)
  	{
  		i = slh.length() + posq + 1;
  		ans += posq + 1;
  		i %= len;
		}
		else if (posh != -1)
		{
			int p = slq.length() + posh + 1;
			i = posh + 1;
			ans += p;
		}
		else
		{
			puts("-1");
			return 0;
		}
		if (w == sb.length())
		{
			cout << ans << endl;
			return 0;
		}
	}
	  
  return 0;
  
}


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

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

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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    int minus = 0, plus = 0;
    for (int i = 0; i < n; ++i) {
        if(v[i] < 0) minus++;
        else plus++;
    }
    sort(v.begin(),v.end());
    if(minus == n) minus--, plus++;
    if(plus == n) plus--, minus++;
    vector<int> P, M, A;
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if(i < minus) {
            M.emplace_back(v[i]);
            ans += -v[i];
        } else {
            P.emplace_back(v[i]);
            ans += v[i];
        }
    }
    cout << ans << "\n";
    ll k = M[0];
    for (int i = 0; i < plus-1; ++i) {
        cout << k << " " << P[i] << "\n";
        k -= P[i];
    }
    cout << P[plus-1] << " " << k << "\n";
    k = P[plus-1]-k;
    for (int i = 0; i < minus-1; ++i) {
        cout << k << " " << M[i+1] << "\n";
        k -= M[i+1];
    }
    return 0;
}

Measured memory_bytes: 2808
//コンパイラ最適化用
#pragma GCC optimize("Ofast")

//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//INT_MAXなど
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

// clang++ main.cc -std=c++11 -stdlib=libc++

/*
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
*/

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

  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  sort(A.begin(), A.end());

  int res = 0;
  for (int i = 0; i < N; i++) {
    if (X >= A[i]) {
      X -= A[i];
      res++;
    } else {
      X = 0;
      break;
    }
  }

  if (res != 0 && X != 0)
    res -= 1;

  cout << res << endl;


  return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
int main() {
    string a;
    cin >> a;
    if (a.size()==3){
        cout << a[2] << a[1] << a[0] << endl;
        return 0;
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
import itertools
def I(): return int(input())
def LI(): return list(map(int,input().split()))
k = I()
rc = [LI() for _ in range(k)]
for a in itertools.permutations(range(8)):
    XY = [[x,y] for x,y in enumerate(a)]
    if len(set([x+y for x,y in XY])) !=8 or len(set([x-y for x,y in XY])) !=8:
        continue
    count = 0
    for r,c in rc:
        if [r,c] in XY:
            count += 1
    if count !=k:
        continue
    board = [['.' for _ in range(8)] for _ in range(8)]
    for x,y in XY:
        board[x][y] = 'Q'
    break
for b in board:
    print(*b,sep='')


Measured memory_bytes: 5660
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int hyou[100][3];
	int a;
	int b;
	int c = 0;
	int kari[2];
	int p = 1;
	char d;
	while(1) {
		cin  >> a >> d >> b;
		if (a == 0 && b == 0) {
			break;
		}
		hyou[c][0] = a;
		hyou[c][1] = b;
		c++;
	}
	
	for (int i = c-1; i >= 1; i--) {
		for (int j = 0; j <i; j++) {
			if(hyou[j][1] < hyou[j+1][1]) {
				kari[0] = hyou[j][0];
				kari[1] = hyou[j][1];
				hyou[j][0] = hyou[j+1][0];
				hyou[j][1] = hyou[j+1][1];
				hyou[j+1][0] = kari[0];
				hyou[j+1][1] = kari[1];
			}
		}
	}

	for (int i = 0; i < c-1; i++) {
		hyou[i][2] = p;
		if (hyou[i][1] > hyou[i+1][1]) {
			p++;
		}
	}
	hyou[c-1][2] = p;
	
	while (cin >> a) {
		for (int i = 0; i < c; i++) {
			if (hyou[i][0] == a) {
				cout << hyou[i][2] << endl;
				break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<atcoder/all>
#include<map>
using namespace std;
typedef long long li;
#define MOD 998244353
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}
// struct modint{
//   li num;

//   modint(li a=0){
//     num=(a%MOD+MOD)%MOD;
//   }
//   modint operator+(modint a) {return{(num+a.num)%MOD};} 
//   modint operator-(modint a) {return{((num-a.num)%MOD+MOD)%MOD};}
//   modint operator*(modint a) {return{num*a.num%MOD};}
//   modint inv(modint a);
//   modint operator/(modint a) {return {*this*inv(a)};}
//   modint& operator+=(modint a) {
//     (num += a.num)%=MOD;
//     return *this;
//   }
//   modint& operator*=(modint a) {
//     (num*=a.num)%=MOD;
//     return *this;
//   }
// };

// std::ostream& operator<<(std::ostream& os, const modint& m){
//   // ここでストリームに obj を書き込みます。
//   li a=m.num;
//   a%=MOD;
//   a+=MOD;
//   a%=MOD;
//   cout << a;
//   return os;
// }

// std::istream& operator>>(std::istream& os,modint& m){
//   // ここでストリームに obj を書き込みます。
//   li a; cin >>a;
//   m=a;
//   return os;
// }
// modint pow(modint a,int r){
//   modint b=a,ans=1;
//   while(r){
//     if(r%2) ans*=b;
//     b*=b;
//     r/=2;
//   }
//   return ans;
// }

// modint inv(modint a){
//   // MOD: prime
//   return pow(a,MOD-2);
// }



void decline(vector<li>& g,int n){
  while(g.size()>n) g.pop_back();
}
vector<li> operator*(const vector<li>& a,const vector<li> & b){
  vector<li> g=atcoder::convolution<MOD>(a,b);
  decline(g,max(a.size(),b.size()));
  return g;
}
vector<li>& operator*=(vector<li>& a,const vector<li> & b){
  auto n=a.size();
  a=atcoder::convolution<MOD>(a,b);
  decline(a,max(n,b.size()));
  return a;
}

vector<li> pow(vector<li> a,int r,int dec=1){
  int n=a.size();
  vector<li> b=a,ans(1,1);
  while(r){
    if(r%2) ans=atcoder::convolution<MOD>(ans,b);
    b=atcoder::convolution<MOD>(b,b);
    if(dec){
      decline(ans,n);
      decline(b,n);
    }
    r/=2;
  }
  return ans;
}

vector<li> g;

vector<li> f(int a){
  vector<li> tane(2,1);
  tane=pow(tane,a,0);
  if(df)print("tane",a,":",tane);
  vector<li> v;
  int t=1,n=a/2+1;
  rep(i,n){
    v.push_back(tane[2*i]*g[i]*t);
    t*=-1;
  }
  if(df)print("f_a",v);
  return v;
}

int main(){
  int n; cin >>n;
  map<int,int> cnt;
  g.resize(n+1,1);
  rep(i,n){
    g[i+1]=g[i]*(2*i+1)%MOD;
  }
  if(df)print("g:",g);
  rep(i,2*n){
    int a; cin >>a; cnt[a]++;
  } 
  map<int,int> deg;
  for(auto x:cnt){
    deg[x.second]++;
  }
  vector<li> ans(1,1);
  for(auto p:deg){
    if(df)print("a,d:",p.first,p.second);
    ans=atcoder::convolution<MOD>(ans,pow(f(p.first),p.second,0));
    if(df)print("ans",ans);
  }
  ans*=g;
  if(df)print("ans",ans);
  print(ans[n]);
}


Measured memory_bytes: 8816
/*input
3 4
4 3
4 1
2 2
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,m;
pii a[100001];
vector<int> v[100001];
signed main() {
	IOS;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i].f>>a[i].s;
		v[a[i].f].pb(a[i].s);
	}
	priority_queue<int> pq;
	int ans = 0;
	for(int i=1;i<=m;i++){
		for(auto x : v[i]){
			pq.push(x);
		}
		if(pq.size())
			{
				ans += pq.top();
				pq.pop();
			}
	}
	cout << ans << endl;
return 0;
}


Measured memory_bytes: 7296