akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

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

template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template <class T> inline T ison(T n, T pos) { return (bool)(n & ((T)1 << pos)); }
template <class T> inline T gcd(T a, T b) { while (b) { a = a%b; swap(a, b); } return a; }
template <class T> inline T bigmod(T p, T e, T m) { T ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % m; p = (p * p) % m; } return (T)ret; }

const int N = 100000;

int items[N + 1];
int n, m;

long long dp[N + 1];

long long mod = 1000000007;

long long recur(int step) {

	if (step > n) {
		return 0;
	}

	if (step == n) {
		return 1;
	}

	if (items[step] > 0) {
		return 0;
	}

	if (dp[step] != -1) {
		return dp[step];
	}

	long long one = recur(step + 1);
	long long two = recur(step + 2);

	return dp[step]=(one% mod + two% mod)% mod;
}

void solve() {

	SET(dp);

	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int mth;
		cin >> mth;
		items[mth]++;
	}

	long long res = recur(0);
	cout << res << endl;
	
}

int main()
{

	ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(10); cout.tie(nullptr); cin.tie(nullptr);

	int t = 1;

	while (t--) {

		solve();
	}



	return 0;
}

Measured memory_bytes: 4480
using System;
using System.IO;
using System.Collections.Generic;

namespace ABC122A
{
    public partial class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var S = ss.Next();
            if (S == "A") sw.WriteLine("T");
            if (S == "T") sw.WriteLine("A");
            if (S == "C") sw.WriteLine("G");
            if (S == "G") sw.WriteLine("C");
            //---------------------------------
        }
    }

    public class StreamScanner
    {
        static readonly char[] Separator = {' '};
        readonly StreamReader streamReader;

        string[] line = new string[0];
        int index = 0;

        public StreamScanner(Stream stream)
        {
            this.streamReader = new StreamReader(stream);
        }

        public string Next()
        {
            return Next(s => s);
        }

        public string[] Next(int x)
        {
            return Next(s => s, x);
        }

        public string[][] Next(int x, int y)
        {
            return Next(s => s, x, y);
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (index < line.Length) return parser(line[index++]);
            index = 0;
            line = streamReader.ReadLine()?.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }

    public partial class Program
    {
        static void Main()
        {
            Excute(Console.OpenStandardInput(), Console.OpenStandardOutput());
        }

        public static void Excute(Stream input, Stream output)
        {
            var ss = new StreamScanner(input);
            var sw = new StreamWriter(output);
            new Program().Solve(ss, sw);
            sw.Flush();
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

LL n;
LL a[100005];
LL k;
LL numbits[70];
int main(){
	cin >> n >> k;
	FOR(i,0,n) cin >> a[i];
	FOR(i,0,n){
		for (LL j = 0, nx = a[i]; nx > 0; j++, nx>>=1){
			if (nx & 1) numbits[j]++;
		}
	}
//	for (int i = 0; i < 64; i++) cout << numbits[i] << " \n"[i==63];
	LL ans = 0LL;
	for (int i = 63; i >= 0; --i){
		LL now = 1LL << i;
		if (now > k){
			ans += now * numbits[i];
		} else {
			LL m1 = now * numbits[i];
			LL m2 = now * (n - numbits[i]);
			if (m1 >= m2){
				ans += m1;
			} else {
				ans += m2;
				k -= now;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}


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

const int inf = 0x3fffffff;

struct node {
	int delta, minv;
	node *son[2];
} pool[400010], *root;
int idx;

int h, w;
void build(node *p, const int &l, const int &r);
void modify(node *p, const int &l, const int &r, const int &L, const int &R, const int &x);
int query(node *p, const int &des, const int &L, const int &R);

int main() {
	scanf("%d%d", &h, &w);
	build(root = &pool[idx++], 0, w);
	for (int i = 1; i <= h; ++i) {
		int a, b; scanf("%d%d", &a, &b);
		modify(root, a, b, 0, w, query(root, a - 1, 0, w));
		printf("%d\n", root->minv >= inf ? -1 : i + root->minv);
	}
	return 0;
}

void build(node *p, const int &l, const int &r) {
	p->delta = l == r ? l == 0 ? inf : -l : 0;
	p->minv = l == 0 && r == 0 ? inf : 0;
	if (l != r) {
		build(p->son[0] = &pool[idx++], l, l + r >> 1);
		build(p->son[1] = &pool[idx++], (l + r >> 1) + 1, r);
	}
}

void modify(node *p, const int &l, const int &r, const int &L, const int &R, const int &x) {
	if (l == L && r == R) {
		p->delta = x;
		p->minv = x + l;
		return;
	}
	if (p->delta)
		p->son[0]->delta = p->son[1]->delta = p->delta,
			p->son[0]->minv = p->delta + L,
			p->son[1]->minv = p->delta + (L + R >> 1) + 1,
			p->delta = 0;
	if (r <= L + R >> 1)
		modify(p->son[0], l, r, L, L + R >> 1, x);
	else if (l > L + R >> 1)
		modify(p->son[1], l, r, (L + R >> 1) + 1, R, x);
	else {
		modify(p->son[0], l, L + R >> 1, L, L + R >> 1, x);
		modify(p->son[1], (L + R >> 1) + 1, r, (L + R >> 1) + 1, R, x);
	}
	p->minv = min(p->son[0]->minv, p->son[1]->minv);
}

int query(node *p, const int &des, const int &L, const int &R) {
	if (p->delta)
		return p->delta;
	else if (des <= L + R >> 1)
		return query(p->son[0], des, L, L + R >> 1);
	else
		return query(p->son[1], des, (L + R >> 1) + 1, R);
}



Measured memory_bytes: 13088
[A,B,H,M] = list(map(int,input().split()))

X = (H+M*1/60)*30
Y = M*6
Z = min(abs(X-Y),abs(X+360-Y),abs(Y+360-X))
import math
cos = math.cos(math.radians(Z))
print((A**2+B**2-2*A*B*cos)**0.5)


Measured memory_bytes: 62444
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (n-1)/m  + 1 ;
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
const int N = 2e6 + 5 ;
si s ;
bool check ( int x){
	while( x!=0 ){
		int k = x%10 ;
		if( s.find(k) != s.end()) return false ;
		x = x/10 ;
	}
	return true ;
}
signed main(){
	int n , k,x ;
	cin >> n >> k ;
	f(k) cin >> x , s.insert(x) ;

	for ( int i = n; ;i++){
		if ( check(i) ) 
		{
			cout << i ; 
			exit(0) ;
		}
	}
	
	

}

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

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  priority_queue<tuple<i64, i64, int>> ha;
  priority_queue<tuple<i64, i64, int>> hb;
  REP(i, N) {
    i64 a, b;
    cin >> a >> b;
    ha.emplace(a + b, a, i);
    hb.emplace(b + a, b, i);
  }
  i64 sa = 0, sb = 0;
  vector<bool> taken(N, false);
  REP(i, N) {
    if (i % 2 == 0) {
      i64 h, a, j;
      for (;;) {
        tie(h, a, j) = ha.top();
        if (!taken[j]) break;
        ha.pop();
      }
      taken[j] = true;
      sa += a;
    } else {
      i64 h, b, j;
      for (;;) {
        tie(h, b, j) = hb.top();
        if (!taken[j]) break;
        hb.pop();
      }
      taken[j] = true;
      sb += b;
    }
  }
  cout << (sa - sb) << endl;
}


Measured memory_bytes: 8148
#include<iostream>
#include<math.h>
using namespace std;
void week_1_E()
{
    struct M
    {
        int x, y, h;
    }*arr, *All;
    int N, n = 0, n1 = 0;
    cin >> N;
    arr = new M [N];
    All = new M [N];
    for (int i = 0; i < N; i ++)
    {
        int x, y, h;
        cin >> x >> y >> h;
        if( h == 0 )
        {
            All[n1].x = x;
            All[n1].y = y;
            All[n1++].h = 0;
            continue;
        }
        arr[n].x = x;
        arr[n].y = y;
        arr[n++].h = h;
    }
    int H;
    
    for (int A = 0; A < 101; A++)
        for (int B = 0; B < 101; B++)
        {
            int *temp, flag = 0;
            temp = new int[n];
            temp[0] = abs(A-arr[0].x) +abs(B-arr[0].y) + arr[0].h;
            if (temp[0] < 1)
                flag = 1;
            else
               for (int i = 1; i < n; i++)
               {
                  temp[i] = abs(A-arr[i].x) +abs(B-arr[i].y) + arr[i].h;
                  flag = ( temp[i] != temp[0] );
                   if(flag) break;
               }
            
            if(!flag)
            {
                H = temp[0];
                int flag1 = 0;
                for (int j = 0; j < n1; j++)
                {
                    int h ;
                    h = H - abs(A-All[j].x) - abs(B-All[j].y);
                    if(h < 0)
                        continue;
                    if(h)
                    {
                        flag1 = 1;
                        break;
                    }
                }
                if (!flag1)
                {
                    cout << A << ' ' << B << ' ' << H;
                    return;
                }
            }
            delete []temp;
        }
}
int main()
{
    week_1_E();
    return 0;
}

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

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    int dp[50];
    rep(i,50)dp[i]=0;
    dp[0]=1;
    rep(i,40){
        dp[i+1]+=dp[i];
        dp[i+2]+=dp[i];
        dp[i+3]+=dp[i];
    }
    
    
    int n;
    while(cin>>n){
        if(n==0)break;
        int num = (int)((dp[n]-1)/3650)+1;
        cout<<num<<endl;
    }

}

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

int main(int argc, const char * argv[]) {
    int N; cin >> N;
    
    int sum = N;
    while (sum <= 999) {
        string st = to_string(sum);
        if (st[0] == st[1] && st[1] == st[2]) {
            cout << sum << endl;
            return 0;
        }
        sum++;
    }

    return 0;
}


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

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

    int h,a;
    cin >> h >> a;

    int cnt = 0;
    while(h > 0){
        h -= a;
        cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    double a,b,c,d,e,f;
    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF)
    {
        
        double x=(c*e-b*f)/(a*e-b*d);
        double y=(c*d-a*f)/(b*d-a*e);
        x+=0.00;
        y+=0.00;
        printf("%.3f %.3f\n",x,y);
        
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> times(N);
  int times_sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> times.at(i);
    times_sum += times.at(i);
  }
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int P, X;
    cin >> P >> X;
    cout << times_sum - times.at(P - 1) + X << endl;
  }
  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
	ll n, r;
	cin >> n >> r;
	ll rate = r;
	if (n <= 10) {
		rate = r+  100 * (10 - n);
	}
	cout << rate << endl;
	system("PAUSE");
}

Measured memory_bytes: 504
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

t = 1
N = int(input())
K = int(input())

dp = [0]*(N+1)
dp[0] = 1

for i in range(1, N+1):
    dp[i] = min(dp[i-1]+K, dp[i-1]*2)
print(dp[-1])


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


struct ch {
	int ver, idx, pre;
};

vector<int> a(200010);
vector<vector<int>> graph(200010);
vector<int> lis(200010, inf);
vector<int> ans(200010);
stack<ch> st;

void dfs(int n, int p) {
	int pl = lower_bound(all(lis), a[n]) - lis.begin();
	st.push({ n,pl,lis[pl] });
	lis[pl] = a[n];
	ans[n] = lower_bound(all(lis), inf) - lis.begin();
	for (int i : graph[n]) {
		if (i != p) {
			while (!st.empty() && st.top().ver != n) {
				ch c = st.top(); st.pop();
				lis[c.idx] = c.pre;
			}
			dfs(i, n);
		}
	}
}

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

	int n;
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n - 1) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		graph[u].pb(v);
		graph[v].pb(u);
	}
	dfs(0, -1);
	rep(i, n) cout << ans[i] << '\n';
}

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

int main()
{
    int h,w;
    cin >> h >> w;
    while(h!=0)
    {
        int i,j;
        for(i=0; i<h; i++)
        {
            for(j=0; j<w; j++)
            {
                if(i%2==0&&j%2==0||i%2==1&&j%2==1)
                    cout << "#";
                else
                    cout<<".";
            }
            cout << endl;
        }
        cout << endl;
        cin >> h >> w;
    }
    return 0;
}



Measured memory_bytes: 3088
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    double X;
    double nisin[12]={128,64,32,16,8,4,2,1,0.5,0.25,0.125,0.0625};
    while(cin>>X){
        X+=0.00000001;
        if(X<0)break;
        int check[12]={0};
        for(int i=0;i<12;i++){
            if(X>nisin[i]){
                //printf("[%d]",i);
                X-=nisin[i];
                check[i]=1;
            }
        }
        if(fabs(X)<0.000001){
            for(int i=0;i<12;i++){
                cout<<check[i];
                if(i==7)cout<<'.';
            }
            puts("");
        }
        else puts("NA");
    }
    return 0;
}

Measured memory_bytes: 1224
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if v <= w:
    print("NO")
else:
    if a < b:
        time = (b-a)/(v-w)
        if time <= t:
            print("YES")
        else:
            print("NO")
    if b < a:
        time = (a-b)/(v-w)
        if time <= t:
            print("YES")
        else:
            print("NO")


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
    cin >> N;
    int cnt = 0;
    int total = 0;
    for(int i = 1; i <= N; ++i) {
        if(i % 2 != 0) {
            for(int j = 1; j <= i; ++j) {
                if(i % j == 0) cnt++;
            }
            if(cnt == 8) total++;
            cnt = 0;
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {

    let n = read_t_in_line::<i64>()[0];
    let mut ans = -1;
    for i in 1..(n+1) {
        let r = i * i;
        if r > n {
            break;
        }
        ans = max(ans, r);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	arr := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&arr[i])
	}
	ans := 1
	for _, v := range arr {
		ans = lcm(ans, v)
	}
	fmt.Println(ans)
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;

using ll = long long;
const int N = 1e5+5;

int main()
{
    ios_base::sync_with_stdio(0);

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

    vector<ll> l(n),r(n);
    ll GCD = 0;
    for(int i = 0; i < n; ++i) {
        GCD = __gcd(GCD, a[i]);
        l[i] = GCD;
    }

    GCD = 0;
    for(int i = n-1; i >= 0; --i) {
        GCD = __gcd(GCD, a[i]);
        r[i] = GCD;
    }

    ll ans = 1;
    for(int i = 0; i < n; ++i) {
        if(i == 0) {
            ans = max(ans, r[1]);
            continue;
        }
        if(i == n-1) {
            ans = max(ans, l[n-2]);
            continue;
        }
        ans = max(ans, __gcd(l[i-1], r[i+1]));
    }
    cout << ans;
    return 0;
}


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

static const int MIN = -1 * (1 << 21);

int main() {
	int i, j, n, a, maxa, max_so_far, max_ending_here;
	
	while (1) {
		cin >> n;
		if (n == 0)break;
		max_so_far = 0;
		max_ending_here = 0;
		maxa = MIN;
		for (i = 0; i < n; i++) {
			cin >> a;
			maxa = max(maxa, a);
			max_ending_here = max_ending_here + a;
			if (max_ending_here < 0)max_ending_here = 0;
			if (max_so_far < max_ending_here)max_so_far = max_ending_here;
		}
		if (max_so_far == 0)max_so_far = maxa;
		cout << max_so_far << endl;

	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,D1,D2,i,zorome_counter=0;
  cin >> N;
  for(i=1;i<=N;i++){
    cin >> D1>>D2;
    if(D1==D2){
      zorome_counter++;
    }else{
      zorome_counter=0;
    }
    if(zorome_counter==3){
      break;
    }
  }
  if(zorome_counter==3){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

Measured memory_bytes: 3556
N, P = map(int, input().split())
S = input()
ans = 0
if P in [2, 5]:
    for l, s in enumerate(S, 1):
        if int(s) % P == 0: ans += l
else:
    counter = [0] * P
    counter[0] = 1
    prev = 0
    temp = 1
    for i, s in reversed(list(enumerate(S))):
        num = (int(s) * temp + prev) % P
        ans += counter[num]
        counter[num] += 1
        prev = num
        temp = (temp * 10) % P
print(ans)

Measured memory_bytes: 24040
#include <iostream>

using namespace std;

int main()
{
    while(1)
    {
        int n,m;
        cin>>n>>m;if(!n)return 0;
        int a[1000]={0};
        for(int i=0;i<n;++i){
            cin>>a[i];
        }
        int now=0,res=0,d[1000]={0};
        for(int i=0;i<m;++i){
            cin>>d[i];
        }
        for(int i=0;i<m;++i){
            res++;
            now+=d[i];
            if(now>=n-1){break;}
            now+=a[now];
            if(now>=n-1){break;}
        }
        cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 1164
N,M,*as=$<.read.split.map(&:to_i)
mod=10**9+7
fib = Array.new(N+1,1)
2.upto(N) do |i|
    fib[i] = fib[i-2]+fib[i-1]
end
prev = 0
ret = 1
as << N+1
as.each do |a|
    if prev == a
        puts 0
        exit
    end
    ret = ret * fib[a-prev-1] % mod
    prev = a+1
end
puts ret


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF 1000000000 //
#define LINF (ll)4000000000000000000 //
#define MOD (ll)1000000007
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    int n;
    ll x;
    cin >> n >> x;
    ll a[n];
    rep(i, n) cin >> a[i];

    ll cost = 0;
    if (a[0] > x) {
        cost += a[0] - x;
        a[0] = x;
    }

    rep2(i, n - 1) {
        ll sum = a[i] + a[i - 1];
        if (sum > x) {
            cost += sum - x;
            a[i] -= sum - x;
        }
    }

    cout << cost << endl;

    return 0;
}



Measured memory_bytes: 1024
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    rep(bit, 1<<n) {
        cout << bit << ":";
        rep(i, n) {
            if (bit >> i & 1) cout << " " << i;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string T; cin >> T;

    for(int i=0;i<T.size();i++){
        if(T[i]=='?'){
            cout << "D";
        }else{
            cout << T[i];
        }
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >>N;
  string S;
  cin >>S;
  for(int i=0; i<S.size()-1; i++){
    if(S[i]==S[i+1]){
      S.erase(S.begin()+i);
      i--;
    }
  }
  cout << S.size() << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll ans = (ll)(pow(k-1, n-1) + 0.5);
    ans *= k;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 384
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.input()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: usize = sc.input();
    let mut arr: Vec<usize> = sc.vec(n);

    arr.sort_by_key(|&x| std::cmp::Reverse(x));
    let mut ans = arr[0];
    for i in 0..n - 2 {
        ans += arr[i / 2 + 1];
    }
    println!("{}", ans);
}


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

#define int long long
#define REP(i, n) for ( int i = 0; i < (n); i++ )

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  cin >> N >> M;

  if ( N == M ) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
#define p(x) cout<<(x)<<endl
#define pv(v) for(auto a: array){ cout << a << endl; }

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

  vector <int> array(n);
  rep(i, n){
    cin >> array[i];
  }

  int i; i=0;
  rep(z, n) {
    if (i == 1){
      p(z);
      return 0;
    }
    i = array[i] - 1;
  }
  p(-1);
}


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

struct Card {char suit, value; };

void bubble(struct Card A[], int N) {
 for ( int i = 0; i < N; i++ ) {
  for ( int j = N - 1; j >= i + 1; j-- ) {
   if ( A[j].value < A[j - 1].value ) {
     Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t;
    }
  }
 }
}

void selection(struct Card A[], int N) {
 for ( int i = 0; i < N; i++ ) {
 int minj = i;
 for ( int j = i; j < N; j++ ) {
   if ( A[j].value < A[minj].value ) minj = j;
}
Card t = A[i]; A[i] = A[minj]; A[minj] = t;
}
}

void print(struct Card A[], int N) {
 for ( int i = 0; i < N; i++ ) {
  if ( i > 0 ) cout << " ";
  cout << A[i].suit << A[i].value;
}
cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
 for ( int i = 0; i < N; i++ ) {
  if ( C1[i].suit != C2[i].suit ) return false;
}
return true;
}

int main() {
  Card C1[100], C2[100];
  int N;
  char ch;

  cin >> N;
  for ( int i = 0; i < N; i++ ) {
    cin >> C1[i].suit >> C1[i].value;
}

for ( int i = 0; i < N; i++ ) C2[i] = C1[i];

bubble(C1, N);
selection(C2, N);

print(C1, N);
cout << "Stable" << endl;
print(C2, N);
if ( isStable(C1, C2, N) ) {
 cout << "Stable" << endl;
} else {
 cout << "Not stable" << endl;
}

return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    int N;
    cin >> N;
    int A[N];
    int co=0;
    rep(i,N) {
        cin >> A[i];
        if(A[i]%2==0) co++;
    }
    long long ans=pow(3,N)-pow(2,co);

    cout << ans << endl;


}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    ll H, W;
    int n;
    cin >> H >> W >> n;

    using P = pair<int, int>;
    map<P, int> ma;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        a--; b--;
        for(int i=-2; i<=0; i++){
            for(int j=-2; j<=0; j++){
                int y = a+i;
                int x = b+j;
                if(0<=y && y+2<H && 0<=x && x+2<W) ma[{x, y}]++;
            }
        }
    }

    vector<ll> ans(10);
    for(auto p: ma) ans[p.second]++;
    ll sum = accumulate(all(ans), 0LL);
    ans[0] = (H-2)*(W-2) - sum;

    rep(i, ans.size()) cout << ans[i] << endl;
}

Measured memory_bytes: 56448
/*input
10 4 8

*/
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define trace1(x) cout<<#x<<": "<<x<<endl
#define trace2(x, y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cout<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
 
//typedef long long ll;
#define int long long
#define ll long long

 
#define PI 3.141592653589793
#define MOD 1000000007
#define INF 1e15
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; a=a%m; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
/*prime m*/ template<typename T> T modInv(T a, T m){return pow(a,m-2,m);} 

#define MAX 2005
int ans[MAX];


int32_t main() {
	IOS

	int n, x, y; cin>>n>>x>>y;

	for(int i = 1; i<n; i++){
		for(int j = i+1; j<=n; j++){
			int dist = abs(j-i);
			dist = min(dist, abs(j-x) + abs(y-i) + 1);
			dist = min(dist, abs(j-y) + abs(x-i) + 1);
			ans[dist]++;
		}
	}

	for(int j = 1; j<n; j++){
		cout<<ans[j]<<endl;
	}



 
return 0;
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<long double,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

int main()
{
  long double N;
  cin >> N;
  long double K;
  cin >> K;
  VEC(ll,inA,N);
  vll A=inA;
  long double sum = 0;
  REP(i,sz(A)){
    sum+=A[i];
  }
  long double x = sum/(K+N);
  vll ans(N,0);
  ll cntK=0;
  REP(i,N){
    int j=A[i]/x;
    if(j!=0){
      A[i]/=j;
      ans[i]+=j-1;
      cntK+=j-1;
    }
  }

  priority_queue<P> pq;
  REP(i,sz(A)){
    pq.push(make_pair(A[i],i));
  }
  REP(i,K-cntK){
    ans[pq.top().se]++;
    ll y = pq.top().se;
    pq.pop();
    long double z = A[y];
    pq.push(make_pair(z/(ans[y]+1),y));
  }
  
  ll MAX = 0;
  REP(i,N){
    MAX=max(MAX,(inA[i]+ans[i])/(ans[i]+1));
  }
  cout << MAX << endl;
}

Measured memory_bytes: 16384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n;
int a[60];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	bool tp=1;
	for(int i=1;i<=n;i++)if(a[i]!=i){
		tp=0;break;
	}
	if(tp){
		
				puts("YES");
				return 0;
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++){
			swap(a[i],a[j]);
			bool flg=1;
			for(int k=1;k<=n;k++)if(a[k]!=k){flg=0;break;}
			if(flg){
				puts("YES");
				return 0;
			}
			swap(a[i],a[j]);
		}
	puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

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

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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007

//container-use 

typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< ll,ll > pll;
typedef vector<pair<ll,ll > > vpl;
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,a,b) for (int i = a; i <= b; i++)

//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    char c;
    cin>>c;
    cout<<char(c+1);
  return 0;
 }

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n;cin>>n;
    vector<ll> v(n),w(n);
    REP(i,n){
        cin>>v[i];
    }
    REP(i,n){
        cin>>w[i];
    }
    ll max=0;
    REP(i,n){
        ll candy=0;
        REP(j,i+1){
            candy+=v[j];
        }
        for(int k=n-1; k>=i ;k--){
            candy+=w[k];
        }
        if(max<candy){
            max=candy;
        }
    }
    
    cout<<max;
    return 0;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<complex>
#define inf 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define ll long long
#define pii pair<int,int> 
const int N=1e6+10;
const int mod=1e9+7;
using namespace std;

int f[N],inv[N];
ll ksm(ll a, ll k){
    ll ans=1;
    while(k){if(k&1) ans=ans*a%mod; a=a*a%mod; k>>=1;}
    return ans;
}
void init(int n){
    f[0]=1; inv[0]=1;
    for(int i=1;i<=n;++i) f[i]=1LL*f[i-1]*i%mod,inv[i]=ksm(f[i],mod-2);
}
vector<int> v[N];
int n,dp[N],sz[N],ans[N];
void dfs(int x, int fa=-1){
    sz[x]=1; dp[x]=1;
    for(auto e: v[x]) if(e!=fa){
        dfs(e,x);
        sz[x]+=sz[e];
        dp[x]=1LL*dp[x]*dp[e]%mod*inv[sz[e]]%mod;
    }
    dp[x]=1LL*dp[x]*f[sz[x]-1]%mod;
}
void dfs2(int x, int fa=-1){
    ans[x]=dp[x];
    ll tmp=dp[x];
    for(auto e: v[x]) if(e!=fa){
        ll ff=1LL*tmp*ksm(dp[e],mod-2)%mod*inv[n-1]%mod*f[sz[e]]%mod*f[n-1-sz[e]]%mod;
        dp[e]=ff*dp[e]%mod*inv[sz[e]-1]%mod*f[n-1]%mod*inv[n-sz[e]]%mod; 
        dp[x]=ff;
        dfs2(e,x);
    }
}
void solve(){
    scanf("%d",&n);
    init(n);
    for(int i=1,x,y;i<n;++i){
        scanf("%d%d",&x,&y);
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1);
    dfs2(1);
    for(int i=1;i<=n;++i) printf("%d\n",ans[i]);
}
int main() 
{
    int _=1;  //scanf("%d",&_);
    while(_--) solve();
return 0;
}
/*
2 1
1 2
*/




Measured memory_bytes: 46836
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl; 
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF =0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a,LL b){LL s=1;while(b>0){if(b&1)s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
LL gcd(LL a,LL b) {return b?gcd(b,a%b):a;}
int dr[2][4] = {1,-1,0,0,0,0,-1,1};
typedef pair<int,int> P;

const int maxn =1e5+10;
char ar[maxn],br[maxn],cr[2*maxn];

int nxt[maxn*2][27];
int main(void)
{
    cin>>ar>>br;
    int n = strlen(ar);
    int m = strlen(br);
    for(int i = 0;i < n; ++i)
        cr[i] = cr[i+n] = ar[i];
    for(int j = 0;j < 26; ++j)
        nxt[2*n][j] = -1;
    for(int i = 2*n-1;i >= 0; --i){

        for(int j = 0;j < 26; ++j)
            nxt[i][j] = nxt[i+1][j];
        nxt[i][cr[i]-'a'] = i;
    }
    LL ans = 0;
    int j = 0;
    for(int i = 0;i < m;++i){
        if(nxt[j][br[i]-'a']==-1){
            // ans = 1e8;
            ans =-1;
            break;
        }
        int t = nxt[j][br[i]-'a'];
        ans += t-j+1;
        j = (t+1)%n;

    }
   
    cout<<ans<<endl;
   return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

LL n, a;
LL ans;

int main() {
    //freopen("input.txt", "r", stdin);
    cin >> n >> a;
    ans = n;
    for (int cnt = 2; ; ++cnt) {
        LL prod = 1;
        int sum = 2 * cnt;
        forn(i, cnt) {
            prod *= 2;
        }
        if (prod >= n) {
            ans = min(ans, sum + a * (cnt - 1));
            break;
        }
        for (int i = 2; ; ++i) {
            forn(j, cnt) {
                prod /= i;
                prod *= i + 1;
                ++sum;
                if (prod >= n) {
                    break;
                }
            }
            if (prod >= n) {
                break;
            }
        }
        ans = min(ans, sum + a * (cnt - 1));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
from collections import defaultdict
from collections import deque


def bfs(s):
    queue = deque([s])
    cv = [0] * n
    cv[s] = 1
    dist[0] = 0
    while queue:
        u = queue.popleft()
        for nxt in adj[u]:
            if not cv[nxt]:
                queue.append(nxt)
                cv[nxt] = 1
                if dist[u] + 1 < dist[nxt]:
                    dist[nxt] = dist[u] + 1
                    parent[nxt] = u


def dfs(u):
    st = [u]
    cv = [0] * n
    dist[0] = 0
    while st:
        u = st.pop()
        if cv[u]:
            continue
        cv[u] = 1
        for nxt in adj[u]:
            if dist[u] + 1 < dist[nxt]:
                parent[nxt] = u
                dist[nxt] = dist[u] + 1
            st.append(nxt)


n, m = [int(item) for item in input().split()]
parent = [-1] * n
dist = [float('inf')] * n
parent[0] = 0
adj = defaultdict(list)
for i in range(m):
    u, v = [int(item) - 1 for item in input().split()]
    adj[u].append(v)
    adj[v].append(u)
bfs(0)
# print(parent, adj)
if -1 in parent:
    print("No")
else:
    print("Yes")
    for i in range(1, n):
        print(parent[i] + 1)


Measured memory_bytes: 39872
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (_N, _M, r): (usize, usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let (_A, _B, _C): (Vec<usize>, Vec<usize>, Vec<i64>) = {
        let (mut _A, mut _B, mut _C) = (vec![], vec![], vec![]);
        for _ in 0.._M {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            _A.push(iter.next().unwrap().parse().unwrap());
            _B.push(iter.next().unwrap().parse().unwrap());
            _C.push(iter.next().unwrap().parse().unwrap());
        }
        (_A, _B, _C)
    };
    // snip
    let _G = {
        let mut _G = vec![std::collections::HashMap::new(); _N + 1];
        for i in 0.._M { _G[_A[i]].insert(_B[i], _C[i]); }
        _G
    };
    // snip

    let V = _N;
    let E = _M;
    let s = _A;
    let t = _B;
    let d = _C;
    let G = _G;
    const INF: i64 = 1_000_000_000_000_000;
    let mut dp = vec![INF; V];
    let mut q = std::collections::BinaryHeap::new();
    q.push((0, r));
    while !q.is_empty() {
        let (dist, i) = {
            let (dist, i) = q.pop().unwrap();
            (-dist, i)
        };
        if dist < dp[i] {
            dp[i] = dist;
            for (&j, &w) in &G[i] { q.push((-(dist + w), j)); }
        }
    }
    let ans = dp.iter()
        .map(|&dist| if dist < INF { dist.to_string() } else { "INF".to_string() } )
        .collect::<Vec<_>>()
        .join("\n");

    println!("{}", ans);
}


Measured memory_bytes: 107444
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int a, b;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        a = sc.nextInt();
        b = sc.nextInt();
        solve();
    }

    void solve() {
        int c = a + b;
        if (c >= 24) {
            c -= 24;
        }
        System.out.println(c);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21076
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;

class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws IOException {
        int a = ReadInt();
        int b = ReadInt();
        int c = ReadInt();
        int res = 0;
        for(int i = a; i <= b; ++i) {
            if( c % i == 0 ) res += 1;
        }
        System.out.println(res);
    }
    static int ReadInt() throws IOException {
        return Integer.parseInt(sc.next());
    }
}

Measured memory_bytes: 26308
#include <iostream>
#include <vector>
//#include <algorithm>

using namespace std;

struct object
{
    int weight, value;
    object(){};
};

int main()
{
    int no_of_objects, capacity;
    cin >> no_of_objects >> capacity;

    vector<object> O(no_of_objects + 1);
    for (int i = 1; i <= no_of_objects; i++)
    {
        cin >> O[i].weight >> O[i].value;
    }

    long long total_value = 0;
    for (int i = 1; i <= no_of_objects; i++)
    {
        total_value += O[i].value;
    }

    int answer = 0;
    vector<long long> minimum_weight(total_value + 1, -1);
    total_value = 0;
    minimum_weight[0] = 0;

    for (int i = 1; i <= no_of_objects; i++)
    {
        total_value += O[i].value;

        for (int v = total_value; v >= O[i].value; v--)
        {
            if (minimum_weight[v - O[i].value] != -1)
            {
                long long weight_required = minimum_weight[v - O[i].value] + O[i].weight;

                if (weight_required <= capacity)
                {
                    answer = max(answer, v);
                }

                if (minimum_weight[v] == -1 || minimum_weight[v] > weight_required)
                {
                    minimum_weight[v] = weight_required;
                }
            }
        }
    }

    cout << answer;

    return 0;
}


Measured memory_bytes: 1024