akhauriyash/Code-Regression huggingface dataset:
package main

import (
    "fmt"
    "math"
)

func min(nums ...int) int {
    res := nums[0]
    for i := 0; i < len(nums); i++ {
        res = int(math.Min(float64(res), float64(nums[i])))
    }
    return res
}

func main() {
    var n int
    var ws []int

    var sum int
    sum = 0
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        var w int
        fmt.Scan(&w)
        ws = append(ws, w)
        sum += w
    }
    var tmp int
    tmp = 0
    var ans int
    ans = 10000000
    for i := 0; i < n; i++ {
        tmp += ws[i]
        ans = min(ans, int(math.Abs(float64(tmp - (sum - tmp)))))
    }
    fmt.Println(ans)
}

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

int main(){
	// sengen
	long long sum,k,n;
	// nyuryoku
	cin >> n >> k;
	// keisan
	sum = k;
	for(int i=0;i<n-1;i++){
		sum *=k-1;
	}
	cout << sum;
}

Measured memory_bytes: 256
import numpy as np

def search_min(h):
    global ans
    my_min = min(h)
    ans += my_min
    if len(h) == 1:
        return 0
    min_index = [i for i, k in enumerate(h) if k == my_min]
    h -= my_min
    if len(min_index) > 1:
        for i in range(len(min_index) - 1):
            h_new = h[min_index[i] + 1: min_index[i + 1]]
            if len(h_new) > 0:
                search_min(h_new)
    h_new = h[: min_index[0]]
    if len(h_new) > 0:
        search_min(h_new)
    h_new = h[min_index[-1] + 1:]
    if len(h_new) > 0:
        search_min(h_new)
        
    return 0
    
if __name__ == "__main__":
    N = int(input())
    H = list(map(int, input().split()))
    H_new = [H[i] for i in range(1, len(H)) if H[i] != H[i - 1]]
    H_new.insert(0, H[0])
    H_new = np.array(H_new)
    ans = 0
    search_min(H_new)
    print(ans)

Measured memory_bytes: 14488
import sys

while True:
    n = int(sys.stdin.readline().rstrip())
    if n == 0:
        break;
    x = {}
    for i in range(n):
        k,v = sys.stdin.readline().rstrip().split()
        x[k] = v
    n = int(sys.stdin.readline().rstrip())
    y = []
    for i in range(n):
        a = sys.stdin.readline().rstrip()
        if a in x.keys():
            y.append(x[a])
        else:
            y.append(a)
    print(''.join(y))

Measured memory_bytes: 8660
#include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
     
    const int RLEN=1<<18|1;
    inline char nc() {
        static char ibuf[RLEN],*ib,*ob;
        (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
        return (ib==ob) ? -1 : *ib++;
    }
    inline int rd() {
        char ch=nc(); int i=0,f=1;
        while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
        while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
        return i*f;
    }
     
    const int N=1e5+50;
    int n,m,stx,sty,dep[N],fa[N],s[N];
    vector <int> edge[N]; LL ans=0;
    inline void dfs(int x,int f,int val) {
        dep[x]=dep[f]+1; fa[x]=f; s[x]=val;
        for(auto v:edge[x]) {
            if(v!=f) {
                if(dep[v]) stx=x, sty=v;
                else dfs(v,x,-val), s[x]+=s[v];
            }
        }
    }
    inline int lca(int x,int y) {
        while(dep[x]>dep[y]) x=fa[x];
        while(dep[x]<dep[y]) y=fa[y];
        while(x!=y) x=fa[x], y=fa[y];
        return x;
    }
    int main() {
        n=rd(), m=rd();
        for(int i=1;i<=m;i++) {
            int x=rd(), y=rd();
            edge[x].push_back(y);
            edge[y].push_back(x);
        } dfs(1,0,1);
        if(m==n-1) {
            if(s[1]) {puts("-1"); return 0;}
            for(int i=1;i<=n;i++) ans+=abs(s[i]);
        } else {
            if((dep[stx]-dep[sty])&1) { // even circle
                if(s[1]) {puts("-1"); return 0;}
                static int a[N],tot;
                int l=lca(stx,sty);
                for(int u=stx;u!=l;u=fa[u]) a[++tot]=s[u],dep[u]=-1;
                for(int u=sty;u!=l;u=fa[u]) a[++tot]=-s[u],dep[u]=-1;
                a[++tot]=0; int mid=tot/2+1;
                nth_element(a+1,a+mid,a+tot+1);
                int z=a[mid];
                for(int i=1;i<=n;i++) if(~dep[i]) ans+=abs(s[i]);
                for(int i=1;i<=tot;i++) ans+=abs(a[i]-z);
            } else {
                if(s[1]&1) {puts("-1"); return 0;}
                int z=-s[1]/2; ans+=abs(z);
                for(int u=stx;u;u=fa[u]) s[u]+=z;
                for(int u=sty;u;u=fa[u]) s[u]+=z;
                for(int i=1;i<=n;i++) ans+=abs(s[i]);
            }
        } cout<<ans<<'\n';
    }

Measured memory_bytes: 10880
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long D = scanner.nextLong();
        long D2 = D * D;

        long[] X = new long[N];
        long[] Y = new long[N];

        for (int i = 0; i < N; i++) {
            X[i] = scanner.nextLong();
            Y[i] = scanner.nextLong();
        }

        int result = 0;
        for (int i = 0; i < N; i++) {
            if (X[i]*X[i] + Y[i]*Y[i] <= D2) {
                result++;
            }
        }

        System.out.println(result);
    }

}


Measured memory_bytes: 64456
#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;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 123;
int n, a[N], p[N], b[N];
ll f[2][N], t, cur, ans[N];

void upd(int c, int x, ll y) {
	for (; x <= n; x |= (x + 1))
		f[c][x] += y;
}

ll get(int c, int x) {
	ll res = 0;
	for (; x >= 0; x = (x & (x + 1)) - 1)
		res += f[c][x];
	return res;
}

void solve(int pos, int mx) {
	if (pos == 1) {
		ans[pos] = t - cur;
		return;
	}
	int to = p[pos - 1];
	for (int i = pos; i > to; i--)
		upd(0, b[i], 1), upd(1, b[i], a[i]);
	ll num = get(0, mx) - get(0, b[to]);
	ans[pos] = (get(1, mx) - get(1, b[to])) - a[to] * num;
	upd(0, b[to], num);
	upd(1, b[to], num * a[to]);
	cur += ans[pos];
	solve(to, b[to]);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	vector <int> v;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		t += a[i];
		v.pb(a[i]);
		p[i] = p[i - 1];
		if (a[i] > a[p[i]])
			p[i] = i;
	}
	sort(all(v));
	v.erase(unique(all(v)), v.end());
	for (int i = 1; i <= n; i++) b[i] = lower_bound(all(v), a[i]) - v.begin() + 1;
	for (int i = n; i > p[n]; i--)
		upd(0, b[i], 1), upd(1, b[i], a[i]);
	solve(p[n], b[p[n]]);
	for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
}


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

typedef pair<int, int> pii;

int N, K;
vector<vector<int> > adj;
vector<int> col;
vector<pii> dp;
vector<int> pari;

void dfs(int u, int p) {
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(v == p) continue;
        pari[v] = pari[u] ^ 1;
        dfs(v, u);
    }
}

bool dfs1(int u, int p) {
    dp[u] = pii(-1e9, 1e9);
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(v == p) continue;
        if(!dfs1(v, u)) return false;
        dp[u].first = max(dp[u].first, dp[v].first - 1);
        dp[u].second = min(dp[u].second, dp[v].second + 1);
    }
    if(col[u] != -1) {
        if(dp[u].first <= col[u] && col[u] <= dp[u].second) {
            dp[u] = pii(col[u], col[u]);
            return true;
        }
        else return false;
    }
    else return dp[u].first <= dp[u].second;
}

vector<int> sol;

void dfs2(int u, int p) {
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(v == p) continue;
        sol[v] = (dp[v].first <= sol[u] - 1)? sol[u] - 1 : sol[u] + 1;
        dfs2(v, u);
    }
}

int main() {
    scanf("%d", &N);
    adj.resize(N);
    for(int i = 0; i < N - 1; i++) {
        int u, v; scanf("%d %d", &u, &v);
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    col = vector<int>(N, -1);
    scanf("%d", &K);
    for(int i = 0; i < K; i++) {
        int u, c; scanf("%d %d", &u, &c);
        col[--u] = c;
    }
    pari = vector<int>(N, 0);
    dfs(0, -1);
    int p = -1;
    for(int i = 0; i < N; i++) if(col[i] != -1) {
        if(p == -1) p = (col[i] % 2) ^ pari[i];
        else if(p != (col[i] % 2) ^ pari[i]) {
            printf("No");
            return 0;
        }
    }
    dp = vector<pii>(N);
    if(dfs1(0, -1)) {
        printf("Yes\n");
        sol = vector<int>(N);
        sol[0] = dp[0].first;
        dfs2(0, -1);
        for(int i = 0; i < N; i++) {
            printf("%d\n", sol[i]);
        }
    }
    else printf("No");
}


Measured memory_bytes: 16128
from collections import defaultdict
import itertools

def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf

n = int(input())

plist = defaultdict(lambda: 0)
for i in range(2, n+1):
	for j, k in pfact(i).items():
		plist[j] += k

def makediv(n):
	lower_divisors , upper_divisors = [], []
	i = 1
	while i*i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n//i)
		i += 1
	return lower_divisors + upper_divisors[::-1]

shichigo = set(makediv(75))
shichigo.remove(1)

thelist = [j+1 for j in plist.values()]
thelist.sort()

ansdict = {
	3: 0,
	5: 0,
	15: 0,
	25: 0,
	75: 0
}

for cnt, i in enumerate(thelist):
	for j in range(i+1):
		if j in shichigo:
			ansdict[j] += 1

"""
75
= 5*15
= 3*25
= 3*5*5
"""

ans = 0
ans += ansdict[75]
ans += ansdict[15]*(ansdict[5]-1)
ans += ansdict[25]*(ansdict[3]-1)
ans += ansdict[5]*(ansdict[5]-1)*(ansdict[3]-2)//2
print(ans)

Measured memory_bytes: 3444
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

class Node{
public:
    int location;
    int p, l, r;
    Node(){}
};

class Point{
public:
    int id, x, y;
    Point(){}
    Point(int id, int x, int y): id(id), x(x), y(y) {}
    bool operator < ( const Point &p) const {
        return id < p.id;
    }
    
    void print() {
        printf("%d\n", id);
    }
};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1, const Point &p2) { return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2) { return p1.y < p2.y; }

int makeKDTree(int l, int r, int depth){
    if(!(l<r)) return NIL;
    int mid = (l+r)/2;
    int t = np++;
    if(depth%2==0){
        sort(P+l, P+r, lessX);
    } else {
        sort(P+l, P+r, lessY);
    }
    T[t].location = mid;
    T[t].l = makeKDTree(l, mid, depth+1);
    T[t].r = makeKDTree(mid+1, r, depth+1);
    
    return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans){
    int x = P[T[v].location].x;
    int y = P[T[v].location].y;
    
    if(sx<=x && x<=tx && sy<=y && y<=ty){
        ans.push_back(P[T[v].location]);
    }
    
    if(depth%2==0){
        if(T[v].l != NIL){
            if(sx<=x) find(T[v].l, sx, tx, sy, ty, depth+1, ans);
        }
        if(T[v].r != NIL){
            if(x<=tx) find(T[v].r, sx, tx, sy, ty, depth+1, ans);
        }
    } else {
        if(T[v].l != NIL){
            if(sy <= y) find(T[v].l, sx, tx, sy, ty, depth+1, ans);
        }
        if(T[v].r != NIL){
            if(y<=ty) find(T[v].r, sx, tx, sy, ty, depth+1, ans);
        }
    }
}

int main(){
    int x, y;
    scanf("%d", &N);
    for(int i=0; i<N; i++){
        scanf("%d %d", &x, &y);
        P[i] = Point(i, x, y);
        T[i].l = T[i].r = T[i].p = NIL;
    }
    
    np = 0;
    
    int root = makeKDTree(0, N, 0);
    
    int q;
    scanf("%d", &q);
    int sx, tx, sy, ty;
    vector<Point> ans;
    for(int i=0; i<q; i++){
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
        ans.clear();
        find(root, sx, tx, sy, ty, 0, ans);
        sort(ans.begin(), ans.end());
        for(int j=0; j<ans.size(); j++){
            ans[j].print();
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 15952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef pair<l_l,ll> lll;
typedef vector<string> vs;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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 ll mod=1000000007;
ll dp[110][11000],dp_sum[110][11000];
ll a[110];
int main(){
    ll n,k;cin>>n>>k;
    rep(i,n)cin>>a[i];
    dp[0][0]=1;
    dp_sum[0][0]=1;
    rrep(i,n){
        for(int j=0;j<=k;j++){
            dp_sum[i-1][j]=dp[i-1][j];
            if(j>=1){
                dp_sum[i-1][j]+=dp_sum[i-1][j-1];
                dp_sum[i-1][j]%=mod;
            }
        }
        for(int j=0;j<=k;j++){
            dp[i][j]=dp_sum[i-1][j];
            if(j-a[i-1]-1>=0){
                dp[i][j]-=dp_sum[i-1][j-a[i-1]-1];
                dp[i][j]%=mod;
                if(dp[i][j]<0)dp[i][j]+=mod;
            }
        }
    }
    cout<<dp[n][k]<<endl;
    return 0;
}

Measured memory_bytes: 22064
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=50+5;
int main()
{
	int n,k;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		long long num,i,j,even=0,odd=0;
		for(i=1;i<=n;i++)
		cin>>num,even+=(!(num&1)),odd+=(num&1);
		if(k)
		{
			if(odd)
			cout<<(1ll<<(odd-1))*(1ll<<even)<<endl;
			else
			cout<<0<<endl;
		}
		else 
		{
			if(odd==0)
			cout<<(1ll<<n)<<endl;
			else
			cout<<(1ll<<(odd-1))*(1ll<<even)<<endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 256
'use strict';
function main(input) {
  input = input.split("\n");
  const a = input[0];
  
  if (a[2] === a[3] && a[4] === a[5]) {
    console.log('Yes');
  } else {
    console.log('No');
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
const long long mo=50000007;
const int maxn=200010;

int n,m,id[maxn],fa[maxn];
long long d[maxn],siz[maxn],ans,js[maxn];
int tot,nex[maxn*2],las[maxn*2],tov[maxn*2];
int hs[mo+10];

void con(int x,int y)
{
	tot++;
	tov[tot]=y;
	nex[tot]=las[x];
	las[x]=tot;
}

void insert(long long x,int id)
{
	long long i=x%mo;
	while (hs[i]!=0)
	{
		i++;
		if (i==mo) i=0;
	}
	hs[i]=id;
}

long long find(long long x)
{
	long long i=x%mo;
	while (hs[i]!=0 && d[hs[i]]!=x)
	{
		i++;
		if (i==mo) i=0;
	}
	return hs[i];
}

void qsort(int l,int r)
{
	int i=l;int j=r;
	long long m=d[(i+j)/2];
	while (i<=j)
	{
		while (d[i]>m) i++;
		while (d[j]<m) j--;
		if (i<=j)
		{
			swap(d[i],d[j]);
			swap(id[i],id[j]);
			i++;j--;
		}
	}
	if (l<j) qsort(l,j);
	if (r>i) qsort(i,r);
}

void dfs(int x,int ff)
{
	js[x]=js[ff]+1;
	for (int i=las[x];i;i=nex[i])
	{
		if (tov[i]!=ff)
		{
			dfs(tov[i],x);
			ans+=js[x];
		}
	}
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&d[i]);
		id[i]=i;
		siz[i]=1;
	}
	qsort(1,n);
	for (int i=1;i<=n;i++)
	{
		insert(d[i],i);
	}
	for (int i=1;i<n;i++)
	{
		long long op=d[i]-(n-2*siz[i]);
		long long oq=find(op);
		if (oq==0 || oq==i)
		{
			printf("-1\n");
			return 0;
		}
		else
		{
			fa[i]=oq;
			siz[oq]+=siz[i];
			con(i,oq);con(oq,i);
		}
	}
	dfs(n,0);
	if (ans!=d[n])
	{
		printf("-1\n");
		return 0;
	}
	else
	{
		for (int i=1;i<n;i++)
		{
			printf("%d %d\n",id[i],id[fa[i]]);
		}
	}
}

Measured memory_bytes: 208896
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int n,ans=0;
string x;
int main(){
cin>>x;
n=x.size();
for(int i=0;i<n;i++)
if(x[i]=='A'){
for(int j=n-1;j>i;j--)
if(x[j]=='Z'){
ans=j-i+1;
break;}
break;
}
cout<<ans;
system("pause");
return 0;
}

Measured memory_bytes: 764
open Hashtbl

let h = create 1000

let f n =
  let rec g n' =
    if n' <= 0 then ()
    else
      let a = read_int () in
      (if mem h a then replace h a (not (find h a))
       else add h a true);
      g (n' - 1)
  in
  g n

let () =
  f (read_int ()) ;
  fold (fun _ v s -> if v then s + 1 else s) h 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 10112
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    tot_M = (N-1)*N/2
    M = tot_M - K
    if M < N - 1:
        print(-1)
        return
    print(int(M))
    cnt = 0
    for ix in range(N-1):
        print("1 {}".format(ix+2))
        cnt += 1

    for ix in range(2, N+1):
        for jx in range(ix+1, N+1):
            if cnt >= M:
                return
            print("{} {}".format(ix, jx))
            cnt += 1
            
main()



Measured memory_bytes: 68196
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      //freopen("q.gir","r",stdin);
      int n;
      cin>>n;
      cout<<n*n;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

struct Graph {
    struct Edge {
        bool operator>(Edge o) { return d > o.d; }
        int d, i;
    };
    Graph(int n) : e(n), v(n) {}
    void add_edge(int i, int j, int l) {
        e[i].push_back({ l, j });
    }
    void dijkstra(int i) {
        priority_queue<Edge, vector<Edge>, greater<>> q;
        fill(v.begin(), v.end(), 1 << 30);
        q.push({ v[i] = 0, i });
        while (!q.empty()) {
            auto p = q.top(); q.pop();
            if (p.d > v[p.i]) continue;
            for (auto o : e[p.i]) {
                int d = p.d + o.d;
                if (d < v[o.i]) {
                    v[o.i] = d;
                    q.push({ d, o.i });
                }
            }
        }
    }
    vector<vector<Edge>> e;
    vector<int> v;
};

int n, m, R;
int p[8];
int d[8][8];
int s = 1 << 30;

void dfs(int t, int d = 0) {
    if (d == R) {
        s = min(s, t);
        return;
    }
    for (int i = d; i < R; i++) {
        swap(p[d], p[i]);
        dfs(t + (d == 0 ? 0 : ::d[p[d - 1]][p[d]]), d + 1);
        swap(p[d], p[i]);
    }
}

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

    cin >> n >> m >> R;

    int r[8];
    for (int i = 0; i < R; i++) {
        cin >> r[i];
        r[i]--;
    }

    Graph g(n);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;

        g.add_edge(a, b, c);
        g.add_edge(b, a, c);
    }

    for (int i = 1; i < R; i++) {
        g.dijkstra(r[i]);
        for (int j = 0; j < i; j++) {
            d[i][j] = d[j][i] = g.v[r[j]];
        }
    }

    for (int i = 0; i < R; i++) {
        p[i] = i;
    }
    dfs(0);

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
int main(void)
{
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
	if(a>=b){
		printf("delicious\n");
	}else if(b-a<=x){
		printf("safe\n");
	}else{
		printf("dangerous\n");
	}
	return 0;
}

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


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

    int n,m;
    cin>>n>>m;
    int a[m];
    int ans = 0;
    for(int i=0;i<m;i++){
        cin>>a[i];
        if(a[i]>m) ans++;
    }
    cout << ans << endl;
    
}


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

vector<int> A(20);
vector<vector<int>> x(20, vector<int>(20));
vector<vector<int>> y(20, vector<int>(20));


int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;

    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        for (int j = 1; j <= A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }

    int answer = 0;
    for (int state = 1; state < (1 << N); state++) {
        bool isPossible = true;
        for (int i = 1; i <= N; i++) {
            if (!(state&(1 << (i - 1)))) continue;
            for (int j = 1; j <= A[i]; j++) {
                if (((state >> (x[i][j]-1)) & 1) ^ y[i][j]) isPossible = false;
            }
        }
        if(isPossible) answer = max(answer, __builtin_popcount(state));
    }

    cout << answer;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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 (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}


inline void solve(){

    int n;
    double v[100];
    cin >> n ;
    for(int i = 0; i < n; i++){
        cin >> v[i]; 
    }
    sort(v,v+n);
    double  ans = v[0];
    for(int i = 1; i < n;i++){
        ans = (ans+v[i])/2;
    }

    cout << ans fin;
        
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll a[100010];
    cin >> N;
    rep(i,0,N){
        cin >> a[i];
    }
    ll cnt_2 = 0;
    ll cnt_4 = 0;
    rep(i,0,N){
        if(a[i] % 4 == 0){
            cnt_4++;
        }else if(a[i] % 2 == 0){
            cnt_2++;
        }
    }

    ll ans = N;
    ans -= 2 * cnt_4;
    if(ans <= 1){
        print("Yes");
    }else{
        ans -= cnt_2;
        if(ans <= 0){
            print("Yes");
        }else{
            print("No");
        }
    }

}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>

using namespace std;
int n,k;
int a[233333],pos;
int main()
{
	scanf("%d%d",&n,&k);
	return printf("%d\n",(n-1+k-2)/(k-1)),0;
}

Measured memory_bytes: 256
void main(){
	int n,k;
	readf("%d %d\n", &n, &k);
	bool[] snk = new bool [n];
	fill(snk, true);
	
	// お菓子を持っていない人の数え上げ
	int d;
	int[] a;
	foreach(i; 0..k){
		d = _scan();
		a = _scanln();
		foreach(elm; a){
			snk[elm-1] = false; 
		}
	}
	snk.count(true).writeln();
}

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: 3324
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=5e5+5,mo=998244353;
int n,m,ans;
int f[N<<1],g[N];
inline int ksm(int x,int y)
{
	int s=1;
	while(y)
	{
		if(y&1) s=(LL)s*x%mo;
		x=(LL)x*x%mo;
		y>>=1;
	}
	return s;
}
inline int C(int x,int y)
{
	return (LL)f[x]*g[y]%mo*g[x-y]%mo;
}
int main()
{
	scanf("%d%d",&n,&m);
	if(n>m) swap(n,m);
	int inv2=mo+1>>1,up=n+m;
	f[0]=g[0]=1;
	for(int i=1;i<=up;i++) f[i]=(LL)f[i-1]*i%mo;
	g[m]=ksm(f[m],mo-2);
	for(int i=m-1;i;i--) g[i]=(LL)g[i+1]*(i+1)%mo;
	for(int i=m-n;i<m;i++)
	{
		int x=i,y=i-(m-n);
		ans=(ans+(LL)C(x+y,x)*C(m-x+n-y,m-x))%mo;
	}
	int num=(LL)inv2*ksm(C(n+m,m),mo-2)%mo;
	ans=(m+(LL)ans*num%mo)%mo;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX 2000000
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
  int x, y;
  cin >> x >> y;
  vector<int> dp(x);
  int M = max(x, y);
  COMinit();
  ll ans = 0;
  for (int i = 1; i <= min(x, y); i++)
  {
    int p = x - i,q=y-i;
    if(p+q==i){
      ans += COM(p + q, p);
      ans %= MOD;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 51072
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String board = s.next();
        int n = board.length();
        char prev = board.charAt(0);
        int a = 0;
        for (int i = 1; i < n; i++) {
            char c = board.charAt(i);
            if (c != prev) {
                a ++;
            }
            prev = c;
        }
        System.out.println(a);

    }
}


Measured memory_bytes: 25940
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=1e5,INF=1e8;
ll N;
vector<ll> G[MAX_N];
ll dp[MAX_N][2];
void dfs(ll v,ll p){
	vector<ll> chl;
	for(auto e:G[v]){
		if(e!=p){
			chl.push_back(e);
			dfs(e,v);
		}
	}
	if(chl.size()>1){
		ll chldp=0;
		for(auto c:chl){
			chldp+=dp[c][1];
		}
		dp[v][0]=INF;
		REP(i,chl.size()){
			dp[v][0]=min(dp[v][0],chldp-dp[chl[i]][1]+dp[chl[i]][0]);
		}
		dp[v][1]=dp[v][0];
	}else if(chl.size()==1){
		dp[v][0]=dp[chl[0]][0];
		dp[v][1]=min(dp[chl[0]][1],1+dp[chl[0]][0]);
	}else{
		REP(f,2){
			dp[v][f]=f;
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	REP(i,N-1){
		ll a,b;
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	ll rt=-1;
	REP(i,N){
		if(G[i].size()>=3){
			rt=i;
			break;
		}
	}
	ll ans;
	if(rt==-1){
		ans=1;
	}else{
		dfs(rt,-1);
		ans=dp[rt][0];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 14208
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string S;
	cin >> S;
	for (int i = 0, j = S.size() - 1; i < j; ++i, --j) {
		if (S[i] != S[j]) {
			cout << "No";
			return 0;
		}
	}
	for (int i = 0, j = (S.size() - 1) / 2 - 1; i < j; ++i, --j) {
		if (S[i] != S[j]) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)
S=input()
ans=0
def func(n,now):
    global ans
    if n==0:
        ans+=eval(now)
    else:
        func(n-1,now[:-n]+'+'+now[-n:])
        func(n-1,now[:-n]+now[-n:])
func(len(S)-1,S)
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-10;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
vector<int>G[110];
vector<int>g[110];
int bfs[110];
int pre[110];
int bk[110];
void dfs(int a,int b,int c){
	int tmp=0;
	for(int i=0;i<g[a].size();i++){
		if(b==g[a][i])continue;
		tmp++;
		dfs(g[a][i],a,c+1);
	}
//	printf("%d %d %d\n",a,c,tmp);
	bk[c]=max(bk[c],tmp);
}
int li[110];
pair<int,long long> solve(int n){
	for(int i=0;i<n;i++){
		bfs[i]=-1;
	}
	bfs[0]=0;
	queue<int>Q;
	Q.push(0);
	while(Q.size()){
		int at=Q.front();
		Q.pop();
		for(int i=0;i<g[at].size();i++){
			if(!~bfs[g[at][i]]){
				bfs[g[at][i]]=bfs[at]+1;
				Q.push(g[at][i]);
			}
		}
	}
	int mm=0;
	for(int i=0;i<n;i++){
		if(bfs[mm]<bfs[i])mm=i;
	}
	for(int i=0;i<n;i++)bfs[i]=-1;
	bfs[mm]=0;
	pre[mm]=-1;
	Q.push(mm);
	while(Q.size()){
		int at=Q.front();
		Q.pop();
		for(int i=0;i<g[at].size();i++){
			if(!~bfs[g[at][i]]){
				bfs[g[at][i]]=bfs[at]+1;
				pre[g[at][i]]=at;
				Q.push(g[at][i]);
			}
		}
	}
	int mv=0;
	int mr=0;
	for(int i=0;i<n;i++){
		if(mv<bfs[i]){
			mv=max(mv,bfs[i]);
			mr=i;
		}
	}
	int now=mr;
	int re1=mv/2+1;
//	printf("%d\n",re1);
	for(int i=0;i<=mv;i++){
		li[i]=now;
		now=pre[now];
	}
	for(int i=0;i<110;i++)bk[i]=1;
	//	printf("%d\n",re1);
	
	long long re2=1;
	if(mv%2==0){
		dfs(li[mv/2],-1,0);
		for(int i=0;i<re1;i++){
			re2*=bk[i];
		}
		int cc=li[mv/2];
		for(int i=0;i<g[cc].size();i++){
			for(int i=0;i<110;i++)bk[i]=1;
			bk[0]=2;
			dfs(cc,g[cc][i],1);
			dfs(g[cc][i],cc,1);
			long long tmp=1;
			for(int i=0;i<re1;i++){
				tmp*=bk[i];
			}
			re2=min(re2,tmp);
		}
	}else{
		bk[0]=2;
		dfs(li[mv/2],li[mv/2+1],1);
		dfs(li[mv/2+1],li[mv/2],1);
		for(int i=0;i<re1;i++){
			re2*=bk[i];
		}
	}
//	printf("%d %d %d %lld: ",mv,li[mv/2],re1,re2);
//	for(int i=0;i<re1;i++)printf("%d ",bk[i]);printf("\n");
	return make_pair(re1,re2);
}
int UF[120];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}

int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)UF[i]=-1;
	for(int i=0;i<a-1;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		assert(0<=p&&p<a);
		assert(0<=q&&q<a);
		
		G[p].push_back(q);
		G[q].push_back(p);
		UNION(p,q);
	}
	assert(UF[FIND(0)]==-a);
	for(int i=0;i<a;i++)g[i]=G[i];
	pair<int,long long>tmp=solve(a);
/*	for(int i=0;i<a;i++){
		for(int i=0;i<=a;i++)g[i]=G[i];
		g[i].push_back(a);
		g[a].push_back(i);
		tmp=min(tmp,solve(a+1));
	}*/
	printf("%d %lld\n",tmp.first,tmp.second);
}


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

int pow(int n){

        int ans = 1;
        for(int i=0;i<n;i++){
            ans *= 10;
        }
    return ans;

}


int main()
{
    long long N,A,bit=0;

    cin >>N;

    rep(i,N){
        cin >> A;
        if(A%2==0){
            if(A%3!=0 && A%5 !=0){
                bit = 1;
                break;
            }
        }
    }

    if(bit==0){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }

    return 0;

}

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n = lread();
    auto s = new string[n];
    foreach (ref e; s)
    {
        e = sread();
    }
    long count;
    auto first_b = new long[n];
    auto last_a = new long[n];
    foreach (i, e; s)
    {
        foreach (j; 0 .. e.length - 1)
        {
            if (e[j .. j + 2] == "AB")
            {
                count++;
            }
        }
        if (e[0] == 'B')
        {
            first_b[i]++;
        }
        if (e[$ - 1] == 'A')
        {
            last_a[i]++;
        }
    }
    long allequal;
    foreach (i; 0 .. n)
    {
        if (first_b[i] == last_a[i])
        {
            allequal++;
        }
    }
    auto mintwo = min(first_b.sum, last_a.sum);
    if (allequal == n && mintwo != 0)
    {
        count--;
    }
    writeln(count + mintwo);
}

Measured memory_bytes: 2556
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<unordered_set>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 1000 * 100 + 47;

struct Fenvic
{
	int T[MAX];
	int n;
	void init(int n1)
	{
		n = n1;
		FOR(i, 0, n) T[i] = 0;
	}

	void add(int i, int delta)
	{
		for (; i < n; i = i | (i + 1))
		{
			T[i] += delta;
		}
	}

	int get(int i)
	{
		int res = 0;
		for (; i >= 0; i = (i & (i + 1)) - 1)
		{
			res += T[i];
		}

		return res;
	}

	int get(int l, int r)
	{
		int res = get(r);
		if (l) res -= get(l - 1);
		return res;
	}
} F;

int A[MAX];
int B[MAX];
int C[3][MAX];

void no()
{
	cout << "No" << endl;
	exit(0);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, 3)
	{
		FOR(j, 0, n)
		{
			cin >> C[i][j];
			C[i][j]--;
		}
	}

	FOR(j, 0, n)
	{
		if (C[0][j] / 3 != C[1][j] / 3 || C[0][j] / 3 != C[2][j] / 3) no();

		A[j] = C[0][j] / 3;
		if (C[0][j] < C[1][j] && C[1][j] < C[2][j])
		{
			B[j] = 0;
			continue;
		}

		if (C[0][j] > C[1][j] && C[1][j] > C[2][j])
		{
			B[j] = 1;
			continue;
		}

		no();
	}

	FOR(i, 0, n)
	{
		if (A[i] % 2 != i % 2) no();
	}

	F.init(n);
	int odd = 0;
	for (int i = 0; i < n; i += 2)
	{
		odd ^= F.get(A[i] + 1, n - 1) % 2;
		F.add(A[i], 1);
	}

	F.init(n);
	int even = 0;
	for (int i = 1; i < n; i += 2)
	{
		even ^= F.get(A[i] + 1, n - 1) % 2;
		F.add(A[i], 1);
	}

	FOR(i, 0, n)
	{
		if (i % 2 == 0 && B[i] == 1) even ^= 1;
		if (i % 2 == 1 && B[i] == 1) odd ^= 1;
	}

	if (odd == 0 && even == 0)
	{
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;
}

Measured memory_bytes: 3712
#include <iostream>
#include <set>

using namespace std;

int main()
{
    int N;
    pair <int, int> r_pair;
    pair <int, int> r_pair_rev;
    set <pair <int, int> > r_set;
    int rabbit, index, counter;

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> rabbit;
        index = i + 1;
        r_pair_rev = make_pair(rabbit, index);
        r_pair = make_pair(index, rabbit);

        if (r_set.find(r_pair) != r_set.end()) {

        }
        else {
            r_set.insert(r_pair_rev);
        }
    }
    cout << endl;
    cout << N - r_set.size() << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
struct edge {
    int to, cost;
};

int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

map<int,int> factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////
signed main() {
int n;
cin>>n;
vector<int>a(n);
rep(i,n)cin>>a[i];
sort(a.begin(),a.end());
map<int,int>m;
rep(i,n)m[a[i]]++;
vector<int>an(1000050);
vector<int>furui(1000050,0);
for(auto i:a){
  if(furui[i]==0){
    an[i]=1;
  for(int t=i;t<1000050;t+=i){
    furui.at(t)++;
  }
}
}
int ans=0;
rep(i,n){
  if(m.at(a.at(i))==1&&an[a[i]]==1)ans++;
}
cout<<ans<<endl;
}


Measured memory_bytes: 32648
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

vector<int> par;
vector<int> depth;

int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if (x == y) return;

  if(depth[x] < depth[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if (depth[x] == depth[y]) depth[x]++;
  }
}

bool same(int x,int y){
  return find(x) == find(y);
}
    
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,q;
  cin >> n >> q;
  par.resize(n);
  REP(i,n)par[i] = i;
  depth.resize(n,0);
  REP(i,q){
    int type,x,y;
    cin >> type >> x >> y;
    if(!type){
      unite(x,y);
    }else{
      cout << same(x,y) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3260
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto n = readln.chomp.to!int;
  auto at = readln.chomp.split.to!(int[]);
  auto a = new int[][](n, 2);
  foreach (i; 0..n) {
    a[i][0] = at[i];
    a[i][1] = i.to!int;
  }
  a.sort!((a,b) => a[0] < b[0]);
  foreach (i; 0..n-1) {
    writef("%s ", a[i][1] + 1);
  }
  writefln("%s", a[$-1][1] + 1);
}


Measured memory_bytes: 10300
a[2][101],n,m,i,j,c,p;main(s){for(;scanf(m="%d",&n),n;printf(m>210?"NA\n":"%d\n",m)){for(i=2;i--;)for(j=0;j-n;scanf(m,a[i]+j++));for(i=2;i--;m>c?m=c:0)for(j=i,c=p=0;s=a[j][p],c<220&&s==2|n+~p;)p-n&&s-2?s-1|a[j][p+1]-1?p+=2,j=1&~j,++c:++p:--p;}}

Measured memory_bytes: 0
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
const int maxn = 100 + 10;
const int maxm = 2e5 + 10;
const int INF = 2147483647; 
typedef long long ll;
using namespace std;
inline int read()
{
	int x=0,t=1,c;
	while(!isdigit(c=getchar()))if(c=='-')t=-1;
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*t;
}
int head[maxn],cur[maxn],nx[maxm<<1],to[maxm<<1],flow[maxm<<1],ppp=2;
struct Dinic
{
	int d[maxn];
	int s,t;
	long long ans;
	void Init()
	{
		memset(head, 0, sizeof(head));
		ppp = 2;
	}
	void AddEdge(int u,int v,int c)
	{
		to[ppp]=v;flow[ppp]=c;nx[ppp]=head[u];head[u]=ppp++;swap(u,v);
		to[ppp]=v;flow[ppp]=0;nx[ppp]=head[u];head[u]=ppp++;
	}
	bool BFS()
	{
		memset(d,-1,sizeof d);
		d[t]=1;
		queue<int> Q;
		Q.push(t);
		while(!Q.empty())
		{
			int x=Q.front();Q.pop();
			for(int i=head[x];i;i=nx[i])
			{
				if(flow[i^1]&&d[to[i]]==-1)
				{
					d[to[i]]=d[x]+1;
					Q.push(to[i]);
				}
			}
		}
		return d[s]!=-1;
	}
	int DFS(int x,int maxflow)
	{
		if(x==t||!maxflow){ans+=maxflow;return maxflow;}
		int ret=0,f;
		for(int &i=cur[x];i;i=nx[i])
		{
			if(d[to[i]]==d[x]-1&&(f=DFS(to[i],min(maxflow,flow[i]))))
			{
				ret+=f;
				flow[i]-=f;
				flow[i^1]+=f;
				maxflow-=f;
				if(!maxflow)
					break;
			}
		}
		return ret;
	}
	long long solve(int source,int tank)
	{
		s=source;
		t=tank;
		ans=0;
		while(BFS())
		{
			memcpy(cur,head,sizeof(cur));
			DFS(s,INF);
		}
		return ans;
	}
}dinic;
int a[maxn];
ll sum, negsum;
int main()
{
	int n;
	scanf("%d", &n);
	dinic.Init();
	int s = n + 1, t = s + 1;
	for(int i = 1; i <= n; ++i) 
	{
		scanf("%d", &a[i]);
		sum += a[i];
		if(a[i] < 0) 
		{
			dinic.AddEdge(s, i, -a[i]);
			negsum += a[i];
		}
		if(a[i] > 0)
			dinic.AddEdge(i, t, a[i]);
		for(int j = i + i; j <= n; j += i)
			dinic.AddEdge(i, j, INF);
	}
	cout << sum - (negsum + dinic.solve(s, t)) << endl;
	return 0;
}


Measured memory_bytes: 2304
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] d = new int[n];
        Arrays.setAll(d, i -> scanner.nextInt());
        Arrays.sort(d);
        System.out.println(d[n / 2] - d[n / 2 - 1]);
    }
}

Measured memory_bytes: 53364
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

count = 0
for i in range(n):
    if A[i] >= B[i]:
        count += B[i]
    elif A[i] < B[i]:
        count += A[i]
        if A[i+1] >= B[i] - A[i]:
            count += B[i] - A[i]
            A[i+1] -= B[i] - A[i]
        else:
            count += A[i+1]
            A[i+1] = 0
            
print(count)

Measured memory_bytes: 18624
#include<stdio.h>

int main(void)
{
	int W,H,x,y,r;
	
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	if(W>=x+r&&H>=y+r&&x-r>=0&&y-r>=0){
	printf("Yes\n");
	}else{
		printf("No\n");}
	return 0;
}


Measured memory_bytes: 2104
// Atcoder contest
#include<iostream>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a==5 && b==5 && c==7)
  {
  	cout<<"YES";
  }
  else
  if(a==5 && b==7 && c==5)
  {
  	cout<<"YES";
  }	
  else
  if(a==7 && b==5 && c==5)
  {
  	cout<<"YES";
  }
  else
  {
  	cout<<"NO";
  }
}


Measured memory_bytes: 256
// Problem : C - Go Home
// Contest : AtCoder Regular Contest 070
// URL : https://atcoder.jp/contests/arc070/tasks/arc070_a
// Memory Limit : 256.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
#include<chrono>
using namespace std::chrono; 
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
//#define count(x, vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
//#define min(a, b, c) min(a, min(b, c))
//#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp;
string str;
set<ll> s;
vll v;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	auto start = high_resolution_clock::now(); 
	cin>>a;
	for(int i=1;i<=100000;i++)
	{
		b+=i;
		if(b>=a)
		{cout<<i;return 0;}
	}
	auto stop = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stop - start); 
	cout<<"\nRun time = ";
	cout <<fixed<<setprecision(5)<<(long double)duration.count()/1000<<" ms";
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N],b[N],c[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    for(int i=0;i<N;i++){
        cin >> b[i];
    }
    for(int i=0;i<N;i++){
        cin >> c[i];
    }
    int sum=0;
    sum = sum + b[a[0]-1];
    for(int i=1;i<N;i++){
        if(a[i]-a[i-1]==1){
            sum = sum + b[a[i]-1] + c[a[i-1]-1];
        } else {
            sum = sum + b[a[i]-1];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        int n=0;
        int []a=new int[5];
        for (int i = 0; i < 5; i++) {
            a[i]=tan.nextInt();
            if(a[i]==0)
                n=i+1;
        }
        System.out.println(n);
    }
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans=0, tmp=0;
string S, T;

signed main(){
    cin >> S >> T;
    for(int i=0;i<S.size();i++) {
        if(S[i]!=T[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int L, R, d;
    std::cin >> L >> R >> d;

    int ans = 0;
    for (int i = L; i <= R; ++i) {
        if (i % d == 0) {
            ++ans;
        }
    }

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


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

int main() {
  ll x,y; cin >>x >>y;
  ll cnt = 1;
  ll buf = x;
  
  while (true){
    if (buf<=y/2){
      cnt++; buf *= 2;
    }else{
      break;
    }
  }
  ll ans = cnt;
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl
#define MAX 1000000000
#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
long long a,b;
long long m;
long long Min(long long x,long long y)
{
	if(x>y)return y;
	else return x;
}
long long del(long long x,long long y,long long z)
{
	long long M=max(x,max(y,z));
	long long m=Min(x,Min(y,z));
	return M-m;
}
int main()
{
	m=MAX;//
	cin>>a>>b;
	if(a%3==0)
	{
		m=Min(m,0);
	}
	else m=Min(m,b);
	//cout<<m<<endl;
	rep(i,a-1)
	{
		if(b%2==0)
		{
			m=Min(m,abs((i+1)*b-(a-i-1)*b/2));
		}
		else m=Min(m,del((i+1)*b,(a-i-1)*(b-1)/2,(a-i-1)*(b+1)/2));
	}
	long long c=a;
	a=b;
	b=c;
	if(a%3==0)
	{
		m=Min(m,0);
	}
	else m=Min(m,b);
	rep(i,a-1)
	{
		if(b%2==0)
		{
			m=Min(m,abs((i+1)*b-(a-i-1)*b/2));
		}
		else m=Min(m,del((i+1)*b,(a-i-1)*(b-1)/2,(a-i-1)*(b+1)/2));
	}
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 256