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

using namespace std;

#define DEBUG

const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1e9 + 7;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    string sep;
    for (const auto &x : v) os << sep << x, sep = ", ";
    return os << '}';
}

template<typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
    os << '{';
    string sep;
    for (const auto &x : arr) os << sep << x, sep = ", ";
    return os << '}';
}

template<typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }

template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
    cerr << ' ' << H;
    dbg_out(T...);
}

#ifdef DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


const int N = 1e6 + 100;

int go[N][26];
int leaf[N];

int sz = 1;

void add_string(string &s) {
    int v = 0;
    for (char &c: s) {
        if (!go[v][c - 'a']) {
            go[v][c - 'a'] = sz++;
        }
        v = go[v][c - 'a'];
    }
    leaf[v]++;
}

string s[200010];

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

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        reverse(s[i].begin(), s[i].end());
        add_string(s[i]);
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        string &t = s[i];
        vector<int> c(26, 0);
        for (int j = t.length() - 1; j >= 0; j--) {
            c[t[j] - 'a']++;
        }
        int v = 0;
        for (int j = 0; j + 1 < t.length(); j++) {
            for (int ch = 0; ch < 26; ch++) {
                if (c[ch] > 0 && go[v][ch]) {
                    ans += leaf[go[v][ch]];
                }
            }
            c[t[j] - 'a']--;
            if (!go[v][t[j] - 'a']) break;
            v = go[v][t[j] - 'a'];
        }
    }
    cout << ans << '\n';
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;
  int cnt = 0;
  reps(i, 1, s.size()) {
    if(s[i] != s[i-1]) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int a, b;
   cin >> a >> b;
   rep(p, 0, 10005) {
      if (p * 8/100  == a && p * 10/100 == b) {
         cout << p << endl;
         return 0;
      }
   }
   cout << -1 << endl;
   return 0;
}

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

ll solve(ll B, ll S) {
    ll a1 = (S+1)/2;
    a1 *= B;
    ll a2 = S/2;
    a2 *= B;

    ll a3 = 0;
    ll ans = a1;
    //printf("%lld %lld %lld\n", a1, a2, a3);
    for(int i=1;i<=B;i++) {
        a3 += S;
        a1 -= (S+1)/2;
        a2 -= S/2;
        //printf("%lld %lld %lld\n", a1, a2, a3);

        ll smax = max(max(a1, a2), a3);
        ll smin = min(min(a1, a2), a3);
        ans = min(ans, smax-smin);
    }

    if(B%3 == 1) {
        ll smax = (B+2)/3;
        smax *= S;
        ll smin = B/3;
        smin *= S;
        ans = min(ans, smax-smin);
    }

    if(B%3==2) {
        ll smax = (B+1)/3;
        smax *= S;
        ll smin = B/3;
        smin *= S;
        ans = min(ans, smax-smin);
    }


    return ans;
}
long long B, S;
int main() {
    scanf("%lld %lld", &B, &S);
    if(B%3 == 0 || S%3 == 0) {
        printf("0\n");
    } else {
        ll ans = solve(B, S);
        ans = min(ans, solve(S,B));
        printf("%lld\n", ans);
    }

}



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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >>D;
  int count=0;
  while(A>0&&C>0){
    C-=B;
    if(C<=0){
      count++;
      break;
    }
    A-=D;
  }
  if(count==1){
    cout << "Yes";
  }
  else{
   cout << "No"; 
  }
}

Measured memory_bytes: 3640
N = int(input())
A = input()
B = input()
C = input()

n = 0
for a, b, c in zip(list(A), list(B), list(C)):
    if a == b:
        if c != a:
            n += 1
    else:
        if c != a:
            n += 1
        if c != b:
            n += 1

print(n)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

struct Info{

	bool operator<(const struct Info &arg) const{

		if(value != arg.value){

			return value < arg.value;

		}else if(weight != arg.weight){

			return weight < arg.weight;

		}else if(type != arg.type){

			return type < arg.type;

		}else if(date != arg.date){

			return date < arg.date;
		}else{

			return name < arg.name;
		}
	}

	ll value,weight,date;
	string type,name;
};

int N;
Info info[SIZE];

int main(){

	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		cin >> info[i].value >> info[i].weight >> info[i].type >> info[i].date >> info[i].name;
	}

	sort(info,info+N);

	for(int i = 0; i < N; i++){

		printf("%lld %lld %s %lld %s\n",info[i].value,info[i].weight,info[i].type.c_str(),info[i].date,info[i].name.c_str());
	}

	return 0;
}




Measured memory_bytes: 18036
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  string S;
  int K;
  cin >> S >> K;

  int num = 1;
  rep(i,min(K, (int)S.size())){
    if(S[i]!='1') {
      num = S[i]-'0';
      break;
    }
  }

  cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vi> g(h, vi(w, -1));
  rep(i, h) rep(j, w) {
    char c;
    cin >> c;
    if(c == '#') g[i][j] = 0;
  }
  ll ans = 0;
  rep(hi, 1 << h) rep(wi, 1 << w) {
    vector<vi> ng = g;
    rep(j, h) {
      if(hi >> j & 1) {
        rep(jj, w) ng[j][jj] = 1;
      }
    }
    rep(j, w) {
      if(wi >> j & 1) {
        rep(ii, h) ng[ii][j] = 1;
      }
    }
    ll now = 0;
    rep(x, h) rep(y, w) if(ng[x][y] == 0) now++;
    if(now == k) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
N, L = map(int, input().split())

state = [0 for _ in range(N)]

for i in range(N):
    state[i] = L + i

tmp = 10 ** 9

for i in range(N):
    if tmp > abs(sum(state) - sum(state)-state[i]):
        tmp = abs(sum(state) - sum(state)-state[i])
        res = sum(state) - state[i]

print(res)


Measured memory_bytes: 3060
use std::io::Read;

fn solve(i : usize, n : usize, a : Vec<usize>, d : usize) -> i32 {
    if d > n { return -1 }
    else if i == 2 { return d as i32 }
    else { return solve(a[i-1], n, a, d+1) }
}


fn main() {
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    use std::iter::FromIterator;
    let mut iter = input.split_whitespace();
    let n : usize = iter.next().unwrap().parse().unwrap();
    let a : Vec<usize> = Vec::from_iter(iter.map(|s| s.parse().unwrap()));

    println!("{}", solve(1, n, a, 0))
}


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

using namespace std;
int main()
{
    string s;
    cin>>s;

    int n=0,l,i;
    l=s.size();

    for(i=0;i<l/2;i++)
    {
        if(s[i]!=s[l-1-i])
        {
            n++;
        }
    }
    cout<<n<<endl;

    return 0;

}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

int w, h;
ll p, q;

struct node {
    ll val;
    int type;
    bool operator<(const node& rhs) const {
        return val < rhs.val;
    }
} edges[200010];

int main() {
    scanf("%d%d", &w, &h);
    for (int i = 0; i < w; i++) {
        scanf("%lld", &edges[i].val);
        edges[i].type = 0;
    }
    for (int i = w; i < w + h; i++) {
        scanf("%lld", &edges[i].val);
        edges[i].type = 1;
    }
    sort(edges, edges + w + h);
    ll left[2];
    left[0] = w + 1, left[1] = h + 1;
    ll ans = 0;
    for (int i = 0; i < w + h; i++) {
        ans += edges[i].val * left[1 - edges[i].type];
        left[edges[i].type]--;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 3456
# Aizu Problem 0195: What is the Most Popular Shop in Tokaichi?
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    most = 0
    shop = 'A'
    a, b = [int(_) for _ in input().split()]
    if a == b == 0:
        break
    most = a + b
    for s in range(4):
        a = sum([int(_) for _ in input().split()])
        if a > most:
            most = a
            shop = chr(66 + s)
    print(shop, most)
            

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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;


void solve_2(){
    int n;
    cin>>n;
    vector<int> dp(3, 0), new_dp(3, 0);
    fr(day, n){
        vector<int> c(3);
        fr(j, 3) cin>>c[j];

        fr(i, 3){
            fr(j, 3){
                if(i != j){
                    new_dp[j] = max(new_dp[j], c[j] + dp[i]);
                }
            }
        }
        dp = new_dp;
    }

    cout<<(*max_element(dp.begin(), dp.end()));
}


void solve(){
    ll n;
    cin>>n;
    ll a[n], b[n], c[n];
    ll a_, b_, c_;  /// value of happiness at ith day, if activity was done A, B and C resp
    fr(i, n) cin>>a[i]>>b[i]>>c[i];

    a_ = a[0], b_ = b[0], c_ = c[0];
    ll ta, tb, tc;  /// temp vars
    rep(i, 1, n-1){
        ta = a[i] + max(b_, c_);
        tb = b[i] + max(a_, c_);
        tc = c[i] + max(b_, a_);

        a_ = ta, b_ = tb, c_ = tc;
    }
    cout<<max({a_, b_, c_});
}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve_2();
    }

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	int j, m;
	if (b%d != 0) j = b / d + 1;
	else j = b / d;
	if (c%e != 0) m = c / e + 1;
	else m = c / e;
	cout << a - max(j, m) << endl;
}


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[])
{

	string s;

	cin >> s;

	s[5] = ' ';
	s[13] = ' ';

	cout << s << endl;

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ifor(i,n) for(i=0;i<n;i++)
#define ll long long
///vector<int>vec;
///sort(s.begin(),s.endl());
///sort(ara,ara+n);
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    ll int i,n,t,p=INT_MAX,j=0,x,a=0,b,l;
     string s,m;
     cin>>n>>p;
     if(n>9){
        cout<<p<<endl;
     }
     else{
        cout<<p+100*(10-n)<<endl;
     }

     return EXIT_SUCCESS;
}



Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main(){
    input!{
        v: [u64; 3]
    }
    if v[0] > v[2] {print!("{} {}", v[0]-v[2], v[1])} else if v[0] + v[1] < v[2] {print!("0 0")} else {print!("0 {}",v[1]-(v[2]-v[0]))}
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

s64 modpow(s64 x, s64 n, s64 mod)
{
    s64 ret = 1;
    while (n)
    {
        if (n & 1) ret = ret * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return ret;
}

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

    int n;
    cin >> n;

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

    s64 sum1 = 0;
    s64 sum2 = 0;
    s64 squaredsum;
    s64 ans;
    rep (i, n)
    {
        sum1 = (sum1 + a[i]) % MOD;
        sum2 = (sum2 + a[i] * a[i] % MOD) % MOD;
    }

    squaredsum = (sum1 * sum1) % MOD;

    ans = (squaredsum + (MOD - sum2)) % MOD * modpow(2, MOD - 2, MOD) % MOD;

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



Measured memory_bytes: 4708
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ul n;
  cin >> n;
  vector< tuple< ul, ul > > v(n);
  for (ul i=0; i<n; ++i) {
    ul x;
    cin >> x;
    v[i] = make_tuple(x, i);
  }
  sort(v.begin(), v.end());
  ul x1 = get<0>(v[n/2-1]), x2 = get<0>(v[n/2]);
  vector< ul > ans(n);
  for (ul i=0; i<n; ++i) {
    ans[get<1>(v[i])] = (i < n/2 ? x2 : x1);
  }
  for (ul i=0; i<n; ++i) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 6912
n,m =  gets.chomp.split(" ").map(&:to_i)
a = m.times.map{gets.chomp.split(" ").map(&:to_i)}.sort_by{|i,j|j}.sort_by{|i,j|i}
ans = 0
minb = a[0][1]
for i in 1..m-1
  if minb > a[i][0]
    minb = [minb,a[i][1]].min
  else
    ans += 1
    minb = a[i][1]
  end
end
puts ans+1

Measured memory_bytes: 14544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll b = 117;

vector<int> G[100000];
int used[100000];

ll hs[100000];

ll dfs(int n) {
	used[n] = 1;
	ll res = 1;
	for (auto v : G[n]) {
		if (!used[v]) {
			res = (res + dfs(v) * b) % mod;
		}
	}
	return hs[n] = res;
}

int main()
{
	int N;
	cin >> N;
	for (int i = 0, a, b; i < N - 1; i++) {
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
	}
	dfs(0);
	sort(hs, hs + N);
	ll res = 0;
	for (int i = 0; i < N; i++) {
		auto p = equal_range(hs, hs + N, hs[i]);
		res += p.second - p.first - 1;
	}
	cout << res / 2 << endl;
	return 0;
}

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

int main(){
  int N,K;
  cin>>N>>K;
  int n,m=0;
  int l=0;
  for(int j=1;j<K;j*=2)
    l++;
  n=(1<<l)*N;
  for(int i=1;i<=N;i++){
    int k=l;
    for(int j=i;j<K;j*=2)
      k--;
    m+=(1<<k);
  }
  cout<<setprecision(32)<<(double)m/(double)n<<endl;
}

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

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

	int n, m, x, y, cnt, ap = 0, bp = 0;
	vector<int> a, b;
	cin >> n >> m;
	while (m--){
		cin >> x >> y;
		a.push_back(x);
		b.push_back(y);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	for (int i = 0; i < n; ++i){
		cnt = 0;
		for (int j = ap; a[j] == i+1; ++j){
			cnt++;
			ap++;
		}
		for (int j = bp; b[j] == i+1; ++j){
			cnt++;
			bp++;
		}
		cout << cnt << "\n";
	}
	return 0;
}

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

char a[26];

signed main(){
    int n,x=26,i=0,now,next;
    cin>>n;
    n--;
    
    for(int i=0;i<26;i++)
        a[i]=i+'a';
    
    for(;n-x>=0;n-=x,x*=26,i++);
    
    next=n;
    
    if(i==0){
        cout<<a[n]<<endl;
        return 0;
    }
    
    if(n==0)
        for(int j=1;j<=i+1;j++)
            cout<<'a';
    else
        for(int j=1;j<=i+1;j++){
            x/=26;
            now=next/x,next%=x;
            cout<<a[now];
        }
        
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const int mod = 1e9+7;
struct Combination {
    long long *fac, *facInv, *inv;
    explicit Combination(int size) {
        fac = (long long *) malloc(sizeof(long long) * (size+1));
        facInv = (long long *) malloc(sizeof(long long) * (size+1));
        inv = (long long *) malloc(sizeof(long long) * (size+1));
        fac[0] = fac[1] = 1;
        facInv[0] = facInv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i <= size; ++i) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            facInv[i] = facInv[i - 1] * inv[i] % mod;
        }
    }
    long long operator()(int n, int r) {
        if (n < r || n < 0 || r < 0) return 0;
        return fac[n] * facInv[r] % mod * facInv[n - r] % mod;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<long long> A(N);
    for (auto & a : A) cin >> a;
    long long tmp = A[0], tmpGCD = A[0];
    boost::multiprecision::cpp_int tmpLCM = A[0];
    for (int i = 1; i < N; ++i) {
        tmp *= A[i];
        tmp %= mod;
        tmpGCD = __gcd(A[i], tmpGCD);
        tmpGCD %= mod;
        tmpLCM = tmpLCM*A[i]/__gcd((boost::multiprecision::cpp_int)A[i], tmpLCM);
    }
    long long lcm = (long long)(tmpLCM % mod);
    long long ans = 0;
    Combination c(1000000);
    for (int i = 0; i < N; ++i) {
        ans += lcm * c.inv[A[i]] % mod;
        if (ans >= mod) {
            ans -= mod;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 23936
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	map<int,int> M;
	REP(i,N){
		M[in()]++;
	}
	
	int S=0;
	for(auto& x:M){
		S += x.second-1;
	}
	out(S%2?M.size()-1:M.size());
	return 0;
}


Measured memory_bytes: 4992
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  char c;cin>>c;
  if(c<='Z')cout<<'A'<<endl;
  else cout<<'a'<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define N (100000+1000)
using namespace std;

long long n,m,k,x,a[N],d[N],p[N],ans[N],tmp[N],sum;

void Qpow()
{
	for (int i=1; i<=n; ++i) ans[i]=i;
	while (k)
	{
		if (k&1)
		{
			for (int i=1; i<=n; ++i) tmp[i]=ans[p[i]];
			for (int i=1; i<=n; ++i) ans[i]=tmp[i];
		}
		for (int i=1; i<=n; ++i) tmp[i]=p[p[i]];
		for (int i=1; i<=n; ++i) p[i]=tmp[i];
		k>>=1;
	}
	for (int i=1; i<=n; ++i) tmp[i]=d[ans[i]];
	for (int i=1; i<=n; ++i) d[i]=tmp[i];
}

int main()
{
	scanf("%lld",&n);
	for (int i=1; i<=n; ++i)
		scanf("%lld",&a[i]),d[i]=a[i]-a[i-1],p[i]=i;
	scanf("%lld%lld",&m,&k);
	for (int i=1; i<=m; ++i)
		scanf("%lld",&x),swap(p[x],p[x+1]);
	Qpow();
	for (int i=1; i<=n; ++i)
		sum+=d[i],printf("%lld\n",sum);
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

vector<int> dx = {-1, 0, 1, -1, 1, -1, 0, 1};
vector<int> dy = {-1, -1, -1, 0, 0, 1, 1, 1};

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    rep(i, h)rep(j, w){
        if(s[i][j] == '.'){
            int bomb = 0;
            rep(k, 8){
                int x = j + dx[k];
                int y = i + dy[k];
                if(x < 0 || x >= w) continue;
                if(y < 0 || y >= h) continue;
                if(s[y][x] == '#') bomb++;
            }
            s[i][j] = to_string(bomb)[0];
        }
    }
    rep(i, h) cout << s[i] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int palindromo(int n){
    int a = 0, m = n;
    while(m!=0){
        a*=10;
        a=a+m%10;
        m = m/10;
    }
    if (a == n) return 1;
    return 0;
}
int main(){
    int a,b,n = 0;
    scanf("%d %d",&a,&b);
    for(a;a<=b;++a) if(palindromo(a) == 1) ++n;
    printf("%d\n",n);
    return 0;
}

Measured memory_bytes: 128
if __name__ == '__main__':
    s = input()
    t = input()

    dp = [[0 for _ in range(len(s) + 1)] for _ in range(len(t) + 1)]

    for i in range(len(t)):
        for j in range(len(s)):
            if t[i] == s[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])

    r = []

    li, lj = len(t), len(s)

    while li != 0 and lj != 0:
        if t[li - 1] == s[lj - 1]:
            r.append(t[li - 1])
            li -= 1
            lj -= 1
        elif dp[li][lj - 1] > dp[li - 1][lj]:
            lj -= 1
        else:
            li -= 1

    print("".join(r[::-1]))


Measured memory_bytes: 119772
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    cout<<n*(n-1)/2;
}


Measured memory_bytes: 3656
# -*- coding: utf-8 -*-
"""
Bitset II - Enumeration of Subsets III
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_11_C&lang=jp

"""
from itertools import combinations

_ = input()
k, *B = map(int, input().split())
for v, combi in sorted([((sum([1 << cc for cc in c])), ' '.join(map(str, c))) for i in range(k + 1) for c in combinations(B, i)]):
    print(f'{v}: {combi}' if v else '0:')



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

using namespace std;

int main()
{
    //system("chcp 65001");

    int H,W,h,w;
    cin >> H >> W;
    cin >> h >> w;

    cout << H * W - (h*W + H*w - h*w);

    //cout << N;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()

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;
}
template<class T>inline int cmp(vector<T>&v,T &a){
	return lower_bound(all(v),a)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N,K;
vector<pair<int,bool>>v;
int mod_pow(int x,int y,int m=mod){
	int res=1;
	while(y>0){
		if(y&1)(res*=x)%=m;
		(x*=x)%=m;
		y>>=1;
	}
	return res;
}
signed main(){
	cin>>N>>K;
	rep(i,N){
		int a;cin>>a;
		if(a>=0)v.push_back({a,true});
		else v.push_back({-a,false});
	}
	sort(all(v),greater<>());
	int cnt=0,now=1,lastmi=-1,lastp=-1;
	rep(i,K){
		int n=v[i].first;
		if(!v[i].second){
			n=(-n+mod)%mod;
			lastmi=v[i].first;
			cnt++;
		}else {
			lastp=n;
		}
		now*=n;
		now%=mod;
	}
	if(now==0){
		cout<<now<<endl;return 0;
	}
	if(cnt%2){
		long double ptom=-inf,mtop=-inf;
		int pp,mm;
		for(int i=K;i<N;i++){
			if(v[i].second&&lastmi!=-1&&mtop==-inf){
				mtop=(long double)v[i].first/lastmi;
				pp=v[i].first;
			}
			if(!v[i].second&&lastp!=-1&&ptom==-inf){
				ptom=(long double)v[i].first/lastp;
				mm=v[i].first;
			}
		}
		if(ptom!=-inf||mtop!=-inf){
			if(ptom<mtop){
				now=now*mod_pow((-lastmi+mod)%mod,mod-2)%mod;
				now*=pp;now%=mod;
			}else {
				now=now*mod_pow(lastp,mod-2)%mod;
				now*=(-mm+mod)%mod;now%=mod;
			}
		}else {
			sort(all(v));
			now=1;
			rep(i,K){
				int n=v[i].first;
				if(!v[i].second){
					n=(-n+mod)%mod;
				}
				now*=n;now%=mod;
			}
		}
	}
	cout<<now<<endl;
}


Measured memory_bytes: 7432
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>


//pair sort firstに揃う

#define int long long
#define pb(n) push_back(n)
#define Rap(n,i) for(int (i)=0;(i)<(n);(i)++)
#define Pr(n) cout<<n<<endl;
#define F first
#define S second
#define vector2 vector<vector<int> >
#define index(v,x) find((v).begin(), (v).end(), (x))-(v).begin()
#define ctoi(c) (int)(c-'0')
#define incin(n) int (n); cin>>(n);
#define all(v) (v).begin() , (v).end()
#define ELM 100001 //問題によっては1000000001に変更

//限定
using namespace std;

signed  main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<string> s(n);
    Rap(n, i){
        cin >> s.at(i);
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());
    int c=1;
    int ans = 0;
    Rap(n-1, i){
        if (s[i+1]!=s[i]) {
            ans += c*(c-1)/2;
            c=1;
        }else{
            c++;
            if (i==n-1-1) {
                ans+=c*(c-1)/2;
            }
        }
    }
    Pr(ans);
//    int ans = 0;
//    Rap(n-1, i){
//        Rap(n-1-i, j){
//            if (s[i]==s[i+j+1]) {
//                ans ++;
//            }
//        }
//    }
    return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//_|

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int i,n,an,cn;
	cin>>n;
	
	vector<int> a(n,0),b(n,0),c(n,0);
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	rep(i,n)cin>>c[i];
	
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
//	rep(i,n)cout<<a[i]<<" ";
//	cout<<endl;
//	rep(i,n)cout<<b[i]<<" ";
//	cout<<endl;
//	rep(i,n)cout<<c[i]<<" ";
//	cout<<endl;
	
	ll ans=0;
	rep(i,n){
		an=(lower_bound((a).begin(),(a).end(), b[i])-a.begin());
		cn=c.end()-upper_bound((c).begin(),(c).end(), b[i]);
		ans+=(ll)an*cn;
//		cout<<an<<" "<<cn<<endl;
	}
	fin(ans);
	
	
//////////////////////////////////////////////////////
return 0;}











Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline void Max(T &a, T b){if(a < b) a = b;}
template <typename T> inline void Min(T &a, T b){if(a > b) a = b;}
const int N = 4007, mod = 998244353;
int n, K, ans;
int fac[N], invfac[N], inv[N], bin[N], suf0[N], suf1[N];
int C(int n, int m) {
	if(n < m) return 0;
	return 1ll * fac[n] * invfac[m] % mod * invfac[n - m] % mod;
}
void add(int &a, int b) {
	a += b;if(a >= mod) a -= mod;
}
void solve(int n, int cnt, int w) {
	for(int i = 0; i <= w; ++i) {
//		int tmp = 0;
//		for(int j = i; j <= w; ++j) add(tmp, 1ll * (j - i & 1 ? mod - 1 : 1) * C(n + cnt - j - 1, cnt - j - 1) % mod * C(w, j) % mod * C(j, i) % mod);
//		add(ans, 1ll * tmp * bin[w - i] % mod);
		add(ans, 1ll * (i & 1 ? mod - 1: 1) * C(n + cnt - i - 1, cnt - i - 1) % mod * C(w, i)% mod * bin[w - i] % mod);
	}
}
int main() {
#ifndef ONLINE_JUDGE
//	freopen("data.in", "r", stdin);
#endif
	K = gi(), n = gi();
	inv[1] = fac[0] = invfac[0] = 1, bin[0] = 1;
	rep(i, 1, 4000) {
		if(i ^ 1) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
		fac[i] = 1ll * fac[i - 1] * i % mod;
		invfac[i] = 1ll * invfac[i - 1] * inv[i] % mod;
		bin[i] = 1ll * bin[i - 1] * 2 % mod;
	}
	rep(k, 2, 2 * K) {
		ans = 0;
		int w = min(k / 2, K - (k - 1) / 2), cnt = K - w;
		if(k % 2 == 0 && K >= k / 2) {
			solve(n, cnt, w - 1);
			solve(n - 1, cnt, w - 1);
		}
		else solve(n, cnt, w);
		printf("%d\n", ans);
	}
	return 0;
}

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

using namespace std;

int N;
vector< int > g[200000];
int ans[200000];
map< int, int > mp[200000];

int dfs2(int idx, int par, int v) {
  if(mp[idx].count(v)) return mp[idx][v];
  int ret = 1;
  for(auto &to : g[idx]) {
    if(to == par) continue;
    if(to < v) ret += dfs2(to, idx, v);
  }
  return mp[idx][v] = ret;
}

void dfs(int idx, int par, int c, int delta) {
  int add = dfs2(idx, par, max(c, par));
  if(c > idx) add -= dfs2(idx, par, c);
  delta += add;
  ans[idx] = delta;
  for(auto &to : g[idx]) {
    if(to == par) continue;
    dfs(to, idx, max(c, par), delta);
  }
}

int main() {
  cin >> N;
  for(int i = 1; i < N; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for(auto to : g[0]) dfs(to, 0, 0, 0);
  for(int i = 1; i < N; i++) cout << ans[i] << " ";
  cout << endl;
}


Measured memory_bytes: 53888
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    lli n, x;
    cin >> n >> x;
    vector<lli> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    lli ans = 0;
    rep(i, n)
    {
        if (x >= a[i])
            ans++, x -= a[i];
    }
    if (ans == 0) {
        cout << 0 << endl;
    } else if (x == 0) {
        cout << ans << endl;
    } else {
        if (ans != n) {
            cout << ans << endl;
        } else {
            cout << ans - 1 << endl;
        }
    }
}


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

int main() {
	int n,x;cin>>n>>x;
	vector<ll>v(n),vv(n);
	for(int i=0;i<n;++i)cin>>v[i];
	vv[0]=v[0];
	for(int i=1;i<n;++i)vv[i]=vv[i-1]+v[i];
	int cnt=1;
	for(int i=0;i<n;++i)if(vv[i]<=x)cnt++;
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#define loop_input(fmt,...) while(~scanf(fmt,__VA_ARGS__))

int main() {
    int a, op ,b;
    loop_input("%d %c %d", &a, &op, &b) {
        if (a == 0 && b == 0 && op == '?')  break;
        switch(op) {
            case '+':
                printf("%d\n", a+b);
                break;
            case '-':
                printf("%d\n", a-b);
                break;
            case '*':
                printf("%d\n", a*b);
                break;
            case '/':
                printf("%d\n", a/b);
                break;
        }
    }
    return 0;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

string in[510];
bool graph[30][30];

bool insert(string a,string b){
	int n=min(a.size(),b.size());
	rep(i,n){
		if(a[i]==b[i])
			continue;
		int aa=a[i]-'a';
		int bb=b[i]-'a';
		graph[aa][bb]=true;
		return true;
	}
	if(a.size()<=b.size())
		return true;
	return false;
}

vi ans;
bool visited[30];
void dfs(int i){
	visited[i]=true;
	rep(j,26) if(graph[i][j]&&!visited[j]) dfs(j);
	ans.pb(i);
}

bool check(){
	ans.clear();
	rep(i,26) visited[i]=false;
	rep(i,26) if(!visited[i]) dfs(i);
	reverse(ans.begin(),ans.end());
	bool ok=true;
	rep(i,ans.size())rep(j,i) if(graph[ans[i]][ans[j]]) ok=false;
	return ok;
}

int main(void){
	int n;
	while(cin >> n){
		if(n==0)
			break;
		rep(i,28)rep(j,28) graph[i][j]=false;
		rep(i,n) cin >> in[i];
		bool ok=true;
		rep(i,n)rep(j,n){
			if(i>=j) continue;
			ok&=insert(in[i],in[j]);
		}
		ok&=check();
		if(ok)
			puts("yes");
		else
			puts("no");
	}
	return 0;
}

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

int solve()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q, ans = 0, count = 0;
  string s;
  cin >> q;
  vector<int> v(101010, 0);
  vector<int> vm(101011, 0);

  // エラトステネスのふるい
  int MAX = 101010;
  vector<int> is_prime(MAX, 1);
  is_prime[0] = 0;
  is_prime[1] = 0;
  for (int i = 2; i < MAX; ++i)
  {
    if (!is_prime[i])
      continue;
    for (int j = i * 2; j < MAX; j += i)
      is_prime[j] = 0;
  }

  for (int j = 0; j < 101010; j++)
  {
    if (is_prime[j] != 1 || is_prime[(j + 1) / 2] != 1 || j % 2 == 0)
    {
    }
    else
    {
      v[j]++;
    }
  }
  for (int j = 0; j <= 101010; j++)
  {
    vm[j + 1] = v[j] + vm[j];
  }

  for (int i = 0; i < q; i++)
  {
    int l, r;
    cin >> l >> r;
    ans = vm[r + 1] - vm[l];
    cout << ans << endl;
    count = 0;
  }
  return 0;
}
signed main()
{
  solve();
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
long long N;
int main() {
	cin >> N;
	cout << 50 << endl;
	for (int i = 0; i < 50; i++) {
		if (i) cout << ' ';
		cout << 49 - i + (N + 49 - i) / 50;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int N,R,ANS,F[111111][3],RES;
char C[111111];
bool L[111111],W[111111];
vector<int>G[111111],T[111111];
void dfs1(int x,int f){
	 L[x]|=(C[x]=='W');
	 for (vector<int>::iterator i=G[x].begin();i!=G[x].end();i++){
	 	 if ((*i)!=f){
			dfs1((*i),x);
			if (L[(*i)]){
			   ANS+=2;
			   L[x]|=1;
			   T[x].push_back(*i);
			   T[*i].push_back(x);
			}
		 }
	 }
}
void dfs2(int x,int f){
	 for (vector<int>::iterator i=T[x].begin();i!=T[x].end();i++){
	 	 if ((*i)!=f){
			dfs2((*i),x);
			F[x][0]=F[(*i)][2];
			sort(F[x],F[x]+3);
		 }
	 }
	 F[x][2]+=W[x];
	 RES=max(RES,F[x][1]+F[x][2]);
}
int main(){
	int u,v;
	scanf("%d",&N);
	for (int i=1;i!=N;i++){
		scanf("%d%d",&u,&v);
    	G[u].push_back(v);
		G[v].push_back(u);
	}
	scanf("%s",C+1);
	bool flg=true;
	for (int i=1;i<=N;i++){
		if (C[i]=='W'){
		   flg=false;
		   R=i;
		   break;
		}
	}
	if (flg){
	   printf("0");
	   return 0;
	}
	dfs1(R,0);
	for (int i=1;i<=N;i++){
		if (L[i]){
  		   W[i]=((C[i]=='W')^(T[i].size()&1));
		   ANS+=W[i];
		}
	}
	dfs2(R,0);
	printf("%d",max(ANS-(RES<<1),1));
	return 0;
}

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

int cnt(int y,int m,int d){
  int res = 0;
  while(y<1000){
    d++; res++;
    if(m&1 && d>20 || ( !(m&1) && ( (y%3 && d>19) || (!(y%3) && d>20)) ) ){
      m++; d=1;
    }
    if(m>10){
      m = 1; y++;
    }
  }
  return res;
}

int main(){
  int n,y,m,d;
  scanf("%d",&n);
  while(n--){
    scanf("%d%d%d",&y,&m,&d);
    printf("%d\n",cnt(y,m,d));
  }
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  string s;
  cin >> s;
  reverse(s.begin(),s.end());
  int64_t val = 0;
  int64_t ten = 1;
  map<int64_t, int64_t> map;
  map[0]=1;
  for(auto c:s){
    val += (c-'0')*ten;
    val %= 2019;
    ten *= 10;
    ten %= 2019;
    map[val]++;
  }
  int64_t count = 0;
  for(auto x: map){
    count += x.second*(x.second-1)/2;
  }
  cout << count << endl;;
  return 0;
}

Measured memory_bytes: 3792
#!/usr/bin/env python3

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    alpha = input()

    if alpha == alpha.upper():
        print('A')
    else:
        print('a')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9108
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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;
}

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    ll i1 = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < i; j++){
            if(a[i] < a[j]){
                i1++;
            }
        }
    }

    ll i2 = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(a[i] < a[j]){
                i2++;
            }
        }
    }
    // i1 %= MOD;
    // i2 %= MOD;

    ll ans1 = i1 * k % MOD;
    ll ans2 = i2 * ((k * (k - 1) / 2) % MOD) % MOD;

    cout << (ans1 + ans2) % MOD << endl;
}

Measured memory_bytes: 256
def calc_max(a, b, n):
    if n == 0:
        return 0
    m = (b - a) // 2
    if m < 0:
        return a*b
    elif m < n:
        return (a+m)*(b-m)
    else:
        return (a+(n-1))*(b-(n-1))


def judge(a, b, m, x):
    max_value = 0
    if x == 0:
        pass
    elif x < a and x < b:
        max_value = calc_max(1, x, x)
    elif x >= a and x < b:
        max_value = max(calc_max(1, x, a-1),
                        calc_max(a+1, x-(a-1), x-(a-1)))
    else:
        max_value = max(calc_max(1, x+1, x+1-b),
                        calc_max(x + 1-b+1, b-1, a-(x+1-b+1)),
                        calc_max(a+1, x+1-a, x+1-a))
    return True if max_value < m else False


def bs(a, b):
    m = a * b
    lft = 0
    rgt = m
    nxt, prv = -1, -1
    while True:
        nxt = (lft + rgt) // 2
        if nxt == prv:
            return nxt
        if judge(a, b, m, nxt):
            lft = nxt
        else:
            rgt = nxt
        prv = nxt


Q = int(input())
for _ in range(Q):
    A, B = map(int, input().split())
    if A > B:
        A, B = B, A
    print(bs(A, B))


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

int main() {
  int a, b, c, x, y;
  scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
  
  int price = 0;
  int mini = min(x, y);
  int sum1 = a*mini + b*mini;
  int sum2 = c*mini*2;
  if (sum1 > sum2) {
    price = min(sum2 + (x-mini)*a + (y-mini)*b, sum2 + (x-mini)*c*2 + (y-mini)*c*2);
  } else {
    price = min(sum1 + (x-mini)*a + (y-mini)*b, sum1 + (x-mini)*c*2 + (y-mini)*c*2);
  }
  
  printf("%d\n", price);
}

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

int main()
{
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  
  int cnt = 0;
  int b = a[2]*2-a[1]-a[0];
  cnt += b / 2;
  if(b%2 != 0) cnt += 2;
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256