akhauriyash/Code-Regression huggingface dataset:
let levenshtein_distance (x, y) =
  if x = y then 0
  else
    let m = String.length x in
    let n = String.length y in
    if m = 0 then n
    else if n = 0 then m
    else begin
      let s = Array.init (n + 1) (fun i -> i) in
      let t = Array.make (n + 1) 0 in
      for i = 0 to m - 1 do
        t.(0) <- i + 1;
        for j = 0 to n - 1 do
          let c = s.(j) + if x.[i] = y.[j] then 0 else 1 in
          let d = 1 + if t.(j) < s.(j+1) then t.(j) else s.(j+1) in
          t.(j+1) <- if c < d then c else d
        done;
        Array.iteri (fun i e -> s.(i) <- e) t
      done;
      t.(n)
    end

let () =
  Scanf.scanf "%s %s " (fun x y -> x, y)
  |> levenshtein_distance
  |> Printf.printf "%d\n"

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
int n;

struct data {
	ll x; int id;
	bool operator < (const data &t) const {
		return x < t.x;
	}
}a[maxn + 10];
ll b[maxn + 10], c[maxn + 10], dep[maxn + 10], d[maxn + 10];
int sz[maxn + 10];
vector<int> g[maxn + 10];

void dfs1(int p) {
	c[a[1].id] += dep[p]; sz[p] = 1;
	for (int i = 0; i < (int)g[p].size(); ++i) {
		int e = g[p][i];
		dep[e] = dep[p] + 1;
		dfs1(e); 
		sz[p] += sz[e];
	}
}

void dfs2(int p) {
	for (int i = 0; i < (int)g[p].size(); ++i) {
		int e = g[p][i];
		c[e] = c[p] + n - 2 * sz[e];
		dfs2(e);
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i].x);
		d[i] = a[i].x; a[i].id = i;
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i) {
		b[i] = a[i].x; sz[i] = 1;
	}
	for (int i = n; i > 1; --i) {
		ll v = b[i] - n + 2 * sz[i];
		int p = lower_bound(b + 1, b + i, v) - b;
		if (p < i && b[p] == v) {
			g[a[p].id].push_back(a[i].id);
			sz[p] += sz[i];
		} else {
			printf("-1"); return 0;
		}
	}
	dfs1(a[1].id);
	dfs2(a[1].id);
	for (int i = 1; i <= n; ++i)
		if (d[i] != c[i]) {
			printf("-1"); return 0;
		}
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j < (int)g[i].size(); ++j)
			printf("%d %d\n", i, g[i][j]);
}


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

int main(){
  
  int S,W;
  
  cin >> S >> W;
  
  if( W >= S ){
    
    cout << "unsafe" << endl;
    
  }
  
  else{
    
    cout << "safe" << endl;
    
  }
  
}

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

#define ll long long 
#define sz(x) (int)x.size()

using namespace std;

int main(){
	
	int n,x,ans=0,d=0;
	cin>>n>>x;
	for(int i=0;i<n;i++){
		int q;
		cin>>q;
		d+=q;
		if(d<=x)ans++;
	}
	cout<<ans+1;
}

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

const int N = 2e5 + 10;

int n;
int a[N], b[N];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i] - (i + 1);
  }
  sort(b, b + n);
  long long ans = 0;
  for (int i = 0; i < n; i++)
    ans += abs(b[i] - b[n / 2]);
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 1792
#ifndef LOCAL
#pragma GCC optimize("O2")
#endif
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

int main(){
    int N; cin >> N;
    vector<double> Ainverse;
    double S;S=0;
    for(int i=0; i<N; i++)
    {
        double tmp;
        cin >> tmp;
        S += 1 / tmp;
    }

    cout << 1 / S << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int in, a[4], b=1000, i;
	scanf("%d", &in);
	for(i=0;i<4;i++){
		a[i] = in/b;
		in -= b*a[i];
		b/=10;
	}	
	
	for(i=0;i<3;i++){
		if(a[i] == a[i+1]){
			printf("Bad");
			return 0;
		}	
	}	
	
	printf("Good");
	
	
	return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  int res = 0;
  for (int i = 0; i < (int)S.size(); i++) {
    res += S[i] - '0';
  }
  res = max(res, (S[0] - '0' - 1) + 9 * ((int)S.size() - 1));
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;

int H, W;
vector<string> grids;
vector<vector<bool>> visited;

Pii link_size(int i, int j) {
    visited[i][j] = true;
    bool color = grids[i][j] == '#';

    Pii ret = Pii(0, 0);
    if (color) ret.first++;
    else ret.second++;

    Pii t;
    if (i > 0 && grids[i][j] != grids[i-1][j] && !visited[i-1][j]) {
        t = link_size(i-1, j); 
        ret.first += t.first; 
        ret.second += t.second;
    }
    if (i < H-1 && grids[i][j] != grids[i+1][j] && !visited[i+1][j]) {
        t = link_size(i+1, j);
        ret.first += t.first; 
        ret.second += t.second;
    }
    if (j > 0 && grids[i][j] != grids[i][j-1] && !visited[i][j-1]) {
        t = link_size(i, j-1);
        ret.first += t.first; 
        ret.second += t.second;
    }
    if (j < W-1 && grids[i][j] != grids[i][j+1] && !visited[i][j+1]) {
        t = link_size(i, j+1);
        ret.first += t.first; 
        ret.second += t.second;
    }
    return ret;
}

int main() {
    cin >> H >> W;
    grids.resize(H);
    for (int i = 0; i < H; i++) cin >> grids[i];
    visited.resize(H);
    for (int i = 0; i < H; i++) visited[i].resize(W);
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) visited[i][j] = false;

    ll ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (!visited[i][j]) {
                Pii t = link_size(i, j);
                ans += (ll)t.first * (ll)t.second;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 18048
H, W = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min((c[i][j], c[i][k] + c[k][j]))
ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] == -1:
            continue
        ans += c[A[i][j]][1]
print(ans)


Measured memory_bytes: 3444
import math
import fractions
import functools
def main():
    n = int(input())
    a = [int(t)for t in input().split()]

    M = 10**9+7
    culcm = functools.reduce(lcm,a)

    b = [culcm//a_i for a_i in a]

    print(sum(b)%M)

def lcm(a,b):
    return a*b//fractions.gcd(a,b)

if __name__ == "__main__":
    main()

Measured memory_bytes: 264700
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double;
const string FILENAME = "input";
const int MAXN = 200228;


int n;
ll a[MAXN];


void solve() {
	cin >> n;
	ll sum = 0;
	for (int i = 0; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
	}	
	ll cur = 1;
	ll ans = 0;
	bool bad = false;
	for (int i = 0; i < n; i++) {
		ans += cur;
		if (cur < a[i]) {
			bad = true;
			break;
		}
		cur -= a[i];
		sum -= a[i];
		cur = min(cur * 2, sum);
	}
	ans += cur;
	if (cur != a[n]) {
		bad = true;
	}
	if (bad) {
		cout << -1 << '\n';
	} else {
		cout << ans << '\n';
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
	int t;
	//cin >> t;
	t = 1;
	while (t--) {
		solve();
	}
	return 0; 	
}

Measured memory_bytes: 4400
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9+5)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;

bool operator>(const PLL &a, const PLL &b){
	return a.second > b.second;
}

bool operator<(const PLL &a, const PLL &b){
	return a.second > b.second;
}

bool compare(const PLL &a, const PLL &b){
	return a.first < b.first;
}

int main(){
	LL N, M, P;
	cin >> N >> M >> P;
	vector<vector<PLL>> ro(N+1);
	REP(i, M){
		LL a, b, c;
		cin >> a >> b >> c;
		ro[a].push_back(PLL(b, c-P));
	}
	vector<LL> much(N+1, (LL)-INF*10);
	much[1]=0;
	REP(k, N){
		REPA(i, N+1){
			foreach(j, ro[i]){
			much[j.first] = max(much[j.first], much[i] + j.second);
			}
		}
	}
	LL ans = much[N];
	REPA(k, N){
		REPA(i, N+1){
			foreach(j, ro[i]){
			much[j.first] = max(much[j.first], much[i] + j.second);
			}
		}
	}
	if(ans != much[N]){
		cout << -1 << endl;
	}else{
		cout << max(ans, (LL)0) << endl;
	}
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int count=0;
int vec[n];
for(int i=0;i<n;i++)cin>>vec[i];
for(int i=0;i<n-1;i++){
    for(int a=i+1;a<n;a++){
        count=count+vec[i]*vec[a];
    }
}
cout<<count<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>
#include<time.h>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;


/*vectorの要素を全部確認するやつだよ。


for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}


*/


/*for文でx,yを上下左右確認するやつだよ。

int dy[] = { 0, 1, 0, -1 };
int dx[] = { 1, 0, -1, 0 };


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}
*/

/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}


*/

/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; i++) {
	for (int j = 0; j < w; j++) {

	}
}

*/


int main(void) {
	int a, p; cin >> a >> p;

	cout << (a * 3 + p) / 2 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
mint choose(int n,int a){
  mint x = 1,y=1;
  rep(i,a){
    x*= n-i;
    y*= i+1;
  }
  return x/y;
}
int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll> sum(n+2,0);
  sum[0]=0;
  rep(i,n+1){
    if(i==0)continue;
    sum[i]=sum[i-1]+i;
  }
  ll ans =0;
  for(int i=k;i<=n+1;i++){
    if(i==n+1)ans++;
    else{
    ans+=(sum[n]-sum[n-i])-sum[i-1]+1;
  }
  ans%=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4844
#include <iostream>
using namespace std;
int main()
{
    int N, Y;
    cin >> N >> Y;
    for(int i=0; i<=N; i++)
    {
    	for(int j=0; j<=N-i; j++)
    	{
    		 int X = 10000*i + 5000*j + 1000*(N-i-j);
             if(X==Y){
             	cout << i <<" "<< j <<" " << N-i-j<< endl; 
             	return 0;
             }
    	}
    }

    cout << -1 <<" "<<-1<<" "<<-1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>

using namespace std;

int main() {

   int i,ball,balls,num_ball_type;
   int ball_type[210000] = {0};
   int counter = 0;
   int number_of_changed_type = 0;

   cin >> balls >> num_ball_type;

   for(i = 0; i < balls; i++){
       cin >> ball; 
       ball_type[ball]++;
   }

   sort(ball_type,ball_type+210000,greater<int>());

   for(i = 0; i < 210000; i++){

       if(ball_type[i] == 0){
           break;
       }
       if(counter >= num_ball_type) {
           number_of_changed_type += ball_type[i];
       } else {
           counter++;
       }
   }

    cout << number_of_changed_type << endl;

    return 0;
}

Measured memory_bytes: 1024
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
ll dp[500][500], val[500][500];

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

  cin >> n;
  rep(i, n) cin >> a[i];

  rep(i, n + 1) rep(j, n + 1) dp[i][j] = LINF, val[i][j] = LINF;

  rep(i, n) {
    dp[i][i] = 0;
    val[i][i] = a[i];
  }
  rrep(diff, 1, n) {
    rep(i, n) {
      ll j = i + diff;
      if (j >= n) continue;
      rrep(k, i, j) {
        dp[i][j] =
            min(dp[i][j], dp[i][k] + dp[k + 1][j] + val[i][k] + val[k + 1][j]);
        val[i][j] = min(val[i][k] + val[k + 1][j], val[i][j]);
      }
    }
  }
  Cout(dp[0][n - 1]);
  return 0;
}

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

int main() {
  int x;
  cin >> x;
  int tmp = x / 500;
  int tmp_2 = x % 500;
  int tmp_3 = tmp_2 / 5;
  int total = 1000 * tmp + 5 * tmp_3;
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>

using namespace std;

int main(void)
{
	int n, m, c[21],dp[50001];
	cin >> n >> m;
	for (int i = 0;i < m;i++)
		cin >> c[i];

	memset(dp, 0x7f, sizeof(dp));
	dp[0] = 0;

	for (int i = 0;i < n;i++)
	{
		for (int j = 0;j < m;j++)
		{
			if(n>=i+c[j])
			dp[i + c[j]] = min(dp[i + c[j]], dp[i] + 1);
		}
	}
	cout << dp[n] << endl;
	return 0;
}


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


int main(){
  while(1){
    int n,p;
    cin>>n>>p;
    if(n==0&&p==0)return 0;
    vector<int> a(n,0);
    int pool=p;
    int i=0;
    while(1){
      for(i = 0;i<n;i++){
        //assert(0<=i && i<n);
        if(pool==0){
          pool+=a[i];
          a[i]=0;
        }else{
          pool--;
          a[i]++;
        }
        //assert(0<=i && i<n);
        if(a[i]==p)break;
      }
      //assert(0<=i && i<n);
      if(a[i]==p&&i<n)break;
    }
    cout<<i<<endl;
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> V(N + 1);
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j += i) {
      V.at(j)++;
    }
  }
  long ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += (long) i * V.at(i);
  }
  cout << ans << "\n";
}

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

int main(void){
	int n;
	cin >> n;
	int a[3];
	for(int i=0;i<n;++i) cin >> a[i];

	int limit=*min_element(a,a+n);
	
	
	set<int> ans;	
	
	for(int f=1;f*f<=limit;++f){
		if(limit%f) continue;
		bool small=true;
		for(int j=0;j<n;++j) if(a[j]%f) small=false;
		if(small) ans.insert(f);
		bool big=true;
		for(int j=0;j<n;++j) if(a[j]%(limit/f)) big=false;
		if(big) ans.insert(limit/f); 
	}

	for(auto &i:ans) cout << i << endl;
	return 0;
}

Measured memory_bytes: 3088
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    string s;
    cin >> s;
    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c=0;
  cin>>a>>b;
  for(int i=a;i<=b;i++){
    string s=to_string(i);
    string x=s;
    reverse(x.begin(),x.end());
    if(s==x) c++;
  }
  cout<<c;
}


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

int main() {
  string s;
  cin >> s;
  
  int i;
  deque<char> d;
  for(i = 0; i < s.size(); i++){
    if(s.at(i) == '0') d.push_back('0');
    else if(s.at(i) == '1') d.push_back('1');
    else{
      if(d.size() > 0) d.pop_back();
    }
  }
  
  while(!d.empty()){
    cout << d.front();
    d.pop_front();
  }
  cout << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            //string s = Console.ReadLine();

            // 整数の入力
            //long n = long.Parse(Console.ReadLine());

            // 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            var inputIntArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            var N = inputIntArray[0];
            var K = inputIntArray[1];
            int j;
            int[] d = new int[K];
            var listN = Enumerable.Range(1, N).ToList();

            for (j = 0; j < K; j++)
            {
                int n = int.Parse(Console.ReadLine());
                d[j] = n;
                var A = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
                List<int> listA= new List<int>(A);
                listN = listN.Except(listA).ToList();
            }


            Console.WriteLine(listN.Count());

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28936
import sys

n, m = map(int, sys.stdin.readline().split())
graph = [[] for _ in range(n)]
for i in range(m):
    for s in [int(x) for x in sys.stdin.readline().split()][1:]:
        graph[s-1].append(i)
*p, = map(int, sys.stdin.readline().split())

def main():
    cnt = 0
    for i in range(1 << n):
        bits = [0] * m
        for j in range(n):
            if i >> j & 1:
                for s in graph[j]:
                    bits[s] ^= 1
        for j in range(m):
            if bits[j] ^ p[j]: break
        else:
            cnt += 1
    print(cnt)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
  int a;
  int b;
  cin>>a>>b;
  if(a<b){
  cout<<"a < b"<<endl;
  }
  if(a>b){
    cout<<"a > b"<<endl;
  }
  if(a==b){
    cout<<"a == b"<<endl;
  }
}


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

// template {{{
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define sort_by(x, y) sort(all(x), [&](const auto& a, const auto& b) { return y; })

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;

using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;

template<typename T> void ckmin(T& a, const T& b) { a = min(a, b); }
template<typename T> void ckmax(T& a, const T& b) { a = max(a, b); }

void solve()
{
    int x;
    cin>>x;
    if(x==1)
        cout<<"0"<<endl;
    else
    {
        cout<<"1"<<endl;
    }
    
}
int main() {
    int t;
    
      solve();

    return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x;
	cin >> x;
	for(int i = 1; i <= 360; ++i){
		if((x*i)%360 == 0){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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

int main() {
        int n, maxv, minv, r;
        maxv = -1000000000;
        cin >> n;
        cin >> minv;
        for(int i = 0; i < n - 1; i++) {
                cin >> r;
                maxv = max(maxv, r - minv);
                minv = min(minv, r);
        }
        cout << maxv << endl;
        return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    ll high[n];
    for (int i = 0;i < n;i++){
        cin >> high[i];
    }
    ll hmax = 0;
    ll c = 0;
    for (int i = 0;i < n - 1;i++){
        if (high[i] >= high[i+1]){
            c++;

        }else{
            hmax = max(hmax,c);
            c = 0;
        }
    }
    hmax = max(hmax,c);
    cout << hmax << '\n';
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i=0;i<a.length;i++)
        {
            a[i] = scan.nextInt();
        }
        
        int tmp = 1;
        for(int i=0;i<a.length;i++)
        {
            tmp = a[tmp-1];
            if(tmp==2)
            {
                System.out.println(i+1);
                return;
            }
        }
        System.out.println(-1);
    }
}

Measured memory_bytes: 51988
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

const int size=1000000;
vector<int> map(size,1);
void sieve(int p)
{
    for(int j=p*2;j<size;j+=p)
    {
        map[j]=0;
    }
}
int main(void)
{
    map[0]=0;
    map[1]=0;
    sieve(2);
    sieve(3);
    sieve(5);
    for(int i=7;i<1000;i+=6)
    {
        sieve(i);
        sieve(i+4);
    }

    while(1)
    {
        int n;
        int num=scanf("%d",&n);
        if(num != 1)
            break;
        printf("%d\n",count(map.begin(),map.begin()+n+1,1));
    }
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var res = 0;
        for (var i = 0; i < num; i++)
        {
            var minj = i;
            for (var j = i; j < num; j++)
                if (ar[j] < ar[minj])
                    minj = j;
            if (i != minj) res++;
            var t = ar[i];
            ar[i] = ar[minj];
            ar[minj] = t;
        }
        WriteLine($"{string.Join(" ", ar)}\n{res}");
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


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

int main()
{
    int k;cin>>k;
    int a,b;cin>>a>>b;
    int x=0;
    for(int i=a;i<=b;i++)if(i%k==0)x=1;

    if(x==0)cout<<"NG"<<endl;
    else cout<<"OK"<<endl;



}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


const ll MOD = 1e9+7;
 
template <ll MOD>
struct modint{
    ll x;
    modint() : x(0) {}
    modint(ll a): x((a % MOD + MOD) % MOD) {}
    
    
 
    bool operator!() const{return !x;}
 
    bool operator<(const modint &a) const{
        modint res(*this);
        return res.x < a.x;
    }
    
    bool operator>(const modint &a) const{
        modint res(*this);
        return res.x > a.x;
    }
 
    modint &operator+=(const modint &a){
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator-=(const modint &a){
        if((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator*=(const modint &a){
        (x *= a.x) %= MOD;
        return *this;
    }
 
    modint &operator/=(const modint &a){
        *this *= a.inv();
        return *this;
    }
 
    modint &operator%=(const modint &a){
        x %= a.x;
        return *this;
    }
 
    modint operator-() const{ return modint(-x); }
 
    modint operator+(const modint &a) const{ return modint(*this) += a; }
    modint operator-(const modint &a) const{ return modint(*this) -= a; }
    modint operator*(const modint &a) const{ return modint(*this) *= a; }
    modint operator/(const modint &a) const{ return modint(*this) /= a; }
    modint operator%(const modint &a) const{ return modint(*this) %= a; }
    bool operator==(const modint &a) const{ return x == a.x; }
    bool operator!=(const modint &a) const{ return x != a.x; }
 
 
    modint pow(ll n) const{
        modint res(1), a(x);
        while(n > 0){
            if(n & 1) res *= a;
            a *= a;
            n /= 2;
        }
        return res;
    }
 
    modint inv() const{
        return this->pow(MOD-2);
    }
 
    friend ostream &operator<<(ostream &os, const modint &m){
        return os << m.x;
    }
 
    friend istream &operator>>(istream &is, modint &m){
        ll t;
        is >> t;
        m = modint<MOD>(t);
        return (is);
    }
    
    static ll get_mod(){ return MOD; }
};
using mint = modint<MOD>;


signed main(){
    ll n,m;
    cin >> n >> m;

    mint fact[m+1] = {};
    fact[0] = 1; fact[1] = 1;
    rep(i,2,m+1){
        fact[i] = fact[i-1]*i;
    }

    mint sum = 0;
    rep(k,1,n+1){
        mint tmp = fact[n]/fact[k]/fact[n-k]*fact[m-k]/fact[m-n];
        if(k % 2) sum += tmp;
        else sum -= tmp;
    }
    sum *= fact[m]/fact[m-n];
    mint ans = fact[m]/fact[m-n]*fact[m]/fact[m-n] - sum;
    cout << ans << endl;

    return 0;
}


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

const int maxn = 1e5+10;
char s[maxn];
int main()
{
    while(scanf("%s",s)!=EOF)
    {
        
        int len=strlen(s);
        int ans=len;
        for(int i=1;i<len;i++)
        {
            if(s[i]!=s[i-1])
            {
                ans=min(max(i,len-i),ans);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 384
a,b=map(int,input().split())
ans=0
if(b<10):
  ans=a*10+b
elif(b<100):
  ans=a*100+b
else:
  ans=a*1000+b
  
  
n=int(1+ans**0.5)
flag=0
for i in range(n):
  if(i**2==ans):
    flag=1
    break
    
if(flag==1):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

vector<int> da[31];
int main() {
	int id,sc,n,i,j;
	while (scanf("%d,%d",&id,&sc)) {
		if (id==0 && sc==0) break;
		da[sc].push_back(id);
	}
	while (cin >> id) {
		n=0;  
		for (i=30;i>=0;i--) {
			if (da[i].size()>0) {
				n++;
				for (j=0; j<da[i].size(); j++) if (da[i][j]==id) cout << n << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1264
#include <iostream>

using namespace std;

long n;
long march[5] = {0, 0, 0, 0, 0};

long solve(int i, int j){
  
  if (j == 0) 
    return 1;
  
  if (i == 5)
    return 0;
  
  return march[i] * solve(i+1, j-1) + solve(i+1, j);

}
  
int main() {
 
  cin >> n;
  
  for (int i = 0; i < n; i++) {
    char s[11];
    cin >> s;
    switch(s[0]) {
    case 'M':
      march[0]++;
      break;
    case 'A':
      march[1]++;
      break;
    case 'R':
      march[2]++;
      break;
    case 'C':
      march[3]++;
      break;
    case 'H':
      march[4]++;
      break;
    }   
  }

  //for (int i = 0; i < 5; i++)
  // cout << march[i] << endl;
  
  cout << solve(0,3) << endl;

  return 0;
}  


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 2019;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string s;
    cin >> s;
    ll n = s.size();
    vector<ll> ab(n + 1,0);
    ll tmp = 0;
    ll mod = 1;
    for (int i = 0; i < n; i++)
    {
       tmp += (ll(s[n - 1 - i] - '0') * mod);
       ab[i + 1] = tmp % MOD;
       mod *= 10;
       mod %= MOD;
    }
    ll ans = 0;
    vector<ll> c(2019,0);
    for(int i = 0; i < n + 1; i++){
        c[ab[i]]++;
    }
    for (int i = 0; i < 2019; i++)
    {
        ans += c[i] * (c[i] - 1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5204
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 3e3 + 5;
const ll LINF = 1e18 + 5;
int n, a[N];
ll dp[N][N];
ll solve(int x, int y)
{
	if(~dp[x][y]) return dp[x][y];
	ll &cur = dp[x][y];
	if(x==y) cur = a[x];
	else cur = max(-solve(x+1, y)+a[x], -solve(x, y-1)+a[y]);
	return cur;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n;
 	for(int i=1; i<=n; i++) cin >> a[i];
 	memset(dp, -1, sizeof(dp));
 	cout << solve(1, n);
	return 0;
}


Measured memory_bytes: 71040
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <list>
//#include <unordered_map>
//#include <unordered_set>
#include <ctime>

using namespace std;

typedef long long			LL;
typedef long double			LD;
typedef unsigned long long	ULL;
typedef unsigned int		UI;
typedef unsigned short		US;

//#define FILE
#define fr			first
#define sc			second
#define mp			make_pair
#define pb			push_back
#define all(x)		(x).begin(), (x).end()
#define sz(x)		LL((x).size())
#define F(i,a,b)	for (int i = a; i < b; i++)
#define R(i,a,b)	for (int i = a - 1; i >= b; i--)

const UI		N = 200005;
const LL		Mod = 1000000007;
const LL		INF = 1000000000;
const LL		INF64 = 1000000000000000000;
const LD		PI = acos(-1.0);
const LD		E = 2.7182818284590452353602874713527;
const UI		dir = 4;
const int		prime = 31;

LL gcd(LL a, LL b) { return a != 0 ? gcd(b%a, a) : b; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
LL length(LL n) { return n < 10 ? 1 : 1 + length(n / 10); }

LL A[N], B[N], C[N], NN, W[N];
int modl, modr;


void input()
{
	LL sum = 0;
	cin >> NN;
	F(i, 0, NN) {
		cin >> A[i];
		sum += A[i];
		C[i] = A[i];
	}

	F(i, 0, NN) {
		cin >> B[i];
		sum -= B[i];
		W[i] = B[i] - A[i];
	}
	if (sum < 0) {
		cout << "-1" << endl;
		exit(0);
	}
}


void solve()
{
	sort(W, W + NN);
	int l = 0, r = NN - 1;
	modl = -1;	modr = NN;
	while (W[r] > 0) {
		if (W[l] + W[r] < 0) {
			W[l] += W[r];
			modr = r;
			modl = l;
			r--;
		}
		else {
			W[r] += W[l];
			modr = r;
			modl = l;
			if (W[r] == 0)
				r--;
			l++;
		}
	}
	cout << NN - max(0, modr - modl - 1) << endl;
}	

int main()
{

#ifdef FILE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int testcases = 1;
	// cin >> testcases;
	while (testcases--) {
		input();
		//clock_t start = clock();
		solve();
		//printf("---------------------\n%.5f seconds\n---------------------\n", (clock() - start + 0.) / CLOCKS_PER_SEC);
	}

	return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using ll=long long;

const ll INF = pow(10,18)+1;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}
template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}
 
int main(){
    string b;
    cin >> b;
    string ans = "";
    for(int i = 0; i < b.length(); ++i){
        if(b[i]=='A') ans += "T";
        if(b[i]=='T') ans += "A";
        if(b[i]=='C') ans += "G";
        if(b[i]=='G') ans += "C";
    }
    cout << ans << endl;
    return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int a, b;
    cin >> a >> b;
    cout << (a >= 13 ? b : (a <= 5 ? 0 : b / 2)) << endl;

    return 0;
}

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

vector<int> G[100+1];
vector<int> d(100+1,-1);
vector<int> f(100+1,-1);
int timer= 1;

void dfs(int x){

    if(d[x]!=-1)
        return;
    d[x] = timer;
    timer++;
    for (int i = 0; i < G[x].size(); ++i) {
        dfs(G[x][i]);
    }
    f[x] = timer;
    timer++;
}

int main(void) {

    int n; cin>>n;
    for (int i = 1; i <= n; ++i) {
        int u,k; cin>>u>>k;
        for (int j = 1; j <= k; ++j) {
            int v; cin>>v;
            G[u].push_back(v);
        }
    }

    for (int i = 1; i <= n; ++i) {
        dfs(i);
    }

    for (int i = 1; i <= n; ++i) {
        cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

const ll max_n=100005;
vi fac(max_n),finv(max_n),inv(max_n);
// テーブルを作る前処理 O(max_n)
void init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  REP(i,2,max_n){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
// 二項係数計算 O(1)
ll COM(int n,int k){
  if(n<k) return 0;
  if(n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
void solve(){
  init();
  int n,k;
  cin>>n>>k;
  vi a(n);
  rep(i,n) cin>>a[i];
  sort(all(a));
  ll big=0,small=0;
  rep(i,n-k+1) small=(small+a[i]*COM(n-i-1,k-1))%mod;
  REP(i,k-1,n) big=(big+a[i]*COM(i,k-1))%mod;
  out((mod+big-small)%mod);
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n, d;
	while(cin >> n >> d) {

		int fib[1005];
		memset(fib, 0, sizeof(fib));

		fib[0] = 2;
		fib[1] = 3;

		rep(i,n) {
			fib[i+2] = fib[i+1] + fib[i];
			fib[i+2] %= 1001;
		}

		sort(fib, fib+n);
		
		int ans = 1;
		rep(i,n-1) {
			if(fib[i+1] - fib[i] >= d) {
				ans++;
			}
		}

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

Measured memory_bytes: 1180
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    result = 0
    rate = 380000.0
    for _ in range(N):
        x, u = input().split()
        if u == 'BTC':
            result += float(x) * rate
        elif u == 'JPY':
            result += float(x)
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
long solve(long a, long b, long h){
	return (a+b)*h/2;
}
void main(){
	int a = inelm();
	int b = inelm();
	int h = inelm();
	solve(a, b, h).writeln();
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


Measured memory_bytes: 2688
(function(stdin) {
  function search(array) {
    return allCards.filter(function(card) {
      return array.indexOf(card) === -1;
    });
  }
  var inputs = stdin.toString().trim().split('\n');
  var line = [].concat(inputs);
  var allCards = ['S', 'H', 'C', 'D'].map(function(v) {
    var newArray = [];
    for (var i = 0; i < 13; i++) {
      newArray.push([v, i + 1].join(' '));
    }
    return newArray;
  }).reduce(function(a, b) {
    return a.concat(b);
  });
  if (inputs[0] < 52) {
    console.log(search(line).join('\n'));
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 15472
#set
n = gets.chomp.to_i
answer = 'No'

#main
(1 .. 9).each do |i|
  (1 .. 9).each do |j|
    if i * j == n then
      answer = 'Yes'
      print ("#{answer}\n")
      exit
    end
  end
end

print ("#{answer}\n")

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef pair<lli, pii> ppi;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
    }
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
lli solve(){
    lli n;
    cin>>n;
    vll A(n);
    loop(i, 0, n)
        cin>>A[i];
    lli ans = 1e9;
    loop(i, 1, 101){
        lli temp = 0;
        loop(j, 0, n)
            temp += (A[j] - i) * (A[j]-i);
        ans = min(ans, temp);
    }
    cout<<ans<<"\n";
    return 0;
 }
int main(){
    fastio;
    lli t;
    // cin>>t;
    t = 1;
    while(t>0){
        t--;
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;
int main() {
	int A , B, C,five,seven;
	cin >> A >> B >> C;
	if (A == 5)five++;
	if (B == 5)five++;
	if (C == 5)five++;
	if (A == 7)seven++;
	if (B == 7)seven++;
	if (C == 7)seven++;
	if (five == 2 && seven == 1)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

#define int long long

int x, y;
int a, b, c;
int p[200000], q[200000], r[200000];
int z[400000];
int num;
int ans;

signed main(){
	cin >> x >> y >> a >> b >> c;
	for(int i = 0; i < a; i++)cin >> p[i];
	sort(p, p + a);
	reverse(p, p + a);
	for(int i = 0; i < x; i++){
		z[num] = p[i];
		num++;
	}
	for(int i = 0; i < b; i++)cin >> q[i];
	sort(q, q + b);
	reverse(q, q + b);
	for(int i = 0; i < y; i++){
		z[num] = q[i];
		num++;
	}
	for(int i = 0; i < c; i++){
		cin >> r[i];
		z[num] = r[i];
		num++;
	}
	sort(z, z + (x + y + c));
	reverse(z, z + (x + y + c));
	for(int i = 0; i < x + y; i++)ans += z[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7168
use std::io;

fn main() {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    let n = n.trim().parse::<u32>().unwrap();
    let mut ans = 0_u64;
    for i in 1..=n {
        if i % 3 != 0 && i % 5 != 0 {ans += i as u64};
    }
    print!("{}",ans);
}

Measured memory_bytes: 2120
#include<iostream>
using namespace std;
int main(){
    int i,m,N,K,p[1000],tmp,sum=0;
    cin >> N >> K;
    for(i=0;i<N;++i){
        cin >> p[i];
    }
    for(i=0;i<N;++i){
        for(m=0;m<N;++m){
            if(p[m]>=p[i]){
                tmp=p[m];
                p[m]=p[i];
                p[i]=tmp;
            }
        }
    }
    for(i=0;i<K;++i){
        sum+=p[i];
    }
    cout << sum << endl;

    

    

}

Measured memory_bytes: 3500
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 120

int main(){
  long long i=0,ans;
  string s;
  cin>>s;
  long long k;
  cin>>k;
  long long count=0;
  while(true){
    if(s[i]-'0'==1){
      count++;
      if(count==k){
        ans=1;
        break;
      }
    }else {
      ans=s[i]-'0';
      break;
    }
    i++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256