akhauriyash/Code-Regression huggingface dataset:
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

// get sum of [0..pos]
fn get_acc(v: &Vec<usize>, pos: usize) -> usize {
    return v[pos];
}

fn get_acc_ranges(v: &Vec<usize>, cur: usize, r: (usize, usize)) -> usize {
    let mm: usize = 998244353;
    if cur < r.0 {
        return 0;
    }
    let mut ans = get_acc(v, cur - r.0);

    if cur < r.1 + 1 {
        return ans;
    }

    ans += mm - get_acc(v, cur - r.1 - 1);
    return ans % mm;
}
fn main() {
    let line = read_as_vec::<usize>();
    let (n, k) = (line[0], line[1]);
    let mut s: Vec<(usize, usize)> = vec![];
    for _ in 0..k {
        let line = read_as_vec::<usize>();
        s.push((line[0], line[1]));
    }
    let mm: usize = 998244353;

    let mut dp: Vec<usize> = vec![0; n];
    dp[0] = 1;
    let mut acc: Vec<usize> = vec![1];

    for i in 1..n {
        //println!("\n**** i = {} ****", i);
        for r in &s {
            // println!("r = {:?}", r);
            // println!("before dp = {:?}", &dp);
            dp[i] = (dp[i] + get_acc_ranges(&acc, i, *r)) % mm;
            //println!("after  dp = {:?}\n", &dp);
        }
        acc.push(dp[i] + acc[i - 1]);
        acc[i] = acc[i] % mm;
        //println!("{:?}", acc);
    }
    // println!("{:?}", &dp);
    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 5284
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]
red = [0] * N
red[0] = 1
ballnum = [1] * N

for a,b in src:
    a,b = a-1,b-1
    ballnum[b] += 1
    ballnum[a] -= 1
    if red[a]:
        red[b] = 1
        if not ballnum[a]:
            red[a] = 0
print(sum(red))

Measured memory_bytes: 18140
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int MAXN = 200005;
const int MOD = 1000000007;

vector<int> g[MAXN];
ll even,odd,isolated,tim;
int vis[MAXN];

int dfs(int a,int f){
	vis[a] = f;
	int ans = 0;
	for(int i:g[a]){
		if(vis[i] && (vis[a] - vis[i]) == 0) ans = 1;
		if(!vis[i]){
			int k = dfs(i,3-f);
			if(k) ans = 1;
		}
	}
	return ans;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n; cin >> n;
	int m; cin >> m;
	for(int i=0;i<m;i++){
		int a,b; cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			if(g[i].size() == 0) {
				isolated++; continue;
			}
			int k = dfs(i,1);
			if(k) odd++;
			else even++;
		}
	}
	ll ans = odd * (odd + even) + even * (even * 2 + odd) + (n - isolated) * isolated * 2 + isolated * isolated;
	cout << ans << '\n';
	return 0;
}


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

inline int addmod(lli x,lli y)
{
    return (x%mod + y%mod)%mod;
}
inline int submod(lli x,lli y)
{
    return (x%mod - y%mod + mod)%mod;
}
inline int mulmod(lli x,lli y)
{
    return (x%mod * y%mod)%mod;
}

inline int nextSubMask(int i, int mask)
{
    return (i-1)&mask;   /// returns next  submask
}

template<typename T>
void we_r_done(T mssg)
{
    cout<<mssg;
    exit(0);
}

const int N = 1e5 + 5;
int parent[N] , Size[N];

int Find(int x){
    if(parent[x] == x) return x;
    return parent[x] = Find(parent[x]);
}
int main()
{
    ///freopen("output.txt","w",stdout);
   // freopen("input.txt","r",stdin);
    FastIO;

    int n,m;
    while(cin>>n>>m){
        for(int i=1; i<=n; i++){
            parent[i] = i;
            Size[i] = 1;
        }
        vector<pii>v;
        for(int i=1; i<=m; i++){
            int x,y;
            cin>>x>>y;
            v.pb({x,y});
        }
        lli res[m+1];
        res[m] = (n-1)*1LL*n;
        res[m] /= 2;
        for(int i=m; i ; i--){
            int p1 = Find(v[i-1].fi);
            int p2 = Find(v[i-1].se);

            if(p1 == p2) res[i-1] = res[i];
            else{
                res[i-1] = res[i] - Size[p1]*1LL*Size[p2];
                Size[p1] += Size[p2];
                parent[p2] = p1;
            }
        }
        for(int i=1; i<=m; i++) cout<<res[i]<<"\n";

       // cout<<endl;
    }


    return 0;
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?
///sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b : x.a<y.a);});


Measured memory_bytes: 3828
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
		String S = sc.next();
		char[] s = S.toCharArray();
      
        long r = 0;
        long g = 0;
        long b = 0;
        for(int i = 0; i < n; i++){
          if(s[i] == 'R'){
            r++;
          }else if(s[i] == 'G'){
            g++;
          }else{
            b++;
          }
        }
      
        long all = r*g*b;
        long ans = 0;
      
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++){
              if(s[i] == s[j]){
                continue;
              }
              
                int k = j*2-i;
                
              if(k >= n || s[k] == s[i] || s[k] == s[j]){
                  continue;
              }
                  ans++;
            }
		}
		
		System.out.println(all - ans);
	}
}

Measured memory_bytes: 35796
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var dic1 = new Dictionary<int, long>();
        var dic2 = new Dictionary<int, long>();

        for(int i = 0; i < N; i++)
        {
            int a = A[i] + i;
            int b = i - A[i];
            if (!dic1.ContainsKey(a))
            {
                dic1[a] = 1;
            }
            else
            {
                dic1[a]++;
            }
            if (!dic2.ContainsKey(b))
            {
                dic2[b] = 1;
            }
            else
            {
                dic2[b]++;
            }
        }
        long count = 0;
        foreach(int i in dic1.Keys)
        {
            if (dic2.ContainsKey(i))
            {
                count += dic1[i] * dic2[i];
            }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 67848
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

ll n;
vector<int> G[N];
vector<ll> X;
bool can;

ll saiki(int now){
	if(G[now].size() == 0){
		return 0;
	}
	vector<ll> x;
	vector<ll> kouho;
	bool hamidasi = false;
	rep(i, G[now].size()){
		int next = G[now][i];
		kouho.push_back(saiki(next));
		x.push_back(X[next]);
		if(kouho[i] > X[now]) hamidasi = true;
	}
	vector<bool> dp;
	rep(i,5002){
		dp.push_back(false);
	}
	dp[0] = true;

	ll sum = 0;
	rep(i,kouho.size()){
		sum += kouho[i];
		sum += x[i];
		vector<bool> dp2;
		rep(j,5002){
			dp2.push_back(false);
		}
		rep(j,5002){
			if(dp[j]){
				if(j + x[i] < 5002){
					dp2[j + x[i]] = true;
				}else{
					dp2[5001] = true;
				}
				if(j + kouho[i] < 5002){
					dp2[j + kouho[i]] = true;
				}else{
					dp2[5001] = true;
				}
			}
		}
		dp = dp2;
	}

	REP(i, dp.size()-1){
		if(dp[i] && i <= X[now]){
			return min((ll)5001, sum - i);
		}
	}
	cerr<<now<<" "<<dp[2]<<endl;
	can = false;
	return 0;
}

int main(void){
	cin>>n;
	reps(i,n-1){
		int p; cin>>p;p--;
		G[p].push_back(i);
	}
	rep(i,n){
		ll x;cin>>x;
		X.push_back(x);
	}
	can = true;
	saiki(0);
	cout<<(can?"POSSIBLE":"IMPOSSIBLE")<<endl;
	return 0;
}


Measured memory_bytes: 7804
N = int(input())
d_arr = []
for i in range(N):
    d_arr.append(int(input()))

# d_arr = [5,5]
# N = len(d_arr)
d_max = max(d_arr)
d_ind = d_arr.index(d_max)

for i in range(N):
    if i == d_ind:
        d_arr.pop(d_ind)
        print(max(d_arr))
    else:
        print(d_max)


Measured memory_bytes: 12520
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
        EXPLAINATION BELOW->
        
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
void solve()
{
   ll n,r;cin>>n>>r;
   if(n>=10)cout<<r;
   else cout<<r+(100)*(10-n);
   cout<<"\n";
}
int main()
{
   fastio
   solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using ll = long long;

int n;
vector<ll> a;
vector<ll> imos;

ll sum(ll l, ll r){
    return imos[r] - imos[l];
}

ll get(int l, int r, ll lb){
    ll x = l;
    while(l+1 < r){
        int m = (l+r)/2;
        if(sum(x,m) < lb) l = m;
        else r = m;
    }
    return r;
}

bool check(ll lb){
    ll S = sum(0,n);
    rep(i,n){
        ll x = get(i,i+n,lb);
        if(S - sum(i,x) < lb) return false;
        ll y = get(x,i+n,lb);
        if(sum(i,x) >= lb && sum(x,y) >= lb && sum(y,i+n) >= lb){
            return true;
        }
    }
    return false;
}

ll solve(){
    a.insert(a.end(), a.begin(), a.end());
    imos.assign(a.size()+1,0);
    rep(i,a.size()) imos[i+1] = imos[i] + a[i];
    ll l = 1, r = imos[n];
    while(l+1 < r){
        ll m = (l+r)/2;
        if(check(m)) l = m; else r = m;
    }
    return l;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(cin >> n){
        a.resize(n);
        rep(i,n) cin >> a[i];
        cout << solve() << endl;
    }
}

Measured memory_bytes: 5824
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define sortV(v) v.begin(),v.end()
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
// DSU
/*
const int maxn=100009;
int arr[maxn];
int sz[maxn];
void init(){rep(i,maxn){arr[i]=i;sz[i]=1;}}
int root(int a){while(a!=arr[a]){arr[a]=arr[arr[a]];a=arr[a];}return a;}
int check(int a,int b){if(root(a)==root(b))return 1;return 0;}
int un(int a,int b)
{
  int roota=root(a);int rootb=root(b);
  if(sz[roota]>=sz[rootb]){sz[roota]+=sz[rootb];arr[rootb]=roota;}
  else {sz[rootb]+=sz[roota];arr[roota]=rootb;}
}
*/

//Dijkstra
/*
const int maxn=0x3f3f3f3f;
void dijkstra(int n,int dist[],vector<pi >adj[],int s)
{
  int visited[n+1];
  repre(i,0,n)
  {
    visited[i]=0;
    dist[i]=maxn;
  }
  dist[s]=0;
  priority_queue<pi ,vector<pi>,greater<pi> >p;
  p.push(mkp(0,s));
  while(p.empty()==false)
  {
    pi temp=p.top();
    p.pop();
    if(visited[temp.ss])continue;
    visited[temp.ss]=1;
    int u=temp.ss;
    rep(i,adj[u].size())
    {
      if(dist[u]+adj[u][i].ss<dist[adj[u][i].ff])
      {
        dist[adj[u][i].ff]=dist[u]+adj[u][i].ss;
        p.push(mkp(dist[adj[u][i].ff],adj[u][i].ff));
      }
    }
  }
}*/
int32_t main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  fastio
  string s;
  cin>>s;
  int ans=1;
  string prev="";
  prev+=s[0];
  int n=s.size();
  for(int i=1;i<n;)
  {
    string temp="";
    temp=temp+s[i];
    if(prev!=temp)
    {
      prev=temp;
      ans++;
      i++;
    }
    else
    {
      if(i+1>n-1)break;
      prev=""+s[i]+s[i+1];
      ans++;
      i+=2;
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 720
N = int(input())
A = []
max_num = 0
for _ in range(2):
    Ai = list(map(int, input().split()))
    A.append(Ai)
for i in range(N):
    num = sum(A[0][0:i+1]) + sum(A[1][i:N+1])
    if max_num < num:
        max_num = num
print(max_num)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long   ll;
typedef pair<ll,ll> pll;
typedef long double ld; 
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb           push_back
#define F            first
#define S            second
#define ios          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define hell   1000000007LL
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p){ ll res = 1;x = x % p;while (y > 0) {if (y & 1) res = (res*x) % p;y = y>>1;
  x = (x*x) % p;} return res;} 

const long double PI = acos(-1);
// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
ll euclid(ll x,ll y,ll a,ll b){
  return (a-x)*(a-x)+(b-y)*(b-y);
}
void solve()
{
  ll n;
  cin>>n;
  std::vector<ll> f(100005,0);
  ll x,q,b,c,i,sum=0;
  rep(i,0,n)
  {
    cin>>x;
    f[x]++;
    sum+=x;
  }
  cin>>q;
  while(q--)
  {
    cin>>b>>c;
    sum-=f[b]*b;
    sum+=f[b]*c;
    f[c]+=f[b];
    f[b]=0;
    cout<<sum<<endl;
  }
}
int main()
{ 
  ios; 
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll t=1,i=1;
  // sieve();
  // cin>>t;
  while(i<=t)
  {
    solve();
    i++;
  }
  return 0;
}


Measured memory_bytes: 3988
M = 1000000007
N = int(input())
A = list(map(int, input().split()))

ans = 1
rgb = [0, 0, 0]
for i in range(N):
    c = rgb.count(A[i])
    if c == 0:
        ans = 0
        break
    p = rgb.index(A[i])
    ans *= c
    rgb[p] += 1

print(ans % M)

Measured memory_bytes: 14056
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

int n; 

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	scanf("%d",&n); 	
	int odd=0,even=0; 
	rep(i,1,n){
		int x; scanf("%d",&x); 
		odd+=x%2==1;
		even+=x%2==0; 
	}
	even+=odd/2;
	odd%=2;
	while(even>1)even=(even+1)/2;
	if(odd+even==1)puts("YES");else puts("NO"); 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
using namespace std;
signed main() {
	int n, k, ans = 0; cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		ans += a >= k;
	}cout << ans << endl;
}

Measured memory_bytes: 256
// AOJ 1291 Search of Concatenated Strings
// 2018.5.6 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char e[12][22]; int w[12];
char t[5001]; int len;
char dp[5001][1<<12];
  
int main()
{
	int n, m, i, j, k, S, lim, ans;
	char *p;

	while (n = in()) {
		m = in();

		for (i = 0; i < n; i++) {
			p = e[i]; while ((*p = gc()) > ' ') p++;
			*p = 0, w[i] = p-e[i];
		}

		p = t; while (m--) {
			while ((*p = gc()) > ' ') p++;
		}
		*p = 0, len = p-t;

		lim = (1<<n)-1;
		memset(dp, 0, sizeof(dp));

	    for (i = 0; i < len; i++) {
			for (j = 0; j < n; j++) if ((k = i+1-w[j]) >= 0) {
				if (memcmp(t+k, e[j], w[j])) continue;
  
				for (S = 0; S <= lim; S++) {
					if ((S >> j) & 1) continue;
					dp[i+1][S|(1<<j)] |= dp[k][S];
				}
				dp[i+1][1<<j] = 1;
			}
		}
  
		ans = 0;
		for (i = 0; i <= len; i++) if (dp[i][lim]) ans++;
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 21760
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    map<int, int> mp;
    int ans = 0;
    rep(i, n) mp[a[i]]++;
    for (auto x : mp) {
        if (x.fi > x.se) ans += x.se;
        if (x.fi < x.se) ans += x.se - x.fi;
    }

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

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  ll n, g;
  cin >> n;
  ll a[n] = {};
  map<ll, ll> mp;
  cin >> g;
  mp[0] = -1;
  mp[g] = 0;
  ll ans = 0;
  if(g == 0) ans = 1, mp[g] = -1;
  rep(i, 1, n) {
    ll d;
    cin >> d;
    g += d;
    if(mp.count(g)) {
      ans = max(ans, i - mp[g]);
    }else mp[g] = i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 17092
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define pb push_back
typedef long long ll;
typedef long double ld;

using namespace std;

signed main(){
    int r,d ,x;
    cin >> r >> d >> x;
    for(int i = 0 ; i < 10 ; ++i){
        x = r*x-d;
        cout << x << ' ';
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:>
問題文============================================================

=================================================================

解説=============================================================

================================================================
*/

struct SegTree {
    int N;
    pll init_v;
    vector<pll> node;
    
    SegTree(int _N) {
        init_v = pll(-INF,-INF);
        N = 1;
        while (N < _N) N *= 2;
        node.resize(2 * N - 1, init_v);
    }
    
    void update(int k, pll val) {
        k += N - 1;
        node[k] = val;
        while (k) {
            k = (k - 1) / 2;
            node[k] = max(node[2 * k + 1], node[2 * k + 2]);
        }
    }
    pll query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return init_v;
        if (a <= l && r <= b) return node[k];
        else {
            pll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            pll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }
    pll rmq(int a, int b) { return query(a, b, 0, 0, N); }
};

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int N,R,L; cin >> N >> R >> L;
    vector<ll> d(R),t(R),x(R);
    for(int i = 0; i < R;i++){
        cin >> d[i] >> t[i] >> x[i];
        d[i]--;
    }
    
    SegTree st(N);
    for(int i = 0; i < N;i++){
        st.update(i,pll(0,-i));
    }
    vector<pll> team(N);
    for(int i = 0; i < N;i++) team[i] = pll(0,-i);
    
    ll pre_t = 0;
    for(int i = 0; i < R;i++){
        auto ret = st.rmq(0,N);
        team[abs(ret.second)].first += t[i] - pre_t;
        pre_t = t[i];
        
        st.update((int)d[i],pll(st.node[d[i] + st.N - 1].first + x[i],-d[i]));
    }
    auto ret = st.rmq(0,N);
    team[abs(ret.second)].first += L - pre_t;
    pre_t = L;
    
    sort(team.begin(),team.end());
    reverse(team.begin(), team.end());
    cout << abs(team[0].second) + 1 << endl;
	return 0;
}



Measured memory_bytes: 23676
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const ll mod = 1e9 + 7 ;
const ll inf =
 1e9 + 5 ;
 //1e18L + 5;
const ll nax = 2e5 + 5;
void min_self(ll&a , ll b){a=min(a,b);}
void max_self(ll&a , ll b){a=max(a,b);}
void add_self(ll&a , ll b){a=(a+b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

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

ll base = 1; 
while(base<=n)base*=2;
vector<ll>t(base*2);

for(ll i = 0 ; i<n ; i++){

	ll best = 0 ;
	ll l = base  , r = base + h[i] - 1;
	// cout<<l-base<<"f"<<r-base<<" ";
	while(l<=r){
		if(l%2!=0)max_self(best , t[l++]);
		if(r%2==0)max_self(best , t[r--]);
		l/=2;
		r/=2;
	} 
	
	// cout<<i<<" "<<best<<endl;
	t[h[i]+base] = best + a[i];

	ll x  = h[i]+base; 

	while(x>0){
		max_self(t[x],t[h[i]+base]);
		x/=2;
	}
}

cout<<t[1];



	
}

Measured memory_bytes: 7552
dentyu = []
for i in range(5):
    dentyu.append(int(input()))
k = int(input())
flag = False
for i in range(4):
    for j in range(i,5):
        if k < abs(dentyu[i]-dentyu[j]):
            flag = True
            break 
print('Yay!' if flag==False else ':(')

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

bool isSame(vector<P> a,vector<P> b){
    int sz=a.size();
    rep(i,4){
        rep(j,sz){
            if((a[j].first!=b[j].first)||(a[j].second!=b[j].second))break;
            if(j==(sz-1))return true;
        }
        if(i==3) return false;
        rep(j,sz){
            int x=b[j].first;
            int y=b[j].second;
            b[j].first=-y;
            b[j].second=x;
        }
    }
}

int main(){
    while(true){
        int n;cin>>n;
        if(n==0)break;
        int m;cin>>m;
        vector<P> ori(m);
        rep(i,m)cin>>ori[i].first>>ori[i].second;
        vector<P> inv(m);
        rep(i,m){
            inv[i].first=ori[i].first;
            inv[i].second=ori[i].second;
        }
        rep(i,m){
            ori[m-1-i].first-=ori[0].first;
            ori[m-1-i].second-=ori[0].second;
            inv[i].first-=inv[m-1].first;
            inv[i].second-=inv[m-1].second;
        }
        reverse(all(inv));
        rep(i,n){
            int l;cin>>l;
            vector<P> q(l);
            rep(i,l)cin>>q[i].first>>q[i].second;
            if(l!=m)continue;
            rep(i,l){
                q[l-1-i].first-=q[0].first;
                q[l-1-i].second-=q[0].second;
            }
            if(isSame(q,ori)||isSame(q,inv))cout<<i+1<<endl;
        }
        cout<<"+++++"<<endl;
    }
}            




Measured memory_bytes: 3024
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    println!("{}", s.chars().filter(|&c| c == '1').count());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int a[200010],b[200010];
long long sa[200010],sb[200010];
int n,m,k,ans = 0;
int main() {
  cin >> n >> m >> k;
  sa[0] = sb[0] = 0;
  for(int i = 1; i <= n; i++){
        cin >> a[i];
        sa[i] = sa[i-1]+a[i];
  }
  for(int i = 1; i <= m; i++){
        cin >> b[i];
        sb[i] = sb[i-1]+b[i];
  }
  for(int i = 0,j = m; i <= n; i++){
    if(sa[i] <= k){
        while(sa[i] + sb[j] > k){
            j--;
        }
        ans = max(ans,i+j);
    }else
        break;
    
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8240
#include <bits/stdc++.h>
using namespace std;
struct hash_pair
{ // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;

    template <class T1, class T2>

    size_t operator()(const pair<T1, T2> &p) const

    {

        auto hash1 = hash<T1>{}(p.first);

        auto hash2 = hash<T2>{}(p.second);

        return hash1 ^ hash2;
    }
};
#define int long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define mod1 998244353
#define MAX 2000010
int DP[100 + 5][100000 + 10];
void check(int wt[], int val[], int n, int a)
{
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j < a + 10; j++)
        {
            if (val[i] <= j)
            {
                // cout << val[i] << " " << j << endl;
                DP[i][j] = min(DP[i - 1][j - val[i]] + wt[i], DP[i - 1][j]);
            }
            else
            {
                DP[i][j] = DP[i - 1][j];
            }
        }
    }
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
//#endif
    for (int i = 0; i < 105; i++)
        for (int j = 0; j < 100000 + 10; j++)
            DP[i][j] = INT_MAX;
    for (int i = 0; i <= 100; i++)
        DP[i][0] = 0;
    int n, w;
    cin >> n >> w;
    int wt[n + 2], val[n + 3];
    int a = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> wt[i] >> val[i];
        a += val[i];
    }
    check(wt, val, n, a);
    int ans = 0;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= a; j++)
        {
            if (DP[i][j] <= w)

            {
                ans = max(ans, j);
            }
            // if (DP[i][j] == INT_MAX)
            //     cout << -1 << "\t";
            // else
            // {
            //     cout << DP[i][j] << "\t";
            // }
        }
        // cout << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 82304
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  map<char,char> m;
  m['A']='T';
  m['T']='A';
  m['C']='G';
  m['G']='C';
  char c;
  cin>>c;
  cout<<m[c]<<endl;
  return 0;
}


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

int main() {
	int a, b;
  	cin >> a >> b;
  	if(a > 9 || b > 9) cout << -1 << endl;
  	else cout << a*b << endl;
  	return 0;  
}


Measured memory_bytes: 3644
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int32_t N, K;
    cin >> N >> K;
    vector<pair<int32_t, int32_t>> lrs(K);
    for (int32_t k = 0; k < K; ++k)
    {
        cin >> lrs[k].first >> lrs[k].second;
    }

    vector<uint32_t> dp{1};
    vector<int64_t> hs(K);

    for (int32_t i = 1; i < N; ++i)
    {
        dp.push_back(0);
        uint32_t &cdp = dp[i];
        for (int32_t k = 0; k < K; ++k)
        {
            const auto &lr = lrs[k];
            auto &h = hs[k];
            int32_t e = i - lr.first;
            int32_t s = i - lr.second;

            if (e < 0)
            {
                continue;
            }

            h += dp[e];

            if (s > 0)
            {
                h -= dp[s - 1];
                if (h < 0)
                {
                    h += 998244353;
                }
            }

            cdp = (cdp + h) % 998244353;
        }
    }

    cout << dp[N - 1];
}

Measured memory_bytes: 3824
<?php
$input = explode(' ', trim(fgets(STDIN)));
$rectanglePosWidth = $input[0];
$rectanglePosHeight = $input[1];
$circlePosWidth = $input[2];
$circlePosHeight = $input[3];
$rectangleRadius = $input[4];
 
if (judge1($circlePosWidth, $rectangleRadius, $rectanglePosWidth) && judge2($circlePosHeight, $rectangleRadius, $rectanglePosHeight)) {
    echo 'Yes', PHP_EOL;
} else {
    echo 'No', PHP_EOL;
}
 
function judge1($circlePosWidth, $rectangleRadius, $rectanglePosWidth)
{
    return 0 <= ($circlePosWidth - $rectangleRadius) && ($circlePosWidth + $rectangleRadius) <= $rectanglePosWidth;
}
 
function judge2($circlePosHeight, $rectangleRadius, $rectanglePosHeight)
{
    return  0 <= ($circlePosHeight - $rectangleRadius) && ($circlePosHeight + $rectangleRadius) <= $rectanglePosHeight;
}

Measured memory_bytes: 15376
'use strict';
(function(stdin) {

  var inputs = stdin.toString().split('\n');
  var cols   = inputs[0].split(' ').map(Number);
  var result = (function(numbers, divisable) {

    return  numbers.filter(divisable).length;

  })(range(cols[0], cols[1]), isDivisable(cols[2]));

  console.log(result);

  function range(n, m) {
    var array = [];

    for (var i = n; i < m + 1; i++) {
      array.push(i);
    }
    return array;
  }

  function isDivisable(diviser) {
    return function(n) {
      return diviser % n === 0;
    };
  }

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

int main(){
    long long N;
    cin >> N;
    if(N%10==3){
        cout << "bon" << endl;
    }else if(N%10==0 || N%10==1||N%10==6||N%10==8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;

ll arr[100000];
bool flag[100000];
int main()
{
	cin >> N >> M;
	rep(i, N) {
		cin >> arr[i];
		flag[i] = true;
	}
	rep(i, M) {
		cin >> A >> B;
		A--; B--;
		if (arr[A] < arr[B]) flag[A] = false;
		if (arr[B] < arr[A]) flag[B] = false;
		if (arr[A] == arr[B]) {
			flag[A] = false;
			flag[B] = false;
		}
	}
	int cnt = 0;
	rep(i, N) {
		if (flag[i]) cnt++;
	}
	cout << cnt;
}


Measured memory_bytes: 4552
//#include <bits/stdc++.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

    int n,q; cin >> n >> q;
    string s; cin >> s;
    vint imos(n+1,0);
    FOR(i,1,n){
        if(s[i]=='C' && s[i-1]=='A') imos[i+1]++;
    }
    rep(i,n) imos[i+1]+=imos[i];
    rep(i,q){
        int minus=0;
        int l,r; cin >> l >> r;
        l--; 
        if(s[l]=='C' && s[l-1]=='A')  minus=1;
        cout<<imos[r]-imos[l]-minus<<endl;
    }
}

Measured memory_bytes: 1872
# def linear_search(seq1, seq2):
#     count = 0
#     for i in seq1:
#         for j in seq2:
#             if i == j:
#                 count += 1
#     return count
from copy import deepcopy


def linear_search(seq, seq1_len, key):
    # 番兵
    seq[seq1_len] = key
    i = 0
    while seq[i] != key:
        i += 1
    return i != seq1_len


def main():
    # num_seq1 = int(input())
    seq1_len = int(input())
    seq1 = list(map(int, input().split(" "))) + [0]  # 番兵
    # num_seq2 = int(input())
    input()
    seq2 = list(map(int, input().split(" ")))
    count = 0
    for key in seq2:
        if linear_search(seq1, seq1_len, key):
            count += 1

    print(count)


if __name__ == "__main__":
    main()



Measured memory_bytes: 7104
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <utility>
using namespace std;
const int inf = 1e9;

int main(){
    int n;
    cin >> n;
    vector<int> c(n);
    for(int i=0; i<n; i++){
        cin >> c[i];
        c[i] += i;
    }

    vector<bool> checked(n, false);
    for(int i=0; i<n; i++){
        if(checked[i]) continue;
        if(c[i]==i){
            checked[i] = true;
            continue;
        }
        set<int> p;
        int cur = i;
        int next = 0;
        while(p.find(cur) == p.end()){
            p.insert(cur);
            cur = c[cur];
            if(checked[cur]){
                next = c[cur];
                break;
            }
            if(c[cur]==cur){
                next = cur;
                break;
            }
        }
        cur = i;
        while(!checked[cur]){
            int prev=cur;
            checked[cur] = true;
            cur = c[cur];
            c[prev] = next;
        }
    }

    queue<pair<int, int> > q;
    q.push(make_pair(0,0));
    vector<int> used(n);
    while(!q.empty()){
        int pos = q.front().first;
        int cost = q.front().second;
        q.pop();
        if(used[pos]) continue;
        if(pos == n-1){
            cout << cost << endl;
            break;
        }
        used[pos] = true;
        for(int i=1; i<=6; i++){
            if(pos+i<n){
                q.push(make_pair(c[pos+i], cost+1));
            }
        }
    }
    return 0;
}

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

int main()
{
	int a,b,sum=0,cnt=0;
	cin >> a >> b;
	
	if (b == 1)
	{
		cout << 0 << endl;
	}
	else if (a > b || a == b)
	{
		cout << 1 << endl;
	}
	else
	{
		for (int i = 1; i <= 20; ++i)
		{
			if (i == 1)
			{
				sum += a;
				cnt++;
			}
			else
			{
				sum += a;
				sum--;
				cnt++;
			}
			
			if (b <= sum)
			{
				cout << cnt << endl;
				break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
{-#LANGUAGE FlexibleContexts#-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V

getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]

type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)

mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
ti = toInteger
fi = fromInteger
fig = fromIntegral
rf = realToFrac

(.<.) :: Integer -> Integer -> Integer
(.<.) f g -- combination
    | g < 1 || f < 1 || f < g = 1
    | True = foldr1 (*) (take (fi g) [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)

unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x
 
zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do 
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros
 
i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)

mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a

countIf f = length . filter f

enumDivisor :: Int -> [Int]
enumDivisor n = do
    let sqrted = floor $ sqrt (fromIntegral n)
        smaller = filter (\x -> mod n x == 0) [1..sqrted]
        bigger = reverse $ map (div n) smaller
    if head bigger == sqrted then smaller ++ (init bigger)
    else smaller ++ bigger

safeHead [] = Nothing
safeHead (x:_) = Just x

-- 
--
--

main = do
    [a,b,c] <- getIs
    putStrLn . show $ b + min c (a + b + 1)


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<(n); i++)
using ll = long long;
using P = pair<ll,ll>;
struct UnionFind{
    vector<ll> d;
    UnionFind(ll  n):d(n,-1){}
    ll root(ll x){
        if(d[x] < 0)return x;
        return d[x] = root(d[x]);
    }
    bool unite(ll x,ll y){
        x = root(x),y = root(y);
        if(x == y)return false;
        if(d[x] > d[y])swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    ll size(ll x){
        return -d[root(x)];
    }
    bool issame(ll x,ll y){
        return root(x) == root(y);
    }

};
int main()
{
    ll n,m;
    cin >> n >> m;
    vector<P> p(m);
    UnionFind uf(n);
    rep(i,m){
        cin >> p[i].first >> p[i].second;
        p[i].first--;p[i].second--;
    }
    reverse(p.begin(),p.end());
    vector<ll> ans(m+1);
    ans[0] = n*(n-1)/2;
    rep(i,m){
        ll a = p[i].first,b = p[i].second;
        
        if(!uf.issame(a,b)){
            ans[i+1] = ans[i] - (uf.size(a)*uf.size(b));
            uf.unite(a,b);
        }
        else ans[i+1] = ans[i];
        
    }
    for(ll i = m-1;i>=0;i--){
        cout << ans[i] <<endl;
    }

    return 0;
}


Measured memory_bytes: 4480
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = ReadSplit();
            var n = r[0].Int();
            var k = r[1].Int();
            var l = new int[n];
            var dp = new int[100010];
            var INF = 1000000007;
            var r2 = ReadSplit();
            for (int i = 0; i < n; i++)
            {
                l[i] = r2[i].Int();
            }
            for (int i = 0; i < 100010; i++)
            {
                dp[i] = INF;
            }
            dp[0] = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = 1; j <= k; j++)
                {
                    if (i + j < n)
                    {
                        ChangeMin(ref dp[i + j], dp[i] + Math.Abs(l[i + j] - l[i]));
                    }
                }
            }
            WriteRead(dp[n - 1]);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 26540
n, m = map(int, input().split())
a = list(map(int , input().split()))

class Cumulative_Sum:
    def __init__(self, a):
        la = len(a)
        self.s = [0] * (la + 1)
        for i in range(la):
            self.s[i+1] = self.s[i] + a[i]
    # s[l]からs[r]までの和
    def sum(self, l, r):
        return self.s[r] - self.s[l]

cs = Cumulative_Sum(a)
from collections import defaultdict
b = defaultdict(int)

for i in range(n+1):
    b[cs.s[i] % m] += 1

ans = 0
for bi in b:
    if b[bi] > 1:
        ans += b[bi] * (b[bi] - 1) // 2
print(ans)

"""
ans = 0
for i in range(n):
    for j in range(i+1, n+1):
        if cs.sum(i, j) % m == 0:
            ans += 1
#print(ans)
"""

Measured memory_bytes: 16800