akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

using namespace std;

typedef pair<int, int> pii;




int main() {
    int n;
    int x[100000];
    int l[100000];
    pii ps[100000];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> l[i];
        ps[i] = pii(x[i]+l[i], x[i]-l[i]);
    }
    sort(ps, ps+n);

    int cursol = -1000000000;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (cursol <= ps[i].second) {
            ans++;
            cursol = ps[i].first;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#import numpy as np

N=int(input())
AAA=input().split()
#A = np.array([int(i) for i in AAA])
A = [int(i) for i in AAA]

max_abs_index = -1

indexbox = [[-1 for i in range(2)] for j in range(2*N)]
i=0
j=0
c=-1
max_abs_index=max(range(N), key=lambda i: abs(A[i]))
while(0!=c):
    max_abs_index=max(range(N), key=lambda i: abs(A[i]))
#    print('here')
    indexbox[i][0] = A[max_abs_index]
    indexbox[i][1] = max_abs_index
    c = A[max_abs_index]
    if indexbox[i][0] < 0:
        for p in range(max_abs_index+1):
            A[p] =0
    if indexbox[i][0] > 0:
        for p in range(max_abs_index,N):
            A[p] =0
    i = i+1
#    print(indexbox)
#    print(A)
#    print(c)
#    print(i)
#print(A)    

if i == 1:
    print(0)
else:
    a = indexbox[i-2][1]
#    print(indexbox)
 #   print(a)
    if (a == 0 and indexbox[i-2][0]>0) or (a == N-1 and indexbox[i-2][0] < 0):
        pp=2*N-2
    else:
        pp = 2*N-4
    print(pp)
    if indexbox[i-2][0] > 0:
 #       print('positive')
        for j in range(a,N-1):
            print(j+1, j+2)
            print(j+1, j+2)
        for j in range(a,1,-1):
            print(j, j-1)
            print(j, j-1)
    else:
  #      print('negative')
        for j in range(a+1,N-1):
            print(j+1, j+2)
            print(j+1, j+2)
        for j in range(a+1,1,-1):
            print(j, j-1)
            print(j, j-1)
        
    




Measured memory_bytes: 3188
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class M
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (N, K) = Scanner.Scan<int, int>();
            var A = Scanner.ScanEnumerable<long>().ToArray();
            var p = (int)1e9 + 7;

            var dp = new long[K + 1];
            dp[0] = 1;
            for (var i = 0; i < N; i++)
            {
                var tmp = dp.ToArray();
                for (var j = 1; j <= K; j++)
                {
                    tmp[j] += tmp[j - 1];
                    tmp[j] %= p;
                }

                dp = tmp.ToArray();
                for (var j = 0; j <= K; j++)
                {
                    var l = j - A[i] - 1;
                    if (l < 0) continue;
                    dp[j] -= tmp[l];
                    dp[j] += p;
                    dp[j] %= p;
                }
            }

            Console.WriteLine(dp[K]);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 32648
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll D, G, p[20], c[20];

ll solve(ll st){
    ll sum = 0, cnt = 0;
    REP(i, D){
        if(st & (1 << i)){
            sum += p[i] * 100 * (i + 1) + c[i];
            cnt += p[i];
        }
    }
    while(sum < G){
        for(int i = D - 1; i >= 0; i--){
            if(st & (1 << i)) continue;
            ll d = (G - sum + 100 * (i + 1) - 1) / (100 * (i + 1));
            if(d <= p[i]){
                cnt += d;
                return cnt;
            }
            cnt += p[i];
            sum += p[i] * 100 * (i + 1);
        }
    }
    return cnt;
}

signed main(){
    cin >> D >> G;
    REP(i, D) cin >> p[i] >> c[i];
    ll ans = INT64_MAX;
    REP(i, 1 << D){
        ans = min(ans, solve(i));
    }
    PRINT(ans);
    return 0;
}

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

int k, n, v;

int main() {
  scanf("%d", &k);
  if (k <= 500) {
    printf("%d\n", k);
    for (int i = 1; i <= k; ++i) 
      for (int j = 1; j <= k; ++j) 
        printf("%d%c", i, j == k ? '\n' : ' ');
  } else {
    int n = (k + 3) / 4 * 2;
    printf("%d\n", n);
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        if (i & 1) v = (i + j) % n;
        else v = n + (i + j) % n;
        if (v >= k) v -= n;     
        printf("%d%c", v + 1, j == n ? '\n' : ' ');
      }
    }
  }
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
#define pb push_back
#define SZ(x) ((int)x.size())
#define fi first
#define se second
#define mp make_pair
const int N=100010;
int n, mk[N*3];
int main(){
	cin>>n;
	ref(i,0,17)if((1<<i)==n){
		cout<<"No"<<endl;
		return 0;
	}
    cout<<"Yes"<<endl;
	cout<<1+n<<" "<<3<<endl;
	for(int i=2;i<n;i+=2){
		cout<<1<<" "<<i<<endl; mk[i]=i;
		cout<<i<<" "<<i+1<<endl;
		cout<<1<<" "<<i+1+n<<endl; mk[i+1]=i+1+n;
		cout<<i+1+n<<" "<<i+n<<endl;
	}
	if(n%2==0){
		int m=0;
		while(!(n>>m&1))m++;
		m=1<<m;
		cout<<mk[(n-m)]<<" "<<n<<endl;
		cout<<mk[m+1]<<" "<<n+n<<endl;
	}
}

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

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  if (y == 0) return x;
  return gcd(x % y, y);
}

int main() {
  int N;
  scanf("%d", &N);
  vector<int> A(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A.at(i));
  }

  vector<int> L(N + 1, 0);
  for (int i = 0; i < N; i++) L.at(i + 1) = gcd(L.at(i), A.at(i));
  vector<int> R(N + 1, 0);
  for (int i = N - 1; i >= 0; i--) R.at(i) = gcd(R.at(i + 1), A.at(i));

  int ans = 1;
  for (int i = 0; i < N; i++) {
    ans = max(ans, gcd(L.at(i), R.at(i + 1)));
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 1408
k, n = map(int, input().split())
a = list(map(int, input().split()))


m = a[0] + k - a[n-1]

for i in range(1, n):
    if a[i] - a[i-1] > m:
        m = a[i] - a[i-1]

ans = k - m

print(ans)


Measured memory_bytes: 25840
a,b = map(int,input().split())
def h(a,b,n):
  k = 2**n
  x = a%k
  y = b%k
  l = 2**(n-1)
  if x<l and y<l:
    return(0)
  elif x < l and y >= l:
    z = y%2
    return(-z+1)
  elif x >= l and y < l:
    z = x%2
    return(z)
  else:
    z = (y-x)%2
    return(-z+1)
ll = len(bin(b)[2:])
res = []
if b%2 == 1:
  if (b-a+1)%4 in [0,3]:
    res.append(0)
  else:
    res.append(1)
else:
  if (b-a+1)%4 in [0,1]:
    res.append(0)
  else:
    res.append(1)
for i in range(1,ll):
  res.append(h(a,b,i+1))
ans = 0
for j in range(ll):
  ans += res[j]*(2**j)
print(ans)
  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;


int main()
{
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if(u==s)
        a--;
    else
        b--;
    cout<<a<<" "<<b<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n,q;
    cin >> n;
    vec<long> kosuu(100000);
    long sum=0;
    for (int i = 0; i < n; i++)
    {
        long hoge;
        cin >> hoge;
        kosuu[hoge]++;
        sum += hoge;
    }

    cin >> q;
    while (q>0)
    {
        q--;
        long b,c;
        cin >> b >> c;
        sum += kosuu[b] * (c-b);
        kosuu[c] += kosuu[b];
        kosuu[b] = 0;
        cout << sum << endl;
    }
}


Measured memory_bytes: 4052
#include <stdio.h>

int main(){
    int N,ans=0;
    scanf("%d",&N);
    int A[N],B[N],C[N-1];
    for(int i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    for(int i=0;i<N;i++){
        scanf("%d",&B[i]);
    }
    for(int i=0;i<N-1;i++){
        scanf("%d",&C[i]);
    }
    for(int i=0;i<N;i++){
        ans+=B[i];
    }
    for(int i=0;i<N-1;i++){
        if(A[i+1]==A[i]+1){
            ans+=C[A[i]-1];
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int min(int a,int b)
{
	if(a > b) return b;
	else return a;
}
int main(void)
{
	int N;
	scanf("%d",&N);
	int A[N],B[N-1];
	int i;
	for(i=0;i<N-1;i++)
	{
		scanf("%d",&B[i]);
	}
	A[0] = B[0];
	for(i=1;i<N-1;i++)
	{
		A[i] = min(B[i],B[i-1]);
	}
	A[N-1] = B[N-2];
	int ans = 0;
	for(i=0;i<N;i++){
		//printf("i = %d, A[i] = %d\n",i,A[i]);
		ans += A[i];
	}
	
	printf("%d",ans);
	return 0;
}





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

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

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  cout << (x-a)%b << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stack>
#include<utility>
#include<vector>
int main(void) {
	std::string Input;
	std::cin >> Input;
	std::stack<int> PlaceBackSlash;
	std::stack<std::pair<int, int> >Puddle_Place_Quantity;
	for (unsigned int i = 0; i < Input.size(); ++i) {
		if (Input[i] == '\\') { PlaceBackSlash.push(i); }
		else if (Input[i] == '/') {
			if (!(PlaceBackSlash.empty())) {
				//???????????????????????\?????´???
				int PlaceFirstBackSlash = PlaceBackSlash.top();
				PlaceBackSlash.pop();
				int Quantity = 0;
				//??????????????\??¨?°´?????????????????????????????\??\???????°´???????¶??????????
				while (!(Puddle_Place_Quantity.empty()) && Puddle_Place_Quantity.top().first > PlaceFirstBackSlash) {
					Quantity += Puddle_Place_Quantity.top().second; Puddle_Place_Quantity.pop();
				}
				//?????????????????????????????????????????\??\???????°´??????????????????
				Puddle_Place_Quantity.push(std::pair<int, int>(PlaceFirstBackSlash, i - PlaceFirstBackSlash + Quantity));
			}
		}
	}
	int TotalQuantity = 0;
	std::vector<int> Puddle_Quantity(Puddle_Place_Quantity.size());
	for (unsigned int i = 0; i < Puddle_Quantity.size(); ++i) {
		Puddle_Quantity[i] = Puddle_Place_Quantity.top().second;
		Puddle_Place_Quantity.pop();
		TotalQuantity += Puddle_Quantity[i];
	}
	std::cout << TotalQuantity << std::endl;
	std::cout << Puddle_Quantity.size();
	for (int i = Puddle_Quantity.size() - 1; i >= 0; --i) {
		std::cout << " " << Puddle_Quantity[i];
	}
	std::cout << std::endl;
//	system("pause");
	return 0;
}

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

int main(void)
{
    int a,b,c;
    int i,ans;

    cin >> a >> b >> c;

    ans = 0;
    for (i=a;i<=b;++i)
    {
        if (c % i == 0)
            ++ans;
    }

    cout << ans << endl;
}



Measured memory_bytes: 3092
//h10-1 旅人(Atcoder)
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -21474836487
#define INT_MAX 2147483647
#define LL_MIN -922337203685477580
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int n,m;
int dis[100005];
int a[100005];
int dp[100005];
 
int main(){
     
    cin >> n >> m;
    dis[0] = 0;
    dp[0] = 0;
    for(int i=1; i<n; i++){
        cin >> dis[i];
        dp[i] = dp[i-1] + dis[i];
    }

    int now = 0;
    LL ans = 0;
    for(int i=0; i<m; i++){
        cin >> a[i];
        int goal = now + a[i];
        if(a[i] > 0){
            ans += dp[goal] - dp[now];
        }
        else{
            ans += dp[now] - dp[goal];
        }
        ans = ans%100000;
        
        now = goal;
    }
 
    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 4252
#include <iostream>
#include <stack>

int main ()
{
    std::stack<u_int> cars;
    u_int number;

    while(std::cin >> number){
        if(number != 0){
            cars.push(number);
        }else{
            std::cout << cars.top() << std::endl;
            cars.pop();
        }
    }
    
    return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

ll gcd( ll a, ll b )
{
    ll temp;

    if( a < b ) { temp = a; a = b; b = temp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return gcd( b, a % b );
}

void solve(){

    ll k;
    cin >> k;
    ll ans = 0;
    rep(i,k){
        rep(j,k){
            rep(l,k){
                ans += (gcd(gcd(i+1,j+1), l+1));
            }
        }
    }
    cout << ans << endl;

}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

int main(){
	int n;
	int a[110];
	cin>>n;
	rep(i,n) cin>>a[i];
	double ans=0;
	double sum=0;
	rep(i,n) sum += 1/(double)a[i]; 
	ans = 1/sum;
	cout<<ans<<endl;
	return 0;		
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
    int d,g;
    cin>>d>>g;
    vector<int> p(d),c(d);
    for(int i=0;i<d;i++)cin>>p[i]>>c[i];
    int ans=(int)1e9;
    for(int bit=0;bit<(1<<d);bit++){
        int sum=0;
        int cnt=0;
        for(int i=0;i<d;i++){
            if(bit & 1<<i){
                sum+=100*(i+1)*p[i];
                sum+=c[i];
                cnt+=p[i];
            }
        }
        int j=d-1;
        while(sum<g){
            if(!(bit & 1<<j)){
                if(sum+100*(j+1)*p[j]+c[j]<g){
                    sum+=100*(j+1)*p[j]+c[j];
                    cnt+=p[j];
                }
                else {
                    int q=p[j];
                    while(sum<g && q>0){
                        sum+=100*(j+1);
                        cnt++;
                        q--;
                    }
                    sum+=c[j];
                }
                
            }
            j--;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}

   


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

using namespace std;

int main(void)
{
    int N, X, answer = 1, move = 0;
    cin >> N >> X;
    vector<int> L(N);
    for (int count = 0; count < N; count++)
    {
        cin >> L.at(count);
    }
    for (int count = 0; count < N; count++)
    {
        move += L.at(count);
        if (move > X)
        {
            break;
        }
        else
        {
            answer++;
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
    
    long x = sc.nextLong();
    long y = sc.nextLong();
    long z = sc.nextLong();    
    long k = sc.nextLong();  
    
    if (x <= k){
      if (x + y >= k){
      	System.out.println(x);
      }else{
        System.out.println(x + (-1*(k - x - y)));
      }
     }else{
      	System.out.println(k);
     }
    
  }
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll a,b;
	ll ans=0ll;
	cin >>n;
	VP data(n);
	rep(i,n){
		cin>>a>>b;
		data[i]=mp(a+b,a);
	}
	sort(all(data),greater<pair<ll,ll>>());
	rep(i,n){
		ans -= data[i].F-data[i].S;
		if(i%2==0){
			
			ans+=data[i].F;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }

const LL MAX_LEN = 1e+18;

void shortest_path1(vector<vector<pair<LL,LL>>>& graph, LL l){
    LL n = graph.size();
    for(LL k = 0; k < n; ++k){
        for(LL i = 0; i < n; ++i){
            for(LL j = 0; j < n; ++j){
                if(graph[i][k].second == MAX_LEN || graph[k][j].second == MAX_LEN) continue;
                if(graph[i][k].second + graph[k][j].second > l) continue;
                if(graph[i][j].second == MAX_LEN){
                    graph[i][j].second = graph[i][k].second + graph[k][j].second;
                }else{
                    graph[i][j].second = min(graph[i][j].second, graph[i][k].second + graph[k][j].second);
                }
            }
        }
    }
}

void shortest_path(vector<vector<pair<LL,LL>>>& graph, LL l){
    LL n = graph.size();
    for(LL k = 0; k < n; ++k){
        for(LL i = 0; i < n; ++i){
            for(LL j = 0; j < n; ++j){
                if(graph[i][k].second == MAX_LEN || graph[k][j].second == MAX_LEN) continue;
                pair<LL,LL> dist = pair<LL,LL>(graph[i][k].first + graph[k][j].first + 1, graph[k][j].second);
                if(graph[i][j].second == MAX_LEN){
                    graph[i][j] = dist;
                }else{
                    graph[i][j] = min(graph[i][j], dist);
                }
            }
        }
    }
}


int main(){
    LL n, m, l;
    cin >> n >> m >> l;
    vector<vector<pair<LL,LL>>> mat(n, vector<pair<LL,LL>>(n, pair<LL,LL>(0, MAX_LEN)));
    for(LL i = 0; i < m; ++i){
        LL a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        if(c > l) continue;
        mat[a][b] = pair<LL,LL>(0, c);
        mat[b][a] = pair<LL,LL>(0, c);
    }
    shortest_path1(mat, l);
    shortest_path(mat, l);
    LL q;
    cin >> q;
    for(LL i = 0; i < q; ++i){
        LL s, t;
        cin >> s >> t;
        --s; --t;
        if(mat[s][t].second == MAX_LEN){
            cout << -1 << endl;
        }else{
            cout << mat[s][t].first << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 1920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		int n = Integer.parseInt(reader.readLine());
		Pattern pattern = Pattern.compile("that|this");
		while (n-- > 0) {
			String result = reader.readLine();
			String a = result;
			loop: for (int i = 1; i < 26; i = i + 2) {
				for (int j = 0; j < 26; j++) {
					a = rep(result, i, j);
					
					if (pattern.matcher(a).find()) {
						builder.append(a).append('\n');
						break loop;
					}
				}
			}
		}
		System.out.print(builder);
	}

	private static String rep(String a, int i, int j) {
		char[] chs = a.toCharArray();
		for (int k = 0; k < a.length(); k++) {
			if ('a' <= chs[k] && chs[k] <= 'z') {
				int b = chs[k] - 'a';
				chs[k] = (char) ((b * i + j) % 26 + 'a');
			}
		}
		return String.valueOf(chs);
	}
}

Measured memory_bytes: 21596
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <deque>
#include <numeric>
#include <set>
using namespace std;

typedef long long ll;

const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toid(int i, int j){
    if(i > j)   swap(i, j);
    return id[i][j];
}

bool visited[MAXV];     // 訪問済みフラグ
bool calculated[MAXV];  // 計算済みフラグ
int dp[MAXV];           // 距離
int dfs(int v){
    if(visited[v]){
        // 計算済みでない場合に、訪問済みの頂点に訪れた場合、閉路を検出した。
        if(!calculated[v])   return -1;

        return dp[v];
    }

    visited[v] = true;
    dp[v] = 1;
    for(auto u : to[v]){
        int res = dfs(u);
        // 閉路を検出すれば、-1を返す。
        if(res == -1)   return -1;
        dp[v] = max(dp[v], res + 1);
    }
    
    calculated[v] = true;
    return dp[v];
}

int main(){
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n-1));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n-1; ++j){
            cin >> a[i][j];
            --a[i][j];
        }
    }

    int V = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(i < j)   id[i][j] = V++;
        }
    }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n - 1; ++j){
            a[i][j] = toid(i, a[i][j]);
        }
        for(int j = 0; j < n - 2; ++j){
            to[a[i][j + 1]].push_back(a[i][j]);
        }
    }

    int ans = 0;
    for(int i = 0; i < V; ++i){
        int res = dfs(i);
        if(res == -1){
            puts("-1");
            return 0;
        }
        ans = max(ans, res);
    }

    cout << ans << endl;
}

Measured memory_bytes: 38528
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;

const int INF = 2000000000;
const double pi = 3.1415926;
const int base = 1000000007;

int n, x[100000], sum, ans;


int main()
{
    //ifstream cin ("sysadmin.in");
    //ofstream cout ("sysadmin.out");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(20);
    cin >> n;
    for (int i = 0 ;i < n; i++)
    {
        cin >> x[i];
        sum += x[i];
    }
    sum = (int) round((double) sum / n);
    for (int i = 0; i < n; i++)
    {
        ans += (x[i] - sum) * (x[i] - sum);
    }
    cout << ans;
    return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;

    vector<int> b(N);
    cin >> b[0];
    int g = b[0];
    for(int i = 1; i < N; ++i) {
        cin >> b[i];
        g = __gcd(g, b[i]);
    }

    if(g != 1) {
        cout << "not coprime" << endl;
        return 0;
    }

    sort(all(b), greater<>());

    bool a[1000005] = {};
    vector<LL> d;
    bool f = true;
    for(int i = 0; i < N; ++i) {
        if(a[b[i]]) {
            f = false;
            cout << "setwise coprime" << endl;
            return 0;
        }
        d = Div(b[i]);
        for(int j = 1; j < d.size(); ++j) {
            if(a[d[j]]) {
                cout << "setwise coprime" << endl;
                return 0;
            }
            a[d[j]] = true;
        }
    }

    if(f) cout << "pairwise coprime";
    else if(g == 1) cout << "setwise coprime";
    else cout << "not coprime";
    cout << endl;

    return 0;
}

Measured memory_bytes: 8168
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n;cin>>n;
	if(1200>n) cout<<"ABC";
	else cout<<"ARC";
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl 

const int N = 1e5;
ll dp[N][3];
int n , a[N][3] , k;

ll calc (int idx , int last){

    if (idx == n)
        return 0;

    ll &ret = dp[idx][last];
    if (~ret)
        return ret;

    ret = 0;

    for (int i = 0 ; i < 3 ; ++i){
        if (last != i)
            ret = max (ret , calc(idx+1,i) + a[idx][i]);
    }

    return ret;

} 

void Suhaib_Sawalha (){

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

    memset(dp,-1,sizeof dp);
    cout << max({calc(1,0) + a[0][0] , calc(1,1) + a[0][1] , calc(1,2) + a[0][2]});

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}

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

int main(void) {
  int n;
  string s;
  cin >> n >> s;
  int maxcnt = 0;
  for (int i = 0; i < n; i++) {
    vector<int> a(26), b(26);
    for (int j = 0; j < n; j++) {
      if (j < i) {
        a[s[j] - 'a']++;
      } else {
        b[s[j] - 'a']++;
      }
    }
    int cnt = 0;
    for (int j = 0; j < 26; j++) {
      if (a[j] && b[j]) cnt++;
    }
    maxcnt = max(maxcnt, cnt);
  }
  cout << maxcnt << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
//ll _pfact(ll a);
//static ll pf[100000000];
//static ll pc;
//
//ll _pfact(ll a) {
//	long i, r;
//	if (a % 2 == 0) {
//		pf[pc] = 2; pc++;
//		return(_pfact(a / 2));
//	}
//	r = sqrt(a);
//	for (i = 3; i <= r; i += 2) {
//		if (a % i == 0) {
//			pf[pc] = i; pc++;
//			return(_pfact(a / i));
//		}
//	}
//	if (a != 1) {
//		pf[pc] = a; pc++;
//	}
//	return 0;
//
//}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}
// 立っている ビットの数
int bitcount(unsigned int uc);
int bitcount(unsigned int uc)
{
	int bit;

	for (bit = 0; 0 != uc; uc = (unsigned int)(uc >> 1))
		if (0 != (uc & 1))++bit;

	return bit;
}//bitco

#define _rnd(a,b)    ((a+b-1)/b) //　A/Bの余りを繰り上げる

#pragma endregion

// ABC085 A-  Already 2018
int main(void) {
	char s[101],t[101];
	int l;
	
	scanf("%s",s); scanf("%s",t); 
	
	qsort(s, strlen(s), sizeof(char), s_asort);
	qsort(t, strlen(t), sizeof(char), s_dsort);

	(strcmp(s, t) >=0)?printf("No\n"): printf("Yes\n");

	return 0;
}

Measured memory_bytes: 1664
N, Y = map(int, input().split())
exit = False

for i in range(N+1):
    if exit == True:
        break
    for j in range(N-i+1):
        if exit == True:
            break
        k = N - i - j
        if 10000*i + 5000*j + 1000*k == Y:
            exit = True
            print("{} {} {}".format(i, j, k))
            
if exit == False:
    print("-1 -1 -1")

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


int64_t gcd(int64_t a, int64_t b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int64_t lcm(int64_t a, int64_t b)
{
   return a * b / gcd(a, b);
}

int main() {

    int64_t a,b,c,d;
    cin>>a>>b>>c>>d;


    int64_t div_n_lcm =b/lcm(c,d)-(a-1)/lcm(c,d);
    int64_t div_n_c = b/c-(a-1)/c;
    int64_t div_n_d = b/d-(a-1)/d;
    cout<<(b-a+1)-div_n_c-div_n_d+div_n_lcm<<endl;

    return 0;
}


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

using namespace std;

int main(int argc, char* argv[])
{

	int A[3];

	cin >> A[0] >> A[1] >> A[2];

	cout << max(A[0],max(A[1],A[2])) -min(A[0],min(A[1],A[2])) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll k;
    cin >> k;

    ll cnt = 0;
    rep(i, k) {
        rep(j, k) {
            rep(l, k) { cnt += gcd(i + 1, gcd(j + 1, l + 1)); }
        }
    }
    cout << cnt;
}


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		var ans="Yes";
		for(int i = 1;i<n;i++) {
			if(a[i]>a[i-1]){a[i]--;}
		}
		for(int i = 1;i<n;i++) {
			if(a[i]<a[i-1]){ans="No";}
		}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 25052
/*
 * atcoder/abc093_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * A, B, Cのうち２つを+1するか１つを+2してすべて等しくする
 * i) すべて異なる場合: 最小値を+2
 * ii) ２つ等しくて１つが小さい場合 +2
 * iii) ２つ等しくて1つが大きい場合+1
 */
ll J[3];
void solve() {
  cin >> J[0] >> J[1] >> J[2];
  ll count = 0;
  while (J[0] != J[1] or J[1] != J[2]) {
    count++;
    sort(J, J+3);
    if (J[0] < J[1] and J[1] < J[2]) {
      J[0] += 2;
      continue;
    }

    if (J[1] == J[2]) {
      J[0]+=2;
      continue;
    }

    J[0]++;J[1]++;
  }
  cout << count << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 100005
using namespace std;
typedef long long ll;
int n,pos=1;
int a[maxn];
ll b[2][maxn];
ll ans,len[2],res[2];
int tot=0;
int op[maxn];
void solve()
{
	for(int i=1;i<b[pos][1];i++)
		op[++tot]=1;
//	cerr<<"+1"<<endl;
	for(int i=n;i>b[pos][len[pos]];i--)
		op[++tot]=i-b[pos][1]+1;
//	cerr<<"+1"<<endl;
	for(int i=2;i<=len[pos];i++)
	{
		int sz=(b[pos][i]-b[pos][i-1])/2;
		for(int j=sz+1;j>1;j--)
			op[++tot]=j;
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>a[pos])
			pos=i;
	}
	if(a[pos]<=0)
	{
		res[0]=a[pos];
		b[0][++len[0]]=pos;
		pos=0;
	}
	else
	{
		for(int i=1;i<=n;i+=2)
			if(a[i]>0)
				b[0][++len[0]]=i,res[0]+=a[i];
		for(int i=2;i<=n;i+=2)
			if(a[i]>0)
				b[1][++len[1]]=i,res[1]+=a[i];
		if(res[0]>res[1])
			pos=0;
		else
			pos=1;
	}
//	cerr<<"+1"<<endl;
	solve();
	printf("%lld\n%d\n",res[pos],tot);
	for(int i=1;i<=tot;i++)
		printf("%d\n",op[i]);
}


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

const int MAX_N = 10010;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> Array;
typedef vector<Array> Graph;
typedef pair<double, double> pdd;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int N;
    cin >> N;
    ll a[3*N];
    REP(i, 3*N) cin >> a[i];
    vector<ll> pre(N+1), post(N+1);
    priority_queue<ll, vector<ll>, greater<ll> > que1;
    ll tmp1 = 0;
    REP(i, N){
        que1.push(a[i]);
        tmp1 += a[i];
    }
    pre[0] = tmp1;
    for(int i=0;i<N;i++){
        ll x = que1.top();
        if(x < a[N+i]){
            que1.pop();
            que1.push(a[N+i]);
            tmp1 += a[N+i] - x;
        }
        pre[i+1] = tmp1;
    }

    reverse(a, a+3*N);
    priority_queue<ll> que2;
    ll tmp2 = 0;
    REP(i, N){
        que2.push(a[i]);
        tmp2 += a[i];
    }
    post[N] = tmp2;
    for(int i=0;i<N;i++){
        ll x = que2.top();
        if(x > a[N+i]){
            que2.pop();
            que2.push(a[N+i]);
            tmp2 += a[N+i] - x;
        }
        post[N-i-1] = tmp2;
    }
    ll res = -LLONG_MAX/3;
    REP(i, N+1){
        res = max(res, pre[i]-post[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6516
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	double takasa;
	double ans;
    vector<double>  data;


	while(cin >> takasa)
	{
		data.push_back(takasa);
	}

	stable_sort(data.begin(), data.end());

	ans = data.back() - data.front();

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 1304
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

char S[SIZE];
char T[SIZE];
vector<ll> V[26];


int main(){

	scanf("%s",S);

	int len_S = 0;
	for(ll i = 0; S[i]!= '\0'; i++,len_S++){

		V[S[i]-'a'].push_back(i);
	}
	scanf("%s",T);

	int len_T = 0;
	for(ll i = 0; T[i] != '\0'; i++,len_T++){

		if(V[T[i]-'a'].size() == 0){

			printf("-1\n");
			return 0;
		}
	}

	int loc = 0;
	ll ans = 0;

	while(loc < len_T){

		ll pos = -1;

		while(true){
			int next_ch = T[loc]-'a';

			if(V[next_ch][V[next_ch].size()-1] <= pos)break;

			int index = upper_bound(V[next_ch].begin(),V[next_ch].end(),pos)-V[next_ch].begin();

			pos = V[next_ch][index];

			loc++;
			if(pos == len_S-1)break;
			if(loc == len_T)break;
		}

		if(loc == len_T){

			ans += pos+1;
			break;

		}else{

			ans += len_S;
		}
	}

	printf("%lld\n",ans);

	return 0;
}


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

struct Node {
    int parent;
    int lc, rc;
};

#define NIL -1

vector<Node> tree;

void pre(int n) {
    if (n == NIL) return;
    cout << " " << n;
    pre(tree[n].lc);
    pre(tree[n].rc);
}

void in(int n) {
    if (n == NIL) return;
    in(tree[n].lc);
    cout << " " << n;
    in(tree[n].rc);
}

void post(int n) {
    if (n == NIL) return;
    post(tree[n].lc);
    post(tree[n].rc);
    cout << " " << n;
}

int main() {
    int n;
    cin >> n;
    int i;
    rep(i, n) { // init
        Node node;
        node.parent = NIL;
        node.lc = NIL;
        node.rc = NIL;
        tree.push_back(node);
    }

    rep(i, n) { // input
        int id, l, r;
        cin >> id >> l >> r;
        tree[id].lc = l;
        tree[id].rc = r;
        if (l != NIL) tree[l].parent = id;
        if (r != NIL) tree[r].parent = id;
    }

    // search root
    int root;
    rep(i, n) {
        if (tree[i].parent == NIL)
            root = i;
    }

    cout << "Preorder" << endl;
    pre(root);
    cout << endl;
    cout << "Inorder" << endl;
    in(root);
    cout << endl;
    cout << "Postorder" << endl;
    post(root);
    cout << endl;

    return 0;
}



Measured memory_bytes: 3144
N,M=list(map(int,input().strip().split(' ')))
A=[]
for _ in range(N):
    A+=[list(map(int,input().strip().split(' ')))[::-1]]
    
current=[0]*(M+1)
deleted=[0]*(M+1)

for j in range(N):
    current[A[j][-1]]+=1
    
#print(current)    
MAX=max(current)
ANS=MAX
index=-1
for j in range(1,len(current)):
    if current[j]==MAX:
        index=j
good=0       
if MAX==1:
    good=1
    print(1)
if good==0:
    count=0
    while(count<M-1):
        current=[0]*(M+1)
        deleted[index]=1
        for x in range(N):
            while(deleted[A[x][-1]]==1):
                A[x].pop()
                if A[x]==[]:
                    break
        for x in range(N):
            if A[x]!=[]:
                current[A[x][-1]]+=1
        MAX=max(current)
        if MAX<ANS:
            ANS=MAX
        for x in range(M+1):
            if current[x]==MAX:
                index=x
                
        count+=1  
    print(ANS)    
            
                
        

Measured memory_bytes: 44252
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;

int main(void) {
	i64 n, k, ans = 0;
	vector<i64> a;
	vector<pair<i64, i64> > c;
	string s;
	cin >> n >> k >> s;
	if (s[0] == '0') c.push_back({'1', 0});
	for (i64 i = 0; i < n; i++) {
		if (c.size() == 0 || c.back().first != s[i]) c.push_back({s[i], 1});
		else c.back().second++;
	}
	if (s.back() == '0') c.push_back({'1', 0});
	/*for (i64 i = 0; i < c.size(); i++) cout << c[i].second << ' ';
	cout << endl;*/
	a.push_back(0);
	for (i64 i = 0; i < c.size(); i++) a.push_back(a.back() + c[i].second);
	for (i64 i = 0; i < c.size(); i++) {
		if (c[i].first == '0') continue;
		/*cout << min((int)(i + k * 2 + 1), (int)c.size()) << ' '
			<< max((int)i, 0) << ' '
			<< a[min((int)(i + k * 2 + 1), (int)c.size())] - a[max((int)i, 0)] << endl;*/
		ans = max(a[min((int)(i + k * 2 + 1), (int)c.size())] - a[max((int)i, 0)], ans);
	}
	cout << ans << endl;
}

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

int main(){

  int N, ans=0, num=0;
  string S;
  cin >> N >> S;

  int mx[N];

  for(int i=0; i<S.size(); i++){
    num += S[i] == 'I' ? 1 : -1 ;
    ans = max(ans, num);
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int n; cin>>n;
    map<string,int> t;
    for(int i=0;i<n;i++){
        string s; cin>>s;
        t[s]++;
    }
    int m; cin>>m;
    for(int i=0;i<m;i++){
        string s; cin>>s;
        t[s]--;
    }
    int num=0;
    for(auto a:t){
        if(a.second>num) num=a.second;
    }
    if(num>0) cout<<num<<endl;
    else cout<<0<<endl;
}

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

#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define rrep(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,n) rep(i,0,n)
#define RREP(i,n) rrep(i,n,0)

int main()
{
    int a,b;
    cin>>a>>b;
    if(a<=5)
    {
        cout<<"0"<<endl;
    }
    else if(a>=6&&a<=12)
    {
        cout<<b/2<<endl;
    }
    else{
        cout<<b<<endl;
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np

N = np.int64(input())
a = np.array([int(x) for x in input().split()])

mod_a = np.mod(a, 4)
count4 = (mod_a==0).sum()
count2 = (mod_a==2).sum()
odd = ((mod_a==1) | (mod_a==3)).sum()
if N % 2 == 0:
    if count4 >= odd:
        print('Yes')
    else:
        print('No')
else:
    if count4 >= odd - 1:
        print('Yes')
    else:
        print('No')


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

a_max = 10**5
cnts = [0]*(a_max+1)
for a in A:
    if a >= 1:
        cnts[a - 1] += 1
    cnts[a] += 1
    if a <= a_max - 1:
        cnts[a + 1] += 1

print(max(cnts))


Measured memory_bytes: 10712
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	int n;
	cin >> n;
	vector<vector<ll>> l(n);
	rep(i, n) {
		int a, b, c;
		cin >> a >> b >> c;
		l[i].push_back(a);
		l[i].push_back(b);
		l[i].push_back(c);
	}

	vector<vector<ll>> dp(100010, vector<ll>(3, -1));
	rep(i, 3) {
		dp[0][i] = 0;
	}
	rep(i, n) {
		rep(j, 3) {
			rep(k, 3) {
				if (j != k) {
					chmax(dp[i + 1][k], dp[i][j] + l[i][k]);
				}
			}
		}
	}
	ll ans = 0;
	rep(i, 3) {
		ans = max(ans, dp[n][i]);
	}
	cout << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}

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

if sum(A) > sum(B):
    print('No')
    exit()

d = 0
for i in range(N):
    if B[i] > A[i]:  # B[i]の方が大きい時
        d += (B[i]-A[i])//2
    else:  # A[i]がB[i]以上の時
        d -= A[i]-B[i]

if d >= 0:
    print('Yes')
else:
    print('No')

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

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;


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

    n = n % 10;
    if(n == 3){
        cout << "bon" << endl;
    }
    else if(n == 0 || n == 1 || n == 6 || n == 8){
        cout << "pon" << endl;
    }
    else{
        cout << "hon" << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$m = (int)$input[1];

$input = explode(' ', trim(fgets(STDIN)));
$sum = 0;
$a_list =[];
foreach ($input as $v) {
	$a_list[] = (int)$v;
	$sum += (int)$v;
}
$limit = $sum / (4 * $m);

rsort($a_list);

if ($a_list[$m-1] < $limit) {
	echo 'No';
}else {
	echo 'Yes';
}

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

int main(){
    int i;
    unsigned long long r,d,x,num;
    cin>>r>>d>>x;

    for(i=1;i<=10;i++){
        num = r*x-d;
        cout<<num<<"\n";
        x=num;
    }
    return 0;
}


Measured memory_bytes: 256