akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
using LL = long long;
using VLL = std::vector<LL>;
using VVLL = std::vector<VLL>;
using VVVLL = std::vector<VVLL>;
using LD = long double;
using VLD = std::vector<LD>;
using VVLD = std::vector<VLD>;
using VVVLD = std::vector<VVLD>;
using BL = bool;
using VBL = std::vector<BL>;
using VVBL = std::vector<VBL>;
using VVVBL = std::vector<VVBL>;


template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }

//template<class T=LL> inline vector<T> cinv(LL N){ vector<T> v(N); REP(i, N)cin>>v[i]; return move(v);}
//template<class T=LL> inline vector<T> cinv(LL N){ vector<T> v(N); REP(i, N)cin>>v[i]; return move(v);}
#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define REPM(i,n,m) for(LL (i)=m;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
//#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl

template<class T> 
void PRINTSP(vector<T> v, size_t w=3){
  for(auto (a): v ) {cerr <<setw(w)<< a << " ";} cerr << endl;
} 

#define cmax(a,b) {if(a<b){a=b;}}
#define cmin(a,b) {if(a>b){a=b;}}
#define EACH(a,A) for(auto a: A)
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 
//cin,cout高速化のおまじない＋桁数指定
inline VLL cinvll(LL N, LL minus = 0){
  VLL A(N);
  REP(i,N){
    cin >> A[i];
    A[i] -= minus;
  }
  return move(A);
}
inline VVLL zerosll(LL H, LL W, LL val=0){
  VVLL A(H,VLL(W,val));
  return move(A);
}
struct Fast{
	Fast(){
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
	}
} fast;

void func(){
  LL N;
  cin >> N;
  LL Ma;
  cin >> Ma;
  LL Mb;
  cin >> Mb;

  VLL A(N);
  VLL B(N);
  VLL C(N);
  REP(i,N){
    cin >> A[i];
    cin >> B[i];
    cin >> C[i];
  }
  const size_t DP_SIZE =  500;
  const size_t MAX_COST = 1e9;
  VVVLL DP(N+1,VVLL(DP_SIZE,VLL(DP_SIZE,MAX_COST)));
  /*
  REP(j,DP_SIZE){
    REP(k,DP_SIZE){
      DP[0][j][k]=0;
    }
  }
  */
  DP[0][0][0]=0;
  REP(i,N){
    LL a = A[i];
    LL b = B[i];
    LL c = C[i];
    REP(j,DP_SIZE){
      REP(k,DP_SIZE){
      //DP[i+1][j][k] = min(DP[i][j][k],DP[i][j-a][k-b]+c);
        DP[i+1][j][k] = DP[i][j][k];
        if(j-a>=0 and k-b>=0){
          DP[i+1][j][k] = min(DP[i][j][k],DP[i][j-a][k-b]+c);
        }
      }
    }

  }



  LL min_cost = MAX_COST;
  REPM(i,DP_SIZE,1){
    LL j = i*Ma;
    LL k = i*Mb;
    if(j<DP_SIZE and k<DP_SIZE){
      chmin(min_cost,DP[N][j][k]);
    }
  }
  if(min_cost==MAX_COST){
    cout << -1;
  }
  else{
    cout << min_cost;
  }
} 


int main()
{
  func();
  return 0;
}
 

Measured memory_bytes: 83072
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

ll gcd(ll a, ll b){
  ll temp;
	while (a % b != 0){
		temp = b;
		b = a % b;
		a = temp;
	}
	return b;
}

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

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};


int main(){
    int N;
    string S_original,S;
    cin >> N;
    cin >> S_original;

    int max_len = 0;
    rep(p,N){
        S = S_original.substr(p);
        int A[5002];
        A[0] = S.size();
        int i = 1, j = 0;
        while (i < S.size()) {
        while (i+j < S.size() && S[j] == S[i+j]) ++j;
        A[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k;
        i += k; j -= k;
        }

        rep(i,N){
            A[i] = min(A[i], i);
            if (A[i] > max_len) max_len = A[i];
            // cout << A[i] << endl;
        }
    }

    cout << max_len << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long cr[50],p,n,m,a[50],c[50][50],ans,k,F;
void go(int cur,int r,long long x){
	
	for(k=1;k<=m;k++){
		cr[k]+=r*c[cur][k]; 
	}
	
	int f=0;
	for(k=1;k<=m;k++){
		if(cr[k]<p) f=1;
	}
	
	//cout<<cur<<" "<<r<<" "<<x<<endl;
	if(f==0){ ans=min(ans,x+a[cur]*r);
	F=1;  }
	if(cur!=n){
		go(cur+1,0,x+a[cur]*r);
		go(cur+1,1,x+a[cur]*r);
	}
	for(k=1;k<=m;k++){
		cr[k]-=r*c[cur][k]; 
	}
}
int main(){
	cin>>n>>m>>p;
	for(k=1;k<=n;k++)
	{
		cin>>a[k];
		for(int i=1;i<=m;i++){
			cin>>c[k][i];
		}
	}
	ans=1e10;
	go(1,0,0);
	go(1,1,0);
	
	if(F==0) cout<<-1;
	else cout<<ans;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int n;cin >> n;
    int ans = 0;
    for(int i=1;i<=50000;i++){
        if((i*108-n*100)>=0 && (i*108-n*100)<=99)ans=i;
    }
    if(ans!=0)cout << ans << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n;
    cin >> n;
    vector<double> a(n);
    rep(i,n) cin >> a[i];
    vector<double> b = a;
    sort(all(b));
    rep(i,n){
        double in = a[i];
        int ans = 0;
        int ind1 = lower_bound(all(b),in) - b.begin();
        int ind2 = upper_bound(all(b),in) - b.begin();
        if(ind1){
            ans += ind1*3;
        }
        ans += max(ind2 - ind1 - 1,0LL);
        cout << ans << endl;
    }

}



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

int main()
{
  ll N,M;
  ll count=0;
  cin>>N>>M;
  string ans="No";
  vector<ll>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end(),greater<ll>());
  ll sum=accumulate(A.begin(),A.end(),0);
  for(int i=0;i<M;i++){
    double line=(double)sum/(4*M);
    if(A[i]>=line){
      count++;
    }
  }
  if(count==M){
    ans="Yes";
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static final FS sc = new FS();  // 封装输入类
    static final PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int res = n % 1000;
        pw.println(res == 0 ? 0 : 1000 - res);
        pw.flush();
    }

    static class FS {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        String next() {
            while(!st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch(Exception ignored) {}
            }
            return st.nextToken();
        }
        int[] nextArray(int n) {
            int[] a = new int[n];
            for(int i = 0;i < n;i++) {
                a[i] = nextInt();
            }
            return a;
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 32828
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

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

int main()
{
    int n,x;
    cin>>n>>x;
    if(x==1 || x==2*n-1){
        cout<<"No\n";
        return 0;
    }
    cout<<"Yes\n";
    if(x<=n){
        for(int ctr1=2;ctr1<=n;ctr1++)
            if(ctr1!=x)
                cout<<ctr1<<"\n";
        cout<<2*n-1<<"\n1\n"<<x<<"\n";
        for(int ctr1=n+1;ctr1<2*n-1;ctr1++)
            cout<<ctr1<<"\n";
    }
    else{
        for(int ctr1=2;ctr1<n;ctr1++)
            cout<<ctr1<<"\n";
        cout<<x<<"\n"<<2*n-1<<"\n1\n";
        for(int ctr1=n;ctr1<2*n-1;ctr1++)
            if(ctr1!=x)
                cout<<ctr1<<"\n";
    }
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
const int N=12;
int c[N],a[N][N],ans=1e9,w,now[N],n,m,x;
bool check(){
	for(int i=0;i<m;i++)if(now[i]<x)return 0;
	return 1;
}
void dfs(int d){
	if(check()){ans=min(w,ans);return;}
	if(d==n||w>=ans)return;
	w+=c[d];for(int i=0;i<m;i++)now[i]+=a[d][i];
	dfs(d+1);
	w-=c[d];for(int i=0;i<m;i++)now[i]-=a[d][i];
	dfs(d+1);
}
int main(){
	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i<n;i++){
		scanf("%d",c+i);
		for(int j=0;j<m;j++)scanf("%d",a[i]+j);
	}
	dfs(0);
	printf("%d",ans==1e9?-1:ans);
	return 0;
}

Measured memory_bytes: 3824
N=int(input())
graph=[]
d=[2000]*(N)
p=[None]*(N)
color=["white"]*(N+1)
for i in range(N):
    a=list(map(int,input().split()))
    graph.append(a)
def prim():
    d[0]=0
    p[0]=-1
    while (True):
        mincost=2000
        for i in range(N):
            if color[i]!="black" and d[i]<mincost:
                mincost=d[i]
                u=i
        if mincost==2000:break
        color[u]="black"
        for v in range(N):
            if color[v]!="black" and graph[u][v]!=-1:
                if graph[u][v]<d[v]:
                    d[v]=graph[u][v]
                    p[v]=u
                    color[v]="gray"
prim()
print(sum(d))


Measured memory_bytes: 5888
#include<bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fo(i, x, y)   for (__typeof(x) i = x; i < y; ++i)
#define fr(i, x, y)   for (__typeof(x) i = x; i > y; i--)
#define vdp(n,x) vector<vector<double>>dp(n+1,vector<double>(x+1));
const ll mod=1000000007;
const ll AM=2e5+5;
using namespace std;
int main()
{
    fast;
    ll n; cin>>n;
    double p[n+1];
    fo(i,1,n+1) cin>>p[i];
   	vdp(n+1,n+1);
   	dp[1][0]=1-p[1];
   	for(ll i=2;i<=n;i++)
   		dp[i][0]=(dp[i-1][0]*(1-p[i]));
   	dp[1][1]=p[1];
   	for(ll i=2;i<=n;i++)
   		dp[i][i]=dp[i-1][i-1]*p[i];
   	for(ll i=1;i<=n;i++)
   	{
   		for(ll j=1;j<i;j++)
   		{
   			dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
   		}
   	}
   	double ans=0;
   	for(ll i=n/2+1;i<=n;i++)
   	{
   		ans+=dp[n][i];
   	}
   	cout<<fixed<<setprecision(10)<<ans;
}

Measured memory_bytes: 70784
#include<iostream>

using namespace std;
/*
struct data{
  int a;
  int b;
  int x;
};
*/
//int judge(int);
//struct data bord[10000];

main(){
  int i;
  i=0;
  int out1=0;
  int out2=0;
  int judge=0;
  int x2=0;
  int a, b, x;
  while(1){
    if(scanf("%d,%d,%d",&a,&b,&x)== EOF)break;
    //cout << bord[i].a << endl<< bord[i].b << endl << bord[i].x<< endl;
    x2 = x;
    x *= x;
    if(a != b && x == a*a + b*b )out1++;
    else if (a == b && x2 <= a+b)  out2++;
    //cout << out1 << endl << out2 << endl;
    
    /* 
       if(judge( i)==0)out1++;
       else out2++;
    */
    i++;
  }
  
  cout << out1 << endl << out2 << endl;


  return 0;
}

/*
judge(int i ){
  
  if(bord[i].a == bord[i].b )return 1;//()
  else return 0;
}
*/

Measured memory_bytes: 0
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=105;
char s[N],t[N];int n;
inline bool eq(R int k){fp(i,1,k)if(s[n-k+i]!=t[i])return false;return true;}
int main(){
	scanf("%d%s%s",&n,s+1,t+1);
	fd(k,n,0)if(eq(k))return printf("%d\n",(n<<1)-k),0;
	return 233;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define NR 20000
#define H 500001

typedef struct point {
  int x, ver, length;
} GVE;

int main(){
  GVE W[H];
  int n, i, j, g, ci, size = 0;
  int d[NR];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &ci);
    scanf("%d", &g);

    for(j = 1; j <= g; j++){
      W[size].x = ci;
      scanf("%d %d", &W[size].ver, &W[size].length);
      size++;
    }
  }

  for(i = 1; i < n; i++){
    d[i]=INT_MAX;
  }
  j = 1;
  while(j){
    j = 0;
    for(i = 0; i < size; i++) {
      if(d[W[i].x] !=INT_MAX && d[W[i].x]+W[i].length < d[W[i].ver]) {
        d[W[i].ver] = d[W[i].x]+W[i].length;
        j++;
      }
    }
  }
  for(i = 0; i < n; i++){
    printf("%d %d\n", i, d[i]);
  }
  return 0;
}



Measured memory_bytes: 7544
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N_all = int(readline())
A_all = list(map(int,readline().split()))
A = [A_all[0]]
for i in range(1,N_all):
    if A[-1] != A_all[i]:
        A.append(A_all[i])
N = len(A) 
if N == 1:
    print(1000)
    sys.exit()
money = 1000
kabu = 0 
for i in range(N):
    if i == 0:
        if A[i] > A[i+1]:
            continue
        else:
        	kabu = money // A[i]
        	money -= kabu * A[i]
    elif i == N-1:
        money += A[i]*kabu
        kabu = 0
    else:
        if A[i-1] < A[i] and A[i] > A[i+1]:
            money += A[i]*kabu
            kabu = 0
        if A[i-1] > A[i] and A[i] < A[i+1]:
            kabu = money // A[i]
            money -= kabu * A[i]
print(money)

Measured memory_bytes: 9196
# AOJ 0088: The Code A Doctor Loved
# Python3 2018.6.28 bal4u

c2d = {'A':"100101", 'B':"10011010", 'C':"0101", 'D':"0001", 'E':"110", 'F':"01001", \
'G':"10011011", 'H':"010000", 'I':"0111", 'J':"10011000", 'K':"0110", 'L':"00100", \
'M':"10011001", 'N':"10011110", 'O':"00101", 'P':"111", 'Q':"10011111", 'R':"1000", \
'S':"00110", 'T':"00111", 'U':"10011100", 'V':"10011101", 'W':"000010", 'X':"10010010", \
'Y':"10010011", 'Z':"10010000", ' ':"101", "'":"000000", ',':"000011", \
'-':"10010001", '.':"010001", '?':"000001"}

d2c = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', \
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '.', ',', '-',	'\'', '?']

while True:
	try: p = input()
	except: break
	ans, tmp = '', ''
	for c in p: tmp += c2d[c]
	if len(tmp) % 5 > 0: tmp += '0'*(5-len(tmp)%5)
	for i in range(0, len(tmp), 5): ans += d2c[int(tmp[i:i+5], 2)]
	print(ans)


Measured memory_bytes: 5596
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

int N,K;
int d[100];
int A[100][100];
int cnt[101];

int main(){
    cin>>N>>K;
    rep(i,K){
        cin>>d[i];
        rep(j,d[i]) cin>>A[i][j];
    }

    rep(i,K){
        rep(j,d[i]){
            cnt[A[i][j]]++;
        }
    }

    int ans=0;
    repn(i,N){
        if(cnt[i]==0) ans++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3628
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

class Program
{
    static void Main(string[] args)
    {

        long total = 0;

        long N=long.Parse(Console.ReadLine());
        for(long i = 1; i < N ; i++)
        {
            total += i;
        }
        Console.WriteLine(total);
    }
}



Measured memory_bytes: 11092
c = []
for i in range(3):
    C = list(map(int, input().split()))
    c.append(C)
for i in range(3):
    Min = min(c[i])
    for j in range(3):
        c[i][j] -= Min
for i in range(2):
    if c[i] == c[i + 1]:
        pass
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 3060
import heapq

X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)

heap = []
heapq.heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0))
added = []
for _ in range(K):
    p, i, j, k = heapq.heappop(heap)
    if (i + 1, j, k) not in added and i + 1 < X:
        heapq.heappush(heap, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))
        added.append((i + 1, j, k))
    if (i, j + 1, k) not in added and j + 1 < Y:
        heapq.heappush(heap, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))
        added.append((i, j + 1, k))
    if (i, j, k + 1) not in added and k + 1 < Z:
        heapq.heappush(heap, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        added.append((i, j, k + 1))
    print(-p)

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

struct C {char s, value;};

void swap(C& a, C& b){
	C tmp = a;
	a = b;
	b = tmp;
}

int main(){
	int N;cin >> N;
	C a[N],b[N];
	for(int i=0;i<N;i++){
		cin >> a[i].s >> a[i].value;
    b[i] = a[i];
	}
	for(int i=0;i<N;i++){
		for(int j=N-1;j>i;j--){
			if(a[j-1].value>a[j].value){
				swap(a[j-1],a[j]);
			}
		}
	}
	for(int i=0;i<N;i++){
		if(i == N-1) {
			cout << a[i].s << a[i].value << endl;
		}else {
			cout << a[i].s << a[i].value << " ";
		}
	}
	cout << "Stable" << endl;
	for(int i=0;i<N;i++){
    int minid = i;
		for(int j=i;j<N;j++){
			if(b[minid].value>b[j].value){
        minid = j;
			}
		}
    if(minid != i){
      swap(b[i],b[minid]);
    }
	}
	int stable = true;
	for(int i=0;i<N;i++){
		if(a[i].s != b[i].s) stable = false;
		if(i == N-1) {
			cout << b[i].s << b[i].value << endl;
		}else {
			cout << b[i].s << b[i].value << " ";
		}
	}
	if(stable) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	return 0;
}



Measured memory_bytes: 3108
//
// Created on 2020/04/18.
//


#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 <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


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

    ans = (n + (2 * d +1)- 1) / (2 * d +1);

    cout<<ans<<endl;
}


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

void solve() {
    int x, y;
    cin >> x >> y;
    int ans = 0;
    if(x == 1) ans += 300000;
    if(x == 2) ans += 200000;
    if(x == 3) ans += 100000;
    if(y == 1) ans += 300000;
    if(y == 2) ans += 200000;
    if(y == 3) ans += 100000;
    if(x == 1 && y == 1) ans += 400000;
    cout << ans << '\n';
}

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


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long leftMax = -1, rightMin = 10000000;
        for(int i = 0; i < m; i++) {
            leftMax = Math.max(leftMax, sc.nextInt());
            rightMin = Math.min(rightMin, sc.nextInt());
        }
        long ans = rightMin - leftMax + 1;

        if(ans < 0) {
            System.out.println(0);
        } else {
            System.out.println(ans);
        }
    }
}


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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,limit,ans=INT_MAX;
	cin >> n >> limit;
	int c[n+1],t[n+1];
	for(int i=1;i<=n;i++)
	{
		cin >> c[i] >> t[i];
		if(t[i]<=limit&&c[i]<ans) ans=c[i];
	}
	if(ans==INT_MAX) cout << "TLE";
	else cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    string N;
    cin >> N;
    if(N[0] == '7' || N[1] == '7' || N[2] == '7') cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N+2];
        long sum = 0;
        for(int i=1;i<=N;i++){
            A[i] =sc.nextInt();
            sum += Math.abs(A[i]-A[i-1]);
        }
        sum += Math.abs(A[N]);
        for(int i=1;i<=N;i++){
            long ans = sum - Math.abs(A[i]-A[i-1])-Math.abs(A[i+1]-A[i])+Math.abs(A[i+1]-A[i-1]);
            System.out.println(ans);
        }


        //System.out.println(ans);
    }
}


Measured memory_bytes: 65612
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
vector<P> v;
int main(){
    int n;cin>>n;
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        v.push_back(P(a,b));
    }
    int m;cin>>m;
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        v.push_back(P(a,b));
    }
    sort(all(v));
    v.erase(unique(all(v)),v.end());
    for(int i=0;i<v.size();i++){
        int a=v[i].first;int b=v[i].second;
        cout<<a<<":";
        if(b<10){
            cout<<"0";
        }
        cout<<b;
        if(i!=v.size()-1){
            cout<<" ";
        }
    }
    cout<<endl;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

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

    string s;
    cin>>s;
    int ans=0,l=0,r=s.size()-1;
    bool f=true;
    while(1){
        if(s[l]==s[r]){
            l++;
            r--;
        }
        else if(s[l]=='x'){
            ans++;
            l++;
        }
        else if(s[r]=='x'){
            ans++;
            r--;
        }
        else{
            f=false;
            break;
        }
        if(l>=r)break;
    }
    if(!f)ans=-1;
    cout<<ans<<endl;

}

Measured memory_bytes: 512
n = int(input())
s = input()
# st = set()
# for i in range(n-2):
#     for j in range(i+1, n-1):
#         for k in range(j+1, n):
#             pin = s[i] + s[j] + s[k]
#             st.add(pin)
# print(st)
count = 0
# for i in range(1000):
#     if len(str(i)) == 1:
#         v = "00" + str(i)
#     elif len(str(i)) == 2:
#         v = "0" + str(i)
#     else:
#         v = str(i)
#     k = 0
#     for j in range(len(v)):
#         while k < len(s):
#             if s[k] == v[j]:
#                 k += 1
#                 break
#             k += 1
#         else:
#             break
#     else:
#         count += 1
for i in range(1000):
    v = [i // 100, (i // 10) % 10, i % 10]
    first = s[:-2].find(str(v[0]))
    if first == -1:
        continue
    second = s[first + 1:-1].find(str(v[1]))
    if second == -1:
        continue
    third = s[first + 1 + second + 1:].find(str(v[2]))
    if third == -1:
        continue
    # print(v, first, second, third, first + second +1)
    count += 1
print(count)

Measured memory_bytes: 3188
#include <stdint.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

const string YES = "Yes";
const string NO = "No";

void solve(long long X, long long Y) {
  REP(i, 100) {
    REP(j, 100) {
      if (i + j == X) {
        if (2 * i + 4 * j == Y) {
          cout << YES << endl;
          return;
        }
      }
    }
  }
  cout << NO << endl;
}

int main() {
  long long X;
  scanf("%lld", &X);
  long long Y;
  scanf("%lld", &Y);
  solve(X, Y);
  return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int gcd(int a, int b){
  return b?gcd(b,a%b):a;
}

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n){cin>>a[i];}
  sort(a.begin(),a.end());
  vector<int> dpl(n),dpr(n);
  
  dpl[0] = a[0];
  dpr[0] = a[n-1];
  for(int i=0; i<n-1; i++){
    dpl[i+1] = gcd(dpl[i],a[i+1]);
    dpr[i+1] = gcd(dpr[i],a[n-i-2]);
  }


  int ans=0;
  for(int i=0; i<n-1; i++){
    ans = max(ans,gcd(dpl[i],dpr[n-i-3]));
  }
  ans = max(ans,dpl[n-2]);
  ans = max(ans,dpr[n-2]);

  cout << ans << endl;
}


Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10 ** 7)
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

N = int(input())

d = int(str(N)[-1])

if d in (2,4,5,7,9):
    print('hon')
elif d in (0, 1,6,8):
    print('pon')
else:
    print('bon')




Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 1e3+7;
const int maxV = 90010;
//const int INF = 1e9+9;
//const ll INF = (1ll)<<60;
const int INF = 2e9+9;
const int MOD = 1e9+7;


vector<int> v[maxN];
int p[maxN];
map<string,set<pii>> mp; 
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int k;
		scanf("%d",&k);
		for(int j=1;j<=k;j++)
		{
			int x;
			scanf("%d",&x);
			v[i].push_back(x-1);
		}
	}
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&p[i]);
	}
	int maxv = (1<<n)-1;
	int ans = 0;
	for(int i=0;i<=maxv;i++)
	{
		int flag = 1;
		for(int j=1;j<=m;j++)
		{
			int cnt = 0;
			for(auto x:v[j])
			{
				if(i>>x & 1 == 1)
				{
					cnt++;
				}
			}
			if(cnt%2 != p[j])
				flag = 0;
		}
		if(flag == 1)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	int n;
	cin>>n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin>>a[i];
	vector<vector<long long>> dp(n, vector<long long>(n));
	for (int i = 0; i < n; i++) dp[i][i] = a[i];
	for (int i = 0; i < n-1; i++) dp[i][i+1] = max(a[i], a[i+1]);
	for (int g = 2; g < n; g++) {
		for (int i = 0, j = g; j < n; i++, j++) {
			dp[i][j] = max(a[i] + min(dp[i+1][j-1], dp[i+2][j]), a[j] + min(dp[i][j-2], dp[i+1][j-1]));
		}
	}
	long long s = 0;
	for (int i : a) s += i;
	long long x = dp[0][n-1], y = s - x;
	cout<<x-y<<endl;
	return 0;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    int m=0,t=1;
    for(int i=2;i<=n;i++){
        cout << "? " << 1 << " " << i << endl;
        int d;cin >> d;
        if(d>m){
            t=i;
            m=d;
        }
    }
    vector<int> dis(n);
    for(int i=1;i<=n;i++){
        if(i==t){
            continue;
        }
        cout << "? " << t << " " << i << endl;
        int d;cin >> d;
        dis[i-1]=d;
    }
    vector<pair<int,int>> p(n);
    for(int i=0;i<n;i++){
        p[i]={dis[i],i};
    }
    sort(p.begin(),p.end());
    cout << "! ";
    for(int i=0;i<n;i++){
        if(i!=n-1){
            cout << p[i].second+1 << " ";
        }
        if(i==n-1){
            cout << p[i].second+1;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>

int main(void)          
{
	int n;
	int i;
	int check = 0, check_n;

	scanf("%d", &n);
	for (i = 1; i <= n; i++) 
	{
		check = 0;
		check_n = i;
		while ((check == 0) && (check_n != 0)) 
		{
			if (check > 0) break;
			if (check_n % 10 == 3) check++;
			check_n = check_n / 10;
		}
		if (i % 3 == 0 || check != 0 || i % 10 == 3)	printf(" %d", i);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
//
//  main.cpp
//  atcoder
//
//  Created by Hisaki Kobayashi on 2020/04/14.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;

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

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

ll a[50];
ll b[50];
ll c[50];
ll d[50];
long long N,M,Q;

ll sum=0;
void dfs(ll i,ll m, vector<ll> A){
//    cout << "i=" << i << endl;
    if(i==N){
    //検証
        ll temp = 0;
        for(ll q=0;q<Q;q++){
            if(A[b[q]-1] - A[a[q]-1] == c[q]){
//                cout << "qの値＝" << q <<" のとき満たし、"<<d[q]<< " を加算します" << endl;
                temp += d[q];
            }
        }
//        cout << "Aのvalueは " << temp<< endl;
        sum = max(sum,temp);
        return;
    }
    for(ll j=m; j<=M; j++){
        A[i]=j;
        dfs(i+1,A[i],A);
    }
    
    return;
}

int main(int argc, const char * argv[]) {
    cin >> N >> M >> Q;
    for(ll i=0;i<Q;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    vector<ll> A(N,-1);
    
    dfs(0,1,A);

    cout << sum << endl;
    return 0;
}




Measured memory_bytes: 3632
#include <iostream>
using namespace std;
long long gcd(long long x, long long y) {
    if (x == 0) return y;
    if (y == 0) return x;
    return gcd(y, x%y);
}

long long num(long long a,long long b,long long c){
  long long ac = (a - 1) / c;
  long long bc = b / c;
  return bc - ac;
}

int main(void){
  long long A,B,C,D;
  cin >> A >> B >> C >> D;

  cout << B - A + 1 -num(A,B,C) - num(A,B,D) + num(A,B,C * D / gcd(C,D)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

int main() {
    string S;
    cin >> S;
    int r = 0;
    for (int i = 0; i < 4; ++i) {
        if(S[i] == '+'){
            r++;
        }
        if(S[i] == '-'){
            r--;
        }
    }
    cout << r;


    return 0;
}

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

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

#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define ferrari ios_base::sync_with_stdio(false); cin.tie(NULL)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll LIM = 3234566667;

set<ll> nums;

void generate(int len, ll dig, ll cur = 0, int pos = 1, ll ten = 1)
{
	if (cur > LIM || dig < 0 || dig > 9) return;
	cur += dig * ten;
	if (pos == len) {
		nums.insert(cur);
		return;
	}
	ten *= 10;
	generate(len, dig - 1, cur, pos + 1, ten);
	generate(len, dig, cur, pos + 1, ten);
	generate(len, dig + 1, cur, pos + 1, ten);
}

int main()
{
	for (int len = 1; len <= 10; len++)
		for (ll start = 0; start < 10; start++)
			generate(len, start);
	vector<ll> a;
	for (ll i: nums) a.pb(i);
	int n;
	cin >> n;
	cout << a[n];	
}


Measured memory_bytes: 11764
#include<cstdio>
int n,f[200005];
long long ans=0;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&f[i]);
	int l=1,r=0,x=0,y=0;
	for (;l<=n;x=x^f[l],y=y-f[l],l++)
	{
		while ((x^f[r+1])==(y+f[r+1])&&r<n) ++r,x=x^f[r],y=y+f[r];
		ans=ans+(r-l+1);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1024
s = " " + input().strip()
t = " " + input().strip()
LS, LT = len(s), len(t)
dp = [[0]*LT for _ in range(LS)]
for i in range(1, LS):
    for j in range(1, LT):
        if s[i] == t[j]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
a, b = (LS-1, LT-1)
r = ""
while a > 0 and b > 0:
    if s[a] == t[b]:
        r+=s[a]
        a, b = a-1, b-1
    elif dp[a][b] == dp[a-1][b]:
        a -= 1
    else:
        b -= 1

print(r[::-1])


Measured memory_bytes: 112220
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            sum = 500*i + 100*j + 50*k
            if sum == x:
                count += 1

print(count)


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

const bool DEBUG = false;

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<double> v(N);
  for (size_t i = 0; i < N; i++) cin >> v[i];
  sort(v.begin(), v.end(), greater<double>());

  double total = 0;
  for (int i = 0; i < N; i++) {
    total += pow(0.5, (double)min(i + 1, N - 1)) * v[i];
  }

  cout << total << endl;

  return 0;
}


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


int main(void) {
	char search[101],word[1001];
	    scanf("%s",search);
	    //??§???????°?????????????
        int i;
        for (i = 0; i < strlen(search); i++)if (search[i] <= 'Z')search[i] = tolower(search[i]);
		int cnt=0; 
		//??\???????¶???????
		while(scanf(" %s",word)){
		    //END_OF_TEXT??§??????
		    if(strstr(word,"END_OF_TEXT")!=0)break;
		    //?°?????????????
            for (i = 0; i < strlen(word); i++)  if (word[i] <= 'Z')word[i] = tolower(word[i]);
		    //????????§????????°1?????°??????
		    if(strstr(word,search)!=0&&strlen(word)==strlen(search))cnt++; 
		}
		printf("%d\n",cnt);

	return 0;
}

Measured memory_bytes: 552
WHN=input()
WHN=WHN.rstrip().split(" ")
W=int(WHN[0])
H=int(WHN[1])
N=int(WHN[2])

list1=[]
for i in range(H):
    list2=[]
    for j in range(W):
        list2.append('w')
    list1.append(list2)
    list2=[]
#print(list1)

i=0
for i in range(N):
    xya=input()
    xya=xya.rstrip().split(" ")
    x=int(xya[0])
    y=int(xya[1])
    a=int(xya[2])
    #print(x,y,a)
    if a==1:
        j=0
        for j in range(H):
            k=0
            for k in range(W):
                if k<x:
                    list1[j][k]='b'
    elif a==2:
        j=0
        for j in range(H):
            k=0
            for k in range(W):
                if k+1>x:
                    list1[j][k]='b'
    elif a==3:
        j=0
        for j in range(H):
            k=0
            for k in range(W):
                if j<y:
                    list1[j][k]='b'
    elif a==4:
        j=0
        for j in range(H):
            k=0
            for k in range(W):
                if j+1>y:
                    list1[j][k]='b'
                    #print(list1)
                    
count=0
i=0
for i in range(H):
    k=0
    for j in range(W):
        if list1[i][j]=='w':
            count+=1
print(count)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){
  string s, t;
  cin >> s >> t;
  int n = sz(s);
  vector<set<int>> st(26);
  for (int i = 0; i < n; i++) {
    st[s[i] - 'a'].insert(i);
    st[s[i] - 'a'].insert(i + n);
  }
  ll res = 0;
  ll cnt = 0;
  int m = sz(t);
  int id = 0;
  for (int i = 0; i < m; i++) {
    if (st[t[i] - 'a'].empty()) {
      cout << -1 << endl;
      return 0;
    }
    auto itr = *st[t[i] - 'a'].lower_bound(id) + 1;
    if (itr >= n) itr %= n, cnt++;
    id = itr;
  }
  res += id;
  cout << cnt * n + id << endl;
  return 0;
} 

Measured memory_bytes: 9856
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include<algorithm>
#include<vector>

int main()
{
    int n;
    int tmp;
    
    std::vector<int> a;
    
    std::cin>>n;
    
    for(;std::cin>>tmp;)
        a.push_back(tmp);
    std::sort(a.begin(),a.end());
    
    std::size_t s0=0;
    for(int i=0;i<n;++i){
        for(int k=i+1;k<n;++k){
            auto it = std::lower_bound(a.begin()+k,a.end(),a[i]+a[k]); // c < x+y
            s0 += it - (a.begin() + k)-1;
        }
    }
    
    std::cout<<s0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;

using System.Linq;
public class abc178_c {

    static DateTime START_TIME;
    public static void Main() {
        START_TIME = DateTime.Now;
#if MYTEST
        while (true) {
            System.Console.Error.WriteLine("TEST MODE>");
            START_TIME = DateTime.Now;
            System.Console.WriteLine(Answer());  // debug
            System.Console.WriteLine($"{(DateTime.Now - START_TIME).Seconds} sec.");
        }
#else
        System.Console.WriteLine(Answer());
#endif
    }
    public static void debugOut(string str) {
#if MYTEST
        System.Console.Error.Write(str);
#endif
    }
    public static long ModPow(long x, long n, long mod) {
        long result = x % mod;
        for (long i = 1; i < n; i++) {
            result = (result * x) % mod;
        }
        return result;
    }
    public static long ModSub(long x, long n, long mod) {
        while (x < n) {
            x += mod;
        }
        return (x - n) % mod;
    }
    public static string Answer() {
        var p = System.Console.ReadLine().Trim().Split(' ');
        var N = long.Parse(p[0]);
        var mod = (long)Math.Pow(10, 9) + 7;
        debugOut(mod.ToString() + "\n");

        var ans = ModPow(10, N, mod);
        ans = ModSub(ans, (ModPow(9, N, mod) * 2), mod);
        ans += ModPow(8, N, mod);
        while (ans >= mod) {
            ans %= mod;
        }
        return ans.ToString();
    }
}


Measured memory_bytes: 29892
/**
  *  Worg
  */
#include <iostream>

int main() {
  unsigned long long x, y; std::cin >> x >> y;

  unsigned long long current = x;
  int answer = 1;

  while (y / current >= 2) {
    answer ++;
    current *= 2;
  }

  std::cout << answer << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;
const double PI = acos(-1.0);

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

    string str;
    
    stack<int> s;
    while(cin >> str){
        int a, b;
        if(str[0] == '+'){
            a = s.top(); s.pop();
            b = s.top(); s.pop();
            s.push(b+a);
        }else if(str[0] == '-'){
            a = s.top(); s.pop();
            b = s.top(); s.pop();
            s.push(b-a);
        }else if(str[0] == '*'){
            a = s.top(); s.pop();
            b = s.top(); s.pop();
            s.push(b*a);
        }else{
            s.push(atoi(str.c_str()));
        }
    }

    cout << s.top() << "\n";

    return 0;
}

Measured memory_bytes: 3204
n, k= [int(i) for i in input().split()]
mod = 10**9 + 7

n_max = 4 * 10**5
fac = [1 for _ in range(n_max)]
inv = [1 for _ in range(n_max)]
finv = [1 for _ in range(n_max)]
def init():
  for i in range(2, n_max):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] =finv[i-1] * inv[i] % mod    
  
def nCk(n, k, mod):
  return (fac[n] * finv[k] % mod)* finv[n-k] % mod
  
def nHm(n, m, mod):
  return nCk(n+m-1, m, mod)

init()
total = 1
n_max = min(n, k + 1)
for m in range(1, n_max):
  diff = nCk(n, m, mod) * nHm(n - m, m, mod) % mod
  total = total + diff
  

print(total % mod)


Measured memory_bytes: 50712
#include <bits/stdc++.h>
#define int             long long
#define ld              long double
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(int i=1;i<=n;i++)
#define fok(i,k,n)      for(int i=k;i<=n;i++)
#define rfo(i,n)        for(int i=n;i>=0;i--)
#define rfo1(i,n)       for(int i=n;i>0;i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<string,string>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcount(x)
#define zerobits(x)     __builtin_ctz(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define endl            '\n'
#define mod             1000000007
#define M               (int)1e6+6
#define inf             1e18
using namespace std;

int n,k,x,y,z,a1,b,c,d,i,j,l,r;
string s,t;





void sol()
{   
    cin>>s>>t;
    int n=s.size();
    int m=t.size();
    string dp[2][m+1];

    for(int i=1;i<=n;i++)
    {   int x=i%2;
        for(int j=1;j<=m;j++)
        {   
            y=(x==0)?1:0;
            if(s[i-1]==t[j-1])dp[x][j]=dp[y][j-1]+s[i-1];
            else
            {
                dp[x][j]=(dp[x][j-1].length()>dp[y][j].length())?dp[x][j-1]:dp[y][j];
            }
           
        }
    }
    
    cout<<dp[n%2][m]<<endl;
    
}





int32_t main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // w(t)
    sol();
    return 0;
}



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

int main(){
    int a, b, N;
    cin>>a>>b>>N;
    bool Z=0;
    int s,f;
    for(int i=0;i<N;i++){
        
        cin>>s>>f;
        if((f>a&&b>s)||(s<b&&a<f))
        Z=1;
    }

    cout<<Z<<endl;

    
    return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<utility>
#include<queue>

typedef long long lli;
using namespace std;

int main() {
	int n;
	int data[100000] = { 0 };
	cin >> n;
	int o = n % 2;
	for (int i = 1;i <= n / 2;i++) {
		if (o == 1)data[i * 2] = 2;
		else data[i * 2 - 1] = 2;
	}
	if (o == 1)data[0] = 1;

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

	for (int i = 0;i < n;i++) {
		if (data[i] != 0) {
			printf("0\n");
			return 0;
		}
	}
	lli ans = 2;
	for (int i = 1;i < n/2;i++) {
		ans = (ans * 2) % 1000000007;

	}
	if (n == 1)ans = 1;
	printf("%lld\n", ans);

	return 0;

}

//改行注意


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define ll long long int 
#define gof for(long long int i = 0 ; i < n ; i++)
#define for1(i,s,e) for(long long int i = s ; i < e ; i++)
const ll ARR = 1e5;
const ll MOD = 1e9+7;
const ll INF = 1e9;
ll power(ll x, ll y)
{
	ll res = 1;
	x = x % MOD;
	if (x == 0)
		return 0;

	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % MOD;
		y = y >> 1;
		x = (x * x) % MOD;
	}
	return res;
}

ll gcd(ll a, ll b)
{
	if (a == 0)
		return b;
	return gcd(b % a, a);
}
ll max(ll a, ll b)
{
	if (a > b)
		return a;
	else
		return b;
}
ll min(ll a, ll b)
{
	if (a < b)
		return a;
	else
		return b;
}
ll max(ll a[], ll n)
{
	ll ans = 0;
	for (ll i = 0; i < n; i++)
		ans = max(ans, a[i]);
	return ans;
}

ll min(ll a[], ll n)
{
	ll ans = INF;
	for (ll i = 0; i < n; i++)
		ans = min(ans, a[i]);
	return ans;
}
bool isPrime(ll N)
{
	for (int i = 2; i * i <= N; ++i)
	{
		if (N % i == 0)
			return false;
	}
	return true;
}

void solve(){
	ll n,m,dp[1000][1000];
	for1(i,0,1000) dp[i][0]=0,dp[0][i]=0;
	cin >> n >> m;
	vector<string> s(n);
	for1(i,0,n){
		cin >> s[i];
	}
	for1(i,0,n){
		if(s[i][0] == '#')
			break;
		dp[i][0] = 1;
	}
	for1(i, 0, m)
	{
		if (s[0][i] == '#')
			break;
		dp[0][i] = 1;
	}
	for1(i,1,n){
		for1(j,1,m){
			if(s[i][j] == '#'){
				dp[i][j] = 0;
				continue;
			}
			dp[i][j] = (dp[i-1][j]%MOD + dp[i][j-1]%MOD)%MOD; 
		}
	}
	cout << dp[n-1][m-1] << endl;
}
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

	ll t = 1;
	//cin >> t;
	while(t--) solve();
	return 0;
}

Measured memory_bytes: 9088