akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}


Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    string s,t;
    cin >> s;
    cin >> t;
    bool tmp = true;
    for(int i = 2; i >= 0; i--){
        if(s[i] != t[2-i]) tmp = false;
    }
    if(tmp) cout << "YES" << endl;
    else cout << "NO" << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    int f=0;
    int s=0;
    for(int i=0;i<3;i++){
        if(a[i]==5){
            f++;
        }else if(a[i]==7){
            s++;
        }
    }
    if((f==2)&&(s==1)){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}   



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

const int maxn = 5000006;
const int mod = 998244353;

int p[maxn];
int *dp = &p[2500006];

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, k;
	cin >> n >> k;
	vector <pair <int, int> > segs(k);
	for (int i = 0; i < k; ++i) 
		cin >> segs[i].first >> segs[i].second;
	sort(segs.begin(), segs.end());
	vector <pair <int, int> > s;
	for (int i = 0; i < k; ++i) {
		if (s.empty() || s.back().second < segs[i].first)
			s.push_back(segs[i]);
		else
			s[int(s.size()) - 1].second = max(s[int(s.size()) - 1].second, segs[i].second);
	}
	dp[1] = 1;
	int united = 0; // usb zdes', zdes' vse, nikita, stas, gena, turbo, i dyusha metelkin
	for (int i = 2; i <= n; ++i) {
		for (auto seg: s) {
			(united += dp[i - seg.first]) %= mod;
			(united += mod - dp[i - seg.second - 1]) %= mod;
		}
		dp[i] = united;
	}
	cout << dp[n] << '\n';
}


Measured memory_bytes: 4436
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	ll n; cin >> n;
	string res = "";
	while (n > 0)
	{
		--n;
		res = (char)('a' + (n % 26)) + res;
		n /= 26;
	}
	cout << res << endl;
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC120A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B, C;

            int x;
            var word = Console.ReadLine().Split(' ');

            A = int.Parse(word[0]);
            B = int.Parse(word[1]);
            C = int.Parse(word[2]);

            if (B / A >= C)
                Console.WriteLine(C);
            if (B / A < C)
                Console.WriteLine(B / A);
            
            else
                ;

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int x;
    int y=0;
    int ans=0;
    
    cin >> x;
    
    if(x==2){
        
        cout << "2" << endl;
        
        return 0;
        
    }
    
    for(int i=x; i<=999999; i++){
        
        y = 0;
        
        for(int j=2; j<=i-1; j++){
            
            if(i%j==0){
                
                break;
                
            }
            
            if(j==i-1){
                
                y = 1;
                break;
                
            }
            
        }
        
        if(y==1){
            
            ans = i;
            break;
            
        }
        
    }
    
    cout << ans << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/


void solve() {
	int n; cin >> n;
	string s; cin >> s;
	vector<int> l(n, 0), r(n, 0);
	if (s[0] == 'W') l[0] = 1;
	for (int i = 1; i < n; i++) {
		l[i] = (s[i] == 'W');
		l[i] += l[i - 1];
	}
	r[n - 1] = (s[n - 1] == 'W');
	for (int i = n - 2; i >= 0; i--) {
		r[i] = (s[i] == 'W');
		r[i] += r[i + 1];
	}
	int ans = min(l[n - 1], n - l[n - 1]);
	for (int i = 0; i < n - 1; i++) {
		int x = min(max(0LL, l[i]), max(0LL, n - i - 1 - r[i + 1]));
		int y = x;
		y += max(max(0LL, l[i] - x), max(0LL, n - i - 1 - r[i + 1] - x));
		ans = min(ans, y);
	}
	cout << ans << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

Measured memory_bytes: 6752
#include<iostream>
#include<vector>
#include<map>
using namespace std;
#define inRange(x,a,b) (a <= x && x <= b)

struct button{
    int a[4];
    string to;
};

int main(){
    int n;
    while(cin >> n, n){
        int w, h;
        cin >> w >> h;

        map<int, string> iton;
        map<string, int> ntoi;
        vector<button> v[n];
        for(int i = 0; i < n; i++){
            string name;
            int b;

            cin >> name >> b;

            ntoi[name] = i;
            iton[i] = name;

            while(b-- > 0){
                button x;
                for(int j = 0; j < 4; j++)  cin >> x.a[j];
                cin >> x.to;
                v[i].push_back(x);
            }
        }

        int m;
        cin >> m;

        vector<int> buf;
        buf.push_back(0);
        vector<int>::iterator it = buf.begin();

        string op;
        while(m-- > 0){
            cin >> op;
            if(op == "show"){
                cout << iton[*it] << endl;
            }else if(op == "back"){
                if(it != buf.begin())   it--;
            }else if(op == "forward"){
                it++;
                if(it == buf.end()) it--;
            }else if(op == "click"){
                cin >> w >> h;
                for(button b : v[*it]){
                    if(inRange(w, b.a[0], b.a[2]) && inRange(h, b.a[1], b.a[3])){
                        it++;
                        buf.erase(it, buf.end());
                        buf.push_back(ntoi[b.to]);
                        it = --buf.end();
                    }
                }
            }
        }

    }
    return 0;
}


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

using namespace std;

 int main(){
	
 	char numero[10000];
 	char num[2];
 	int i;
 	long int soma=0,x,y;

 	cin >> numero;
 	y = atol(numero);
 	int tam = strlen(numero);
 	for(i=0;i<tam;i++){
 		num[0] = numero[i];
 		num[1] = '\0';
 		x = atol(num);
 		soma+=x;
 	}
 	if(y%soma==0){
 		cout << "Yes" << '\n';
 	}
 	else{
 		cout << "No" << '\n';
 	}

	return 0;
}

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

int x, n;
bool b[102];

int main() {
	cin >> x >> n;
	for (int i = 0; i < n; ++i) {
		int p;
		cin >> p;
		b[p] = 1;
	}
	for (int i = 0; i <= 100; ++i) {
		if (x - i >= 0 && !b[x - i]) {
			cout << x - i << endl;
			return 0;
		}
		if (x + i <= 101 && !b[x + i]) {
			cout << x + i << endl;
			return 0;
		}
	}

}


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

using namespace std;

#define P pair < int,int >

int main(){
	
	ios_base::sync_with_stdio(false);
	
	int N,W;
	
	cin>>N>>W;
	
	vector <P> w_v(N);
	
	int sum = 0;
	
	for(int i=0; i<N; i+=1){
		
		cin>>w_v[i].second>>w_v[i].first;
		
		sum += w_v[i].first;
	}
	
	sort(w_v.rbegin(),w_v.rend());
	
	int dp[sum+1];
	
	for(int i=0; i<=sum; i+=1){
		
		dp[i] = W+1;
	}
	
	dp[0] = 0;
	
	for(int i=N-1; i>=0; i-=1){
		
		for(int j=sum; j>=w_v[i].first; j-=1){
			
			dp[j] = min(dp[j] , w_v[i].second+dp[j-w_v[i].first]);
		}
	}
	
	for(int i=sum; i>=0; i-=1){
		
		if(dp[i]<=W){
			
			cout<<i;
			
			break;
		}
	}
}

Measured memory_bytes: 640
# ダイクストラ法
from heapq import heappop, heappush

N = int(input())
links = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    links[a].append((b, c))
    links[b].append((a, c))

Q, K = map(int, input().split())

d = [float('inf')] * (N + 1)
d[K] = 0
#prev = [None] * (N + 1)
q = [(0, K)]
while q:
    _, u = heappop(q)
    for v, c in links[u]:
        alt = d[u] + c
        if d[v] > alt:
            d[v] = alt
            #prev[v] = u
            heappush(q, (alt, v))

result = []
for _ in range(Q):
    x, y = map(int, input().split())
    result.append(d[x] + d[y])
print(*result, sep='\n')
#print('\n'.join(str(v) for v in result))


Measured memory_bytes: 54520
#第5回 ドワンゴからの挑戦状 予選-B Sum AND Subarrays
"""
数列Aが与えられる。
整数kが与えられる。
数列Aの空でない部分列からk個取る。
各部分列の合計を"美しさ"と言う。
この時、k個すべての"美しさ"のbit andを取った時、最大値がいくつになるか
求めよ。
n <= 1000, k <= n*(n+1)//2

解法：
まず直感的に、すべての要素の合計sum(lst1)を使うとして良い。
また、回答は必ずこれ未満の値となる。
更に、andを用いることから、上位桁のbit積を優先して良い。

となると、結局大きい値が上位桁のbitも多いことから、
和が大きい順にk個取った時の論理積ということになる。

N<1000という制約から、n*(n+1)//2が愚直に間に合うので、これを
実装すれば良い。

WA:
下位桁を優先したほうが良い場合が存在する。
解説：
下位桁を優先する、のではなく、上位桁を満たすようなk個を用意できなかった場合、
次に下位の桁を探すという解き方をする必要がある。つまり、上位桁を優先にするのは
変わらず、その桁のbitが1であるようなものをどんどん絞っていく形になる。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,k = map(int,readline().split())
lst1 = list(map(int,readline().split()))

def cumsum(lst): #元のリストを保持
    res = lst[:]
    for i in range(1,len(res)):
        res[i] += res[i-1]
    return res
def cumsumdif(l,r,lst): #求めたい差のインデックスを入れる
    if l == 0:
        return lst[r]
    else:
        return lst[r] - lst[l-1]
lst2 = cumsum(lst1)

lst3 = []

for i in range(n):
    for j in range(i,n):
        lst3.append(cumsumdif(i,j,lst2))

lst3.sort(reverse=True)

for i in range(40,-1,-1): #まず最上位桁について決定
    ct = 0
    res = []
    for j in lst3:
        if j>>i&1:
            ct += 1
            res.append(j)
    if ct >= k:
        m = i
        ans = pow(2,m)
        break

for i in range(m-1,-1,-1): #次に、上位桁からその桁においてandが1になるようなものを優先して絞っていく
    ct = 0
    resres = []
    for j in res:
        if j>>i&1:
            ct += 1
            resres.append(j)
    if ct >= k:
        ans += pow(2,i)
        res = resres

print(ans)


Measured memory_bytes: 112592
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		int cnt = 0;
		
		switch(D){
			case 0:
				for(int i=1;;i++){
					if(i % 100 == 0) continue;
					cnt++;
					if(cnt == N){
						Console.WriteLine(i);
						return;
					}
				}
				break;
			case 1:
				for(int i=100;;i+=100){
					if(i % 10000 == 0) continue;
					cnt++;
					if(cnt == N){
						Console.WriteLine(i);
						return;
					}
				}
				break;
			case 2:
				for(int i=10000;;i+=10000){
					if(i % 1000000 == 0) continue;
					cnt++;
					if(cnt == N){
						Console.WriteLine(i);
						return;
					}
				}
				break;
			default: break;
		}
		
		
		
	}
	int D,N;
	public Sol(){
		var d = ria();
		D = d[0]; N = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, m = readmi()
a = [0] * (n + 2)
r = defaultdict(int)
for i in range(m):
    x,y = readmi()
    a[x - 1] += 1
    a[y] += -1

for i in range(n + 1):
    a[i + 1] += a[i]
count = 0
flg = True
for i in range(n):
    if a[i] >= m:
        count += 1
print(count)

Measured memory_bytes: 64168
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include <list>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <climits>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
using namespace std;

char nextChar(char c){
	if (c == 'z'){ return 'a'; }
	return (char)(c + 1);
}

int acount(char c){
	int tmp = c - 'a';
	return 26 - tmp;
}

class str{
public:
	string s;
	int c{ 0 };
	int chari{0};
};


int main(){
	string s;
	int k;
	cin >> s;
	cin >> k;

	int now = 0;
	while (s[now] != '\0'){
		int cost = acount(s[now]);
		if (s[now]!='a' && cost <= k){k-=cost ; s[now] = 'a'; }
		now++;
	}
	if (k>0){ 
		k = k % 26;
		for (int i = 0; i < k; i++)
		{
			s[s.size() - 1] = nextChar(s[s.size() - 1]);
		}
		
	}
	cout << s << endl;
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define ull unsigned long long int
#define forn(i,n)for(ll i=0;i<(n);i++)
#define forn_rev(i,n)for(ll i=(n)-1;i>=0;i--)
#define for1n(i,n) for(ll i=1;i<=(n);i++)
#define ARRAY_SIZE(a) sizeof(a)/sizeof(*a)
#define MOD 1000000007
#define MAXN 100005
 
using namespace std;
 
 
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
 
    ll T=1;
    //cin>>T;
    while(T--)
    {
        ll N;
        cin>>N;
        vector<ll> arr(N);
        forn(i,N) cin>>arr[i];
        unordered_map<ll,ll> mp;
        forn(i,N){
            mp[i+arr[i]]++;
        }
        ll c=0;
        forn(i,N){
            c+=mp[i-arr[i]];
 
        }
        cout<<c;
 
 
 
 
 
    }
 
 
 
    return 0;
}

Measured memory_bytes: 20052
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
#define rep(i,n) for(int i = 0;i<(n);++i)
#define MAXN 100010
#define md 1000000007

lint powmod_h;
lint powmod(lint a,lint p){
	if(!p)return 1;
	if(p&1)return powmod(a,p-1)*a%md;
	else{
		powmod_h=powmod(a,p/2);
		return powmod_h*powmod_h%md;
	}
}

lint ncr_ret,ncr_div;
lint ncr(lint n,lint r){
	if(r>n/2)return ncr(n,n-r);
	ncr_ret=1;ncr_div=1;
	rep(i,r){
		ncr_ret=ncr_ret*(n-i)%md;
		ncr_div=ncr_div*(r-i)%md;
	}return ncr_ret*powmod(ncr_div,md-2)%md;
}

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

	lint n,m;cin>>n>>m;
	lint ans=1;
	//mを素因数分解
	lint lf=m,p;
	for(int i=2;i*i<m;++i){
		p=0;
		while(lf%i==0){
			++p;lf/=i;
		}if(p){//ここで因数i**pがわかる
			ans*=ncr(n+p-1,p);ans%=md;
		}
	}if(lf!=1){//ここで因数lf**1がわかる
		ans*=ncr(n,1);ans%=md;
	}cout<<ans<<endl;
	getchar();
	getchar();
	return 0;
}


//#include "bits/stdc++.h"
//using namespace std;
//typedef long long lint;
//
//#define rep(i,n) for(int i=0;i<(n);++i)
//#define MAXN 1010
//#define linf 8223372036854775808
//
////d,edge,g
//lint d[MAXN];
//struct edge{ int to;lint cost; };
//vector<edge> g[MAXN];
//
//bool bellmanford(int n,int s){
//	d[s]=0;
//	rep(i,n){
//		rep(v,n){
//			for(edge &e:g[v])if(d[v]!=linf&&d[e.to]>d[v]+e.cost){
//				d[e.to]=d[v]+e.cost;
//				if(i==n-1&&e.to==n-1)return 1;
//			}
//		}
//	}return 0;
//}
//
//int main(){
//	int n,m;cin>>n>>m;
//	int a,b;lint c;
//	fill(d,d+n,linf);
//	rep(i,m){
//		cin>>a>>b>>c;--a;--b;
//		g[a].push_back({b,-c});
//	}
//	if(bellmanford(n,0))cout<<"inf";
//	else cout<<-d[n-1];
//	return 0;
//}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

#define int ll

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

  string s,t;
  cin>>s>>t;
  map<char,int>m;
  vector<map<char,int>>ms(s.size()+1);
  bool ok=true;
  ms[s.size()-1][s[s.size()-1]]=1;
  for(int i=s.size()-1;i>0;i--){
    for(auto it:ms[i])ms[i-1][it.first]=++it.second;
    ms[i-1][s[i-1]]=1;
  }
  for(auto it:t)if(ms[0][it]==0)ok=false;
  if(!ok){
    cout<<-1<<endl;
    return 0;
  }
  m=ms[0];
  int ans=0;
  int now=0;
  for(auto it:t){
    if(m[it]>0){
      now+=m[it];
      m=ms[now];
    }
    else{
      ans++;
      now=0;
      now+=ms[now][it];
      m=ms[now];
    }
  }

  cout<<ans*s.size()+now<<endl;
  return 0;
}


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

int main() {
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	    cin>>arr[i];
	int dp[n]={0};
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
	{
	    dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define pb push_back 
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sz(v) (int((v).size()))
const ll INF = 1e18;
const int MOD = 1e9+7;
const int N = 5e5+5;
void nope(){
	puts("-1");
	exit(0);
}
int main(){
	int n;
	cin >> n;
	vector<int> arr(n);
	for(int i = 0; i < n; ++i)
		scanf("%d",&arr[i]);
	int mini = 0;
	if(arr[0] > 0)
		nope();
	ll ans = 0;
	for(int i = n-1; i >= 0; --i){
		mini = max(mini-1,0);
		if(arr[i] < mini)
			nope();
		if(arr[i] > mini){
			mini = arr[i];
			ans += arr[i];
		}
	}
	cout << ans << '\n';
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    deque<ll> dq;
    ll n;
    cin >> n;
    ll a;
    for(int i=0;i<n;i++){
    	cin >> a;
    	if(i&1){
    		dq.push_front(a);
    	}else{
    		dq.push_back(a);
    	}
    }
    if(n%2 == 0){
    	while(!dq.empty()){
    		cout << dq.front() << " ";
    	    dq.pop_front();
    	}
    }else{
    	while(!dq.empty()){
    		cout << dq.back() << " ";
    	    dq.pop_back();
    	}
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
typedef pair<pill,int> PA;
//ll MOD;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	ll weight;
};
int N,M;
double dp[200000];
double dp2[200000];
vi gr[700];
int main(){
	cin>>N>>M;
	rep(i,M){
		int s,t;
		cin>>s>>t;s--;t--;
		gr[s].pb(t);
	}
	dp[N-1]=0.0;
	for(int i=N-2;i>=0;i--){
		dp[i]=0.0;
		int num=gr[i].size();
		rep(j,num){
			int x=gr[i][j];
			dp[i]+=(1.0/(double)num)*(dp[x]+1.0);
		}
	}
	double ans=dp[0];
	//cout<<dp[0]<<endl;
	for(int j=N-2;j>=0;j--){
		int check=j;
		bool flag=true;
		for(int i=N-2;i>=0;i--){
			if(i==check){
				dp2[i]=0.0;
				int num=gr[i].size();
				if(num==1)flag=false;
				else{
					double ma=dp2[gr[i][0]];
					rep(j,num){
						int x=gr[i][j];
						ma=max(ma,dp[x]);
						dp2[i]+=(1.0/(double)(num-1))*(dp2[x]+1.0);
					}
					dp2[i]-=(ma+1.0)/(double)(num-1);
				}

			}else{
				dp2[i]=0.0;
				int num=gr[i].size();
				rep(j,num){
					int x=gr[i][j];
					dp2[i]+=(1.0/(double)num)*(dp2[x]+1.0);
				}
			}
		}
		if(flag)ans=min(ans,dp2[0]);
	}
	cout<< setprecision(10)<<ans<<endl;

}


Measured memory_bytes: 1408
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 100010;
const int MAX_K = 110;
int N, K;
vector<int> heights;
ll dp[MAX_N];
void init()
{
    for (int i = 0; i < MAX_N; i++)
    {
            dp[i] = LL_INF;
    }
}

int main()
{
    init();
    cin >> N >> K;
    heights.resize(N);
    for (auto &val : heights)
    {
        cin >> val;
    }

    dp[0] = 0;
    for (int i = 1; i < N; i++)
    {
        for (int j = 1; j <= K; j++)
        {
            int k = i - j;
            if (k >= 0)
            {
                dp[i] = min(dp[i], dp[k] + abs(heights[i] - heights[k]));
            }
        }
    }
    cout << dp[N - 1] << endl;
    return 0;
}


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

int main(){
  int n;
  cin>>n;
  if(n>=1&&n<=104)cout<<0<<endl;
  else if(n>=105&&n<=134) cout<<1<<endl;
  else if(n>=135&&n<=164) cout<<2<<endl;
  else if(n>=165&&n<=188) cout<<3<<endl;                         //⚫ 165≤𝑁≤188 のとき、答えは 3
  else if(n>=189&&n<=194) cout<<4<<endl;                       //⚫ 189≤𝑁≤194 のとき、答えは 4
  else if(n>=195&&n<=200) cout<<5<<endl;    
}//⚫ 195≤𝑁≤200 のとき、答えは 5
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=200005,mod=1e9+7;
const ll inf = (ll)1e15;
int add(int x,int y)
{
  x+=y;
  if(x>=mod) x-=mod;
  if(x<0) x+=mod;
  return x;
}
int mult(int x,int y)
{
  ll tmp=(ll)x*y;
  if(tmp>=mod) tmp%=mod;
  return tmp;
}
int a[N],b[N],c[N];
vi v[N];
ll d[2][N],dp[2][N];
set<pair<ll,int> > s;
void dist(int u,int idx)
{
  rep(i,0,N) d[idx][i]=inf;
  s.clear();
  d[idx][u]=0; dp[idx][u]=1;
  s.insert(mp(0,u));
  while(sz(s))
    {
      u=(*s.begin()).se;
      ll tmp=(*s.begin()).fi;
      s.erase(s.begin());
      if(tmp>d[idx][u]) continue;
      for(int ind:v[u])
	{
	  int v1=(a[ind]^b[ind]^u);
	  if(d[idx][v1]>d[idx][u]+c[ind])
	    d[idx][v1]=d[idx][u]+c[ind],dp[idx][v1]=dp[idx][u];
	  else if(d[idx][v1]==d[idx][u]+c[ind])
	    dp[idx][v1]=add(dp[idx][v1],dp[idx][u]);
	  s.insert(mp(d[idx][u]+c[ind],v1));
	}
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,m,x,y,z,s,t;
  cin>>n>>m>>s>>t;
  rep(i,1,m+1)
    {
      cin>>a[i]>>b[i]>>c[i];
      c[i]+=c[i];
      v[a[i]].pb(i); v[b[i]].pb(i);
    }
  dist(s,0); dist(t,1);
  int ans=mult(dp[0][t],dp[1][s]);
  rep(i,1,n+1)//meet at vertices
    if(d[0][i]==d[1][i] && d[0][i]==d[0][t]/2)
      ans=add(ans,-mult(mult(dp[0][i],dp[1][i]),mult(dp[0][i],dp[1][i])));
  rep(i,1,m+1)//meet at edges
    {
      if(d[0][a[i]]<d[0][t]/2 && d[1][b[i]]<d[0][t]/2 && d[0][a[i]]+d[1][b[i]]+c[i]==d[0][t])
	ans=add(ans,-mult(mult(dp[0][a[i]],dp[1][b[i]]),mult(dp[0][a[i]],dp[1][b[i]])));
      if(d[0][b[i]]<d[0][t]/2 && d[1][a[i]]<d[0][t]/2 && d[0][b[i]]+d[1][a[i]]+c[i]==d[0][t])
	ans=add(ans,-mult(mult(dp[0][b[i]],dp[1][a[i]]),mult(dp[0][b[i]],dp[1][a[i]])));
    }
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 26368
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, (int)vec.size() - 1)std::cout << vec[i] << " ";
	if(!vec.empty())std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int main(){
	std::string s,t;
	std::cin>>s;
	t=s;
	std::reverse(t.begin(),t.end());
	if(s!=t){
		puts("No");
		return 0;
	}
	std::reverse(t.begin(),t.end());
	std::reverse(t.begin(),t.begin()+t.size()/2);
	if(s.substr(0,s.size()/2)!=t.substr(0,s.size()/2)){
		puts("No");
		return 0;
	}
	std::reverse(t.begin(),t.begin()+t.size()/2);
	std::reverse(t.begin()+t.size()/2+1,t.end());
	if(s.substr(s.size()/2+1,s.size()/2)!=t.substr(s.size()/2+1,s.size()/2)){
		puts("No");
	}
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 3608
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer, Integer> ma = new HashMap<>();
		for (int i = 0; i < N; i++) {
			int a = sc.nextInt();
			ma.put(a, ma.get(a) == null ? 1 : ma.get(a) + 1);
		}
		int ans = 0;
		for (Integer i : ma.keySet()) {
			ans += ma.get(i) >= i ? ma.get(i) - i : ma.get(i);
		}
		System.out.println(ans);
	}
}

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



int main() {
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());
    
    int ans = k;
    rep(i,n) {
        int d;
        if(i == 0) {
            d = a.back() - a[i];
        }
        else {
            d = a[i] - a[i-1];
        }
        ans = min(ans, max(d, k-d));
    }
    
    cout << ans << endl;
    
    return 0;
}




Measured memory_bytes: 4028
x = input()
S = [1,2,3,4,5,6,7,8,9,10,11,12,13]
H = [1,2,3,4,5,6,7,8,9,10,11,12,13]
C = [1,2,3,4,5,6,7,8,9,10,11,12,13]
D = [1,2,3,4,5,6,7,8,9,10,11,12,13]
for i in range(x):
	mark, num = map(str, raw_input().split())
	if mark == 'S':
		S.remove(int(num))
	elif mark == 'H':
		H.remove(int(num))
	elif mark == 'C':
		C.remove(int(num))
	elif mark == 'D':
		D.remove(int(num))
for i in range(len(S)):
	print "S " + str(S[i])
for i in range(len(H)):
	print "H " + str(H[i])
for i in range(len(C)):
	print "C " + str(C[i])
for i in range(len(D)):
	print "D " + str(D[i])

Measured memory_bytes: 4304
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

int _maxi = 0;
int _num = 0;
vector<string> _myList;

void ParseIn () {
	string curStr = "";
	char curChar = 0;
	
	ifstream inFile("palindromeP1015.in");
	
	inFile >> _maxi >> _num;
	
	for (int i = 0; i < _maxi; i++) {
		for (int m = 0; m < _num; m++) {
			inFile >> curChar;
			curStr += curChar;
		}
		
		_myList.push_back(curStr);
		curStr = "";
	}
	
	inFile.close();
}

void CParseIn () {
	string curStr = "";
	char curChar = 0;
	
	cin >> _maxi >> _num;
	
	for (int i = 0; i < _maxi; i++) {
		for (int m = 0; m < _num; m++) {
			cin >> curChar;
			curStr += curChar;
		}
		
		_myList.push_back(curStr);
		curStr = "";
	}

}

bool CompareStr (string one, string two) {
	return one < two;
}

void Core () {
	sort(_myList.begin(), _myList.end(), CompareStr);
}

void CWriteOut () {
	
	for (int i = 0; i < _myList.size(); i++) {
		cout << _myList[i];
	}
	
	cout << endl;
}

int main () {
	
	CParseIn();
	//ParseIn();
	Core();
	CWriteOut();
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
 
#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
  int h,w;
  cin >> h >> w;
  string b[h];
  string a[h][w];
  rep(i,h){
    cin >> b[i];
    rep(j,w){
      a[i][j] = b[i].substr(j,1);
    }
  }

  bool c[w];
  bool d[h];
  rep(x,w){
    c[x]=false;
  }
  rep(y,h){
    d[y]=false;
  }
  rep(k,w){
    rep(m,h){
      if(a[m][k] == "#"){
        c[k] = true;
      }
    }
  }
  rep(p,h){
    rep(q,w){
      if(a[p][q] == "#"){
        d[p] = true;
      }
    }
  }
    rep(r,h){
      rep(s,w){
        if(d[r] == true && c[s] == true){
          cout << a[r][s];
        }
        if(s == w-1 && d[r] == true){
          cout << endl;
        }
      }
    }
        
    
    
 
 return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  string t;
  cin >> t;
  
  ll n = t.size();
  for (int i = 0; i < n; i++){
    if (t[i] == '?')
      t[i] = 'D';
  }

  cout << t << endl;

  return 0;
}


Measured memory_bytes: 3720
#include<stdio.h>
int main(void)
{
    int a,b;
    scanf("%d %d", &a, &b);
    if(a<b){
        printf("a < b\n");
    }
    else if(a>b){
        printf("a > b\n");
    }
    else{
        printf("a == b\n");
    }
    return 0;
}
         


Measured memory_bytes: 2072
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>

using namespace std;


int main() {
    int N;
    cin >> N ;
    vector<int> apple(N);
    int flag = 0;
    for (auto& x : apple) {
        cin >> x;
        if (x % 2)flag = 1;
        
    }
    if (flag) cout << "first" << endl;
    else cout << "second" << endl;
}


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


int main(){
    int x , y;
    cin >>x;
    y =x*x*x;
    cout << y <<endl;
    
}



Measured memory_bytes: 3084
import java.util.*;

public class Main {
    static List<long[]>[] to; // 頂点iの隣接リスト
    static long[] dist;
    static int n;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        
        // 隣接リストの作成
        to = new List[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<long[]>();
        }
        for (int i = 0; i < n - 1; i++) {
            long p = sc.nextInt() - 1;
            long q = sc.nextInt() - 1;
            long dis = sc.nextLong();
            to[(int)p].add(new long[]{q, dis});
            to[(int)q].add(new long[]{p, dis});
        }
        
        // 点kから各点までの距離を計算
        int query = sc.nextInt();
        int k = sc.nextInt() - 1;
        long[] distK = calcDist(k);
        
        // p→k→qの最短距離を出力
        while (query-- > 0) {
            int p = sc.nextInt() - 1;
            int q = sc.nextInt() - 1;
            
            System.out.println(distK[p] + distK[q]);
        }
    }
    
    public static long[] calcDist(int p) {
        dist = new long[n];
        dfs(p, 0, -1);
        return dist;
    }
    
    // 頂点pと隣接する点に自分の値+距離を配る
    public static void dfs(int p, long d, int par) {
        dist[p] = d;
        
        for (long[] q : to[p]) {
            if (q[0] == par) continue;
            dfs((int)q[0], d + q[1], p);
        }
    }
}

Measured memory_bytes: 180468
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    
    if(s[0]==s[2]){
        cout1("Yes")
    }else{
        cout1("No")
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	if((b-a+1)%2==1)
		printf("Alice\n");
	else
		printf("Borys\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>
#include <memory.h>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <time.h>
#include <assert.h>
#include <cmath>
#include <stack>
#include <string.h>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 300;
string s;
int n, k, dp[N][N][N + 1];
int calc(int i, int j, int k) {
	if (k < 0)
		return -1e9;
	if (i >= j)
		return i==j;
	int &ret = dp[i][j][k];
	if (ret != -1)
		return ret;
	ret = max(calc(i + 1, j, k), calc(i, j - 1, k));
	if (s[i] == s[j])
		ret = max(ret, calc(i + 1, j - 1, k) + 2);
	ret = max(ret, calc(i + 1, j - 1, k - 1) + 2);
	return ret;
}
int main()
{
	cin >> s;
	n = s.size();
	cin >> k;
	memset(dp, -1, sizeof(dp));
	cout << calc(0, n - 1, k) << endl;
	return 0;
}

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

using namespace std;

int main(void)
{
  string s, t;
  cin >> s >> t;
  bool res = false;
  for (int i = 0; i < s.size(); ++i) {
    rotate(s.begin(), s.begin() + 1, s.end());
    if (s == t) res = true;
  }
  cout << (res ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	if(n%2)
	{
		cout<<"0\n";
		return 0;
	}
	ll ans=0,p=5;
	n/=2;
	while(p<=n)
	{
		ans+=n/p;
		p*=5;
	}
	cout<<ans<<"\n";
	return 0;
}

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

void solve(vector<string> c){
	cout << c[0].c_str()[0] << c[1].c_str()[1] << c[2].c_str()[2] << endl;
}

int main(){	
	vector<string> c(3-1+1);
	for(int i = 0 ; i <= 3-1 ; i++){
		cin >> c[i];
	}
	solve(c);
	return 0;
}



Measured memory_bytes: 256
n,k=map(int,input().split())


def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy > 0:
        out = str(X_dumy % n) + out
        X_dumy = int(X_dumy / n)
    return out

x2 = Base_10_to_n(n, k)

cnt=str(x2)
print(len(cnt))

Measured memory_bytes: 3060
using System.Collections.Generic;
using static System.Console;

class Program {
    static void Main() {
        var a = NextInt();
        var b = NextInt();

        WriteLine(calc(a, b));
    }

    static string calc(int a, int b) {
        if (a <= 0 && 0 <= b) {
            return "Zero";
        } else if (a < 0 && (b - a) % 2 == 0) {
            return "Negative";
        }
        return "Positive";
    }

    static int NextInt() {
        return int.Parse(NextString());
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}

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

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

using namespace std;

int main()
{
    fast;
    string s;
    cin>>s;
    ll sum=0;
    f(i,s.length()) sum+=(s[i]-'0');
    if(sum%9==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

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


Measured memory_bytes: 3716
#include <stdio.h>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;

int maxNum(int N){
  int maxInt=0,i=1,a,b;
  int lenN=(int)log10(N)+1;
  while (i<lenN){
    a=N/(int)pow(10.0,(double)lenN-i);
    b=N%(int)pow(10.0,(double)lenN-i);
    maxInt=max(maxInt,a*b);
    i++;
  }
  return maxInt;
}

int main(){
  int Q,cnt,N;
  scanf("%d",&Q);
  for (int i=0;i<Q;i++){
    set<int> S;
    scanf("%d",&N);
    cnt=0;
    while (true){
      set<int>::iterator iti=S.find(N);
      if (N<10){
        printf("%d\n",cnt);
        break;
      }else if (iti!=S.end()){
        printf("-1\n");
        break;
      }else{
        S.insert(N);
        N=maxNum(N);
        cnt++;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1092
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, x, d;
  cin >> n >> x >> d;
  if (!d) {
    if (x)
      cout << n+1 << endl;
    else
      cout << 1 << endl;
    return 0;
  }
  if (d < 0) {
    x = -x;
    d = -d;
  }
  map<int, map<ll, ll>> imos;
  for (int i = 0; i <= n; i++) {
    int idx = (x*i%d+d)%d;
    ll l = (x*i+d*(i-1)*i/2-idx)/d; //dで割り切れるようにしてから座標圧縮
    ll r = (x*i+d*(n*2-i-1)*i/2-idx)/d+1;
    imos[idx][l]++;
    imos[idx][r]--;
  }
  ll ans = 0;
  for (auto e : imos) {
    ll sum = 0, l;
    for (auto r : e.second) {
      if (!sum) {
        l = r.first;
        sum += r.second;
      } else {
        sum += r.second;
        if (!sum)
          ans += r.first-l;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 50304