akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        for (; x <= 100003; x++) {
            if (isPrime(x)) {
                System.out.println(x);
                break;
            }
        }
    }

    static boolean isPrime(long n) {
        if (n < 2)
            return false;
        else if (n == 2)
            return true;
        else if (n % 2 == 0)
            return false;
        double sqrtNum = Math.sqrt(n);
        for (long i = 3; i <= sqrtNum; i += 2) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin>>x>>y;
  int z=0;
  for(int i=0;i<=x;i++){
    if(i*2+(x-i)*4==y){
      z++;
      break;
    }
  }
  if(z==0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 3580
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()

struct UnionFind {
    int* parent;
    int* value;
    UnionFind(int N) {
        parent = new int[N + 1]; fill(parent, parent + N + 1, -1);
        value = new int[N + 1]; fill(value, value + N + 1, 0);
    }
    ~UnionFind() {
        delete[] parent;
        delete[] value;
    }
    /* 
     * root :: インデックス -> (ルートのインデックス, ルートとの距離)
     */
    pair<int, int> root(int x) {
        if (parent[x] == -1) return make_pair(x, 0);
        int p = parent[x];
        int v = value[x];
        pair<int, int> proot = root(p);
        parent[x] = proot.first;
        value[x] = v + proot.second;
        return make_pair(parent[x], value[x]);
    }
    static const int INF = 1<<28;
    /* 
     * query :: (インデックスx, インデックスy) -> yとxの差
     */
    int query(int x, int y) {
        pair<int, int> xroot = root(x),
                       yroot = root(y);
        if (xroot.first != yroot.first) return INF;
        return yroot.second - xroot.second;
    }
    /*
     * merge :: (インデックスx, インデックスy, yとxの差w) -> ()
     *
     * xとyがすでに親子関係を持っていて,その差がwでなければ異常終了
     */
    void merge(int x, int y, int w) {
        pair<int, int> xroot = root(x),
                       yroot = root(y);
        if (xroot.first == yroot.first) {
            assert(query(x, y) == w);
            return;
        }
        int px = xroot.first, py = yroot.first;
        int dx = xroot.second, dy = yroot.second;
        /* value[y] - value[x] = w
         * value[x] - value[px] = dx
         * value[y] - value[py] = dy
         * value[py] - value[px] = (value[y] - dy) - (value[x] - dx)
         *                       = (value[y] - value[x]) - (dy - dx)
         *                       = w - dy + dx
         */
        parent[py] = px;
        value[py] = w - dy + dx;
    }
};

int main() {
    int N, M;
    while (cin >> N >> M, N || M) {
        UnionFind uf(N);
        char c; int a, b, w;
        for (int i = 0; i < M; i++) {
            cin >> c;
            if (c == '?') {
                cin >> a >> b;
                int ans = uf.query(a, b);
                //cerr << "?" << " " << a << " " << b << endl;
                if (ans == UnionFind::INF) {
                    cout << "UNKNOWN" << endl;
                } else {
                    cout << ans << endl;
                }
            } else {
                assert(c == '!');
                cin >> a >> b >> w;
                //cerr << "!" << " " << a << " " << b << " " << w << endl;
                uf.merge(a, b, w);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;

int main(){
    int n;
    cin >> n;
    vector<ll> A(2);
    A[0] = 2;
    A[1] = 1;
    for(int i=1;i<86;i++){
        A.push_back(A[i] + A[i-1]);
    }
    cout << A[n] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
int n;
signed main()
{
	scanf("%d",&n);
	printf("%d",((n*800)-((n/15)*200)));
	return putchar(10),0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int unsigned long long
random_device rd;
mt19937_64 mt(rd());
int modpro(int x, int n, int md) {//log^2 n
	int res = 0;
	for (; n; n >>= 1) {
		if (n & 1)res = (res + x) % md; x = (x + x) % md;
	}
	return res;
}
int modpow(int x, int n, int md) {//log n
	int res = 1;
	for (; n; n >>= 1) {
		if (n & 1)res = res*x%md;
		x = x*x%md;
	}
	return res;
}

int gcd(int a, int b) {
	if (!b)return a; return gcd(b, a%b);
}

bool isprime(int n) {
	if (n < 2)return false;
	if (n == 2)return true;
	if (!(n & 1))return false;
	int m = n - 1;
	int e = 0;
	while (!(m & 1)) {
		m /= 2; e++;
	}
	for (int z = 0; z<7; z++) {
		int b = mt() % (n - 1) + 1;
		if (gcd(b, n) != 1)return false;
		bool ok = false;
		int now = modpow(b, m, n);
		if (now != 1) {
			for (int k = 0; k <= e; k++) {
				if (now == n - 1) {
					ok = true; break;
				}
				now = now*now%n;
			}
		}
		else ok = true;
		if (!ok) {
			return false;
		}
	}
	return true;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	signed n; cin >> n;
	int p;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> p;
		if (isprime(p))cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3192
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
ll INF = 1LL<<40;

int N;
string s;
ll dp[100005][13];

ll solve(){

}

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

    ll res = 0;
    
    cin >> s;
    N = s.size();
    
    dp[0][0] = 1;
    for(int i = 0; i < N; i++){
        int c;
        if(s[i] == '?') c = -1;
        else c = s[i] - '0';
        for(int j = 0; j < 10; j++){
            if( c!= -1 && c != j){continue;}
            for(int k = 0; k < 13; k++){
                dp[i + 1][(k * 10 + j)%13] += dp[i][k];
            }
        }
        for(int j = 0; j < 13; j++){
            dp[i+1][j] %= MOD;
        }
    }
    cout << dp[N][5] << endl;
    
    return 0;
}


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

long long f(long long N){
    if(N%2==1){
        return 0;
    }else{
        long long F=0;
        N/=2;
        while(N){
            F += N/5;
            N/=5;
        }
        return F;
    }
}

int main(){
    long long N;
    cin>>N;
    cout<<f(N)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << c <<  " " << a << " " << b << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
import Data.Char

ans c [] = 0
ans c (x:xs) =
  let s = if x > c then 0 else 1
  in
    s + ans x xs

main = do
  l <- getLine
  let i = map (\c -> ord c - ord 'A')l :: [Int]
      o = ans 0 i
  print o



Measured memory_bytes: 3560
program shift
  implicit none
  integer(8), parameter :: modu = 998244353
  character(300) :: s
  integer :: k, n, a(302) = 0, m = 1, x = 0, h = 0, r, d, w, c, b, i, j
  integer(8) :: dp(0:300, 0:301) = 0
  read(*,*) s, k
  n = len_trim(s)
  do i = 1, n
    if (s(i:i) == '0') then
      m = m + 1
      a(m) = x
    else
      x = x + 1
    end if
  end do
  m = m + 1
  a(m) = x
  k = min(k, x)
  dp(0, 0) = 1
  do i = 1, m - 1
    do j = h, 0, -1
      r = min(k - j, a(i + 1) - a(i))
      do d = 1, r
        w = j + d
        b = a(m) - a(i + 1) + d
        do c = 0, a(m) - a(i + 1)
          b = c + d
          dp(w, c) = dp(w, c) + dp(j, b)
          if (dp(w, c) >= modu) dp(w, c) = dp(w, c) - modu
        end do
      end do
      do c = 1, a(m) - a(i + 1)
        dp(j, c) = dp(j, c) + dp(j, c - 1)
        if (dp(j, c) >= modu) dp(j, c) = dp(j, c) - modu
      end do
    end do
    h = min(k, h + a(i + 1) - a(i))
  end do
  write(*,'(i0)') mod(sum(dp(0:h, 0)), modu)
end program shift

Measured memory_bytes: 3564
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long int ll;


/*bool compare_function(const pair<int, int> a, const pair<int, int> b) {
    return a.first < b.first;
}
use case
sort(V.begin(), V.end(), compare_function);*/

ll laip(ll a, ll b, ll liek) {
if (b==0) {return 1;}
if (b==1) {return a%liek;}
ll c=(a*a)%liek;
if (b%2==0) {return laip(c,b/2,liek);}
return (a*laip(c,b/2,liek))%liek;
}

ll cnk(ll n, ll i, ll liek, vector <ll> &F) {
ll x=F[n]%liek;
//cout<<n<<" "<<x<<endl;
ll y=F[i]*F[n-i];
y=y%liek;
//cout<<i<<" "<<n-i<<" "<<x<<" "<<y<<endl;
ll ats=x*laip(y,liek-2,liek);
ats=ats%liek;
return ats;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,m,k;
    cin>>n>>m>>k;
    ll liek=998244353;
    vector <ll> F;
    F.push_back(1);
    for (int i=0;i<200005;i++) {
    ll x=(i+1)*F[i];
    x=x%liek;
    F.push_back(x);
    }
    //cout<<cnk(3,2,liek,F)<<endl;
    ll ats=0;
    for (int i=0;i<=k;i++) {
    ll x=cnk(n-1,i,liek,F)*m;
    //cout<<x<<endl;
    x=x%liek;
    x=x*laip(m-1,n-i-1,liek);
    x=x%liek;
    //cout<<i<<" "<<x<<endl;
    ats=ats+x;
    ats=ats%liek;
    }
    cout<<ats<<endl;
    return 0;
}



Measured memory_bytes: 5328
n,x,m = map(int, input().split())
ai = x
tmp = [ai]
used = set(tmp)
for i in range(n):
    nxt = ai**2 % m
    if nxt in tmp:
        break
    tmp.append(nxt)
    ai = nxt
if len(tmp) == n:
    ans = sum(tmp)
    print(ans)
    exit()

first = tmp.index(nxt)
ans = 0
l = []
for i in range(len(tmp)):
    if i < first:
        ans += tmp[i]
        n -= 1
    else:
        l.append(tmp[i])
m = len(l)
x,y = divmod(n, m)
ans += sum(l)*x
for i in range(y):
    ans += l[i]
print(ans)



Measured memory_bytes: 70644
import sys;sys.setrecursionlimit(9**9);h,w=map(int,input().split());b=[[0]*(w+1)]
for i in range(h):
  b.append([0])
  for j in input():b[-1].append(1+(j=="#"))
  b[-1].append(0)
b.append([0]*(w+1));d=[[0,1],[0,-1],[1,0],[-1,0]];a=0
def s(i,j):
  global B;B[b[i][j]-1]+=1;v=b[i][j];b[i][j]=0
  for k in d:
    if v^3==b[i+k[0]][j+k[1]]:s(i+k[0],j+k[1])
for i in range(1,h+1):
  for j in range(1,w+1):B=[0,0];s(i,j);a+=B[0]*B[1]
print(a)

Measured memory_bytes: 149364
void main(){
	int k,a,b;
	k = _scan();
	scanf("%d %d", &a, &b);

	if( a<= b/k*k ) writeln("OK");
	else writeln("NG");
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


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

using namespace std;

const int N = 1e5+5;

int dp[N][3];
int points[N][3];
bool vis[N];


int main (){
	
	int n;
	cin>>n;
	
	for (int i=1;i<=n;i++) {
		for (int j=0;j<3;j++) cin>>points[i][j];
		
	}
	
	dp[1][0]=points[1][0];
	dp[1][1]=points[1][1];
	dp[1][2]=points[1][2];
	
	
	for (int i=2;i<=n;i++) {
		for (int j=0;j<3;j++) {
			int mx=0;
			for (int k=0;k<3;k++) {
				if (k==j) continue;
				mx=max(mx,dp[i-1][k]);
			}
			dp[i][j]=mx+points[i][j];
		}
	}
	
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}	


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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;

  int ans = 0;
  vector<bool> results(t.size());
  for (int i = 0; i < t.size(); i++) {
    if (i >= k && t[i - k] == t[i] && results[i - k]) {
      results[i] = false;
      continue;
    }

    results[i] = true;
    switch (t[i]) {
      case 'r':
        ans += p;
        break;
      case 's':
        ans += r;
        break;
      default:
        ans += s;
        break;
    }
  }

  cout << ans << "\n";

  return 0;
}

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

int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int lw = A + B;
  int rw = C + D;
  if (lw > rw)
  {
    printf("Left");
  }
  else if (lw < rw)
  {
    printf("Right");
  }
  else
  {
    printf("Balanced");
  }
}


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

#define ll long long
#define db double
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define all(x) x.begin(),x.end()
#define fo(i, n) for(i=0 ; i<n ; i++)
#define Fo(i, k, n) for(i=k ; i<n ; i++)

using namespace std;
using namespace chrono;

const ll MOD = 1000000007;
const ll N = 300005;  // array size
const ll inf = 10000000000000000;


void print(vector<ll> v) {
    ll i;
    fo(i, v.size())cout << v[i] << " ";
    cout << "\n";
}

void print(vector<pair<ll, ll> > v) {
    ll i;
    fo(i, v.size()) {
        cout << v[i].first << " " << v[i].second << "\n";
    }
}

vector<ll> read(ll n) {
    ll i;
    vector<ll> arr(n, 0);
    fo(i, n)cin >> arr[i];
    return arr;
}

vector<ll> read(ll n, ll k) {
    ll i;
    vector<ll> arr(n + k, 0);
    Fo(i, k, n + k)cin >> arr[i];
    return arr;
}

bool isEven(ll n) {
    return n % 2 == 0;
}

bool isOdd(ll n) {
    return n % 2 != 0;
}


void solve() {
    ll t = 1;
//    cin >> (t);
    while (t--) {

        ll i, j, k, n, m, p, q, x, y, a, b, l, r;
        ll h;
        cin >> n >> k;
        vector<ll> arr(n);
        ll ans = 0;
        arr = read(n);
        sort(all(arr));
        reverse(all(arr));
        Fo(i, k, n) {
            ans += arr[i];
        }
        cout << ans;

    }
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

    auto start = high_resolution_clock::now();

    solve();

    ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
#ifndef ONLINE_JUDGE
    cerr << "Time: " << duration.count() / 1000.0 << endl;
#endif


    return 0;
}




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

int main(){

  int n, k,l,total = 0;
  vector<int> v;

  cin >> n >> k;

  for(int i = 0;i < n;i++){
    cin >> l;
    v.push_back(l);
  }

  sort(v.begin(),v.end());

  for(int i = 1;i <= k;i++){
    total += v[n-i];
  }

  cout << total << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;


int main(){
	int in;
	double q, x;
	while(cin>>in&&in!=-1){
		q=in;
		x=q/2;
		while(fabs(x*x*x-q) >= q*1e-5){
			x=x-(x*x*x-q)/(3*x*x);
		}
		printf("%.5f\n",x);
	}
	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;
int N;
void dfs(string S,char c){
    if(S.size()==N){
        cout<<S<<endl;
        return;
    }
    for(char d='a';d<=c;d++){
        dfs(S+d,(c==d?(char)(c+1):c));
    }
}
void solve(){
    cin>>N;
    dfs("",'a');
}

signed main(){
    solve();
}

Measured memory_bytes: 1536
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p==NIL) printf("root, ");
  else if(T[u].l==NIL) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r!=NIL) calcDepth(T[u].r,p);
  if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 6384
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

pos = []
neg = []
for i in range(n):
    d = a[i] - b[i]
    if d >= 0:
        pos.append(d)
    else:
        neg.append(-d)

pos.sort()


cnt = len(neg)
val = 0
while len(neg) > 0:
    n = neg.pop()
    while n > val:
        if len(pos) == 0:
            print(-1)
            exit()
        val += pos.pop()
        cnt += 1
    val -= n

print(cnt)



Measured memory_bytes: 24108
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

const ll INFL = 1LL << 60;//10^18 = 2^60
ll MOD = 1000000007;
//ll MOD = 998244353;


ll N, M;//頂点数、辺数
vector<ll> E[1010];
vector<ll> rE[1010];
ll dist[1010];
ll pre[1010];
vector<ll> bfs(ll start){
  rep(i, N) dist[i] = INFL;
  dist[start] = 0;
  queue<ll> Q;
  Q.push(start);
  while(!Q.empty()){
    ll now = Q.front();
    Q.pop();
    for(ll to: E[now]){
      if(dist[to] != INFL) continue;
      dist[to] = dist[now] + 1;
      pre[to] = now;
      Q.push(to);
    }
  }
  pair<ll, ll> best = {INFL, -1};
  for(ll v: rE[start]){
    best = min(best, {dist[v], v});
  }
  if(best.f == INFL) return {};
  ll now = best.s;
  vector<ll> res;
  res.pb(now);
  while(true){
    now = pre[now];
    res.pb(now);
    if(now == start) break;
  }
  return res;
}

void solve(){
  cin >> N >> M;
  rep(i, M){
    ll a, b;
    cin >> a >> b;
    a--, b--;
    E[a].pb(b);
    rE[b].pb(a);
  }
  vector<ll> ans(N+1);
  rep(i, N){
    vector<ll> get = bfs(i);
    if(get.size() == 0) continue;
    if(get.size() < ans.size()){
      ans = get;
    }
  }
  if(ans.size() == N+1){
    cout << -1 << endl;
  }else{
    cout << ans.size() << endl;
    sort(ans.begin(), ans.end());
    rep(i, ans.size()){
      cout << ans[i] + 1 << " ";
    }
    cout << endl;
  }
}

int main(){
  solve();
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
long long D(int a){
  int ans = 1;
  for (int i = 2; i <= sqrt(a); i++) {
    int cnt = 0;
    while (a % i == 0) {
      cnt++;
      a /= i;
    }
    ans *= (cnt + 1);
    if (a == 1) break;
  }
  if (a != 1) ans *= 2;
  return ans;
}
int main() {
  int N;cin>>N;long long V=0;
  for(int X=1;X<N;X++){
    V+=D(X);
  }
  cout<<V<<endl;
}

Measured memory_bytes: 3672
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int count = 0;
        for (int i = 0 ; i < 1000 ; i++) {
            if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
                count++;
                int temp1 = b/2 + c/2;
                int temp2 = c/2 + a/2;
                int temp3 = a/2 + b/2;
                a = temp1;
                b = temp2;
                c = temp3;
            } else {
                System.out.println(count);
                return;
            }
        }
        System.out.println(-1);
    }

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define mp make_pair
 
using namespace std;

ll mod=1e9+7;

int main(){
	int n;cin>>n;
	ll a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	ll suf[n+1];
	suf[n]=a[n];
	for(int i=n-1;i>=1;i--)suf[i]=suf[i+1]+a[i];
	ll ans=0;
    for(int i=1;i<n;i++){
    	ans+=(a[i]*(suf[i+1]%mod))%mod;
    	ans%=mod;
	}
	cout<<ans;
	return 0;
}
	

	


Measured memory_bytes: 6740
#include <bits/stdc++.h>
using namespace std;
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#define rep(i, a, b) for(int i = a; i < b; i++)
#define print(x) cout << x << "\n"
const int inf = 1e9+7;

int main() {
    fastcin;
    string s;
    int w;
    cin >> s >> w;
    for(int i=0; i<s.size(); i+=w) cout<<s[i];
    cout<<endl;
}

Measured memory_bytes: 256
/*
 * Author: madlogic
 * It's better to do something than nothing
*/
#include <bits/stdc++.h>
using namespace std;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define int long long
const int INF = 1000000000;
const int MOD = 1000000007;
const double PI = 2*acos(0.0);
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	vector<pair<int,int>>v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i].first;
		v[i].second=i+1;
	}
	sort(v.begin(),v.end());
	for(pair<int,int> a : v)
		cout<<a.second<<" ";
	cout<<endl;
	return 0;	
}

Measured memory_bytes: 2432
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>

using namespace std;
typedef long long ll;
typedef map<int,int>::iterator miter;
typedef map<int,int>::const_iterator cmiter;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
int _w;

int T, a, m;
map<int,int> fac[1000];

ll fmul( ll a, ll b, ll p ) {
	ll c = 0;
	while(b) {
		if( b & 1 ) c = (c + a) % p;
		a = (a << 1) % p;
		b >>= 1;
	}
	return c;
}
ll fpow( ll a, ll b, ll p ) {
	ll c = 1;
	while(b) {
		if( b & 1 ) c = fmul(c, a, p);
		a = fmul(a, a, p);
		b >>= 1;
	}
	return c;
}
void addfac( int x, map<int,int> &mp ) {
	for( int i = 2; i*i <= x; ++i )
		while( x % i == 0 )
			++mp[i], x /= i;
	if( x > 1 ) ++mp[x];
}
ll phi( const map<int,int> &mp ) {
	ll x = 1;
	for( cmiter it = mp.begin(); it != mp.end(); ++it )
		x *= (it->first - 1) * fpow(it->first, it->second-1, INFLL);
	return x;
}
ll calc( const map<int,int> &mp ) {
	ll x = 1;
	for( cmiter it = mp.begin(); it != mp.end(); ++it )
		x *= fpow(it->first, it->second, INFLL);
	return x;
}
void phi2( const map<int,int> &mp1, map<int,int> &mp2 ) {
	for( cmiter it = mp1.begin(); it != mp1.end(); ++it ) {
		addfac(it->first-1, mp2);
		if( it->second > 1 )
			mp2[it->first] += it->second-1;
	}
}

ll solve( int idx ) {
	if( fac[idx].empty() ) return 1;
	fac[idx+1].clear();
	ll p = calc( fac[idx] );
	phi2( fac[idx], fac[idx+1] );
	return fpow(a, solve(idx+1), p) + p;
}

int main() {
	_w = scanf( "%d", &T );
	while( T-- ) {
		_w = scanf( "%d%d", &a, &m );
		fac[0].clear();
		addfac( m, fac[0] );
		// printf( "m = %lld\n", calc( fac[0] ) );
		// printf( "phi(m) = %lld\n", phi( fac[0] ) );
		addfac( (int)phi( fac[0] ), fac[0] );
		// printf( "m * phi(m) = %lld\n", calc( fac[0] ) );
		printf( "%lld\n", solve(0) );
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg

using namespace std;

const int N = 7e5 + 7;
const int M = 1e5 + 7;
const int inf = 0x3f3f3f3f;


int n, m, tot, head[N], all, d[N], que[2000100];

struct Edge {
    int u, v, w, nx;
} edge[3000100];

struct node {
    int u, v, w, id;
    bool operator < (const node &rhs) const {
        return w < rhs.w;
    }
} a[N];

vector<node> vec[100001];

void add(int u, int v, int w) {
    edge[tot].u = u;
    edge[tot].v = v;
    edge[tot].w = w;
    edge[tot].nx = head[u];
    head[u] = tot++;
}

void init() {
    all = m + 1; tot = 0;
    for(int i = 0; i <= all; i++) head[i] = -1;
    for(int i = 1; i <= n; i++) vec[i].clear();
}

int Dij(int S, int T) {
    for(int i = 0; i <= all; i++) d[i] = inf;
    int l = 1000001, r = 1000000;
    d[S] = 0; que[++r] = S;
    while(l <= r) {
        int u = que[l++];
        if(u == T) return d[u];
        for(int i = head[u]; ~i; i = edge[i].nx) {
            int v = edge[i].v, w = edge[i].w;
            if(d[v] != inf) continue;
            if(w == 0) {
                d[v] = d[u];
                que[--l] = v;
            } else {
                d[v] = d[u] + w;
                que[++r] = v;
            }
        }
    }
    return -1;
}

inline int read() {
    char ch = getchar(); int x = 0, f = 1;
    while(ch < '0' || ch > '9') {
        if(ch == '-') f = -1;
        ch = getchar();
    } while('0' <= ch && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    } return x * f;
}

int main() {
    while(scanf("%d%d", &n, &m) != EOF) {
        init();
        for(int i = 1; i <= m; i++) {
            a[i].u = read();
            a[i].v = read();
            a[i].w = read();
            a[i].id = i;
            vec[a[i].u].push_back(a[i]);
            vec[a[i].v].push_back(a[i]);
        }

        for(int i = 1; i <= n; i++) {
            sort(vec[i].begin(), vec[i].end());
            if(vec[i].size() <= 1) continue;
            head[++all] = -1;
            int root = all;
            for(int j = 0; j < vec[i].size(); j++) {
                if(!j || vec[i][j].w != vec[i][j - 1].w) {
                    add(root, vec[i][j].id, 1);
                    add(vec[i][j].id, root, 1);
                    head[++all] = -1;
                }
                add(all, vec[i][j].id, 0);
                add(vec[i][j].id, all, 0);
            }
        }

        for(int i = 1; i <= m; i++) {
            if(a[i].u == 1 || a[i].v == 1) {
                add(0, a[i].id, 0);
                add(a[i].id, 0, 0);
            }
            if(a[i].u == n || a[i].v == n) {
                add(m + 1, a[i].id, 0);
                add(a[i].id, m + 1, 0);
            }
        }
        int ans = Dij(0, m + 1);
        if(ans < 0) printf("%d\n", ans);
        else printf("%d\n", ans / 2 + 1);
    }
    return 0;
}

/********************
********************/


/*
*/


Measured memory_bytes: 51584
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;

long long dat[2 * MAX_N - 1];

//b
int main(void) {
	string s;
	cin >> s;
	string ans = "Yes";
	rep(i, 0, s.size()) {
		if (i % 2 == 0) {
			if (s[i] == 'L') {
				ans = "No";
				break;
			}
		}
		else {
			if (s[i] == 'R') {
				ans = "No";
				break;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	int x = a+b, y = a-b, z = a*b;
	if(x>=y&&x>=z) printf("%d\n", x);
	else if(y>=x&&y>=z) printf("%d\n", y);
	else printf("%d\n", z);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] arg = new int[n];
        for(int i=0;i<n;i++){
            arg[i] = Integer.parseInt(sc.next());
        }
        int min = cnt(arg[0]);
        if(min>0){
            for(int i=1;i<n;i++){
                int tmp = cnt(arg[i]);
                if(tmp<min){
                    min = tmp;
                }
                if(min==0){break;}
            }
        }
        
        System.out.println(min);
    }
    private static int cnt(int a){
        int cnt = 0;
        while(a%2==0){
            cnt++;
            a=a/2;
        }
        return cnt;
    }
}

Measured memory_bytes: 21712
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      	int nam = 0;
        int min = 1001;
      	int max = -1;
      
      for(int i = 0;i < n;i++){
        nam = sc.nextInt();
        min = Math.min(min,nam);
        max = Math.max(max,nam);
      }
     	 System.out.print(max-min);   
    }
}

Measured memory_bytes: 22740
import java.util.Scanner;

public class Main {

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

		for(int i= 0;i<50;i++) {
			int m = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();

			if(m==-1 && f==-1 && r==-1) break;
			if(m==-1 || f==-1) System.out.println("F");
			else {
				if(m+f>=80) System.out.println("A");
				if(80>m+f && m+f>=65) System.out.println("B");
				if(65>m+f && m+f>=50) System.out.println("C");
				if(50>m+f && m+f>=30 && r>=50) System.out.println("C");
				if(50>m+f && m+f>=30 && 50>r) System.out.println("D");
				if(30>m+f) System.out.println("F");
			}
		}
	}
}


Measured memory_bytes: 26284
N = gets.to_i
V = gets.split.map(&:to_i)

f02 = Hash.new(0)
f13 = Hash.new(0)

V.each.with_index do |v, i|
  if i.even?
    f02[v] += 1
  else
    f13[v] += 1
  end 
end 

tmp = (f02.to_a + f13.to_a + [[0, 0]]).sort_by{|x| -x[1]}
pri = tmp.first
sec = tmp.find{|x| x[0] != pri[0]}
puts N - pri[1] - sec[1]


Measured memory_bytes: 23432
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    int ans = 0;
    if (a+b <= c*2) {
        ans = a*x+b*y;
    }
    else {
        if (x < y) ans = 2*c*x + min(b*(y-x), 2*c*(y-x)); 
        else ans = 2*c*y + min(a*(x-y), 2*c*(x-y));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS

vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int n,m;
cin>>n>>m;
int sum=0;
for(int i=0;i<m;i++){
    int a;
    cin>>a;
    sum+=a;
}
if(n>=sum) cout<<n-sum;
else cout<<-1;
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#define ll long long
#define vi vector <int>
#define vii vector <vi>
using namespace std;

const int mod = 1e9 + 7;
const int mnx = 1e6 + 9;

ll a, b;

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

    for(int i = 1; i <= 3; i++){
        if(i != b && i != a){
            cout << i << '\n';
            return 0;
        }
    }

    return 0;
}















































Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(){
  int N,i,j,A[100],count=0,temp;

  scanf("%d",&N);
  if(N<1 || N>100){
    exit(1);
  }

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
    if(A[i]<0 || A[i]>100){
      exit(8);
    }
  }
  
  for(i=0;i<N-1;i++){
    for(j=N-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
	temp=A[j];
	A[j]=A[j-1];
	A[j-1]=temp;

	count++;
      }
    }
  }

  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[N-1]);

  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <array>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>

using namespace std;

struct edge
{
	long long to;
};

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long N, M;
	cin >> N >> M;
	vector<long long> tower(N);
	vector<edge> graph[N];
	long long a, b;
	for (long long i = 0; i < N; i++)
	{
		cin >> tower[i];
	}
	for (long long i = 0; i < M; i++)
	{
		cin >> a >> b;
		edge e1 = {b - 1};
		edge e2 = {a - 1};
		graph[a - 1].push_back(e1);
		graph[b - 1].push_back(e2);
	}
	long long count, result;
	result = 0;
	for (long long i = 0; i < N; i++)
	{
		count = 0;
		for (long long j = 0; j < graph[i].size(); j++)
		{
			if (tower[i] > tower[graph[i][j].to])
				count++;
		}
		if (count == graph[i].size())
			result++;
	}
	cout << result;
	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  int F[50];
  F[0] = F[1] = 1;
  for (int i = 2; i <= n; i++) F[i] = F[i - 1] + F[i - 2];
  cout << F[n] << endl;
  return 0;
}



Measured memory_bytes: 3124
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(void){
  int N;
  cin>>N;
  string s;
  vector<string>strVec;
  for(int i(0);i<N;i++){
    cin>>s;
    strVec.push_back(s);
  }
  int f(0);
  for(int i(0);i<N-1;i++){
    for(int j(i+1);j<N;j++){
      if(strVec[i]==strVec[j])f++;
    }
  }
  for(int i(0);i<N-1;i++){
    size_t size=strVec[i].length();
    if(strVec[i][size-1]!=strVec[i+1][0])f++;
  }
  if(f==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np
n, m, x = map(int, input().split())
l = []
for _ in range(n):
  l.append(list(map(int, input().split())))

l = np.array(l)
val = 9999999
for i in range(2 ** n):
  curr = np.array([0 for _ in range(m+1)])
  for j in range(n):
    if ((i >> j) & 1):
      curr += l[j]
  flag = True
  for k in range(m):
    if curr[k+1] < x:
      flag = False
  if flag:
    if val > curr[0]:
      val = curr[0]
      
if val == 9999999:
  print("-1")
else:
  print(val)

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

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

	ans = 100000;
	for(int i=0; i<n; i++) {
		ans *= 1.05;
		if(ans%1000 != 0) ans = (ans/1000+1)*1000;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3076
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.io.InputStream;

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

    static class TaskD {
        int N;
        int A;
        int B;
        int[] h;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            N = in.nextInt();
            A = in.nextInt();
            B = in.nextInt();

            h = new int[N + 1];

            for (int i = 1; i <= N; i++) {
                h[i] = in.nextInt();
            }

            long lo = 0;
            long hi = (int) 1e9;

            while (hi - lo > 1) {
                long md = lo + (hi - lo) / 2;

                if (checkExplosives(md)) hi = md;
                else lo = md;
            }

            for (long i = lo; i <= hi; i++) {
                if (checkExplosives(i)) {
                    out.println(i);
                    return;
                }
            }
        }

        private boolean checkExplosives(long u) {
            long count = 0;

            for (int i = 1; i <= N; i++) {
                long v = h[i] - B * u;
                if (v < 0) continue;
                long c = v / (A - B);
                if (v % (A - B) != 0) {
                    c++;
                }
                count += c;
            }
            return count <= u;
        }

    }

    static class FastScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        public FastScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 36796
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  cout << (N + 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
const int inf=0x3f3f3f3f;
int a[maxn],b[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		b[a[i]]++; 
	}
	for(int i=1;i<=n;i++)
	{
		int flag=0;
		for(int j=2;j<=int(sqrt(a[i]));j++)//枚举因子 
		{
			if(a[i]%j==0)
			{
				int tmp=a[i]/j;
				if(b[j]>=1||b[tmp]>=1)
				{
					flag=1;
					break;
				}
			}
		}
		if(b[a[i]]>1||b[1]>=1)
			flag=1;
		if(a[i]==1)
		{
			if(b[1]>1)
				flag=1;
			else
				flag=0;
		}
		if(flag==0)
		{ 
			ans++;
//			cout<<i<<" ";
		} 
	}
//	cout<<endl;
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 8212
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
#print(a,b,c)
s = 0
b_ia = 0
for ia in a:
  #print('ia:{} s:{}'.format(ia, s))
  s += b[ia-1]
  if b_ia != 0 and (b_ia + 1) == ia:
    s += c[b_ia-1]
  b_ia = ia
print(s)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	const int NUM = 10;
	int con = 0;
	int N;
	string s;
	static int  dp[NUM+1][NUM+1][NUM+1] = {};
	
	cin>>N;
	cin>>s;
	
	for(int i = 0; i < N; i++){
		int n = s[i] - '0';
		
		for(int j = 0; j < NUM; j++){
			for(int k = 0; k < NUM; k++){
				if(dp[j][k][NUM]){
					dp[j][k][n] = true;
				}
			}
			if(dp[j][NUM][NUM]){
				dp[j][n][NUM] = true;
			}
		}
		
		dp[n][NUM][NUM] = true;
	}
	
	for(int i = 0; i < NUM; i++){
		for(int j = 0; j < NUM; j++){
			for(int k = 0; k < NUM; k++){
				if(dp[i][j][k]) con++;
			}
		}
	}
	
	cout<<con<<endl;
	
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
	int n;
	List<Integer> a = new ArrayList<>();
	int max, result;

	private Main(Scanner in) {
		n = Integer.parseInt(in.nextLine());
		String[] tokens = in.nextLine().split(" ");
		for (int i = 0; i < n; ++i) {
			a.add(Integer.parseInt(tokens[i]));
		}
	}

	private void calc() {
		// 最大値をとる
		max = a.stream().max(new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {
				if (o1 < o2) {
					return -1;
				} else if (o1 > o2) {
					return 1;
				} else {
					return 0;
				}
			}
		}).get().intValue();
		double half = (double) max / 2.0;
		result = -1;
		double diff = Double.MAX_VALUE;
		for (Integer val : a) {
			if (val != max && diff > Math.abs((double) val - half)) {
				diff = Math.abs((double) val - half);
				result = val;
			}
		}
	}

	private void show() {
		System.out.println(max + " " + result);
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Main ins = new Main(in);
		in.close();
		ins.calc();
		ins.show();
	}

}

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

int main()
{
  int a, b, c;
  while( cin >> a >> b >> c ) {
    if( a == 0 && b == 0 && c == 0 ) break;
    int p = 2*a, r = 2*a;
    int q = -(-b+(sqrt((double)(b*b-4*a*c))));
    int s = -(-b-(sqrt((double)(b*b-4*a*c))));
    //int tmp = (int)sqrt((double)(b*b-4*a*c));
    //cout << b*b-4*a*c << endl;
    //cout << sqrt((double)b*b-4*a*c) << endl;
    //cout << q << " " << s << endl;
    int tmp = (int)sqrt((double)(b*b-4*a*c));
    //cout << tmp << endl;
    if( abs(sqrt((double)(b*b-4*a*c)) - (double)tmp) != 0 || b*b-4*a*c < 0 ) {
      cout << "Impossible" << endl;
    } else { 
      //cout << sqrt((double)(b*b-4*a*c)) << endl;
      //cout << q << " " << s << endl;
      for(int i=100000; i>1; i--) {
	if( !(p % i) && !(q % i) ) {
	  p /= i; q /= i;
	}
	if( !(r % i) && !(s % i) ) {
	  r /= i; s /= i;
	}
	
	
      }

      if( p < r ) {
	swap(p, r);
	swap(q, s);
      }
      if( p == r ) {
	if( q < s ) {
	  swap(q, s);
	}
      }
      cout << p << " " << q << " " << r << " " << s << endl;
    }
  }
}
  

Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{ return firstElof.second < secondElof.second; }
//**Snippetリスト**//
//rep, vin, all//
//gcdlcm, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; 
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D;
//***********//
int main() {
	cin >> N;
	ll L = pow(4, 3);
	vll F(N + 1, vl(L, 0));
	for (i = 0; i < N + 1; i++) {
		for (j = 0; j < L; j++) {
			F[i][j] = 0;
			if (i == 3) {
				F[i][j] = 1;
				if (j == 2*4+1|| j == 2*16+1 || j == 1*4+2) F[i][j] = 0;
			}
		}
	}
	for (i = 3; i < N; i++) {
		for (j = 0; j < L; j++) {
			ll p = j; vl a = { 0,0,0 };
			a[2] = p % 4; p /= 4; a[1] = p % 4; p /= 4; a[0] = p % 4;
			//ABCDの順
			string S = "NNNN";
			for (k = 0; k < 3; k++) {
				if (a[k] == 0) S[k] = 'A';
				else if (a[k] == 1) S[k] = 'C';
				else if (a[k] == 2) S[k] = 'G';
				else if (a[k] == 3) S[k] = 'T';
			}
			for (k = 0; k < 4; k++) {
				if (k == 0) S[3] = 'A';
				else if (k == 1) S[3] = 'C';
				else if (k == 2) S[3] = 'G';
				else if (k == 3) S[3] = 'T';
				ll next = a[1] * 16 + a[2] * 4 + k;
				ll valid = 1;
				if (S[0] == 'A' && S.substr(2, 2) == "GC") valid = 0;
				if (S.substr(0,2) == "AG" &&S[3] == 'C') valid = 0;
				if (S.substr(1,3) == "AGC") valid = 0;
				if (S.substr(1, 3) == "GAC") valid = 0;
				if (S.substr(1, 3) == "ACG") valid = 0;
				if (valid) F[i + 1][next] = (F[i + 1][next] + F[i][j]) % MOD;
				//cout << F[i][j] << " " << S << " " << valid << endl;
			}
		}
	}
	for (j = 0; j < L; j++) {
		ans = (ans + F[N][j])%MOD;
	}
	cout << ans;
}
	


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

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

	int n, p;
	string s;
	cin >> n >> p >> s;
	if (p == 2 || p == 5) {
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if ((s[i] - '0') % p == 0) ans += (i + 1);
		}
		cout << ans << endl;
	} else {
		map<int, int> ps;
		ps[0] = 1;
		int ans = 0;
		int cp = 0;
		int tp = 1;
		for (int i = n - 1; i >= 0; i--) {
			cp += (s[i] - '0') * tp;
			tp *= 10;
			tp %= p;
			cp %= p;
			ans += ps[cp % p];
			ps[cp % p]++;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 1044