akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll N) {
  cout << (N-2)*180 << endl;
}

int main() {
  ll N;
  cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  ll N;
  cin >> N;
  vector<vector<ll>> A(N, vector<ll>(N));
  rep(i, N){
    rep(j, N){
      cin >> A.at(i).at(j);
    }
  }
  set<pair<ll, ll>> S;
  rep(i, N){
    rep2(j, i+1, N){
      S.insert(make_pair(i, j));
    }
  }
  rep(k, N){
    rep(i, N){
      rep2(j, i+1, N){
        if(k == i || k == j){
          continue;
        }
        if(A.at(i).at(j) > A.at(i).at(k)+A.at(k).at(j)){
          cout << -1 << endl;
          return 0;
        }
        if(A.at(i).at(j) == A.at(i).at(k)+A.at(k).at(j)){
          S.erase(make_pair(i, j));
        }
      }
    }
  }
  ll ans = 0;
  for(auto x : S){
    ans += A.at(x.first).at(x.second);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3712
#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; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    ll a,b,c=0,d=0,n=0;
    //VI a(N);
    string s,s1,s2;
    cin >> s; 
    for(int i=0; i < s.size();i++){
        if(s[i] == 'B' && !s1.empty()){
            s1.pop_back();
        }
        else if (s[i] == 'B' && s1.empty()) {
            continue;
        }
        else {
            s1.push_back(s[i]);
        }
    }
    cout << s1 << endl; 
    return 0;
}


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

int main(){
  int n,f;
  cin >> n;
  int p = 0;
  string s;
  cin >> s;
  while(true){

     f = s.find("ABC");
     if(f==-1){break;}
     p++;
     s.at(f) = 'z';
  }

  cout << p << endl;
}

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

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

  vector<int> dist(N, -1);
  int addedCount = 0;
  vector<bool> added(N);
  vector<int> list;
  int temp = 1;
  while (!added[temp]) {
    added[temp] = true;
    addedCount += 1;
    dist[temp] = 0;
    list.push_back(temp);
    temp = (temp * 10) % N;
  }

  int tempDist = 0;
  while (addedCount < N) {
    tempDist += 1;
    vector<int> tempList;
    for (int i = 0; i < list.size(); i++) {
      temp = (list[i] + 1) % N;
      while (!added[temp]) {
        added[temp] = true;
        addedCount += 1;
        dist[temp] = tempDist;
        tempList.push_back(temp);
        temp = (temp * 10) % N;
      }
    }

    list = tempList;
  }

  cout << dist[0] + 1 << endl;

  return 0;
}

Measured memory_bytes: 1564
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    long long int sum=0,i,n;
    for(i=0;i<s.size();i++)
    {
        sum+=(s[i]-'0');
    }
    if(sum%9==0)
        cout<<"Yes";
    else
        cout<<"No";
}    
        
 
       


Measured memory_bytes: 3720
#include<iostream>
#include<algorithm>
#include<cmath>
#define INF 1<<28
using namespace std;

int a[222], b[222], c[222];
int d, n;
int t[222];
int memo[222][222];
int fulele;

int solve(int p, int q){
  if(p == d-1) return 0;
  if(memo[p][q]) return memo[p][q];
  
  int ret = -INF;
  for(int i=0;i<n;i++) 
    if(a[i] <= t[p+1] && t[p+1] <= b[i])
      ret = max(solve(p+1, i)+abs(c[q]-c[i]), ret);
  
  return memo[p][q] = ret;
}

int main(){
  
  cin >> d >> n;
  for(int i=0;i<d;i++) cin >> t[i];
  for(int i=0;i<n;i++) cin >> a[i] >> b[i] >> c[i];
  
  int ans = -INF;
  for(int i=0;i<n;i++)
    if(a[i] <= t[0] && t[0] <= b[i])
      ans = max(solve(0, i), ans);
  
  cout << ans << endl;
}

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

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

using namespace std;

int main() {

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

    int N, X, Y;
    cin >> N >> X >> Y;

    vector<int> result(N, 0);

    FOR(i, 1, N) FOR(j, i + 1, N + 1) {
        int d = min(j - i, min(abs(i - X), abs(i - Y)) + min(abs(j - X), abs(j - Y)) + 1);
        ++result[d];
    }

    FOR(i, 1, N) {
        cout << result[i] << '\n';
    }
    cout << flush;

    return 0;
}


Measured memory_bytes: 256
/*

  _|_|                              _|  _|    _|
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|
_|    _|  _|_|          _|          _|  _|_|
_|    _|  _|          _|      _|    _|  _|  _|
  _|_|    _|        _|_|_|_|    _|_|    _|    _|

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
typedef long long ll;
const int maxn=4e5+1000;
const int inf=1e9+100;
using namespace std;
vi E[maxn],inset[maxn];
int s=2e5+1,t=2e5+2,cnt=1,head[maxn];
struct gg{
    int u,v,w,next;
}side[maxn*2];
void ins(int u,int v,int w) {
    side[++cnt]=(gg){u,v,w,head[u]};head[u]=cnt;
    side[++cnt]=(gg){v,u,0,head[v]};head[v]=cnt;
}
int rk[maxn],cur[maxn];
queue<int>q;
bool bfs() {
    memset(rk,0,sizeof(rk));rk[s]=1;
    while(!q.empty())q.pop();q.push(s);
    while(!q.empty()) {
        int u=q.front();q.pop();
        for(int i=head[u];i;i=side[i].next) {
            int v=side[i].v;if(rk[v]||!side[i].w)continue;
            rk[v]=rk[u]+1;
            q.push(v);
        }
    }
    if(!rk[t])return 0;
    return 1;
}
int dfs(int u,int flow) {
    if(u==t||!flow)return flow;
    int tot=0;
    for(int &i=cur[u];i;i=side[i].next) {
        int v=side[i].v;//cout<<v<<' '<<rk[v]<<endl;
        if(rk[v]!=rk[u]+1||!side[i].w)continue;
        int sent=dfs(v,min(flow,side[i].w));
        side[i].w-=sent;side[i^1].w+=sent;
        flow-=sent;tot+=sent;
    }
    return tot;
}
int dinic(){
    int maxflow=0;
    while(bfs()){
        memcpy(cur,head,sizeof(cur));
        maxflow+=dfs(s,inf);
    }
    return maxflow;
}
int match[maxn];//match[set_id]=match_point_id
bool inq[maxn];
pii ans[maxn];
int main(){
    //ios::sync_with_stdio(0);
    int n;scanf("%d",&n);//cin>>n;
    rep(i,1,n-1) {
        int c;scanf("%d",&c);//cin>>c;
        rep(j,1,c) {
            int u;scanf("%d",&u);//cin>>u;
            E[i].pb(u);inset[u].pb(i);
            ins(u,n+i,1);
        }
    }
    rep(i,2,n)ins(s,i,1);
    rep(i,1,n-1)ins(n+i,t,1);
    int flow=dinic();
    if(flow!=n-1) {
        printf("-1\n");//cout<<"-1";
        return 0;
    }
    rep(i,n+1,n+n-1) {
        for(int j=head[i];j;j=side[j].next) {
            int v=side[j].v;
            if(v<=n&&side[j].w) {
                match[i-n]=v;break;
            }
        }
    }
    while(!q.empty())q.pop();
    int tot=1;q.push(1);inq[1]=1;
    while(!q.empty()) {
        int u=q.front();q.pop();
        for(int i=0;i<inset[u].size();i++) {
            int setid=inset[u][i],set_match=match[setid];
            if(!inq[set_match]) {
                inq[set_match]=1;ans[setid]=mk(u,set_match);
                q.push(set_match);tot++;
            }
        }
    }
    if(tot!=n) {
        printf("-1\n");//cout<<"-1";
        return 0;
    }
    for(int i=1;i<n;i++) {
        printf("%d %d\n",ans[i].fi,ans[i].se);
        //cout<<ans[i].fi<<' '<<ans[i].se<<endl;
    }
    return 0;
}

Measured memory_bytes: 52780
#include <iostream>
#include <vector>
#include <algorithm>
#include <cinttypes>
#include <string>

using namespace std;

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

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

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

  sort(begin(a), end(a));
  sort(begin(b), end(b));

  vector<int> intersect;

  set_intersection(begin(a), end(a), begin(b), end(b), back_inserter(intersect));

  if (intersect.size() == b.size()) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
set<ll> divisor(ll n) {
  set<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.insert(i);
      if (i != n / i) res.insert(n / i);
    }
  }
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll k; cin>>k;
  vll a(k);
  rep(i,k) cin>>a[i];
  reverse(all(a));
  
  ll l=2, r=2;
  rep(i,k){
    l=(l+a[i]-1)/a[i];
    r=r/a[i];
    if(l>r){
      cout<<-1<<endl;
      return 0;
    }
    l=l*a[i];
    r=r*a[i]+a[i]-1;
  }
  cout<<l<<" "<<r<<endl;
}

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

int main(){
  long long A,B,K,i;
  cin >> A >> B >> K;

  if(A>=K)
  A -= K;
  else if(A<K){
    K -= A;
    A = 0;
    if(B<K)
    B = 0;
    else
    B -= K;
  }
  cout << A << " " << B << endl;
}


Measured memory_bytes: 256
# N = gets.chomp.to_i
# A, B, C = gets.chomp.split.map(&:to_i)
S = gets.chomp.chars
N = S.size + 1

# We use queue
DP = Array.new(N, -1)  # A

if S[0] == '<'
  DP[0] = 0
end
if S[N-2] == '>'
  DP[N-1] = 0
end

1.upto(N-2).each do |i|
  if (S[i-1] == '>' && S[i] == '<')
    DP[i] = 0
  end
end

# Set number from left
1.upto(N-2).each do |i|
  next if DP[i-1] == -1

  if (S[i-1] == '<' && S[i] == '<')
    DP[i] = DP[i-1] + 1
  end
end

# Set number from right
(N-2).downto(1).each do |i|
  next if DP[i+1] == -1

  if (S[i-1] == '>' && S[i] == '>')
    DP[i] = DP[i+1] + 1
  end
end

if S[0] == '>'
  DP[0] = DP[1] + 1
end
if S[N-2] == '<'
  DP[N-1] = DP[N-2]+1
end

# Set < >
1.upto(N-2).each do |i|
  if (S[i-1] == '<' && S[i] == '>')
    DP[i] = [DP[i-1], DP[i+1]].max + 1
  end
end

# For Debug
# p DP

ans = 0
0.upto(N-1).each do |i|
  ans += DP[i]
end

p ans


Measured memory_bytes: 51376
#include<bits/stdc++.h>
using namespace std;
# ifdef DEB
# define debug(...) fprintf(stderr, __VA_ARGS__)
# else
# define debug(...)
#endif
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LL long long
#define LD long double
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define pb pop_back
#define VI vector<int> 
#define VPI vector<PII> 
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define ALL(x) (x).begin(), (x).end()
#define siz(V) ((int)V.size())
const int M = 100005;

int n, m;
int start;
vector<int> V[M];
bool vis[M];
vector<int> R[2];

void DFS(int v, int ind)
{
  vis[v] = true;
  R[ind].PB(v);
  for (int i = 0; i < siz(V[v]); i++)
  {
    if (!vis[V[v][i]])
    {
      DFS(V[v][i], ind);
      return;
    }
  }
  return;
}

int main()
{
  //ios_base::sync_with_stdio(0);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++)
  {
    int a, b;
    scanf("%d%d", &a, &b);
    V[a].PB(b);
    V[b].PB(a);
  }
  DFS(1, 0);
  DFS(1, 1);
  printf("%d\n", siz(R[0]) + siz(R[1]) - 1);
  for (int i = siz(R[0]) - 1; i > 0; i--)
  {
    printf("%d ", R[0][i]);
  }
  for (int i = 0; i < siz(R[1]); i++)
  {
    printf("%d ", R[1][i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 9720
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <math.h>
#include <iterator>
using namespace std;

int main() {
	short mountain[10] = {0};
	for (short i = 0;i < 10;++i) {
		scanf("%d", &mountain[i]);
	}
	sort(mountain, mountain + 10,greater<short>());
	for (short i = 0;i < 3;++i) {
		printf("%d\n", mountain[i]);
	}
}


Measured memory_bytes: 1044
N,K=gets.split.map(&:to_i)
as=gets.split.map(&:to_i)
dp=Array.new(64){Array.new(2,-Float::INFINITY)}
dp[0][0]=0
63.times do |i|
    st=0
    as.each do |e|
        st+=1 if (e & 1<<(62-i)) != 0
    end
    # p [st,N-st,1<<(62-i)]
    if K[62-i]==0
        dp[i+1][0]=dp[i][0]+st*(1<<(62-i))
    else
        dp[i+1][0]=dp[i][0]+(N-st)*(1<<(62-i))
        dp[i+1][1]=dp[i][0]+st*(1<<(62-i))
    end
    jd=dp[i][1]+[N-st,st].max*(1<<(62-i))
    dp[i+1][1]=dp[i+1][1]<jd ? jd : dp[i+1][1]
end
# pp dp
puts dp[63].max

Measured memory_bytes: 11404
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main() {
	int K, X;
	cin >> K >> X;

	vector<int>vec(2 * K);


	int N = (2 * K) - 1;
	int M = X - K + 1;

	for (int i = 0; i < N; i++) {
		vec[i] = M + i;
	}

	for (int i = 0; i < N; i++) {
		cout << vec[i] << ' ';
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,a[N],c[N],b[N],d[N],idx,h[N],ne[N<<1],e[N<<1],w[N<<1];
void add(int a,int b,int c){e[idx]=b;ne[idx]=h[a];w[idx] =c;h[a]=idx ++;}
bool vis[N],use[N];
int lowb(int x)
{
    return lower_bound(d+1,d+1+n,x)-d;
}
int uppb(int x)
{
    return upper_bound(d+1,d+1+n,x)-d;
}
bool dfs(int u)
{
    vis[u]=true;
    int x=c[u];
    for(int i=h[u];~i;i=ne[i])
    {
        int v=e[i];
        if(!vis[v]&&dfs(v))
        {
            x^=1;use[w[i]]=true;
        }
    }
    return x;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i = 0 ;i < N ;i ++) h[i] = -1 ;
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i],&b[i]),d[i]=a[i];
    sort(d+1,d+1+n);
    for(int i=1;i<=n;i++)
        a[i]=lowb(a[i]),c[a[i]]=b[i];
    for(int i=n+1;i>=1;i--)
        c[i]^=c[i-1];
    for(int i=1;i<=m;i++)
    {
        int l,r;scanf("%d%d",&l,&r);
        l=lowb(l);
        r=uppb(r)-1;
        if(l<=r)
            add(l,r+1,i),add(r+1,l,i);
    }
    for(int i=1;i<=n+1;i++)
        if(!vis[i]&&dfs(i))
    {
        printf("-1\n");return 0;
    }
    int ans=0;
    for(int i=1;i<=m;i++)
        if(use[i]) ans++;
    printf("%d\n",ans);
    for(int i=1;i<=m;i++)
    if(use[i])
        printf("%d ",i);
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  string s;
  cin >> s;
  bool ok = true;
  ok = s[0] != s[1] || s[0] != s[2] || s[1] != s[2];
  print(ok ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n;
int a[200000+10],b[200000+10];
priority_queue<mp/*val,index*/> Q;
int main(){
	scanf("%d",&n);
	rb(i,1,n) scanf("%d",&a[i]);
	rb(i,1,n){
		scanf("%d",&b[i]);
		if(b[i]<a[i]){
			puts("-1");
			return 0;
		}
	} 
	b[0]=b[n],b[n+1]=b[1];
	a[0]=a[n],a[n+1]=a[1];
	rb(i,1,n) if(b[i]!=a[i]) Q.push(II(b[i],i));
	LL res=0;
	while(!Q.empty()){
		mp tmp=Q.top();
		int now=tmp.SEC;
		Q.pop();
		LL min2=max(b[now+1],b[now-1]);
		if(b[now]<min2){
			puts("-1");
			return 0;
		}
		min2=b[now]-min2;
		int has=b[now+1]+b[now-1];
		min2=min2/has+1;
		int OKOK=0;
		if(min2*has>=b[now]-a[now]){
			if((b[now]-a[now])%has!=0){
				puts("-1");
				return 0; 
			} 
			else{
			 	res+=(b[now]-a[now])/has;
				b[now]=a[now];
			 	if(now==1) b[n+1]=b[1];
				if(now==n) b[0]=b[n];
				OKOK=1;
			}
		}
		if(OKOK) continue;
		b[now]-=min2*has;
		res+=min2;
		if(now==1) b[n+1]=b[1];
		if(now==n) b[0]=b[n];
		if(b[now]<=0){
			puts("-1");
			return 0;
		}
		if(b[now]!=a[now]) Q.push(II(b[now],now));
	}
	rb(i,1,n){
		if(b[i]!=a[i]){
			puts("-1");
			return 0;
		}
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	set<int> st;
	REP(i, n)
	{
		int a; cin >> a;
		if (st.count(a)) st.erase(a);
		else st.insert(a);
	}
	cout << st.size() << endl;
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(v) (v).begin(), (v).end()
const int M=1e6+7;


int main() {
    
 int n,l;
 cin>>n>>l;
 vector<int> ans;
 int tot=0;
 for(int i=0;i<n;i++)
    ans.pb(l+i),tot+=l+i;
    int f=1e8;
    for(auto i:ans)
    {
        if(abs(i)<abs(f))
            f=i;
    }
    cout<<tot-f;
}



Measured memory_bytes: 256
from collections import deque
k=int(input())
q=deque(list(range(1, 10)))
ans,x,y=0,0,0
for i in range(k):
  ans=q.popleft()
  y=ans%10
  x=ans*10+y
  if y != 0:
    q.append(x-1)
  q.append(x)
  if y != 9:
    q.append(x+1)
print(ans)


Measured memory_bytes: 40688
def solve(n, k):
    if k == 1:
        return 0
    else:
        u = n - (k - 1)
        return u - 1

assert solve(3, 2) == 1
assert solve(8, 5) == 3

if __name__ == '__main__':
    (n, k) = map(int, raw_input().split())
    print solve(n, k)




Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i =0; i < n ;i++)
using namespace std;
int v[500][500];
int p[500];

int main(){
    int N;
    cin >> N;
    int n = 1;
    int t = 2;
    
    
    while(n < 100001){
        if(n==N)
        {

            
            cout << "Yes" <<endl;
            cout << t << endl;
            int val=1;
            for(int i =0; i < t ;i++){
                for(int j =i+1; j < t ;j++){
                    v[i][p[i]] = val;
                    p[i]++;
                    v[j][p[j]] = val;
                    p[j]++;
                    val++;
                }
            }
            for(int i =0; i < t ;i++){

                cout << t-1;
                for(int j =0; j < t-1  ;j++){
                    cout  << " " << v[i][j];
                }
                cout << endl;
            }

            return 0;
        }
        n += t;
        t +=1;
        //cout << n << " "<<t<< " ";
        
    } 
    cout << "No" <<endl;

    return 0;

   
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  ll mod;
  cin >> n >> mod;
  vector<ll> dp(n+1);
  dp[n] = 1;
  for (int i = 1; i < n; i++) {
    int w = 1-max(1-i, i-n);
    for (int j = n-w; j >= 0; j--) {
      (dp[j] += dp[j+w]) %= mod;
    }
  }
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    (ans += dp[i]*i) %= mod;
  }
  cout << (ans+mod)%mod << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

const int MAX_Q = 55;

int N, M, Q;
int A[MAX_Q], B[MAX_Q], C[MAX_Q], D[MAX_Q];

int calc(vi &xs) {
    int ret = 0;
    REP (i, Q) {
        if (xs[B[i]] - xs[A[i]] == C[i]) ret += D[i];
    }
    return ret;
}

int dfs(vi &xs) {
    int sz = xs.size();
    if (sz == N+1) {
        return calc(xs);
    }
    int ret = 0;
    FOR (x, xs[sz-1], M+1) {
        xs.push_back(x);
        CHMAX(ret, dfs(xs));
        xs.pop_back();
    }
    return ret;
}

int solve() {
    vi xs;
    xs.push_back(1);
    return dfs(xs);
}

int main() {
    cin >> N >> M >> Q;
    REP (q, Q) cin >> A[q] >> B[q] >> C[q] >> D[q];
    cout << solve() << endl;
}

Measured memory_bytes: 3616
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T, T) { (args[0], args[1], args[2]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let (n, a, b) = toTuple(readInts())
let ans = (1...n).map {
  var sum = 0
  for c in String($0) { sum += Int(String(c))! }
  if sum >= a && sum <= b { return $0 }
  else { return 0 }
}.reduce(0, +)
print(ans)

Measured memory_bytes: 13692
input()
paper_values = list(map(int, input().split()))
is_approved = True

for val in paper_values:
    if val % 2 != 0:
        continue

    if val % 3 == 0:
        continue

    if val % 5 == 0:
        continue

    is_approved = False

print("APPROVED" if is_approved else "DENIED")

Measured memory_bytes: 3060
import java.util.Scanner;

class Main{
	public static void main(String arg[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.nextLine();
		String A1 = sc.nextLine();
		String A2 = sc.nextLine();
		sc.close();
		int max = 0;
		
		int[][] A = new int[2][N];
		
		for(int j = 0; j < N; j++) {
			String[] s1 = A1.split(" ");
			String[] s2 = A2.split(" ");
			A[0][j] = Integer.valueOf(s1[j]);
			A[1][j] = Integer.valueOf(s2[j]);
		}
		
		for(int j = 0; j < N; j++) {
			max = Math.max(max, candies(j, A));
		}
		System.out.println(max);
	}
	
	public static int candies(int down,int A[][]) {
		int count = 0;
		for(int i = 0; i <= down; i++) {
			count += A[0][i];
		}
		for(int i = down; i < A[0].length; i++) {
			count += A[1][i];
		}
		return count;
	}
}

Measured memory_bytes: 23892
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include <string.h>
#include <math.h>
#include <unordered_map>
using namespace std;

unordered_map<int, int> a;

int main()
{
	int n,tmp,count=0;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		int c = 1;
		if (a.find(tmp) != a.end())c = a[tmp]+1;
		a[tmp] = c;
	}

	for (unordered_map<int, int>::iterator it=a.begin(); it != a.end(); ++it) {
		int f=it->first, s=it->second;

//		cout << f << " " << s << endl;
		if (f > s) count += s;
		if (f < s) count += (s - f);
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    int X, Y;
    cin >> X >> Y;
    int ans = 0;
    map<int, int> m;
    m[3] = 100000;
    m[2] = 200000;
    m[1] = 300000;
    ans += m[X];
    ans += m[Y];
    if (X == 1 && Y == 1) {
        ans += 400000;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>
#include<chrono>
#include<random>

#define for0(i, N)    for (long long i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (long long i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (long long i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (long long i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (long long i = (x), a = 0; a < (N);    \
                              i = (i + 1) % (N), ++a)
#define int long long

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

long long constexpr inf = std::numeric_limits<long long>::max();

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


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

    ll n, m;

    cin >> n >> m;

    vll a(m);
    ll sum = 0;
    for0(i, m)cin >> a[i], sum +=a[i];

    cout << (n - sum >= 0 ? n - sum : -1) << "\n";





    return 0;
}


Measured memory_bytes: 3740
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <string>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define lrep(i, n, m) for(int i = n; i < m; i++)

typedef long long ll;
const int MAX = INT_MAX;


int main()
{	
	int n;
	cin >> n;
	string s;
	cin >> s;
	
	if (n <= 3) {
		cout << 0 << endl;
		return 0;
	}
	
	ll r = 0, g = 0, b = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R')  r++;
		else if (s[i] == 'G') g++;
		else  b++;
	}

	ll ans = r * g * b;

	int t;
	for (int i = 0; i < n; i++) {
		for (int j = 1; i + j * 2 < n; j++) {
			t = 2 * j;
			if (s[i] != s[i + j] && s[i + j] != s[i + t] && s[i] != s[i + t])  ans--;
		}
	}

	cout << ans << endl;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> B(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> B.at(i);
  }

  int result = B.at(0);
  for (int i = 1; i < N - 1; i++) {
    result += min(B.at(i - 1), B.at(i));
  }
  result += B.at(N - 2);

  cout << result << endl;
}

Measured memory_bytes: 256
<?php
ini_set("memory_limit", "-1");

$input = STDIN;

$n = (int)trim(fgets($input));

$keys = array_fill(0, 2000000, 0);
$head = 1;
$tail = 0;

for ($i = 0; $i < $n; $i++) {
    $command = trim(fgets($input));

    if ($command[0] == "i") {
        $keys[$head++] = substr($command, 7);
    } else {
        switch ($command[6]) {
            case "F":
                --$head;
                break;
            case "L":
                ++$tail;
                break;
            default:
                $x = substr($command, 7);
                $keys[$tail] = $x;
                $idx = $head;
                while ($keys[--$idx] != $x) {}
                if ($idx != $tail) {
                    if ($idx - $tail < $head - $idx) {
                        ++$tail;
                        for ($j = $idx; $j > $tail; $j--) {
                            $keys[$j] = $keys[$j-1];
                        }
                    } else {
                        --$head;
                        for ($j = $idx; $j < $head; $j++) {
                            $keys[$j] = $keys[$j+1];
                        }
                    }
                }
        }
    }
}

$reversed_keys = array_slice($keys, $tail + 1, $head - $tail - 1);
print implode(" ", array_reverse($reversed_keys)) . "\n";


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

int N, K, X[66], Y[66], C[66]; double R[66];

bool chk(double r)
{
	for (int i = 0; i < N; i++) R[i] = r / C[i];

	double per = 2 * acos(-1.0);
	for (int i = 0; i < N; i++){
		int base = 1;
		vector<pair<double, int> > stop;
		for (int j = 0; j < N; j++) if (i != j){
			double dist = hypot(X[i] - X[j], Y[i] - Y[j]);
			if (dist >= R[i] + R[j]) continue;
			if (R[i] >= R[j] && dist <= R[i] - R[j]) continue;
			if (R[i] <= R[j] && dist <= R[j] - R[i]){ base++; continue; }

			double dir = atan2(Y[j] - Y[i], X[j] - X[i]);
			double rng = acos((R[i] * R[i] + dist * dist - R[j] * R[j]) / (2 * R[i] * dist));
			double st = dir - rng, ed = dir + rng;

			auto norm = [per](double &x){
				x = fmod(x, per);
				if (x < 0) x += per;
			};
			norm(st);
			norm(ed);

			stop.push_back({ st, +1 });
			if (ed < st){
				stop.push_back({ per, -1 });
				stop.push_back({ 0, +1 });
			}
			stop.push_back({ ed, -1 });
		}

		if (base >= K) return true;
		sort(stop.begin(), stop.end());
		for (auto &p : stop){
			base += p.second;
			if (base >= K) return true;
		}
	}
	return false;
}

int main()
{
	scanf ("%d %d", &N, &K);
	for (int i = 0; i < N; i++) scanf ("%d %d %d", &X[i], &Y[i], &C[i]);

	double l = 0, r = 1e6;
	for (int k = 0; k < 100; k++){
		double m = (l + r) / 2;
		if (chk(m)) r = m;
		else l = m;
	}

	printf ("%.12lf\n", r);
	return 0;
}

Measured memory_bytes: 3736
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m=map(int, readline().rstrip().split())
    hh=list(map(int, readline().rstrip().split()))
    good=[1]*n
    for i in range(m):
        a,b=map(int, readline().rstrip().split())
        a-=1
        b-=1
        if hh[a]<=hh[b]:
            good[a]=0
        if hh[b]<=hh[a]:
            good[b]=0
    print(sum(good))

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 27376
# -*- coding: utf-8 -*-

import math
from decimal import Decimal

def main():
     a, b, c = map(int, input().split())

     # √a + √b < √c
     # (√a + √b)^2 < c
     # a + 2√ab + b < c
     # 2√ab < c - (a + b)

     ab_sqrt = Decimal(a * b).sqrt()
     if ab_sqrt * 2 < (c - (a + b)):
          print('Yes')
     else:
          print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 5204
n,m,x=[int(j) for j in input().split()]
l=[]
import numpy as np
for i in range(n):
    tmp=[int(j) for j in input().split()]
    l.append((tmp[0],np.array(tmp[1:])))
ans=10**18
import itertools
for i in itertools.product(range(2),repeat=n):
    tl=np.array([0]*m)
    tc=0
    for idx,j in enumerate(i):
        if j==1:
            c,ll=l[idx]
            tc+=c
            tl+=ll
    if len(tl[tl>=x])==m:
        ans=min(ans,tc)

if ans!=10**18:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 27184
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	int n;
	cin >> n;
	ll q = 1, ok = 0;
	for(int i = 1; i <= n; i ++)
	{
		ll x;
		cin >> x;
		if(!x)
		{
			return cout << 0, 0;
		}
		
		ll w = 1000000000000000000ll;
		if (q > w / x) {
		ok = 1;
		}
		else {
 	   q = q * x;
		}
	}
	if(ok)
	return cout << -1, 0;
	cout << q;





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int maxn = 200010;

int n,K;
int A[maxn];
int visited[maxn];
int ans;

void dfs(int x,int k, int d) {
	//cout << x << " " << k << " " << d << "\n";
	if (k == 0) {
		ans = x;
		return;
	}
	
	//if (k < 0) assert(false);
	
	if (d == -1) {
		dfs(A[x],k-1,-1);
	} else {
		if (visited[x]) {
			k %= (d - visited[x]);
			if (k == 0) {
				ans = x;
				return;
			} else {
				dfs(A[x],k-1,-1);		
			}
		} else {
			visited[x] = d;
			dfs(A[x],k-1,d+1);
		}
	}
}

int32_t main() {
	FAST
	cin >> n >> K;
	for (int i =1;i<=n;i++) {
		cin >> A[i];
	}
	
	dfs(1,K,0);
	cout << ans;
}







Measured memory_bytes: 6764
#D
N,K = map(int,input().split())
A = list(map(int,input().split()))

now = 1
visited = [-1]*N
visited[0] = 0
for i in range(N+1):
    new = A[now-1]
    if visited[new-1] == -1:
        visited[new-1] = i+1
        now = new
    else:
        f = visited[new-1]
        b = i+1
        break
        
if K <= N:
    now = 1
    for i in range(K):
        new = A[now-1]
        now = new
    print(now)
else:
    k = f + ((K-f)%(b-f))
    now = 1
    for i in range(k):
        new = A[now-1]
        now = new
    print(now)
    
        



Measured memory_bytes: 32256
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)

using pii = pair<int, int>;
using edge = pair<pii, int>;

const ll INF = 1LL << 60;
int n, m;
vector<edge> es;


ll dist(int s) {
    vector<ll> d(n, INF);
    d[s] = 0;
    bool updated = false;
    rep(k, n - 1) {
        for (auto&& e : es) {
            int src = e.first.first, dst = e.first.second;
            if (d[src] < INF && d[dst] > (d[src] + e.second)) {
                d[dst] = d[src] + e.second;
            }
        }
    }
    ll ret = d[n - 1];
    
    vector<int> neg(n, 0);
    rep(k, n) {
        for (auto&& e : es) {
            int src = e.first.first, dst = e.first.second;
            if (d[src] < INF && d[dst] > (d[src] + e.second)) {
                d[dst] = d[src] + e.second;
                neg[dst] = 1;
            }
            if (neg[src]) neg[dst] = 1;
        }
    }

    if (neg[n - 1]) return INF;
    return d[n - 1];
}

int main() {
    cin >> n >> m;
    rep(i, m) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        --a; --b;
        es.push_back(make_pair(make_pair(a, b), -c));
    }

    ll d = dist(0);
    if (d == INF)
        cout << "inf" << endl;
    else
        cout << -d << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a!=b&&a!=c&&b!=c){
	    printf("3\n");
	}
	if(a==b&&a==c&&b==c){
	    printf("1\n");
	}
	else if(a==b||a==c||b==c){
	    printf("2\n");
	}
	return 0;
}	

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


#define FOR(i,a,b) for(ll i = a ; i < b ; i++) // for i in range(a,b)
#define REP(i,n) for(ll i = 0 ; i < n ; i++) // for i in range(b)
#define FORD(i,a,b) for(ll i = a ; i > b ; i--) // for i in range(a,b,-1)
#define ALL(x) x.begin(),x.end()
#define debug(x) cerr << #x << ": " << x << '\n'

const int IINF = 1'001'001'001;
const ll INF = 1'001'001'001'001'001'001ll;
const int MOD = 1'000'000'007;


void solve(){
    int n,k; cin >> n >> k;
    vector<ll> al(n); REP(i,n) cin >> al[i];

    ll ng = 0;
    ll ok = 1e9+1;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng)/2;
        ll cnt = 0;
        for( ll a : al ){
            cnt += (a-1)/mid;
        }
        if(cnt <= k){
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
}

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


Measured memory_bytes: 4748
a, b, k = [int(x) for x in input().split()]
if a + k - 1 < b - k + 1:
    ans_list = list(range(a, a + k)) + list(range(b - k + 1, b + 1))
else:
    ans_list = list(range(a, b + 1))
for ans in ans_list:
    print(ans)

Measured memory_bytes: 3060
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    o, t, f = 0, 0, 0
    for a in A:
        if a % 4 == 0:
            f += 1
        elif a % 2 == 0:
            t += 1
        else:
            o += 1
    if t > 0:
        o += 1
    print('Yes' if o <= f + 1 else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 19728
def main():
    N, K = map(int, input().split())

    # TLE(N, K)
    editorial(N, K)


def editorial(N, K):
    """
    # https://twitter.com/tanakh/status/972832191863336960
    N = p*b + r (0 <= r < b)

    a固定: bが変わるので余りが変わるため意味なし
    b固定: aが変わっても余りは一定周期になる
        0%b, 1%b, 2%b, ..., (b-1)%b, b%b, (b+1)%b, ..., (pb-1)%b, pb%b, ..., (pb+r)%b
        0,   1,   2,   ..., (b-1),   0,   1,       ...,  b-1,      0,    ..., r
        余りの数列: (0...b-1)がp個 と 0...r
        ↓
        0...K-1, K...b-1
        b個の中にKより小さい数はK個
        よって, b - min(b, K) = max(b-K, 0)
    """
    ans = 0
    if K == 0:
        # 次のfor loop計算を0込みにせず、
        # 余り>=0つまりa*bのすべての組合せ数N*Nを返して終了でも良い
        ans -= N

    # 余り>=Kのため mod K+1から
    # K=0のとき、1-N loopよりN余分
    for b in range(K+1, N+1):
        # 0-Nまでの0込みのためN+1
        p, r = divmod(N+1, b)

        ans += p * (b - K) + max(0, r - K)

    print(ans)


def TLE(N, K):
    """
    1 <= a,b <= N <= 10^5
    a mod b >= K
    0 <= K <= N-1
    """
    # a < b: mod b = a, K <= a <= N
    ans = 0
    for a in range(K, N):
        b_pattern = N - a
        ans += b_pattern

    # a > b: mod b = x
    # K >= b: mod b = 0 or K< より
    # K < b < a <= N
    for a in range(K+2, N+1):
        for b in range(K+1, a):
            if a % b >= K:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
n=int(input())
t=list(map(int,input().split()))
a=list(map(int,input().split()))
t=[0]+t+[t[-1]]
a=[a[0]]+a+[0]
ans=1
#print(t,a)
for i in range(n):
    if t[i]<t[i+1]:
        if a[i+1]<t[i+1]:
            ans=0
            break
    if a[i]>a[i+1]:
        if t[i]<a[i]:
            ans=0
            break
    if t[-2]!=a[1]:
        ans=0
        break
    if t[i]==t[i+1] and a[i+1]==a[i+2]:
        ans=(ans*(min(t[i+1],a[i+1])))%(10**9+7)
print(ans)

Measured memory_bytes: 19376
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String str = sc.next();
      String a1 = str.substring(0,1);
      String a2 = str.substring(1,2);
      String a3 = str.substring(2,3);
      String a4 = str.substring(3,4);
      if(a1.equals(a2) && a3.equals(a4) && !(a1.equals(a3))) System.out.println("Yes");
      else if(a1.equals(a3) && a2.equals(a4) && !(a1.equals(a2))) System.out.println("Yes");
      else if(a1.equals(a4) && a2.equals(a3) && !(a1.equals(a2))) System.out.println("Yes");
      else System.out.println("No");
    }
}


Measured memory_bytes: 21844