akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
ll a[100005];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	map<ll, int> mp;
	FOR(i, n) {
		ll a;
		cin >> a;
		mp[a]++;
	}
	vector<ll> v;
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		FOR(cnt, itr->second/2) {
			v.push_back(itr->first);
		}
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	if (v.size() < 2) cout << 0 << endl;
	else cout << v[0]*v[1] << endl;

	// sort(a, a+n);
	// reverse(a, a+n);
	// int cnt = 1;
	// FOR(i, n-1) {
	// 	if (a[i] == a[i+1]) {
	// 		cnt++;
	// 	}

	// }
	// priority_queue<ll> que;
	// int cnt = 1;
	// map<ll, int> mp;
	// for (int i = 1; i < n; i++) {
	// 	if (a[i] == a[i-1]) {
	// 		cnt++;
	// 	}
	// 	else {
	// 		FOR(j, cnt/2) que.push(a[i-1]);
	// 		cnt = 1;
	// 	}
	// }
	// FOR(j, cnt/2) que.push(a[n-1]);
	// ll ma1 = que.top();
	// que.pop();
	// ll ma2 = que.top();
	// cout << ma1 * ma2 << endl;

	return 0;
}

Measured memory_bytes: 6528
#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 pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

class minimum_spanning_tree{
public:
	int n;
	vvector<pll> edges;
	minimum_spanning_tree(int N):n(N){
		edges.resize(n);
	}

	void add_edge(int from, int to, ll cost){
		edges[from].emplace_back(to, cost);
	}

	ll solve(){
		ll res = 0;
		priority_queuer<pll> pq;
		pq.emplace(0, 0);
		vector<bool> used(n, false);
		while(pq.size()){
			pll d = pq.top();
			pq.pop();
			if(used[d.second]){
				continue;
			}
			used[d.second] = true;
			res += d.first;
			foreach(i, edges[d.second]){
				if(used[i.first])continue;
				pq.emplace(i.second, i.first);
			}
		}
		return res;
	}
};


int main(){
	int n;
	cin >> n;
	minimum_spanning_tree msp(n);
	rep(i, n){
		rep(j, n){
			int cost;
			cin >> cost;
			if(cost==-1)continue;
			msp.add_edge(i, j, cost);
		}
	}
	cout << msp.solve() << endl;
	return 0;
}



Measured memory_bytes: 3164
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/27 15:24:23 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1000000007;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

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

// TOP
void	Main()
{
	ll	n;
	string	s;
	cin >> n >> s;

	unordered_map<char, ll>	M;
	rep(i, s.size())
		M[s.at(i)]++;
	ll	sum;
	sum = 1;
	for (auto itr = M.begin(); itr != M.end(); itr++)
	{
		sum *= (itr->second + 1);
		sum %= MOD;
	}
	sum--;
	cout << sum << endl;
}
// END

int		main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 512
#include <stdio.h>

int total = 0;
int a, b, c = 0;
int x, y = 0;
int total1, total2, total3 = 0;

int case1(int a,int b,int x,int y){
  total1 = a*x + b*y;
  return total1;
}

int case2(int a,int b,int c,int x,int y){
  if(x<y){
    total2 = c*y*2;
  }else{
    total2 = c*x*2;
  }
  return total2;
}

int case3(int a,int b,int c,int x,int y){
  if(x<y){
    total3 = c*x*2 + (y-x)*b;
  }else{
    total3 = c*y*2 + (x-y)*a;
  }
  return total3;
}

int compare(int total1,int total2,int total3){
  total = total1;
  if(total2 < total1) total = total2;
  if(total3 < total) total = total3;
  return total;
}

int main(void){
  scanf("%d %d %d %d %d",&a, &b, &c, &x, &y);
  
  case1(a,b,x,y);
  case2(a,b,c,x,y);
  case3(a,b,c,x,y);

  compare(total1,total2,total3);
  
  printf("%d\n",total);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    vector<int> c(9);
    rep(i, 9) cin >> c[i];

    vector<int> x(3);
    vector<int> y(3);
    repi(i, 3) x[i] = c[i] - c[i-1];
    repi(i, 3) y[i] = c[3 * i] - c[3 * (i - 1)];
    
    rep(i, 3) {
        repi (j, 3) {
            if (c[3 * i + j] - c[3 * i + j - 1] != c[3 * 0 + j] - c[3 * 0 + j - 1]){
                put("No");
                return 0;
            }
        }
    }
    
    repi(i, 3) {
        rep (j, 3) {
            if (c[3 * i + j] - c[3 * (i - 1) + j] != c[3 * i + 0] - c[3 * (i - 1) + 0]){
                put("No");
                return 0;
            }
        }
    }

    put("Yes");

    return 0;
}

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

int main() {
    int n, sum = 0;
    cin >>n;
    vector<int> t(n);
    for (int i = 0; i < n; i++) {
        cin >> t.at(i);
        sum += t.at(i);
    }

    int m, p, x;
    cin >>m;
    for (int i = 0; i < m; i++) {
        cin >>p >>x;
        cout << sum - t.at(p-1) + x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int a,b; cin >> a >> b;
    int h = 0;
    for (int i = 1; i < b-a; i++)
    {
        h += i;
    }
    cout << h-a << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

import math
if abs (N - M) > 1:
    print(0)
else:
    if (N + M) % 2 == 0:
        print(math.factorial(N) * math.factorial(M) * 2 % (10 ** 9 + 7))
    else:
        print(math.factorial(N) * math.factorial(M) % (10 ** 9 + 7))

Measured memory_bytes: 5188
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    read!(usize);
    let A = read![[i64]];

    let minus = A.iter().filter(|&&a| a < 0).count();
    let m = A.iter().map(|&a| a.abs()).min().unwrap();
    let sum = A.iter().map(|a| a.abs()).sum::<i64>();
    // debug!(minus, m, sum);

    println!("{}", if minus % 2 == 0 { sum } else { sum - m * 2 })
}


Measured memory_bytes: 8444
#include <algorithm>
#include <iostream>
#include <vector>

int main()
{
  std::vector<int> v(3);
  std::cin >> v[0] >> v[1] >> v[2];

  std::sort(v.begin(), v.end(), std::less<int>());
  bool is557 = (v[0] == 5) && (v[1] == 5) && (v[2] == 7);

  std::cout << (is557 ? "YES" : "NO") << std::endl;

  return 0;
}


Measured memory_bytes: 3592
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
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 ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    vi v;
    v.pb(10);
    rep(i, 30) {
        if(v[i]*5>1000000000000000000) break;
        v.pb(v[i]*5);
    }
    int n;cin >> n;
    if(n&1) {
        printf("0\n");
        return 0;
    }
    int count = 0;
    for(auto p:v) count+=n/p;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define INF INT64_MAX
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[8] = { 1,-1,0,0,1,1,-1,-1 }, ddy[8] = { 0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222

ll fac[MAX];

ll mpow(ll x, ll y) {
  ll ret = 1;
  while (y > 0) {
	if (y & 1) ret = (x*ret) % MOD;
	x = (x*x) % MOD;
	y >>= 1;
  }
  return ret;
}

ll comb(ll x, ll y) {
  if (x < y) return 0;
  ll fac1 = fac[x];
  ll fac2 = fac[y];
  ll fac3 = fac[x - y];
  return ((fac1 *mpow(fac2, MOD - 2)) % MOD * mpow(fac3, MOD - 2)) % MOD;
}

void fac_set() {
  fac[0] = 1;
  FOR(i, 1, MAX) {
	(fac[i] = fac[i - 1] * i) %= MOD;
  }
}

int main(void) {
  ll a, b, h, w;
  fac_set();
  cin >> h >> w >> a >> b;
  ans = comb(h + w - 2, h - 1);

  FOR(i, h - a, h) {
	(tmp += comb(b - 1 + i, i) * comb(w + h - b - i - 2, h - i - 1)) %= MOD;
  }

  (ans = ans - tmp + MOD) %= MOD;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) cerr<<#x<<" "<<x<<endl
#define siz 1005
#define f first
#define s second
#define endl "\n"
#define ci cin.ignore()
using namespace std;
int main()
{
	ll n,i,j;
	cin>>n;
	ll a[n],dp[n];
	for(i = 0;i<n;i++)
	cin>>a[i],
	dp[i] = INT_MAX;
	dp[0] = 0;
	
	for(i = 0;i<n;i++)
	{
		if(i+1<n)
		dp[i+1] = min(dp[i+1],dp[i] + abs(a[i]-a[i+1]));
		if(i+2<n)
		dp[i+2] = min(dp[i+2],dp[i] + abs(a[i]-a[i+2]));
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
//short hand tricks
typedef long long ll;

using namespace std;

ll mod = 1e9+7;
vector<ll> modfact(2e6+1);

//Extended Euclidean Algorithm
ll extended_euclidean(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extended_euclidean(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

void loadModFact(ll n) {
    modfact[0] = 1;//0!
    for(ll i=1; i<=n; i++) {
        modfact[i] = (modfact[i-1]*i) % mod;
    }
}

// Mod arithmetic mod
ll inverse(ll n, ll m) {
    ll x, y;
    ll g = extended_euclidean(n, m, x, y);
    if (g != 1) {
        //No solution should never occur if m is prime
        return 0l;
    }
    x = (x % m + m) % m;
    return x;
}

ll n_choose_k(ll n, ll k) {
    ll res = modfact[n];
    ll div = inverse(modfact[k], mod)*inverse(modfact[n-k], mod) % mod;
    res*=div;
    return res % mod;
}

//all positive in our case
ll powermod(ll n, ll e) {
    if(e==0) {
        return 1l;
    }
    if(e==1) {
        return n;
    }
    ll res = (powermod(n, e/2)*powermod(n, e/2))%mod;
    if(e%2==1)
        res*=n;
    res = res % mod;
    return res;
}

int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(false);
    ll k;
    string s;
    cin >> k >> s;
    int n = k+s.size();
    //26^(n)-(number of strings which don't have s as subsequence)
    ll all = powermod(26, n);
    //consider strings with 0,1,s.size-1 subsequence of s
    loadModFact(n);
    for(int i=0; i<s.size(); i++) {
        ll rem = (n_choose_k(n,i)%mod)*powermod(25, n-i);
        rem = rem % mod;
        all-=rem;
    }
    while(all<0) {
        all+=mod;
    }
    cout << all << "\n";
    return 0;
}


Measured memory_bytes: 19928
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	LLI n, d, a;
	cin >> n >> d >> a;
	vector<pair<LLI, LLI>> v;
	REP(i, n)
	{
		LLI x, h;
		cin >> x >> h;
		v.push_back(make_pair(x, h));
	}
	SORT(v);

	queue<pair<LLI, LLI>> q;
	LLI ans = 0;
	LLI sum = 0;
	REP(i, n)
	{
		while (0 < q.size())
		{
			if (q.front().first < v[i].first)
			{
				sum -= q.front().second;
				q.pop();
			}
			else
			{
				break;
			}
		}
		v[i].second -= sum;

		if (0 < v[i].second)
		{
			LLI minus = (v[i].second - 1) / a + 1;
			q.push(make_pair(v[i].first + 2 * d, minus * a));
			ans += minus;
			sum += minus * a;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl



#define MAX_N 200005


ll factorial[MAX_N];
void make_factorial_tableMOD(){
    factorial[0] = 1;
    for(int i = 1; i < MAX_N; i++){
        factorial[i] = factorial[i-1]*i%MOD;
    }
}

ll bisection_powerMOD(ll x,ll y){
    if(y==0)        { return 1; }
    ll t = bisection_powerMOD(x*x%MOD,y/2);
    if(y%2==1)      { t = t*x%MOD; }
    return t;
}

ll nCrMOD(ll n, ll r){
    if(n<r || n<=0 || r<0){return 0;}
    ll a = factorial[n];
    ll b = a*bisection_powerMOD(factorial[r],(MOD-2))%MOD;
    ll c = b*bisection_powerMOD(factorial[n-r],MOD-2)%MOD;
    return c % MOD;
}

int main(){
    ll n, m, k;
    cin >> n >> m >> k;

    make_factorial_tableMOD();


    ll c = nCrMOD(n*m-2,k-2);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += i*(n-i)*m*m*c;
        ans %= MOD;

    }

    for(int i = 0; i < m; i++){
        ans += i*(m-i)*n*n*c;
        ans %= MOD;

    }

    cout << ans%MOD << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  string s,t;cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(ALL(t));
  	if(s<t){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  return 0;
}


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

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

main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22) cout<<"bust"<<endl;
    else cout<<"win"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <functional>
#include <map>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif


int main(){
	int q, com;
	std::string key;
	long x;
	std::map<std::string, long> m;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif

#if INPUT_FROM_FILE
	ifs >> q;
#else
	std::cin >> q;
#endif
	
	for(int i = 0; i < q; i++){
#if INPUT_FROM_FILE
		ifs >> com >> key;
#else
		std::cin >> com >> key;
#endif
		if(com == 0){
#if INPUT_FROM_FILE
			ifs >> x;
#else
			std::cin >> x;
#endif
			m[key] = x;
		}
		else if(com == 1){
			std::cout << m[key] << std::endl;
		}
		else if(com == 2){
		}
		else{
	
		}
	}
	return 0;
}


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

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> a(n+1);
    vector<ll> b(n+1,0);
    rep2(i,n+1) cin >> a[i];
    ll now=1;
    ll count=1;
    ll repeat=0;
    rep(i,k){
        if(b[now]!=0){
            repeat=count-b[now];
            break;
        }else {
            b[now]=count;
            now=a[now];
            // cout << count << ":" << now << endl;
            count++;
        }
    }

    // rep2(i,n+1){
    //     cout << i << " b:" << b[i] << endl;
    // }
    // cout << "now:" << now << " count:" << count << " b[now]:" << b[now] << endl;

    if(repeat==0){
        cout << now << endl;
    }else {
        k-=b[now];
        k%=repeat;
        rep(i,k+1){
            now=a[now];
        }
    cout << now << endl;
    }
}

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

int main(){
	
  	char c;
  	int ret = 0;
  	for(int i = 0; i < 4 ; i ++){
	   c= getchar();
      if(c=='+')ret++;
      else ret--;
    }
  
  	cout <<ret << endl;
  	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n;
	cin >> n;
	ll maxv = -1000000005;
	vector<vector<int>>f(n, vector<int>(10, 0)), p(n, vector<int>(11));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 10; ++j)cin >> f[i][j];
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 11; ++j)cin >> p[i][j];
	}
	for (int bit = 1; bit < (1 << 10); ++bit) {
		vector<int>count(n, 0);
		ll sum = 0;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 10; ++j) {
				if ((bit&1<<j) && f[i][j]==1)++count[i];
			}
			sum += p[i][count[i]];
		}
		maxv = max(maxv, sum);
	}
	cout << maxv << endl; return 0;
}

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

using namespace std;

#define INF 0x3f3f3f3f

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

	int N;
	cin >> N;

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

	int best = INF;
	int ans = -1;
	for (int i = 0; i < N; i++) {
		int diff = abs( ( A[i] * N) - total);
		if (diff < best) {
			best = diff;
			ans = i;
		}
	}

	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0;
  ll tmp = a[0];

  reps1(i, n) {
    if (tmp <= a[i]) tmp = a[i];
    else ans += tmp - a[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4840
///ShzFahad
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    cout << n*n+n*n*n+n << endl;

}



Measured memory_bytes: 3664
#include <cctype>
#include <iostream>
#include <string>
using namespace std;

int main() {
	string W, T;
	cin >> W;
	int ans = 0;
	while (cin >> T) {
		for (char& i : T) i = tolower(i);
		if (W == T) ++ans;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3236
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i;
  double x = 0;
  for(i=0;i<n;i++){
    double a;
    cin >> a;
    x += 1/a;
  }
  cout << fixed << setprecision(20) << 1/x << "\n";
  return 0;
}

Measured memory_bytes: 3804
def main():
    MOD = 10**9+7
    n,k = map(int, input().split())
    al = list(map(int, input().split()))
    al_abs = []
    al_nl = []
    for a in al: 
        if a > 0: sig = 1
        elif a < 0 : 
            sig = -1
            al_nl.append(a)
        else: sig = 0
        al_abs.append((abs(a), sig))

    if n == k:
        ans = 1
        for i in range(k):
            a = al[i]
            ans *= a
            ans %= MOD
        print(ans)
        exit()

    al_abs.sort(reverse=True)
    n_cnt = 0
    last_p = -1
    last_n = -1
    for i in range(k):
        a, sig = al_abs[i]
        if sig == -1:
            n_cnt+=1
            last_n = i
        elif sig == 1:
            last_p = i
    
    ans = 1
    if n_cnt%2 == 0:
        for i in range(k):
            a, sig = al_abs[i]
            ans *= a
            ans %= MOD
        print(ans)
        exit()


    next_p = -1
    next_n = -1 
    for i in range(k,n):
        a, sig = al_abs[i]
        if sig == 1 and next_p == -1:
            next_p = i
        elif sig == -1 and next_n == -1:
            next_n = i
        if next_n != -1 and next_p != -1:
            break

    comp_np = 0
    if next_p != -1:
        last_n_val = al_abs[last_n][0]
        next_p_val = al_abs[next_p][0]
        comp_np = next_p_val*(1.0)/last_n_val

    comp_pn = 0
    if next_n != -1 and last_p != -1:
        last_p_val = al_abs[last_p][0]
        next_n_val = al_abs[next_n][0]
        comp_pn = next_n_val*(1.0)/last_p_val

    if comp_np == 0 and comp_pn > 0:
        np_or_pn = False
    elif comp_pn == 0 and comp_np > 0:
        np_or_pn = True
    elif comp_np > 0 and comp_pn > 0:
        if next_p_val*last_p_val > next_n_val*last_n_val:
            np_or_pn = True
        else:
            np_or_pn = False

    elif comp_np == 0 and comp_pn == 0:
        if 0 in al:
            print(0)
            exit()
        else:
            al_nl.sort(reverse=True)
            for i in range(k):
                a = al_nl[i]
                ans *= (a)
                ans %= MOD
            print(ans)
            exit()


    # print(next_p, next_n, comp_np, comp_pn)

    for i in range(k):
        if np_or_pn and i == last_n:
            continue
        if (not np_or_pn) and i == last_p:
            continue
        a, sig = al_abs[i]
        ans *= a
        ans %= MOD

    if np_or_pn:
        ans *= next_p_val
        ans %= MOD
    else:
        ans *= next_n_val
        ans %= MOD

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 116040
"""
NTC here
"""
import sys
inp = sys.stdin.readline
def input(): return inp().strip()
# flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**26)
 
def iin(): return int(input())
 
 
def lin(): return list(map(int, input().split()))
 
 
# range = xrange
# input = raw_input
 
def main():
    T = 1
    while T:
        T-=1
        n, k = lin()
        n = n%k
        ans = n
        done = set()
        while n not in done:
            n = abs(n-k)
            ans = min(n, ans)
            done.add(n)
        print(ans)


 
 
 
 
 
main()
 
# threading.Thread(target=main).start()

Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int r0, w, c, r;
	while (cin >> r0 >> w >> c >> r) {
		if (r0 == 0)break;
		int i = 0;
		while (r0 + i * r < c*w) {
			i++;
		}
		cout << i << endl;
	}
	return 0;
}


Measured memory_bytes: 3084
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
int n;
ll segAdd[444444],segMax[444444];
void init(int n_){
  n = 1;
  while( n < n_) n *= 2;
}

//[a,b)
void add(int a,int b,int x,int k,int l,int r){
  if(r <= a || b <= l) return;

  if(a <= l && r <= b){
    segAdd[k] += x;
    while(k){
      k = (k-1)/2;
      segMax[k] = max(segMax[2*k+1] + segAdd[2*k+1],segMax[2*k+2] + segAdd[2*k+2]);
    }
  }else{
    add(a,b,x,2*k+1,l,(l+r)/2);
    add(a,b,x,2*k+2,(l+r)/2,r);
  }
}

ll getMax(int a,int b,int k,int l,int r){
  if(r <= a || b <= l) return -11111111111;

  if(a <= l && r <= b) return segMax[k] + segAdd[k];

  ll left  = getMax(a,b,2*k+1,l,(l+r)/2);
  ll right = getMax(a,b,2*k+2,(l+r)/2,r);

  return max(left,right) + segAdd[k];
}

int H,d[111111],h[111111];
int main(void){
  cin >> n >> H;
  for(int i = 0; i < n-1; i++){
    cin >> d[i] >> h[i];
  }

  int res = 0;
  priority_queue<pair<int,int> > que;
  add(0,1,H,0,0,n);
  for(int i = 0; i < n-1; i++){
    que.push(make_pair(h[i],i));
    while(1){
      if(getMax(i,i+1,0,0,n) - d[i] > 0) break;
      if(que.empty()) break;
      int f = que.top().first;
      int s = que.top().second;
      if(getMax(s,i+1,0,0,n) + f <= H){
	int k1 = (H-getMax(s,i+1,0,0,n))/f;
	int k2 = (d[i]-getMax(i,i+1,0,0,n))/f + 1;
	add(s,i+1,f*min(k1,k2),0,0,n);
	res += min(k1,k2);
      }else{
	que.pop();
	que.push(make_pair(H - getMax(s,i+1,0,0,n),s));
      }
    }
    add(i+1,i+2,getMax(i,i+1,0,0,n) - d[i],0,0,n);
  }
  cout << res << endl;
}

Measured memory_bytes: 8120
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int n,d[101],ans;

int main()
{
    scanf("%d",&n);
    n+=1;
    for(int i=1;i<n;i++)
    {
        scanf("%d",&d[i]);
    }
    sort(d,d+n);
    for(int i=1;i<n;i++)
    {
        if(i%2==0) d[i] = 24-d[i];
    }
    sort(d,d+n);
    ans = 24-d[n-1];
    for(int i=1;i<n;i++)
    {
        //printf("%d %d\n",d[i],d[i-1]);
        ans = min(d[i]-d[i-1],ans);
    }
    
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 888
#include<cstdio>
int n,k,d[15],c;
bool flag;
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=1;i<=k;i++)
    {
        scanf("%d",&c);
        d[c]++;
    }
    while(1)
    {
        int tmp=n;
        while(tmp!=0)
        {
            flag=true;
            if(d[tmp%10]!=0)
            {
                n++;
                flag=false;
                break;
            }
            tmp/=10;
        }
        if(flag==true)
        {
            printf("%d",n);
            return 0;
        }

    }
    return 0;
}

Measured memory_bytes: 128
A, B, C = list(input().split())
print(max(int(A)+int(B+C),int(A+B)+int(C),int(A)+int(C+B),int(A+C)+int(B),int(B)+int(A+C),int(B+A)+int(C),int(B)+int(C+A),int(B+C)+int(A),int(C)+int(A+B),int(C+A)+int(B),int(C)+int(B+A),int(C+B)+int(A)))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int A; int B; int C;
	while (~scanf("%d%d%d", &A, &B, &C)) {
		array<int, 3> xs = { A, B, C };
		sort(xs.begin(), xs.end());
		int x = xs[2] - xs[0], y = xs[2] - xs[1];
		//1. -- x, -- y
		//2. ++ x
		//3. ++ y
		//4. x -= 2
		//5. y -= 2
		//6. x += 2, y += 2
		int ans = (x + y + 1) / 2 + (x % 2 != y % 2);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string N;
  cin >> N;
  cout << "ABC" << N << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

using namespace std;

int main(){
  string a, s, c; cin >> a >> s >> c;
  cout << "A" << s[0] << "C" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define fr first
#define sc second
#define OO (1000000000)         // ToDo
#define EPS (1e-9)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define WT(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    freopen("in", "rt", stdin);
    if(outToFile)
    freopen("out", "wt", stdout);
#endif
}
//
int n;
vvi G;
const int MAXN = 200000+99;
int P[MAXN];
int save;
int num[MAXN], vis[MAXN];
bool ansExist;
//
struct DSU{
    int n;
    vi par;
    
    DSU(int _n){
        n = _n;
        par.resize(n);
        for(int i=0; i<n; i++)
            par[i] = i;
    }
    
    int find(int i){
        if(i == par[i]) return i;
        return par[i] = find(par[i]);
    }
    
    bool same(int i, int j){
        return find(i) == find(j);
    }
    
    void join(int i, int j){
        i = find(i), j = find(j);
        par[j] = i;
    }
};
//
int mex(vi &v){
    sort(all(v));
    v.resize( unique(all(v)) - v.begin() );
    int sz = v.size();
    int ret = 0;
    while(ret < sz && v[ret] == ret) ret++;
    return ret;
}
void DFS(int u){
    
    vi vec;
    for(int i=0; i<G[u].size(); i++)
    {
        int v = G[u][i];
        if(v == save) continue;
        
        if(num[v] == -1)
            DFS(v);
        
        vec.PB( num[v] );
    }
    
    num[u] = mex(vec);
}
void go(int u){
    
    if(vis[u])
    {
        ansExist = false;
        return;
    }
    vis[u] = 1;
    
    vi vec;
    for(int i=0; i<G[u].size(); i++)
    {
        int v = G[u][i];
        vec.PB(num[v]);
    }
    
    int nw = mex(vec);
    if(nw == num[u]) return;
    
    num[u] = nw;
    go(P[u]);
}
//
int main()
{
    read_file();
    while(scanf("%d", &n) != -1)
    {
        G.assign(n, vi());
        for(int i=0; i<n; i++)
        {
            int x;
            scanf("%d", &x);
            x--;
            
            P[i] = x;
            G[x].PB(i);
        }
        
        
        DSU dsu(n);
        save = -1;
        for(int i=0; i<n; i++)
        {
            if(dsu.same(i, P[i]))
            {
                save = i;
                break;
            }
            dsu.join(i, P[i]);
        }
        
        
        memset(num, -1, sizeof num);
        for(int i=0; i<n; i++)
        {
            if(num[i] == -1)
                DFS(i);
        }
        
        
        memset(vis, 0, sizeof vis);
        ansExist = true;
        if(save != -1)
            go( P[save] );
        
        
        string ans = ansExist? "POSSIBLE" : "IMPOSSIBLE";
        printf("%s\n", ans.c_str());
    }
}


Measured memory_bytes: 19584
///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (#x) << " is " << (x) << endl;
#define SPD_emergency 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;
int IM = 1e17;
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " "; cout << endl;}
void PA(int v[], int n) {for (int i = 0 ; i < n ; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n) {for (int i = 0; i < n; i++)cin >> a[i];}
inline void PTN(int n = 1, int a = 0, int b = 0, int c = 0) { if (n--)cout << a << " "; if (n--)cout << b << " "; if (n--)cout << c << " "; cout << endl; }
inline void open() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
// <-------------------------------------------------------------------------------------------------------------------------------------------------------------------------> Ignore This-->  tuple first second push_back string continue make_pair break deque stack queue sort reverse accumulate  count lower_bound upper_bound next_permutation copy_n __builtin_popcount make_tuple
// <========================================================================================================================================================================

signed  main() {
    SPD_emergency

   // int t; cin >> t; int tt = 1; while (t--)
    {
        string s;
        cin >> s;
        if( s=="ABC")
            cout<<"ARC";
        else
            cout<<"ABC";

    }
    return 0;
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
#define dbg(x) cerr << #x"= " << x << endl

std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

vector<int> primes;
void erat(unsigned int limit) {
    vector<bool> prime(limit + 1, true);
    const unsigned int n = sqrt(limit);
    unsigned int i, j;
    primes.push_back(2);
    for(i = 3; i <= n; i += 2) {
        if(prime[i]) {for(j = i * i; j <= limit; j += 2*i) prime[j] = false;}
    }
    for(i = 3; i <= limit; i += 2) {if(prime[i]) primes.push_back(i);}
}

void fact(int n,vii &ret) { //O (cant primos)
    int idx=0;
    int p=primes[0];
    while (p*p<=n) {
        if (n%p==0){
            int cnt=1;
            n /= p;
            while(n%p==0){
                ++cnt;
                n /= p;
            }
            ret.emplace_back(p,cnt);
        }
        p = primes[++idx];
    }
    if(n > 1) ret.emplace_back(n,1);
}

vii merge(const vii &source,const vii &otro){
    vii ret;
    ret.reserve(source.size()+otro.size());
    auto it=source.begin();
    auto it2=otro.begin();
    while(it!=source.end() && it2!=otro.end()){
        if (it->first<it2->first) ret.push_back(*it++);
        else if (it2->first<it->first){
            ret.push_back(*it2++);
        }else{
            if (it->second>it2->second) ret.push_back(*it);
            else ret.push_back(*it2);
            ++it, ++it2;
        }
    }
    while(it!=source.end()) ret.push_back(*it++);
    while(it2!=otro.end()) ret.push_back(*it2++);
    return ret;
}

void add(ui &x, ll y){
    x += y;
    if (x>=MOD) x-=MOD;
}

ui getb(ll b,const vii &a){
    ll div=1;
    for(const auto p:a){
        div = div * powmod(p.first,p.second,MOD)%MOD;
    }
    return b * powmod(div,MOD-2,MOD)%MOD;
}

int main() {
    READ(0);
    erat(2000);
    int n;cin>>n;
    vi a(n);
    vector<vii> f(n);
    FOR(i,n) {cin>>a[i]; fact(a[i],f[i]);}
    vii lcm=f[0];
    for(int i=1;i<n;++i){
        lcm=merge(lcm,f[i]);
    }
    ll b=1;
    for(auto p:lcm) b = b*powmod(p.first,p.second,MOD)%MOD;

    ui ret=0;
    for(int i=0;i<n;++i){
        add(ret,getb(b,f[i]));
    }
    cout << ret;
    return 0;
}



Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#include <bitset>
#include <queue>


#define Z class
#define ln cout<<'\n'
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
using pll = pair<long long, long long>;

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;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
pair<pair<string, int>, int> p[110];

struct UnionFind {
    vector<int> parent;
    UnionFind(int n) : parent(n, -1) { }
    void init(int n) { parent.assign(n, -1); }
    
    int findroot(int x) {
        if (parent[x] < 0) return x;
        else return parent[x] = findroot(parent[x]);
    }
    
    bool issame(int x, int y) {
        return findroot(x) == findroot(y);
    }
    
    bool unite(int x, int y) {
        x = findroot(x);
        y = findroot(y);
        if (x == y)  return false;
        
        if (parent[x] > parent[y]) swap(x, y);
        parent[x] += parent[y];
        parent[y] = x;
        return true;
    }
    
    int size(int x) {
        return -parent[findroot(x)];
    }
};

//　辺が一つもない状態から追加していくことを考える。
// -> 後ろから答えを求めて配列に格納し、逆順出力
int main() {
    ll N, M; cin >> N >> M;
    vector<int> A(M), B(M);
    rep(i, M) {
        cin >> A[i] >> B[i];
             --A[i], --B[i]; //0-origin
    }
    
    UnionFind uf(N);
    
    // はじめはすべての橋が破壊されているので、すべての島の組み合わせ数が”不便さ”になる
    ll current = N * (N-1) / 2;
    vector<ll> res;
    rep (i, M) {
        res.push_back(current);
        
        //逆順に処理していくので、M-1番目からスタートする
        int a = A[M-1-i];
        int b = B[M-1-i];
        
        //【計算量削減】もしa,bが同じ連結成分に入っている場合は処理をスキップ
        if (uf.issame(a, b)) continue;
        
        //aとbがつながれば、新たにsize_a * size_bが行き来可能になる
        ll size_a = uf.size(a);
        ll size_b = uf.size(b);
        //新たに行き来可能になった島の数だけ引き算する
        current -= size_a * size_b;
        uf.unite(a, b);
    }
    
    reverse(res.begin(), res.end());
    rep (i, res.size()) cout << res[i] << endl;
}





Measured memory_bytes: 3444
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<array>

using namespace std;
int main(){
int s,w;
cin>>s>>w;
if(w>=s){
  cout<<"unsafe"<<endl;
}
else 
{
  cout<<"safe"<<endl;
}


}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

const int maxN = 150010;
const int MAXM = 310;
const int MAXK = 17;
const int MOD = 1000000007;
const ll INF = 10000000000000000LL;
const ll inf = 5000000000000LL;

int father[maxN];
int find(int x)
{
	if(x == father[x])
		return x;
	else
		return father[x] = find(father[x]);
}
ll size[maxN];
int n,m;
int X[maxN],Y[maxN];
ll ans[maxN];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&X[i],&Y[i]);
	}
	for(int i=1;i<=n;i++)
	{
		father[i] = i;
		size[i] = 1ll;
	}
	ans[m] = (ll)(n-1)*n/2;
	for(int i=m;i>1;i--)
	{
		int u = find(X[i]);
		int v = find(Y[i]);
		if(u!=v)
		{
			ll tmp = size[u] * size[v];
			ans[i-1] = ans[i] - tmp;
			father[u] = v;
			size[v] += size[u];
		}
		else
			ans[i-1] = ans[i];
	}
	for(int i=1;i<=m;i++)
	{
		cout<<ans[i]<<endl;
	}
    return 0;
}

Measured memory_bytes: 4864