akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
using namespace std;

typedef pair<int, int> P;
int w, h, n;

int x1[1005] = { 0 }, x2[1005] = { 0 };
int Y1[1005] = { 0 }, Y2[1005] = { 0 };
int dy[] = { 0,-1,0,1 }, dx[] = { 1,0,-1,0 };
int f[3005][3005] = { 0 };
int compress(int *x1, int *x2, int w) {
	vector<int>xs;
	for (int i = 0; i < n; i++) {
		for (int d = -1; d <= 1; d++) {
			int tx1 = x1[i] + d;
			int tx2 = x2[i] + d;
			if (0 <= tx1&&tx1 < w) xs.push_back(tx1);
			if (0 <= tx2&&tx2 < w) xs.push_back(tx2);
			
		}
	}
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	for (int i = 0; i < n; i++) {
		x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
		x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
	}
	return xs.size();
}

int main() {
	while (true) {
		
		cin >> w >> h;
		if (w == 0 && h == 0) return 0;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> x1[i] >> Y1[i] >> x2[i] >> Y2[i];
			x2[i]--;
			Y2[i]--;
		}
		w = compress(x1, x2, w);
		h = compress(Y1, Y2, h);
		//int f[3005][3005] = { 0 };
		//memset(f, false, sizeof(f));
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				f[i][j] = 0;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int y = Y1[i]; y <= Y2[i]; y++) {
				f[y][x1[i]]++;
				f[y][x2[i] + 1]--;

			}
		}
		for (int i = 0; i < h; i++) {
			for (int j = 1; j < w; j++) {
				f[i][j] += f[i][j - 1];
			}
		}
		int ans = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (f[i][j] == 0) {
					ans++;
					queue<P>que;
					que.push(P(i, j));
					f[i][j] = 1;
					while (!que.empty()) {
						P p = que.front();
						que.pop();
						int y = p.first;
						int x = p.second;
						//f[y][x] = 1;
						for (int u = 0; u < 4; u++) {
							int ny = y + dy[u];
							int nx = x + dx[u];
							if (0 <= ny&&ny < h && 0 <= nx&&nx < w && f[ny][nx] == 0) {
								que.push(P(ny, nx));
								f[ny][nx] = 1;
							}
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}



Measured memory_bytes: 15164
#include <stdio.h>

#define arr_print_d0dn(a, n) for(int i=0;i<(n);++i)printf(i==(n)-1?"%d\n":"%d ",(a)[i])

int selection_sort(int *a, const int N) {
    int cnt = 0;
    for(int i = 0; i < N; ++i) {
        int mini = i;
        for(int j = i + 1; j < N; ++j) {
            // pick minimum index
            if(a[j] < a[mini]) mini = j;
        }
        // swap minimum and current key
        if(i != mini) {
            int tmp = a[i];
            a[i] = a[mini];
            a[mini] = tmp;
            cnt++;
        }
    }
    return cnt;
}

int main() {
    int n;
    scanf("%d", &n);
    int a[n];
    for(int i = 0; i < n; ++i) scanf("%d", a + i);
    int cnt = selection_sort(a, n);
    arr_print_d0dn(a, n);
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 2080
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
int main(void){
    int R;
    cin>>R;
    cout<<2*R*M_PI<<endl;
}

Measured memory_bytes: 3784
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, x[100] = {}, sum = 0, p1, p2, ans1 = 0, ans2 = 0;
   cin >> n;
   FOR(i, 0, n)
   {
      cin >> x[i];
      sum += x[i];
   }
   p1 = sum / n;
   p2 = p1 + 1;

   FOR(i, 0, n)
   {
      ans1 += (x[i] - p1) * (x[i] - p1);
      ans2 += (x[i] - p2) * (x[i] - p2);
   }

   cout << min(ans1, ans2) << endl;

   return 0;
}


Measured memory_bytes: 256
import scala.annotation.tailrec

object Main extends App {
  val k = io.StdIn.readInt()

  def next(n: Long, digit: Long): Long = {
    @tailrec
    def loop(d: Long, a: Long, x: Long): Long = {
      if (d <= 1) x
      else {
        val dd = d / 10
        val b = (x % d) / dd
        if (Math.abs(a - b) > 1) {
          if (a < b) {
            val m = n - n % d + d
            loop(digit, m / digit, m)
          } else {
            loop(dd, a - 1, x - (b * dd) + ((a - 1) * dd))
          }
        }
        else loop(dd, b, x)
      }
    }
    loop(digit, n / digit, n)
  }

  def solve(): Long = {
    var count = 0
    var d: Long = 1
    var current: Long = 0
    while (count < k) {
      current += 1
      if (d * 10 <= current) d *= 10
      current = next(current, d)
      count += 1
    }
    current
  }

  println(solve())
}

Measured memory_bytes: 27208
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.setf(ios_base::fixed);
	cout.precision(8);

	int n;
	double a, m;
	int s[1000];
	while(true) {
		cin>>n;
		if(n==0) break;
		a=0;
		m=0;
		for(int i=0; i<n; i++) {
			cin>>s[i];
			m+=s[i];
		}
		m/=n;
		for(int i=0; i<n; i++) {
			a+=(s[i]-m)*(s[i]-m);
		}
		a/=n;
		cout<<sqrt(a)<<'\n';
	}
	return 0;
}




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

int N,X;
int main(){
    cin >> N >> X;
    int d = 0,ans = 1;
    int L;
    for(int i=1;i<=N;i++){
        cin >> L;
        d += L;
        if(d<=X) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

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

class BIT{
    ll n;
    vl bit;
public:
    void BIT_init(ll _n){
        bit.assign(_n+1,0);
        n=_n;
    }
    ll get_sum(int i){
        ll res=0;
        while(i>0){
            res+=bit[i];
            i-=i&(-i);
        }
        return res;
    }
    void add(int i,ll x){
        while(i<=n){
            bit[i]+=x;
            i+=i&(-i);
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, Q;
    cin >> N >> Q;
    vl c(N);
    rep(i,N){
        cin >> c[i];
    }
    vl last(N+1,-1);
    vP p;
    rep(i,N){
        int l = last[c[i]];cerr << l << endl;
        if(l != -1){
            p.pb({l+1,i+1});
        }
        last[c[i]] = i;
    }
    /*rep(i,p.size()){
        cerr << p[i].first << ' ' << p[i].second << endl;
    }*/
    BIT bit;
    bit.BIT_init(N+1);
    sort(p.begin(),p.end());
    vector<pair<P,int>> q(Q);
    rep(i,Q){
        cin >> q[i].first.first >> q[i].first.second;
        q[i].second = i;
    }
    vl ans(Q);
    sort(q.begin(),q.end());
    int now=p.size()-1;
    per(i,Q-1){
        while(now>=0&&p[now].first>=q[i].first.first){
            bit.add(p[now].second,1);
            now--;
        }
        ans[q[i].second]=q[i].first.second-q[i].first.first+1-bit.get_sum(q[i].first.second)-bit.get_sum(q[i].first.first-1);
        /*rep(j,N){
            cout << i << ' ' << j << ' ' << bit.get_sum(j) << endl;
        }
        cout << q[i].second << '\n';*/
    }
    rep(i,Q){
        cout << ans[i] << '\n';
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define mem0(x) memset(x, 0, sizeof(x))
#define asort(x) sort(x.begin(), x.end());
#define dsort(x, t) sort(x.begin(), a.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll A, B, ansa, ansb, res;
    cin >> A >> B;
    res = -1;
    for(ll i = 1; i <= 11000; i++) {
        ansa = i * 0.08;
        ansb = i * 0.1;
        if(ansa == A && ansb == B) {
            res = i;
            break;
        }
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);
int gcd(int a, int b);

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int rtn = (b/a > c)? c: b/a;
    cout << rtn << endl;

    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}

// ユークリウッドの互除法
int gcd(int a, int b) {
    if(b==0) return a;
    else return gcd(b, a % b);
}



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

int main(){
	string s,t;
	cin >> s >> t;
	long long ans=0;
	
	long long ls=(long long)s.size();
	long long lt=(long long)t.size();
	
	int bpos=0;
	for(int i=0;i<lt;i++){
		if(s.find(t[i])==std::string::npos){
			cout << "-1" << endl;
			return 0;
		}
		 std::string::size_type pos=s.find(t[i],bpos);
		if(pos==std::string::npos){
			ans-=bpos;
			ans+=ls;
			pos=s.find(t[i]);
			ans+=(long long)((int)pos+1);
			bpos=((int)pos+1)%ls;
		}
		else{
			ans+=(long long)((int)pos-bpos+1);
			bpos=((int)pos+1)%ls;
		}
		//printf("%lld %d\n",ans,bpos);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;

int N, M;
vector<int> G[MAX_N];
int color[MAX_N];

bool dfs(int v, int c){
	if(color[v] == -c) return false;
	color[v] = c;
	for(int i = 0; i < G[v].size(); i++){
		if(color[G[v][i]] == -c) continue;
		if(!dfs(G[v][i], -c)) return false;
	}
	return true;
}

int main(){
	scanf("%d %d", &N, &M);
	for(int i = 0; i < M; i++){
		int A, B;
		scanf("%d %d", &A, &B);
		A--; B--;
		G[A].push_back(B);
		G[B].push_back(A);
	}
	for(int i = 0; i < N; i++){
		if(color[i] == 0){
			if(!dfs(i, 1)){
				printf("%lld\n", (ll)N * (ll)(N - 1) / 2LL - (ll)M);
				return 0;
			}
		}
	}
	ll cnt1 = 0, cnt2 = 0;
	for(int i = 0; i < N; i++){
		if(color[i] == 1) cnt1++;
		if(color[i] == -1) cnt2++;
	}
	printf("%lld\n", (ll)N * (ll)(N - 1) / 2LL - (ll)M - (ll)cnt1 * (ll)(cnt1 - 1) / 2LL - (ll)cnt2 * (ll)(cnt2 - 1) / 2LL);
	return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;
public class Main {
	
	public static int gcd(int a, int b) {
		if(b == 0)
			return a;
		else
			return gcd(b, a % b);
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] x = new int[N];
		x[0] = sc.nextInt();
		int ans = Math.abs(x[0]-X);
		for(int i = 1; i < N; i++) {
			x[i] = sc.nextInt();
			ans = gcd(Math.abs(x[i]-X), ans);
		}
		System.out.println(ans);
	}

}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[n+5],dp[n+5];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<n;i++)
        dp[i]=1e9;

    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
            dp[i]=min((dp[i-1]+abs(arr[i]-arr[i-1])),dp[i-2]+abs(arr[i]-arr[i-2]));
    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define in insert
#define ff first
#define ss second
#define mp make_pair
#define int long long
#define uint unsigned long long
#define rep(i,x,m) for(int i=x;i<m;i++)
#define repr(i,x,m) for(int i=x;i>=m;i--)
#define MOD 1000000007
#define endl "\n"
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi vector<int>
#define vs vector<string>
#define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
using namespace std;
#define noob ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int fac[2000005]={0};
void factorial(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=((i%MOD)*(fac[i-1]%MOD))%MOD;}
int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int ncr(int n,int r){return ((fac[n]*power(fac[r],MOD-2))%MOD*power(fac[n-r],MOD-2))%MOD;}

void ram5564()
{
    int n,k;
    cin>>n>>k;
    int sum=0;
    int x;
    rep(i,0,k)
    {
        cin>>x;
        sum+=x;
    }
    if(sum>n)
    {
        cout<<-1;return;
    }
    cout<<n-sum;
}

signed main()
{
        noob
         
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[5005][5005];

int main()
{
    ll A,B,C,X,Y;
    cin>>A>>B>>C>>X>>Y;
    ll ans = 1000000000000000;
    for(ll i=0; i<X+1; i++){
        int k = (X-i);
        if(k<=Y)
        {
            ans = min(ans,min(A*i+2*C*k+(Y-k)*B,A*i+2*C*k+(Y-k)*2*C ));
            ans = min(ans,min(2*C*i+2*C*k+(Y-k)*B,2*C*i+2*C*k+(Y-k)*2*C));
        }

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


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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

int n;
vector<int> d;
int ans;

int main(void){
	cin>>n;
	d.resize(n);
	for (int i = 0; i < n; i++) cin>>d[i];

	sort(d.begin(), d.end());
	for (int i = 0; i < 100010; i++) {
		auto ite = upper_bound(d.begin(), d.end(), i);
		int abc = 0, arc = 0;
		abc = distance(d.begin(), ite);
		arc = distance(ite, d.end());

		if (abc == arc) ans++;
	}

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

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		if (s.charAt(1) != s.charAt(2)) {
			System.out.println("No");
		} else if (s.charAt(0) == s.charAt(1) || s.charAt(2) == s.charAt(3)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}

}




Measured memory_bytes: 23892
#include<stdio.h>

int solve(int data[],int size);

int main()
{
    int x,n,m,ans=0;
    int i,j;
    int p[110]={0};//あるものは1
	scanf("%d %d",&x,&n);

	for(i=0;i<n;i++)
	{
		scanf("%d",&m);
		p[m]=1;
	}
	if(p[x]==0)
    {
	    printf("%d",x);
	    return 0;
    }

	for(j=0;j<101;j++)
    {
	    if(p[x-j]==0)
        {
	        ans=x-j;
	        break;
        }
	    else if(p[x+j]==0)
        {
	        ans=x+j;
	        break;
        }
    }
	printf("%d",ans);
}


Measured memory_bytes: 1736
S=input()
T=input()
dic={}
change=[]
ans="No"
for s,t in zip(S,T):
  if s not in dic:
    dic.setdefault(s,t)
    s=dic[s]
    change.append(s)
  else:
    s=dic[s]
    change.append(s)
after=dic.values()
if len(after)==len(set(after)) and "".join(change)==T:
  ans="Yes"
print(ans)

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

int main() {
  int n;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int e;
    cin >> e;
    s.insert(e);
  }
  cout << (s.size() == n ? "YES" : "NO") << endl;
}


Measured memory_bytes: 9600
// #include <bits/stdc++.h> // C++を満足に使えるようになったら
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>

using namespace std;

typedef long long ll;

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

int N;

ll ls[87];

int main() {
  scanf("%d", &N);

  rep(i, N + 1) {
    if (i == 0) ls[i] = 2;
    else if (i == 1) ls[i] = 1;
    else ls[i] = ls[i - 1] + ls[i - 2];
  }
  printf("%lld\n", ls[N]);
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  char x,c;
  int i=0;
  int count[26]={};
  while(cin >> c){
    if(c>='a' && c<='z') count[c-'a']++;
    else if(c>='A' && c<='Z') count[c-'A']++;
  }
  for(x='a';x<='z';x++,i++)
    cout << x << " : " << count[i] << endl;
  return 0;

}

Measured memory_bytes: 3060
import sys
rs = lambda: sys.stdin.readline().strip()
ri = lambda: int(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]

MOD = 10 ** 9 + 7

N, K = ri_()
A = ri_()
ans = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            if i < j:
                ans += (K * (K + 1) // 2) % MOD
            elif i > j:
                ans += (K * (K - 1) // 2) % MOD
print(ans % MOD)

Measured memory_bytes: 3188
#!/usr/bin/ruby

class NilClass
  def +(other)
    return other
  end
end

N = STDIN.readline.chomp.to_i
a = STDIN.readline.chomp.split(/\s+/).sort
count = {}
num = 0
a.each do |i|
  num += 1
  count[i] += 1
  if count[i] == i.to_i
    num -= i.to_i
  end
end
puts num


Measured memory_bytes: 19468
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin>>s;
	bool ones = true;
	int count = 1;
	for(int i=1;i<s.length(); i++) {
		//cout<<i<<" "<<count<<endl;
		if(s[i] != s[i-1])
			ones = false;
		if(ones == true && i == s.length()-1 && s[i-1] == s[i])
			break;
		if(s[i] == s[i-1] && ones == true) {
			i++;
			ones = false;
			count++;
		}
		else if(ones == false) {
			count++;
			ones = true;
		}
		else {
			count++;
		}

	}
	cout<<count<<endl;
}

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

const int MOD = 1000000007;
const int INF = 1000000000;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

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


int main(){
    int n;
    cin >> n;
    string S;
    cin >> S;
    int r = 0, b = 0;
    REP(i, S.length()){
        if(S[i] == 'R') r++;
        else b++;
    }
 if(r > b) yes;
 else no;
}




Measured memory_bytes: 256
#include <stdio.h>

void explode(int map[14][14], int x, int y){
	int i,j;
	
	map[x][y] = 0;
	for(i = -3; i <= 3; i++){
		if(x + i < 3 || x + i > 10 || i == 0){continue;}
		if(map[x+i][y]){
			explode(map,x+i,y);	
			
		}
	}
	for(i = -3; i <= 3; i++){
		if(y + i < 3 || y + i > 10 || i == 0){continue;}
		if(map[x][y+i]){
			explode(map,x,y+i);	
		}
	}

}
int main(void){
	int map[14][14];
	int n,i;
	int j,k;
	int sx, sy;
	for( i = 0 ; i < 14; i++){
		for(j = 0; j < 14; j++){
			map[i][j] = 0;
		}
	}
	scanf("%d",&n);
	for(i = 0; i < n; i++){
		getchar();
		getchar();
		for(k = 3; k <= 10; k++){
			for(j= 3; j <= 10; j++){
				map[j][k] = getchar() - '0';
			}
			getchar();
		}
		scanf("%d%d",&sx,&sy);
		sx += 2;
		sy += 2;
		explode(map,sx,sy);
		printf("Data %d:\n",i+1);
		for(k = 3; k <= 10; k++){
			for(j= 3; j <= 10; j++){
				printf("%d",map[j][k]);
			}
			putchar('\n');
		}
	}

	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var line = Console.ReadLine();
        int n = int.Parse(line);
        List<int> d = new List<int>();

        for (int i = 0; i < n; i++)
        {
           d.Add(int.Parse(Console.ReadLine()));
        }
        d.Sort();
        var res = d.Distinct().ToList();

        Console.WriteLine(res.Count.ToString());
        
    }
}

Measured memory_bytes: 13152
/*
 *
 * Author: r3gz3n
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T=int> using order_statistics = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const int MAX = 1e5 + 5;
int dp[MAX], a[MAX];

int main(int argc, char* argv[]) {
    if(argc == 2 or argc == 3) freopen(argv[1], "r", stdin);
    if(argc == 3) freopen(argv[2], "w", stdout);
    int n;
    cin >> n;
    for (int i = 0;i < n;++i) cin >> a[i];
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for (int i = 2;i < n;++i) {
        dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int a,b,c;
	int x,y,z;
	scanf("%d %d %d",&a,&b,&c);
	if(c < b)
	{
		x = b;
		b = c;
		c = x;
	}
	if (b < a)
	{
		y = a;
		a = b;
		b = y;
		/* code */
	}
	if (c < b)
	{
		z = b;
		b = c;
		c = z;
		/* code */
	}
	
	printf("%d %d %d\n",a,b,c);
	

	return 0;
}

Measured memory_bytes: 596
//
//  main.cpp
//  Find Symmetries
//
//  Created by Dong Truong on 7/18/19.
//  Copyright © 2019 Dong Truong. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <vector>

using namespace std;
#define gh 303

struct vt
{
    long x,y;
};

long n,d[gh][gh],a[gh][gh];

void nhap()
{
    cin>>n;
    for (int i=1;i<=n;++i)
        for (int j=1;j<=n;++j)
        {
            char c;cin>>c;
            long o=c-'a'+1;
            a[i][j]=o;
        }
}
void sol()
{
    long kq=0;
    for (int k=0;k<n;++k)
    {
        for (int i=1;i<=n;++i)
            for (int j=1;j<=n;++j)
            {
                long o=(i+k)%n;
                if (o==0) o=n;
                d[i][j]=a[o][j];
            }
        bool kt=true;
        for (int i=1;i<=n;++i)
            for (int j=1;j<=n;++j)
                if (d[i][j]!=d[j][i]) kt=false;
        if (kt==true) kq=kq+n;
    }
    cout<<kq;
}
int main(int argc, const char * argv[]) {
    //freopen("a.inp","r",stdin);
    nhap();
    sol();
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
// make pair, tuple
// __gcd(int, int)
// bool isPrime(int n){
//       if(n <= 1)return false;
//       if(n <= 3)return true;
//       if(n % 2 == 0 || n % 3 == 0)return false;
//       for(int i = 5;i * i <= n;i += 6){
//             if(n % i == 0 || n % (i + 2) == 0)return false;
//       }
//       return true;
// }
// int countSubString(string s, string temp){
//       int ans = 0;
//       size_t f = s.find(temp);
//       while(f != string::npos){
//             ans++;
//             f = s.find(temp, f + 1);
//       }
//       return ans;
// }

int main(){
    int n;cin >> n;
    long long int a[n + 5];
    long long int b[n + 5];
    long long int ans = 0;
    for(int i = 0;i < n + 1;i++)cin >> a[i];
    for(int i = 0;i < n;i++)cin >> b[i];
    for(int i = 0;i < n;i++){
        ans += min(a[i], b[i]);
        if(b[i] > a[i]){
            ans += min(a[i + 1], b[i] - a[i]);
            a[i + 1] = max(0ll, a[i + 1] - (b[i] - a[i]));
        }
    }
    cout << ans;
}

Measured memory_bytes: 1792
# coding: utf-8
# Your code here!

import math

N = int(input())
x = []
y = []

for i in range(N) : 
    x_temp, y_temp = map(int, input().split())
    x.append(x_temp)
    y.append(y_temp)
    
numerator = 0
cnt = 0
    
for i in range(N) : 
    for j in range(N) : 
        if i != j : 
            numerator += math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
            cnt += 1
            
print(numerator/N)

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< int, int > P;
typedef pair< int, P > PP;

//-------------------------------------------------


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

    string s;
	cin >> s;
	int sz = s.size();
	int n;
	cin >> n;
	int ans = 0;
	REP(i, n) {
		string t;
		cin >> t;
        REP(j, 10) {
			bool flg = true;
			REP(k, sz) {
				if (s[k] != t[(j + k) % 10]) {
					flg = false;
				}
			}
			if (flg) {
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;

	return 0;
}




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

using namespace std;

int main(void) {
	int ok = 0, N, S, W, E;
	string s;
	cin >> s;
	N = s.find('N');
	S = s.find('S');
	W = s.find('W');
	E = s.find('E');
	if (N >= 0 && S >= 0)
		ok++;
	else if (N < 0 && S < 0)
		ok++;
	if (W >= 0 && E >= 0)
		ok++;
	else if (W < 0 && E < 0)
		ok++;
	if (ok == 2)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>
#include <list>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
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 namespace std;

int main(void)
{
	int N; cin >> N;
	map<int, int> cnt; cnt[0] = 0;
	rep(i, 0, N) {
		int tmp; cin >> tmp;
		cnt[tmp]++;
	}
	map<int, int>::iterator it = cnt.begin(); it++;
	bool flag = false;
	if (cnt[0] == N)flag = true;
	else if ( cnt[0] == N / 3 && it->second == N * 2 / 3)flag = true;

	if (cnt[0] == 0)cnt.erase(0);
	if (cnt.size() == 3) {
		it = cnt.begin();

		map<int, int>::iterator a = cnt.begin(); a++;
		map<int, int>::iterator b = cnt.begin(); b++; b++;
		if (it->second == N / 3 && a->second == N / 3 && b->second == N / 3) {
			if ((it->first ^ a->first ^ b->first)== 0)flag = true;
		}
	}


	cout << (flag ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 3840
n = input()
l = len(n)
key = [0]*2019
mod = 1
judge = 0
for i in range(l):
  judge += ((mod%2019)*int(n[l-i-1]))%2019
  judge %= 2019
  k = judge%2019
  key[k] += 1
  mod *= 10
  mod %= 2019

ans = key[0]
for i in range(2019):
  if key[i] >= 2:
    ans += key[i]*(key[i]-1)//2
print(ans)

Measured memory_bytes: 9280
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int k;
  cin >> k;
  vector<ll>a(k);
  rep(i,k)cin >> a[i];
  reverse(a.begin(),a.end());
  ll l=2,r=2;
  rep(i,k){
    ll mi = ((l+a[i]-1)/a[i])*a[i];
    ll ma = (r/a[i])*a[i] + a[i] -1;
    if(mi > r || ma < l){
      cout << -1 << endl;
      return 0;
    }
    l = mi;
    r = ma;
  }
  cout << l<< " " << r<< endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
  	int arr[n];
 	int mx=0;
 	int ans=0;
  	for(int i=0;i<n;i++){
      
      cin>>arr[i];
      if(arr[i]>=mx) ++ans;
      mx=max(mx,arr[i]);
    }
  cout<<ans;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(
            Solve(Console.ReadLine())
        );
    }

    static string Solve(params string[] args)
    {
        var N = int.Parse(args[0].Split(' ')[0]);
        var Y = int.Parse(args[0].Split(' ')[1]);

        for (int x = N; x >= 0; x--)
        for (int y = (N - x); y >= 0; y--)
        for (int z = (N - x - y); z >= 0; z--)
        {
            if ((x + y + z) != N) continue;
            if (10000 * x + 5000 * y + 1000 * z == Y)
            {
                return $"{x} {y} {z}";
            }
        }

        return "-1 -1 -1";
    }
}

Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
	}
	sort(all(a));
	rep(i, 0, N) {
		rep(j, i + 1, N) {
			if ((a[j] - a[i]) % (N - 1) == 0) {
				cout << a[i] << " " << a[j] << endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
//構築
//2進数の気持ちになあると解ける
int main(){

    int L; cin >> L;
    L--;
    int n = 1;
    int m = 0;

    //ステップ1(二重辺を張る部分)
    int p = 1;
    while(p <= L){
        n++;
        L -= p;
        p *= 2;
    }

    vector<vector<pair<int, int> > > g(n);
    for(int i = 0; i < n - 1; i++){
        g[i].push_back({i + 1, (int)pow(2, i)});
        g[i].push_back({i + 1, 0});
        m += 2;
    }

    //ステップ2(bitが立っていたら最後の頂点に辺を張る気持ち)
    int to = n - 1;
    int cost = (1 << (n - 1));
    for(int i = 0; i < n - 1; i++){
        if(L & (1 << i)){
            g[i].push_back({to, cost});
            cost += (1 << i);
            m++;
        }
    }

    //出力
    cout << n << " " << m << endl;
    for(int i = 0; i < n; i++){
        for(auto to : g[i])
        cout << i + 1 << " " << to.first + 1 << " " << to.second << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long x = a * b * c;
		long y = Math.max(Math.max(a * b * (c / 2), a * (b / 2) * c), (a / 2) * b * c);
		long z = x - y;
		System.out.println(Math.abs(y - z));
	}
}


Measured memory_bytes: 21844
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int A = ni(), B = ni(), C = ni();
		out.println(Math.max(0, C - A + B));
	}
			    
	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private float nf() {
		return Float.parseFloat(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

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

int partition(int A[],int p,int r){
    int x = A[r];
    int i = p-1;
    for(int j=p;j<=r-1;j++){
        if(A[j]<=x){
            i = i+1;
            int s = A[i];
            A[i] = A[j];
            A[j] = s;
        }
    }
    int c = A[i+1];
    A[i+1] = A[r];
    A[r] = c;
    return i+1;
}

int main(){
    int n;
    cin >> n;
    int A[n];
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    int w = partition(A,0,n-1);

    for(int i=0;i<n;i++){
        if(i==w)
            cout << "[" << A[i] << "] ";
        else if(i==n-1)
            cout << A[i] << endl;
        else
            cout << A[i] << " ";
    }

    return 0;
}


Measured memory_bytes: 3448
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<int> v(n);
	rep(i, n) cin >> v[i];

	map<int, int> ab, ba;
	vector<P> a, b;

	for (int i = 0; i < n; i += 2) ab[v[i]]++;
	for (int i = 1; i < n; i += 2) ba[v[i]]++;

	for (auto& c : ab) a.emplace_back(P(c.second, c.first));
	for (auto& c : ba) b.emplace_back(P(c.second, c.first));

	sort(all(a));
	sort(all(b));

	//最大値の記録
	int res1_1 = 0, res1_2 = 0, res2_1 = 0, res2_2 = 0;
	//最大値の種類
	int e = 0, f = 0;
	for (auto& c : a) {
		if (c.first >= res1_1) {//=は入れないとだめ
			res1_2 = res1_1;
			res1_1 = c.first;
			e = c.second;
		}
	}
	for (auto& c : b) {
		if (c.first >= res2_1) {
			res2_2 = res2_1;
			res2_1 = c.first;
			f = c.second;
		}
	}

	if (e != f) {
		int ans = n / 2 - res1_1 + n / 2 - res2_1;
		dunk(ans);
	}
	else {
		//おそらくここに問題がある
		int w1 = n / 2 - res1_1 + n / 2 - res2_2;
		int w2 = n / 2 - res1_2 + n / 2 - res2_1;
		int ans = min(w1, w2);
		dunk(ans);
	}
	return 0;
}


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

// https://atcoder.jp/contests/abc142/submissions/8554606 を参考
// 最小閉路を探せばよいので全ての頂点からdfs

vector<int> graph[1001];
vector<int> ans, cur;
bitset<1001>flag;
void dfs(int v){
    if(flag[v]) return;
    flag[v] = 1;
    cur.push_back(v);
    for (int x: graph[v]) {
        if(cur[0] == x){
            if(ans.size() == 0 || ans.size() > cur.size()) ans = cur;
        } else {
            dfs(x);
        }
    }
    cur.pop_back();
}

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int A, B;
        cin >> A >> B;
        graph[A].push_back(B);
    }

    for (int i = 1; i <= N; ++i) {
        flag.reset();
        dfs(i);
    }

    if(ans.size() == 0) {
        cout << -1 << "\n";
        return 0;
    }
    cout << ans.size() << "\n";
    for (int x: ans) {
        cout << x << "\n";
    }
    return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;
const int INF = INT_MAX / 2;

typedef long long ll;

int N;
ll d[10], v[10];

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

int main(){
	while(cin >> N, N != -1)
	{
		int ans = 1150;
		if(N > 10) ans += min(10, N - 10) * 125;
		if(N > 20) ans += min(10, N - 20) * 140;
		if(N > 30) ans += (N - 30) * 160;
		printf("%d\n", 4280 - ans);
	}
	return 0;
}

Measured memory_bytes: 1144
N=int(input())

f=[0]*(N+1)

for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            temp=x**2+y**2+z**2+x*y+y*z+z*x
            if temp<=N:
                f[temp]+=1

for i in range(1,N+1):
    print(f[i])


Measured memory_bytes: 9120
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {	
		Scanner sc = new Scanner(System.in);
		long[] trans = new long[5];

		
		long n = Long.parseLong(sc.next());
		
		for(int i=0;i<trans.length;i++) {
			trans[i] = Long.parseLong(sc.next()); 
		}
		
		long min=Long.MAX_VALUE;
		for(int i=0 ;i<trans.length;i++) {
			if(trans[i]<min) {
				min = trans[i];
			}
		}
		
		long power = n/min;
		if(n%min!=0)power++;
						
		System.out.println(power+4l);
	}
}


Measured memory_bytes: 23124
h, w, k = map(int, input().split())
c = [input() for i in range(h)]
ans = 0
for i in range(1 << h):
    for j in range(1 << w):
        cnt = 0
        for x in range(h):
            for y in range(w):
                if (i >> x & 1) or (j >> y & 1):
                    continue
                if c[x][y] == "#":
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Measured memory_bytes: 9008
/*
Dont BLUNDER
*/
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimization ("unroll-loops")
//for n2 loops
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


 */
#define d long double
#define int long long
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define pi acos(-1)

#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod = 998244353;
int const mod1 = 1000000007;
#define l first
#define r second
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// * Using PBDS *
/*typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
               os; */



int modexp(int x, int n) {
	if (n == 0) {
		return 1;
	}
	else if (n & 1) {
		return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod;
	}
	else {
		return (modexp((x * x) % mod, n / 2) % mod);
	}
}

int modinv(int n)
{
	return modexp(n, mod - 2);
}

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}
bool comp(pii a, pii b) {
	return a.second < b.second;

}
struct hash_pair {

	size_t operator()(const pair<int, int>& p) const
	{

		return ((  p.second ^ p.first) << 32);
	}
};



signed main()
{
	haha
// #ifndef ONLINE_JUDGE

// 	freopen("inp.txt", "r", stdin);

// 	freopen("out1.txt", "w", stdout);
// #endif
	string s;
	cin >> s;

	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
		cout << 3;
	else if (s[0] == 'R' && s[1] == 'R' && s[2] == 'S')
		cout << 2;
	else if (s[0] == 'S' && s[1] == 'R' && s[2] == 'R')
		cout << 2;
	else if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S')
		cout << 0;
	else
		cout << 1;



}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>
#include <climits>
#include <cfloat>
#include <cstdint>
#include <cstddef>
#include <cinttypes>
#include <memory>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <array>
#include <valarray>
#include <string>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <queue>
#include <complex>
#include <tuple>
#include <utility>
#include <functional>
#include <algorithm>
#include <numeric>

using namespace std;

const double EPS = 1e-10;
const int64_t INF = 1e9;

int main()
{
	int64_t a, b;
	scanf("%" SCNd64 "%" SCNd64, &a, &b);
	if (a < b) {
		if (a * b >= 0) {
			printf("%" PRId64 "\n",  b - a);
		} else {
			printf("%" PRId64 "\n", 1 + abs(b + a));
		}
	} else {
		if (a * b > 0) {
			printf("%" PRId64 "\n", a - b + 2);
		} else if (a * b == 0) {
			printf("%" PRId64 "\n", abs(a - b) + 1);
		} else {
			printf("%" PRId64 "\n", 1 + abs(b + a));
		}
	}

	return 0;
}



Measured memory_bytes: 256
fun readInts() = readLine()!!.split(' ').map(String::toInt)

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val t = IntArray(n)
    repeat(n - 1) {
        val (c, s, f) = readInts()
        for (i in 0 until it) {
            if (t[i] < s) {
                t[i] = s + c
                continue
            }
            val w = t[i] % f
            t[i] += if (w == 0) c else c + f - w
        }
        t[it] = s + c
    }
    t.forEach(::println)
}


Measured memory_bytes: 38120
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
typedef long long ll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N,M;
  cin >> N>>M;
  vec<vec<int>>ab(N);
  REP(i,M){
    int a,b;
    cin>>a>>b;
    ab[a].pb(b);
  }
  //区間スケジューリング問題として解く。
vec<int>dp(N+1,0);//最大値なので0でよい。[0,i)区間の最大スケジューリング
    REP(i,N){
        //何もしない場合
        chmax(dp[i+1],dp[i]);
        FORA(j,ab[i])chmax(dp[j],dp[i]+1);
    }
    print(dp[N]);
  return 0;
}

Measured memory_bytes: 6528
import sys

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

if m == 0:
  print('{} {}'.format(0, 0))
  sys.exit()

result = {}
ac_result = 0
wa_result = 0
for i in range(m):
  x = input().split()
  p = int(x[0])
  s = x[1]
  if s == 'AC':
    try:
      if result[p] == 'AC':
        pass
      else:
        wa_result += result[p]
        ac_result += 1
        result[p] = 'AC'
    except:
      ac_result += 1
      result[p] = 'AC'
      pass
  else:
    try:
      if result[p] == 'AC':
        pass
      else:
        result[p] += 1
    except:
      result[p] = 1

print('{} {}'.format(ac_result, wa_result))


Measured memory_bytes: 15120
#include<bits/stdc++.h>
using namespace std;
const int SIZE = 1e6;
struct {
    int bit[SIZE];
    int n;
    void init(int _n){
        n=_n;
        for(int i=1;i<=_n;i++)bit[i]=n;
    }
    void ins(int x, int v){
        for(;x;x-=x&-x){
            bit[x]=min(bit[x],v);
        }
    }
    int qq(int x){
        int ret=n;
        for(;x<=n;x+=x&-x){
            ret=min(ret,bit[x]);
        }
        return ret;
    }
}row,col;
int main() {
    int N,Q;
    cin>>N>>Q;
    row.init(N);
    col.init(N);
    long long an=(long long)(N-2)*(N-2);
    for(int i=1;i<=Q;i++){
        int id,x;
        cin>>id>>x;
        if(id==1){
            int mi=col.qq(x);
            an-=mi-2;
            row.ins(mi,x);
        }
        else{
            int mi=row.qq(x);
            an-=mi-2;
            col.ins(mi,x);
        }
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 5192