akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for (auto i=(a); i<(b); ++i)
#define iter(it,c) for (auto it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
const int INF = 2147483647;
const ll DINF = 1000000000000000000LL;

#ifndef STNODE
#define STNODE
struct node {
  int l, r;
  ll x, lazy;
  node() {}
  node(int _l, int _r) : l(_l), r(_r), x(0), lazy(0) { }
  node(int _l, int _r, int _x) : node(_l,_r) { x = _x; }
  node(node a, node b) : node(a.l,b.r) { x = max(a.x, b.x); }
  void update(ll v) { x += v; }
  void range_update(ll v) { lazy = v; }
  void apply() { x += lazy; lazy = 0; }
  void push(node &u) { u.lazy += lazy; } };
#endif

struct segment_tree {
  int n;
  vector<node> arr;
  segment_tree() { }
  segment_tree(const vector<ll> &a) : n(a.size()), arr(4*n) {
    mk(a,0,0,n-1); }
  node mk(const vector<ll> &a, int i, int l, int r) {
    int m = (l+r)/2;
    return arr[i] = l > r ? node(l,r) :
      l == r ? node(l,r,a[l]) :
      node(mk(a,2*i+1,l,m),mk(a,2*i+2,m+1,r)); }
  node update(int at, ll v, int i=0) {
    propagate(i);
    int hl = arr[i].l, hr = arr[i].r;
    if (at < hl || hr < at) return arr[i];
    if (hl == at && at == hr) {
      arr[i].update(v); return arr[i]; }
    return arr[i] =
      node(update(at,v,2*i+1),update(at,v,2*i+2)); }
  node query(int l, int r, int i=0) {
    propagate(i);
    int hl = arr[i].l, hr = arr[i].r;
    if (r < hl || hr < l) return node(hl,hr);
    if (l <= hl && hr <= r) return arr[i];
    return node(query(l,r,2*i+1),query(l,r,2*i+2)); }
  node range_update(int l, int r, ll v, int i=0) {
    propagate(i);
    int hl = arr[i].l, hr = arr[i].r;
    if (r < hl || hr < l) return arr[i];
    if (l <= hl && hr <= r)
      return arr[i].range_update(v), propagate(i), arr[i];
    return arr[i] = node(range_update(l,r,v,2*i+1),
                         range_update(l,r,v,2*i+2)); }
  void propagate(int i) {
    if (arr[i].l < arr[i].r)
      arr[i].push(arr[2*i+1]), arr[i].push(arr[2*i+2]);
    arr[i].apply(); } };

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

    segment_tree st(vector<ll>(n,0));

    vector<ll> sm(n);

    vector<vector<pair<int,int> > > arr(n);
    rep(i,0,m) {
        int l, r, a;
        cin >> l >> r >> a;
        l--, r--;

        sm[l] += a;
        if (r + 1 < n) {
            sm[r+1] -= a;
        }

        st.range_update(l, r, -a);
        arr[l].push_back({r,a});
    }

    rep(i,1,n) {
        sm[i] += sm[i-1];
    }

    ll best = 0;
    for (int i = n-1; i >= 0; i--) {
        ll dp = sm[i] + st.query(i+1,n-1).x;
        best = max(best, dp);
        st.update(i, dp);

        iter(it,arr[i]) {
            st.range_update(i, it->first, it->second);
        }
    }

    cout << best << endl;

    return 0;
}



Measured memory_bytes: 26980
#include<bits/stdc++.h>
#define ll long long int
#define __ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main ()
{
__

int n;

cin >> n;

int a[n+5];

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

for(int i=1;i<n;i++){
if(a[i]>a[i-1]) a[i]--;
}

for(int i=0;i<n-1;i++)
{
if(a[i]> a[i+1]){
cout << "No";
exit(0);
}
}

cout << "Yes";


return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

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

  bool flag = true;
  for (int i = 0; i < s.length(); i++)
  {
    char c = s[i];
    if(i % 2 == 0){
      if(c == 'L'){
        flag = false;
      }
    }else{
      if(c == 'R'){
        flag = false;
      }
    }
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string s;
  cin >> s;
  int cnt=0;
  for(int i=0;i<1000;i++){
    int c[3] = {i/100,(i/10)%10,i%10};
    int f=0;
    for(int j=0;j<N;j++){
      if(s[j]=='0'+c[f]){
        f++;
      }
      if(f==3){
        break;
      }
    }
    if(f==3){
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

int main() {
  double X, Y, Z;
  cin >> X >> Y >> Z;
  for (int i=0; i<=(X-Z)/(Y+Z); i++) {
    if ((X-Y-2*Z)/(Y+Z)<i && i<=(X-Z)/(Y+Z)) {
      cout << i << endl;
    }
  }
}


Measured memory_bytes: 3720
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,H,W,ans;
  cin>>N>>H;
  if(N*500>=H)printyes;
  else printno;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0, x = 0, y = 0, z = 0,n=0,m=0, maxy = -1, mini = 9999, counter = 0, s = 0, endp = 0, checker = 0;
std::vector <char> vec{}, vecsec{}, vecth{};
long long int iremono[1001][1001];
long long int iremono2[1001];
std::vector<unsigned long long int>kinds{}, ans{}, kaku{};
char moji, moji2;
bool okada = false, okada2 = false;
std::string output, output2, input, one, two;
char rev[100001];
unsigned long long int kakunou2[101][101] = {};
unsigned long long int M, A, R, C, H;

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}
int main()
{
	cin >> a >> b >> c;
	cout << (a - b) % c << endl;
}

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

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        if(int(i*1.08) == n){
            cout << i << endl;
            exit(0);
        }
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

const int N = 1e5 + 100;
vector<vector<int>> g(N);
vector<bool> visited(N, false);
vector<int> color(N, 0), par(N, -1);

void dfs1(int v) {
  for (auto &u : g[v]) {
    if (par[u] == -1) {
      par[u] = v;
      dfs1(u);
    }
  }
}

void dfs(int v, int c) {
  visited[v] = true;
  for (auto &u : g[v]) {
    if (!visited[u]) {
      if (color[u]) {
        dfs(u, color[u]);
      } else {
        color[u] = c;
        dfs(u, c);
      }
    }
  }
}
signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  par[1] = 1;
  dfs1(1);

  vector<int> path(1, n);
  int t = n;
  while (t != 1) {
    path.push_back(par[t]);
    t = par[t];
  }

  for (int i = 0; i < sz(path) / 2; i++) {
    color[path[i]] = 2;
  }
  for (int i = sz(path) / 2; i < sz(path); i++) {
    color[path[i]] = 1;
  }
  dfs(1, 1);
  int cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; i++) {
    if (color[i] == 1) cnt1++;
    else cnt2++;
  }
  if (cnt1 > cnt2) {
    cout << "Fennec\n";
  } else {
    cout << "Snuke\n";
  }
}



Measured memory_bytes: 12916
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <climits>
#include <algorithm>

int main()
{
	int n,d,t=1;
	std::cin >> d >> n;
	for (int i = 0; i < d; i++) {
		t *= 100;
	}
	std::cout << t * (n==100?n+1:n);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdio.h>
using namespace std;

void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}

int main() {
  int n=0, sum=0;
  cin >> n;
  for(;n!=0; n--){sum+=n;}
  put(sum);
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a, b;
  scanf("%d %d", &a, &b);
  if(a<b){
    printf("%d", 2*b-1);
  }else if(b<a){
    printf("%d", 2*a-1);
  }else{
    printf("%d", 2*a);
  }
  return 0;
}


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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int cnt = 0;
  for(int i = 0; i <= a; i++) {
    for(int j = 0; j <= b; j++) {
      for(int k = 0; k <= c; k++) {
        int sum = 0;
        sum = 500*i + 100*j + 50*k;
        if(x == sum) cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

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

const int MAXN = 1500*1000+5;
const int N = 500*1000+5;
const int mod = 1000*1000*1000+7;
const int p = 31;

vector<int> g[N], topo;
int color[N], p31[MAXN], p_inv[MAXN], h[MAXN];

int mul(int a, int b) { return 1LL * a * b % mod; }
int mpow(int a, int n) {
	if(n == 0) return 1;
	int x = mpow(a, n/2);
	x = mul(x, x);
	if(n % 2) x = mul(x, a);
	return x;
}

void fix(int& a) {
	while(a >= mod) a -= mod;
	while(a < 0) a += mod;
}

int add(int a, int b) {
	fix(a), fix(b);
	a += b;
	fix(a);
	return a;
}

int sub(int a, int b) {
	fix(a), fix(b);
	a -= b;
	fix(a);
	return a;
}

int hash_s(int i, int j) {
	int L = i == 0 ? 0 : h[i-1];
	return mul(p_inv[i], sub(h[j], L));
}

bool dfs(int u) {
	color[u] = 1;
	for(int v : g[u]) {
		if(color[v] == 1) {
			return false;
		} else if(color[v] == 0 && !dfs(v)) {
			return false;
		}
		
	}
	color[u] = 2;
	topo.push_back(u);
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	p31[0] = p_inv[0] = 1;
	for(int i = 1; i < MAXN; i++) {
		p31[i] = mul(p, p31[i-1]);
		p_inv[i] = mpow(p31[i], mod-2);
	}
	
	string s, t;
	cin >> s >> t;
	int old_length = s.length();
	int n = s.length(), m = t.length();
	while((int) s.length() < n+m) {
		s += s;
	}
	n = s.length();
	for(int i = 0; i < n; i++) {
		int L = i == 0 ? 0 : h[i-1];
		h[i] = add(L, mul(p31[i], s[i]-'a'+1));
	}
	
	int hash_t = 0;
	for(int i = 0; i < m; i++) {
		hash_t = add(hash_t, mul(p31[i], t[i]-'a'+1));
	}
	
	for(int i = 0; i <= n-m; i++) {
		if(hash_s(i, i+m-1) == hash_t) {
			g[i % old_length].push_back((i+m) % old_length);
		}
	}
	
	for(int i = 0; i < old_length; i++) {
		if(color[i] == 0 && !dfs(i)) {
			cout << -1 << endl;
			exit(0);
		}
	}
	
	int ans = 0;
	vector<int> dp(old_length);
	
	for(int u : topo) {
		for(int v : g[u]) {
			dp[u] = max(dp[u], 1+dp[v]);
		}
		ans = max(ans, dp[u]);
	}

	cout << ans << endl;
	
}


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

int main() {
    int q;
    cin >> q;
    while (q--) {
        ll a, b;
        cin >> a >> b;
        ll c = sqrt(a * b);
        ll ans = c * 2 - 2;
        if (a == b) ans++;
        if (c * c == a * b) ans--;
        if (c * (c + 1) < a * b) ans++;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define DEBUG(debug_x) cerr <<#debug_x<<": "<<debug_x<<endl;
#define DEBUG2(debug_x, debug_y) cerr <<#debug_x<<":"<<debug_x<<" "<<#debug_y<<":"<<debug_y<<endl;
#define DEBUG3(debug_x, debug_y, debug_z) cerr <<#debug_x<<":"<<debug_x<<" "<<#debug_y<<":"<<debug_y<<" "<<#debug_z<<":"<<debug_z<<endl;
#define DEBUGVC(debug_x) cerr <<#debug_x<<": "; for(auto a:debug_x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(debug_x) cerr <<#debug_x<<":"<<endl; for(auto a:debug_x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (200005)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;
typedef pair<int,int> Pii;
typedef pair<double,double> Pdd;


int N, Q;
vector<int> G[MAX_N];
vector<bool> F(MAX_N,false);
vector<int> V(MAX_N,0);

void dfs(int s, int c){
    F[s]=true;
    V[s] = c;
    for(int i=0; i<G[s].size(); i++){
        int u = G[s][i];
        if(F[u]) continue;
        dfs(u,c+V[u]);
    }
}
 
signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    double d=0;
    for(int i=0; i<N; i++){
        d += 1.0/A[i];
    }

    printf("%.10f\n", 1.0/d);

}


Measured memory_bytes: 6528
//#pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 500 + 5;
const int M = 1e3 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

int n,m,a[M],b,x,dp[M][1<<12];
vector<int> c[M];

int solve(int idx, int mask) {

    if(idx == m) return mask == (1 << n) - 1 ? 0 : OO;

    int &ret = dp[idx][mask];

    if(~ret) return ret;

    ret = OO;

    ret = min(ret, solve(idx+1, mask));

    int newMask = mask;

    for(auto bit: c[idx]) {

        newMask |= (1 << (bit-1));

    }

    ret = min(ret, solve(idx+1, newMask) + a[idx]);

    return ret;

}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b;
        for (int j = 0; j < b; ++j) {
            cin >> x;
            c[i].pb(x);
        }
    }

    memset(dp, -1, sizeof dp);

    int ans = solve(0, 0);

    cout << (ans == OO ? -1 : ans) << '\n';

    return 0;
}

Measured memory_bytes: 19832
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N;
    cin >> N;
    VI A(N);
    REP(i, N) cin >> A[i];

    double ans = 0;
    REP(i, N) {
        ans += 1. / A[i];
    }

    cout << fixed << setprecision(10) << 1. / ans << endl;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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 long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    int N = S.size();
    vector<int> ans(N);

    int cnt = 1;
    vector<int> num;
    rep(i, N - 1) {
        if (S[i] == S[i+1]) {
            cnt++;
        } else {
            num.push_back(cnt);
            cnt = 1;
        }
    }
    if (cnt) num.push_back(cnt);

    int idx = 0;
    rep(i, N-1) {
        if (S[i] == 'R' && S[i+1] == 'L') {
            ans[i] = (num[idx] + 1) / 2 + num[idx+1] / 2;
            ans[i+1] = num[idx] / 2 + (num[idx+1] + 1) / 2;
            idx += 2;
        }
    }

    rep(i, N) printf("%d%c", ans[i], i<N-1? ' ' : '\n');
}

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

#define INF 1000000007
#define mem(dp,a) memset(dp,a,sizeof dp)
#define flash ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define f(i,n) for (ll i=0;i<n;i++)
#define sieve(j,mp) for(ll j=2*i ; j<=mp ; j+=i)
#define pb(x) push_back(x)
#define mp(x,y) push_back(make_pair(x,y))
#define tr(c,it) for(((c).begin())it=(c).begin();it!=(c).end();it++)
#define test ll t=1; while(t--)
#define F first
#define S second
main()
{
    flash
    clock_t launch=clock();
    test
    {
        ll n,k,val=INT_MAX;
        cin>>n>>k;
        ll dp[n+1],a[n+1];
        mem(dp,0);
        rep(i,1,n+1) cin>>a[i];
        rep(i,2,n+1)
        {
            val=INT_MAX;
            rep(j,1,k+1)
            if(i-j>0) val=min(val,dp[i-j]+abs(a[i]-a[i-j]));
            dp[i]=val;
        }
        cout<<dp[n]<<endl;
    }

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

ll solve()
{
    ll n;
    cin >> n;

    vector<ll> speed = fetch_vec<ll>(5);

    ll minSpeed = *min_element(speed.begin(), speed.end());
    ll res = std::max(0ll, n - minSpeed) / minSpeed;

    if (std::max(0ll, n - minSpeed) % minSpeed != 0)
        res++;

    return res + 5ll;
}

int main()
{
    std::cout << solve() << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n, d1, d2;
    int count = 0;
    bool rpd = false;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> d1 >> d2;
        if (d1 == d2) count++;
        else          count = 0;
        if (count == 3) rpd = true;
    }
    cout << (rpd ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define int long long

int mod_pow(int n, int e, int mod){
    int ans = 1;
    n = n % mod;
    while(e != 0){
        if(e % 2 == 1){
            ans = (ans * n) % mod;
        }
        e /= 2;
        n = (n * n) % mod;
    }
    return ans;
}


int mod_inv(int n, int mod){
    return mod_pow(n, mod-2, mod);
}

int mod_combination(int n, int k, int mod){
    if(n < k || k < 0) return 0;
    int ans = 1;
    for(int i=1; i<=k; i++){
        ans = (((ans * (n+1-i)) % mod) * mod_inv(i, mod)) % mod;
    }
    return ans;
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int mod = 1e9+7;
    int x, y;
    cin >> x >> y;

    if((x+y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }

    int u = x - (x+y)/3;
    int v = y - (x+y)/3;

    cout << mod_combination(u+v, u, mod) << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<char> animal ={'S', 'W'};
  bool flag = false;
  for(int i=0; i<2; i++){
    for(int j=0; j<2; j++){
      vector<char> ans(N);
      ans.at(0) = animal.at(i);
      ans.at(1) = animal.at(j);
      bool A = false;
      bool B = false;
      for(int k=2; k<N; k++){
        if((ans.at(k-1) == 'S' && S.at(k-1) == 'o') || (ans.at(k-1) == 'W' && S.at(k-1) == 'x')){
          ans.at(k) = ans.at(k-2);
        }
        else{
          if(ans.at(k-2) == 'W'){
            ans.at(k) = 'S';
          }
          else{
            ans.at(k) = 'W';
          }
        }
      }
      if((ans.at(0) == 'S' && S.at(0) == 'o') || (ans.at(0) == 'W' && S.at(0) == 'x')){
        if(ans.at(N-1) == ans.at(1)){
          A = true;
        }
      }
      else{
        if(ans.at(N-1) != ans.at(1)){
          A = true;
        }
      }
      if((ans.at(N-1) == 'S' && S.at(N-1) == 'o') || (ans.at(N-1) == 'W' && S.at(N-1) == 'x')){
        if(ans.at(N-2) == ans.at(0)){
          B = true;
        }
      }
      else{
        if(ans.at(N-2) != ans.at(0)){
          B = true;
        }
      }
      if(A && B){
        flag = true;
        for(int i=0; i<N; i++){
          cout << ans.at(i);
        }
        cout << endl;
        break;
      }
    }
    if(flag){
      break;
    }
  }
  
  if(!flag){
    cout << -1 << endl;
  }
}

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

#define ll long long
#define vecint vector<int>
#define listint list<int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define MOD 1000000007;


int main(){
  string S;
  cin>>S;
  string ans="YES";
  while(S.size()>7){
    if(S.find("dreamer",S.size()-7)==S.size()-7){
      S.erase(S.end()-7, S.end());
      // print(S);
      continue;
    }
    if(S.find("dream",S.size()-5)==S.size()-5){
      S.erase(S.end()-5, S.end());
      // print(S);
      continue;
    }
    if(S.find("eraser",S.size()-6)==S.size()-6){
      S.erase(S.end()-6, S.end());
      // print(S);
      continue;
    }
    if(S.find("erase",S.size()-5)==S.size()-5){
      S.erase(S.end()-5, S.end());
      // print(S);
      continue;
    }

    ans="NO";
    break;
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    if (a + b < k) {
        a = 0;
        b = 0;
    }
    else if (a < k) {
        k -= a;
        a = 0;
        b -= k;
    }
    else {
        a -= k;
    }
    cout << a << " " << b << endl;
}

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

int main(){
   int x;
   cin>>x;
   if(x>=30) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int K,N;
    cin >> K >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >> A.at(i);
    int mind = K;
    int tmpd = 0;
    for(int i=0;i<N;i++){
        if ((i+N-1)<N){
            tmpd = A.at(i+N-1) - A.at(i);
        }else{
            tmpd = A.at(i-1) + K - A.at(i);
        }
        mind = min(mind, tmpd);
    }
    cout << mind << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, T;
  cin >> N >> T;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int pos = N - 1;
  vector<int> diff;
  for (int i = N - 2; i >= 0; i--) {
    if (A[pos] < A[i]) {
      pos = i;
      continue;
    }
    diff.emplace_back(A[pos] - A[i]);
  }
  sort(diff.begin(), diff.end(), greater<int>());
  int res = 1;
  for (int i = 0; i < diff.size(); i++) {
    if (diff[i] == diff[i + 1])
      res++;
    else
      break;
  }
  cout << res << '\n';
  return 0;
}


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

using namespace std;
string solve(string s) {
    for (int i = 0; i < s.size() - 1; ++i)
        if (s[i] == s[i+1])
            return "Bad";
    return "Good";
}
int main() {
    string s; cin >> s;
    cout << solve(s) << endl;
    return 0;
}

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

int main() {
  int N, K; cin >> N >> K;
  int max_p = (N-1) * (N-2) / 2;  // 距離 2 の組数の上限
  if (max_p < K) { cout << -1 << endl; return 0; }
  vector<pair<int, int>> ans;
  // うにを作ると距離 2 の組は max_p 組できる
  for (int i = 0; i < N-1; i++) {
    ans.push_back(make_pair(i+1, N));
  }
  // うにの先端の頂点同士を結ぶと、距離 2 の組が 1 つ減る
  int add = max_p - K;
  vector<pair<int, int>> E;  // 加える辺の候補を挙げておく
  for (int i = 0; i < N-2; i++) {
    for (int j = i+1; j < N-1; j++) {
      E.push_back(make_pair(i+1, j+1));
    }
  }
  for (int i = 0; i < add; i++) ans.push_back(E.at(i));
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans.at(i).first << " " << ans.at(i).second << endl;
  }
}

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

typedef vector<int> vi;
const int maxn = 500 + 10;
#define pb push_back

vi g[maxn];

pair<int,int> vv[maxn];

int a[maxn];
int w[maxn * maxn];
int cnt[maxn];

#define NOSOL { puts("No"); return 0; }

int main() {
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), w[a[i]] = i;
	set<int> s(a + 1, a + n + 1);
	if(s.size() != n) NOSOL;
	for(int i = 1; i <= n; ++i) cnt[i] = i - 1;
	priority_queue< pair<int,int> > q;
	for(int i = 1; i <= n; ++i) if(cnt[i]) q.push({-a[i], i});
	for(int k = 1; k <= n * n; ++k) {
		if(w[k]) continue;
		int p, i; tie(p, i) = q.top(); p = -p;
		if(k > p) NOSOL;
		w[k] = i;
		if(--cnt[i] == 0) q.pop();
		if(q.empty()) break;
	}
	if(!q.empty()) NOSOL;
	for(int i = 1; i <= n; ++i) cnt[i] = n - i;
	for(int i = 1; i <= n; ++i) if(cnt[i]) q.push({a[i], i});
	for(int k = n * n; k >= 1; --k) {
		if(w[k]) continue;
		int p, i; tie(p, i) = q.top();
		if(k < p) NOSOL;
		w[k] = i;
		if(--cnt[i] == 0) q.pop();
	}
	if(!q.empty()) NOSOL;
	puts("Yes");
	for(int i = 1; i <= n * n; ++i) 
		printf("%d%c", w[i], " \n"[i==n*n]);
	return 0;
}


Measured memory_bytes: 2304
n = int(input())

a = list(map(int, input().split()))
cs = [0]*9
for i in a:
    if (1 <= i <= 399):
        cs[0] += 1
    elif (400 <= i <= 799):
        cs[1] += 1
    elif (800 <= i <= 1199):
        cs[2] += 1
    elif (1200<= i <= 1599):
        cs[3] += 1
    elif (1600 <= i <= 1999):
        cs[4] += 1
    elif (2000 <= i <= 2399):
        cs[5] += 1
    elif (2400 <= i <= 2799):
        cs[6] += 1
    elif (2800 <= i <= 3199):
        cs[7] += 1
    else:
        cs[8] += 1

rate = sum([(cs[i] != 0) for i in range(0,8)])

print("{} {}".format(max(rate,1),rate+cs[8]))

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"reflect"
)

type card struct {
	s byte
	v int
}

func bubbleSort(a []*card) {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := n - 1; j > i; j-- {
			if a[j].v < a[j-1].v {
				a[j], a[j-1] = a[j-1], a[j]
			}
		}
	}
}

func selectionSort(a []*card) {
	n := len(a)
	for i := 0; i < n; i++ {
		mini := i
		for j := i; j < n; j++ {
			if a[j].v < a[mini].v {
				mini = j
			}
		}
		if i != mini {
			a[i], a[mini] = a[mini], a[i]
		}
	}
}

func printCards(a []*card) {
	for i := 0; i < len(a); i++ {
		fmt.Printf("%c%d", a[i].s, a[i].v)
		if i == len(a)-1 {
			fmt.Println()
		} else {
			fmt.Print(" ")
		}
	}
}
func main() {
	var n int
	fmt.Scan(&n)
	c := make([]*card, n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		c[i] = &card{s[0], int(s[1] - '0')}
	}

	bs := make([]*card, n)
	ss := make([]*card, n)
	copy(bs, c)
	copy(ss, c)
	bubbleSort(bs)
	selectionSort(ss)

	printCards(bs)
	fmt.Println("Stable")
	printCards(ss)
	if reflect.DeepEqual(bs, ss) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
}



Measured memory_bytes: 1212
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
#ifdef _75108D01685041AA959399A981476AD7
  std::freopen("input.txt", "r", stdin);
#endif
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    b[i]--;
  }
  vector<int> res;
  while (!b.empty()) {
    bool found = false;
    for (int j = b.size() - 1; j >= 0; j--) {
      if (b[j] == j) {
        res.push_back(j);
        b.erase(b.begin()+j);
        found = true;
        break;
      }
    }
    if (!found) {
      cout << "-1\n";
      return 0;
    }
  }
  reverse(res.begin(), res.end());
  for (int x : res) {
    cout << x+1 << "\n";
  }

  return 0;
}


Measured memory_bytes: 256
N = gets.to_i

alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

str = ["a"]
num_letter = [1]

for i in 2..N do   #add the i-th letter.
  next_str = []
  next_num_letter = []
  for j in 1..str.length do
    x = num_letter[j-1]
    for k in 0..x do
      next_str.push(str[j-1] + alpha[k])
      if k < x then
        next_num_letter.push(num_letter[j-1])
      else
        next_num_letter.push(num_letter[j-1] + 1)
      end
    end
  end
  str = next_str
  num_letter = next_num_letter
end

puts str

Measured memory_bytes: 14332
n = gets.to_i
works = []

n.times do
  works << gets.split.map(&:to_i)
end

used = 0
works = works.sort_by{|a| a[1]}

while works.size > 0
  nextwork = works.shift
  if nextwork[0] <= nextwork[1] - used
    used += nextwork[0]
  else
    puts :No
    exit
  end
end

puts :Yes


Measured memory_bytes: 24568
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int R, D, X; cin >> R >> D >> X;
    for(int i=0; i<10; i++){
        X = R * X - D;
        cout << X << endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
def main():
    n, T = map(int, input().strip().split())

    min_c = 10000
    for i in range(n):
        c, t = map(int, input().strip().split())
        if t > T:
            continue;
        if c < min_c:
            min_c = c

    if min_c == 10000:
        print("TLE")
    else:
        print(min_c)

if __name__ == "__main__":
    main()

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            new Calc();
        }

        public static List<string> Splitter(string input)
        {
            var result = new List<string>();
            int spaces = input.Where(a => a == ' ').Count();
            int pos = 0;
            for (int i = 0; i <= spaces; i++)
            {
                input = input.Remove(0, pos);
                pos = input.IndexOf(" ");
                if (pos == 0 || pos == -1) { pos = input.Length; }
                string text = "";
                for (int j = 0; j < pos; j++)
                {
                    text += input[j];
                }
                result.Add(text);
                pos++;
            }
            return result;
        }

        public static List<int> IntParser(List<string> input)
        {
            var result = new List<int>();
            foreach (var i in input)
            {
                int num;
                Int32.TryParse(i, out num);
                result.Add(num);
            }
            return result;
        }
    }

    class Calc
    {
        int h, w;
       
        List<Population> pops;
        public Calc()
        {
            pops = new List<Population>();
            var first =Program.IntParser(Program.Splitter(Console.ReadLine()));
            h = first[0];
            w = first[1];
            for (int i = 0; i < h; i++)
            {
                var columm = Program.IntParser(Program.Splitter(Console.ReadLine()));
                for (int j = 0; j < columm.Count; j++)
                {
                    pops.Add(new Population { x = i, y = j, population = columm[j] });
                }
            }
            var distances = new List<int>();
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    int distant = 0;
                    var s = new Section { x = i, y = j };
                    foreach (var p in pops)
                    {
                        distant += p.Distance(s);
                    }
                    distances.Add(distant);
                }
            }
            distances.Sort();
            Console.WriteLine(distances[0]);
            Console.ReadKey();
        }
    }
    struct Population
    {
        public int x, y;
        public int population;

        public int Distance(Section section)
        {
            int dis, dis1, dis2;
            dis1 = Math.Abs(x - section.x);
            dis2 = Math.Abs(y - section.y);
            if (dis1 > dis2)
            {
                dis = dis2;
            }
            else
            {
                dis = dis1;
            }
            return dis * population;
        }
    }
    struct Section
    {
        public int x, y;
    }
}




Measured memory_bytes: 19056
a[7];main(x,n){for(;scanf("%d",&n),n;printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n",*a,a[1],a[2],a[3],a[4],a[5],a[6]))for(memset(a,0,28);n--;)scanf("%d",&x),x>60?a[6]++:a[x/10]++;return 0;}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	ll n,i,ans;
	cin>>n;
	vector<ll> h(n);
	for(i=0;i<n;i++)
		cin>>h[i];
	ans=0;

	for(i=1;i<n;i++){
		if(h[i]<h[i-1]){
			ans=ans+h[i-1]-h[i];
			h[i]=h[i-1];
		}
	}
	cout<<ans<<endl;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<bool, int>> rec(n, { false,0 });
	for (int i = 0; i < m; i++) {
		int p;
		string s;
		cin >> p >> s;
		if (rec.at(p - 1).first == false) {
			if (s == "AC") {
				rec.at(p - 1).first = true;
			}
			else {
				rec.at(p - 1).second++;
			}
		}
	}
	int ans = 0;
	int penalty = 0;
	for (int i = 0; i < n; i++) {
		if (rec.at(i).first) {
			ans++;
			penalty += rec.at(i).second;
		}
	}
	cout << ans << " " << penalty << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define fout(x) cout << fixed << setprecision(10) << x << endl
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

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

  int n;
  cin >> n;
  VL a(n);
  map<ll, ll> mp1, mp2;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    mp1[i + a[i]]++;
    mp2[i - a[i]]++;
  }
  ll ans = 0;
  for(auto& m : mp1) {
    ans += m.second * mp2[m.first];
  }
  out(ans);
  return 0;
}


Measured memory_bytes: 39016
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;


int main(void){
   long long N,K;
   cin>>N>>K;
   vector<int> A(N);
   for(int i=0;i<N;i++){
      cin>>A[i];
      A[i]--;
   }
   int now=0;
   vector<int> count(N,0);
   long long roop_town,rest;
   bool flag=false;
   for(int i=0;i<K;i++){
      now=A[now];
      if(count[now]!=0){
         roop_town=i-count[now];
         rest=K-i-1;
         flag=true;
         break;
      }
      count[now]=i;
   }
   if(flag){
      rest=rest%roop_town;
      for(int j=0;j<rest;j++){
         now=A[now];
      }
   }
   cout<<now+1<<endl;
   return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;
int a[N];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        k += abs(a[i] - a[i - 1]);
    }
    k += abs(a[n]);
    for (int i = 1; i <= n; ++i) {
        cout << k - abs(a[i] - a[i - 1]) -
                abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]) << endl;
    }
    return 0;
}


Measured memory_bytes: 4036
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n  = sc.nextInt();
    int a  = sc.nextInt()-1;
    int b  = sc.nextInt()-1;
    int c  = sc.nextInt()-1;
    int d  = sc.nextInt()-1;
    String S  = sc.next();
    char[] s = S.toCharArray();
   
    if(s[c] == '#' || s[d] == '#'){
      System.out.println("No");
      return;
    }
    
    if(c < d){
      for(int i = a; i < d; i++){
        if(s[i] == '#' && s[i-1] == '#'){
          System.out.println("No");
          return;
        }
      }
      System.out.println("Yes");
      return;
    }else{
      for(int i = a; i < c; i++){
        if(s[i] == '#' && s[i-1] == '#'){
          System.out.println("No");
          return;
        }
      }
      String tmp = S.substring(b-1,d+2);//ふぬけが動く範囲
        if(tmp.contains("...")){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
    }   
  }
}

Measured memory_bytes: 40948
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	Deque<Character> deque = new ArrayDeque<>();
	boolean isInv = false;
	List<Query> queries = new ArrayList<>();

	static class Query {
		int T, F;
		Character C;

		Query(String line) {
			String[] tokens = line.split(" ");
			T = Integer.parseInt(tokens[0]);
			if (T == 2) {
				F = Integer.parseInt(tokens[1]);
				C = tokens[2].charAt(0);
			}
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String S = in.readLine();
		for (int i = 0; i < S.length(); ++i) {
			deque.add(S.charAt(i));
		}
		int Q = Integer.parseInt(in.readLine());
		for (int i = 0; i < Q; ++i) {
			queries.add(new Query(in.readLine()));
		}
	}

	void calc() {
		for (int i = 0; i < queries.size(); ++i) {
			Query query = queries.get(i);
			if (query.T == 1) {
				isInv = !isInv;
			} else {
				if (!isInv) {
					// そのままの評価
					if (query.F == 1) {
						deque.addFirst(query.C);
					} else {
						deque.addLast(query.C);
					}
				} else {
					// 逆の評価
					if (query.F == 1) {
						deque.addLast(query.C);
					} else {
						deque.addFirst(query.C);
					}
				}
			}
		}
	}

	void showResult() {
		StringBuilder strBuilder = new StringBuilder();
		while (!deque.isEmpty()) {
			if (!isInv) {
				strBuilder.append(deque.pollFirst());
			} else {
				strBuilder.append(deque.pollLast());
			}
		}
		System.out.println(strBuilder.toString());
	}

}


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

bool dfs1(int v, int prev, vector<vector<int>>& g, vector<bool>& visited, vector<bool>& f) {
    visited[v] = true;
    bool res = false;
    for(auto to : g[v]) {
        if(to == prev) {
            continue;
        }
        if(visited[to]) {
            res = true;
        } else {
            res |= dfs1(to, v, g, visited, f);
        }
    }
    return f[v] = res;
}

int dfs2(int v, vector<vector<int>>& g, vector<bool>& f, int sum, vector<int> const& w) {
    sum += w[v];
    f[v] = true;
    int res = sum;
    for(auto to : g[v]) {
        if(!f[to]) {
            res = max(res, dfs2(to, g, f, sum, w));
        }
    }
    return res;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> w(N);
    for(int i=0; i<N; ++i) {
        cin >> w[i];
    }
    vector<vector<int>> g(N);
    for(int i=0; i<M; ++i) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<bool> visited(N);
    vector<bool> f(N);
    dfs1(0, -1, g, visited, f);
    int res = 0;
    for(int i=0; i<N; ++i) {
        if(f[i]) {
            res += w[i];
        }
    }
    int ma = 0;
    for(int i=0; i<N; ++i) {
        if(!f[i]) {
            ma = max(ma, dfs2(i, g, f, 0, w));
        }
    }
    cout << res + ma << endl;
}


Measured memory_bytes: 19740
from bisect import bisect_right
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline


n, t = map(int, input().split())

shop = []
shop_a0 = []

for i in range(n):
    a, b = map(int, input().split())
    if a != 0:
        shop.append([a, b, a/(b+1)])
    else:
        shop_a0.append(b)

shop = sorted(shop, key=lambda x: -x[2])
shop_a0 = sorted(shop_a0)

n = len(shop)

INF = 10**10
dp = [INF for _ in range(30)]
dp[0] = 0

m = min(n+1, 30)

for i in range(n):
    for j in range(m)[::-1]:
        dp[j] = min(dp[j], dp[j-1] + 1 +
                         shop[i][0]*(dp[j-1]+1) + shop[i][1])

ss = []
if shop_a0:
    ss.append(1+shop_a0[0])
    for i in range(1, len(shop_a0)):
        ss.append(ss[-1]+1+shop_a0[i])

ans = 0

for i in range(m):
    if t - dp[i] >= 0:
        ans = max(ans, bisect_right(ss, t-dp[i]) + i)

print(ans)


Measured memory_bytes: 92544
#include <iostream>
#include <vector>
#include <cmath>

int state_circles(const std::vector<double> &a, const std::vector<double> &b){
	double d;
	d = sqrt(pow(a[0] - b[0], 2) + pow(a[1] - b[1], 2));
	if((a[2] + b[2]) < d)
		return 0;
		if(std::abs(a[2] - b[2]) > d){
		if(a[2] > b[2])
			return 2;
		else 
			return -2;
	}
	
	else 
		return 1;
}

int main(){
	std::vector<double> a(3), b(3);
	int data_num;
	std::cin >> data_num;
	for(int i = 0; i < data_num; ++i){ 
		std::cin >> a[0] >> a[1] >> a[2] >> b[0] >> b[1] >> b[2];
		std::cout << state_circles(a, b) << std::endl;
	}
	
	return 0;
}
			

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define N 1005
using namespace std;
int n;
int A[N][N];
queue<int>Q[N];
int mark[N];
void solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<n;j++){
			scanf("%d",&A[i][j]);
			Q[i].push(A[i][j]); 
		}
	memset(mark,0,sizeof(mark));
	for(int i=1;i<=n;i++){
		int x=Q[i].front();
		int y=Q[x].front();
		if(i==y)mark[i]=mark[x]=1;
	}
	queue<int>inQ;
	for(int i=1;i<=n;i++)
		if(mark[i]==1)Q[i].pop(),inQ.push(i),mark[i]=0;
	int ans=1;
	queue<int>M;
	while(1){
		int f=1;
		while(!inQ.empty()){
			int x=inQ.front();
			inQ.pop();
			if(Q[x].empty())continue;
			int y=Q[x].front();
			if(Q[y].empty())continue;
			int z=Q[y].front();
			if(mark[x]||mark[y]||x!=z){
				continue;
			}else{
				mark[x]=mark[y]=1;
				M.push(x),M.push(y);
				f=0;
			}
		}
		while(!M.empty()){
			int x=M.front();M.pop();
			mark[x]=0;Q[x].pop();inQ.push(x);
		}
		if(f==1)break;
		ans++;
	}
	for(int i=1;i<=n;i++){
		if(!Q[i].empty()){
			puts("-1");
			return;
		}
	}
	printf("%d\n",ans);
}
int main(){
    solve();
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
int pos[1000000];

int main(){
  int n, m;
  int num, res;
  int pre, cur;
  while(cin >> n >> m && (n || m)){
    pos[1] = 0;
    res = 0;
    pre = 1;
    rep(i, n-1){
      cin >> num;
      pos[i+2] = pos[i+1] + num;
    }
    rep(i, m){
      cin >> cur;
      res = (res + max(pos[pre + cur] - pos[pre], pos[pre] - pos[pre + cur])) % 100000;
      pre += cur;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1228