akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    int T = 0, H = 0;
    for (int i = 0; i < N; i++) {
        string A, B;
        cin >> A >> B;
        if (A > B) T += 3;
        else if (A < B) H += 3;
        else {
            T++;
            H++;
        }
    }
    cout << T << " " << H << endl;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;

const int N = 1e6 + 5;
const int inf = 1e18;
const int mod = 1e9 + 7;

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
	
	int a, b, x;
	cin >> a >> b >> x;
	int ans = b/x - max(0LL,a-1)/x;
	ans += a == 0;
	cout << ans;
}



Measured memory_bytes: 256
a, b, c, x, y = gets.chomp.split.map(&:to_i)
m = [x, y].min
res = []
res << a * x + b * y
res << 2 * c * m + a * (x - m) + b * (y - m)
res << 2 * c * [x, y].max
puts res.min

Measured memory_bytes: 3836
N = int(input())
D = list(map(int, input().split()))
ans = 0
if not D[0] == 0 or not D.count(0) == 1:
    print(0)
else:
    co = [0] * (max(D)+1)
    for i in D:
        co[i] += 1
    ans = 1
    for i in range(2, max(D)+1):
        ans = ans * (co[i-1]**co[i]) % 998244353
    print(ans)

Measured memory_bytes: 14396
NM = list(map(int, input().split()))

K1 = list(map(int, input().split()))
del K1[0]
hat = set(K1)

for i in range(NM[0]-1):
    tmp = list(map(int, input().split()))
    del tmp[0]
    hat = hat & set(tmp)

print(len(hat))

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin >> s;

	stack<char> cubes;
	int removed = 0;
	for (int i = 0; i < (int) s.size(); ++i) {
		if (cubes.empty()) {
			cubes.push(s[i]);
		} else {
			if (cubes.top() != s[i]) {
				cubes.pop();
				removed += 2;
			} else {
				cubes.push(s[i]);
			}
		}
	}

	cout << removed << "\n";

	return 0;

}

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

int main(){
  int N;
  cin >> N;
  N %= 10;
  if(N == 3) cout << "bon";
  else if(N == 0 || N == 1 || N == 6 || N == 8) cout << "pon";
  else cout << "hon";
  return 0;
}

Measured memory_bytes: 3636
/* 
chirag11032000
Chirag Thakur
*/

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

using namespace std;
using namespace __gnu_pbds;

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

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

void testCase();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	testCase();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void testCase() {
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	vector < ll > a(x), b(y), c(z);
	for (auto &el: a) {
		cin >> el;
	}
	for (auto &el: b) {
		cin >> el;
	}
	for (auto &el: c) {
		cin >> el;
	}
	sort(rall(a));
	sort(rall(b));
	sort(rall(c));
	set < pair < int, pii > > st = {{0, {0, 0}}};
	cout << a[0] + b[0] + c[0] << "\n";
	while (st.size() != k) {
		pair < int, pii > p;
		ll mx = 0;
		for (auto &el: st) {
			if (!st.count({el.first + 1, el.second}) && el.first + 1 < x) {
				ll nxt = a[el.first + 1] + b[el.second.first] + c[el.second.second];
				if (nxt > mx) {
					mx = nxt;
					p = el;
					++p.first;
				}
			}
			if (!st.count({el.first, {el.second.first + 1, el.second.second}}) && el.second.first + 1 < y) {
				ll nxt = a[el.first] + b[el.second.first + 1] + c[el.second.second];
				if (nxt > mx) {
					mx = nxt;
					p = el;
					++p.second.first;
				}
			}
			if (!st.count({el.first, {el.second.first, el.second.second + 1}}) && el.second.second + 1 < z) {
				ll nxt = a[el.first] + b[el.second.first] + c[el.second.second + 1];
				if (nxt > mx) {
					mx = nxt;
					p = el;
					++p.second.second;
				}
			}
		}
		st.insert(p);
		cout << mx << "\n";
	}
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int maxn = 3010;
const int mo = 1000000007;
using namespace std;
int a[maxn], b[maxn], f[maxn][maxn], n, m; char s[maxn];
void solve1(int l, int r) {
	int tot = 0;
	rep(i, l, r) tot += a[i];
	rep(i, l, l + tot - 1) a[i] = 1;
	rep(i, l + tot, r) a[i] = 0;
}
void solve2(int l, int r) {
	int tot = 0;
	rep(i, l, r) tot += 1 - b[i];
	rep(i, l, l + tot - 1) b[i] = 0;
	rep(i, l + tot, r) b[i] = 1;
}
int main() {
	scanf("%d%d", &n, &m);
	scanf("%s", s + 1);
	rep(i, 1, n) a[i] = b[i] = (s[i] == '1');
	rep(i, 1, n) b[i] = a[i]; int x, y;
	rep(i, 1, m) scanf("%d%d", &x, &y), solve1(x, y), solve2(x, y);
	rep(i, 2, n) a[i] += a[i - 1], b[i] += b[i - 1];
	f[0][0] = 1;
	rep(i, 1, n) rep(j, b[i], a[i]) f[i][j] = (f[i - 1][j] + f[i - 1][j - 1]) % mo;
	printf("%d\n", f[n][a[n]]);
	return 0;
}

Measured memory_bytes: 12544
// #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const int INF = 1e9;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
   ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
   ostr << "}";
   return ostr;}

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

int make_div(int n){
  int div[n + 100];
  REP(i, n+100){div[i] = 0;}
  int val = int(sqrt(n)) + 1;
  FOR(i, 1, val){
    if (n % i == 0){div[i] = 1;
    if (i != int(n/i)){div[i] = 2;}}
  }

  int ans = 0;
  REP(i, n){ans+=div[i];}
  return ans;
}

int main(void){
 ios::sync_with_stdio(false);

 int x;
 cin >> x;

 int num = 10;
 while (num != 2){
   num = make_div(x);
   int ans = x;
   x++;
   }


   cout << x-1 << endl;


 return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    int N;
    cin >> N;

    double a;
    double tmp = 0;
    REP(i, N) {
        cin >> a;
        tmp += 1.0 / a;
    }
    //cout << (1.0 / tmp) << endl;
    printf("%.5f\n", (1.0 / tmp));

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;


int gcd(int x, int y) {
  if (x % y == 0) return y;
  else return gcd(y, x % y);
}

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

  x = a > b ? a : b;
  y = a > b ? b : a;
  cout << gcd(x, y) << endl;
}



Measured memory_bytes: 3100
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

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

ll llmax(ll a, ll b){
  return a > b ? a : b;
}

ll llmin(ll a, ll b){
  return a < b ? a : b;
}

int main(){
  ll N, K;
  cin >> N >> K;

  double p[K];
  rrep(i, K){
    if(i >= (K+1) / 2) p[i] = 1.0 / 2;
    else p[i] = p[i*2] / 2;
  }
  double ans = 0;
  repi(i, 1, llmin(N+1, K)) ans += p[i];
  ans += llmax(0, N-K+1);
  ans /= N;
  printf("%1.10lf\n", ans);
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<deque>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

ll n;
vector<ll> v(100010);

int f(ll a)
{
	REP(i,n)
	{
		a -= a%v[i];
		if(a==0)return -1;
	}
	if(a==2)return 1;
	else return -2;
}

int main()
{
	cin >> n;
	REP(i,n)cin >> v[i];
	
	if(v[n-1] != 2)
	{
		cout << -1 << endl;
		return 0;
	}
	
	bool flag = false;
	ll l,r,num;
	ll lb = 2,ub = 1000000000000000000;
	
	while(ub-lb>1)
	{
		ll mid = (lb+ub)/2;
		ll tmp = f(mid);
		if(tmp==-1)
		{
			lb = mid;
		}
		else if(tmp==-2)
		{
			ub = mid;
		}
		else
		{
			flag = true;
			num = mid;
			break;
		}
	//	cout << lb << ' ' << ub << endl;
	}
	
	if(!flag)
	{
		cout << -1 << endl;
		return 0;
	}
	
	lb = num;ub = 1000000000000000000;
	
	while(ub-lb>1)
	{
		ll mid = (lb+ub)/2;
		if(f(mid)==1)
		{
			lb = mid;
		}
		else
		{
			ub = mid;
		}
	}
	
	r = lb;
	
	lb = 0;ub = num;
	
	while(ub-lb>1)
	{
		ll mid = (lb+ub)/2;
		if(f(mid)==1)
		{
			ub = mid;
		}
		else
		{
			lb = mid;
		}
	}
	
	l = ub;
	
	cout << l << ' ' << r << endl;
	
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        if (N == 0) {
            System.out.println(1);
        } else if (N == 1) {
            System.out.println(0);
        }

    }
}

Measured memory_bytes: 35672
#include <stdio.h>

int main()
{
    int H, W;
    int i, j, k;

    while (1)
    {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0)
            break;

        for (i = 0; i < H; i++)
        {
            for (j = 0; j < W; j++)
                printf("#");
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
using namespace std;
int main(){
    int N,K; cin >> N >> K;
    vector<int> H(N);
    for (int i=0;i<N;i++) cin >> H[i];
    sort(H.begin(),H.end());
    int res = 1e9;
    for (int i=0;i<=N-K;i++){
        res = min((H[i+K-1])-H[i],res);
    }
    cout << res << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e9+7;
const ll N = 100002;
ll n,ans=INF;
string s;
ll alf[26];

int main(){
	cin>>s;
	FOR(i,0,26)alf[i]=0;
	FOR(i,0,s.size()){
		alf[s[i]-'a']++;
	}
	ll w=0;
	FOR(i,0,26){
		if(alf[i]>0)w++;
	}
	if(w==1){
		cout<<0<<endl;
		return 0;
	}
	ll answ;
	FOR(i,0,26){
		char p='a'+i;
		if(alf[i]==0)continue;
		string sc=s;
		ll ans1=0;
		while(1){
			ans1++;
			string a;
			bool ok=true;
			FOR(i,0,sc.size()-1){
				if(sc[i]==p||sc[i+1]==p){
					a+=p;
				}else{
					a+=p+1;
					ok=false;
				}
			}
			if(ok){
				ans=min(ans,ans1);
				break;
			}else{
				sc=a;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn solve(a: String, b: String) {
    let av: Vec<char> = a.chars().collect();
    let bv: Vec<char> = b.chars().collect();
    let len = av.len();
    let mut cnt: usize = 0;
    for i in 0..len {
        if av[i] > bv[i] {
            println!("GREATER");
            break;
        } else if bv[i] > av[i] {
            println!("LESS");
            break;
        }
        cnt += 1;
    }
    if cnt == len {
        println!("EQUAL");
    }
}

fn main() {
    let a: String = read();
    let b: String = read();

    if a.len() > b.len() {
        println!("GREATER");
    } else if b.len() > a.len() {
        println!("LESS");
    } else {
        solve(a, b);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

ll y[10000005];

int main() {
    int N, M, K; cin >> N >> M >> K;
    for(int m = 0; m <= N; m++){
        for(int n = 0; n <= M; n++){
            if(n * (N-m) + m * (M-n) == K){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007LL

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

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

	ll n, k;cin >> n >> k;
	vector<ll> v(n);REP(i, n)cin >> v[i];

	ll l = 0;
	ll r = LLINF;
	while(r - l > 1){
		ll mid = (l + r) / 2;
		ll cou = 0;
		REP(i, n){
			//cout << v[i] << " " << (v[i] - 1) / mid << endl;
			cou += (v[i] - 1) / mid;
		}
		//cout << l << " " << r << " " << mid << " " << cou << endl;
		if(cou <= k)r = mid;
		else l = mid;
	}

	cout << r << endl;

	return 0;
}


Measured memory_bytes: 4692
n = gets.to_i
a = gets.split.map(&:to_i)
b = Hash.new(0)
n.times do |i|
    b[a[i]] += 1
end
c = b.keys.sort
ans = false
if c.size == 3 && c[0] == (c[1]^c[2])
    if b[c[0]] == b[c[1]] && b[c[1]] == b[c[2]]
        ans = true
    end
end
if c.size == 2
    if c[0] == 0 && b[0]*2 == b[c[1]]
        ans = true
    end
end
if c.size == 1 && c[0] == 0
    ans = true
end
puts (ans ? "Yes" : "No")

Measured memory_bytes: 13824
k=int(input())

if k<=9:
    print(k)
    exit(0)

ans=[1,2,3,4,5,6,7,8,9]

i=0
while len(ans)<k:
    v=str(ans[i])
    n=len(v)
    #最後の桁
    v_last=int(v[-1])

    if v_last==0:
        ans.append(int(v+'0'))
        ans.append(int(v+'1'))
    elif v_last==9:
        ans.append(int(v+'8'))
        ans.append(int(v+'9'))
    else:
        ans.append(int(v+str(v_last-1)))
        ans.append(int(v+str(v_last)))
        ans.append(int(v+str(v_last+1)))
    i+=1

print(ans[k-1])







Measured memory_bytes: 12720
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
 
    int n,k,q;
    cin>>n>>k>>q;

    vector<int> out(n+1,0);


    for(int i=0;i<q;i++){
        int a;
        cin>>a;
        out.at(a)++;
    }
 
    for(int i=1;i<=n;i++){
        if(k-q+out.at(i)>0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }

    
    return 0;
}  

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
typedef unsigned long long ULL;
const int MOD=1e9+7;
ULL pw(ULL a, ULL n){ ULL b=1; while(n){ if(n&1){ b=(b*a)%MOD; } a=(a*a)%MOD; n>>=1; } return b; }

int main(){
int N; cin >> N; ULL ans=0, S=0, T=0, A[N]; 
REP(i, N){ cin >> A[i]; S=(S+A[i])%MOD; T=(T+(A[i]*A[i])%MOD)%MOD; }
ans=((S*S)%MOD+(MOD-T))%MOD; ans=(ans*pw(2, MOD-2))%MOD;
cout << ans << "\n";
}

Measured memory_bytes: 5164
#include <bits//stdc++.h>
 
using namespace std;
 
void fastIO(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
 
 
int main(){
 
int x,y;
 
cin>>x>>y;
int a[y];
long long ans1=0;
long long ans2=0;
long long mini=x;
long long ans3=0;
 
for(int i=0;i<y;i++)
 
 
cin>>a[i];

sort(a,a+y);


 for(int i=1;i<y;i++)
{ans1=x-(a[i]-a[i-1]);
if(mini>ans1)
mini=ans1;

}
ans1=x-(x-a[y-1]+a[0]);
if(mini>ans1)
mini=ans1;
cout<<mini;
return 0;
}
 
 


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

int dp[200010];
bool can[200010];
int nxtid[200010];
char nxtc[200010];

vector<int> idx[26];

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

	string A;
	cin >> A;
	int N = A.size();
	for(int i = 0; i < N; i++) {
		idx[A[i] - 'a'].push_back(i + 1);
	}
	for(int i = 0; i < 26; i++) {
		idx[i].push_back(N + 1);
	}

	const int INF = 1 << 28;
	fill((int*)begin(dp), (int*)end(dp), INF);
	dp[0] = 0;
	for(int i = 0; i < N + 1; i++) {
		if(dp[i] == INF) continue;
		for(int j = 0; j < 26; j++) {
			int nxt = *lower_bound(idx[j].begin(), idx[j].end(), i + 1);
			if(dp[nxt] > dp[i] + 1) {
				dp[nxt] = dp[i] + 1;
			}
		}
	}

	can[N + 1] = true;
	for(int i = N - 1; i >= 0; i--) {
		if(dp[i] == INF) continue;
		for(int j = 0; j < 26; j++) {
			int nxt = *lower_bound(idx[j].begin(), idx[j].end(), i + 1);
			if(can[nxt] && dp[i] + 1 == dp[nxt]) {
				can[i] = true;
				nxtc[i] = 'a' + j;
				nxtid[i] = nxt;
				break;
			}
		}
	}

	string ans;
	for(int i = 0; i < N + 1;) {
		ans += nxtc[i];
		i = nxtid[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 3348
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N;
  while(cin>>N && N){
    vector<int> l(N);
    REP(i, N) cin>>l[i];
    int M = 256;
    int as, aa, ac;
    double ent = 1e32;
    REP(S, 16)REP(A, 16)REP(C, 16){
      vector<int> R(N + 1);
      R[0] = S;
      REP(i, N){
        R[i + 1] = (A * R[i] + C);
        while(R[i + 1] >= M) R[i + 1] -= M;
      }
      REP(i, N){
        R[i + 1] += l[i];
        while(R[i + 1] >= M) R[i + 1] -= M;
      }
      double cnt[256] = {};
      REP(i, N) cnt[R[i + 1]] += 1.0;
      double e = 0;
      REP(i, 256)if(cnt[i] != 0){
        double c = cnt[i];
        e += -c/N * log(c/N);
        if(!(e + EPS < ent)) goto END;
      }
      ent = e;
      as = S, aa = A, ac = C;
END:;
    }
    printf("%d %d %d\n", as, aa, ac);
  }
  return 0;
}

Measured memory_bytes: 1216
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

N,M = map(int,readline().split())
AB = []
C = []
for _ in range(M):
    AB.append(tuple(int(x) for x in readline().split()))
    C.append(sum(1<<(int(x)-1) for  x in readline().split()))

A,B = np.array(AB,np.int64).T
C = np.array(C,np.int64)

INF = 10**18
dp = np.full(1<<N,INF,np.int64)
dp[0] = 0

for n in range(1<<N):
    target = n|C
    value = A
    I = np.lexsort((value,target))
    target = target[I]
    value = value[I]
    is_first_elem = np.ones(M,np.bool)
    is_first_elem[1:] = ~(target[:-1] == target[1:])
    target = target[is_first_elem]
    value = value[is_first_elem]
    dp[target] = np.minimum(dp[target],dp[n]+value)

answer = dp[-1]
if answer == INF:
    answer = -1
print(answer)

Measured memory_bytes: 12512
# coding: utf-8
N = int(input())

list = input().split(" ")

num_list = []

for element in list:
    num_list.append(int(element))

min = 1000000001
max = 0

for num in num_list:
    if num >= max:
        max = num
    if num <= min:
        min = num

print(max - min)


Measured memory_bytes: 2940
<?php
list($a, $b, $c) = ints();
if (isExistOdd()) exit('0');
if ($a === $b && $b === $c) exit('-1');
$cnt = 0;
while (!isExistOdd()) {
    ++$cnt;
    list($a, $b, $c) = [$b / 2 + $c / 2, $a / 2 + $c / 2, $a / 2 + $b / 2];
}
echo $cnt;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
function isExistOdd()
{
    global $a, $b, $c;
    return $a % 2 || $b % 2 || $c % 2;
}


Measured memory_bytes: 16080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.size();
	rep(i,n){
		cout<<"x";
	}
	cout<<endl;
}

Measured memory_bytes: 256
p['   '];t['   '];n,x,k,j;main(i){for(;i++<1e6;)for(x=i;x<1e6;p[x+=i]=1);for(;*t=scanf("%d%d",&n,&x),n;memset(t,!printf(x<2?"NA\n":"%d\n",x),4e6)){for(;n--;)for(i=-scanf("%d",&k);++i<x;)t[i+k]|=t[i];for(;p[x]|!t[x];x--);}}

Measured memory_bytes: 15000
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
const int N = 2e5 + 4;
int n , D ,  A;

int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   cin >> n >> D >> A;
   map<int , int> mp;
   for(int i = 0 ; i < n ; ++i) {
      int x , h;
      cin >> x >> h;
      mp[x] = (h + A - 1) / A;
   }
   ll cur = 0 , ans = 0;
   int i = 0;
   vector<pair<int , ll>> rem;
   for(auto e : mp){
      while (i < (int)rem.size() && rem[i].first < e.first){
         cur -= rem[i].second;
         ++i;
      }
      ll add = max(0ll , e.second - cur);
      ans += add;
      cur += add;
      if(add){
         rem.push_back({e.first + 2 * D , add});
      }
   }

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

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

const long long INF = 1LL << 60;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> h(110000);
    for(int i = 0; i < N; i++){
        cin >> h.at(i);
    }
    long long dp[110000];
    for(int i = 0; i < 110000; i++){
        dp[i] = INF;
    }
    
    dp[0] = 0;

    for(int i = 0; i < N; i++){
        for(int j = 1; j <= K; j++){
            if(dp[i + j] > dp[i] +abs(h.at(i) - h.at(i + j))) dp[i + j] = dp[i] + abs(h.at(i) - h.at(i + j));
        }
    }

    cout << dp[N - 1] << endl;

}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
const lol mod=998244353;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[1000];
    int n;
    bool an=true;
    cin >>n;
    for(int i=0;i<n;i++){
      cin >>a[i];
      if(a[i]%2==0){
	if(a[i]%3!=0&&a[i]%5!=0) an=false;
      }
    }
    if(an) cout <<"APPROVED\n";
    else cout <<"DENIED\n";
    return (0);
}


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

int main(){
	int n,m,x,y ;
	cin >> n >> m >> x >> y ;
	int mxa = -10000 ;
	int mnb = 10000 ;
	for(int i=0;i<n;i++){
		int sub ; cin >> sub ;
		if(sub>mxa) mxa = sub ;
	}
	for(int i=0;i<m;i++){
		int sub ; cin >> sub ;
		if(sub<mnb) mnb = sub ;
	}
	if(mxa<mnb&&mnb>x&&mxa<y) cout << "No War" << endl ;
	else cout << "War" << endl ;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

const double INF = 1e20;

int K, cnt = 1;
long long N = 1, pow[20];

void init()
{
	pow[0] = 1;
	for (int i = 1; i < 20; i++)
		pow[i] = pow[i - 1] * 10;	
}

double sum(long long v)
{
	int ret = 0;
	while (v)
		ret += v % 10, v /= 10;	
	return ret;
}

long long f(long long n)
{
	double mn = INF;
	long long x = n, y = n, ret = n;
	int p = 0;
	while (x >= 10)
	{
		int z = x % 10;
		while (z < 9)
			z++, y += pow[p];
		double now = y / sum(y);
		if (now < mn)
			mn = now, ret = y;
		x /= 10, p++;
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> K;
	init();
	while (cnt <= K)
	{
		cout << N << endl;
		N = f(N + 1);
		cnt++;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)



int main() {
	ll N, M;
	cin >> N >> M;
	vector<ll> X(M);
	REP(i, M) cin >> X[i];
	sort(X.begin(), X.end());

	vector<ll> dist(M - 1);
	REP(i, M - 1) dist[i] = X[i + 1] - X[i];
	sort(dist.begin(), dist.end());

	ll ans = 0;
	REP(i, M - N) ans += dist[i];
	cout << ans << endl;


}

Measured memory_bytes: 1920
N = int(input())
As = list(map(int, input().split()))
def calcgcd(a, b):
  if a > b:
    a, b = b, a
  while a > 0:
    a, b = b%a, a
  return b
r = 0
for A in As:
  r = calcgcd(r, A)
print(r)


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

signed main() {
  string s;
  int N,A,B,C,D;
  cin>>N>>A>>B>>C>>D>>s;
  A--; B--; C--; D--;

  bool ans = true;
  for (int i=B+1; i<=D-2; i++) {
    if (s[i]=='#' && s[i+1]=='#')
      ans = false;
  }

  for (int i=A+1; i<=C-2; i++) {
    if (s[i]=='#' && s[i+1]=='#')
      ans = false;
  }

  if (D<C) {
    bool canOverlap = false;
    // have to overlap funuke
    for (int i=B; i<=D; i++) {
      if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.' ) {
        canOverlap = true;
      }
    }
    if (!canOverlap)
      ans = false;
  }
  cout<<(ans? "Yes": "No")<<endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

class Main {
    public static Boolean PrimeCheck(int x){
	for(int i=2; i<=Math.sqrt(x);i++){
	    if(x%i==0){
		return false;
	    }
	}
	return true;
    }
     public static void main(String[] args) {
	 Scanner sc = new Scanner(System.in);
	 int n = sc.nextInt();
	 int min = sc.nextInt();
	 int profit = Integer.MIN_VALUE;
	 
	 for(int i=1;i<n;i++){
	     int x = sc.nextInt();
	     if(profit<x-min){
		 profit = x - min;
	     }
	     if(min>x){
		 min = x;
	     }
	 }
	 System.out.println(profit);
     }
    
}


Measured memory_bytes: 100240
import numpy as np

a,b,x = list(map(int,input().split()))


l = x/(a*a)

if l<=b/2.0:
    ans = np.rad2deg(np.arctan(b**2.0/(2.0*a*l)))
else:
    ans = np.rad2deg(np.arctan(2.0*(b-l)/a))

print(ans)

Measured memory_bytes: 12452
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif


bool solve()
{
    int a, b, c;
    cin >> a >> b >> c;

    cout <<  std::min(a + b, std::min(a + c, b + c)) << endl;
    
    return false;
}

int main()
{
    solve();

    return 0;
}

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

using namespace std;

bool ask(long long n) {
  printf("? %lld\n", n);
  fflush(stdout);
  char s[10];
  scanf("%s", s);
  return s[0] == 'Y';
}

void answer(long long n) {
  printf("! %lld\n", n);
  fflush(stdout);
}

int main() {
  long long n = (long long)(1e9);
  int k = 9;
  if (ask(n)) {
    n /= 5;
    while (k > 0 && ask(n)) n /= 10, k--;
    if (k == 0)
      answer(1);
    else
      answer(n * 5);
  }
  else {
    n/= 10, k--;
    while (k > 0 && !ask(n)) n /= 10, k--;
    long long ans = 0;
    for (int i = 0; i <= k; i++) {
      int l = 0, r = 9;
      while (l < r) {
        int mid = (l + r + 1) / 2;
        if (ask((ans + n * mid) * 10))
          r = mid-1;
        else
          l = mid;
      }
      ans += l * n;
      n /= 10;
    }
    answer(ans+1);
  }
  return 0;
}

Measured memory_bytes: 596
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		int a = sc.nextInt() * 100;
		int b = sc.nextInt() * 100;
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int f = sc.nextInt();

		int[] dp = new int[f + 1];

		Arrays.fill(dp, -1);
		dp[0] = 0;
		int max_w = Math.min(a, b);
		int max_s = 0;

		for (int i = 0; i < f + 1; i++) {

			if (i >= a) {
				if (dp[i - a] != -1)
					dp[i] = Math.max(dp[i], dp[i - a]);
			}

			if (i >= b) {
				if (dp[i - b] != -1)
					dp[i] = Math.max(dp[i], dp[i - b]);

			}
			if (i >= c) {
				if (dp[i - c] != -1)
					if ((dp[i - c] + c) * 100 <= e * (i-dp[i-c]-c)) {
						dp[i] = Math.max(dp[i], dp[i - c] + c);
					}
			}
			if (i >= d) {
				if (dp[i - d] != -1)
					if ((dp[i - d] + d) * 100 <= e * (i-dp[i-d]-d)) {
						dp[i] = Math.max(dp[i], dp[i - d] + d);
					}
			}

			if (dp[i] != -1 && dp[i] * max_w >= i * max_s) {
				max_w = i;
				max_s = dp[i];
			}
		}
		System.out.println(max_w + " " + max_s);

	}
}


Measured memory_bytes: 23892
let parent i = int_of_float (floor (float_of_int i) /. 2.)

let left i = 2*i

let right i = 2*i + 1

let build_max_heap t h =
  let rec max_heapify i =
    let l = left i in
    let r = right i in
    let m = if l <= h && t.(l) > t.(i) then l else i in
    let m = if r <= h && t.(r) > t.(m) then r else m in
    if m <> i then begin
      let tmp = t.(i) in t.(i) <- t.(m); t.(m) <- tmp;
      max_heapify m
    end
  and doit i =
    if i > 0 then (max_heapify i; doit (i - 1))
  in
  doit (int_of_float (float_of_int h /. 2.))

let () =
  let h = read_int () in
  let t = Array.make (h + 1) 0 in
  let rec read i =
    if i <= h then (t.(i) <- Scanf.scanf "%d " (fun i -> i); read (i + 1))
  in
  read 1;
  build_max_heap t h;
  let rec doit i =
    if i <= h then (Printf.printf " %d" t.(i); doit (i + 1))
  in
  doit 1;
  print_newline ()

Measured memory_bytes: 8412
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;


ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


ll Afact[1000100];
ll Bfact[1000100];
ll var[1000100];
ll A,B;

void fact(ll a, ll fact[]){
  ll i=2;
  ll original = a;
  fact[1]=1;
  rep(i, 1000000-1){
    int ii = i+2;
    while(a%ii==0){
      fact[ii] +=1;
      a = a/ii;
    }
  }
  if(a>1){
    fact[0]=a;
  }
  // bool isprime=true;
  // while(a>1 && i*i <= original){
  //   if(a%i==0){
  //     fact[i]+=1;
  //     a=a/i;
  //     isprime=false;
  //   }else{
  //     i=i+1;
  //   }
  // }
  // if(a%i==0){
  //   fact[i]+=1;
  // }
  // if(a>1){
  //   fact[0]=a;
  // }
  
  return;
}

int main(){
  cin >> A >>B;
  fact(A, Afact);
  fact(B, Bfact);
  ll count = 0;
  rep(i, 1000001){
    //if(i<10)cout << Afact[i] << " " << Bfact[i] << endl;
    if(i==0){
      if(Afact[i]==Bfact[i] && Afact[i]>0){
        count += 1;
        //break;
      }
    }else{
      var[i]=min(Afact[i], Bfact[i]);
      if(var[i]>0){count++;}
    }
  }
  cout << count;
  return 0;
}


Measured memory_bytes: 14592
import fractions
a,b,c,d=map(int,input().split())

#b以下の自然数で、cでもdでも割り切れないものの個数から
#a-1以下の自然数で、cでもdでも割り切れないものの個数を引けばOK

#cとdの最小公倍数を求める
def lcm(x,y):
    return (x*y)//fractions.gcd(x,y)

#b以下の自然数で、cでもdでも割り切れないものの個数を求める
b_ika=b-(b//c+b//d-b//lcm(c,d))
a_mimann=a-1-((a-1)//c+(a-1)//d-(a-1)//lcm(c,d))

ans=b_ika-a_mimann

print(ans)

Measured memory_bytes: 5048
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long LL;

const int N = 100010;

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

int main() {
    scanf("%d", &n);
    LL sum = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &a[i]);
        sum += a[i];
    }
    if (sum % (LL(n + 1) * n / 2)) {
        puts("NO");
        return 0;
    }
    LL k = sum / (LL(n + 1) * n / 2);
    for (int i = 1; i < n; ++i)
        b[i] = a[i + 1] - a[i];
    b[n] = a[1] - a[n];
    for (int i = 1; i <= n; ++i) {
        b[i] -= k;
        if (b[i] > 0 || b[i] % n) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}

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

using namespace std;

int main()
{
  while (1)
  {
    string s;
    cin >> s;
    //終了
    if(s == "-") exit(0);
    //シャッフル
    long long int m;
    cin >> m;
    vector<long long int> h(m);
    for(long long int i = 0;i < m;i++)
    {
      cin >> h[i];
    }
    long long int ans = accumulate(h.begin(), h.end(), 0);
    ans = ans % s.size();
    string front, back;
    front = s.substr(0, ans);
    back = s.substr(ans);
    cout << back << front << endl;
  }
}



Measured memory_bytes: 3172
import itertools


while True:
    n, x = [int(i) for i in input().split()]
    if n == x == 0:
        break
    ans = 0
    for a, b in itertools.combinations(range(1, n + 1), 2):
        c = x - (a + b)
        if b < c <= n:
            ans += 1
    print(ans)



Measured memory_bytes: 5644
# D - Non-decreasing

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

A_min = min(A)
A_max = max(A)

ans = []

if abs(A_max) >= abs(A_min):
    A_max_idx = A.index(A_max)
    for i in range(1,N+1):
        ans.append([A_max_idx + 1, i])
    for i in range(1,N):
        ans.append([i, i+1])
else:
    A_min_idx = A.index(A_min)
    for i in range(1,N+1):
        ans.append([A_min_idx + 1, i])
    for i in reversed(range(2,N+1)):
        ans.append([i, i-1])
        
print(len(ans))
for x in ans:
    print(*x)
#     A[x[1]-1] += A[x[0]-1]
#     print(A)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int N, M;
vector<int> V;
vector<vector<long long>> DP;   //上限、和
vector<int> primes;
vector<int> counter;

int main() {
	cin >> N >> M;
	int copym = M;
	for (int p = 2; p * p <= copym; p++) {
		if (copym % p == 0) {
			primes.push_back(p);
			counter.push_back(0);
			while (copym % p == 0) {
				copym /= p;
				counter.back()++;
			}
		}
	}
	if (copym != 1) {
		primes.push_back(copym);
		counter.push_back(1);
	}
	//拡張拡張Euclidの互除法による(階乗)逆元の求め方
	//O(N)
	vector<long long> inv, sinv,stairs;   //inv[i]*i%M = 1,sinv[i]*(i!)%M = 1(0<=i<=N)
	inv.resize(100000+50 + 1);
	sinv.resize(100000+50 + 1);
	stairs.resize(100000 + 50 + 1);
	stairs[0] = 1;
	stairs[1] = 1;
	inv[1] = 1;
	sinv[0] = 1;
	sinv[1] = 1;
	for (int n = 2; n <= 100000+50; n++) {
		stairs[n] = (stairs[n - 1] * n) % MOD;
		inv[n] = MOD - (inv[MOD % n] * (MOD / n)) % MOD;
		sinv[n] = (sinv[n - 1] * inv[n]) % MOD;
	}
	long long ans = 1;
	for (int p = 0; p < primes.size(); p++) {
		int S = counter[p];
		long long temp = stairs[S + N - 1] * sinv[S];
		temp %= MOD;
		temp = (temp * sinv[N - 1]) % MOD;
		ans *= temp;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
    #define mod 1000000007
    using namespace std;
    int n,k,a[100005];
    int fac[100005],ifac[100005];
    int ans1,ans2;
     
    int ksm(int x,int y){
    	int res=1;
    	while(y){
    		if(y&1) res=1ll*res*x%mod;
    		x=1ll*x*x%mod,y/=2;
    	}
    	return res;
    }
     
    int C(int x,int y){
    	int res=1ll*fac[x]*ifac[y]%mod*ifac[x-y]%mod;
    	return res;
    }
     
    int main(){
    	scanf("%d %d",&n,&k);
    	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    	sort(a+1,a+n+1);
    	for(int i=1;i<=n;i++) if(a[i]<0) a[i]+=mod;
    	fac[0]=1;for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
    	ifac[n]=ksm(fac[n],mod-2);
    	for(int i=n-1;i>=0;i--) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
    	for(int i=k;i<=n;i++){
    		ans1+=1ll*a[i]*C(i-1,k-1)%mod;
    		if(ans1>=mod) ans1-=mod;
    	}
    	for(int i=1;i<=n-k+1;i++){
    		ans2+=1ll*a[i]*C(n-i,k-1)%mod;
    		if(ans2>=mod) ans2-=mod;
    	}
    	printf("%d\n",(ans1-ans2+mod)%mod);
     
    	return 0; 
    }

Measured memory_bytes: 1408
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
signed main(){
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> town[114514];
    for(int i=0;i<m;i++){
        int p,y;
        cin>>p>>y;
        town[p-1].push_back(make_pair(y, i));
    }
    vector<pair<int,string>> a;
    for(int i=0;i<n;i++){
        sort(town[i].begin(),town[i].end());
        for(int j=0;j<town[i].size();j++){
            a.push_back(make_pair(town[i][j].second,to_string(1000000+i+1).substr(1,6)+to_string(1000000+j+1).substr(1,6)));
        }
    }
    sort(a.begin(),a.end());
    for(int i=0;i<m;i++){
        cout<<a[i].second<<endl;
    }
    return 0;
}


Measured memory_bytes: 13552
///Astalavista Code........~boy_with_no_gf
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define mk make_pair
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl; 
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2e6 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
inline void PP(int n) { cout << n << " ";}
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
// <=================================================================================================================================
// <=================================================================================================================================
int power(int num,int powe){
    int ans=1;

    while(powe>0){
        if(powe&1) ans=(ans%M*num%M)%M;
        num=(num%M*num%M)%M;
        powe>>=1;
    }
    return ans;
}

void fun(){
    int n;cin>>n;
    int ans=(power(10,n)-((2*power(9,n))%M)+power(8,n) + M)%M;
    cout<<ans;
}

signed  main() {
    lets_go

    int t;
    t=1;
    //cin >> t;
    while (t--) {            
         fun();             
    }                        
                            
                            
    return 0;

}

Measured memory_bytes: 3616