akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pi 3.1415926535
#define endl '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
//vector<ll>v;
void func(string s,ll x,ll n)
{
  if(s.size()==n)
  {
      cout<<s<<endl;
      return;
  }
  int r=x;
  for(int i=0;i<=x+1;i++)
    {
        char ch='a'+i;
        r=max(r,i);
        s.pb(ch);
        func(s,r,n);
        s.pop_back();
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,a,b;
    string s="";
    cin>>n;
   // for(i=0;i<=25;i++)
     //   v.pb(i);
    a=-1;
    func(s,a,n);
}



Measured memory_bytes: 1536
N = int(input())
rate = 380000.0
ans = 0.0
for i in range(N):
    x, u = input().split()
    x = float(x)
    ans += x * rate if u == "BTC" else x
# 出力時の桁数を11桁くらいにする。    
print("{:.11f}".format(ans))


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

#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define LL long long
#define ppt(x) __builtin_popcount(x)
using namespace std;
const int INF=0x3f3f3f3f,N=1e6+5,MOD=1e9+7;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;

template<typename T>
inline int getplc(T x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}

LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)res=res*a%_MOD;
	}
	return res;
}

template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) {
	return max(a, Smax(args...));
}
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) {
	return min(a, Smin(args...));
}

template <typename T>
#define errorl(args...) {  \
	string _s = #args;   \
	replace(_s.begin(), _s.end(), ',', ' ');  \
    stringstream _ss(_s);  \
    istream_iterator<string> _it(_ss);  \
    errl(_it, args);  \
}
void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	errl(++it, args...);
}
#define error(args...) {  \
    string _s = #args;  \
    replace(_s.begin(), _s.end(), ',', ' ');  \
    stringstream _ss(_s);  \
    istream_iterator<string> _it(_ss);  \
    err(_it, args);  \
    cerr<<endl; \
}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}

void Solve() {
	int l,r;
	cin>>l>>r;
	if(l<=0&&0<=r){
		cout<<"Zero\n";
	}
	else if(max(0,min(0,r+1)-l)&1)cout<<"Negative\n";
	else cout<<"Positive\n";
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
//  freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}


Measured memory_bytes: 3632
n,k=map(int,input().split())
XY=[list(map(int,input().split())) for _ in range(n)]
XY.sort()
ans=float('inf')
for i in range(n):
    for j in range(i+1,n):
        x=XY[j][0]-XY[i][0]
        T=sorted(Z[1] for Z in XY[i:j+1])
        for u,v in zip(T,T[k-1:]):
            ans=min(ans,x*(v-u))
print(ans)

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  char s;
  set<char> st;
  while (cin >> s) {
    st.insert(s);
  }
  for (char c = 'a'; c <= 'z'; c++) {
    if (st.find(c) == st.end()) {
      cout << c << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;

const int N = 200010;
int f[N], r[N], n, m;
int dad(int x){
	if (f[x] == x) return x;
	else {
		int l = dad(f[x]);
		r[x] = r[x] + r[f[x]];
		f[x] = l;
		return l;
	}
}
int main(){
	read(n); read(m);
	for (int i = 1; i <= n; i++) f[i] = i, r[i] = 0;
	for (int i = 1; i <= m; i++){
		int u, v, d;
		read(u); read(v); read(d);
		int tu = dad(u), du = r[u];
		int tv = dad(v), dv = r[v];
		if (tu == tv){
			if (du + d != dv){
				printf("No\n");
				return 0;
			}
		}
		else {
			f[tv] = tu;
			r[tv] = du + d - dv;
		}
	}
	printf("Yes\n");
	return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>

int main (void)
{
	int box;
	int a, b;
	while(scanf("%d %d", &a, &b))
	{
	
	if(a > b)
	{
		box = b;
		b = a;
		a = box;	
	}
	else if(a == 0 && b == 0)
	{
		break;
	}

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


Measured memory_bytes: 2568
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int N;
    cin >> N;
    int K;
    cin >> K;

    int A[N];

    for( int ni = 0 ; ni < N ; ni++ ){
        cin >> A[ni];
    }

    if(N==K){
        cout << 1;
    }else{
        if( (N-1) % (K-1) == 0 ){
            cout << (N-1) / (K-1) ;
        }else{
            cout << (N-1) / (K-1) + 1;
        }

    }



}

Measured memory_bytes: 640
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(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; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
// const ll mod = 1000000007;
const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"

bool solve(){
  map<char,ll>mp;
  ll n;cin>>n;
  string s;cin>>s;
  rep(i,n)mp[s[i]]++;
  ll ans=mp['R']*mp['G']*mp['B'];

  rep(i,n)for(int j=i+1;j<n;j++){
    ll k=j+(j-i);
    if(!(k<n))continue;
    if(s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i])ans--;
  }
  cout<<ans<<endl;
  return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(30);
  solve();
}


Measured memory_bytes: 3608
#include <iostream>
#include <climits>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<long long>
#define vb vector<bool>
#define vs vector<string>
#define px(x) cout << x << endl
#define pfi(x) printf("%d\n", x)
#define pfs(x) printf("%s\n", x)
#define sfi(x) scanf("%d", &x)
#define sfs(x) scanf("%s", x)

int maxsum(vector<int> &arr, int index){
    if(index < 0 ){ return 0; }


    return max( maxsum(arr,index-1) + abs(arr[index]-arr[index-1]) , maxsum(arr, index-2) + abs(arr[index]- arr[index-2]) );
}


int main() {
    int n;
    cin >> n;
    vector<int> arr(n);

    for(auto &val : arr){
        cin >> val;
    }

    //cout << maxsum(arr,n-1) << endl;

    vector<int> dp(n);
    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] << endl;











	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 210000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
// long long C(int a,int b){
// 	if(a<b||b<0)return 0;
// 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
// }
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	if(a>=b*2-1){
		printf("YES\n");
	}else printf("NO\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int n;
    int tmp, ans = 0;

    string s;

    cin >> n >> s;

    for (int i = 1; i < s.size(); i++) {
        if (s[i] == 'E') {
            ans++;
        }
    }

    tmp = ans;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'E' && s[i+1] == 'E') {
            tmp--;
        } else if (s[i] == 'W' && s[i+1] == 'W') {
            tmp++;
        }

        ans = min(ans, tmp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 900
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    string s; cin >> s;
    int N = s.size();

    bool ok = true;
    for(int i=0; i<N; i++) {
        // odd
        if(i % 2 == 0) {
            bool hoge = false;
            hoge |= (s[i] == 'R');
            hoge |= (s[i] == 'U');
            hoge |= (s[i] == 'D');
            ok &= hoge;
        }
        else {
            bool hoge = false;
            hoge |= (s[i] == 'L');
            hoge |= (s[i] == 'U');
            hoge |= (s[i] == 'D');
            ok &= hoge;
        }
        // cout << ok << endl;
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define mod 1000000007
using namespace std;

int main(){
    int n,d,ans;
    cin >> n >> d;

    if(n % (2*d+1) == 0)ans = n / (2*d+1);
    else ans = (n / (2*d+1)) + 1;
    
    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
X, K, D = (int(x) for x in input().split())
P = X
if abs(X) >= K * D:
    if X >= 0:
        P = X - K * D
    else:
        P = abs(X + K * D)
else:
    x = int(abs(X) / D)
    if X >= 0:
        if (K - x) % 2 == 0:
            P = X - D * x
        else:
            P = abs(X - D * (x + 1))
    else:
        if (K - x) % 2 == 0:
            P = abs(X + D * x)
        else:
            P = X + D * (x + 1)
print(int(P))


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

int main(){
  string s;
  cin>>s;
  
  int count=0;
  
  for(int i=0;i<s.size();++i){
    if(s.at(i)=='o')
      ++count;
  }
  
  cout<<700+100*count<<endl;
}


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

int main(){
    int M,N;cin >> N >> M;
    int g[10][10] = {0};

    for(int i = 0 ; i < M ; i++){
        int a,b;cin >> a >> b;
        a--;b--;
        g[a][b] = g[b][a] = 1;
    }

    vector<int> v(N-1);
    for(int i = 1; i < N ; i++){
        v[i-1] = i;
    }
    int ans = 0;

    do{
        int nv = 0;
        for(int i = 0 ; i < v.size() ; i++){
            if(g[nv][v[i]] == 0)break;
            nv = v[i];
            if(i == v.size()-1)ans++;
        }
    }while(next_permutation(v.begin(),v.end()));

    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)



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

    int zero_count=0;
    int tmp = 1;
    while(zero_count < 2) {
        int tmp_c = a*tmp%b;
        if(tmp_c == c) {
            cout << "YES" << endl;
            return 0;
        }
        if(tmp_c == 0) zero_count++;
        tmp++;
    }

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


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
S = list(input())

def solve():
    now = N
    choice = []
    while 1:
        if now==0:
            return choice[::-1]
        for m in range(M, 0, -1):
            nx = now-m
            if nx<0: continue
            if S[nx]=='1': continue
            now = nx
            choice.append(m)
            break
        else:
            return [-1]

print(*solve())

Measured memory_bytes: 89356
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
using namespace std;
typedef long long LL;
int n;
LL a[300050],sum1[300050],sum2[300050],SUM1,SUM2,Max;
priority_queue<LL, vector<LL>, less<LL> >q1;
priority_queue<LL, vector<LL>, greater<LL> >q2;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n*3;i++) scanf("%lld",&a[i]);
	sum1[0]=0;
	sum2[n*3+1]=0;
	SUM1=0;
	SUM2=0;
	for(int i=1;i<=n;i++){
		q2.push(a[i]);
		SUM1+=a[i];
	}
	sum1[n]=SUM1;
	for(int i=n*3;i>=2*n+1;i--){
		q1.push(a[i]);
		SUM2+=a[i];
	}
	sum2[2*n+1]=SUM2;
	int l=n+1,r=2*n;
	while(l<=r){
		if(a[l]>q2.top()){
			SUM1-=q2.top();
			SUM1+=a[l];
			q2.pop();
			q2.push(a[l]);
		}
		sum1[l]=SUM1;
		l++;
	}
	l=n+1,r=2*n;
	while(l<=r){
		if(q1.top()>a[r]){
			SUM2-=q1.top();
			SUM2+=a[r];
			q1.pop();
			q1.push(a[r]);
		}
		sum2[r]=SUM2;
		r--;
	}
	Max=-1e18;
	for(int i=n;i<=2*n;i++){
		if(sum1[i]-sum2[i+1]>Max) Max=sum1[i]-sum2[i+1];
	}
	printf("%lld\n",Max);
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	
	int n;
	cin >> n;
	vector<long long> a(n + 1);
	for(int i = 1; i <= n; i++ ) {
		int x;
		cin >> x;
		a[i] = a[i - 1] + x;
	}
	map<long long, int> mp;
	long long ans = 0;
	for(int i = 0; i <= n; i++) {
		if(mp.count(a[i])) {
			ans += mp[a[i]];
		}
		mp[a[i]]++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string s;
  int b, a, ab,ba;
  b =0;
  a = 0;
  ab = 0;
  ba = 0;
  for(int i = 0 ;i<n;i++){
    cin >> s ;
    int nagasa = s.size();
    for(int j = 0 ; j < nagasa ;j++){
      if( j==0 && s.at(j) == 'B'){
        b += 1;
      }
      if( j == nagasa - 1 && s.at(nagasa-1) == 'A'){
        a += 1;
      }
      if( j == 0 && s.at(0) == 'B' && s.at(nagasa-1) == 'A'){
        a -= 1;
        b -= 1;
        ba += 1;
      }
      if( j == nagasa -1 ){
        break;
      }
      if( s.at(j) == 'A' && s.at(j+1) == 'B'){
        ab += 1;
      }
    }
  }
  int ans = 0;
  ans += ab;
  if( ba == 0){
    ans += min(a,b);
  }
  else if( a == 0 && b == 0){
    ans += ba -1;
  }
  else{
    ans += ba + min(a,b);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int s;
    double bmi,w,h;
    while(~scanf("%d,%lf,%lf",&s,&w,&h)){
        bmi = w/(h*h);
        if(bmi >= 25.0){
            printf("%d\n",s);
        }
    }
    return 0;
}


Measured memory_bytes: 2112
def main():
    from collections import deque

    h, w = map(int, input().split())
    ch, cw = map(lambda x: int(x) - 1, input().split())
    dh, dw = map(lambda x: int(x) - 1, input().split())

    m = [list(input()) for _ in range(h)]
    vis = [[False for _ in range(w + 2)] for _ in range(h + 2)]

    def walk(i, j):
        q = deque()
        q.append((i, j))
        edge = []
        while q:
            y, x = q.popleft()
            if vis[y][x]:
                continue
            vis[y][x] = True
            for s, t in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                if not 0 <= y + s <= h - 1 or not 0 <= x + t <= w - 1:
                    continue
                if m[y + s][x + t] == '#':
                    edge.append((y, x))
                    continue
                q.appendleft((y + s, x + t))
        return edge

    def jump(i, j, c):
        q = walk(i, j)
        if vis[dh][dw]:
            return c
        nx = []
        c += 1
        while q:
            y, x = q.pop()
            for s in range(-2, 3):
                for t in range(-2, 3):
                    if not 0 <= y + s <= h - 1 or not 0 <= x + t <= w - 1:
                        continue
                    if vis[y + s][x + t]:
                        continue
                    if m[y + s][x + t] == '#':
                        continue
                    nx += walk(y + s, x + t)
                    if vis[dh][dw]:
                        return c
            if len(q) == 0:
                c += 1
                q = nx
                nx = []

    ans = jump(ch, cw, 0)
    print(ans if ans is not None else -1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 144768
import sys
from collections import deque

readline = sys.stdin.readline
ni = lambda: int(readline().rstrip())
nl = lambda: list(map(int, readline().split()))

def solve():
    n = ni()
    p = nl()
    diag = [-1, 1, n, -n]
    st = [1]*(n+2)**2
    gr = [0]*(n+2)**2
    ans = 0
    for i in range(n):
        for j in range(n):
            gr[i*n + j + n + 1] = min(min(i, j), n-1-max(i, j))
    for v in p:
        v += n
        ans += gr[v]
        st[v] = 0
        c = gr[v]
        for dv in diag:
            nv = v + dv
            c = min(c, gr[nv] + st[nv])
        gr[v]= c
        q = deque()
        q.append(v)
        while q:
            v = q.popleft()
            for dv in diag:
                nv = v + dv
                if gr[nv] > gr[v] + st[v]:
                    gr[nv] = gr[v] + st[v]
                    if st[v]:
                        q.append(nv)
                    else:
                        q.appendleft(nv)
    print(ans)
    return

if __name__ == '__main__':
    solve()


Measured memory_bytes: 171152
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a=0;string s;cin>>s;
  vector<char> t(s.size());
  for(int i=0;i<s.size();i++)t.at(i)=s.at(i);
  sort(t.begin(),t.end());
  for(int j=0;j<s.size()-1;j++){
    if(t.at(j)==t.at(j+1)){
      a++;
      break;
    }
  }
  if(a>0)cout<<"no"<<endl;
  else cout<<"yes"<<endl;
}
      


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int i;
	int a[100];
	int k, j;
	
	scanf("%d", &i);
	
	for(k=0;k<i;k++){
	scanf("%d", &a[k]);
	}
	
	for(j=(i-1);j>=0;j--){
		printf("%d", a[j]);
		
		if(j!=0){
		printf(" ");
		}
			else{
			printf("\n");
			}
		
	}
	
	return 0;
}

Measured memory_bytes: 600
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		out.println((ir.nextInt()+ir.nextInt())%24);
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 21204
#define DEBUG 0

#include <bits/stdc++.h>

using namespace std;

const int maxn = 5005;

int K, a[maxn], nums = 0;
string str, ans;

bool cmp(int a, int b) {
    int l = str.length();
    if (a < l && b < l)
        return str[a] == str[b] ? a < b : str[a] < str[b];
    else if (a >= l && b < l)
        return false;
    else return a < l && b >= l;
}

bool bfs(int st, int len) {
    int l = str.length();
    ans += str[a[st]];
    if (nums == K) {
        return true;
    }
    int p = 1;
    while (p < len && st + p < l && a[st] < l && a[st + p] < l && str[a[st]] == str[a[st + p]]) {
        p++;
    }
    len = p;
    for (int i = st; i < st + len; i++)
        a[i]++;
    sort(a + st, a + st + len, cmp);
    if (a[st] >= l) return false;
    nums++;
    return bfs(st, len);
}

int main() {
#if DEBUG
    freopen("sample.in", "r", stdin);
#endif
    int len;
    cin >> str >> K;
    len = str.length();
    for (int i = 0; i < len; i++)
        a[i] = i;
    sort(a, a + len, cmp);
    int st = 0;
    for (int i = 1; i <= len; i++) {
        if (i == len || str[a[st]] != str[a[i]]) {
            nums++;
            if (bfs(st, i - st)) {
                cout << ans << endl;
                return 0;
            }
            ans.clear();
            st = i;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define int      long long int
#define MOD      1000000007
#define pb       push_back
#define pf		 push_front
#define vi       vector<int>
#define mi  	 map<int,int>
#define umi		 unordered_map<int,int>
#define pii      pair<int,int>
#define ff 		 first
#define ss 		 second
#define inf		 1e18
#define case	int t;cin>>t;while(t--)
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int powm(int x, int y, int m = MOD) {
	x = x % m; int res = 1; while (y)
	{if (y & 1)res = res * x; res %= m; y = y >> 1; x = x * x; x %= m;} return res;
}
int modi(int a, int m = MOD) {return powm(a, m - 2, m);}
void pre()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
vi adj[100005];
int dp[100005][3];
void fn(int nd, int pr)
{	for (auto i : adj[nd])
	{	if (i != pr)
		{	fn(i, nd);
			//cout << dp[nd][1] << endl;
			dp[nd][1] *= dp[i][0];
			dp[nd][1] %= MOD;
			int tp = dp[i][0] + dp[i][1];
			tp %= MOD;
			dp[nd][0] *= tp;
			dp[nd][0] %= MOD;
		}
	}
}
int32_t main()
{	pre();
	//case
	{	int n, x, y;
		cin >> n;
		for (int i = 0; i < n - 1; i++)
		{	cin >> x >> y;
			adj[x].pb(y);
			adj[y].pb(x);
		}
		for (int i = 1; i <= n; i++)
		{	dp[i][0] = 1;
			dp[i][1] = 1;
		}
		fn(1, 0);
		int as = (dp[1][0] + dp[1][1]) % MOD;
		cout << as;
	}
	return 0;
}

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

#define pb push_back
#define all(a) a.begin(), a.end()

using ll = long long;
using pii = pair<int, int>;

const int N = 82;
int A[N][N], B[N][N];
bool dp[N][N][N * N * 2];

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int H, W; cin >> H >> W;
    for (int i = 1; i <= H; ++i)
        for (int j = 1; j <= W; ++j)
            cin >> A[i][j];
    for (int i = 1; i <= H; ++i)
        for (int j = 1; j <= W; ++j)
            cin >> B[i][j];
    dp[1][1][abs(A[1][1] - B[1][1])] = true;
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            for (int k = 0; k < N * N * 2; ++k) {
                if (dp[i][j][k]) {
                    if (i + 1 <= H) {
                        int d1 = abs(A[i + 1][j] - B[i + 1][j]);
                        dp[i + 1][j][k + d1] = true;
                        dp[i + 1][j][abs(k - d1)] = true;
                    }
                    if (j + 1 <= W) {
                        int d2 = abs(A[i][j + 1] - B[i][j + 1]);
                        dp[i][j + 1][k + d2] = true;
                        dp[i][j + 1][abs(k - d2)] = true;
                    }
                }
            }
        }
    }
    int ans = 0;
    while (!dp[H][W][ans])
        ++ans;
    cout << ans << "\n";
}

Measured memory_bytes: 86784
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- 整数の入力
    n <- readLn
    ls <- replicateM n $ do
        [p, q] <- map strToInt. words <$> getLine
        return (p, q)
    -- 出力
    putStrLn . show . sum $ map (\(l, r) -> r - l + 1) ls


Measured memory_bytes: 1404
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {
	 static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 
	 static int divisors(long x) {
		    long limit = x;
		    int numberOfDivisors = 0;

		    if (x == 1) return 1;

		    for (int i = 1; i < limit; ++i) {
		        if (x % i == 0) {
		            limit = x / i;
		            if (limit != i) {
		                numberOfDivisors++;
		            }
		            numberOfDivisors++;
		        }
		    }

		    return numberOfDivisors;
		} 
	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();		
		int x = s.nextInt();
		int n = s.nextInt();
		List<Integer> ar = new ArrayList<>();
		for(int i=0;i<n;i++) {
			int p =s.nextInt();
			ar.add(p);
		}
		int flag=0,i=0;
		while(flag==0) {
			if(!ar.contains(x-i)) {
				flag=1;
				System.out.println(x-i);
			}
			else if(!ar.contains(x+i)) {
				flag=1;
				System.out.println(x+i);
			}
			i++;
		}
	}
}

Measured memory_bytes: 32652
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll MOD = 1000000007LL;

ll extgcd(ll a, ll b, ll &x, ll &y){
  ll d = a;
  if(b!=0){
    d = extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  }else{
    x = 1; y = 0;
  }
  return d;
}

ll mod_inverse(ll a, ll m){
  ll x, y;
  extgcd(a, m, x, y);
  return (m+x%m)%m;
}

vector<ll> calc(int N){
  ll kaijo = 1;
  REP(i,1,N+1){
    kaijo *= i;
    kaijo %= MOD;
  }
  
  vector<ll> inv(N+1);
  REP(i,1,N+1){
    inv[i] = mod_inverse(i, MOD);
  }
  vector<ll> sum(N+1, 0);
  REP(i,1,N+1){
    sum[i] = (sum[i-1] + inv[i])%MOD;
  }

  vector<ll> ret(N, 0);
  rep(i,N){
    int a = i+1;
    int b = N-i;
    ret[i] = sum[a] + sum[b];
    ret[i] %= MOD;
    ret[i] += MOD - sum[1];
    ret[i] %= MOD;
    ret[i] *= kaijo;
    ret[i] %= MOD;
  }
  return ret;
}


int main(){
  int N;
  cin >> N;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  vector<ll> w = calc(N);
  ll ret = 0;
  rep(i,N){
    ret += w[i] * v[i];
    ret %= MOD;
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
const ll INF = 5e15;
int main(){
    string s;
    cin >> s;
    vector<ll> white;
    for(ll i = 0; i < s.size(); i++){
        char c = s[i];
        if(c == 'W') white.push_back(i);
    }
    vector<ll> a;
    for(ll i = 0; i < white.size(); i++) a.push_back(i);
    ll ans = 0;
    for(ll i = 0; i < white.size(); i++) ans += white[i] - a[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5108
M, D = map(int, input().split())

count = 0
for m in range(4, M+1):
    for d in range(22, D+1):
        d_ten = d // 10
        d_one = d % 10
        if m == d_one * d_ten and (d_ten >= 2) and (d_one >= 2):
            count += 1
            
print(count)

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

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

  int sum = 0;
  int count = 0;
  rep(i,(a + 1)){
    rep(j,(b + 1)){
      rep(k,(c + 1)){
        sum = 500 * i + 100 * j + 50 * k;
        if (sum == x) count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3632
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{  
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] str=br.readLine().split(" ");
        long A=Long.parseLong(str[0]);
        long B=Long.parseLong(str[1]);
        long C=Long.parseLong(str[2]);
        long D=Long.parseLong(str[3]);
        long E=(A%D==0)?A/D:A/D+1;
        long F=(C%B==0)?C/B:C/B+1;
        if(F<=E) System.out.println("Yes");
        else System.out.println("No");
        }
    }


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

int main() {
  int i, N, M, max=0;
  cin >> N;
  map <string,int> card;
  string s;

  vector<string> blue(N);

  rep(i,N) {
    cin >> blue[i];
    card[blue[i]] +=1;
  }
  cin >> M;
  rep(i,M) {
    cin >> s;
    card[s]-=1;
  }
  rep(i,N){
    if(card[blue[i]]>max) max=card[blue[i]];
  }
  
  cout << max;
}

Measured memory_bytes: 3636
a = list('abcdefghijklmnopqrstuvwxyz')
n = int(input()) - 1

ans = ""
while True:
  b = n // 26
  c = n % 26
  if b == 0:
    ans = a[c] + ans
    break
  elif b == 1:
    ans = a[b - 1] + a[c] + ans
    break
  else:
    ans = a[c] + ans
    n = b - 1
    
print(ans)

Measured memory_bytes: 9152
#include<bits/stdc++.h>
#define int			long long
#define ll 			long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define dep(i,a,b)	for(int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

void solve()
{
	ll d,t,s;
	cin>>d>>t>>s;
	if(s*t>=d)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef signed long long int ll;


int A[85][85], B[85][85];
bool dp[85][85][8500];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int H,W; cin>>H>>W;
    FOR(h,H) FOR(w,W)
    cin>>A[h][w];
    FOR(h,H) FOR(w,W)
    cin>>B[h][w];

    dp[0][0][0] = 1;

    FOR(h,H)
    FOR(w,W) 
    FOR(u,8500) {
        if(!dp[h][w][u])
            continue;
        
        int d = abs(A[h][w] - B[h][w]);
        
        if(u+d < 8500)
            dp[h+1][w][u+d] = 1;
        dp[h+1][w][abs(u-d)] = 1;

        if(u+d < 8500)
            dp[h][w+1][u+d] = 1;
        dp[h][w+1][abs(u-d)] = 1;
    }
    
    FOR(u,8500) {
        if(dp[H][W-1][u])
            EXIT(u);
    }

    return 0;
}



Measured memory_bytes: 57216
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def gcd(x, y):
    if x%y == 0:
        return y
    return gcd(y, x%y)

def lcm(x, y):
    return x*y//gcd(x, y)

def f(x):
    res = 0
    while x%2 == 0:
        x//=2
        res += 1
    return res

def main():
    N, M = map(int, readline().split())
    A = [int(i)//2 for i in readline().split()]

    t = f(A[0]) 
    for i in A:
        if f(i) != t:
            print(0)
            return

    A = [i//(2**t) for i in A] 
    M //= 2**t    

    l = 1
    for i in A:
        l = lcm(l, i)
        if l > M:
            print(0)
            return
    M //= l
    ans = (M+1)//2
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 58224
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n; cin>>n;
    map<ll,ll> m;
    vector<ll> q;
    rep(i,n){
        ll a; cin>>a;
        if(!(m.count(a))) m[a]=0;
        m[a]++;
        if(m[a]==2){
            q.push_back(a);
            m.erase(a);
        }
    }
    if((int)q.size()<2) cout<<0<<endl;
    else{
        sort(al(q)); reverse(al(q));
        cout<<q[0]*q[1]<<endl;
    }
}


Measured memory_bytes: 6528
import java.io.BufferedReader
import java.util.*

fun main() = abc138e()

@OptIn(ExperimentalStdlibApi::class)
fun abc138e() = SimpleFastIOWithToken_abc138e().exec {
    val s = readString()
    val t = readString()
    fun Char.toIndex() = this - 'a'

    val appearIndices = Array(26) { mutableListOf<Int>() }

    for ((index, sc) in s.repeat(2).withIndex()) {
        appearIndices[sc.toIndex()].add(index)
    }

    var currentIndex = s.lastIndex
    var answer = 0L

    for (tc in t) {
        val indices = appearIndices[tc.toIndex()]
        val nextIndex = indices.getOrNull(indices.upperBound(currentIndex)) ?: return@exec println(-1)
        answer += nextIndex - currentIndex
        currentIndex = nextIndex % s.length
    }

    println(answer)
}

// list must be sorted
private fun List<Int>.upperBound(key: Int): Int {
    var ng = -1
    var ok = size

    while (ok - ng > 1) {
        val mid = (ok + ng) / 2
        if (this[mid] > key) ok = mid else ng = mid
    }
    return ok
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc138e(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readStringList(size: Int): List<String> = List(size) { readString() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readIntList(size: Int): List<Int> = List(size) { readInt() }
    fun readLong(): Long = java.lang.Long.valueOf(readString())
    fun readLongList(size: Int): List<Long> = List(size) { readLong() }
    inline fun <reified T> readArray(size: Int, init: () -> T) = Array(size) { init() }
    inline fun <T> readList(size: Int, init: () -> T) = List(size) { init() }

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = print(any.toString() + separator)

    fun exec(action: SimpleFastIOWithToken_abc138e.() -> Unit) = run {
        Thread(null, { action() }, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()
    }.run { kotlin.io.print(sb) }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 46904
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;

int main() {
    long long N, Q;
    cin >> N;
    vector<long long> data(N);
    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
    }
    cin >> Q;
    vector<vector<long long>> act(Q, vector<long long> (2));
    for (int i = 0; i < Q; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> act.at(i).at(j);
        }
    }
    long long ans = 0;
    sort(data.begin(), data.end());
    vector<long long> bit(100001, 0);
    for (long long x : data) {
        ans += x;
        bit.at(x)++;
    }
    long long add;
    int sum;
    for (int i = 0; i < Q; i++) {
        add = act.at(i).at(1) - act.at(i).at(0);
        ans += bit.at(act.at(i).at(0)) * add;
        bit.at(act.at(i).at(1)) += bit.at(act.at(i).at(0));
        bit.at(act.at(i).at(0)) = 0;
        cout << ans << endl;
    }
}

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

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

  if( N%(2*D+1)==0 ){
  	cout << N/(2*D+1) << endl;
  }else{
  	cout << N/(2*D+1)+1 << endl;
  }

}

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

using namespace std;

#define forn(a, e) for (i64 a = 0; a < (i64)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logvff(a, f1, f2) {cerr << #a".{"#f1 << ", "#f2 << "} = \n"; fore(e, a) { cerr << "(" << e.f1 <<", " << e.f2 << ") ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logvff(a, f1, f2)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using i64 = long long;
using iip = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;
template<typename T> using vec = vector<T>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

// template<typename T>
// istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }

// template<typename ...T>
// istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  
  string s, t;
  cin >> s >> t;
  cout << t << s << endl;

}

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

using namespace std;

void solve() {
    int H, W;
    cin >> H >> W;

    vector<string> S(H);
    for (auto& s : S) cin >> s;

    vector<vector<bool>> on(26, vector<bool>(26, false));
    // on[x][y] => xがyより上にある

    bool judge = true;
    for (char c = 'A'; c <= 'Z'; ++c) {
        int lx = H, rx = -1, ly = W, ry = -1;
        for (int x = 0; x < H; ++x) {
            for (int y = 0; y < W; ++y) {
                if (S[x][y] != c) continue;
                lx = min(lx, x), rx = max(rx, x);
                ly = min(ly, y), ry = max(ry, y);
            }
        }

        for (int x = lx; x <= rx; ++x) {
            for (int y = ly; y <= ry; ++y) {
                if (S[x][y] == '.') {
                    judge = false;
                } else if (S[x][y] != c) {
                    // S[x][y]はcの上にある
                    on[S[x][y] - 'A'][c - 'A'] = true;
                }
            }
        }
    }

    for (int k = 0; k < 26; ++k) {
        for (int i = 0; i < 26; ++i) {
            for (int j = 0; j < 26; ++j) {
                if (on[i][k] && on[k][j]) on[i][j] = true;
            }
        }
    }


    for (int i = 0; i < 26; ++i) {
        if (on[i][i]) judge = false;
    }

    cout << (judge ? "SAFE" : "SUSPICIOUS") << endl;
}

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) solve();
    return 0;
}


Measured memory_bytes: 3088