akhauriyash/Code-Regression huggingface dataset:
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif
using namespace std;

bool ok = true;
const size_t SIZE = 5000;
V<ll> edges[SIZE];
ll X[SIZE];

PLL dfs(ll cur) {
    bitset<SIZE + 10> bs;
    bs.set(0, 1);
    ll sum = 0;
    for(ll nxt : edges[cur]) {
        ll a, b;
        tie(a, b) = dfs(nxt);
        if(!ok) return PLL();
        sum += a + b;
        bs = (bs << a) | (bs << b);
    }
    for(ll i = SIZE; 0 <= i; i--) {
        if(!bs.test(i)) continue;
        if(X[cur] < i) continue;
        return PLL(X[cur], sum - i);
    }
    ok = false;
    return PLL();
}

int main() {
    ll N;
    cin >> N;
    for(ll i = 1; i < N; i++) {
        ll c = i;
        ll p;
        cin >> p;
        edges[p - 1].push_back(c);
    }
    for(ll i = 0; i < N; i++) cin >> X[i];
    dfs(0);
    if(!ok) cout << "IM";
    cout << "POSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<sstream>
#include<stack>
#include<cmath>
using namespace std;
int main()
{
    int a,b;
    stack <int>s;
    string chs;
    while(cin>>chs)
    {
        //cout<<chs;
        if(chs=="+")
        {
            a=s.top();
            s.pop();
            b=s.top();

            s.pop();
            s.push(a+b);
            //cout<<a<<b;
        }
        else if(chs=="-")
        {
            a=s.top();
            s.pop();
            b=s.top();

            s.pop();
            s.push(b-a);
            //cout<<a<<b;
        }
        else if(chs=="*")
        {
            a=s.top();
            s.pop();
            b=s.top();

            s.pop();
            s.push(a*b);
            //cout<<a<<b;
        }
        else
        {
            stringstream ss;
            int temp;
            ss<<chs;
            ss>>temp;
            s.push(temp);
        }
        if(cin.get()=='\n')
            break;
    }
    cout<<s.top()<<endl;
    return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;

struct union_find {
    vector<int> data;

    union_find(int size) {data.resize(size,-1);}

    int find(int x) {
        if (data[x] < 0) return x;
        return data[x] = find(data[x]);
    }

    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) {return false;}
        if (data[x] > data[y]) swap(x,y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int size(int x) {return -data[x];}
};

template<class T> 
struct edge {int from, to; T cost;};

template<class T>
T kruskal(vector<edge<T>> &edges, int V) {
    sort(edges.begin(),edges.end(),[](const edge<T> &edge1, const edge<T> &edge2) {
        return edge1.cost < edge2.cost;}
    );
    union_find uf(V);
    T res = 0;
    for (edge<T> &e: edges) if (uf.unite(e.from,e.to)) res += e.cost;
    return res;
}

struct cood {int x, y, label;};

int main() {
    int n;
    cin >> n;
    vector<cood> co;
    vector<edge<int>> edges;
    rep(i,n) {
        int a, b;
        cin >> a >> b;
        co.push_back(cood{a,b,i});
    }
    sort(co.begin(),co.end(),[&](const cood &co1, const cood &co2) {
        return co1.x < co2.x;
    });
    rep(i,n-1) {
        edges.push_back(edge<int>{co[i].label,co[i+1].label,co[i+1].x-co[i].x});
    }
    sort(co.begin(),co.end(),[&](const cood &co1, const cood &co2) {
        return co1.y < co2.y;
    });
    rep(i,n-1) {
        edges.push_back(edge<int>{co[i].label,co[i+1].label,co[i+1].y-co[i].y});
    }
    cout << kruskal(edges,n) << endl;
}

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  int a, b;
  cin >> a >> b;
  int n = b - a;
  int original_b = n * (n + 1) / 2;
  cout << original_b - b << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int a = Integer.parseInt(stdIn.next());
    int b = Integer.parseInt(stdIn.next());

    if ((a + b) == 3) {
      System.out.println("3");
    } else if ((a + b) == 4) {
      System.out.println("2");
    } else if ((a + b) == 5) {
      System.out.println("1");
    }
  }
}


Measured memory_bytes: 23124
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S,W = map(int,input().split())

if W-S>=0:
    print("unsafe")
else:
    print("safe")
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 9144
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 10e8+7;
 // const ll INF = 1000000000000000000LL;
 
 int main(){
	 int n;
	 cin >> n;
	 vector<ll> a(n);
	 rep(i,n) cin >> a[i];
	 vector<int> sum(n);
	 rep(i,n-1){
		 sum[i+1] = sum[i]+a[i];
		 sum[i+1] %=MOD;
	 }
	 ll ans=0;
	 for(int i=n-1;i>0;i--){
		 ans += sum[i]*a[i];
		 ans %=MOD;
	 }
	 cout << ans << endl;
 }

Measured memory_bytes: 5632
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long num = sc.nextLong();
        long count = 0;
        for(int i =1 ;i < num+1; i++){
            if(i % 3l == 0l && i % 5l == 0l){
            }else if(i % 3l == 0l){
            }else if(i % 5l == 0l){
            }else{
                count += i;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 2005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to,next;
}E[MAXN * MAXN * 2];
int head[MAXN],sumE,A[MAXN],N;
int dfn[MAXN];
bool vis[MAXN];
vector<int> L;
int gcd(int a,int b) {
    return b == 0 ? a : gcd(b,a % b);
}
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
vector<int> Merge(vector<int> a,vector<int> b) {
    vector<int> c;
    int pa = 0,pb = 0;
    while(pa < a.size() && pb < b.size()) {
        if(a[pa] > b[pb]) c.pb(a[pa++]);
        else c.pb(b[pb++]);
    }
    while(pa < a.size()) c.pb(a[pa++]);
    while(pb < b.size()) c.pb(b[pb++]);
    return c;
}
vector<int> Calc(int u) {
    vector<int> son;
    vis[u] = 1;
    for(int i = head[u] ; i ; i = E[i].next) {
        int v = E[i].to;
        if(!vis[v]) son.pb(v);
    }
    sort(son.begin(),son.end());
    vector<int> tmp;
    for(auto t : son) dfn[t] = dfn[u] + 1;
    for(auto t : son) {
        if(!vis[t] && dfn[t] == dfn[u] + 1) {
            tmp = Merge(tmp,Calc(t));
        }
    }
    tmp.insert(tmp.begin(),A[u]);
    return tmp;
}

void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(A[i]);
    sort(A + 1,A + N + 1);
    for(int i = 1 ; i <= N ; ++i) {
        for(int j = i + 1 ; j <= N ; ++j) {
            if(gcd(A[i],A[j]) != 1) {
                add(i,j);add(j,i);
            }
        }
    }
    for(int i = 1 ; i <= N ; ++i) {
        if(dfn[i] == 0) {
            L = Merge(Calc(i),L);
        }
    }
    for(auto t : L) {
        out(t);space;
    }
    enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 28416
# frozen_string_literal: true
n, m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
if n >= m
  puts 0
  exit 0
end
sorted_x = x.sort
diff_x = {}
(0..m-2).each do |i|
  diff_x[i+1] = sorted_x[i+1] - sorted_x[i]
end
sorted_diff = diff_x.sort { |a,b| a[1] <=> b[1] }.reverse
pos = []
pos[0] = 0
pos[n] = m
(1..n-1).each do |i|
  pos[i] = sorted_diff[i-1][0]
end
puts (0..n-1).reduce(0) { |sum, i| sum += sorted_x[pos[i+1]-1] - sorted_x[pos[i]] }


Measured memory_bytes: 22776
#include <bits/stdc++.h>
const int INF = 1e9;
const int MO = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};


int main(){
    CIN(N);
    SCIN(A);SCIN(B);SCIN(C);
    LL ans = 0;
    for(int a = 0;a < N;a++){
        set<char> se;
        se.insert(A.at(a));
        se.insert(B.at(a));
        se.insert(C.at(a));
        ans += se.size()-1;
    }
    COUT(ans);
}


Measured memory_bytes: 256
#include<cstdio>
using ll = long long;
using ull = unsigned long long;
const static int MOD = 1000000007;

ll RepeatSquaring(ll N, ull P){
	if(P == 0 || N == 1) return 1;
	if(N == -1) return P & 1 ? -1 : 1;
	if(!(P & 1)){
		ll t = RepeatSquaring(N, P >> 1);
		return t*t % MOD;
	}
	//Pが偶数のときN^(P/2)を求めてからそれの2乗を返す
	return N*RepeatSquaring(N, P - 1) % MOD;
	//Pが奇数のときN^((P - 1)/2)を求めてからそれの2乗を返す
}

ull Combination(ull n, ull r){
	ull ret = 1;
	if(n - r < r) r = n - r;
	for (ull i = 0; i < r; ++i){
		ret = ret*((n - i) %MOD) %MOD *RepeatSquaring(i+1, MOD-2) %MOD;
	}
	return ret;
}
int main(){
	ull X, Y;
	scanf("%llu %llu", &X, &Y);
	ull sum = X + Y;
	if(sum % 3){
		printf("0\n");
		return 0;
	}
	ull moves = sum/3;
	if(X < moves || Y < moves){
		printf("0\n");
	}else{
		printf("%llu\n", Combination(moves, X - moves));
	}
	return 0;
}

Measured memory_bytes: 128
import sys
from heapq import*
def m():
 n=int(input())
 A=[]
 for e in sys.stdin:
  e=list(map(int,e.split()))
  A+=[zip(e[2::2],e[3::2])]
 d=[0]+[float('inf')]*n
 H=[(0,0)]
 while H:
  u=heappop(H)[1]
  for v,c in A[u]:
   t=d[u]+c
   if d[v]>t:
    d[v]=t
    heappush(H,(t,v))
 print('\n'.join(f'{i} {d[i]}'for i in range(n)))
m()


Measured memory_bytes: 39980
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, m, q;
    int l, r;
    int qp, qq;
    
    cin >> n >> m >> q;

    vector<vector<int>> x(n+1, vector<int>(n+1, 0));
    vector<vector<int>> c(n+1, vector<int>(n+1, 0));
    vector<vector<int>> z(n+1, vector<int>(n+1, 0));

    for(auto i=0;i<m;++i) {
        cin >> l >> r;
        x[l][r] += 1;
    }

    for(auto i=1;i<n+1;++i) {
        for(auto j=1;j<n+1;++j) {
            c[i][j] = c[i][j-1] + x[i][j];
            z[i][j] = z[i-1][j] + c[i][j];
        }
    }

    for (auto i=0;i<q;++i) {
        cin >> qp >> qq;
        cout << (z[qq][qq] - z[qp-1][qq] - z[qq][qp-1] + z[qp-1][qp-1]) << endl;
    }
}

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

int main() {
  vector<int> a(3);
  for(int i=0;i<3;i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(), a.end());
  int x;
  x = a.at(2) - a.at(0);
  cout << x << endl;
}


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

using namespace std;

const int N = 100005;

int main(){
    int cnt[4] = {};
    for(int i = 0; i < 3; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        cnt[a - 1]++, cnt[b - 1]++;
    }

    for(int i = 0; i < 4; i++) if(cnt[i] > 2)
        return printf("NO\n"), 0;
    printf("YES\n");
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
res = 0
a = 0
b = 0
ab = 0
for _ in range(N):
  s = input()[: -1]
  res += s.count("AB")
  a += s[-1] == "A"
  b += s[0] == "B"
  ab += (s[-1] == "A" and (s[0] == "B"))
ab = ab > 0 and (a == b == ab)
print(res + min(N - 1, a - ab, b - ab))

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!

//

void solve(long long N, std::vector<long long> P, std::vector<long long> Q) {
  vector<ll> R(N); rep(i,N) R[i] = i+1;
  ll a = 0;
  do {
    a++;
    if (P==R) break;
  } while (next_permutation(all(R)));
  rep(i,N) R[i] = i+1;
  ll b = 0;
  do {
    b++;
    if (Q==R) break;
  } while (next_permutation(all(R)));

  cout << abs(a-b) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  long long N;
  std::cin >> N;
  std::vector<long long> P(N);
  for (int i = 0; i < N; i++) {
    std::cin >> P[i];
  }
  std::vector<long long> Q(N);
  for (int i = 0; i < N; i++) {
    std::cin >> Q[i];
  }
  solve(N, std::move(P), std::move(Q));
  return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int ans = 0;
		if (x >= 400 && x <= 599) {
			ans = 8;
		} else if (x <= 799) {
			ans = 7;
		} else if (x <= 999) {
			ans = 6;
		} else if (x <= 1199) {
			ans = 5;
		} else if (x <= 1399) {
			ans = 4;
		} else if (x <= 1599) {
			ans = 3;
		} else if (x <= 1799) {
			ans = 2;
		} else if (x <= 1999) {
			ans = 1;
		}
		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 35624
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) {
    cin >> a[i];
    a[i]--;
  }

  vector<bool> checked(N, false);
  int ans = 1;
  int now = 0;
  rep(i, N) {
    checked[now] = true;
    int next = a[now];
    if (next == 1) {
      cout << ans << endl;
      return 0;
    }
    if (checked[next]) {
      cout << -1 << endl;
      return 0;
    }
    now = next;
    ans++;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
using namespace std;

int main() {
	bool a = false, b = false, c = false;
	char s;
	for (int i = 0; i < 3; i++) {
		cin >> s;
		if (!a) {
			a = 'a' == s;
		}
		if (!b) {
			b = 'b' == s;
		}
		if (!c) {
			c = 'c' == s;
		}
	}
	if (a&&b&&c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;

ll h[MAXn],dp[MAXn];
int main(){
  IOS();
  ll n;
  cin >> n;
  REP (i,n) cin >> h[i], dp[i] = INF;
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  for (int i=2;i<n;i++) {
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

struct edge {
    int to, cost;
};

int V;
vector<edge> G[1000000];

plglg visit(int v) {
    plglg ans(0, v);
    queue<tlglglg> que;
    tlglglg start(-1, v, 0);
    que.push(start);
    while (que.size() > 0) {
        tlglglg p;
        p = que.front();
        que.pop();
        ll back = get<0>(p);
        ll now = get<1>(p);
        ll weight = get<2>(p);
        int n = G[now].size();
        for (int i = 0; i < n; i++) {
            edge e = G[now][i];
            if (e.to != back) {
                tlglglg pp(now, e.to, weight + e.cost);
                que.push(pp);
                if (weight + e.cost > ans.first) {
                    ans.first = weight + e.cost;
                    ans.second = e.to;
                }
            }
        }
    }
    return ans;
}

pii farthest;

ll diameter() {
    plglg r = visit(0);
    plglg t = visit(r.second);
    farthest.first = r.second;
    farthest.second = t.second;
    return t.first;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        edge e1;
        e1.to = t;
        e1.cost = w;
        G[s].push_back(e1);
        edge e2;
        e2.to = s;
        e2.cost = w;
        G[t].push_back(e2);
    }
    ll ans = diameter();
    cout << ans << endl;
}



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

using namespace std;
typedef long long ll;

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

  for (int i = 0; i <= n; i++) {
    for (int j = 0; i + j <= n; j++) {
      int k = n - i - j;
      if (i * 10 + j * 5 + k == y / 1000) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1\n";

  return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int D = scan.nextInt();
        int T = scan.nextInt();
        int S = scan.nextInt();

        int ans;

        if(D <= T*S){
            os.println("Yes");
        } else {
            os.println("No");
        }

    }
}

Measured memory_bytes: 27044
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
	long long int n,max,count=0;
	std::cin>>n;

	std::vector<long long int> v(n);
	std::vector<long long int> x;

	for (int i = 0; i < n; i++) {
		long long int a;
		std::cin >> a;
		v[i] = a;
	}

	if (n == 1) {
		std::cout << 0 << std::endl;
		exit(0);
	}
	
	for (int i = 0; i < v.size()-1; i++) {

		if (v[i] >= v[i+1]) {
			count++;
		}

		if (v[i] < v[i+1] || i==v.size()-2) {
			x.push_back(count);
			count = 0;
		}
		
	}

	std::sort(x.begin(), x.end());

	std::cout << x[(x.size() - 1)] << std::endl;
	
	
	
	return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct Edge {
	int from, to;
	ll w;
};
typedef vector<vector<Edge>> Graph;

#define chmax(a,b) ((a) = max(a,b))
#define chmin(a,b) ((a) = min(a,b))

signed main(void) {
	ll n, lim;
	cin >> n >> lim;
	vector<ll> w(n),v(n);


	REP(i, n) {
		cin >> w[i] >> v[i];
	}

	ll dp[101][200001] = {};
	Fill(dp, LLONG_MAX/2);
	dp[0][0] = 0;

	REP(i, n)
	{
		REP(j, 100001) {
			chmin(dp[i + 1][j], dp[i][j]);
			chmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
		}
	}
	int ans = 0;
	REP(j, 100001) {
		if (dp[n][j] <= lim) {
			chmax(ans, j);
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 158080
i,o,t,j,l,s,z=map(int,input().split())
ans1=o
ans1+=2*(i//2)
ans1+=2*(j//2)
ans1+=2*(l//2)
if i%2==j%2==l%2==1:
  ans1+=3
ans2=o
if i and j and l:
  ans2+=3
  i-=1
  l-=1
  j-=1
ans2+=2*(i//2)
ans2+=2*(l//2)
ans2+=2*(j//2)
print(max(ans1,ans2))

Measured memory_bytes: 9200
#include<iostream>
using namespace std;
int main(){
  string s;
  int field[3][3];
  while(cin >>s){
    int ans = 0;
    for(int i=0; i<s.size(); i++){
      if(s[i] == 'o') field[i%3][i/3] = 1;
      if(s[i] == 'x') field[i%3][i/3] = 2;
      if(s[i] == 's') field[i%3][i/3] = 0;
    }
    for(int i=0; i<3; i++){
      if(field[0][i] == field[1][i] && field[1][i] == field[2][i] && field[0][i]!=0) ans = field[0][i];
      if(field[i][0] == field[i][1] && field[i][1] == field[i][2] && field[i][0]!=0) ans = field[i][0];
    }
    if(field[0][0] == field[1][1] && field[1][1] == field[2][2] && field[0][0]!=0) ans = field[0][0];
    if(field[2][0] == field[1][1] && field[1][1] == field[0][2] && field[2][0]!=0) ans = field[2][0];
    if(ans == 0) cout <<"d"<<endl;
    if(ans == 1) cout <<"o"<<endl;
    if(ans == 2) cout <<"x"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1168
A_list = []
ans = 0

N = int(input())
A = input()
A_list = A.split(' ')

for n in range(N):
    if (int(A_list[n]) % 2 == 0):
        if (int(A_list[n]) % 3 == 0) | (int(A_list[n]) % 5 == 0):
            ans = ans + 0
        else:
            ans = ans + 1
if ans == 0:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		ll n;
		cin>>n;
		ll a[n+1];
		for(int i =1;i<=n;i++){
			cin>>a[i];
		}
		ll ans = 0;
		while(true){
			bool poss=false;
			for(int i =1;i<=n;i++){
				if(i == 1){
					poss |= (a[i] == a[i+1]);
				}
				else if(i == n){
					poss |= (a[i] == a[i-1]);
				}
				else{
					poss |= (a[i] == a[i+1] || a[i]==a[i-1]);
				}
			}
			if(poss==false){
				break;
			}
			ll idx = -1;
			for(int i =2;i<=n-1;i++){
				if(a[i] == a[i-1] && a[i] == a[i+1]){
					idx = i;
					break;
				}
			}
			if(idx != -1){
				set<ll> se;
				se.insert(a[idx-1]);
				se.insert(a[idx+1]);
				se.insert(a[idx]);
				ll gg = -1;
				for(int j = 1;;j++){
					if(se.find(j) == se.end()){
						gg=j;break;
					}
				}
				ans += 1;
				a[idx] = gg;
				continue;
			}
			
					for(int i =2;i<=n-1;i++){
					if(a[i] == a[i-1] || a[i] == a[i+1]){
						idx = i;
						break;
					}
				}
				if (idx != -1){
					set<ll> se;
				se.insert(a[idx-1]);
				se.insert(a[idx+1]);
				se.insert(a[idx]);
				ll gg = -1;
				for(int j = 1;;j++){
					if(se.find(j) == se.end()){
						gg=j;break;
					}
				}
				ans += 1;
				a[idx] = gg;
				continue;
				}
			
				if(a[1] == a[2]){
					ans += 1;
					ll gg = -1;
					for(int j =1;;j++){
						if(j != a[1] && j != a[2]){
							gg=j;break;
						}
					}
					a[1]  = gg;
				}
				else if(a[n]==a[n-1]){
					ans += 1;
					ll gg = -1;
					for(int j =1;;j++){
						if(j != a[n] && j != a[n-1]){
							gg=j;break;
						}
					}
					a[n]  = gg;

				}
				
			
		}
		// for(int i = 1;i<=n;i++){
		// 	cout<<a[i]<<" ";
		// }
		// cout<<endl;
		cout<<ans<<endl;
		return 0;
	}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
#define ll long long
const int maxn = 2e5 + 5;
ll tree[maxn << 2];

void build(int o, int l, int r) {
    tree[o] = 0;
    if (l == r) return ;
    int mid = (l + r) / 2;
    build(o << 1, l, mid);
    build(o << 1 | 1, mid + 1, r);
    tree[o] = max(tree[o << 1], tree[o << 1 | 1]);
}

void update(int o, int l, int r, int p, ll v) {
    if (l == r) {
        tree[o] = v;
        return ;
    }
    int mid = (l + r) / 2;
    if (mid >= p) update(o << 1, l, mid, p, v);
    else if (mid < p) update(o << 1 | 1, mid + 1, r, p, v);
    tree[o] = max(tree[o << 1], tree[o << 1 | 1]);
}

ll query(int o, int l, int r, int x, int y) {
    if (x <= l && y >= r) {
        return tree[o];
    }
    int mid = (l + r) >> 1;
    ll ans = 0;
    if (mid >= x) ans = max(ans, query(o << 1, l, mid, x, y));
    if (mid < y) ans = max(ans, query(o << 1 | 1, mid + 1, r , x, y));
    return ans;
}

pair<ll, ll> a[maxn];
int L[maxn];
ll b[maxn];
ll dp[maxn];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%lld %lld", &a[i].first, &a[i].second);
    }
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n; ++i) {
        b[i] = a[i].first;
    }
    build(1, 1, n);
    for (int i = n; i >= 1; --i) {
        int tmp = upper_bound(b + 1, b + 1 + n, a[i].first + a[i].second - 1) - b;
        if (tmp == i + 1) L[i] = i;
        else L[i] = query(1, 1, n, i + 1, tmp - 1);

        update(1, 1, n, i, L[i]);
    }

    dp[n + 1] = 1;
    for (int i = n; i >= 1; --i) {
        dp[i] = dp[i + 1] + dp[L[i] + 1];
        dp[i] %= mod;
    }
    printf("%lld\n", dp[1]);
    return 0;
}

Measured memory_bytes: 12544
using System;
using System.Collections.Generic;
class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int[] even = new int[100002];
            int[] odd = new int[100002];

            for (int i=0; i<n; i++)
            {
                if (i%2 == 0) even[int.Parse(input[i])]++;
                else odd[int.Parse(input[i])]++;
            }

            int ep1 = 0, op1 = 0, ep2 = 100001, op2 = 100001;
            for (int i=1; i<100001; i++)
            {
                if (even[i] > even[ep1])
                {
                    ep2 = ep1;
                    ep1 = i;
                }
                else if (even[i] > even[ep2]) ep2 = i;
                if (odd[i] > odd[op1])
                {
                    op2 = op1;
                    op1 = i;
                }
                else if (odd[i] > odd[op2]) op2 = i;
            }
            if (ep1 != op1) Console.WriteLine(n - even[ep1] - odd[op1]);
            else
            {
                int ans = Math.Min(n - even[ep1] - odd[op2], n - even[ep2] - odd[op1]);
                Console.WriteLine(ans);
            }



            
            

            
            
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 19296
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n = sc.nextInt();
		long[] a1=new long[n];
		for(int i = 0; i<n; i++){
			long a = sc.nextLong();
			a1[i]=a;
		}
		Arrays.sort(a1);
		long ans=1;
		for(int i=0; i<n-1; i++){
			if(a1[i]*2>=a1[i+1]){
				ans++;
			}else{
				ans=1;
			}
			a1[i+1]+=a1[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 59552
"use strict"
 
let arg_str = require('fs').readFileSync('/dev/stdin', 'UTF-8')
arg_str = arg_str.split('\n')
const arg_str_0 = arg_str[0].split(' ')
const N = arg_str_0[0]
const K = arg_str_0[1]
const Q = arg_str_0[2]
 
const A_array = arg_str.slice(1)
 
let result_val = []
 
for(let i=0;i<N;i++){
  result_val[i] = K - Q
}
 
A_array.map(x=>result_val[x-1]++)

result_val.map(x=>x>0 ? console.log('Yes') : console.log('No'))


Measured memory_bytes: 30380
puts [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][gets.to_i-1]


Measured memory_bytes: 1788
#include <stdio.h>
int main(void) {
    long a,b;
    scanf("%ld %ld", &a, &b);
    
    if((a+b)%2 == 0){
    	printf("%ld\n", (a+b)/2);
    }
    else printf("IMPOSSIBLE\n");
 
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
int par[114514], rrank[114514];//親、木の深さ
void init(int n) {
	rep(i, n) {
		par[i] = i;
		rrank[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rrank[x] < rrank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rrank[x] == rrank[y])rrank[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
signed main() {
	char c;
	cin >> c;
	cout << char(c + 1) << endl;
	ggr
}


Measured memory_bytes: 256
function main()
    n = parse(Int, readline())
    a = parse.(Int, split(readline()))
    a = cat(dims=1, [0], a)
    部下の数 = zeros(Int, n)
    for i = 2:n
        部下の数[a[i]] += 1
    end
    for i = 1:n
        println(部下の数[i])
    end
end

main()


Measured memory_bytes: 228120
n = int(input())
a = tuple(map(int, input().split()))
b = [0] * n
ret = 0
ret2 = []
append = ret2.append
for i in range(n, 0, -1):
  count = 0
  for j in range(i+i, n+1, i):
    count += b[j-1]
  # print((i, count))
  if not (count % 2) == a[i-1]:
    b[i-1] = 1
    ret += 1
    append(i)

# print(b)
print(ret)
if ret == 0:
  exit()

# print(*reversed(ret2))

for i in range(n):
  if b[i] == 1:
    print('%d ' % (i+1), end="")


Measured memory_bytes: 70876
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    s += "0";
    int n = s.size();

    int dp[n+1][2];
    rep(i, n+1)rep(j, 2) dp[i][j] = mod;
    dp[0][0] = 0;
    rep(i, n){
        int t = s[i]-'0';
        dp[i+1][0] = min(dp[i][0]+t, dp[i][1]+t+1);
        dp[i+1][1] = min(dp[i][0]+10-t, dp[i][1]+10-t-1);
    }
    printf("%d\n", dp[n][0]);
}

Measured memory_bytes: 9220
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

//#include "atcoder/all"
//using namespace atcoder;

vector<int> parse(int n, string& s) {
    char c = s[0];
    int tmp = 1;
    vector<int> res;
    for (int i = 1; i < n; i++) {
        if (s[i] != c) {
            c = s[i];
            res.push_back(tmp);
            tmp = 1;
        } else {
            tmp++;
        }
    }
    res.push_back(tmp);
    return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	string s;
	cin >> n >> s;
	cout << parse(n, s).size() << endl;
	return 0;
}


Measured memory_bytes: 4068
import java.util.*;

class Main{
	public static void main(String[] $){
		var s=new Scanner(System.in);
		int n=s.nextInt();
		var t=s.next().toCharArray();

		var a=new int[n+1];
		var b=new int[n+1];
		var c=new int[n+1];
		for(int i=1;i<=n;++i)
			a[i]=t[i-1]=='R'?a[i-1]+1:a[i-1];
		for(int i=1;i<=n;++i)
			b[i]=t[i-1]=='G'?b[i-1]+1:b[i-1];
		for(int i=1;i<=n;++i)
			c[i]=t[i-1]=='B'?c[i-1]+1:c[i-1];

		long r=0;
		for(int i=1;i<=n;++i){
			long l=0;
			if(t[i-1]=='R') {
				l=f(n,b,c,i)+f(n,c,b,i);
			}
			if(t[i-1]=='G') {
				l=f(n,a,c,i)+f(n,c,a,i);
			}
			if(t[i-1]=='B') {
				l=f(n,b,a,i)+f(n,a,b,i);
			}

			for(int d=1;i+d<=n&&i-d>=1;++d){
				if(t[i-1]!=t[i-d-1]&&t[i-1]!=t[i+d-1]&&t[i-d-1]!=t[i+d-1])
					--l;
			}

			r+=l;
		}
		System.out.println(r);
	}

	private static int f(int n,int[] b,int[] c,int i){
		return b[i]*(c[n]-c[i]);
	}
}


Measured memory_bytes: 37156
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {

        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };


    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize,
        w: usize,
        s: [chars; h],
    }
    let mut white_size = 0;
    for x in 0..h {
        for y in 0..w {
            if s[x][y] == '.' {
                white_size += 1;
            }
        }
    }
    // println!("{}", white_size);

    let mut dist = vec![vec![-1; w]; h];
    let mut queue = std::collections::VecDeque::new();
    queue.push_back((0, 0));
    dist[0][0] = 0;
    while let Some((x, y)) = queue.pop_front() {
        for &(dx, dy) in [(-1, 0), (1, 0), (0, -1), (0, 1)].iter() {
            let nx = x as i64 + dx;
            let ny = y as i64 + dy;
            if nx < 0 || h <= nx as usize || ny < 0 || w <= ny as usize {
                continue;
            }
            let nx = nx as usize;
            let ny = ny as usize;
            if dist[nx][ny] == -1 && s[nx][ny] != '#' {
                dist[nx][ny] = dist[x][y] + 1;
                queue.push_back((nx, ny));
            }
        }
    }
    if dist[h - 1][w - 1] == -1 {
        println!("{}", -1);
    } else {
        println!("{}", white_size - dist[h - 1][w - 1] - 1);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int getSum(int n){
    int ans = 0;
    while(n>0){
        ans += n%10;
        n/=10;
    }
    return ans;
}

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int ans = 0;
    for(int i=1;i<=n;i++){
        int summ = getSum(i);
        if(summ>=a && summ <= b)ans+=i;
    }
    cout << ans<<endl;
}


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

int main(void){
	int n;
	cin>>n;
	double ans=0;
	rep(i,n){
		double x;
		string u;
		cin>>x>>u;
		if(u=="JPY")ans+=x;
		else ans+=x*380000;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    int n, m;
    cin >> n >> m;
    vector<vi> g(n);
    vi h(n);
    for(auto& x : h) cin >> x;
    rep(i,0,m) {
        int a,b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    auto check_good = [&] (int node) {
        for(const auto& nei : g[node]) if(h[nei] >= h[node]) {
            return 0; 
        }
        return 1;
    };
    int total = 0; 
    for(int i = 0; i < n; ++i) {
        total += check_good(i); 
    }
    cout << total << endl;
    return 0;
}



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

int main(){
  int n;
  string s;
  cin >> n >> s;
 
  string w = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(int i=0; i<s.size(); i++){
    for(int j=0; j<26; j++){
      if(s.at(i)==w.at(j)){
        if(j+n>=26){
          j-=26;
        }
        cout << w[j+n];
        break;
      }
    }
  }
  cout << endl;
  
  return 0;
}


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

// input
int M;


void input() {
    cin >> M;
}


int main() {
    input();
    int ans = 48 - M;
    cout << ans << endl;
}


Measured memory_bytes: 3620