akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int n,d; cin >> n >> d;
  if(n<=d+1){cout << 1;}
  else{
    if(n%(2*d+1)==0){cout << n/(2*d+1);}
    else{cout << n/(2*d+1) + 1;}
  }
  
  return 0;
}

Measured memory_bytes: 256
use std::io::{self, BufRead};
use std::cmp::min;
use std::collections::BTreeSet;

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let s = lines.next().unwrap().unwrap();
  let k: usize = lines.next().unwrap().unwrap().parse().unwrap();
  let mut ss: BTreeSet<&str> = BTreeSet::new();
  for i in 0..s.len() {
    let len = min(5, s.len() - i);
    for j in 0..len {
      ss.insert(&s[i..(i+j+1)]);
    }
  }
  let mut it = ss.iter();
  for _ in 0..(k-1) {
    it.next();
  }
  println!("{}", it.next().unwrap());
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
};

int main() {

    int k;
    cin >> k;
    
    ll ans = 0;
    RREP(i, 1, k+1) {
        RREP(j, 1, k+1) {
            RREP(l, 1, k+1) {
                ans += gcd(gcd(i, j), l);
            }
        }
    }

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

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
#define int LL
using namespace std;
class Solver {
 public:
  int n;
  vector<int> a, b;
  Solver(LL n) : n(n), a(n), b(n){};
  int pre(int i) {
    return b[(i - 1 + n) % n];
  }
  int nxt(int i) {
    return b[(i + 1) % n];
  }
  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
      cin >> b[i];
    }
    int cnt = 0;
    int ans = 0;
    queue<int> Q;
    for (int i = 0; i < n; ++i) {
      if (b[i] == a[i]) cnt++;
      DBG(i, pre(i), nxt(i))
      if (b[i] - (pre(i) + nxt(i)) >= a[i]) {
        Q.push(i);
      }
    }
    while (!Q.empty()) {
      int pos = Q.front();
      Q.pop();
      DBG(pos)
      int diff = (pre(pos) + nxt(pos));
      int x = (b[pos] - a[pos]) / diff;
      ans += x;
      b[pos] -= x * diff;
      DBG(a)
      DBG(ans, b)
      if (b[pos] == a[pos]) cnt++;
      int p1 = (pos - 1 + n) % n;
      if (check(p1)) Q.push(p1);
      int p2 = (pos + 1) % n;
      if (check(p2)) Q.push(p2);
    }
    if (cnt == n) {
      cout << ans << endl;
    } else {
      cout << -1 << endl;
    }
  }
  bool check(int i) {
    int tmp = pre(i) + nxt(i);
    return (b[i] - tmp >= a[i]);
  }
  void no() {
    cout << -1 << endl;
    exit(0);
  }
};
}  // namespace Problem

signed main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}
	
	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=998244353;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=1e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e6+10;
	//------------------FIXED------------------
	int a[N];vc<pii> ans;
	void main()
	{
		int n=qread();int ps=1;fo(i,1,n) {a[i]=qread();if(abs(a[i])>abs(a[ps])) ps=i;}
		if(a[ps]>0)
		{
			ans.PB({ps,ps});ans.PB({ps,1});
			fo(i,1,n-1) ans.PB({i,i+1}),ans.PB({i,i+1});
		}
		else
		{
			ans.PB({ps,ps});ans.PB({ps,n});
			fd(i,n,2) ans.PB({i,i-1}),ans.PB({i,i-1});
		}
		write2(sz(ans));for(auto in:ans) write1(in.FR),write2(in.SE);
	}
};//����������
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 25600
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;

#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--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;

ll po[POW_MAX + 2];

ll comb(int n, int r) {
  return po[n] / (po[r] * po[n - r]);
}

int N;
int p[101];

int main() {
  scanf("%d", &N);

  if (N < 10) {
    printf("0\n");
    return 0;
  }

  FOR(i, 1, N + 1) {
    int x = i;
    FOR(j, 2, 98) {
      while (x % j == 0) {
        p[j]++;
        x /= j;
        if (x == 1) break;
      }
    }
  }
  int c3 = 0;
  int c5 = 0;
  int c15 = 0;
  int c25 = 0;
  int c75 = 0;
  FOR(i, 1, N + 1) {
    if (p[i] >= 2) c3++;
    if (p[i] >= 4) c5++;
    if (p[i] >= 14) c15++;
    if (p[i] >= 24) c25++;
    if (p[i] >= 74) c75++;
  }
  printf("%d\n", c75 + (c25 * (c3 - 1)) + (c15 * (c5 - 1)) + (c5 * (c5 - 1) * (c3 - 2) / 2));
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int k = scan.nextInt();
    boolean [] g = new boolean[n];
    for (int gg = 0;gg<n;gg++){
      g[gg] = true;
    }
    for (int i=0; i<k; i++){
      int a = scan.nextInt();
      for (int j=0;j<a;j++){
        int d = scan.nextInt();
        g[d-1] = false;
      }
    }
    int sum = 0;
    for (int q=0; q<n; q++){
      if (g[q] == true){
        sum += 1;
      }
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 46136
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int a,b,c,d;cin>>a>>b>>c>>d;
    if(a*c+b*d>(a*max(c,5)+b*max(d,2))*4/5)cout<<(a*max(c,5)+b*max(d,2))*4/5<<endl;
    else cout<<a*c+b*d<<endl;
    
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{

  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  ll n;
  cin >> n;
  vector<pll> v;
  rep(i, n)
  {
    ll a, b;
    cin >> a >> b;
    v.push_back(MP(a, b));
  }

  const auto comp = [](pll &p1, pll &p2) {
    return p1.first + p1.second > p2.first + p2.second;
  };
  sort(all(v), comp);

  ll ans = 0;
  rep(i, n)
  {
    ans += (i % 2 == 0 ? v[i].first : -v[i].second);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2420
#pragma GCC optimize("Ofast")

#include <algorithm>      //sort,二分探索,など
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <iterator>       //集合演算(積集合,和集合,差集合など)
#include <map>            //map(辞書)
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列
#include <list>           //双方向連結リスト

using namespace std;


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

    int n, q;
    cin >> n;
    vector<int> s(n);
    for(int i = 0; i < n; ++i){
        cin >> s[i];
    }
	cin >> q;
    vector<int> t(q);
    for(int i = 0; i < q; ++i){
        cin >> t[i];
    }
    int count = 0;
    for(int i = 0; i < q; ++i){
        for(int j = 0; j < n; ++j){
            if(t[i] == s[j]){
                ++count;
                break;
            }
        }
    }
    cout << count << "\n";
	return 0;
}


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

#define sz(o) ((int)o.size())
#define all(o) o.begin(), o.end()
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define repr(i, a, b) for(int i = (a); i >= (b); i--)
//#define vpal 100

typedef long long int ll;
typedef vector<ll> vll;
typedef vector<int> vi;

void solve(int testcase) {
    int n, m, x;
    cin >> n >> m >> x;
    set<int> s;
    rep(i, 1, m){
        int a;
        cin >> a;
        s.insert(a);
    }
    int p = 0, q = 0;
    int y = x;
    while(y != n){
        y++;
        if(s.count(y)) p++;
    }

    y = x;
    while(y != 0){
        y--;
        if(s.count(y)) q++;
    }

    cout << min(p,q);
}

int main() {
    #ifdef vpal
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << setprecision(10);
    clock_t b = clock();
    int t = 1;
    //cin >> t;
    rep(tt, 1, t) solve(tt);
    clock_t e = clock();
    cerr << (double(e - b) / CLOCKS_PER_SEC) << " sec";
    return 0;
}

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

int one[2005], two[2005];
int bit[4100];
int dp[2005][2005];
#define mxidx 4096
int gett(int x){
    int ret = 0;
    while(x){
        ret += bit[x];
        x = x & (x-1);
    }
    return ret;
}

void sett(int x){
    while(x^mxidx){
        bit[x]++;
        x += x & (-x);
    }
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++){
        char m; int x;
        scanf("%c",&m);
        scanf("%c%d",&m,&x);
        if(m == 'B') one[x] = i;
        else two[x] = i;
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            dp[i][j] = 2100000000;
        }
    }
    dp[0][0] = 0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=mxidx;j++) bit[j] = 0;
        for(int j=1;j<=i;j++){
            sett(one[j]);
        }
        for(int j=0;j<=n;j++){
            if(j>0) sett(two[j]);
            if(i<n){
                int x = one[i+1];
                int pls = (x-1) - gett(x-1);
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + pls);
            }
            if(j<n){
                int x = two[j+1];
                int pls = (x-1) - gett(x-1);
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + pls);
            }
        }
    }
    /*
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            printf("%d ", dp[i][j]);
        }
        printf("\n");
    }
    */
    printf("%d\n", dp[n][n]);
}


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

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

// to avoid error on mingw
string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int M = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}


int H, W;
const int MAX=102;
string field[MAX];
bool vis[MAX][MAX];

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

const char DUMMY = '-';

int dfs(int r, int c) {

    if(vis[r][c])
        return 0;

    char floor = field[r][c];
    field[r][c] = DUMMY;
    vis[r][c] = true;

    rep(i,4) {
        int nr = r + dy[i];
        int nc = c + dx[i];

        if(nr < 0 || H <= nr || nc < 0 || W <= nc)
            continue;

        if(floor == field[nr][nc])
            dfs(nr, nc);
    }

    return 1;
}


int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(8);
    ios_base::sync_with_stdio(false);

    while(cin>>H>>W, (H||W)) {
        memset(vis,0,sizeof(vis));

        rep(i,H)
            cin >> field[i];

        int res = 0;
        rep(i,H) {
            rep(j,W) {
                if(field[i][j] != DUMMY)
                    res += dfs(i, j);
            }
        }

        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 2028
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


n=int(input())
ans=0

for i in range(n):
    for j in range(n):
        for k in range(n):
            
            tmp=gcd(i+1,j+1,k+1)
            ans+=tmp

print(ans)


Measured memory_bytes: 69664
// Abhishek Katara
// Indian Institute of Information Technology, Vadodara

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
 
int main(){
	ll n, cr = 0, cb = 0;
    cin >> n;
	string str;
	cin >> str;
	for(ll i=0;i<n;i++){
		if(str[i] == 'R'){
			cr++;
		}
		else{
			cb++;
		}
	}
	if(cr > cb){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

public class Main {

	static FastScanner sc = new FastScanner();

	public static void main(String[] args) throws Exception {
		int[] I = new int[256];
		double[] en = new double[257];
		StringBuilder sb = new StringBuilder();
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			for (int i = 0; i < N; ++i) {
				double v = 1.0 * (i + 1) / N;
				en[i + 1] = -v * Math.log(v);
				I[i] = sc.nextInt();
			}
			double best = Double.MAX_VALUE;
			int bs = 0;
			int ba = 0;
			int bc = 0;
			for (int s = 0; s < 16; ++s) {
				for (int a = 0; a < 16; ++a) {
					OUT: for (int c = 0; c < 16; ++c) {
						int[] hist = new int[256];
						int r = s;
						for (int i = 0; i < N; ++i) {
							r = (a * r + c) & 0xFF;
							hist[(I[i] + r) & 0xFF]++;
						}
						double e = 0;
						for (int i = 0; i < 256; ++i) {
							if (hist[i] != 0) {
								e += en[hist[i]];
								if (e > best) continue OUT;
							}
						}
						if (e < best - 1e-10) {
							best = e;
							bs = s;
							ba = a;
							bc = c;
						}
					}
				}
			}
			sb.append(bs + " " + ba + " " + bc + "\n");
		}
		System.out.print(sb);
	}

	static class FastScanner {
		Reader input;

		FastScanner() {
			this.input = new BufferedReader(new InputStreamReader(System.in));
		}

		int nextInt() throws IOException {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			int ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		}
	}

}

Measured memory_bytes: 87544
class RollingHash():
    def __init__(self,s):
        self.length=len(s)
        self.base1=1009; self.base2=1013
        self.mod1=10**9+7; self.mod2=10**9+9
        self.hash1=[0]*(self.length+1); self.hash2=[0]*(self.length+1)
        self.pow1=[1]*(self.length+1); self.pow2=[1]*(self.length+1)
        for i in range(self.length):
            self.hash1[i+1]=(self.hash1[i]+ord(s[i]))*self.base1%self.mod1
            self.hash2[i+1]=(self.hash2[i]+ord(s[i]))*self.base2%self.mod2
            self.pow1[i+1]=self.pow1[i]*self.base1%self.mod1
            self.pow2[i+1]=self.pow2[i]*self.base2%self.mod2
    def get(self,l,r):
        h1=((self.hash1[r]-self.hash1[l]*self.pow1[r-l])%self.mod1+self.mod1)%self.mod1
        h2=((self.hash2[r]-self.hash2[l]*self.pow2[r-l])%self.mod2+self.mod2)%self.mod2
        return (h1,h2)

def solve(s,t):
    ls=len(s); lt=len(t)
    RHs=RollingHash(s*2)
    RHt=RollingHash(t)
    Judge=[False]*ls
    B=RHt.get(0,lt)
    for i in range(ls):
        if RHs.get(i,i+lt)==B:
            Judge[i]=True
    ret=0
    Visited=[-1]*ls
    for i in range(ls) :
        if Judge[i] and Visited[i]==-1:
            idx=i
            cnt=0
            while Judge[idx]:
                if Visited[idx]!=-1:
                    cnt+=Visited[idx]
                    break
                cnt+=1
                Visited[idx]=1
                idx=(idx+lt)%ls
                if idx==i:
                    return -1
            Visited[i]=cnt
            ret=max(ret,cnt)
    return ret

s=input(); t=input()
s*=(len(t)+len(s)-1)//len(s)
print(solve(s,t))

Measured memory_bytes: 144340
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i <= g; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1e9 + 7;

struct factorial
{
    vector<ll> fac, finv, inv;

    factorial(int n)
    {
        int i;

        rep(i, 0, 1)
        {
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }

        rep(i, 2, n)
        {
            fac.push_back(fac[i - 1] * i % MOD);
            inv.push_back(MOD - inv[MOD % i] * (MOD / i) % MOD);
            finv.push_back(finv[i - 1] * inv[i] % MOD);
        }
    }

    ll comb(int n, int k)
    {
        if (n < k)
        {
            return 0;
        }

        if (n < 0 || k < 0)
        {
            return 0;
        }

        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

int main(void)
{
    int N, K;
    ll a[100010];
    int i, j;
    ll ans = 0;

    cin >> N >> K;

    factorial f(N);

    rep(i, 0, N - 1)
    {
        cin >> a[i];
    }

    sort(a, a + N);

    rep(i, 0, N - 1)
    {
        ans += (a[i] * f.comb(i, K - 1)) % MOD;
        ans -= (a[i] * f.comb(N - i - 1, K - 1)) % MOD;
        ans %= MOD;
    }

    cout << ans % MOD << endl;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s, t = "753";
  cin >> s;
  int ans = 1e+9;
  for(int i=0;i<=s.size()-3;i++){
    int tp = 0;
    for(int j=0;j<3;j++){
      tp += (s[i+j]-t[j])*pow(10,2-j);
    }
    ans = min(ans,abs(tp));
  }
  cout << ans << endl;
}


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

const int MOD = 998244353;

std::map <std::string, int> mem;

int dp (const std::string &str) {
	int &ans = mem[str];
	if (ans != 0) return ans;
	ans = (str[0] == '0' ? 1 : 2) * dp (str.substr (1, str.size () - 1)) % MOD;
	for (int i = 1; i <= str.size (); ++i)
		for (int j = 2; i * j <= str.size (); ++j) {
			std::string little (i, '1');
			int ptr = 0;
			for (int k = 0; k < j; ++k)
				for (int l = 0; l < i; ++l)
					if (str[ptr++] == '0') little[l] = '0';
			int res = 1ll * dp (little) * dp (str.substr (ptr, str.size () - ptr)) % MOD;
			ans = (ans + res) % MOD;
		}
	return ans;
}

int main () {
	mem[""] = mem["0"] = 1; mem["1"] = 2;
	std::string input;
	std::cin >> input;
	std::cout << dp (input) << std::endl;
}


Measured memory_bytes: 5632
import sys
N,K = map(int,input().split())
lsx = list(map(int,input().split()))
if 0 in lsx:
    K = K-1
    lsx.remove(0)
if bool(lsx) == False or K == 0:
    print(0)
    sys.exit()
lshu = []
sei = len(lsx)
for i in range(len(lsx)):
    if lsx[i] < 0:
        lshu.append(lsx[i])
    else:
        sei = i
        break
lssei = lsx[sei:]
lenhu = len(lshu)
lensei = len(lssei)
lshu2 = [abs(lshu[i]) for i in range(lenhu-1,-1,-1)]
dishu = [0] + lshu2
dissei = [0] + lssei
ans = 10*10**8
for i in range(K+1):
    if i <= lenhu and K-i <= lensei:
        ans = min(ans,2*dishu[i]+dissei[K-i],dishu[i]+2*dissei[K-i])
print(ans)

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

const int maxn=200005;
const int maxm=1000005;
const int mdn=998244353;
const int inv2=(mdn+1)>>1;
int n;
int a[maxn];
int c[maxm];
long long f[maxm];
int mu[maxm];
bool ntp[maxm];
int prm[maxm],prc;
int cnt;
map<int,int> h;
int ex[maxn],px[maxn];
vector<int> fac[maxm];
void seive(){
    mu[1]=ntp[1]=1;
    for(int i=2;i<maxm;i++){
        if(!ntp[i]){prm[++prc]=i;mu[i]=-1;}
        for(int j=1;prm[j]*i<maxm;j++){
            ntp[i*prm[j]]=1;
            if(i%prm[j]){
                mu[i*prm[j]]=-mu[i];
            }else{
                mu[i*prm[j]]=0;
                break;
            }
        }
    }
}

inline long long calc(int n){
    long long tv=0;
    for(int i=0;i<fac[n].size();i++){
        tv=(tv+mu[fac[n][i]]*fac[n][i])%mdn;
    }
    return (tv+mdn)%mdn;
}
int main(){
    ios::sync_with_stdio(0);
    seive();
    cin>>n;
    long long ans=0,sm=0;
    for(int i=1;i<=n;i++){cin>>a[i];sm+=a[i];sm%=mdn;}
    for(int i=1;i<=n;i++){c[a[i]]++;}
    for(int i=1;i<maxm;i++){
        long long t=0;
        for(int j=1;j<=(maxm-1)/i;j++){
            t+=(long long)(j)*c[j*i];t%=mdn;
            fac[j*i].push_back(i);
        }
        f[i]=(t*t)%mdn;
    }
    for(int i=1;i<maxm;i++){
        long long sum=calc(i);//sum{d|n}mu[d]*d
        ans+=f[i]*i%mdn*sum%mdn;
        ans%=mdn;
    }
    cout<<((ans-sm+mdn)*inv2)%mdn;
    return 0;
}

Measured memory_bytes: 135552
#include<stdio.h>


int main(){
	int W,H,x,y,r;

		
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	if(W>= (x+r) && 0<=(x-r) && H>= (y+r) && 0<=(y-r) ){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

return 0;
}


	

Measured memory_bytes: 584
l = list(map(int,input().split()))
n = l[0]
l_all = list(range(1,n+1))
#print(ln)
k = l[1]

a = [list(map(int,input().split()))  for l in range(k*2)]

lh = []
for i in range(1,(k*2)+1):
  #print(i)
  if (i+1)%2 == 0:
    lh.extend(a[i])
    
#print(lh)
lnh = list((set(l_all) - set(lh)))
print( len(lnh) )
    
    

Measured memory_bytes: 9200
#include<stdio.h>
#include<ctype.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int R=1e5+1;
int IN(void)
{
  int x=0,f=1;char c=getchar();
  while(!isdigit(c)){if(c=='-')f=-f;c=getchar();}
  while(isdigit(c))x=(x*10)+(c-48),c=getchar();
  return f*x;
}
int main(void)
{
  int N,M,A,B,count=0,H[R]={0},low[R]={0};
  N=IN(),M=IN();
  rep(i,N)H[i]=IN();
  rep(i,M){A=IN()-1,B=IN()-1;if(H[A]<=H[B])low[A]=1;if(H[A]>=H[B])low[B]=1;}
  rep(i,N)count+=!low[i];
  return printf("%d\n",count),0;
}

Measured memory_bytes: 2376
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if((a * b) % 2 == 0) {
      System.out.println("Even");
    }else {
      System.out.println("Odd");
    }
  }
}

Measured memory_bytes: 26964
# D カンニング

from collections import Counter

n = int(input())
a_list = [int(x) for x in input().split()]
f_list = [True]*n
a_list.sort()
C = Counter(a_list)
ng_s = set()
ans = 0
L = a_list[n-1]

for _a in a_list:
    if _a in ng_s:
        continue
    if C[_a] == 1:
        ans += 1
    idx = 1
    while _a*idx <= L:
        ng_s.add(_a*idx)
        idx += 1

print(ans)

Measured memory_bytes: 170448
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int c[3][3];

int main() {
  rep(i, 3) cin >> c[i][0] >> c[i][1] >> c[i][2];
  int a[3]={}, b[3]={};
  string ans = "No";
  rep(i, 101){ // a0: [0, 100]
    a[0] = i;
    rep(i, 3) b[i] = c[0][i] - a[0];
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];
    bool flag = true;
    rep(i, 3){
      rep(j, 3){
        if (c[i][j] != a[i] + b[j]){
          flag = false;
          break;
        }
      }
    }
    if(flag) ans = "Yes";
  }

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

Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
typedef long long int ll;

ll N, P;

int main(){
	scanf("%lld %lld", &N, &P);
	map<ll, ll> mpa;
	for(ll i = 2; i * i <= P; i++){
		while(P % i == 0){
			mpa[i]++;
			P /= i;
		}
	}
	if(P != 1) mpa[P]++;
	ll res = 1;
	map<ll, ll>::iterator itr;
	for(itr = mpa.begin(); itr != mpa.end(); itr++){
		for(int i = 0; i < (itr->second / N); i++) res *= itr->first;
	}
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 256
from collections import deque
dxdy = ((-1,0), (1,0), (0,-1), (0,1)) # タプルやリストで持っておくと便利

H, W, K = map(int,input().split())
x1, y1, x2, y2 = map(int,input().split())
mp = [input() for _ in range(H)]
INF = 10**10
dist = [[INF]*W for _ in range(H)]
dist[x1-1][y1-1] = 0
q = deque()
q.append((x1-1,y1-1)) # スタート地点をenqueue
while(q):
    x, y = q.popleft()
    if x==x2-1 and y==y2-1:
        print (dist[x2-1][y2-1])
        exit()
    else:
        for dx, dy in  dxdy:
            for i in range(1,K+1):
                nx = x + dx*i
                ny = y + dy*i
                if not (0<=nx<H and 0<=ny<W) or mp[nx][ny]=='@':
                    break
                if dist[nx][ny] <= dist[x][y]:
                    break 
                if dist[nx][ny] == INF:
                    q.append((nx,ny))
                    dist[nx][ny] = dist[x][y] + 1
print(-1)

Measured memory_bytes: 36564
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		StringTokenizer tokenizer;
		Deque<Integer> deque = new ArrayDeque<Integer>();
		String s;
		while((s=reader.readLine())!=null){
			int num = Integer.parseInt(s);
			if(num==0)
				System.out.println(deque.poll());
			else
				deque.push(num);
		}
	}

}

Measured memory_bytes: 16872
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
#define vi vector<int>
#define vvi vector<vector<int>>
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k;
    cin>>k;
    int ans =0;
    vi abs;
    rep(i,1,k+1){
        rep(j,1,k+1){
            abs.push_back(__gcd(i,j));
        }
    }
    rep(i,1,k+1){
        rep(j,0,abs.size())
        ans+=__gcd(abs[j],i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
const int N=1e6+5;

int n,ans,h=1,t,q[N],p; char S[N],T[N];

int main()
{
	scanf("%d%s%s",&n,S+1,T+1); int i,o=1;
	for (i=1; o&&i<=n; i++) if (S[i]!=T[i]) o=0;
	if (o) return puts("0"),0;
	
	for (i=p=n; i; i--)
	{
		if (T[i]==T[i-1]) continue;
		for (p=std::min(p,i); p&&T[i]!=S[p]; p--);
		if (!p) return puts("-1"),0;
		while (h<=t&&q[h]-t+h>i) h++;
		q[++t]=p;
		if (i!=p) ans=std::max(ans,t-h+1);
	}
	printf("%d",ans+1);
	
	return 0;
}


Measured memory_bytes: 9668
use std::fs;
use std::io::{stdin, Read};
use std::iter::FromIterator;

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn primes() -> Vec<usize> {
    const n: usize = 55555;
    let mut ret = std::collections::HashSet::<usize>::from_iter(0..(n + 1));
    ret.remove(&1);
    ret.remove(&0);
    let mut cur = 2;
    while cur <= n {
        for i in ((2 * cur)..(n + 1)).filter(|i| i % cur == 0) {
            ret.remove(&i);
        }
        cur += 1;
        while cur <= n && !ret.contains(&cur) {
            cur += 1;
        }
    }
    ret.into_iter().collect()
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let n = parse!(it);
    let p = primes();
    println!(
        "{}",
        p.iter()
            .filter(|&x| x % 5 == 1)
            .take(n)
            .map(|x| x.to_string())
            .collect::<Vec<String>>()
            .join(" ")
    );
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
if __name__ == "__main__":
    N, A, B = map(int, input().split())
    ans = 0
    for i in range(1, N+1):
        x = sum(list(map(int, str(i))))
        #print("{} {}".format(i, x))
        if A <= x and x <= B:
            #print("{}!".format(i))
            ans += i
    print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


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

	int N;
	cin >> N;

	ll A[200001] = {};
	rep(i, N) {
		ll a;
		cin >> a;
		A[i + 1] = A[i] + a;
	}

	ll saishou = 1e18;
	rep1(i, N - 1) {
		saishou = min(saishou, abs(A[i] - A[N] + A[i]));
	}
	co(saishou);

	Would you please return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
        int n;
        cin >>n;
        int a[n];
        for(int i=0; i<n; i++) {
                cin >> a[i];
        }
        sort(a,a+n); int k; int sum=1; int ans=0;
        if(n==1) {
                if(a[0]==1) cout << 0 <<endl;
                else cout <<1 <<endl;
        }
        else{
                for(int i=0; i<n; i++) {
                        if(a[i]==a[i+1]) sum++;
                        else {
                                if(sum==a[i]) sum=1;
                                else if(sum>a[i]) {
                                        ans+=(sum-a[i]);
                                        sum=1;
                                }
                                else {
                                        ans+=sum;
                                        sum=1;
                                }
                        }
                }
                cout << ans <<endl;
        }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	int n = s.size();
	int ans = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] != s[n - 1 - i]) {
			s[i] = '#';
			s[n - 1 - i] = '#';
			++ans;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
S = input()

ans = "WA"
if S[0] == "A":
    if S[2:-1].count("C") == 1 and S.count("C") == 1:
        n = len(S)
        for i in range(len(S)):
            if S[i] == "A" or S[i] == "C":
                pass 
            elif S[i].isupper() == True:
                n -= 1
                break
        if n == len(S):
            ans = "AC"

print(ans)

Measured memory_bytes: 3060
import math

q = int(input())
cnt = [0] * (5 * 10 ** 4)
cnt[1] = 1
cnt[2] = 2


def is_prime(n):
    visit = []
    if n % 2 == 0:
        return 0
    for i in range(3, 1 + math.ceil(n ** (0.5))):
        if i not in visit:
            if n % i == 0:
                return 0
            else:
                visit.append(i)
    return 1


for i in range(3, 5 * 10 ** 4):
    odd = 2 * i + 1
    if odd % 3 != 1 or (odd + 1) % 4 == 0:
        cnt[i] = cnt[i - 1]
    else:
        k = 0
        if is_prime(odd) and is_prime((odd + 1) // 2):
            k = 1
            # print(odd, is_prime(odd), is_prime((odd + 1) // 2))
        cnt[i] = cnt[i - 1] + k
cnt.append(0)
for i in range(q):
    l, r = map(int, input().split())
    print(cnt[(r - 1) // 2] - cnt[(l - 3) // 2])


Measured memory_bytes: 3992
l, r = list(map(int, input().split()))
ans = 1e20
for i in range(l, min(r, l+2020)):
  for j in range(i+1, min(r+1, i+1+2020)):
    ans = min(ans, (i%2019)*(j%2019)%2019)
print(ans)

Measured memory_bytes: 42220
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>

int main() {
  using namespace std;
  namespace mp = boost::multiprecision;
  // 任意長整数型
  using Bint = mp::cpp_int;
  Bint A,B,C,D,ans;
  cin >> A >> B >> C >> D;
  Bint a=C,b=D;
  Bint x=a*b;
  Bint r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  Bint res=x/b;
  ans=B-A+1-((B/C-(A-1)/C)+(B/D-(A-1)/D)-(B/res-(A-1)/res));
  //cout << B/C-(A-1)/C<<" "<<B/D-(A-1)/D << " " << B/res-(A-1)/res <<" " << endl;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, M;
  cin >> N >> M;
  bool did = true;
  for (int i = 0; i < M/N;  i ++) {
    int j = M/N - i;
    if (M % j == 0) {
      cout << j << endl;
      did = false;
    }
    if (!did) break;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using  namespace std;
int main(){
    int N;
    cin >> N;
    int c = N/4, d = N/7;
    bool f = false;
    for(int i = 0; i <= c; i++){
        for(int j =0; j <= d; j++){
            if(4*i + 7*j == N){
                f = true; break;
            }
        }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <istream>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)cout<<"x";
	cout<<endl;
	return 0;
}

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

using namespace std;
#define int long long
#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) a.begin(),a.end()
#define fst first
#define scd second

const int inf=3e18;

using pii=pair<int,int>;

struct edge{int to,cost;};
vector<edge> G[100010];
int d[100010];

int n, m, x;
int H[100010];
int hei[100010];

signed main()
{
	cin>>n>>m>>x;
	
	rep(i, n) cin>>H[i];
	rep(i, m) {
		int a,b,t; cin >> a >> b >> t;
		--a, --b;
		G[a].push_back(edge{b, t});
		G[b].push_back(edge{a, t});
	}
	
	priority_queue<pii, vector<pii>, greater<pii>> q;
	q.push(pii(0,0));
	fill_n(d, n+1, inf);
	d[0] = 0;
	hei[0] = x;
	
	while (q.size()) {
		pii p = q.top(); q.pop();
		
		int v = p.scd;
		
		if (d[v] < p.fst) continue;
		
		for (edge &e : G[v]) {
			if (H[v] < e.cost) continue;
			
			int c = e.cost, h = hei[v] - e.cost;
			
			if (hei[v] - e.cost > H[e.to]) c += hei[v] - e.cost - H[e.to], h = H[e.to];
			if (hei[v] - e.cost < 0) c += abs(hei[v] - e.cost), h = 0;
			
			if (d[e.to] > d[v] + c) {
				hei[e.to] = h;
				d[e.to] = d[v] + c;
				q.push(pii(d[e.to], e.to));
			}
		}
	}
	
	int ans;
	
	if (d[n-1]==inf)ans=-1;
	else ans = d[n-1] + (H[n-1] - hei[n-1]);
	
	cout << ans << endl;
}

Measured memory_bytes: 23924
#include <iostream>
#include <string>

using namespace std;

int counter[26];

int main() {
	string s, p;
	getline(cin, s);
	getline(cin, p);
	for (int i = 0; i < s.size(); i++) {
		int j = 0;
		for (; j < p.size() && s.at((i + j) % s.size()) == p.at(j); j++);
		if (j == p.size()) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
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; }
//-------------------
int A, B;

int main(){
	cin >> A >> B;
	if(A >= 13) cout << B;
	else if(A>=6) cout << B/2;
	else cout << 0;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define inf (int)(3e18)
#define mod 998244353

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N,S;
int A[3005],dp[3005];
signed main() {
	cin>>N>>S;
	rep(i,N)cin>>A[i];
	int ans=0;
	rep(i,N){
		for(int j=S;j>=0;j--){
			dp[j]%=mod;
			if(j+A[i]<=S)dp[j+A[i]]+=dp[j];
		}
		dp[A[i]]+=i+1;
		ans+=dp[S];
		ans%=mod;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
namespace mp = boost::multiprecision;

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

	int n;
	cin >> n;
	ll* a = new ll[n];
	rep(i, n) cin >> a[i];
	rep(i, n) {
		if (a[i] == 0) {
			cout << 0 << "\n";
			return 0;
		}
	}

	mp::cpp_int ans = 1;
	rep(i, n) {
		ans *= a[i];
		if (ans > INF - 1) {
			cout << "-1" << "\n";
			return 0;
		}
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 4492
def solve1():
    n = int(input())
    a, b, c = 1, 1, 1
    ans = 0

    while n >= c:
        while b <= (n-c):
            ans += (n-c)//b
            b += 1
        c += 1

    print(ans)


def solve2():
    n = int(input())
    ans = 0

    for i in range(1, n):
        ans += (n-1)//i

    print(ans)


solve2()


Measured memory_bytes: 9124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

#define Vint vector<int>
#define VVint vector<Vint>
#define Fsize() front().size()

int VVint_zero(VVint vv) {
	int num = 0;
	for (int i = 0; i < (int)vv.size(); i++) {
		for (int j = 0; j < (int)vv.Fsize(); j++) {
			if (vv[i][j] == 0) num++;
		}
	}
	return num;
}

int VVint_max(VVint vv) {
	int max = 0;
	for (int i = 0; i < (int)vv.size(); i++) {
		for (int j = 0; j < (int)vv.Fsize(); j++) {
			if (vv[i][j] > max) max = vv[i][j];
		}
	}
	return max;
}

int main() {
	int x, y, s;
	char cha;
	VVint vec(10, Vint(10, 0));
	while (cin >> x >> cha >> y >> cha >> s) {
		vec[y][x] += 1;
		if (y - 1 >= 0) vec[y - 1][x]++;
		if (y + 1 < 10) vec[y + 1][x]++;
		if (x - 1 >= 0) vec[y][x - 1]++;
		if (x + 1 < 10) vec[y][x + 1]++;
		if (s >= 2) {
			if (y - 1 >= 0 && x - 1 >= 0) vec[y - 1][x - 1]++;
			if (y - 1 >= 0 && x + 1 < 10) vec[y - 1][x + 1]++;
			if (y + 1 < 10 && x - 1 >= 0) vec[y + 1][x - 1]++;
			if (y + 1 < 10 && x + 1 < 10) vec[y + 1][x + 1]++;
		}
		if (s == 3) {
			if (y - 2 >= 0) vec[y - 2][x]++;
			if (y + 2 < 10) vec[y + 2][x]++;
			if (x - 2 >= 0) vec[y][x - 2]++;
			if (x + 2 < 10) vec[y][x + 2]++;
		}
	}
	cout << VVint_zero(vec) << endl;
	cout << VVint_max(vec) << endl;
	return 0;
}


Measured memory_bytes: 3028
#pragma region template
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define vint vector<int>
#define vll vector<ll>
#define vstr vector<string>
#define vbl vector<bool>
#define pb push_back
using namespace std;
using ll = long long;

const string Yes = "Yes\n";
const string No = "No\n";

static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> inline T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}template<class T> inline T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}
#pragma endregion template

void solve(ll N, vector<string> W) {
  bool legit = true;
  rep(i, N - 1) {
    if (W.at(i).at((int)W.at(i).size() - 1) != W.at(i + 1).at(0)) {
      legit &= false;
      break;
    }
  }
  vstr W2 = W;
  sort(all(W2));
  W2.erase(unique(all(W2)), W2.end());
  legit &= (W2.size() == W.size());

  Yes(legit);
}

int main() {
  ll N;
  ignore_ret(scanf("%lld",&N));
  vector<string> W(N);
  for(int i = 0 ; i < N ; i++){
    cin >> W[i];
  }
  solve(N, move(W));
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

int n;
long double dp[3009];
long double ans;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> n;

    dp[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        long double prob;
        cin >> prob;

        for (int j = i; j >= 0; j--)
        {
            if (j == 0)
            {
                dp[j] = dp[j] * (1.0 - prob);
            }
            else
            {
                dp[j] = dp[j - 1] * prob + dp[j] * (1.0 - prob);
            }
        }
    }

    for (int heads = 0; heads <= n; heads++)
    {
        int tails = n - heads;

        if (heads > tails) ans += dp[heads];
    }

    cout << setprecision(10) << fixed << ans << "\n";
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    for(ll i=-121; i<=121; i++)
    {
        for(ll j=-121; j<=121; j++)
        {
            if(i*i*i*i*i - j*j*j*j*j == x)
            {
                cout << i << ' ' << j << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3664