akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define NMAX 200000
int UF_find(int, int*);
void UF_union(int, int, int*);
int main(void)
{
  int i, j, n, k, l, rdgrp = 0;
  int droot[NMAX], troot[NMAX], dleaf[NMAX], dnext[NMAX], trgrp[NMAX], trgcnt[NMAX], ans[NMAX] = {0};
  scanf("%d %d %d", &n, &k, &l);
  for (i = 0; i < n; i++) {
    droot[i] = troot[i] = -1;
    dleaf[i] = dnext[i] = -1;
    trgrp[i] = trgcnt[i] = 0;
  }
  for (i = 0; i < k; i++) {
    int p, q, proot, qroot;
    scanf("%d %d", &p, &q);
    UF_union(p - 1, q - 1, droot);
  }
  for (i = 0; i < l; i++) {
    int r, s, rroot, sroot;
    scanf("%d %d", &r, &s);
    UF_union(r - 1, s - 1, troot);
  }
  for (i = 0; i < n; i++) {
    int rd = UF_find(i, droot);
    dnext[i] = dleaf[rd];
    dleaf[rd] = i;
  }
  for (i = 0; i < n; i++) {
    if (dleaf[i] >= 0) {
      rdgrp++;
      for (j = dleaf[i]; j >= 0; j = dnext[j]) {
        int rt = UF_find(j, troot);
        if (trgrp[rt] == rdgrp) trgcnt[rt]++;
        else {
          trgrp[rt] = rdgrp;
          trgcnt[rt] = 1;
        }
      }
      for (j = dleaf[i]; j >= 0; j = dnext[j]) {
        int rt = UF_find(j, troot);
        ans[j] = trgcnt[rt];
      }
    }
  }
  for (i = 0; i < n; i++) printf("%d%c", ans[i], i == n - 1 ? '\n': ' ');
}

int UF_find(int a, int *ufp)
{
  if (ufp[a] < 0) return a;
  else {
    ufp[a] = UF_find(ufp[a], ufp);
    return ufp[a];
  }
}

void UF_union(int a, int b, int *ufp)
{
  a = UF_find(a, ufp);
  b = UF_find(b, ufp);
  if (a == b) return;
  if (ufp[a] < ufp[b]) {
    ufp[a] += ufp[b];
    ufp[b] = a;
  } else {
    ufp[b] += ufp[a];
    ufp[a] = b;
  }
}

Measured memory_bytes: 6144
import java.util.Scanner;

class Main {

	public static class Point {
		public double x;
		public double y;
		public Point(double x_, double y_) {
			x = x_; y=y_;
		}
	}
	
	public static class Line {
		public Point s,t;
		public Line(Point s_, Point t_) {
			s = s_; t = t_;
		}
	}
	
	public static Point crosspoint(Line l, Line m) {
		if(isParallel(l, m)){
			throw new IllegalArgumentException("parallel");
		}
		  double A = extp(sub(l.t, l.s), sub(m.t, m.s));
		  double B = extp(sub(l.t, l.s), sub(l.t, m.s));
		  if (Math.abs(A) < EPS && Math.abs(B) < EPS) return m.s;
		  if (Math.abs(A) < EPS) assert(false);
		  Point tp = sub(m.t, m.s);
		  return new Point(m.s.x + B/A*tp.x, m.s.y + B/A*tp.y);
	}
	
	public static boolean isParallel(Line l, Line m){
		Point a = new Point(l.t.x - l.s.x, l.t.y - l.s.y);
		Point b = new Point(m.t.x - m.s.x, m.t.y - m.s.y);
		if(Math.abs(Math.abs((a.x * b.x + a.y * b.y) / (Math.hypot(a.x, a.y)*Math.hypot(b.x, b.y)) - 1)) < EPS){
			return true;
		}
		return false;
	}
	
	public static Point sub(Point p1, Point p2) {
		return new Point(p1.x - p2.x, p1.y - p2.y);
	}
	
	public static double extp(Point p1, Point p2) {
		return p1.x * p2.y - p2.x * p1.y;
	}
	
	public static final double EPS = 1.0e-8;
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		while(t-- != 0){
			Point[] p = new Point[3];
			for(int i = 0; i < 3; i++)p[i] = new Point(scan.nextDouble(), scan.nextDouble());
			Point mid1 = new Point((p[0].x + p[1].x) / 2, (p[0].y + p[1].y) / 2);
			Point dv = new Point(p[1].x - p[0].x, p[1].y - p[0].y);
			Point cv = new Point(-dv.y, dv.x);
			Point c1 = new Point(mid1.x + cv.x, mid1.y + cv.y);
			Point mid2 = new Point((p[0].x + p[2].x) / 2, (p[0].y+p[2].y) / 2);
			dv = new Point(p[2].x - p[0].x, p[2].y - p[0].y);
			cv = new Point(-dv.y, dv.x);
			Point c2 = new Point(mid2.x + cv.x, mid2.y + cv.y);
			Point c = crosspoint(new Line(mid1, c1), new Line(mid2, c2));
			double r = Math.hypot(c.x - p[0].x, c.y - p[0].y);
			System.out.printf("%.3f %.3f %.3f\n", c.x, c.y, r);
		}
	}
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll ;

const ll inf = 1e9 + 17;
const int maxn = 1e5 + 10;
const int maxq = 1e2 + 10;
const int alf = 26;
const ll dlm = 1e9 + 7;
const int del = 998244353 ;
const int eps = 1e-7 ;

ll dp[maxq][maxn];
//      n      w
int we[maxq];
int co[maxq];

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,w;
    cin>>n>>w;
    for(int i=1;i<=n;i++){
        cin>>we[i];
        cin>>co[i];
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            dp[i][j] = dp[i-1][j];
            int vasn = we[i] ;
            int z = j-vasn;
            if((z)>=0){
                dp[i][j] = max(dp[i-1][z] + co[i],dp[i][j]);
            }
        }
    }
    for(int i=1;i<=w;i++){
        ans = max(ans,dp[n][i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 79360
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr ll MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

template <typename T>
T mypow(T a, T b)
{
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}

vector<ll> fact(200020, 1), inv(200020, 1);

ll comb(int n, int k)
{
    if (k < 0 || n < k)
        return 0;
    ll ret = fact[n] * inv[k] % MOD;
    return ret * inv[n - k] % MOD;
}

vector<int> ch(100010, 0);

void dfs(int cur, int pre, const vector<vector<int>> &g)
{
    if (pre != -1)
        ch[pre]++;
    for (auto v : g[cur])
    {
        if (v != pre)
            dfs(v, cur, g);
    }
}

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

    for (int i = 2; i <= 100000; i++)
    {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = mypow(fact[i], MOD - 2);
    }
    ll n, k;
    cin >> n >> k;
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0, -1, g);
    ll ret = k * comb(k - 1, ch[0]) % MOD;
    ret = ret * fact[ch[0]] % MOD;
    queue<P> que;
    for (auto v : g[0])
        que.emplace(v, 0);
    while (!que.empty())
    {
        int cur = que.front().first;
        int pre = que.front().second;
        que.pop();
        ret = ret * comb(k - 2, ch[cur]) % MOD;
        ret = ret * fact[ch[cur]] % MOD;
        for (auto v : g[cur])
        {
            if (v == pre)
                continue;
            que.emplace(v, cur);
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 12800
#include<iostream>

using namespace std;
int a[1000010]; 
int main() {
	int n;
	cin>>n;
	for(int i=1;i<100;i++) 
		for(int j=1;j<100;j++)
			for(int k=1;k<100;k++) {
				int t = i+j+k;
				t*=t;
				t-=i*j+i*k+j*k;
				a[t]++;
			}
	
	for(int i=1;i<=n;i++) printf("%d\n",a[i]);
	return 0;
}


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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount

ll a, b, x;

ll f(ll s){
    if(s==-1)return 0LL;
    return s/x+1;
}

int main() {
    cin>>a>>b>>x;
    cout<<f(b)-f(a-1)<<endl;
    
    return 0;
}

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

using namespace std;

int main()
{
  int n, r;
  while(cin >> n >> r, n || r){
    int deck[50];
    for(int i = 0; i < n; i++) deck[i] = n - i;
    while(r--){
      int p, c;
      cin >> p >> c;
      --p;
      int tmp[50];
      for(int i = 0; i < c; i++) tmp[i] = deck[p + i];
      for(int i = p + c - 1; i >= c; i--) deck[i] = deck[i - c];
      for(int i = 0; i < c; i++) deck[i] = tmp[i];
    }
    cout << deck[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
#define N 200010

int f[N];
int pos[N][26];
char s[N];

int main() {
	memset(f, 0x3f, sizeof(f));
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	for(int i = 0; i < 26; ++i) pos[n + 1][i] = n + 1;
	f[n + 1] = 1, f[n + 2] = 0;
	for(int i = n; i; i--) {
		for(int j = 0; j < 26; ++j) 
			pos[i][j] = pos[i + 1][j];
		pos[i][s[i] - 'a'] = i;
	}
	for(int i = n; i; i--) 
		for(int j = 0; j < 26; ++j)
			f[i] = min(f[i], f[pos[i][j] + 1] + 1);
	int now = 1;
	for(int j = f[1]; j; --j)
		for(int i = 0; i < 26; ++i) 
			if(f[now] == f[pos[now][i] + 1] + 1) {
				putchar(i + 'a');
				now = pos[now][i] + 1;
				break;
			}
}

Measured memory_bytes: 21504
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		boolean lastWrong = false;
		int ans = n;
		for(int i=0;i<n;i++) {
			if (s[i] == 'o') {
				lastWrong = false;
			}else{
				if (lastWrong) {
					ans = i;
					break;
				}
				lastWrong = true;
			}
		}
		System.out.println(ans);
	}

}



Measured memory_bytes: 29724
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  ll ans = 0;
  for(int i = 0; i < n; ++i){
    if(h[i] >= k) ans ++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ADiverseWord solver = new ADiverseWord();
        solver.solve(1, in, out);
        out.close();
    }

    static class ADiverseWord {
        static final char lower = 'a';
        static final char upper = 'z';
        static final int alphabetSize = upper - lower + 1;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            char[] chars = s.toCharArray();
            int n = chars.length;

            String answer = "-1";
            if (n < alphabetSize) {
                TreeSet<Character> available = new TreeSet<>();
                for (char c = lower; c <= upper; c++) {
                    available.add(c);
                }
                for (char c : chars) {
                    available.remove(c);
                }
                answer = s + available.first();
            } else {
                outer:
                for (int i = n - 1; i >= 0; i--) {
                    for (int j = n - 1; j > i; j--) {
                        if (chars[i] < chars[j]) {
                            char c = chars[i];
                            chars[i] = chars[j];
                            chars[j] = c;
                            answer = String.valueOf(chars);
                            answer = answer.substring(0, i + 1);
                            break outer;
                        }
                    }
                }
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 21460
#include<bits/stdc++.h>
#define maxn 2011
using namespace std;
bitset<2000100> f;
int a[maxn],n,sum;
inline int read(){
	int res=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')res=res*10+ch-48,ch=getchar();
	return res;
}
int main(){
	n=read();
	for(register int i=1;i<=n;i++){
		a[i]=read();
		sum+=a[i];
	}
	f[0]=1;
	for(register int i=n;i>=1;i--){//01
		f|=f<<a[i];
		}
		for(register int i=sum+1>>1;i<=sum;i++){
			if(f[i]){
				cout<<i;
				return 0;
			}
		}
	return 0;
}

Measured memory_bytes: 1024
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(long[]);

    if (N == 0) {
        writeln(AS[0] == 1 ? 1 : -1);
        return;
    }

    long r, c = 1;
    long[] BS;
    foreach (a; AS) {
        r += a;
        c -= a;
        if (c < 0) {
            writeln(-1);
            return;
        }
        BS ~= c;
        if (c <= c*2) {
            c *= 2;
        } else {
            c = 10L^^18;
        }
    }

    long d;
    foreach_reverse (i, a; AS[1..$]) {
        d = min(d + a, BS[i]);
        r += d;
    }

    writeln(r);
}

Measured memory_bytes: 6876
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
    u64 D, T, S;
    cin >> D >> T >> S;

    if((D + S - 1) / S <= T) {
        cout << "Yes" << endl;
    } else {
        cout << "No"  << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector> 
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    string s;
    int preSint,tmp;
    int n,k;
    vector<int> bi;
    vector<int> groupby;
    cin >> n >> k;
    cin >> s;
    
    k=2*k+1;
    preSint=s[0];
    tmp=0;

    for (int i=0;i<n;i++){
        bi.push_back(s[i]);
    }
    for (int i=0;i<n;i++){
        if (preSint==bi[i]){
            tmp=tmp+1;
        }else{
            groupby.push_back(tmp);
            tmp=1;
            preSint=bi[i];
        }
    }
    groupby.push_back(tmp);
    //仮想の1追加フェイズ
    if (bi[n-1]==48){
        groupby.insert(groupby.end(),0);
    }
    if (bi[0]==48){
        groupby.insert(groupby.begin(),0);
    }
    
    
    vector<int> x1; //x1 はgroupbyのkから
    vector<int> x2; //x2 はgroupbyのn-kまで
    vector<int> ruiseki; //累積前
    int x3,Gn;         
    x3=0;
    Gn=groupby.size();
    //cout<<Gn;
    for (int i=k ; i<Gn+1 ; i++){
        x1.push_back(groupby[i]);
    }
    for (int i=0 ; i<Gn-k+1 ; i++){
        x2.push_back(groupby[i]);
    }
    int m;
    m = min<unsigned long>(k,groupby.size());
    for (int i=0 ; i<m  ; i++){
        x3=x3+groupby[i];
        //cout<<x3;
    }
    
    //for (int i=0;i<groupby.size();i++){
    //    cout<<groupby[i]<<endl;
    //}
    
    //ここまであってる
    for (int i=0 ; i<Gn-k+1 ; i++){
        ruiseki.push_back(x1[i]-x2[i]);
        //cout<<ruiseki[i];
    }
    for (int i=1 ; i<ruiseki.size() ; i++){
        ruiseki[i]=ruiseki[i-1]+ruiseki[i];
        //cout<<ruiseki[i];
    }
    for (int i=0 ; i<ruiseki.size() ; i++){
        ruiseki[i]=ruiseki[i]+x3;
    }
    ruiseki.insert(ruiseki.begin(),x3);
    //for (int i=0 ; i<ruiseki.size() ; i++){
    //    cout<<ruiseki[i];
    //}
    
    vector<int> ans;
    for (int i=0 ; i<ruiseki.size() ; i++){
        if (i%2==0){
            ans.push_back(ruiseki[i]);
        }
    }
    cout<<*max_element(ans.begin(),ans.end())<<endl;
}
    

Measured memory_bytes: 2808
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int n;
VI g[110];
int d[110];
int f[110];


void dfs(int v, int p, int& t){
    d[v] = t;
    t++;
    rep(i, 0, SZ(g[v])) if(g[v][i] != p and d[g[v][i]] == 0) dfs(g[v][i], v, t);
    f[v] = t;
    t++;
}


signed main(){
    cin >> n;
    rep(i, 0, n){
        int u, k;
        cin >> u >> k;
        u--;
        int v;
        rep(j, 0, k) cin >> v, g[u].pb(v-1);
    }

    int t = 1;
    rep(i, 0, n) if(d[i] == 0) dfs(i, -1, t);

    rep(i, 0, n) cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;

    return 0;
}


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

using namespace std;

typedef long long int ll;

const ll MAXN = 1e4 + 5;

vector < vector < ll > > adj(MAXN, vector < ll > ());
vector < ll > val(MAXN), v;

ll ans = 0;
void dfs(ll u, ll p){
  val[u] = v.back();
  v.pop_back();
  for(auto to : adj[u]){
    if(to != p){
      dfs(to, u);
      ans += min(val[to], val[u]);
    }
  }
}

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

  ll n;
  cin >> n;
  vector < ll > deg(n + 1, 0);
  set < ll > score;
  for(int i = 0; i < n - 1; i++){
    ll u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  for(int i = 0; i < n; i++){
    ll a; cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());

  dfs(1, -1);

  cout << ans << '\n';
  for(int i = 1; i <= n; i++) cout << val[i] << " ";
  cout << '\n';
}


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

using namespace std;

string dfs(string s, string op) {
  if (op.length() == 3) {
    int sum = s[0] - '0';
    stringstream ss;
    ss << s[0];
    for (int i = 0; i < 3; i++) {
      ss << op[i] << s[i+1];
      if (op[i] == '+') {
        sum = sum + (s[i+1] - '0');
      } else {
        sum = sum - (s[i+1] - '0');
      }
    }
    if (sum == 7) {
      ss << "=7";
      return ss.str();
    } else {
      return "";
    }
  }

  string t = dfs(s, op + "+");
  if (t.length() > 0) {
    return t;
  } else {
    return dfs(s, op + '-');
  }
}

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

  cout << dfs(s, "") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <array>

using namespace std;

const int maxn=2e5+5;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int a;
	int id=1;
	for(int i=0; i<n; i++){
		cin >> a;
		if(a==id){
			id++;
		}
	}
	if(id==1){
		cout << -1 << '\n';
	}
	else{
		cout << n-id+1 << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a<b&&b<c){printf("%d %d %d\n",a,b,c);
	}
		else if(c<b&&b<a){printf("%d %d %d\n",c,b,a);
		}
		else if(b<a&&a<c){printf("%d %d %d\n",b,a,c);
		}
		else if(c<a&&a<b){printf("%d %d %d\n",c,a,b);
		}
		else if(a<c&&c<b){printf("%d %d %d\n",a,c,b);
		}
		else if(b<c&&c<a){printf("%d %d %d\n",b,c,a);
		}
		else if(a==b&&a<c){printf("%d %d %d\n",a,b,c);
		}
		else if(a==c&&a<b){printf("%d %d %d\n",a,c,b);
		}
		else if(b==c&&b<a){printf("%d %d %d\n",b,c,a);
		}
		
		else if(a==b&&a>c){printf("%d %d %d\n",c,a,b);
		}
		else if(a==c&&a>b){printf("%d %d %d\n",b,a,c);
		}
		else if(b==c&&b>a){printf("%d %d %d\n",a,b,c);
		}
		
		else {printf("%d %d %d\n",a,b,c);
		}
	return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

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

    std::string s;
    int64_t k;
    cin >> s;
    cin >> k;
    for (int i = 0; i < k; i++) {
        if (s[i] != '1') {
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << '1' << endl;

    return 0;
}


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

int64_t question(int l, int r){
    cout << "? " << l + 1 << " " << r + 1 << endl;
    int64_t res;
    cin >> res;
    return res;
}

void output(vector<int> &A){
    cout << "!";
    for (const auto &a: A)
        cout << " " << a;
    cout << endl;
}

ll INF = 1e9+7;
ll N, dat[2222222];
void init(ll k){
    N = 1;
    while(N < k) N *= 2;
    for(ll i=0;i<2*N-1;i++) dat[i] = 0;
}

void update(ll k, ll num){
    k += N-1;
    dat[k] = num;
    while(k>0){
        k = (k-1)/2;
        dat[k] = dat[k*2 + 1] + dat[k*2+2];
    }
}

// query(a,b,0,0,n) → [a,b)
ll query(ll a, ll b, ll k, ll l, ll r){
    if(r<=a || b<=l) return 0;
    if(a<=l && r<=b) return dat[k];
    else{
        ll vl = query(a,b,k*2+1,l,(l+r)/2);
        ll vr = query(a,b,k*2+2,(l+r)/2,r);
        return vl+vr;
    }
}


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

    int n;
    cin >> n;
    vector<int64_t> D(n);
    int64_t prev = 0;
    for (int i = 1; i < n; i++){
        auto res = question(0, i);
        D[i] = res - prev;
        prev = res;
    }
    init(n + 1);

    auto check = [&](auto k, auto d){
        return d < query(k, n + 1, 0, 0, N);
    };

    auto b_serach = [&](auto ok, auto ng, auto check, auto d){
        while (abs(ok - ng) > 1){
            auto mid = (ok + ng) / 2;
            (check(mid, d) ? ok : ng) = mid;
        }
        return ok;
    };

    for (int i = 1; i <= n; i++)
        update(i, 1);
    vector<int> ans(n);
    
    for (int i = n - 1; i >= 0; i--){
        int res = b_serach(0, n + 2, check, D[i]);
        update(res, 0);
        ans[i] = res;
    }

    output(ans);
}


Measured memory_bytes: 288908
#include <cstdio>
#include <algorithm>
#include <ctype.h>
const int bufSize = 1e6;
inline char nc()
{
    #ifdef DEBUG
    return getchar();
    #endif
    static char buf[bufSize], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2) ? EOF : *p1++;
}
inline void read(char *s)
{
    static char c;
    for (; !isalpha(c); c = nc());
    for (; isalpha(c); c = nc()) *s++ = c;
    *s = '\0';
}
template<typename T>
inline T read(T &r)
{
    static char c;
    static int flag;
    flag = 1, r = 0;
    for (c = nc(); !isdigit(c); c = nc()) if (c == '-') flag = -1;
    for (; isdigit(c); c = nc()) r = r * 10 + c - 48;
    return r *= flag;
}
const int maxn = 2e5 + 100;
int n;
long long a[maxn];
int main()
{
    read(n);
    for (int i = 1; i <= n; ++i) read(a[i]);
    long long ans = 0;
    for (int i = 1; i <= n; ++i) if(a[i] < a[i-1]) ans += a[i-1] - a[i],a[i] = a[i-1];
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 5764
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;

namespace INPUT{
	const int L=1<<15;
	char _buf[L],*S,*T,c;
	char _gc(){
		if(S==T){
			T=(S=_buf)+fread(_buf,1,L,stdin);
			if(S==T) return EOF;
		}
		return *S++;
	}
	void readi(int &X){
		register bool flag;
		for(c=_gc();(c<'0'||c>'9')&&c!='-';c=_gc());
		if(c=='-') X=0,flag=true; else X=c&15,flag=false;
		for(c=_gc();c>='0'&&c<='9';X=X*10+(c&15),c=_gc());
		if(flag) X=-X;
	}
}
using INPUT::readi;

const int Maxn=4E5+5;

int N,M,K,V;
int a[Maxn];
int F[Maxn],G[Maxn];
int L[25][Maxn],R[25][Maxn];
//char Ans[50],_1[50]={"Possible"},_2[50]={"Impossible"};
int nxt[Maxn];

inline void MIN(int &x,int y){if(x>y)x=y;}
inline void MAX(int &x,int y){if(x<y)x=y;}

int main(){
	readi(N),readi(V);
	while(V>>M) ++M;
	for(int i=1;i<=N;++i) readi(a[i]);
	for(int i=0;i<=M;++i){
		L[i][1]=1;
		for(int j=2;j<=N;++j)
			if(a[j]-a[j-1]>(V>>i)) L[i][j]=j;
		for(int j=2;j<=N;++j)
			if(L[i][j]==0) L[i][j]=L[i][j-1];
		
		R[i][N]=N;
		for(int j=N-1;j>=1;--j)
			if(a[j+1]-a[j]>(V>>i)) R[i][j]=j;
		for(int j=N-1;j>=1;--j)
			if(R[i][j]==0) R[i][j]=R[i][j+1];
	}
	G[0]=N+1;
	for(int i=1;i<(1<<M);++i){
		G[i]=N+1;
		for(int j=0;j<M;++j)
			if((i>>j)&1)
				MAX(F[i],R[M-j][min(F[i-(1<<j)]+1,N)]),
				MIN(G[i],L[M-j][max(G[i-(1<<j)]-1,1)]);
	}
/*	for(int i=1;i<=N;++i)
		K+=(L[0][i]!=L[0][i-1]);
	if(K>20){
		for(int i=1;i<=N;++i)
			puts("Impossible");
		return 0;
	}
	for(int i=1,j;i<=N;++i)
		if(L[0][i]!=L[0][i-1]){
			for(j=0;j<(1<<M);++j)
				if(F[j]>=L[0][i]-1 && G[(1<<M)-1-j]<=R[0][i]+1)
					{memcpy(Ans,_1,sizeof(_1)); break ;}
			if(j==1<<M) memcpy(Ans,_2,sizeof(_2));
			printf("%s\n",Ans);
		}else printf("%s\n",Ans);*/
	memset(nxt,-1,sizeof(nxt));
	for(int i=0;i<(1<<M);++i) MAX(nxt[G[(1<<M)-1-i]],F[i]);
	for(int i=1;i<=N+1;++i) MAX(nxt[i],nxt[i-1]);
	for(int i=1;i<=N;++i)
		if(nxt[R[0][i]+1]>=L[0][i]-1)
			puts("Possible");
		else
			puts("Impossible");
	return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int kohei = a * b;
 
    if (kohei % 2 == 1){
      cout << "Odd" << endl;
    }
  
    else if (kohei % 2 == 0){
      cout << "Even" <<endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
main()
{
	long int n, w, i, a, x, s=0, p=100010;
	scanf("%ld%ld", &n, &w);
	i=n;
	while (i--)
	{
		scanf("%ld", &a);
		s=s+a;
		if (a<p)
		{
			p=a;
		}
	}
	x=(w-s)/p;
	printf("%ld\n", x+n);
	return 0;
}

Measured memory_bytes: 128
H, W = map(int, input().split())
A = []
for _ in range(H):
    row = [{'.': 0, '#': 1}[c] for c in input()]
    if 0 < sum(row):
        A.append(row)
for x in range(W - 1, -1, -1):
    if sum(A[i][x] for i in range(len(A))) == 0:
        for y in range(len(A)):
            A[y][x:x + 1] = []
for row in A:
    print(''.join(['.' if v == 0 else '#' for v in row]))

Measured memory_bytes: 9112
let scan2 f = stdin.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
let scanVecH f = stdin.ReadLine().Split() |> Array.map f
 
let n, k = scan2 int
let data = scanVecH int
 
let f x1 x2 = abs (x2 - x1) + (min (abs x1) (abs x2))
 
seq { 0..n-k }
|> Seq.map (fun i -> f data.[i] data.[i+k-1])
|> Seq.min
|> printfn "%d"

Measured memory_bytes: 23004
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        long[] l = new long[5] {0,0,0,0,0};
       for(int i = 0; i < n; i ++) {
           string s = Console.ReadLine();
           if(s[0]=='M') l[0] ++;
           if(s[0]=='A') l[1] ++;
           if(s[0]=='R') l[2] ++;
           if(s[0]=='C') l[3] ++;
           if(s[0]=='H') l[4] ++;
       }
       Console.WriteLine(solve(l));
    }
    static long solve(long[] l) {
        long count = 0;
        count += l[0] * l[1] * (l[2]+l[3]+l[4]);
        count += l[0] * l[2] * (l[3]+l[4]);
        count += l[0] * l[3] * l[4];
        count += l[1] * l[2] * (l[3]+l[4]);
        count += l[1] * l[3] * l[4];
        count += l[2] * l[3] * l[4];
        return count;
    }
}

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


int64_t gcd(int64_t a,int64_t b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
int64_t lcm(int64_t a,int64_t b){
  return a/gcd(a,b)*b;
}


int main() {

	int n;
	cin >> n;
	vector<int64_t> data(n);
	for(int i=0; i<n; i++){
		cin >> data.at(i);
	}

	int64_t num = data.at(0);
	for(int i=0; i<n; i++){
		num = lcm(num, data.at(i));
	}
	
	cout << num <<endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  int sum=0;
  rep(i,n) {cin>>a[i]; sum+=a[i];}
  sort(a.rbegin(),a.rend());
  double mini = ((double)sum)/((double)(4*m));
  rep(i,m){
    if(a[i]<mini){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

ll n;
ll a[(1 << 18)];
pair <ll, ll> s[(1 << 18)][2];

int main()
{
    cin >> n;
    for (int i = 0; i < (1 << n); i++)
    {
        cin >> a[i];
        s[i][0] = {a[i], i};
        s[i][1] = {-1, -1};
    }
    ll ans = -1;
    for (int i = 1; i < (1 << n); i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (!(i & (1 << j)))
                continue;
            int k = i - (1 << j);
            for (int l = 0; l <= 1; l++)
            {
                if (s[k][l].second == s[i][0].second || s[k][l].second == s[i][1].second)
                    continue;
                if (s[k][l].first > s[i][0].first)
                {
                    s[i][1] = s[i][0];
                    s[i][0] = s[k][l];
                }
                else if (s[k][l].first > s[i][1].first)
                    s[i][1] = s[k][l];
            }
        }
        ans = max(ans, s[i][0].first + s[i][1].first);
        cout << ans << "\n";
    }
}


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

bool isMale() {
    string result;
    cin >> result;
    if (result == "Vacant") {
        exit(0);
    }
    return result == "Male";
}

int main() {
    int N;
    cin >> N;
    int left = 0;
    int right = N - 1;
    cout << 0 << endl;
    bool leftMale = isMale();
    cout << N - 1 << endl;
    bool rightMale = isMale();
    while (left < right) {
        int mid = (left + right) / 2;
        cout << mid << endl;
        bool midMale = isMale();
        bool vacantLeft = false;
        bool vacantRight = false;
        if ((mid - left) % 2 == 0) {
            if (leftMale != midMale) {
                vacantLeft = true;
            }
        } else {
            if (leftMale == midMale) {
                vacantLeft = true;
            }
        }
        if ((right - mid) % 2 == 0) {
            if (rightMale != midMale) {
                vacantRight = true;
            }
        } else {
            if (rightMale == midMale) {
                vacantRight = true;
            }
        }
        if (vacantLeft) {
            right = mid;
            rightMale = midMale;
        } else {
            left = mid;
            leftMale = midMale;
        }
    }
}

Measured memory_bytes: 852
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
N=int(input())
if N==1:
    print(0)
else:
    l=[]
    for i in range(0,len(factorization(N))):
        l.append(factorization(N)[i][1])
    l.sort(reverse=True)
    s=0
    t=1
    while l[0]>0:
        for i in range(0,len(l)):
            if l[i]>=t:
                s += 1
            l[i]-=t
        t+=1
    print(s)

Measured memory_bytes: 9508
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

const int MAX_N = 110;
char A[MAX_N], B[MAX_N], C[MAX_N];
int num[MAX_N][30];

int main()
{
    int N;
    scanf("%d", &N);
    scanf("%s %s %s", A, B, C);
    for(int i = 0; i < N; ++i) ++num[i][A[i]-'a'], ++num[i][B[i]-'a'], ++num[i][C[i]-'a'];

    int res = 0;
    for(int i = 0; i < N; ++i) {
        int tmp = 3;
        for(int j = 0; j < 26; ++j) tmp = min(tmp, 3 - num[i][j]);
        res += tmp;
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{

int x, a;
scanf("%d %d", &x, &a);

    if(x==2||a==2){
        printf("No\n");
    }
    else if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(a==1||a==3||a==5||a==7||a==8||a==10||a==12))
    {
        printf("Yes\n");
    }
    else if((x==4||x==6||x==9||x==11)&&(a==4||a==6||a==9||a==11))
    {
        printf("Yes");
    }
    else{
        printf("No");
    }

return 0;

}

Measured memory_bytes: 1648
#define RangeFor(i,n) for(int i=0; i<n; ++i)
#define RvRngFor(i,n) for(int i=n-1; i>=0; --i)

#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <limits>

using std::vector;
using std::cin;
using std::priority_queue;
using std::pair;
using std::make_pair;


vector<int> sssp(vector<vector<pair<int, int> > > c, int start_node = 0){
    int n = c.size();
    priority_queue<pair<int, int>, vector<pair<int,int> >, std::greater<pair<int, int>> > pq;
    vector<int> temp_dist(n, std::numeric_limits<int>::max());
    pq.push(make_pair(0, start_node));

    for(;!pq.empty();){
        auto t = pq.top(); pq.pop();
        auto d = t.first;
        auto u = t.second;


        if(d < temp_dist[u]){
            temp_dist[u] = d;
            auto k = c[u].size();
            RangeFor(j, k) {
                pq.push(make_pair(d + c[u][j].second, c[u][j].first));
            }
        }
    }

    return temp_dist;
}

int main(){
    int n; cin >> n;
    vector<vector< pair<int,int> > > c(n);
    RangeFor(_, n) {
        int u;
        cin >> u;
        int k;
        cin >> k;
        c[u] = vector<pair<int, int> >(k);
        RangeFor(j, k) {
            int v;
            cin >> v;
            int d;
            cin >> d;
            c[u][j] = make_pair(v, d);
        }
    }

//    RangeFor(i, n){
//        RangeFor(j, c[i].size()){
//            std::cout << c[i][j].first << ' ' << c[i][j].second;
//        }
//        std::cout << std::endl;
//    }

    auto res = sssp(c);
    RangeFor(i, n){
        std::cout << i << ' ' << res[i] << std::endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long int;

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

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

int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    ll b_range = B - (B/C) - (B/D) + (B/gcd(C,D));
    A -= 1;
    ll a_range = A - (A/C) - (A/D) + (A/gcd(C,D));

    cout << (b_range - a_range) << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:256000000")
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

int const mod = 1e9 + 7;
namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}
	ll poww(ll a, ll b){
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}


int const maxn = 2e5 + 5;

ll fact[maxn];

ll C(ll n, ll k) {
	if (n < k) return 0;
	return mul(fact[n], inv(mul(fact[n - k], fact[k])));
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	fact[0] = 1;
	for (ll i = 1; i < maxn; i++) fact[i] = (fact[i - 1] * i) % mod;
	ll n, m, k; cin >> n >> m >> k;
	ll sum_xs = 0;
	for (ll dl = 0; dl <= n; dl++) {
		ll cnt_pairs = max(0LL, n - dl);
		cnt_pairs = mul(cnt_pairs, mul(m, m));
		(sum_xs += mul(cnt_pairs, dl)) %= mod;
	}
	ll sum_ys = 0;
	for (ll dl = 0; dl <= m; dl++) {
		ll cnt_pairs = max(0LL, m - dl);
		cnt_pairs = mul(cnt_pairs, mul(n, n));
		(sum_ys += mul(cnt_pairs, dl)) %= mod;
	}
	ll ans = mul((sum_xs + sum_ys) % mod, C(n * m - 2, k - 2));
	cout << ans;
	return 0;
}
/*

*/

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

using namespace std;

int main()
{
	int N, Z, W;
	cin >> N >> Z >> W;

	vector<long long> a(N);
	for (auto& x : a) {
		cin >> x;
	}

	if (N == 1) {
		cout << abs(a[0] - W) << endl;
	}
	else {
		auto ans = max(abs(a[N - 1] - W), abs(a[N - 2] - a[N - 1]));
		cout << ans << endl;
	}
}


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

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )

typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int N=1e5+10, M=(ll)1e9+1 ;
const int mod = 1e9+7;

vl g[3*N],vis(3*N,0);

ll bfs(ll s,ll t){
    queue<pll>q;
    q.push({s,0});
    vis[s]=1;
    while(!q.empty()){
        ll u=q.front().f,dist=q.front().s;
        q.pop();
//        vis[u]=1;
        if(u==t){
            return dist;
        }
        for(auto &it:g[u]){
            if(!vis[it]){
                vis[it]=1;
                q.push({it,dist+1});
            }
        }
    }
}

void work(){
    ll n,m;
    cin >> n >> m;
    for(ll i=1;i<=m;i++){
        ll u,v;
        cin >> u >> v;
        g[u].pb(v+n);
        g[u+n].pb(v+2*n);
        g[u+2*n].pb(v);
    }
    ll s,t;
    cin >> s >> t;
    ll ans=-1;
    ans=bfs(s,t);
    if(vis[t]==0)
        cout << -1;
    else{
        cout << ans/3;
    }
}

int main(){
 ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t,z;
//     cin >> t;
    // z=t;
    t=1;
    while(t--){
            // cout << "Case #" << z-t << ": ";
            work();
    }
   return 0;

}


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

using namespace std;


int main() {
    int n;
    cin>>n;
    
    // vector<int> v;
    // v.push_back(1);
    // v.push_back(2);
    // v.push_back(6);
    // v.push_back(24);
    // v.push_back(120);
    //  v.push_back(720);
    // v.push_back(5040);
    // v.push_back(40320);
    // v.push_back(362880);
    
    
    cout<<n*n*n;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    string S[N];
    for (int i = 0; i < N; i++)
    {
        cin >> S[i];
    }

    sort(S, S + N);

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans++;
        if (i < (N - 1))
        {
            while (S[i] == S[i + 1])
            {
                i++;
            }
            
        }
        
    }

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

Measured memory_bytes: 9844
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx,avx2")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ld long double
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 3010;

int dp[maxn][maxn][4];
int a[maxn][maxn];

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

    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++) {
        int x, y, v;
        cin >> x >> y >> v;
        a[x][y] = v;
    }
    dp[1][1][1] = a[1][1];
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            for (int cnt = 0; cnt <= 3; cnt++) {
                if (i + 1 <= n) {
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][cnt]);
                    dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][cnt] + a[i + 1][j]);
                }
                if (j + 1 <= m) {
                    dp[i][j + 1][cnt] = max(dp[i][j + 1][cnt], dp[i][j][cnt]);
                    if (cnt + 1 <= 3) {
                        dp[i][j + 1][cnt + 1] = max(dp[i][j + 1][cnt + 1], dp[i][j][cnt] + a[i][j + 1]);
                    }
                }
            }
        }
    }
    cout << max({dp[n][m][0], dp[n][m][1], dp[n][m][2], dp[n][m][3]}) << "\n";

    return 0;
}

Measured memory_bytes: 356052
L, R = list(map(int, input().split(' ')))
#print(L, R)

min = 2019
for i in range(L, R):
    for j in range(i + 1, R + 1):
        mod_ij = (i * j) % 2019
        if min > mod_ij:
            min = mod_ij
            if min == 0:
                break
    if min == 0:
        break

print(min)

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

using namespace std;

typedef long long ll;

int n, gx, sx, bx, gy, sy, by;

ll F[25000010];

int main() {
	scanf("%d%d%d%d", &n, &gx, &sx, &bx);
	scanf("%d%d%d", &gy, &sy, &by);
	int o = (gx <= gy) + (sx <= sy) + (bx <= by);
	if(o == 3) {
		// 3
		F[0] = 0;
		for(int i = 1; i <= n; i++) {
			F[i] = F[i - 1] + 1;
			if(i >= gx) F[i] = max(F[i], F[i - gx] + gy);
			if(i >= sx) F[i] = max(F[i], F[i - sx] + sy);
			if(i >= bx) F[i] = max(F[i], F[i - bx] + by);
		}
		printf("%lld\n", F[n]);
		return 0;
	} else if(o == 2) {
		if(sx > sy) swap(gx, sx), swap(gy, sy);
		if(bx > by) swap(gx, bx), swap(gy, by);
		F[0] = 0;
		for(int i = 1; i <= n; i++) {
			F[i] = F[i - 1] + 1;
			if(i >= sx) F[i] = max(F[i], F[i - sx] + sy);
			if(i >= bx) F[i] = max(F[i], F[i - bx] + by);
		}
		printf("%lld\n", F[n] % gy + F[n] / gy * gx);
		return 0;
	} else if(o == 1) {
		if(sx <= sy) swap(gx, sx), swap(gy, sy);
		if(bx <= by) swap(gx, bx), swap(gy, by);
		F[0] = 0;
		ll tmp = n / gx * gy + n % gx;
		for(int i = 1; i <= tmp; i++) {
			F[i] = F[i - 1] + 1;
			if(i >= sy) F[i] = max(F[i], F[i - sy] + sx);
			if(i >= by) F[i] = max(F[i], F[i - by] + bx);
		}
		printf("%lld\n", F[tmp]);
	} else {
		F[0] = 0;
		for(int i = 1; i <= n; i++) {
			F[i] = F[i - 1] + 1;
			if(i >= gy) F[i] = max(F[i], F[i - gy] + gx);
			if(i >= sy) F[i] = max(F[i], F[i - sy] + sx);
			if(i >= by) F[i] = max(F[i], F[i - by] + bx);
		}
		printf("%lld\n", F[n]);
		return 0;
	}
	return 0;
}

Measured memory_bytes: 194816
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;

int main() {
	int N, D, X;
	cin >> N >> D >> X;

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

	int ans = N;
	for (int i = 0; i < N; i++) {		//iは合宿に参加した人数
		for (int j = 1; j < D; j++) {	//jは合宿の日数
			if (j * vec[i] + 1 <= D) {
				ans = ans + 1;
				//continue;
			}
			else if (j * vec[i] + 1 > D) {
				//break;
			}
		}
	}
	cout << ans + X << endl;
}


Measured memory_bytes: 256
class UnionFindTree:
    '''
    Union Find木の実装
    ランクは無視する
    '''
    
    def __init__(self, n):
        '''ノード数nで初期化'''
        # nodes[i] < 0 すなわち各ノードは自身が根
        # 根の値はその木の要素数の符号反転したもの
        self.nodes = [-1] * n

    def is_root(self, idx):
        '''根ならTrue、根以外ならFalse'''
        return self.nodes[idx] < 0
        
    def is_same_group(self, idxA, idxB):
        return self.root(idxA) == self.root(idxB)
    
    def size(self, idx):
        '''ノードを含むグループのノード数を返す'''
        return -self.nodes[self.root(idx)]

    def union(self, idxA, idxB):
        '''ノードAを含む木とノードBを含む木を結合'''
        a = self.root(idxA)
        b = self.root(idxB)

        size_a = self.size(idxA)
        size_b  =self.size(idxB)

        # b番目のノードの根をaにする
        if a != b:
            self.nodes[b] = a
            self.nodes[a] -= size_b
    
    def root(self, idx):
        '''ノードの根番号を返す。途中で経路圧縮を行う'''
        
        # 探索
        _idx = idx
        while not self.is_root(_idx):
            _idx = self.nodes[_idx]
        root_idx = _idx

        # 経路圧縮
        _idx = idx
        while root_idx != _idx:
            tmp = _idx
            _idx = self.nodes[_idx]
            self.nodes[tmp] = root_idx

        return root_idx
###========================

N, M = map(int, input().split())
A = []
B = []
for i in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


tree = UnionFindTree(N)

hubensa_list = [None] * M
hubensa_list[M-1] = N * (N-1) // 2

for i in range(M-2, -1, -1):
    if tree.is_same_group(A[i+1]-1, B[i+1]-1):
        hubensa_list[i] = hubensa_list[i+1]    
    else:
        sa = tree.size(A[i+1]-1)
        sb = tree.size(B[i+1]-1)
        hubensa_list[i] = hubensa_list[i+1] - sa * sb
    tree.union(A[i+1]-1, B[i+1]-1)

for x in hubensa_list:
    print(x)

Measured memory_bytes: 19492