akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b>>1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll N, S;
	cin >> N >> S;

	vector<ll> A(N + 1);
	repn(i, N) cin >> A[i];

	ll T = S * 2;

	vvmint dp(N + 1, vmint(T + 1, 0));
	dp[0][0] = 1;

	repn(i, N) {
		rep(j, T+1) {
			dp[i][j] = dp[i - 1][j] * 2;
			if (j >= A[i]) { dp[i][j] += dp[i - 1][j - A[i]]; }

			//cout << i << " " << j << dp[i][j] << endl;
		}
	}

	cout << dp[N][S] << endl;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
ll A[200100], B[200100];
ll dp[200100];

ll rec(int i, bool odd){
    if(i == N - 1){
        return odd ? 0 : A[N-1];
    }

    if(i >= N){
        return 0;
    }

    if(dp[i] != -1){
        return dp[i];
    }

    if(odd){
        dp[i] = std::max({B[i+2], A[i] + rec(i + 2, 1), A[i+1] + rec(i + 3, 0)});
    }else{
        dp[i] = std::max(A[i] + rec(i + 2, 0), B[i+1]);
    }

    return dp[i];
}

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    for(int i=N-1;i>=0;--i){
        B[i] = A[i] + B[i+2];
    }

    memset(dp, -1, sizeof(dp));

    ll res = rec(0, N % 2);
    std::cout << res << std::endl;
}


Measured memory_bytes: 14592
#include <cstdio>
#include <utility>
#include <cctype>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
struct range{
	int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

int main() {
	for (int r, c; (r = in, c = in);)
		outl((r * c & 1 ? "no" : "yes"));
}


Measured memory_bytes: 2436
#include <iostream>
    #include <algorithm>
    #include <numeric>
    #include <utility>
    #include <cmath>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #define MAX_U   10
    #define MIN_U   0
    #define rep(i,n) for(int i=0;i<n;i++)
    #define sz(x) ((int)(x).size())
    using namespace std;
    typedef long long ll;
    typedef vector<int> vi;
    typedef vector<char> vc;
    typedef vector<string> vs;
    typedef queue<int> qi;
    const int INF=numeric_limits<int>::infinity();
    void printa(){cout<<"\n";}
    template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
    template<class... A>void printa(const A&... rest){printa(rest...);}
    void prints(){cout<<" ";}
    template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
    template<class... A>void prints(const A&... rest){prints(rest...);}
    int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
    int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
    int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
    double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
    double trapezium(int a,int b,int h){return (a+b)*h/2;}
    double triangle(int a,int h){return a*h/2;}
    int main(void){
        cin.tie(0);
        ios::sync_with_stdio(false);
        int a,b,c,d;
        cin >>a>>b>>c>>d;
        if(a>b||a==b){
            if(c>d||c==d)printa(b+d);
            else printa(b+c);
        }
        else{
            if(c>d)printa(a+d);
            else printa(a+c);
        }
        return 0;
    }

Measured memory_bytes: 256
n, a, b = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
h = 0
for i in range(n- 1):
    if (x[i + 1] - x[i]) * a >= b:
        h += b
    else:
        h += (x[i + 1] - x[i]) * a
print(h)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
int dfs(vector<int> &x, vector<int> &y, vector<int> &P, vector<pair<int, int>> &id, int d){
  int m = x.size();
  if (d == m / 2){
    return 0;
  } else {
    vector<int> R;
    for (int i = 0; i < m; i++){
      if (P[i] == -1){
        R.push_back(i);
      }
    }
    int sz = R.size();
    int ans = 0;
    P[R[0]] = d;
    for (int i = 1; i < sz; i++){
      P[R[i]] = d;
      id[d] = make_pair(R[0], R[i]);
      int dy = y[R[i]] - y[R[0]];
      int dx = x[R[i]] - x[R[0]];
      int cnt = 0;
      for (int j = 0; j < d; j++){
        if ((x[id[j].second] - x[id[j].first]) * dy == (y[id[j].second] - y[id[j].first]) * dx){
          cnt++;
        }
      }
      ans = max(ans, cnt + dfs(x, y, P, id, d + 1));
      id[d] = make_pair(-1, -1);
      P[R[i]] = -1;
    }
    P[R[0]] = -1;
    return ans;
  }
}
int main(){
  int m;
  cin >> m;
  vector<int> x(m), y(m);
  for (int i = 0; i < m; i++){
    cin >> x[i] >> y[i];
  }
  vector<int> P(m, -1);
  vector<pair<int, int>> id(m);
  for (int i = 0; i < m; i++){
    id[i] = make_pair(-1, -1);
  }
  cout << dfs(x, y, P, id, 0) << endl;
}


Measured memory_bytes: 3168
List = [int(n) for n in input()]
ans = [List[0]] * 4
for i in range(8):
    for j in range(3):
        if i & (1<<j):
            ans[j+1]= -List[j+1]
        else:
            ans[j+1] = List[j+1]
    if sum(ans) == 7:
        break
ans = [str(ans[0])] + ['+' + str(x) if x>=0 else str(x) for x in ans[1:]]
print("".join(ans) + '=7')

Measured memory_bytes: 9200
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define GG  {puts("No");continue;}
const int maxn=100005;
typedef long long ll;
int ufs1[maxn];ll w1[maxn];
int ufs2[maxn];ll w2[maxn];
struct node{
  int x,y,val;
  void read(){
    scanf("%d%d%d",&x,&y,&val);
  }
}P[maxn];
bool cmpx(const node &A,const node &B){
  return A.x<B.x;
}
bool cmpy(const node &A,const node &B){
  return A.y<B.y;
}
int find1(int x){
  if(x==ufs1[x])return x;
  int rt=find1(ufs1[x]);
  w1[x]+=w1[ufs1[x]];
  return ufs1[x]=rt;
}
int find2(int x){
  if(x==ufs2[x])return x;
  int rt=find2(ufs2[x]);
  w2[x]+=w2[ufs2[x]];
  return ufs2[x]=rt;
}
bool link1(int a,int b,ll w){
  if(find1(a)!=find1(b)){
    int ra=find1(a),rb=find1(b);
    ufs1[ra]=ufs1[rb];
    w1[ra]=w+w1[b]-w1[a];
    return true;
  }else{
    return w1[a]==w+w1[b];
  }
}
bool link2(int a,int b,ll w){
  if(find2(a)!=find2(b)){
    int ra=find2(a),rb=find2(b);
    ufs2[ra]=ufs2[rb];
    w2[ra]=w+w2[b]-w2[a];
    return true;
  }else{
    return w2[a]==w+w2[b];
  }
}
ll Min1[maxn],Min2[maxn];
int main(){
  int tests=1;
  while(tests--){
    bool flag=true;
    int R,C;scanf("%d%d",&R,&C);
    for(int i=1;i<=R;++i){
      ufs1[i]=i;w1[i]=0;
    }
    for(int i=1;i<=C;++i){
      ufs2[i]=i;w2[i]=0;
    }
    int n;scanf("%d",&n);
    for(int i=1;i<=n;++i)P[i].read();
    for(int i=1;i<=n;++i)if(P[i].val<0)flag=false;
    sort(P+1,P+n+1,cmpx);
    for(int i=1;i<n;++i)
      if(P[i].x==P[i+1].x)
	if(!link2(P[i].y,P[i+1].y,P[i+1].val-P[i].val))flag=false;

    sort(P+1,P+n+1,cmpy);
    for(int i=1;i<n;++i)
      if(P[i].y==P[i+1].y)
	if(!link1(P[i].x,P[i+1].x,P[i+1].val-P[i].val))flag=false;

    memset(Min1,0x3f,sizeof(Min1));
    memset(Min2,0x3f,sizeof(Min2));
    for(int i=1;i<=n;++i){
      int rt=find1(P[i].x);
      Min1[rt]=min(Min1[rt],P[i].val+w1[P[i].x]);
    }
    for(int i=1;i<=R;++i){
      int rt=find1(i);
      Min2[rt]=min(Min2[rt],-w1[i]);
    }
    for(int i=1;i<=R;++i)
      if(ufs1[i]==i&&Min1[i]+Min2[i]<0)
	flag=false;

    // memset(Min1,0x3f,sizeof(Min1));
    // memset(Min2,0x3f,sizeof(Min2));
    // for(int i=1;i<=n;++i){
    //   int rt=find2(P[i].y);
    //   Min1[rt]=min(Min1[rt],P[i].val+w2[P[i].y]);
    // }
    // for(int i=1;i<=C;++i){
    //   int rt=find2(i);
    //   Min2[rt]=min(Min2[rt],-w2[i]);
    // }
    // for(int i=1;i<=C;++i)
    //   if(ufs2[i]==i&&Min1[i]+Min2[i]<0)
    // 	flag=false;
    
    printf("%s\n",flag?"Yes":"No");
  }
  return 0;
}


Measured memory_bytes: 5248
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 100000 + 10;

map<ll,int> id;
int n, sz[maxn], fa[maxn], h[maxn], cnt = 0;
struct enode{
  int v, n;
  enode() {}
  enode(int _v, int _n):v(_v), n(_n) {}
}e[maxn << 1];
struct anode{
  ll x; int y;  
  friend bool operator < (anode a, anode b) { return a.x > b.x; }
}a[maxn];
int ans[maxn][2];
ll d[maxn], dep[maxn];

inline void addedge(int u, int v) { cnt ++; e[cnt] = enode(v,h[u]); h[u] = cnt; }

void dfs1(int u, int fa, int r) {
	d[r] += dep[u];
	for(int i = h[u];~ i;i = e[i].n) {
	  int v = e[i].v;
	  if(v == fa) continue;
	  dep[v] = dep[u] + 1;
	  dfs1(v,u,r);
	}
}

void dfs2(int u, int fa) {
  for(int i = h[u];~ i;i = e[i].n) {
    int v = e[i].v;
    if(v == fa) continue;
    d[v] = d[u] - 2 * sz[v] + n;
    dfs2(v,u);
	}
}

inline void fail() {
  puts("-1");
  exit(0);
}

int main() {
	scanf("%d", &n); cnt = 0;
	memset(h,-1,sizeof(h));
	for(int i = 1;i <= n;i ++) scanf("%lld", &a[i].x), sz[i] = 1, a[i].y = i, id[a[i].x] = i;
	sort(a + 1,a + n + 1);
	for(int i = 1;i < n;i ++) {
		int u = a[i].y;
		ll tmp = a[i].x + 2 * sz[u] - n;
		if(!id.count(tmp)) fail();
	  if(n - 2 * sz[u]<= 0) fail();
	  fa[u] = id[tmp];
	  sz[fa[u]] += sz[u];
	  ans[i][0] = u;
	  ans[i][1] = fa[u];
	  addedge(u,fa[u]);
	  addedge(fa[u],u);
	}
	dep[a[n].y] = 0;
	dfs1(a[n].y,0,a[n].y);
	dfs2(a[n].y,0);
	for(int i = 1;i <= n;i ++) if(a[i].x != d[a[i].y]) fail();
	for(int i = 1;i < n;i ++) printf("%d %d\n", ans[i][0], ans[i][1]);
  return 0;
}

Measured memory_bytes: 16640
package main

import (
	"fmt"
	"math"
)

func main() {
	points := make([]float64, 5)
	for i := range points {
		fmt.Scan(&points[i])
	}
	var k float64
	fmt.Scan(&k)

	for i := 0; i < 5; i++ {
		for j := i+1; j < 5; j++ {
			if math.Abs(points[i] - points[j]) > k {
				fmt.Println(":(")
				return
			}
		}
	}
	fmt.Println("Yay!")
}


Measured memory_bytes: 512
let h, dp, ab_s = Scanf.(scanf "%d %d" @@ fun h n -> Array.(h, make (h + 1) (1 lsl 40), init n @@ fun _ -> scanf " %d %d" @@ fun a b -> a, b))
let _ = for i = 1 to h do Array.iter (fun (a, b) -> dp.(i) <- min dp.(i) @@ if a >= i then b else dp.(i - a) + b) ab_s done; Printf.printf "%d\n" @@ dp.(h)

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;

int main(void){
  int N;
	string S;
	cin>>N>>S;
	int max = -10;
	int cnt = 0;
	for(int i = 0; i < N; i++){
		if(S[i] == 'I')cnt++;
		else cnt--;

		if(cnt >= max)max = cnt;

	}
	cout<<(max >= 0?max:0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int a,b,c,d; cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
}

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

using std::cout;
using std::cin;
using std::endl;
using std::string;


int main()
{
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
   
    if ((a1 + a2 + a3) >= 22)
        cout << "bust";
    else
        cout << "win";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

struct edge {
    int from, to, cost;
    edge(int to, int cost): to(to), cost(cost) {}
};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
constexpr int INF = 1000000000+7;

template<class T> inline T sqr(T x) {return x*x;}

template <typename T = pair<int, int>>
void Dijkstra(int s, vector<vector<edge>> &g, VI &d, VI &prev) {
    int numv = d.size();
    priority_queue<T, vector<T>, greater<T>> q;
    for (int i = 0; i < numv; ++i) d[i] = INF;
    for (int i = 0; i < numv; ++i) prev[i] = -1;
    d[s] = 0;
    q.emplace(0,s);

    while (!q.empty()) {
        T p = q.top(); q.pop();
        int v = p.second; // vertex
        if (d[v] < p.first) continue;
        for (int i = 0; i < g[v].size(); ++i) {
            edge e = g[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                q.emplace(d[e.to], e.to);
                prev[e.to] = v;
            }
        }
    }
}
vector<int> get_path(int s, int t, VI &prev) {
    vector<int> path;
    for (; t != s; t = prev[t]) path.push_back(t);
    reverse(begin(path), end(path));
    return path;
}

void solve() {
    int n,m;
    cin >> n >> m;
    VI d(n), prev(n);
    VVI jj(n,VI(n,0));
    int a,b,c;
    vector<vector<edge>> es(n);
    REP(i,0,m) {
        cin >> a >> b >> c;
        --a;--b;
        es[a].emplace_back(b,c);
        es[b].emplace_back(a,c);
        jj[a][b] = jj[b][a] = 1;
    }
    REP(i,0,n) {
        Dijkstra(i,es,d,prev);
        REP(j,0,n) {
            auto v = get_path(i,j,prev);
            int p = i;
            REP(k,0,v.size()) {
                jj[p][v[k]] = jj[v[k]][p] = 0;
                p = v[k];
            }
        }
    }
    
    int cnt = 0;
    REP(i,0,n) REP(j,i+1,n) cnt += jj[i][j];
    cout << cnt << endl;
}

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

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
limit = 10**18
ans = 1




flag = True

if 0 in a:
  print(0)
  flag = False

if flag:
  for i in a:
    ans *= i
    if ans > limit:
      print(-1)
      flag = False
      break

if flag:
  print(ans)
  
  

Measured memory_bytes: 21464
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
const int MAXA = 1e5 + 5;

int a[MAXN];
int t[MAXA];

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i) scanf("%d",&a[i]);
	
	ll ans = 0;
	for(int i=1; i<=n; ++i)
		++t[a[i]],
		ans += a[i];
	
	int Q;
	scanf("%d",&Q);
	while(Q--)
	{
		int b,c;
		scanf("%d%d",&b,&c);
		ans += (c-b) * (ll)t[b];
		printf("%lld\n",ans);
		
		t[c] += t[b];
		t[b] = 0;
	}
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      sum += a.at(i);
    } else sum -= a.at(i);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main()
{
    bool f[200005] = {};
    for (int i = 3; i <= 200000; i+=2) {
        f[i] = 1;
        for (int j = 3; j * j <= i; j+=2) {
            if (i % j == 0) {
                f[i] = 0; break;
            }
        }
    }
    f[2] = 1;
    int n;
    cin >> n;
    int x = 0;
    for (int i = 0;; i++) {
        if (f[i + n]) {
            x = i+n; break;
        }
        
    }
    cout << x << endl;

    return 0;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a,b,c[200],d,m;
int main(){
scanf("%d%d",&a,&b);
d=a;m=0xffff;
for(int i=0;i<a;i++){
	scanf("%d",&c[i]);
	m=m < c[i] ? m : c[i];
	b-=c[i];
}
d+=b/m;
printf("%d",d);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		double debt = 100000;
		int N = in.nextInt();
		for(int i=0;i<N;i++){
			debt = Math.ceil(debt*1.05/1000)*1000;
		}
		System.out.printf("%.0f\n",debt);
	}
}

Measured memory_bytes: 17364
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input()) # even
    V=list(map(int,input().split()))
    # 1種類しかないときはindexの関係上別処理する
    if len(set(V))==1:
        print(n//2)
        return
    from collections import Counter
    E=Counter(V[::2]).most_common() # list of tuple
    O=Counter(V[1::2]).most_common()
    if E[0][0]!=O[0][0]:
        print(n-E[0][1]-O[0][1])
    elif E[0][1]>O[0][1]:
        print(n-E[0][1]-O[1][1])
    elif E[0][1]<O[0][1]:
        print(n-E[1][1]-O[0][1])
    else:
        print(min(n-E[0][1]-O[1][1],n-E[1][1]-O[0][1]))
resolve()

Measured memory_bytes: 64872
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{
    public static void Main()
    {
        String[] input = Console.ReadLine().Split();
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);
        int[] a = new int[M];
        int[] b = new int[M];
        List<int>[] ikerutoko = new List<int>[N];
        for (int i = 0; i < N; i++) ikerutoko[i] = new List<int>();
        for (int i = 0; i < M; i++)
        {
            input = Console.ReadLine().Split();
            a[i] = int.Parse(input[0]);
            b[i] = int.Parse(input[1]);
            ikerutoko[a[i] - 1].Add(b[i]);
            ikerutoko[b[i] - 1].Add(a[i]);
        }
        int[] michishirube = new int[N];
        michishirube[0] = -1;

        Queue<int> que = new Queue<int>();
        que.Enqueue(1);
        while (que.Count > 0)
        {
            int num = que.Dequeue();
            foreach (int pointNext in ikerutoko[num - 1])
            {
                que.Enqueue(pointNext);
                if (michishirube[pointNext - 1] == 0) michishirube[pointNext - 1] = num;
            }
            ikerutoko[num - 1].Clear();
        }
        bool flag = true;
        for (int i = 0; i < N; i++)
        {
            if(michishirube[i] == 0)flag=false;
        }
        if (flag)
        {
            Console.WriteLine("Yes");
            for(int i = 1; i < N; i++)
            {
                Console.WriteLine(michishirube[i]);
            }
        }
        else
        {
            Console.WriteLine("No");
        }

    }
}

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

using namespace std;

int main(void) {
  
  long long A;
  long long B, N;
  cin >> A >> B >> N;

  long long max = 0;

  if (N < B) {
    max = (A * N) / B - A * (N / B);
  } else {
    max = (A * (B-1)) / B - A * ((B-1) / B);
  }

  cout << max << endl;
  



}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
using namespace std;

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

int main(){
    int H,W,K;
    cin >> H >> W >> K;
    char c[H][W];
    rep(i,H)rep(j,W) cin >> c[i][j];
    
    int ans=0;
    rep(i,1<<H)rep(j,1<<W){
        char temp[H][W];
        rep(m,H)rep(n,W) temp[m][n] = c[m][n];
        rep(k,H){
            if(i>>k&1){
                rep(m,W) temp[k][m] = '.';
            }
        }
        rep(l,W){
            if(j>>l&1){
                rep(m,H) temp[m][l] = '.';
            }
        }
        int sum=0;
        rep(m,H)rep(n,W){
            if(temp[m][n]=='#') sum+=1;
        }
        if(sum==K) ans+=1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3176
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] s_char = s.toCharArray();
		if(s_char[2]==s_char[3]&&s_char[4]==s_char[5]) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=15;

int n, k;
int d[N], forbidden[N];

bool check(int x)
{
	while(x>0)
	{
		if(forbidden[x%10])
			return 0;
		x/=10;
	}
	return 1;
}

int32_t main()
{
	IOS;
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		cin>>d[i];
		forbidden[d[i]]=1;
	}
	for(int ans=n;;ans++)
	{
		if(check(ans))
		{
			cout<<ans;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	ll x,y;
	cin >> x >> y;
	if(y>=2*x&&y<=4*x&&y%2==0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 3620
import sys
from operator import mul
f = sys.stdin

#from io import StringIO
#f = StringIO('''3 1 4 0 4 1''')

coins = map(int, f.readline().split())
coin_values = (1, 5, 10, 50, 100, 500)
paper = 1000

is_exchangeable = paper <= sum(map(mul, coins, coin_values))

print(1 if is_exchangeable else 0)

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}


int main(){

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

    int a,b;
    cin>>a>>b;
    string s = "";
    if(b < a) {
        
        for(int i = 0; i < a; i++) {
            char c = '0' + b;
            s += c;
        }
    } else {

        for(int i = 0; i < b; i++) {
            char c = '0' + a;
            s += c;
        }
    }

    cout<<s<<endl;


}


Measured memory_bytes: 256
class Node
  attr_accessor :parent, :size
  def initialize(n)
    @parent = n
    @size = 1
  end
end

class UnionFindTree
  def initialize(n)
    @nodes = (0..n).map { |i| Node.new(i) }
  end

  def find(x)
    return x if @nodes[x].parent == x
    @nodes[x].parent = find(@nodes[x].parent)
  end

  def unite(a, b)
    pa = find(a)
    pb = find(b)
    return if pa == pb

    if @nodes[pa].size < @nodes[pb].size
      @nodes[pa].parent = pb
      @nodes[pb].size += @nodes[pa].size
    else
      @nodes[pb].parent = pa
      @nodes[pa].size += @nodes[pb].size
    end
  end

  def same?(a, b)
    find(a) == find(b)
  end

  def size(x)
    @nodes[find(x)].size
  end
end

n, m = gets.split.map(&:to_i)
uft = UnionFindTree.new(n)

m.times do |i|
  x, y, z = gets.split.map(&:to_i)
  uft.unite(x,y)
end

con = Hash.new{|h,k| h[k] = 0}

1.upto(n) do |i|
  con[uft.find(i)] += 1
end

puts con.size


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	double r;cin>>r;
	printf("%.12lf\n",2*M_PI*r);
}

Measured memory_bytes: 3788
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n, m, mapp[55][55] = {0};
    int a, b;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; ++i)
    {
        scanf("%d%d", &a, &b);
        mapp[a][b]++;
        mapp[b][a]++;
    }
    int num = 0;
    for(int i = 1; i <= n; ++i)
    {
        num = 0;
        for(int j = 1; j <= n; ++j)
        {
            num += mapp[i][j];
        }
        cout << num << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def f(x, y, cx, cy):
    return abs(cx - x) + abs(cy - y)

n = int(input())
x = [0]*n
y = [0]*n
h = [0]*n
MAX = 2*(10**9)
for i in range(n):
    x[i], y[i], h[i] = map(int, input().split())

for cx in range(101):
    for cy in range(101):
        maxH = MAX
        res = 0
        isAnswer = True
        for i in range(n):
            if h[i] == 0:
                maxH = min(maxH, f(x[i], y[i], cx, cy))
            else:
                curH = h[i] + f(x[i], y[i], cx, cy)
                if res == 0:
                    res = curH
                elif curH != res:
                    isAnswer = False
                    break
        if isAnswer and res <= maxH:
            print(cx, cy, res)
            cy = cx = 101

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;


int main() {
	int N,A;
	cin >> N >> A;
	cout << N*N -A << endl;
	
	return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A <= B && B <= C) {
    cout << B - A + C - B  << endl;
  } else if (A <= C && C <= B) {
    cout << C - A + B - C << endl;
  } else if (B <= A && A <= C) {
    cout << A - B + C - A << endl;
  } else if (B <= C && C <= A) {
    cout << C - B + A - C << endl;
  } else if (C <= A && A <= B) {
    cout << A - C + B - A << endl;
  } else if (C <= B && B <= A) {
    cout << B - C + A - B << endl;
  }
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int H,W; cin >> H >> W;
    char A[H][W];
    set<P> s;
    REP(i,H)REP(j,W){
        cin >> A[i][j];
        if(A[i][j] == '#') s.insert(P(i,j));
    }
    s.erase(P(0,0));
    int x = 0, y = 0;
    while(x != H-1 || y != W-1){
        if((x<H-1 && A[x+1][y]=='#') ^ (y<W-1 && A[x][y+1]=='#')){
            if(A[x+1][y]=='#') x++;
            else y++;
            s.erase(P(x,y));
        }
        else{
            cout << "Impossible" << endl;
            return 0;
        }
    }
    if(s.size()) cout << "Impossible" << endl;
    else cout << "Possible" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> T1 pow_(T1 a, T2 b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n + 1);
  rep(i, k) {
    int d;
    cin >> d;
    rep(j, d) {
      int a;
      cin >> a;
      v[a] = 1;
    }
  }
  cout << n - accumulate(all(v), 0) << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int N,K;
vector<ll> W;

bool check(ll x){
  int num = 0;
  ll sum = 0;
  rep(i, N){
    if (W[i] > x) return false;
    sum += W[i];
    if (sum > x){ num++; sum = W[i]; }
  }
  if (sum > 0) num++;
  return num <= K;
}

int main() {
  cin >>N >>K;
  W.assign(N, 0); rep(i, N) cin >>W[i];
  ll ok = 1001001001, ng = 0;
  while (abs(ok-ng) > 1){
    ll mid = (ok+ng)/2;
    if (check(mid)) ok = mid;
    else ng = mid;
  }
  ll res = ok;
  cout <<res <<endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

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

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;

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

  cin >> n >> m;
  vector<int> v(n + 2, 0);

  REP(i, m) {
    int l, r;
    cin >> l >> r;
    v[l]++; v[r + 1]--;
  }

  int ans = 0;
  FOR(i, 1, n + 1) {
    v[i] += v[i - 1];
    if(v[i] == m) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
n = int(input())
for i in range(1, n + 1):
    x = i
    if x % 3 == 0:
        print(" ", i, sep="", end="")
    else:
        while x > 0:
            if x % 10 == 3:
                print(" ", i, sep="", end="")
                break
            x //= 10
print()

Measured memory_bytes: 8208
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
int n;
pair<int,bool>a[100000];
signed main() {
  cin>>n;
  int w=0;
  rep(i,n) {
    int ai;
    cin>>ai;
    a[i].F=ai;
    a[i].S=true;
  }
  rep(i,n) {
    int ai=a[w].F;
    a[w].S=false;
    if(ai==2) {
      cout<<i+1<<endl;
      break;
    }
    else if(a[ai-1].S) {
      w=ai-1;
    }
    else {
      cout<<"-1"<<endl;
      break;
    }
  }
}

Measured memory_bytes: 1792
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*(n+1)
d = [0]*(m+1)
for i in range(n):
    c[i+1] = a[i]+c[i]
for i in range(m):
    d[i+1] = b[i]+d[i]
for i in range(m+1)[::-1]:
    if d[i] <= k:
        x = i
        break
ans = x
for i in range(1,n+1):
    while c[i] + d[x] > k:
        if x >= 1:
            x -= 1
        else:
            break
    if c[i] + d[x] <= k:
        ans = max(ans,i+x)
print(ans)

Measured memory_bytes: 47344
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';
int mod = 1e9 + 7;
ll inf = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int m = n - n / 2;
    cout << fixed << setprecision(15) <<(double)m / (double)n << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<String> set = new HashSet<>();
		for (int i = 0; i < n; i++) {
			set.add(sc.next());
		}
		System.out.println(set.size());
	}
}


Measured memory_bytes: 77212
N = int(input())
c = input()

R_r = c.count("R")
W_l = 0
ans = N
for i in range(N+1):
  t = max(R_r,W_l)
  ans = min(ans, t)
  if R_r == 0:
    break
  if c[i] == "R":
    R_r -= 1
  else:
    W_l += 1

print(ans)

Measured memory_bytes: 9400
from itertools import combinations_with_replacement as c
n, m, q = [int(i) for i in input().split()]
abc = [[int(i) for i in input().split()] for _ in range(q)]
aa = list(range(1,m+1))
ans = 0
for bb in c(aa, n):
    cc = 0
    for a, b, c, d in abc:
        if bb[b-1] - bb[a-1] == c:
            cc += d
    ans = max(ans, cc)
print(ans)

Measured memory_bytes: 9140
use proconio::input;
use proconio::marker::Usize1;

fn main() {
  input! {
    n: usize,
    nums: [Usize1;n]
  }
  
  let mut orders: Vec<(usize, usize)> = vec![];
  for (i, num) in nums.into_iter().enumerate() {
    orders.push((i, num));
  }
  
  orders.sort_by(|a, b| {
    a.1.partial_cmp(&b.1).unwrap()
  });
  
  let result = orders
    .into_iter()
    .map(|a| (a.0 + 1).to_string())
    .collect::<Vec<String>>()
    .join(" ");

  println!("{}", result);
}

Measured memory_bytes: 9680
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
   int n;cin>>n;
   vector<int> v(n);
   map<int,int> m;
   for(int i=0;i<n;i++)cin>>v[i],m[v[i]]++;
   ll cur=0;
   for(auto it=m.begin();it!=m.end();it++){
       if(it->second>=2)cur+=1ll*(it->second)*(it->second-1)/2;
   }
   for(int i=0;i<n;i++){
       ll res=cur;
       if(m[v[i]]==2){
           res-=1;
           cout<<res<<endl;
       }
       else if(m[v[i]]>2){
           res +=1-m[v[i]];
           cout<<res<<endl;
       }
       else cout<<res<<endl;
   }
   
   
}

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

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    unsigned int a, b;
    cin >> a >> b;
    bitset<32> bit1(a);
    bitset<32> bit2(b);

    cout << (bit1 & bit2) << endl;
    cout << (bit1 | bit2) << endl;
    cout << (bit1 ^ bit2) << endl;

    return 0;
}



Measured memory_bytes: 3200
mod = 10**9+7

def fact(n):
    ans = 1
    while n > 0:
        ans = (ans*n) % mod
        n -= 1
    return ans

N,M = map(int,input().split())
if N-M < -1 or N-M > 1:
    print(0)
elif N-M == 0:
    tmp = fact(N)
    print(2*tmp*tmp % mod)
else:
    print(fact(N)*fact(M) % mod)
    

Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC diagnostic ignored "-Wunused-result"

#include <cstdio>
#include <chrono>
#include <random>
using namespace std;
using namespace chrono;

constexpr int c_max = 26;
constexpr int D = 365;
constexpr int INF = 1e9;
constexpr int time_limit = 1980;

int c[c_max];
int s[D][c_max];
int best_score[D];
int last[c_max];
int schedule[D];

inline int calc_score(const int &day, const int &examining) {
  int ret;
  if (day == 0) ret = s[day][examining];
  else ret = best_score[day - 1] + s[day][examining];
  
  for (int i = 0; i < c_max; i++) {
    if (i == examining) continue;
    ret -= (day - last[i]) * c[i];
  }

  return ret;
}

inline int calc_score_diff(const int &day1, const int &day2) {
  /*
  int prev_interval_1 = 0;
  for (int i = day1 - 1; i >= 0; i--) {
    prev_interval_1++;
    if (schedule[i] == schedule[day1]) break;
  }

  int prev_interval_2 = 0;
  for (int i = day2 - 1; i >= 0; i--) {
    prev_interval_2++;
    if (schedule[i] == schedule[day2]) break;
  }

  int new_interval_1 = 0;
  for (int i = day2 - 1; i >= 0; i--) {
    new_interval_1++;
    if (schedule[i] == schedule[day1]) break;
  }

  int new_interval_2 = 0;
  for (int i = day1 - 1; i >= 0; i--) {
    new_interval_2++;
    if (schedule[i] == schedule[day2]) break;
  }
  */
  int ret = s[day1][schedule[day2]]
          + s[day2][schedule[day1]]
          - s[day1][schedule[day1]]
          - s[day2][schedule[day2]];
  
  // ret += c[schedule[day1]] * ((prev_interval_1 + 1) * prev_interval_1 - (new_interval_1 + 1) * new_interval_1) / 2;
  // ret += c[schedule[day2]] * ((prev_interval_2 + 1) * prev_interval_2 - (new_interval_2 + 1) * new_interval_2) / 2;

  return ret;
}

int main() {
  system_clock::time_point start = system_clock::now(), now;

  random_device seed;
  mt19937 rnd(seed());

  /* input */
  scanf("%*d");

  for (int i = 0; i < c_max; i++) {
    scanf("%d", &c[i]);
  }

  for (int i = 0; i < D; i++) {
    for (int j = 0; j < c_max; j++) {
      scanf("%d", &s[i][j]);
    }
  }

  /* calc initial solution */
  for (int d = 0; d < D; d++) {
    int best = -INF;
    int contest_to_hold = 0;
    for (int type = 0; type < c_max; type++) {
      int score = calc_score(d, type);
      if (best < score) {
        best = score;
        contest_to_hold = type;
      }
    }
    last[contest_to_hold] = d;
    schedule[d] = contest_to_hold;
  }

  /* try and error */
  int day1, day2, score_diff;
  while (1) {
    now = system_clock::now();
    if (duration_cast<milliseconds>(now - start).count() > time_limit) break;
    day1 = rnd() % D;
    day2 = rnd() % D;
    score_diff = calc_score_diff(day1, day2);
    if (score_diff > 0) {
      swap(schedule[day1], schedule[day2]);
    }
  }

  /* output */
  for (const int &x : schedule) {
    printf("%d\n", x+1);
  }

  return 0;
}


Measured memory_bytes: 3384
#include <iostream>
#include <string>
#include <vector>
#define sz(a) (int)(a).size()
#define mod 1e9+7
using namespace std;

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



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,m;
	cin>>n>>m;
	vector<vector<char>> t(n,vector<char>(m));
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>t[i][j];
	vector<vector<ll>> dp(n,vector<ll>(m,0));
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(t[i][j]=='#')
				continue;
			if(j!=0)
				dp[i][j]=max(dp[i][j-1],dp[i][j]);
			if(i!=0)
				dp[i][j]=dp[i-1][j]+dp[i][j];
			dp[i][j]%=(ll)mod;
		}
	}
	cout<<dp[n-1][m-1]<<"\n";
}


Measured memory_bytes: 9088
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	string s;
	cin>>s;
	ll l=0,h=s.size()-1,flag=0;
	while(h>l)
	{
		if(s[l++]!=s[h--])
		flag=1;
	}
	ll si=s.size()-1;
	l=0;
	h=(si-1)/2;
	while(h>l)
	{
		if(s[l++]!=s[h--])
		flag=1;
	}
	h=si;
	l=(si+3)/2;
	while(h>l)
	{
		if(s[l++]!=s[h--])
		flag=1;
	}
	if(flag==1)
	cout<<"No"<<endl;
	else
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        
        vi data;
        rep(i,n){
            int a;
            cin>>a;
            data.pb(a);
        }
        sort(all(data));

        ll sum=0;
        int now=0;
        for(int i=0;i<data.size()-1;i++){
            now=now+data[i];
            sum+=now;
        }
        cout<<sum<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1320