akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cstdio>
using namespace std;
char s[100005];
int check(int x,int y){
	if(s[x]=='W'){
		if(s[y]=='B') return 1;
		else return 0;
	}
	if(s[x]=='B'){
		if(s[y]=='W') return 1;
		else return 0;
	}
}
int main(){
	scanf("%s",s);
	int n=strlen(s),ans=0;
	for(int i=0;i<n;i++){
		if(check(i,i+1)){
			ans++;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
/**
 *    author:  DFLMKWR
 */

#include <iostream>
#include <algorithm>

using namespace std;

int l[103];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> l[i];
  sort(l, l + n);
  int cnt = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      for (int k = j + 1; k < n; k++)
        if (l[i] != l[j] && l[i] != l[k] && l[j] != l[k] && l[i] + l[j] > l[k])
          cnt++;
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
vector<pair<int, int>> directions = {
    {1,0}, {0,1}, {-1,0}, {0,-1}, {1,1}, {1,-1}, {-1,1}, {-1,-1}
};
void dfs(Graph &chart, int x, int y) {
    int H = chart.size(), W = chart[0].size();
    chart[x][y] = -1;
    for (int i = 0; i < directions.size(); i++) {
        int nx = x + directions[i].first;
        int ny = y + directions[i].second;
        if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
        if (chart[nx][ny] == 1) dfs(chart, nx, ny);
    }
}

int main() {
    while (true) {
        int H, W;
        cin >> W >> H;
        if (H == 0 && W == 0) break;
        Graph chart(H, vector<int>(W));
        for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
            cin >> chart[i][j];
        }
        int cnt = 0;
        for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
            if (chart[i][j] == 1) {
                dfs(chart, i, j);
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


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

string plus_all(string s) {
  int ssize = s.size();
  int64_t sum = 0;
  int64_t tmp = 0;
  for (int f = 0; f < (1 << ssize-1); f++) {
    bitset<10> flag(f);
    flag <<= 1;
    for (int i = 0; i < ssize; i++) {
      if (flag.test(ssize - 1 - i) == true) {
        tmp += (s[i] - '0');
        tmp *= 10;
      } else {
        tmp += (s[i] - '0');
        sum += tmp;
        tmp = 0;
      }
    }
  }
  return to_string(sum);
}


int main() {
  string s;
  cin >> s;
  cout << plus_all(s) << endl;
}


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

using namespace std;

using ll = long long;

int main(){
    ll n;
    cin >> n;
    ll arr[n + 1] = {0};
    for(ll i = 0; i < n - 1; ++i){
        ll tmp; cin >> tmp;
        arr[tmp]++;
    }
    for(ll i = 1; i <= n; ++i){
        cout << arr[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 5252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int s=0;
  for(int i=0;i<m;i++){
    int a;
    cin>>a;
    s+=a;
  }
  cout<<(s<=n?n-s:-1)<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;
#define PI  3.14159265358979323846

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

int main() {
    ll N, M, X;
    cin >> N >> M >> X;
    ll C[12]{ 0 };
    ll A[12][12]{ 0 };
    rep(i,N) {
        ll c;
        cin >> c;
        C[i] = c;
        rep(j,M) {
            ll a;
            cin >> a;
            A[i][j] = a;
        }
    }
    ll min = 100000*12+1;
    for (ll bit = 0; bit < (1 << N);++bit) {
        ll tmpMin = 0;
        ll tmpA[12]{ 0 };
        rep(i,N) {
            if (bit&(1<<i)) {
                rep(j, M) {
                    tmpA[j] += A[i][j];
                }
                tmpMin += C[i];
            }
        }
        bool flg = true;
        rep(i, M) {
            if (tmpA[i] < X) {
                flg = false;
                break;
            }
        }
        if (flg&&(tmpMin<min)) {
            min = tmpMin;
        }
    }
    if (100000 * 12<min) {
        cout << -1 << endl;
    }
    else {
        cout << min << endl;
    }
    return 0;
}

Measured memory_bytes: 3540
a = input()
b = 0

if a == 'SAT':
  b=1
elif a=='MON':
  b=6
elif a=='TUE':
  b=5
elif a=='WED':
  b=4
elif a=='THU':
  b=3
elif a=='FRI':
  b=2
else :
  b=7

print(b)

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

using namespace std;

int N, ap[30];
char sir[200009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%s", sir + 1), N = strlen (sir + 1);
long long ans = 0;
for (int i=1; i<=N ;i++)
{
    sir[i] -= 'a';
    ans += (ap[sir[i]] ++);
}
ans = 1LL * N * (N - 1) / 2 - ans;
ans ++;
printf ("%lld\n", ans);
return 0;
}


Measured memory_bytes: 384
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        String day = scan.next();

        switch (day) {
            case "SUN":
                os.println(7);
                break;

            case "MON":
                os.println(6);
                break;

            case "TUE":
                os.println(5);
                break;

            case "WED":
                os.println(4);
                break;

            case "THU":
                os.println(3);
                break;

            case "FRI":
                os.println(2);
                break;

            case "SAT":
                os.println(1);
                break;
        }
    }
}

Measured memory_bytes: 25300
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;
using VP = vector<P>;
using VVI = vector<VI>;

bool isp(long p) {
    if (p == 2) return true;
    if (p < 3) return false;
    if (p % 2 == 0) return false;
    for (long i = 3; i * i <= p; i += 2) {
        if (p % i == 0) return false;
    }
    return true;
}

VI ps[5];

int main() {
    long n;
    cin >> n;
    REP(i,55556) {
        if (isp(i)) {
            ps[i%5].push_back(i);
        }
    }
    
    REP(i,n-1) {
        cout << ps[1][i] << " ";
    }
    cout << ps[1][n-1] << endl;
}


Measured memory_bytes: 384
s = input()
l = len(s)
mod = (10**9)+7

dp = [[0 for j in range(13)] for i in range(l)]

if s[0] == '?':
    dp[0][0:9] = [1 for x in range(10)]
else:
    dp[0][int(s[0])] = 1

for i in range(l-1):
    a = i+1
    x = s[a]
    if x == '?':
        for j in range(10):
            for k in range(13):
                dp[a][(k*10+j)%13] += dp[a-1][k]%mod
    else:
        for k in range(13):
            dp[a][(k*10+int(x))%13] += dp[a-1][k]%mod

print(dp[-1][5]%mod)


Measured memory_bytes: 66268
#include<bits/stdc++.h>
#define MAX_V 2005
#define INF (1e9)
using namespace std;
typedef pair<int,int> P;

//????????¨????§???????(???????????????????????????????????????)
struct edge{int to, cap,cost,rev;};

int V;                         //????????°
vector<edge> G[MAX_V];         //??°???????????£??\???????????¨???
int dist[MAX_V];               //???????????¢
int prevv[MAX_V],preve[MAX_V]; //??´??????????????¨???

// from??????to??????????????????cap????????????cost???????????°????????????????????????
void add_edge(int from,int to,int cap,int cost){
  G[from].push_back((edge){to,cap,cost,G[to].size()});
  G[to].push_back((edge){from,0,-cost,G[from].size()-1});
}

//s??????t????????????f???????°??????¨???????±???????
//??????????????´???-1?????????
int min_cost_flow(int s,int t,int f){
  int res=0;
  while(f>0){
    //????????????????????????????????????,s-t????????????????±???????
    fill(dist,dist+V,INF);
    dist[s]=0;
    bool update = true;
    while(update){
      update = false;
      for(int v=0; v<V ;v++){
	if(dist[v]==INF) continue;
	for(int i=0; i<G[v].size(); i++){
	  edge &e = G[v][i];
	  if(e.cap > 0 && dist[e.to] > dist[v]+e.cost) {
	    dist[e.to] = dist[v] + e.cost;
	    prevv[e.to] = v;
	    preve[e.to] = i;
	    update = true;
	  }
	}
      }
    }
    if(dist[t]==INF) return -1; //????????\??????????????????
    
    //s???t?????????????????£??????????????????
    int d = f;
    for(int v=t; v!=s; v=prevv[v])d=min(d,G[prevv[v]][preve[v]].cap);
    f -= d;
    res += d*dist[t];
    for(int v=t; v!=s; v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int a[MAX_V],b[MAX_V],w[MAX_V];
vector<P> v;

int main(){
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    
    for(int i=0;i<n;i++){
      cin>>a[i]>>b[i]>>w[i];
      v.push_back(P(a[i],i));
    }
    sort(v.begin(),v.end());

    int s=n*2,g=s+1;
    
    for(int i=0;i<n;i++){
      add_edge(s,i*2,1,0);
      add_edge(i*2,i*2+1,1,-w[i]);
      add_edge(i*2+1,g,1,0);

      for(int j=0;j<v.size();j++){
	if(i==v[j].second)continue;
	if(b[i]<v[j].first)
	  add_edge(i*2+1,v[j].second*2,1,0);
      }
    }

    V=g+1;

    cout<<-min_cost_flow(s,g,2)<<endl;
    
    for(int i=0;i<V;i++)G[i].clear();
    v.clear();
  }
  return 0;
}

Measured memory_bytes: 25876
#include <iostream>
using namespace std;
int arr[3][100005];
 int n;

 int dp[3][100005];

int foo(int ind, int restriction)
{
  if(restriction != -1 && dp[restriction][ind] != -1) return dp[restriction][ind];
  if(ind == n) 
    {
      //dp[restriction][ind] = 0;
      return 0;
    }
  int maxm = -1;

  for (int i = 0; i < 3; ++i)
  {
     if(i != restriction)
     maxm = max(maxm, foo(ind + 1, i) + arr[i][ind]);
  }
  if(restriction != -1)
  dp[restriction][ind] = maxm;
  return maxm;
}
int main()
{
 
  cin >> n;

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

     dp[0][i] = -1;
     dp[1][i] = -1;
     dp[2][i] = -1;
  }

  cout << foo(0, -1);
  return 0;
}

Measured memory_bytes: 8832
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; string s; cin >> n >> s;
	int cnt = 0;
	forl(i, 0, n-2) {
		if(s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C') cnt++;
	}
	println(cnt);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

inline double abs(double x) {
  if (x > 0) {
    return(x);
  } else {
    return(-x);
  }
}

int main(){
  int n;
  double a[101], m, tot, result, idx;
  tot = 0;
  result = 1000000;
  idx = -1;
  cin >> n;
  for (int i=0;i<n;i++) {
    int tmp;
    cin >> tmp;
    a[i] = tmp;
    tot += tmp;
  }
  m = tot/double(n);
  for (int i=0;i<n;i++) {
    if (abs(a[i] - m) < abs(result - m)) {
      result = a[i];
      idx = i;
    }
  }
  cout << idx << endl;
  return(0);
}


Measured memory_bytes: 888
N, K = map(int, input().split())
S = input()

happy = 0

for i, s in enumerate(S):
    if s == "L":
        if i != 0 and S[i - 1] == "L":
            happy += 1
    else:
        if i != N - 1 and S[i + 1] == "R":
            happy += 1
print(min(N - 1, happy + 2 * K))


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

int f[1000000],s[80000];

int main() {
   int n,i,j,k=0;
   for (i=2;i<1000000;i++) if (f[i]==0) {
	   f[i]=1; s[k++]=i;
	   for (j=i+i;j<1000000;j+=i) f[j]=2;
   }
   while ( cin >> n && n>0) {
	   for (i=0,j=0;s[i]<=n/2;i++) if (f[n-s[i]]==1)  j++;
	   cout << j << endl;
   }  
return 0;
}	

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

using namespace std;

const int P = 1000000007;

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

	vector<vector<long long> > dp;
	dp.resize(k + 1);

	vector<int> block;
	vector<int> len;

	for(int i = 1, j; i <= n; i = j + 1) {
		j = n / (n / i);

		block.emplace_back(i);
		len.emplace_back(j - i + 1);
	}

	int m = len.size();

	for(int i = 0; i < k + 1; ++i) {
		dp[i].resize(m);
	}

	dp[0].assign(m, 1);

	auto find = [&] (int x) {
		return upper_bound(block.begin(), block.end(), x) - block.begin() - 1;
	};

	for(int i = 0; i < k; ++i) {
		for(int j = 0; j < m; ++j) {
			dp[i + 1][j] = dp[i][find(n / block[j])] * len[j] % P;
		}

		for(int j = 0; j < m - 1; ++j) {
			dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i + 1][j]) % P;
		}
	}

	cout << dp[k].back() << '\n';

	return 0;
}


Measured memory_bytes: 51068
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s;
  cin >> s;
  int a[10000100] ={0};
  a[1] += s;
  bool b = false;
  int i = 1;
  while(i < 10000100){
    if(a[i]==4||a[i]==1||a[i]==2){
      cout << i+3 << endl;
      return 0;
    }
    else if(a[i]%2 != 0){
      a[i+1] += 3*a[i]+1;
      i++;
    }
    else{
      a[i+1] += a[i]/2;
      i++;
    }
  }
}



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

using namespace std;

int main( )
{	
    int n;
    int maxProfit = 1-1000000000;
    int Ri = 2000000000;
   
    cin>>n;
    
    vector<int> R(n);
    vector<int>::iterator itr = R.begin( );
    vector<int>::iterator itrE = R.end( );
    
    for( ; itr!=itrE; itr++ ) {
    	cin>>*itr;
    	if( maxProfit < *itr - Ri ) {
       		maxProfit = *itr - Ri;
       	}
       	if( *itr < Ri ) {
    		Ri = *itr;
    	}
    }
    cout<<maxProfit<<endl;
	
	return 0;
}

Measured memory_bytes: 1796
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define int long long
#define mod 998244353
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
#define N 200005
int lowbit(int x){return x&(-x);}
struct Node
{
	int x,y,rk,num;// y rk
};
Node a[N];
Node b[N];
bool cmp1(Node x,Node y)
{
	return x.y<y.y;
}
bool cmp2(Node x,Node y)
{
	return x.x<y.x;
}
int t1[N],t2[N];
int n;
void add1(int u,int d)
{
	while(u<=n) t1[u]+=d,u+=lowbit(u);
}
void add2(int u,int d)
{
	while(u<=n) t2[u]+=d,u+=lowbit(u);
}
int sum1(int u)
{
	int ans=0;
	while(u) ans+=t1[u],u-=lowbit(u);
	return ans;
}
int sum2(int u)
{
	int ans=0;
	while(u) ans+=t2[u],u-=lowbit(u);
	return ans;
}
int qpow(int x,int y)
{
	int ans=1;
	while(y)
	{
		if(y&1) ans=ans*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ans;
}
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	n=read();
	for(int i=1;i<=n;i++)
	{
		a[i].x=read(),a[i].y=read();
		b[i].y=a[i].y,b[i].num=i;
	}
	sort(b+1,b+n+1,cmp1);
	for(int i=1;i<=n;i++)
	{
		a[b[i].num].rk=i;
	}
	sort(a+1,a+n+1,cmp2);
	for(int i=1;i<=n;i++)
	{
		add2(i,1);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		add2(a[i].rk,-1);
		int A=sum1(a[i].rk),B=sum1(n)-A,C=sum2(a[i].rk),D=sum2(n)-C;
		int ta=qpow(2,A),tb=qpow(2,B),tc=qpow(2,C),td=qpow(2,D);
		ans=(ans+(ta-1)*(td-1)%mod*tb%mod*tc)%mod;
		ans=(ans+(tb-1)*(tc-1)%mod*ta%mod*td)%mod;
		ans=(ans-(tb-1)*(tc-1)%mod*(ta-1)%mod*(td-1))%mod;
		ans=(ans+qpow(2,n-1));
		add1(a[i].rk,1);
	}
	ans=(ans%mod+mod)%mod;
	cout<<ans<<endl;
#ifdef __LOCAL__
	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



Measured memory_bytes: 15872
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int [][]array1=new int [4][11];
        int [][]array2=new int [4][11];
        int [][]array3=new int [4][11];
        int [][]array4=new int [4][11];
        
        for(int i=1;i<=n;i++){
            int b=sc.nextInt();
            int f=sc.nextInt();
            int r=sc.nextInt();
            int v=sc.nextInt();
            switch(b){
                case 1:array1[f-1][r-1]+=v; break;
                case 2:array2[f-1][r-1]+=v; break;
                case 3:array3[f-1][r-1]+=v; break;
                case 4:array4[f-1][r-1]+=v; break;
            }
        }
        for(int i=0;i<3;i++){
            for(int j=0;j<10;j++){
                System.out.printf(" %d",array1[i][j]);
            }
            System.out.println();
        }System.out.println("####################");
        
        for(int i=0;i<3;i++){
            for(int j=0;j<10;j++){
                System.out.printf(" %d",array2[i][j]);
            }
            System.out.println();
        }System.out.println("####################");
        
        for(int i=0;i<3;i++){
            for(int j=0;j<10;j++){
                System.out.printf(" %d",array3[i][j]);
            }
            System.out.println();
        }System.out.println("####################");
        
        for(int i=0;i<3;i++){
            for(int j=0;j<10;j++){
                System.out.printf(" %d",array4[i][j]);
            }
            System.out.println();
        }
        
    }
}



Measured memory_bytes: 30044
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def main():
    N = S()[::-1] + '0'
    dp = [[0 for _ in range(2)] for _ in range(len(N)+1)]
    dp[0][1] = inf
    for d_i in range(len(N)):
        digit = int(N[d_i])
        i = d_i + 1
        dp[i][0] = min(
            dp[i-1][0] + digit,
            dp[i-1][1] + digit + 1,
        )
        dp[i][1] = min(
            dp[i-1][0] + (10 - digit),
            dp[i-1][1] + (10 - (digit + 1))
        )
    print(dp[len(N)][0])

main()



Measured memory_bytes: 166692
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a > mod)a %= mod;
}
ll dp[101][2];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int d;
	string s;
	cin>>s;
	cin>>d;
	int n = s(s);
	dp[0][0] = 1;
	rep(i,n){
		ll temp[d][2];
		rep(j,d){
			rep(k,2)temp[j][k] = 0;
		}
		rep(j,d){
			rep(k,2){
				rep(di,10){
					if(di > s[i]-'0'){
						if(k){
							add(temp[(j+di)%d][k],dp[j][k]);
						}
					}
					else if(di == s[i]-'0'){
						add(temp[(j+di)%d][k],dp[j][k]);
						// add()
					}
					else{
						add(temp[(j+di)%d][1],dp[j][k]);
					}
				}
			}
		}
		rep(j,d){
			rep(k,2){
				dp[j][k] = temp[j][k];
			}	
		}
	}
	ll ans = 0;
	rep(i,2){
		add(ans,dp[0][i]);
	}
	sub(ans,1ll);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using ld = long double;                  //   | grep -v ' .* '  1300111 ~2^20.31
using vl = vector<ll>;                   //                    10300777 ~2^23.30
using vvl = vector<vl>;                  //                   100400999 ~2^26.58
using pll = pair<ll,ll>;                 //                  1300400999 ~2^30.28
using vpll = vector<pll>;                //                 10200500333 ~2^33.25
using vb = vector<bool>;                 //                100200400777 ~2^36.54
using vs = vector<string>;               //               1200300700111 ~2^40.13
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //              10200300500777 ~2^43.21
const ld eps = 1e-9;                     //             100200300400777 ~2^46.51
#define sz(c) ll((c).size())             //            1200300400600999 ~2^50.09
#define all(c) begin(c),end(c)           //           10200300400600111 ~2^53.18
#define mp make_pair                     //          100200300400600333 ~2^56.48
#define mt make_tuple                    //         1200300400500800999 ~2^60.06
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(0) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);

	ll n; cin >> n;
	vvl acts(n+1, vl(3));
	FOR(i,0,n) cin >> acts[i+1][0] >> acts[i+1][1] >> acts[i+1][2];

	vvl dp(n+1, vl(3, 0));
	FOR(i,1,n+1) {
		TR(i);
		vl prev = dp[i-1];
		dp[i][0] = max(prev[1], prev[2]) + acts[i][0];
		dp[i][1] = max(prev[0], prev[2]) + acts[i][1];
		dp[i][2] = max(prev[0], prev[1]) + acts[i][2];
		TR(dp[i][0]);
		TR(dp[i][1]);
		TR(dp[i][2]);
	}

	cout << *max_element(all(dp[n])) << "\n";

	return 0;
}


Measured memory_bytes: 11264
a,b,c,d = map(int, input().split())

AC = a * c
AD = a * d
BC = b * c
BD = b * d

if AC > AD and AC > BC and AC > BD:
    print(AC)
elif AD > BC and AD > BD:
    print(AD)
elif BC > BD:
    print(BC)
else:
    print(BD)


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

map<char,int> cnt;
bool solve() {
    string s;
    cin>>s;
    FORE(x,s) {
        cnt[x]++;
    }
    int n=SZ(s);
    int t=n/3;
    int u=n%3;
    if(cnt['a']<t) return false;
    cnt['a']-=t;
    if(cnt['b']<t) return false;
    cnt['b']-=t;
    if(cnt['c']<t) return false;
    cnt['c']-=t;
    int a=cnt['a'];
    int b=cnt['b'];
    int c=cnt['c'];
    if(a>=2 || b>=2 || c>=2) return false;
    return true;
}
signed main() {
    cout<<(solve()?"YES":"NO")<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void shortestPath(const vector<vector<int> >& graph, int start, vector<int>& dist)
{
    int n = graph.size();
    dist.assign(n, INT_MAX);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(int i=0; i<n; ++i){
            if(graph[v][i] >= 0 && dist[v] + graph[v][i] < dist[i]){
                dist[i] = dist[v] + graph[v][i];
                q.push(make_pair(dist[i], i));
            }
        }
    }

    replace(dist.begin(), dist.end(), INT_MAX, -1);
}

double dfs1(vector<vector<int> >& graph, vector<int>& dist, vector<double>& num, int pos){
     if(num[pos] != -1)
         return num[pos];

     int n = graph.size();
     if(pos == n-1)
         return num[pos] = 1;

     double tmp = 0;
     for(int i=0; i<n; ++i){
         if(graph[pos][i] != -1 && dist[pos] + graph[pos][i] == dist[i])
             tmp += dfs1(graph, dist, num, i);
     }
     return num[pos] = tmp;
}

double dfs2(vector<vector<int> >& graph, vector<int>& dist, vector<double>& num, int pos){
     if(num[pos] != -1)
         return num[pos];

     int n = graph.size();
     if(pos == 0)
         return num[pos] = 1;

     double tmp = 0;
     for(int i=0; i<n; ++i){
         if(graph[i][pos] != -1 && dist[pos] == dist[i] + graph[i][pos])
             tmp += dfs2(graph, dist, num, i);
     }
     return num[pos] = tmp;
}

void solve(vector<vector<int> >& graph, vector<double>& p)
{
    int n = graph.size();
    vector<int> dist;
    shortestPath(graph, 0, dist);

    vector<double> num1(n, -1.0), num2(n, -1.0);
    dfs1(graph, dist, num1, 0);
    dfs2(graph, dist, num2, n-1);

    p.resize(n, 0.0);
    for(int i=0; i<n; ++i){
        if(num2[i] > -0.5)
            p[i] = num1[i] * num2[i] / num1[0];
    }
}

int main()
{
    for(;;){
        int n, m, p;
        cin >> n >> m >> p;
        if(n == 0)
            return 0;

        vector<vector<int> > graph(n, vector<int>(n, -1));
        for(int i=0; i<m; ++i){
            int a, b, c;
            cin >> a >> b >> c;
            graph[a][b] = graph[b][a] = c;
        }

        vector<double> prob;
        solve(graph, prob);
        for(int i=0; i<p; ++i){
            int a;
            cin >> a;
            printf("%.10f\n", prob[a]);
        }
        cout << endl;
    }
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, A):
    b_lcm = 1


    d2 = set()
    for a in A:
        b = a // 2
        b_lcm = b_lcm//math.gcd(b_lcm, b) * b
        for i in range(100000000):
            if a % 2 == 0:
                a //= 2
            else:
                d2.add(i)
                break

    return -(-(M // b_lcm)//2) if len(d2) == 1 else 0





def main():
    N, M = read_int_n()
    A = read_int_n()
    print(slv(N, M, A))


if __name__ == '__main__':
    main()


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

using namespace std;

#define rep(i, n) for(int i = 0; i < static_cast<int>(n); ++i)
#define per(i, n) for(int i = static_cast<int>(n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}

using ll = long long;

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

constexpr char sp = ' ';
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n, ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}

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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s<<'[';for(size_t i=0;i<v.size();++i){s << v[i];if(i < v.size()-1) s << ", ";}s<<']';return s;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    int n, k; cin >> n >> k;
    vector<int> p(n);
    vector<int> s(n+1, 0);
    for(int i = 0; i < n; ++i) cin >> p[i];
    partial_sum(p.begin(), p.end(), s.begin()+1);
    int sum = 0;
    for(int i = 0; i < n-k+1; ++i){
        chmax(sum, s[i+k] - s[i]);
    }
    double ans = (sum+k)/2.0;
    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	//char str[1005];
	cin>>n;
	//sprintf(str,"%d",n);
	int flag=0;
	while(n>0)
	{
		int tmp=n%10;
		if(tmp==7)
		{
			flag=1;
			break;
		}
		n=n/10;
	}
	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3624
// --------------
// Tejas Pandey  |
// 11 - 07 - 20  |
// AIsing ABC    |
// --------------

#include <bits/stdc++.h>
using namespace std;
     
#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int get_res(ll a){
	ll ret = 1;
	while(a){
	ll f = __builtin_popcount(a);
	ret++;
	a%=f;
	} 
	return ret;
}
    
int main (void){
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int val = 0;
  for(int i = 0;i < n;i++) val += (s[i] -'0');
  if(!val){
	for(int i = 0;i < n;i++) cout << "1\n";  
	return 0;
  }
  val++;
  ll cur = 1,res = 0,c2 = 1,res2 = 0;
  vector<int> v;
  for(int i = n - 1;i > -1;i--){
	if(s[i] - '0')
	res += cur,res %= val;
	cur *= 2;
	cur %= val;
	if(val - 2 > 0){
		if(s[i] - '0')
			res2 += c2,res2 %= (val - 2);
			c2 *= 2;
			c2 %= (val - 2);
	}
  }
  cur = 1,c2 = 1;
  for(int i = n - 1;i > -1;i--){
	ll nres = res;
	if(s[i] - '0'){
		if(val - 2 > 0)
		 nres = res2,nres -= c2,nres += (val - 2),nres %= (val - 2);
		else{
			v.push_back(0);
			continue;
		}
	 }
	else nres += cur,nres %= val;
	cur *= 2;
	cur %= val;
	if(val - 2 > 0)
		c2 *= 2,c2 %= (val - 2);
	v.push_back(get_res(nres));
  }
  reverse(v.begin(),v.end());
  for(auto it:v) cout << it << "\n";
  return 0;
}


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

#define ll long long

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define alll(it,A) for(it=A.begin();it!=A.end();it++)

#define err1(a) cout<<a<<endl
#define err2(a,b) cout<<a<<" "<<b<<endl
#define err3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>

const ll N=100005;
const ll M = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,k;cin>>n>>k;
    ll A[max(n,k+1)],dp[max(n,k+1)];
    rep(i,0,n)	dp[i]=M;
    rep(i,0,n)	cin>>A[i];
    dp[0]=0;
    rep(i,1,k+1){
    	dp[i]=abs(A[i]-A[0]);
    }
    rep(i,k+1,n){
    	rep(j,1,k+1){
    		dp[i]=min(dp[i],dp[i-j]+abs(A[i]-A[i-j]));
    	}
    	//err1(dp[i]);
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  int i,j,n,sum=0,x,y,a,b,sum1=0,p,m=0,h;
    cin>>p;
    string s;
    vector<pair<int,string>>imran;
    for(i=0; i<p; i++)
    {
        cin>>s;
        imran.push_back(make_pair(0,s));
    }
    sort(imran.begin(),imran.end());
    j=0,h=0;
    for(i=0;i<p;i++)
    {

        if(imran[j].second==imran[i].second)
        {
            imran[j].first++;
            //cout<<"imran"<<imran[j].first<<endl;
        }
        else
        {
            //cout<<"imran"<<imran[j].first<<endl;
            j=i,i--;

        }
    }
    sort(imran.begin(),imran.end());
    for(i=0;i<p;i++)
     {
        if(imran[p-1].first==imran[i].first)
        {
            cout<<imran[i].second<<endl;
        }
     }

    return 0;

}


Measured memory_bytes: 16748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;


ll dp[1001][1001];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,k;
	cin >> n >> k;

	n-=k;
	FOR(i,0,k+1){
		dp[i][0]=1;
		FOR(j,1,n+1){
			if((j-i)>=0)
				dp[i][j]+=dp[i][j-i];
			if(i>=1)
				dp[i][j]+=dp[i-1][j];
			dp[i][j] %= MOD;
		}
	}
	if(n>=0)cout << dp[k][n] << endl;
	else cout << 0 << endl; 
}


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll N,D,Ans=0;
    ll x,y;
    cin >> N >> D;
    REP(i,N){
        cin >> x >> y;
        if(x*x+y*y<=D*D){
            Ans++;
        }
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 3632
n = int(input())
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
res = 1

nprime = [p for p in prime if p <= n]

for p in prime:
    tempn = n
    tres = 1
    while tempn >= p:
        tempn = tempn // p
        tres += tempn
    res *= tres
    if res > 10**9+7:
        res %= (10**9+7)

print(res)

Measured memory_bytes: 3188
n = int(input())
p = list(map(int,input().split()))
#ans = 0
#for key in range(n):
#    cnt = True
#    for i in range(key+1):
#        if p[i]<p[key]:
#            cnt = False
#    if cnt:
#        ans += 1
#print(ans)

ans = 0
min_left = 2 * 10**5
for i in range(n):
    min_left = min(min_left,p[i])
    if min_left >= p[i]:
        ans += 1
print(ans)

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

int gcd2(int m, int n){
  int div, nom, tmp;
  if(m < n){
    div = m; nom = n;
  }else{
    div = n; nom = m;
  }
  for(;;){
    tmp = nom%div;
    if(tmp == 0) break;
    nom = div;
    div = tmp;
  }
  return div;
}

int gcd(int a, int b, int c){
  return gcd2(gcd2(a, b), c);
}

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

  int sum = 0;
  for(int a=1;a<=K;a++){
    for(int b=1;b<=K;b++){
      for(int c=1;c<=K;c++){
        sum += gcd(a, b, c);
      }
    }
  }

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


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
int A, B; 
cin >> A >> B; 
if((A % 2 == 1) && (B % 2 == 1)){
cout << "Yes" << endl; 
}
else{
cout << "No" << endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<ll,ll>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}


int main(){

  string s;
  cin >> s;
  string t;
  cin >> t;

  int N=sz(s), M=sz(t);
  vector<vector<int>> is(26);

  rep(i, N) is[s[i]-'a'].push_back(i);
  rep(i, N) is[s[i]-'a'].push_back(i+N);

  ll ans = 0;
  int p = 0;

  rep(i, M){
    int c = t[i] - 'a';
    if(sz(is[c]) == 0){
      cout << -1 << endl;
      return 0;
    } 
    p = *lower_bound(is[c].begin(), is[c].end(), p) + 1;
    if(p >= N){
      ans += N;
      p -= N;
    }
  }
  ans += p;
  cout << ans << endl;
  return 0;
}


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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int d,g;
	cin >> d >> g;

	int p[d], c[d];
	rep(i, d) cin >> p[i] >> c[i];

	int mp[d];
	rep(i, d) mp[i] = 100 * (i + 1) * p[i] + c[i];

	int mn = 1e6;
	rep(i, 1 << d){
		int score = 0;
		int cnt = 0;
		rep(j, d){
			if(i & (1 << j)){
				score += mp[j];
				cnt += p[j];
			}
		}

		if(score >= g){
			mn = min(mn, cnt);
			continue;
		}
		
		bool ok = false;
		rrep(j, d){
			if(!(i & (1 << j))){
				if(score + 100 * (j + 1) * (p[j] - 1) >= g){
					cnt += ceil((1.0 * g - score) / (100 * (j+1)));
					ok = true;
				}else{
					score += 100 * (j + 1) * (p[j] - 1);
					cnt += p[j] - 1;
				}
				if(ok) break;
			}
		}

		if(ok) mn = min(mn, cnt);
	}

	cout << mn << endl;
	
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(2e3 + 5);
const int MAX_M = (int)(2e3 + 5);

const ll MOD = (ll)(1e9 + 7);

int n, m;

int s[MAX_N], t[MAX_M];

ll dp[MAX_N][MAX_M];

ll acc[MAX_N][MAX_M];

ll ans;

/////////////////////////////////////////////////////////////
class ModuloOperator {
public:
  ll mo_modulo;

  ModuloOperator(ll modulo) {
    mo_modulo = modulo;
  }

  ll add(ll a, ll b) {
    ll ret = a + b;
    ret %= mo_modulo;
    return ret;
  }

  ll sub(ll a, ll b) {
    ll ret = a - b;
    if (ret < 0) ret += mo_modulo;
    else ret %= mo_modulo;
    return ret;
  }

  ll mul(ll a, ll b) {
    ll ret = a * b;
    ret %= mo_modulo;
    return ret;
  }

  ll div(ll a, ll b) {
    return mul(a, pow(b, mo_modulo - 2));
  }

  ll pow(ll x, ll y) {
    ll res = 1LL;

    x %= mo_modulo;

    while (y > 0) {
      if (y & 1) {
        res = mul(res, x);
      }

      y = y >> 1;
      x = mul(x, x);
    }

    return res;
  }
};
/////////////////////////////////////////////////////////////

ModuloOperator mo(MOD);

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

  for (int i = 1; i <= n; ++i) {
    scanf("%d", &(s[i]));
  }

  for (int i = 1; i <= m; ++i) {
    scanf("%d", &(t[i]));
  }

  for (int i = 0; i <= n; ++i) acc[i][0] = 1LL;
  for (int i = 0; i <= m; ++i) acc[0][i] = 1LL;

  dp[0][0] = 1LL;

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dp[i][j] = (s[i] == t[j]) ? acc[i - 1][j - 1] : 0LL;
      acc[i][j] = mo.add(
        mo.sub(
          mo.add(
            acc[i - 1][j],
            acc[i][j - 1]),
          acc[i - 1][j - 1]),
      dp[i][j]);
    }
  }

  ans = acc[n][m];

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

  return 0;
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};

ll pow_mod(ll n, ll m, ll mod=1000000007){
    ll a = 1;
    while(m>0){
        if(m&1) a = a*n % mod;
        n = n*n % mod;
        m >>= 1;
    }
    return a;
}

ll combi(ll n, ll m, ll mod=1000000007){
    static const ll N_MAX = 200001;
    static vll fac(N_MAX+1, -1);
    static vll ifac(N_MAX+1, -1);

    if(fac[0]<0){
        fac[0] = ifac[0] = 1;
        rep(i, N_MAX){
            fac[i+1] = fac[i] * (i+1) % mod;
            ifac[i+1] = ifac[i] * pow_mod(i+1, mod-2, mod) % mod;
        }
    }

    if(n<=0 && m<=0) return 1;
    if(n<m || n<0) return 0;
    return (ifac[n-m] * ifac[m] % mod) * fac[n] % mod;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll N;
    cin >> N;

    ll s = ((pow_mod(10, N)-pow_mod(9, N)*2) % 1000000007 + 1000000007) % 1000000007;
    s = (s+pow_mod(8, N)) % 1000000007;
    cout << s << endl;
}


Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
	int a[] = new int[10000];
	int b[] = new int[10000];
	public void score(int c1, int c2, int c3, int c4){
		if(c3 > c4){
			a[c1] += 3;
		}else if(c3 < c4){
			a[c2] += 3;
		}else if(c3 == c4){
			a[c1] += 1;
			a[c2] += 1;
		}
	}
	public void rank(int n){
		for(int j = 1; j <= n; j++){
			int an = n;
			for(int k = 1; k <= n; k++){
				if(j == k){
					continue;
				}else if(a[j] >= a[k]){
					an--;
				}
			}
			System.out.println(an);
		}
	}
	
	void doIt(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for(int i = 1; i <= n*(n-1)/2; i++){
			for(int h = 1; h <= 4; h++){
				b[h] = in.nextInt();
			}
			score(b[1], b[2], b[3], b[4]);
		}
		rank(n);
	}
		
	
	public static void main(String[] args) {
			new Main() . doIt();
	}
}

Measured memory_bytes: 43228
//abc124_a.cpp
//Fri Apr 19 20:59:47 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	if (a==b){
		cout << a*2 << endl;
	}else {
		int x = max(a,b);
		cout << x + x -1 << endl;
	}
}

Measured memory_bytes: 256