akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;


struct edge{
  int cost;
  int to;
  edge(int to,int cost):to(to),cost(cost){}
};
int H,W;
vector<edge> G[11];
int d[10];
void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P>> que;
  fill(d,d+10,INF);
  d[s]=0;
  que.push(P(0,s));

  while(!que.empty()){
   P p=que.top();que.pop();
   int v=p.second;
   if(d[v]<p.first)continue;
   for(int i=0;i<G[v].size();i++){
     edge e = G[v][i];
     if(d[e.to]>d[v]+e.cost){
       d[e.to] = d[v] + e.cost;
       que.push(P(d[e.to],e.to));
     }
   }
  }
}

int main(){
  cin>>H>>W;
  rep(i,10)rep(j,10){
    int a;
    cin>>a;
  //  G[i].push_back(edge(j,a));
    G[j].push_back(edge(i,a));
  }

  dijkstra(1);
  int ans=0;
  rep(i,H)rep(j,W){
    int a;
    cin>>a;
    if(a==-1)continue;
    ans+=d[a];
    dump(a);
    dump(d[a]);
    dump(ans);
  }
  cout<<ans<<endl;


}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int N, M;
vector<vector<int>> E, ansE, revansE;
int cntin[100000 + 100], cntout[100000 + 100];
int d[100000 + 100], Log[100000 + 100];

int main() {
	cin >> N >> M;
	E.resize(N), ansE.resize(N);
	revansE.resize(N);
	for (int i = 0; i < N + M - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		E[a].push_back(b);
		cntout[a]++;
		cntin[b]++;
	}

	queue<int> q;
	for (int i = 0; i < N; i++) {
		if (cntin[i] == 0) {
			q.push(i);
			break;
		}
	}

	vector<int> sorted;
	while (q.size()) {
		int pos = q.front();
		q.pop();
		sorted.push_back(pos);
		
		for (int i = 0; i < E[pos].size(); i++) {
			int nxt = E[pos][i];
			cntin[nxt]--;
			if (cntin[nxt] == 0) {
				q.push(nxt);
			}
		}
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < E[sorted[i]].size(); j++) {
			int nxt = E[sorted[i]][j];
			if (d[nxt] < d[sorted[i]] + 1) {
				d[nxt] = d[sorted[i]] + 1;
				Log[nxt] = sorted[i];
			}
		}
	}

	for (int i = 0; i < N; i++) {
		if (cntout[i] == 0) {
			//葉ならば
			int idx = i;
			while (idx != sorted[0]) {
				revansE[idx].push_back(Log[idx]);
				idx = Log[idx];
			}
		}
	}

	for (int i = 0; i < N; i++) {
		if (revansE[i].size() == 0)cout << 0 << endl;
		else cout << revansE[i][0] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 16376
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	long long int d,n,a=1,sum=0;
	cin>>d>>n;
	for(int i=0;i<d;i++){
		a=100*a;
	}
	if(n!=100){
		cout<<a*n<<endl;
	}
	else{
		cout<<a*101<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
arr = gets.split
stack = []
arr.each{|s|
  case s
  when "+";
    a = stack.pop
    b = stack.pop
    stack.push(b+a)
  when "-";
    a = stack.pop
    b = stack.pop
    stack.push(b-a)
  when "*";
    a = stack.pop
    b = stack.pop
    stack.push(b*a)
  else
    stack.push(s.to_i)
  end
}
puts stack[0]

Measured memory_bytes: 8592
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
c = [list(map(int,input().split())) for i in range(m)]

for i in a:
    ans = [abs(i[0]-j[0])+abs(i[1]-j[1])for j in c]
    ans_min = min(ans)
    print(ans.index(ans_min)+1)

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

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

int main(){
  int N,A;
  cin >> N >> A;
  vector<int> x(N+1);
  x.at(0)=0;
  for(int i=1;i<=N;i++)  cin >> x.at(i);

  vector<vector<vector<long long>>> dp(N+1,vector<vector<long long>>(N+1,vector<long long>(N*50+1,0)));
  dp.at(0).at(0).at(0)=1;
  for(int i=1;i<=N;i++){
    for(int j=0;j<=i;j++){
      for(int k=0;k<=N*50;k++){
        dp.at(i).at(j).at(k)=dp.at(i-1).at(j).at(k);
        if(j>=1 && k>=x.at(i))  dp.at(i).at(j).at(k)+=dp.at(i-1).at(j-1).at(k-x.at(i));
      }
    }
  }

  long long ans=0;
  for(int j=1;j<=N;j++){
    ans+=dp.at(N).at(j).at(j*A);
  }
  cout << ans << endl;
  
  return 0;
}


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


int A[4];
int main(){
	cin >> A[0] >> A[1] >> A[2] >> A[3];
	sort(A,A+4);
	if(A[0]==1 && A[1]==4 && A[2]==7 && A[3]==9) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
#define MOD_BIG2 998244353
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

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



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

int main() {
    
    int N;
    cin >> N;
    vector<ll> A(N);
    std::multiset<ll> ms;
    int cnt = 0;
    REP(i, N) {
        cin >> A[i];
        ms.insert(A[i]);
        if (A[i] < 0) {
            cnt++;
        }
    }
    std::sort(A.begin(), A.end());
    int M = 0;
    if (cnt == 0) {
        M -= A[0];
        FOR(i, 1, N) {
            M += A[i];
        }
        cnt = 1;
    } else if (cnt == N) {
        M += A[N-1];
        IFOR(i, 0, N-1) {
            M -= A[i];
        }
        cnt = N-1;
    } else {
        REP(i, N) {
            M += std::abs(A[i]);
        }
    }
    cout << M << endl;
    ll x, y;
    std::queue<ll> tmp;
    FOR(i, 0, N-cnt-1) {
        y = *ms.begin();
        x = *std::prev(ms.end());
        cout << y << " " << x << endl;
        ms.erase(ms.begin());
        ms.erase(std::prev(ms.end()));
        ms.insert(y-x);
    }
    FOR(i, 0, cnt) {
        y = *std::prev(ms.end());
        x = *ms.begin();
        cout << y << " " << x << endl;
        ms.erase(std::prev(ms.end()));
        ms.erase(ms.begin());
        ms.insert(y-x);
    }
    
    return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

ll rui(ll a,ll b){
    if(b==1) return a%mod;
    else if(b==0) return 1;
    else if(b%2==0) return (rui(a,b/2)*rui(a,b/2))%mod;
    else return (rui(a,b-1)*a)%mod;
}

ll inv[MAX],fac[MAX],finv[MAX];

void make(){
    
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    
    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
    
}

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

int main(){

    int N,K;cin>>N>>K;
    if(N>K) cout<<0<<endl;
    else cout<<1<<endl;
}




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

int main() {
  int N ,D;
  cin >> N >> D;
  vector<vector<int>> data(N, vector<int>(D));
  for(int i = 0;i < N;i++){
    for(int j =0;j < D;j++){
      cin >> data.at(i).at(j);
    }
  }
  
  int count = 0;
  int sum = 0;
  
  for(int j = 0;j < N;j++){
    for(int k = j + 1;k < N;k++){
      int sum = 0;
      for(int i = 0;i < D;i++){
        sum += (data.at(k).at(i) - data.at(j).at(i)) * (data.at(k).at(i) - data.at(j).at(i));
  }
  
  for(int i = 0;i <= sum;i++){
    if(i * i == sum){
      count++;
    }
  }
    }
  }
  cout << count << endl;
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();

    System.out.println(((n - h) + 1) * ((n - w) + 1));

  }
}

Measured memory_bytes: 35776
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>

#define BIT(a) (1 << (a))

using namespace std;

long long MOD = 1000000007;


long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

int amari[1000];

int main(void){
	int N;
	cin >> N;
	int a;
	int flag = 1;
	for (int i = 0; i < N; i++){
		cin >> a;
		if (amari[a%(N-1)] && flag){
			cout << amari[a%(N-1)] << " " << a << endl;
			flag = 0;
		}
		else amari[a%(N-1)] = a;
	}
	return 0;

}




Measured memory_bytes: 3100
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

int n,a[10005],b[10005];ll s;

int main(){
	scanf("%d",&n);
	fore(i,0,n)scanf("%d",a+i);
	fore(i,0,n)scanf("%d",b+i);
	fore(i,0,n)s+=b[i]-a[i];
	fore(i,0,n){
		s-=max(a[i]-b[i],0);
		if(b[i]>a[i]&&(b[i]-a[i])%2)s--;
	}
	puts(s>=0?"Yes":"No");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int main() {
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N), F(N);
	rep(i,N) {
		cin >> A[i];
	}
	rep(i,N) {
		cin >> F[i];
	}
	sort(all(A));
	sort(rall(F));
	ll res;
	ll l = 0, r = 1e17;
	while(l <= r) {
		ll m = (l + r) / 2;
		ll cnt = 0;
		rep(i,N) {
			if(A[i] * F[i] > m) {
				cnt += A[i] - (m / F[i]);
			}
		}
		if(cnt <= K) {
			res = m;
			r = m-1;
		}
		else {
			l = m+1;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define fo(int, i, a, b)        for (int i=a; i<(b); i++)
#define forev(int, i, b, a)     for (int i = (b)-1; i >= a; i--)
#define uns                     unsigned
#define lli                     long long int
#define ld                      long double
#define all(x)                  x.begin(), x.end()
#define sortall(x)              sort(all(x))
#define enl                     "\n"
// #define PI 3.1415926535897932384626
// const int MOD = 1000000007; const lli INF = 1e18; const int MX = 100001;
//==================================================================================

void solve() {
    int a; cin >> a;
    cout << a +  a * a + a * (a * a);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // int testcase; cin >> testcase; for (int i = 1; i <= testcase; ++i)
    solve();
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main() {
	int n, k; cin >> n >> k;
	int a[200005];
	map<int, int> m;
	for(int i=0;i<n;i++){
		cin >> a[i];
		m[a[i]]++;
	}
	int s = 0;
	vector<int> v;
	for(auto kv:m){
		if(kv.second!=0){
			s++;
			v.push_back(kv.second);
		}
	}
	if(s<=k){
		cout << 0 << endl;
		return 0;
	}
	sort(v.begin(), v.end());
	int ans = 0;
	for(int i=0;i<s-k;i++){
		ans += v[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11516
#include <stdio.h>

int main(){
  int N,S=0,n;
  scanf("%d",&N);
  n=N;


  
  while(n){
    S+=n%10;
    n=n/10;
  }

  if(N%S)
    printf("No\n");
  else
    printf("Yes\n");

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;

ll w[100005], v[100005];
ll dp[105][100005];

int main() {
	int N, W; cin >> N >> W;
	for (int i = 1; i <= N; i++) cin >> w[i] >> v[i];
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= W; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j >= w[i]) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}

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

using namespace std;

int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };
int field[8][8] = { { 0 } };
bool used[8][8] = { { false } };
vector<int> startX, startY;

bool dfs(int n, int x, int y, int r, int k){
	if(r == 0){
		if(k == startX.size()){ return true; }
		x = startX[k];
		y = startY[k];
		++k;
	}else if(used[y][x] || field[y][x] < 0){
		return false;
	}
	r -= field[y][x];
	if(r < 0){ return false; }
	used[y][x] = true;
	if(r == 0){
		if(dfs(n, 0, 0, 0, k)){ return true; }
	}else{
		for(int i = 0; i < 4; ++i){
			int nx = x + dx[i], ny = y + dy[i];
			if(x >= 0 && x < n && y >= 0 && y < n){
				if(dfs(n, nx, ny, r, k)){ return true; }
			}
		}
	}
	used[y][x] = false;
	return false;
}

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		int sum = 0;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				cin >> field[i][j];
				sum += field[i][j];
				if(field[i][j] < 0){
					startX.push_back(j);
					startY.push_back(i);
				}
				used[i][j] = false;
			}
		}
		cout << (sum == 0 && dfs(n, 0, 0, 0, 0) ? "YES" : "NO") << endl;
		startX.clear();
		startY.clear();
	}
	return 0;
}

Measured memory_bytes: 912
#include<iostream>
#include<stdio.h>
#include<algorithm>
 
using namespace std;
 
int main(){
  int k, x;
  cin >> k >> x;
  
  int inf = x - k + 1;
  int sup = x + k - 1;
  
  if(inf != sup){
    for(int i = inf; i <= sup; ++i){
      cout << i << " ";
    }
    cout << endl;
  }else{
    cout << x;
  }
  
  return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n,m; cin >> n >> m;

    for(i32 dist = m, p = 1, q = n; dist >= 1; --dist) {
        if(dist%2 == m%2) {
            cout << p << ' ' << p+dist << '\n';
            ++p;
        }
        else {
            cout << q-dist << ' ' << q << '\n';
            --q;
        }
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 3624
N = int(input())
L0 = 2
L1 = 1
if N == 0:
    print(L0)
elif N == 1:
    print(L1)
else:    
    for _ in range(N-1):
        L = L1 + L0
        L0 = L1
        L1 = L
    print(L)

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

if N==2:
  print(1)
  exit()

ans = 2 # N and N-1
for K in range(2, N):
    if K*K>N: break
    n = N
    if n%K!=0: continue
    while n%K==0: n//=K
    if n%K==1: ans +=1

y = 0
N_ = N-1
for K in range(2, N):
    if K*K>=N_: break
    if N_%K==0: y +=2
if K*K==N_: y += 1

print(ans+y)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>

using namespace std;

int map[1000][1000];
int n;
int ans;

void serch(int x,int y,int h)
{
	for(int i=0;y+i<n && map[x][y+i]==1;i++)
	{
		h=i+1;
	}
	
	for(int i=0;i<h;i++)
	{
		if(x+i==n)
		{
			h=i;
			break;
		}
		for(int j=0;j<h;j++)
		{
			if(y+j==n)
			{
				h=j;
				break;
			}
			if(map[x+i][y]==0)
			{
				h=i;
				break;
			}
			if(map[x+i][y+j]==0)
			{
				h=j;
				break;
			}
		}
	}
	ans=max(ans,h);
	return ;
}
int main()
{
	int i,j;
	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		ans=0;
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				char a;
				cin >> a ;
				if(a=='.')
					map[i][j]=1;
				else
					map[i][j]=0;
			}
		}
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				if(map[i][j]==1)
				{
					serch(i,j,1);
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3904
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e6+69, INF=2e9+6969;

int qq;

int main()
{
	int l,r,d;
	cin >> l >> r >> d;
	ll ans=0;
	for(int i=l;i<=r;++i) if(i%d==0) ans++;
	printf("%lld\n", ans);
	return 0;
}


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

#define M 100005
#define MOD 1000000007
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> PII;
typedef pair<ulli,ulli> PLL;

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

    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

	int n,m;
	cin>>n>>m;

	vector<lli> h(n+1);
	for(int i=1;i<=n;i++)
		cin>>h[i];

	vector<int> adjList[n+1];
	for(int i=0;i<m;i++)
	{
		int u,v;
		cin>>u>>v;
		adjList[u].ep(v);
		adjList[v].ep(u);
	}

	lli ans = 0;
	for(int i=1;i<=n;i++)
	{
		if(adjList[i].size()==0)
		{
			ans++;
			continue;
		}

		int flag = 1;
		for(int x:adjList[i])
		{
			if(h[i]<=h[x])
			{
				flag = 0;
				break;
			}
		}

		if(flag == 1)
			ans++;
	}

	cout<<ans<<"\n";
}


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
int n;
int ans = 1e9+7;
inline int js(int k) {
	int cnt = 0;
	do{
		cnt += (k % 10);
		k /= 10;
	} while(k > 0);
	return cnt;
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		ans = min(ans, js(i) + js(n-i));
	}
	printf("%d", ans);
	return 0;
} 

Measured memory_bytes: 256
n = gets.to_i
count = 0
case n
when 1..9
  count = n
when 10..99
  count = 9
when 100..999
  count = n - 90
when 1000..9999
  count = 909
when 10000..99999
  count = n - 90 - 9000
when 100000
  count = 90909
end
puts count


Measured memory_bytes: 1788
#include <iostream>
#include<vector>
#define roop(i,n) for(int i=0;i<n;i++)
using namespace std;
vector<int> iwa;
signed main() {
	int ta, rin, suo, age;
	cin >> ta >> rin;
	suo = rin;
	roop(i, ta) {
		cin >> age;
		iwa.push_back(age);
	}
	roop(i, ta-1) {
		if (iwa[i + 1]-iwa[i] < rin )suo += iwa[i+1]-iwa[i];
		else suo += rin;
	}
	cout << suo << endl;
}

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

int main() {
  int N;
  int cnt=0;
  int i;
  cin >> N;
  int a[N];/////////こいつの位置！？！？！？！？！？
  for(i=0;i<N;i++){
    cin >> a[i];
  }

  //処理
  for( i=0;i<N-2;i++){
    if(a[i]==a[i+1]&&a[i+1]==a[i+2]){
      a[i+1]= 10001;
      cnt++;
    }
  }
  for( i=0;i<N-1;i++){
    if(a[i]==a[i+1]){
      a[i]= 10002;
      cnt++;
    }
  }



  cout<<cnt<<endl;
  /*for( i=0;i<N;i++){
    cout << a[i]<<" " ;
  }*/
}


Measured memory_bytes: 256
import java.util.*;

class Main
{
	public static void main(String[] args)
	{
		String S,str1,str2;
		Scanner sc = new Scanner(System.in);
		S = sc.next();
		
		str1 = S.substring(0,2);
		str2 = S.substring(2);
		
		int a = Integer.parseInt(str1);
		int b = Integer.parseInt(str2);
				
		if((a>12 && b>12) || (a==0 && b>12) || (a>12 && b==0) || (a==0 && b==0))	System.out.println("NA");
		else if((a<=12 && b>12) || (a<=12 && b==0))	System.out.println("MMYY");
		else if((a>12 && b<=12) || (a==0 && b<=12))	System.out.println("YYMM");
		else	System.out.println("AMBIGUOUS");
	}
}

Measured memory_bytes: 21716
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

pair<pair<char,int>,int> variable(const string& s,int i,map<char,int>& ntos,map<pair<char,int>,int>& vton);

pair<int,int> expression(const string& s,int i,map<char,int>& ntos,map<pair<char,int>,int>& vton)
{
	if(isdigit(s[i])){
		int x=0;
		for(;i<s.size() && isdigit(s[i]);i++)
			x=x*10+s[i]-'0';
		return mp(x,i);
	}
	else{
		auto p=variable(s,i,ntos,vton);
		char name; int index;
		tie(name,index)=p.first;
		if(index>=ntos[name]) throw "out of range";
		if(!vton.count(mp(name,index))) throw "undefined";
		return mp(vton[p.first],p.second);
	}
}

pair<pair<char,int>,int> variable(const string& s,int i,map<char,int>& ntos,map<pair<char,int>,int>& vton)
{
	char name=s[i];
	auto p=expression(s,i+2,ntos,vton);
	return mp(mp(name,p.first),p.second+1);
}

void program(const string& s,map<char,int>& ntos,map<pair<char,int>,int>& vton)
{
	if(s.find('=')==string::npos){ // declaration
		ntos[s[0]]=atoi(s.substr(2,s.size()-3).c_str());
	}
	else{ // assignment
		auto p=variable(s,0,ntos,vton);
		char name; int index;
		tie(name,index)=p.first;
		if(index>=ntos[name]) throw "out of range";
		assert(s[p.second]=='=');
		auto q=expression(s,p.second+1,ntos,vton);
		vton[p.first]=q.first;
	}
}

int main()
{
	for(string s;getline(cin,s) && s!=".";){
		vs lines;
		do{
			lines.push_back(s);
			getline(cin,s);
		}while(s!=".");
		
		//dump(lines);
		
		map<char,int> ntos; // name -> size
		map<pair<char,int>,int> vton; // variable -> number
		
		int res=0;
		rep(i,lines.size()){
			try{
				program(lines[i],ntos,vton);
				//cout<<"ntos:"; for(auto p:ntos) cout<<' '<<p; cout<<endl;
				//cout<<"vton:"; for(auto p:vton) cout<<' '<<p; cout<<endl;
			}
			catch(...){
				res=i+1;
				break;
			}
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1416
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

 
int main() {
    string s;
    cin>>s;
    string t=s;
    reverse(all(s));
    int n=s.size();
    rep(i,n){
        if(s[i]!=t[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    t=s.substr(0,n/2);
    string u=t;
    reverse(all(u));
    rep(i,n/2){
        if(t[i]!=u[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    t=s.substr(n/2+1,n/2);
    u=t;
    reverse(all(u));
    rep(i,n/2){
        if(t[i]!=u[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>
struct Node {
  int p,l,r;
};
void print(int);
#define NIL -1
struct Node T[100005];
int rec(int,int);
int n,F[100005];
int main(){
  scanf("%d",&n);
  int i,j,k,s,v,h,m;
  for(i=0;i<n;i++){
    T[i].p=NIL;
    T[i].l=NIL;
    T[i].r=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&k,&s);
    for(j=0;j<s;j++){
      scanf("%d",&v);
      if(j==0){
	T[k].l=v;
      }else{
	T[h].r=v;
      }
      h=v;
      T[v].p=k;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL)m=i;
  }
  rec(m,0);
  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}
int rec(int u,int s){
  F[u]=s;
  if(T[u].r!=NIL) rec(T[u].r,s);
  if(T[u].l!=NIL) rec(T[u].l,s+1);
}
void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",F[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");
}		    



Measured memory_bytes: 6380
#include <bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define pb push_back
int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    vector<ll>v;
    v.pb(a*c);
    v.pb(a*d);
    v.pb(b*c);
    v.pb(b*d);
    cout<<*max_element(v.begin(),v.end());
    
   
}

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

const long long INF =  1000000000000;
const long long N = 10000;

long long n,m;
struct edge{
	long long from,to,cost; 
}w[N];

long long d[N];

void path(long long s){
	for(long long i=0;i<n;i++) d[i]=INF;
	d[s] = 0;
	while(true){
		bool u = false;
		for(long long i=0;i<m;i++){
			edge e = w[i];
			if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
				d[e.to] = d[e.from]+e.cost;
				//printf("d[%lld] = %lld\n",e.to,d[e.to]);
				u = true;
			}
		}
		if(!u) break;
	}
}

bool f(){
	memset(d,0,sizeof(d));
	for(long long i=0;i<n;i++){
		for(long long j=0;j<m;j++){
			edge e = w[j];
			if(d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				if(i==n-1) return true;
			}
		}
	}
	return false;
}

int main(){
	while((scanf("%lld%lld",&n,&m))!=EOF){
		for(long long i=0;i<m;i++){
			scanf("%lld%lld%lld",&w[i].from,&w[i].to,&w[i].cost);
		}
		if(f()) {
			printf("NEGATIVE CYCLE\n");
			continue;
		}
		for(long long i=0;i<n;i++){
			path(i);
			for(long long j=0;j<n;j++){
				if(d[j]==INF&&j!=n-1) printf("INF ");
				else if(d[j]==INF&&j==n-1) printf("INF");
				else if(d[j]!=INF&&j==n-1)printf("%lld",d[j]);
				else if(d[j]!=INF&&j!=n-1)printf("%lld ",d[j]);
			}
			printf("\n");
		}
	}
} 



Measured memory_bytes: 3460
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	a, b, c := sc.nextInt(), sc.nextInt(), sc.nextInt()
	if (b - a) == (c - b) {
		fmt.Fprintln(wtr, "YES")
	} else {
		fmt.Fprintln(wtr, "NO")
	}

	wtr.Flush()
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{

    static int GCD(int a, int b)
    {
        var c = 1;
        while (c != 0)
        {
            c = a % b;
            a = b;
            b = c;
        }
        return a;
    }
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split().Select(int.Parse).ToArray();

        var s = new SegmentTree<int>(A, int.MaxValue, aa);
        var ans = Max(s.Query(1, N), s.Query(0, N - 1));
        for (int i = 1; i < N - 1; i++)
        {
            ans = Max(ans, GCD(s.Query(0, i), s.Query(i + 1, N)));
        }
        WriteLine(ans);
    }

    static int aa(int a, int b)
    {
        if (a == int.MaxValue) return b;
        if (b == int.MaxValue) return a;
        return GCD(a, b);
    }
}

public class SegmentTree<T> where T : struct
{
    T[] buffer;
    int N;
    T IE;
    Func<T, T, T> Op;


    public SegmentTree(T[] init, T E, Func<T, T, T> op)
    {
        var c = 1;
        while (c < init.Length) c <<= 1;
        N = c;
        buffer = new T[N * 2 - 1];
        for (int i = 0; i < buffer.Length; i++)
        {
            buffer[i] = E;
        }
        Array.Copy(init, 0, buffer, N - 1, init.Length);
        for (int i = N - 2; i >= 0; i--)
        {
            buffer[i] = op(buffer[i * 2 + 1], buffer[i * 2 + 2]);
        }
        Op = op;
        IE = E;
    }

    public void Update(int index, T value)
    {
        index += N - 1;
        buffer[index] = value;
        while (index > 0)
        {
            index = (index - 1) / 2;
            buffer[index] = Op(buffer[index * 2 + 1], buffer[index * 2 + 2]);
        }
    }

    public T this[int index]
    {
        set
        {
            Update(index, value);
        }
        get
        {
            return buffer[index + N - 1];
        }
    }

    public T Query(int l, int r)
    {
        var y = IE;
        l += N - 1;
        r += N - 1;
        while (l < r)
        {
            if ((l & 1) == 0)
            {
                y = Op(y, buffer[l]);
            }
            if ((r & 1) == 0)
            {
                y = Op(y, buffer[r - 1]);
            }
            l /= 2;
            r = (r - 1) / 2;
        }
        return y;
    }
}


Measured memory_bytes: 27228
//Md Fahad
// CSE 18

#include<bits/stdc++.h>


using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / __gcd(a,b)))
#define en '\n'

#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);
#define Infi                0x3f3f3f3f

const int fx[] = {+1,-1,+0,+0};                         // 4 X directions
const int fy[] = {+0,+0,+1,-1};                         // 4 Y directions
const int fx8[] = {+0,+0,+1,-1,-1,+1,-1,+1};            // King X Moves
const int fy8[] = {-1,+1,+0,+0,+1,+1,-1,-1};            // King Y Moves
const int kx[] = {-2, -2, -1, -1,  1,  1,  2,  2};      // Knight X Moves
const int ky[] = {-1,  1, -2,  2, -2,  2, -1,  1};      // Knight Y Moves



int  Set    (int N,int pos) {return N=N | (1<<pos);}    /// turn a bit on
int  reset  (int N,int pos) {return N= N & ~(1<<pos);}  /// turn a bit off
bool check  (int N,int pos) {return (bool)(N & (1<<pos));} /// check, if a bit is on or not

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif


typedef long long int           ll;
typedef unsigned long long int  llu;

int main(void){

    int n;
    cin >> n;
    ll sum =0;
    for(int i=1;i<=n;i++){

        if(i%3==0 || i%5==0){
            //sum+=i;
        }
        else{
            sum+=i;
        }
    }
    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 3648
N = gets.to_i
W = gets.split.map(&:to_i)

result = []
1.upto(N-1) do |t|
  s1 = [0]
  s2 = [0]
  W.each_with_index do |w, i|
    if i + 1 > t
      s2 << w
    else
      s1 << w
    end
  end

  result << (s1.inject(:+) - s2.inject(:+)).abs
end

p result.min

Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

double x[20],y[20];

int main(){
	int c=0;
	while(scanf("%lf,%lf",&x[c],&y[c])!=EOF){c++;}
	double ans=x[0]*y[c-1]-x[c-1]*y[0];
	for(int i=1;i<c;i++)ans+=x[i]*y[i-1]-x[i-1]*y[i];
	if(ans<0)ans*=-1;
	printf("%.6f",ans/2);
}

Measured memory_bytes: 0
s = input()
t = input()
ls, lt = len(s), len(t)
ans = float("inf")
for i in range(ls - lt + 1):
    cnt = 0
    s2 = s[i:i + lt]
    for j in range(lt):
        if s2[j] != t[j]:
            cnt += 1
    ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 9060
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
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 II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    S = SI()
    ans = 'Good' if S[0] != S[1] != S[2] != S[3] else 'Bad'
    return ans

print(main())

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int n, r;
  cin >> n >> r;

  if (n >= 10) cout << r << endl;
  else cout << r + 100 * (10 - n) << endl;
}


Measured memory_bytes: 3600
import sys

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N = ni()
A = nl()


def solve():
    tot = sum(A)
    ans = 1 << 60
    s = 0
    for i, x in enumerate(A):
        if i == N - 1:
            break
        s += x
        a = abs(2 * s - tot)
        ans = min(ans, a)
    return ans


print(solve())


Measured memory_bytes: 23792
N=int(input())
if N>=100000:
    print(9+900+90000)
elif N>=10000:
    print(9+900+N-9999)
elif N>=1000:
    print(9+900)
elif N>=100:
    print(9+N-99)
elif N>=10:
    print(9)
else:
    print(N)

Measured memory_bytes: 2940
import Data.ByteString.Char8 as BS
import Data.List
main = do
  s <- BS.getLine :: IO BS.ByteString
  let xs = BS.sort $ BS.filter (`BS.notElem` s) $ BS.pack ['a'..'z']
  BS.putStr $ if BS.null xs then BS.pack "None" else BS.singleton $ BS.head xs


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

int main() {
  int k,t;
  cin >> k >> t;
  int ma=0;
  rep(i,t){
    int u;
    cin >> u;
    ma=max(ma,u);
  }
  if(ma>(k*1)/2){
    cout << k-1-(k-ma)*2 << endl;
  }
  else cout << 0 << endl;
}


Measured memory_bytes: 256
using System;
class Mainclass
{
    static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        Array.Sort(str);
        if (str[0] == "5" && str[1] == "5" && str[2] == "7")
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 26012
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int fact(int n)
{
  int m;

  if (n == 0)
    return 1;    // 0! = 1
  /* 以下、n が 0 でないとき */
  m = fact(n - 1);    // (n-1)! を求めてそれを m とおく。ここのfact(n-1)が再帰呼出し。
  return n * m;       // n! = n * m
}

int main()
{
  int n;
  cin>>n;
  vector<vector<int>> v(n,vector<int>(2));
  for(int i=0;i<n;i++){
    for(int j=0;j<2;j++){
      cin>>v.at(i).at(j);
    }
  }
  vector<int> p(n);
  iota(p.begin(),p.end(),0);
  double sum=0;
  do{
    double r=0;
     //for(auto x : p) cout << x << " "; cout << "\n";
    for(int i=0;i<n-1;i++){
      r+=sqrt(pow(v[p[i]][0]-v[p[i+1]][0],2)+pow(v[p[i]][1]-v[p[i+1]][1],2));
    }
    sum+=r;
  }while(next_permutation(p.begin(), p.end()));
  printf("%lf",sum/fact(n));
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
M = max(A)
num = [0] * (M)
T = [0] * (M)
for a in A:
  num[a-1] += 1
  T[a-1] = 1
for i in range(M):
  if num[i] != 0 and T[i] == 1:
    n = 2 * (i + 1)
    while n <= M:
      T[n-1] = 0
      n += (i + 1)
ans = 0
for i in range(M):
  if T[i] == 1 and num[i] == 1:
    ans += 1
print(ans)

Measured memory_bytes: 140644
#include<bits/stdc++.h>
using namespace std;
#define int long long
template <class Q>
void clearQueue(Q & q) {
    q = Q();
}
void solve(){
	int n;cin>>n;
    vector<int>h(n);
    for(int& x:h){
        cin>>x;
    }
    int dp[n];
    memset(dp,0,sizeof(dp));
    dp[0]=0;
    for(int i=1;i<n;i++){
        if(i==1){
            dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        }
        else{
            dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
        }
    }
    cout<<dp[n-1];
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL); 
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 4696
#include<iostream>
#include <string>
#include <cstdlib> //絶対値利用のため
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
	int a[6];
	bool b = false;
	for (int i = 0; i < 6; i++) cin >> a[i];


	for (int j = 1; j <= 4; j++) {
		int counter = 0;
		for (int i = 0; i < 6; i++) {
			if (j == a[i]) counter++;
		}
		if (counter == 3) {
			b = true;
			break;
		}
	}

	if (b == true) cout << "NO" << endl;
	else cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    int n; cin>>n; 
    cout << n*n*n+n*n+n<< endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3604
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


int main()
{
    ll n,k,i,j,cc;
    cin>>n>>k;

        ll rem=n%k;
        cout<<min(rem,abs(rem-k))<<endl;

return 0;
}


Measured memory_bytes: 8268
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[200100];

int main(){
  ll x;
  cin>>x;
  clr(dp,0);
  dp[0] = 1;
  rep(i,0,200050){
    rep(j,0,6){
      ll a = 100+j;
      if(i-a>=0&&dp[i-a]==1){
        dp[i] = 1;
      }
    }
  }
  cout << dp[x] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstdlib>
#include<set>

using namespace std;

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

int main(){
    string s;
    cin >> s;
    bool flag = false;
    rep(i, s.size()){
        // cout << i << endl;
        if (i == 0){
            if (s[i] != 'A'){
                cout << "WA" << endl;
                return 0;
            }
        }else if (i >= 2 && i <= s.size() - 2){
            if(s[i] == 'C' && flag){
                cout << "WA" << endl;
                return 0;
            }else if(s[i] == 'C' && !flag){
                flag = true;
            }else if (0 > s[i] - 'a' && s[i] - 'a' >= 26){
                cout << "WA" << endl;
                return 0;
            }
        }else{
            if (0 > s[i] - 'a' || s[i] - 'a' >= 26){
                cout << "WA" << endl;
                return 0;
            }
        }
        

    }
    if (flag){
        cout << "AC" << endl;
    }else{
        cout << "WA" << endl;
    }
}

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

using namespace std;

long long n,a,b;

int main()
{
    cin>>n>>a>>b;
    if(n>1&&b>=a||n==1&&a==b)
        cout<<(n-2)*(b-a)+1<<endl;
    else
        cout<<0<<endl; 
 } 

Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;

int main(void){

    ll N,K; cin>>N>>K;
    vector<ll> A(N+1,0);
    vector<ll> check(N+1,0);
    vector<pair<ll,ll>> visited;

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

    ll looppos = 0;

    ll nowpos = 1;
    check[nowpos]++;
    visited.push_back(make_pair(1,A[nowpos]));
    nowpos = A[nowpos];

    for (int i = 1; i <= N; ++i) {
        check[nowpos]++;
        if(check[nowpos]!=1){ // ok
            looppos = nowpos;
            break;
        }
        visited.push_back(make_pair(nowpos,A[nowpos]));
        nowpos = A[nowpos];
    }

    if(K<visited.size()){
        cout<<visited[K].first<<endl;
        return 0;
    }

    ll looppos2 = 0;
    ll katamari = 0;
    for (int i = 0; i < visited.size(); ++i) {
        if(visited[i].first==looppos){
            looppos2 = i;
            katamari = visited.size() - i;
            break;
        }
    }

    K -= looppos2;
    ll tmp = K % katamari;
    cout<<visited[looppos2+tmp].first<<endl;


}


Measured memory_bytes: 10592
a, b = map(int, input().split())

A = list(map(int, input().split()))

B = []

for i in range(b):
    begin = A[i]
    # end = A[-1+i]
    if i == 0:
        end = A[-1+i]
    else:
        end = A[-1+i] + a
    B.append(end - begin)
print(min(B))

Measured memory_bytes: 87372
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  int n,i,j;
  scanf("%d\n",&n);
  for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
      if(i*j==n){
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 384