akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int q;
    cin>>q;
    list<int> l;
    list<int>::iterator cursor = l.end();
    rep(i, q) {
        int p, x;
        cin>>p;
        switch (p)
        {
        case 0:
            cin>>x;
            cursor = l.insert(cursor, x);
            break;
        case 1:
            cin>>x;
            if (x > 0) {
                rep(j, x) cursor++;
            }
            else rep(j, -x) cursor--;
            break;
        default:
            cursor = l.erase(cursor);
            break;
        }
    }
    for (auto item : l) cout<<item<<endl;
}


Measured memory_bytes: 18660
# 1, 2, 3, 5

from itertools import chain
from math import ceil

# def factorization(n):
#     tmp = n
#     arr = []
#     for i in range(2, ceil(n ** (1/2)) + 1):
#         m, r = divmod(tmp, i)
#         print(f'm: {m}, r: {r}')
#         count = 0 if r == 0 else 1
#         while r == 0:
#             m, r  = divmod(tmp, i)
#             if r == 0:
#                 tmp = m
#                 count += 1


#         if count != 0:
#             arr.append((i, count))

#     return arr

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def get_prime_facts(n):
    return set(map(lambda x: x[0], factorization(n)))

def solution(A, B):
    s = get_prime_facts(A) & get_prime_facts(B) | {1}

    return len(s)

if __name__ == '__main__': 
    A, B = map(int, input().split())
    a = solution(A, B)

    print(a)


Measured memory_bytes: 3188
use std::str::FromStr;

fn parse_line() -> u32 {
    let mut buf = String::new();

    std::io::stdin().read_line(&mut buf).unwrap();
    let buf = buf.trim();

    u32::from_str(buf).unwrap()
}

fn parse() -> [u32; 5] {
    let mut ret = <[u32; 5]>::default();
    
    for v in ret.iter_mut() {
        *v = parse_line();
    }

    ret
}

fn div_10(t: u32) -> u32 {
    if (t % 10) == 0 {
        t
    } else {
        (t / 10 + 1) * 10
    }
}

fn reminder(t: u32) -> u32 {
    if (t % 10) == 0 {
        10
    } else {
        t % 10
    }
}

fn calc(times: &[u32]) -> u32 {
    let mut last = 0;
    for i in 0..times.len() {
        if reminder(times[i]) < reminder(times[last]) {
            last = i;
        }
    }

    let mut ret = 0;
    for i in 0 .. times.len() {
        if i == last {
            ret = ret + times[i];
        } else {
            ret = ret + div_10(times[i]);
        }
    }

    ret
}

fn main() {
    let times = parse();
    println!("{}", calc(&times));
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main()
{
    int n;
    cin>>n;
    vector<ll> a(n),b(n);
    ll suma=0,sumb=0,adda=0,addb=0;
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
        suma+=a[i];
    }
    
    for(int i = 0; i < n; i++)
    {
        cin>>b[i];
        sumb+=b[i];
    }
    ll diff=sumb-suma;
    for(int i = 0; i < n; i++)
    {
        if(a[i]<b[i])
        {
            adda+=(b[i]-a[i])/2;
            if((b[i]-a[i])%2>0)
            {
                adda++;
                addb++;
            }
        }
        else if(a[i]>b[i])
        {
            addb+=(a[i]-b[i]);
        }
    }
    
    if(adda<=diff &&addb<=diff)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h> 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define int long long
#define swap(x,y) (x^=y^=x^=y)

#define debug1(a) cerr<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

using namespace std;
 
#define mod 1000000007
long long modexpo(long long x, long long p){
    int res = 1;x = x%mod;
    while(p){
        if(p%2)res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

struct compare{
    bool operator() (const pair<int,int> a, const pair<int,int> b) const{
        return a.first < b.first;
    }
};

const int nax = 2005;
int fact[nax], inv[nax];

int nck(int n, int k){
    if(k > n){
        return 0;
    }
    if(k == 0 || k == n){
        return 1;
    }
    if(k == 1 || k == n-1){
        return n; 
    }
    
    int x =  fact[n];
    x *= inv[n-k];
    x %= mod;
    x *= inv[k];
    x %= mod;
    return x;
}

int32_t main(){
    IOS
    fact[0] = inv[0] = 1;
    fact[1] = 1, inv[1] = 1;
    for(int i = 2; i < nax; i++){
        fact[i] = fact[i-1]*i;
        fact[i] %= mod;
        inv[i] = modexpo(fact[i], mod - 2);
    }
    // cout << inv[2] << " ";
    int n;
    cin >> n;
    if(n < 3){
        cout << 0 << "\n";
        exit(0);
    }
    int ans = 0;
    for(int i = 1; i <= 1000; i++){
        int x = n-i*3;
        if(x < 0){
            break;
        }
        int up = x + i - 1;
        int down = i - 1;
        int steps = nck(up,down);
        ans += steps;
        // cout << ans << "\n";
        ans %= mod;
    }
    cout << ans << "\n";
} 

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

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

    int s = a[0];

    for(int i = 1; i < n; ++i) {
        s = __gcd(s, a[i]);
    }

    cout << s << endl;
    
    return 0;
}


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

int n;
P d[200000];
vector<int>E[200000];
int sz[200000];
ll dp1[200000],dp2[200000];
vector<pair<int,int>>ans;

void dfs1(int v){
	for(int u:E[v]){
		dfs1(u);
		dp1[v]+=dp1[u]+sz[u];
	}
}
void dfs2(int v,int p){
	if(p==-1)dp2[v]=dp1[v];
	else dp2[v]=dp2[p]+n-2*sz[v];
	for(int u:E[v]){
		ans.push_back({v+1,u+1});
		dfs2(u,v);
	}
}

int main(){
	scanf("%d",&n);
	rep(i,n){
		scanf("%lld",&d[i].first);
		d[i].second=i;
	}
	rep(i,n)sz[i]=1;
	sort(d,d+n);
	for(int i=n-1;i>0;i--){
		ll c=d[i].first-n+2*sz[d[i].second];
		int id=lower_bound(d,d+n,P(c,0))-d;
		if(id==n||d[id].first!=c){
			puts("-1");return 0;
		}
		E[d[id].second].push_back(d[i].second);
		sz[d[id].second]+=sz[d[i].second];
	}
	dfs1(d[0].second);
	dfs2(d[0].second,-1);
	rep(i,n){
		if(dp2[d[i].second]!=d[i].first){
			puts("-1");return 0;
		}
	}
	for(auto p:ans){
		printf("%d %d\n",p.first,p.second);
	}
}

Measured memory_bytes: 18036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int n; cin >> n;
	int N = 1<<n;
	V<int> A(N);
	rep(i,N) cin >> A[i];
	sort(all(A),greater<int>());
	V<int> vc;
	for(int i=0;i<N;){
		int j = i;
		while(j!=N && A[i]==A[j]) j++;
		vc.pb(j-i);
		i = j;
	}
	V<int> buf(n+1);
	V<int> open(n+1); open[0] = 1;
	for(int x: vc){
		int num = accumulate(all(open),0);
		if(x > num){
			cout << "No" << endl;
			return 0;
		}
		rep(i,n+1){
			int a = min(x,open[i]);
			open[i] -= a;
			buf[i] = a;
			x -= a;
		}
		rep(i,n){
			for(int j=i+1;j<=n;j++) open[j] += buf[i];
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 2424
#include<bits/stdc++.h>
using namespace std;
#define fori(i,a,n) for(i=a;i<=n;i++)
#define ford(i,n,a) for(i=n;i>=a;i--)
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
const ll inf=1e12;
ll n,i,j,x[1000],ans,anss;
int main()
{
	cin>>n;
	anss=inf;
	fori(i,1,n)
	cin>>x[i];
	fori(i,1,100)
	{
		ans=0;
		fori(j,1,n)
		ans+=(x[j]-i)*(x[j]-i);
		anss=min(ans,anss);
	}
	cout<<anss<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;

using namespace std;

vector<vector<pair<int,ll> > > g;    // to, val   
vector<ll> dist;

void dfs( int curr, ll curr_dist )
{
    dist[curr]=curr_dist;

    int i;
    for(i=0; i<(int)g[curr].size(); i++) {
        int next = g[curr][i].first;
        if(dist[next]<0) {
            dfs( next, curr_dist + g[curr][i].second );
        }
    }

    return;
}

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    g.resize(n);
    dist.resize(n);
    int i;
    for(i=0; i<n; i++) {
        dist[i]=-1;
    }
    for(i=0; i<n-1; i++) {
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w);
        g[u-1].push_back(make_pair(v-1, w) );
        g[v-1].push_back(make_pair(u-1, w) );
    }
    dfs(0, 0);

    for(i=0; i<n; i++) {
        printf("%lld\n", dist[i]%2);
    }

    return 0;
}


Measured memory_bytes: 9216
#!/bin/bash

read a
read b
read c
read x

ans=0
for (( i_c = 0; i_c <= c; i_c++ ))
do
    for (( i_b = 0; i_b <= b; i_b++ ))
    do
        for (( i_a = 0; i_a <= a; i_a++ ))
        do
            total=$((i_a * 500 + i_b * 100 + i_c * 50))
            if [ $total -eq $x ];then
                ans=$((ans + 1))
            fi
        done
    done
done
echo $ans

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

using namespace std;

int main()
{
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n; cin >> n;
        int a[n+1], b[n+1], c[n+1];
        for (int i=1; i<=n; i++)
                cin >> a[i] >> b[i] >> c[i];
        int dp1[n+1], dp2[n+1], dp3[n+1];
        memset(dp1,0,sizeof(dp1));
        memset(dp2,0,sizeof(dp2));
        memset(dp3,0,sizeof(dp3));
        for (int i=1; i<=n; i++)
        {
                dp1[i] = max(dp2[i-1], dp3[i-1]) + a[i];
                dp2[i] = max(dp1[i-1], dp3[i-1]) + b[i];
                dp3[i] = max(dp1[i-1], dp2[i-1]) + c[i]; 
        }
        cout << max(dp1[n], max(dp2[n], dp3[n]));
        return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define SHOW(a) cout << #a << " = " << a << endl;

void solve(){
	int n, k;
	bool d[10] = {};
	cin >> n >> k;

	rep(i,k){
		int a;
		cin >> a;
		d[a] = true;
	}
	
	while(true){
		int i = n;
		bool flag = true;
		while(i){
			flag &= !d[i%10];
			if(!flag)
				break;
			i /= 10;
		}
		if(flag)
			break;
		n++;
	}

	cout << n << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  for (int i = 0; i < n; i++) cin >> h.at(i);
  sort(h.begin(), h.end());
  priority_queue<ll, vector<ll>, greater<ll>> gap;
  for (int i = 0; i < n - k + 1; i++)
    gap.push(h.at(n - 1 - i) - h.at(n - 1 - i - k + 1));
  cout << gap.top() << endl;
}

Measured memory_bytes: 2168
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007
using namespace std;
int main(){
    int a,b,c;  cin>>a>>b>>c;
    int ans=0;
    for(int i=a;i<=b;++i){
        if(c%i==0){
            ++ans;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
int n;
  cin>>n;
  vll a(n);
  rep(i,0,n)cin>>a[i];
  ll ans=0;
  
  sort(all(a));
  reverse(all(a));
  
 /* vll cnt(n);
  rep(i,0,n) cnt[i]=0;*/
  
  rep(i,0,n){
    if(i==0)continue;
    if(i==1) {
      ans+=a[0];
      continue;
    }
      ans+=a[i/2];
    
  //  cout<<ans<<endl;
  }
  cout<<ans<<endl;
  //cout<<a[0]<<endl;
}

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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while(A > 0){
        C = C - B;
        if(C <= 0){
            cout << "Yes";
            break;}
        A = A - D;
        if( A <= 0)
            cout << "No";
    }
}

Measured memory_bytes: 3608
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,ans=0;
  cin>>N;
  ll A[N],CNT[200010];
  REP(i,200010) CNT[i]=0;
  REP(i,N){
    cin>>A[i];
    CNT[A[i]]++;
  }
  REP(i,200010){
    ans+=CNT[i]*(CNT[i]-1)/2;
  }
  ans++;
  REP(i,N) co(ans-CNT[A[i]]);
  return 0;
}

Measured memory_bytes: 6620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
int main () {
    int n, m ;
    cin >> n >> m;
    if (n == m){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



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

struct RollingHash{
  typedef unsigned long long ull;
  string S;
  ull B;
  Int len;
  vector<ull> hash,p;
  RollingHash(){}
  RollingHash(string S_,ull B_=1000000007LL):
    S(S_),B(B_),len(S.length()),hash(len+1),p(len+1){
    hash[0]=0;p[0]=1;
    for(Int i=0;i<len;i++){
      hash[i+1]=hash[i]*B+S[i];
      p[i+1]=p[i]*B;
    }
  }
  //S[l,r)
  ull find(Int l,Int r){
    return hash[r]-hash[l]*p[r-l];
  }
};


template<Int X>
struct Trie{
  struct Node{
    char c;
    vector<Int> nxt;
    Int idx;
    Node(char c):c(c),nxt(X,-1),idx(-1){}
  };

  using F = function<Int(char)>;
  vector<Node> v;
  F conv;
  
  Trie(F conv,char c='$'):conv(conv){v.emplace_back(c);}

  void add(const string &s,Int x){
    Int pos=0;
    for(Int i=0;i<(Int)s.size();i++){
      Int k=conv(s[i]);
      if(~v[pos].nxt[k]){
	pos=v[pos].nxt[k];
	continue;
      }
      Int npos=v.size();
      v[pos].nxt[k]=npos;
      v.emplace_back(s[i]);
      pos=npos;
    }
    v[pos].idx=x;
  }

  Int find(const string &s){
    Int pos;
    for(Int i=0;i<(Int)s.size();i++){
      Int k=conv(s[i]);
      if(v[pos].nxt[k]<0) return -1;
      pos=v[pos].nxt[k];
    }
    return pos;
  }
  
  Int find(Int pos,char c){
    return v[pos].nxt[conv(c)];
  }

  Int calc(Int pos){
    return (pos<0?pos:v[pos].idx);
  }
  
};


template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  Int n;
  cin>>n;
  vector<string> p(n);
  for(Int i=0;i<n;i++) cin>>p[i];

  Trie<26>::F f=[](char c){return c-'a';};
  Trie<26> G(f);
  for(Int i=0;i<n;i++) G.add(p[i],i);

  const Int LIM = 500;
  vector<string> l;
  for(Int i=0;i<n;i++)
    if((Int)p[i].size()>=LIM) l.emplace_back(p[i]);

  Int INF = s.size()+1;
  RollingHash rh(s);
  vector<RollingHash> rhs;
  for(Int i=0;i<(Int)l.size();i++)
    rhs.emplace_back(l[i]);

  vector<Int> dp(s.size(),INF);
  for(Int i=0;i<(Int)s.size();i++){
    Int pos=0;
    for(Int j=0;j<LIM&&i+j<(Int)s.size();j++){
      pos=G.find(pos,s[i+j]);
      if(pos<0) break;
      Int k=G.calc(pos);
      if(~k){
	chmin(dp[i],i+j);
	break;
      }
    }
    for(Int j=0;j<(Int)l.size();j++){
      if(i+l[j].size()>s.size()) continue;
      if(rh.find(i,i+l[j].size())==rhs[j].find(0,l[j].size()))
	chmin(dp[i],i+(Int)l[j].size());
    }
  }
  Int ans=0,pos=INF;
  for(Int i=0;i<(Int)s.size();i++){
    //cout<<i<<":"<<pos<<" "<<dp[i]<<endl;
    chmin(pos,dp[i]);
    if(pos<=i) ans++,pos=INF;
  }
  if(pos!=INF) ans++;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 26572
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int l = in.nextInt() + in.nextInt();
        int r = in.nextInt() + in.nextInt();
        out.println(l == r ? "Balanced" : l > r ? "Left" : "Right");
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

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

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

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

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 22356
#include <cstring>
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack<int> num;
char s[2000];
int main() {
	int shu=0;
	char fh=0;
	cin.getline(s, sizeof(s), '\n');
	int len=strlen(s);
	for (int i=0; i<len; i++) {
		int x=s[i];
		if (x>='0'&&x<='9') {
			shu*=10;
			shu+=x;
			shu-='0';
		} else if (x==' ') {
			if (fh==0) num.push(shu);
			fh=0;
			shu=0;
		} else {
			fh=x;
			int x,y;
			x=num.top();
			num.pop(); 
			y=num.top();
			num.pop();
//			cout << x << ' ' << y << ' ' << fh << endl;
			if (fh=='+') num.push(x+y);
			else if (fh=='-') num.push(y-x);
			else if (fh=='*') num.push(x*y);
			shu=0;
		}
	}
	printf("%d\n",num.top());
	return 0;
}


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

const int MOD = 1e9 + 7;
vector<long long> fact, fact_inv, inv;
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}

/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}

int main() {
    int x,y; cin >> x >> y;
    int n = (x + y) / 3;
    // if((x+y)%3!=0 || x < n || y < n){
    //     cout << 0 << endl;
    //     return 0;
    // }
    int k = -1;
    for(int i=0; i<=n; i++){
        if(x == i + 2*(n-i) && y == (n-i) + 2 * i){
            k = i;
            break;
        } 
    }
    if(k == -1){
        cout << 0 << endl;
        return 0;
    }

    init_nCk(1e6 + 5);
    cout << nCk(n,k) << endl;
}

Measured memory_bytes: 26672
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

printNum (x : xs) = do
  print x
  when (xs /= []) $ printNum xs

main = do
  [a, b, k] <- getIntList
  let xs = filter (\x -> (x < (a + k)) || (x > (b - k))) [a .. b]
  printNum xs


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

int main(){
    int i,n;
    cin >> n;
    vector<int> a(n);
    for(i=0;i<n;i++){
        cin >> a.at(i);
    }
    map<int,int>Map;
    Map[1]++;
    int tmp=1,count=0;
    while(true){
        if(tmp==2){cout << count << endl;break;}
        if(Map[tmp]==2){cout << -1 << endl;break;}
        tmp=a.at(tmp-1);
        Map[tmp]++;
        count++;
    }
    return 0;
}

Measured memory_bytes: 5376
S = list(input())
N = len(S)
import collections
import sys
C = collections.Counter(S)
Ckey = C.keys()
ans = 10 ** 9 + 7
if len(Ckey) == 1:
    print(0)
    sys.exit()
for s in Ckey:
    post = S[:]
    for i in range(1,N):
        #test = ''.join(post)
        #print(s,i,test,ans)
        flag = True
        tmp = ['0'] * (N-i)
        for j in range(N-i):
            if post[j] == s or post[j+1] == s:
                tmp[j] = s
            else:
                tmp[j] = post[j]
                flag = False
        post = tmp[:]
        if (flag):
            break
    ans = min(ans,i)
print(ans)

Measured memory_bytes: 3316
N = int(input())
ans = 0
a = list(map(int,input().split()))
for i in range(1,len(a)+1):
    # print(i,a[i-1])

    if(i % 2 == 1 and a[i-1] %2 ==1):
        # print(i)
        ans += 1
print(ans)

Measured memory_bytes: 9192
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var map = new HashMap<String, Integer>();
		map.put("AC", 0);
		map.put("WA", 0);
		map.put("TLE", 0);
		map.put("RE", 0);
		for(var i = 0; i < n; i++) {
			var text = sc.next();
			map.put(text, map.get(text) + 1);
		}
		sc.close();

		var sb = new StringBuilder();
		sb.append(String.format("AC x %d\r\n", map.get("AC")));
		sb.append(String.format("WA x %d\r\n", map.get("WA")));
		sb.append(String.format("TLE x %d\r\n", map.get("TLE")));
		sb.append(String.format("RE x %d\r\n", map.get("RE")));
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 57304
K = int(input())

ans = -1
mod = 0

for i in range(1, K+1):
    if i==1:
        mod_tmp = 7 % K
    else:
        mod_tmp = (mod_tmp * 10) % K
    mod += mod_tmp
    if mod%K == 0:
        ans = i
        break

print(ans)


Measured memory_bytes: 63280
#include<bits/stdc++.h>
using namespace std;
#define forr(x,n) for(int x = 0; x < n; ++x)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,x,y;
    cin>>n>>x>>y;
    int dist[n];
    memset(dist,0,sizeof(dist));
    for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
    dist[min(j-i,abs(x-i)+1+abs(j-y))]++;
    for(int i=1;i<n;i++)
    cout<<dist[i]<<endl;
}


Measured memory_bytes: 256
from math import *
from collections import *
from itertools import *
from bisect import *
from operator import *
import sys
sys.setrecursionlimit(1000000)
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
def o():
    return int(input())
def kl(con,x=0):
    if x==0:print('Yes') if con else print('No')
    elif x==1:print('yes') if con else print('no')
    elif x==2:print('YES') if con else print('NO')
MOD =    1000000007
MAX=float('inf')
MIN=-float('inf')
p=input
# for _ in range(o()):
n,m,x=io()
cost=[0]*n
a=[0]*n
skill=[0]*m

for i in range(n):
    t=op()
    cost[i]=t[0]
    a[i]=t[1:]
ans=MAX
for i in range(1<<n):
    c=0
    skill=[0]*m
    for j in range(n):
        if (i>>j)&1:
            c+=cost[j]
            for k in range(m):
                skill[k]+=a[j][k]
    if min(skill) >= x:
        ans=min(ans,c)
if ans==MAX:print(-1)
else:print(ans)







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

using namespace std;

int main()
{
    int A, B, X;
    cin >> A>> B >> X;
    if (A>X)
        cout << "NO";
   else
        if (A+B>=X )
        cout << "YES";

    else
        cout << "NO";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int dp[4001][4001];

int main(){
  string s1, s2;
  while(cin >> s1 >> s2){
    memset(dp, 0, sizeof(dp));
    int ans = 0;
    for(int i = 0 ; i < s1.size() ; i++){
      for(int j = 0 ; j < s2.size() ; j++){
	if(s1[i] == s2[j]){
	  dp[i+1][j+1] = dp[i][j]+1;
	  ans = max(ans, dp[i+1][j+1]);
	}
	else dp[i+1][j+1] = 0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

	  

Measured memory_bytes: 63748
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl;
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

const ll INF = 1e9+7;

// 各桁の和
template<typename T>T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;}
template<typename T>T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

#define test(a) cout<<#a<<':'<<a<<endl;

class tree{
public:
  tree* par;
  vector<tree*> chi;
  int cnt;
};


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int m,d;cin>>m>>d;
  int f = d % 10;
  int s = d / 10;
  int ans = 0;

  for(int i = 4;i <= m;++i){
    if(s < 2)break;
    for(int j = 2;j < s;++j){
      for(int k = 2; k < 10;++k){
        if(k < 2 && j == 0)continue;
        if(i == j*k){
          ans++;
        }
      }
    }
    
    for(int j = 2;j <= f;++j){
      if(i == j*s){
        ans++;
      }
    }
    
  }
  
  print(ans)
  return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}

const int MAXN = 1e7 + 10;

int is_prime[MAXN], cnt[MAXN], prime[MAXN], p_cnt, num[MAXN];

void sieve() {
    cnt[1] = 1, num[1] = 0;
    rep(i, 2, MAXN) {
        if (!is_prime[i]) prime[++p_cnt] = i, cnt[i] = 2, num[i] = 1;
        rep(j, 1, p_cnt) {
            if (i * prime[j] > MAXN) break;
            is_prime[i * prime[j]] = true;
            if (i % prime[j]) {
                cnt[i * prime[j]] = cnt[i] << 1;
                num[i * prime[j]] = 1;
            } else {
                num[i * prime[j]] = num[i] + 1;
                cnt[i * prime[j]] = 1ll * cnt[i] / num[i * prime[j]] * (num[i * prime[j]] + 1);
                break;
            }
        }
    }
}

int n;

int main() {
    sieve();
    IO::read(n);
    long long ans = 0;
    rep(i, 1, n) {
        ans += 1ll * i * cnt[i];
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 123456
m,k=map(int,input().split())

if k==0:
    x=[[i]*2 for i in range(2**m)]
    for i in x:
        print(*i,end=" ")
elif m==1:
    print(-1)
elif 2**m<=k:
    print(-1)
else:
    for i in reversed(range(2**m)):
        if i!=k:
            print(i,end=" ")
    print(k,end=" ")
    for i in range(2**m):
        if i!=k:
            print(i,end=" ")
    print(k)

Measured memory_bytes: 22480
package main

import (
        "fmt"
        "strings"
)

type Pos struct {
        X, Y int
}

func calc(p Pos, m []string, a [][]int, q []Pos) []Pos {
        x := []int{p.X - 1, p.X + 1}
        for _, v := range x {
                if 0 <= v && v < len(m) && m[v][p.Y] != '#' && a[v][p.Y] == 0 {
                        a[v][p.Y] = a[p.X][p.Y] + 1
                        q = append(q, Pos{v, p.Y})
                }
        }
        y := []int{p.Y - 1, p.Y + 1}
        for _, v := range y {
                if 0 <= v && v < len(m[0]) && m[p.X][v] != '#' && a[p.X][v] == 0 {
                        a[p.X][v] = a[p.X][p.Y] + 1
                        q = append(q, Pos{p.X, v})
                }
        }
        return q
}
func main() {
        var H, W, s int
        fmt.Scanf("%d %d", &H, &W)
        m := make([]string, H, H)
        for i := range m {
                fmt.Scanf("%s", &(m[i]))
                s += strings.Count(m[i], "#")
        }
        a := make([][]int, H, H)
        for i := range a {
                a[i] = make([]int, W, W)
        }
        q := []Pos{Pos{0, 0}}
        for len(q) > 0 {
                q = calc(q[0], m, a, q[1:])
                if a[H-1][W-1] != 0 {
                        break
                }
        }
        if a[H-1][W-1] == 0 {
                fmt.Println(-1)
                return
        }
        fmt.Println(H*W - s - a[H-1][W-1]-1)

}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define   ll  long long
ll dp[1002][1002];
string s[1002];
int main()
{
    int i,j,n,m;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
    }
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=m;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(s[i-1][j-1]=='#')
            {
                dp[i][j]=0;
            }
            else if(i==1 && j==1)
            {
                dp[i][j]=1;
            }
            else
            {
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
            }
        }
    }
    cout<<dp[n][m]<<"\n";
    return 0;
}



Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int a,b,c,n,h;
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&n);
    for(int i=0; i<=a; i++)
    for(int j=0; j<=b; j++)
    if((n-i*500-j*100>=0)&&(n-i*500-j*100<=c*50))h++;
    printf("%d\n",h);
    return 0;
}

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

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

    string res = "No";
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (i * j == n) res = "Yes";
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())

# 0を挟む場合
if a <= 0 and 0 <= b:
    print("Zero")
# 両方プラスの場合
elif a > 0:
    print("Positive")
else:
    if (b + a + 1) % 2 == 0:
        print("Positive")
    else:
        print("Negative")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <random>
#include <queue>
#include <deque>
#include <iterator>
#include <map>
#include <functional>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define pb(a) push_back(a)
#define llong long long
#define INF 1145141919
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = { 1, 0, -1, 0 };
int dx[] = { 0, 1, 0, -1 };
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }


int main() {
	int a, b, t;
	cin >> a >> b >> t;
	int ret = 0;
	for (int i = a; i <= t; i += a) {
		ret += b;
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();

		// 条件を満たせるかチェック
		int sum = 0;
		for (int i = n-2; i > 0; i--) {
			sum += i;
		}
		if (sum < k) {
			System.out.println(-1);
		}

		List<String> graph = new ArrayList<>();
		// まず最短距離2が最多になるグラフを書く
		for (int i = 2; i <= n; i++) {
			graph.add("1 " + i);
		}
		// この時点で達成していたら終了
		if (sum == k) {
			print(graph);
			return;
		}
		// 最短距離2の組み合わせがk個になるまで要素をつなげていく
		for (int i = 2; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				graph.add(i + " " + j);
				sum--;
				if (sum == k) {
					print(graph);
					return;
				}
			}
		}
	}

	private static void print(List<String> graph) {
		System.out.println(graph.size());
		for (String pear : graph) {
			System.out.println(pear);
		}
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  ModInt() : v(0) {}
  template<class Z> ModInt(Z x) : v(x >= 0 ? x % P : -x % P ? P - -x % P : 0) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool) *this; }
  M operator*(M r) const { return M(*this) *= r; }
  M operator/(M r) const { return M(*this) /= r; }
  M operator+(M r) const { return M(*this) += r; }
  M operator-(M r) const { return M(*this) -= r; }
  bool operator==(M r) const { return v == r.v; }
  bool operator!=(M r) const { return !(*this == r); }
  M& operator*=(M r) { v = (uint64_t) v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { v = r.v < P - v ? v + r.v : v - (P - r.v); return *this; }
  M& operator-=(M r) { v = r.v <= v ? v - r.v : v + (P - r.v); return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  template<class Z> M pow(Z n) const {
    n = n >= 0 ? n % (P - 1) : P - 1 - -n % (P - 1);
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  template<class Z> friend M operator*(Z l, M r) { return M(l) *= r; }
  template<class Z> friend M operator/(Z l, M r) { return M(l) /= r; }
  template<class Z> friend M operator+(Z l, M r) { return M(l) += r; }
  template<class Z> friend M operator-(Z l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; }
  template<class Z> friend bool operator==(Z l, M r) { return M(l) == r; }
  template<class Z> friend bool operator!=(Z l, M r) { return !(l == r); }
};
using Mint = ModInt<(unsigned) 1e9 + 7>;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> c(n); for (auto&& e : c) cin >> e, --e;
  c.erase(unique(begin(c), end(c)), end(c));
  n = c.size();
  V<> prev(2e5);
  V<Mint> dp(n + 1);
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    dp[i + 1] = dp[i] + (prev[c[i]] ? dp[prev[c[i]]] : 0);
    prev[c[i]] = i + 1;
  }
  cout << dp.back() << '\n';
}

Measured memory_bytes: 2560
import sys
a,b,c = map(int,input().split())

if a%2 == 1 or b%2 == 1 or c%2 == 1:
    print(0)
    sys.exit()
if a==b==c:
    print(-1)
    sys.exit()

C = 1
while 1:
    a, b, c = b//2 + c//2 , a//2 + c//2 , b//2 + a//2
    if a%2 == 1 or b%2 == 1 or c%2 == 1:
        print(C)
        sys.exit()
    else:
        C += 1

Measured memory_bytes: 3060
n, m, l = [int(i) for i in input().split()]
d = [[10 ** 18] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0

for _ in range(m):
    a, b, c = [int(i) for i in input().split()]
    a -= 1
    b -= 1
    d[a][b] = min(d[a][b], c)
    d[b][a] = min(d[b][a], c)

for i in range(n):
    for j in range(n):
        for k in range(n):
            d[j][k] = min(d[j][k], d[j][i] + d[i][k])

d2 = [[10 ** 18] * n for _ in range(n)]
for i in range(n):
    d2[i][i] = 0

for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            d2[i][j] = min(d2[i][j], 1)

for i in range(n):
    for j in range(n):
        for k in range(n):
            d2[j][k] = min(d2[j][k], d2[j][i] + d2[i][k])

q = int(input())
for _ in range(q):
    s, t = [int(i) - 1 for i in input().split()]
    if d2[s][t] == 10 ** 18:
        print(-1)
    else:
        print(d2[s][t]-1)


Measured memory_bytes: 61144
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
A = np.zeros(N+2,np.int32)
A[1:-1] = np.array(read().split(),np.int32)

A

from_left = np.maximum.accumulate(A)
from_right = np.maximum.accumulate(A[::-1])[::-1]

answer = np.maximum(from_left[:-2], from_right[2:])
print('\n'.join(answer.astype(str)))

Measured memory_bytes: 50848
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <map>
#include <iterator>
#include <queue>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

bool compare(pair<int,int> i1, pair<int,int> i2) 
{ 
    return (i1.second < i2.second); 
} 

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

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

  // int a, b, c;
  string s;
  cin >> s;
  
  int length = s.size() - 2;
  while(length > 0){
    bool flag = true;
    rep(i, length/2){
      if (s[i] != s[i+(length/2)]){
        flag = false;
        break;
      }
    }
    if(flag){
      cout << length << endl;
      return 0;
    }
    length-=2;
  }
  cout << length << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a ,b ;
    scanf("%d %d" , &a , &b);

	if(a < b){
		printf("a < b\n");
	} else if(a>b){
	   printf("a > b\n");
    } else  {
	    printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#define R(i, n) for(int i = 0;i < n;i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define SC(a) scanf("%c", &a);
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;

ll N;

int main() {
	SL(N);
	PL(N * (N - 1) / 2);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    string S,T;
    cin>>S>>T;
    bool ok=true;
    map<char,char> ma,ima;
    for(int i=0;i<S.size();i++){
        char s=S[i],t=T[i];
        if(ma.count(s)) if(ma[s]!=t) ok=false;
        if(ima.count(t)) if(ima[t]!=s) ok=false;
        ma[s]=t; ima[t]=s;
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}



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

int main() {
  int N;
  cin >> N;
  vector<int> X(N), Y(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
    Y.at(i) = X.at(i);
  }
  sort(Y.begin(), Y.end());
  int A = Y.at(N / 2 - 1);
  int B = Y.at(N / 2);
  if (A == B) {
    for (int i = 0; i < N; i++) cout << A << endl;
  }
  else {
    for (int i = 0; i < N; i++) {
      if (X.at(i) >= B) cout << A << endl;
      else cout << B << endl;
    }
  }
}


Measured memory_bytes: 3712
n=int(input())
a = list(map(int,input().split()))
b = range(1,n+1)
ab = [[a[i],b[i]] for i in range(n)]
ab.sort()
ans = ""
for i in range(n):
    ans += str(ab[i][1])
    if i+1 != n:
        ans += " "


print(ans)
#

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

using namespace std;

int main() {
    string s = "";
    cin >> s;
    bool flag = true;

    int n = s.size();

    for(int i = 0 ; i < n / 2 ; i++){
        if(s[i] != s[n - 1 - i]){
            flag = false;
            break;
        }
    }

    if(flag == true){
        for(int i = 0; i < (n - 1) / 4; i++){
            if(s[i] != s[((n - 1) / 2) - 1 - i]){
                flag = false;
                break;
            }
        }
    }

    if(flag == true){
        for(int i = (n + 3) / 2 - 1; i < n ;i++){
            if(s[i] != s[n - 1 - i]){
                flag = false;
                break;
            }
        }
    }

    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
#include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)   (x).begin(),(x).end()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define mp       make_pair
#define eb       emplace_back

int main() {
	string s, ss;
	cin >> s >> ss;
	reverse(ALL(ss));
	cout << (s == ss ? "YES" : "NO") << endl;
}

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

using namespace std;

int main()
{
   string a, b, c;

   cin >> a >> b >> c;

   char s1 = a[0];

   char s2 = b[0];

   char s3 = c[0];

   if(s1 >= 97 && s1<=122)
   {
      s1 = s1 - 32;
   }
   if (s2 >= 97 && s2 <= 122)
   {
     s2 = s2 - 32;
   }
   if(s3 >= 97 && s3 <= 122)
   {
      s3 = s3-32;
   }
   cout<<s1 << s2 << s3;

}

Measured memory_bytes: 256