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

int main() {
  int n;
  cin >> n;
  int flag = 1;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  
  for (auto x : a) {
    if (x % 2 == 0) {
      if (x % 3 == 0 || x % 5 == 0) {
      } else {
        flag = 0;
      }
    }
  }

  if (flag == 1) {
    cout << "APPROVED" << endl;
  }else {
    cout << "DENIED" << endl;
  }
}


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

dic = {}

for i in range(N) :
    str = input()
    if str in dic :
        dic[str] += 1
    else :
        dic[str] = 1

cnt = 0

for e in dic.values() :
    if e % 2 != 0 :
        cnt += 1

print(cnt)


Measured memory_bytes: 17892
#include <bits/stdc++.h>
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;
using namespace std;

int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};

int main(){
    ll a; cin >> a;
    cout << a+a*a+a*a*a << endl;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;


int main(){
      int n;
    cin>>n;
    string s;
    cin>>s;
    int c=0;
   for(int i=0;s[i];i++){
    if(s[i]=='R') c++;
   }
   int ans = c;
    for(int i=0;i<c;i++){
           if(s[i]=='R') ans--;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3692
N = int(input())
p = list(map(int, input().split()))

ans = 0
isZero = False
for i in range(N):
    if p[i] - (i+1) == 0:
        ans += 1
        if isZero:
            ans -= 1
            isZero = False
        else:
            isZero = True
    else:
        isZero = False

print(ans)


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

int solve();

int main()
{
	printf("%d\n", solve());

	return 0;
}

int solve()
{
	int h, w, n;
	scanf("%d%d%d", &h, &w, &n);
	std::vector<std::pair<int, int>> yx;
	for (int i = 0; i < n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		yx.push_back({y, x});
	}
	std::sort(yx.begin(), yx.end());
	
	int min_x{1 << 30}, shift{};
	for (int i = 0; i < n; i++)
	{
		if (yx[i].first + shift < yx[i].second)
			min_x = std::min(min_x, yx[i].second);
		else if (yx[i].first + shift == yx[i].second)
			shift++;
	}
	if (min_x == 1 << 30) return h;
	return min_x - 1;
}

Measured memory_bytes: 2420
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int N;
const int MAX_N = 100000;
ll A[MAX_N];

int main(){
  cin >> N;
  REP(i, N) cin >> A[i];
  map<ll, int> mp;
  REP(i, N) {
    mp[A[i]] = i;
  }
  sort(A, A + N);
  int ans2 = 0;
  REP(i, N) {
    if(mp[A[i]] % 2 != i % 2) ans2++;
  }
  cout << ans2 / 2 << endl;


  return 0;
}



Measured memory_bytes: 7296
(n,),a=$<.map{|l|l.split.map &:to_i}
a=p,*a
m=->f,i{r=1+l=2*j=i
x,y=a[l,2]
x&&x>a[i]&&j=l
y&&y>a[j]&&j=r
j!=i&&(a[i],a[j]=a[j],a[i]
f[f,j])}
i=n/2
(m[m,i]
i-=1)while i>0
puts a*" "

Measured memory_bytes: 96212
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <numeric>

intmax_t gcd(intmax_t m, intmax_t n) {
  while (n) std::swap(m %= n, n);
  return m;
}

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<intmax_t> A(N);
  for (auto& ai: A) scanf("%jd", &ai);

  std::vector<intmax_t> pos, neg;
  for (auto ai: A)
    ((ai < 0)? neg:pos).push_back(ai);

  intmax_t res;
  std::vector<std::pair<intmax_t, intmax_t>> ctor;

  if (pos.empty()) {
    // neg only
    std::sort(neg.begin(), neg.end());
    while (neg.size() > 1) {
      intmax_t x = neg.back();
      neg.pop_back();
      intmax_t y = neg.back();
      neg.pop_back();
      ctor.emplace_back(x, y);
      neg.push_back(x-y);
    }
    res = neg.back();
  } else if (neg.empty()) {
    // pos only
    std::sort(pos.rbegin(), pos.rend());
    while (pos.size() > 2) {
      intmax_t x = pos.back();
      pos.pop_back();
      intmax_t y = pos.back();
      pos.pop_back();
      ctor.emplace_back(x, y);
      pos.push_back(x-y);
    }
    {
      intmax_t y = pos.back();
      pos.pop_back();
      intmax_t x = pos.back();
      pos.pop_back();
      ctor.emplace_back(x, y);
      pos.push_back(x-y);
      res = pos.back();
    }
  } else {
    while (pos.size() > 1) {
      intmax_t y = pos.back();
      pos.pop_back();
      intmax_t x = neg.back();
      neg.pop_back();
      ctor.emplace_back(x, y);
      neg.push_back(x-y);
    }
    while (!neg.empty()) {
      intmax_t x = pos.back();
      pos.pop_back();
      intmax_t y = neg.back();
      neg.pop_back();
      ctor.emplace_back(x, y);
      pos.push_back(x-y);
    }
    res = pos.back();
  }

  printf("%jd\n", res);
  for (auto const& p: ctor)
    printf("%jd %jd\n", p.first, p.second);
}


Measured memory_bytes: 5872
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> h(N+1, vector<int>(3, 0));
    rep(i, 1, N + 1) {
        int a, b, c;
        cin >> a >> b >> c;
        h[i][0] = a;
        h[i][1] = b;
        h[i][2] = c;
    }

    int dp[N+2][3] = {};

    for (int i = 1; i < N + 1; i++) {
        for (int j = 0; j < 3; j++) {
            dp[i][j] = max({dp[i][j], dp[i-1][(j+1) % 3] + h[i][j], dp[i-1][(j+2) % 3] + h[i][j]});
        }
    }

    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;

    return 0;
}

Measured memory_bytes: 6912
import sys
input = sys.stdin.readline

mod = 10 ** 9 + 7


def read_valus():
    return map(int, input().split())


def read_list():
    return list(read_valus())


def read_lists(N):
    return [read_list() for n in range(N)]


def p(N, a):
    return (a * (N - a)) % mod


def main():
    pows = [1] * 66
    for i in range(65):
        pows[i + 1] = (pows[i] * 2) % mod

    N = int(input())
    A = read_list()

    num = [0] * 65
    for a in A:
        tmp = a
        for i in range(65):
            if tmp == 0:
                break
            num[i] += tmp % 2
            tmp //= 2

    res = 0
    for i in range(65):
        if num[i] == 0:
            continue

        res = (res + (pows[i] * p(N, num[i])) % mod) % mod

    print(res % mod)


if __name__ == "__main__":
    main()


Measured memory_bytes: 123084
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    int N,M;
    cin>>N>>M;
    ll q=1,t=0;
    for(int i=0;i<M;i++){
        q*=2;
    }
    t=M*1900+(N-M)*100;
    cout<<t*q<<endl;
}



Measured memory_bytes: 384
#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--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7;
const int MAX_N=10000;
int n,a,b;

int main(){
	cin >> n;
	ll s=0;
	REP(i,0,n) cin >> a >> b,s+=b-a+1;
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


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

  string s;
  cin>>s;
  int n = s.size();

  int valid = 1;
  for(int i=0;i<n;i++){
    if(i%2 == 0){
      valid &= s[i] == 'R' || s[i] == 'U' || s[i] == 'D';
    }
    else{
      valid &= s[i] == 'L' || s[i] == 'U' || s[i] == 'D';
    }
  }

  cout<<(valid? "Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
use std::io;
use std::cmp;


fn main() {
    let (n, a, b) = {
        let i = read::<isize>();
        (i[0], i[1], i[2])
    };
    println!("{} {}", cmp::min(a, b), cmp::max(0, a + b - n));
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
n,m=io.read("*n","*n")
if n>=m then
    n,m=m,n
end

if n>=2 and m>=2 then
    print((n-2)*(m-2))
elseif n==1 and m==1 then
    print(1)
elseif n==1 and m>1 then
    print(m-2)
end

Measured memory_bytes: 1016
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int n;
int a[100010];
int b[100010];
int c[100010];

int dp[100010][3];

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

    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];

    for(int i=1;i<=n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }

    cout<<max(max(dp[n][0],dp[n][1]),dp[n][2]);

	return 0;
}


Measured memory_bytes: 2560
import scala.math._

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
//  val a, b, c = sc.nextInt
  val list = List.fill(3)(sc.nextInt)

  val ans = list.distinct.size

  println(ans)


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

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 25912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    int N;
    cin >> N;
    int max_m = 0;
    map<string, int> M;
    for(int i=0; i<N; i++) {
        string s;
        cin >> s;
        M[s]++;
        max_m = max(M[s], max_m);
    }

    for(auto m:M) {
        if(m.second == max_m) {
            cout << m.first << endl;
        }
    }
}



Measured memory_bytes: 19224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int count = S.length()/2;
		for (int i=1;i<S.length()/2;i++) {
			String front = S.substring(0,count-i);
			String back = S.substring(count-i,(count-i)*2);
			if (front.equals(back)==true) {
				System.out.println(front.length()*2);
				return ;
			}
		}
	}

}

Measured memory_bytes: 23124
import sys
from collections import Counter
input = lambda: sys.stdin.readline().rstrip()

MAX = 1000001
dp = [True for _ in range(MAX)]
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
a = sorted(list(set(a)))
ans = 0
for v in a:
   if cnt[v] <= 1 and dp[v]:
      ans += 1
   m = v
   while m < MAX:
      dp[m] = False
      m += v
print(ans)

Measured memory_bytes: 169844
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>

using namespace std;

void solve(int A, int B, int C) { printf("%d\n", A * B / 2); }

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  solve(A, B, C);
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{       
   public static void main(String[] args){

       Scanner sc = new Scanner(System.in);            
            
       char[] s = sc.next().toCharArray();
       
       int n = s.length;
       int ans = 0,l = 0,r = n-1;
       
       while(l < r){
           if(s[l] == s[r]){
               l++;r--;
           }else{
                if(s[l] != 'x' && s[r] != 'x'){
                    System.out.println(-1);
                    return;
                }else{
                    if(s[l] == 'x'){
                        l++;
                        ans++;
                    }
                    if(s[r] == 'x'){
                        r--;
                        ans++;
                    }                    
                }                                               
           }                      
       }
      
       System.out.println(ans);
      
   }
}

Measured memory_bytes: 27604
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
#include <algorithm>
#include<set>
#include <limits>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
#define d9_7 1000000007
int main(void){
  int x,y,z,k;
  cin >> x>>y>>z>>k;
  vector<ll> a(x,0);
  vector<ll> b(y,0);
  vector<ll> c(z,0);
  rep(i,x){
    cin >> a[i];
  }
  rep(i,y){
    cin >> b[i];
  }
  rep(i,z){
    cin >> c[i];
  }
  //rep(i,z)cout<<c[i]<<endl;
  /*int nowa=0,nowb=0,nowc=0;
  rep(i,k){
    cout<<a[nowa]+b[nowb]+c[nowc]<<endl;
    if((nowa!=x-1)&&(a[nowa+1]>b[nowb+1] && a[nowa+1]>c[nowc+1] && nowa<x-1 || nowc==z-1&&a[nowa+1]>b[nowb+1] || nowb==y-1 && a[nowa+1]>c[nowc+1] || nowb==y-1 && nowc==z-1)){
      nowa++;
    }else if((b[nowb+1]>c[nowc+1] && nowb < y-1 || nowc==z-1)&&(nowb!=y-1)){
      nowb++;
    }else{
      nowc++;
    }
  }*/
  vector<ll> v1;
  rep(i,x){
    rep(j,y){
      v1.push_back(a[i]+b[j]);
    }
  }
  sort(v1.begin(),v1.end(),greater<ll>());
  vector<ll> v2;
  rep(i,z){
    rep(j,min((int)v1.size(),k)){
      v2.push_back(c[i]+v1[j]);
    }
  }
  sort(v2.begin(),v2.end(),greater<ll>());
  rep(i,k){
    cout<<v2[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 43112
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}
int main(){
    ll x;cin >> x;
    ll t=360;
    while(true){
        if(t%x==0){
            cout << t/x <<endl;
            return 0;
        }
        t+=360;
    }
}   

Measured memory_bytes: 3564
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let t = read::<String>().chars().collect::<Vec<_>>();
    'outer: for i in (0..s.len() - t.len() + 1).rev() {
        for j in i..i + t.len() {
            if s[j] != t[j - i] && s[j] != '?' {
                continue 'outer;
            }
        }

        for k in 0..s.len() {
            if s[k] == '?' {
                if k >= i && k < i + t.len() {
                    print!("{}", t[k - i]);
                } else {
                    print!("a");
                }
            } else {
                print!("{}", s[k]);
            }
        }
        println!("");
        return;
    }
    println!("UNRESTORABLE");
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
import numpy as np

N, M = map(int,input().split())

As = sorted(list(map(int,input().split())))
BCs = []

for i in range(M):
	inputs = list(map(int,input().split()))
	BCs.append(inputs)
BCs = sorted(BCs, reverse = True, key=lambda x: x[1])

index = 0
for bc in BCs:
	b = bc[0]
	c = bc[1]

	for n in range(b):
		try:
			if As[index] < c:
				As[index] = c
				index += 1
			else:
				break
		except:
			break
print(sum(As))


Measured memory_bytes: 42712
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
 
from functools import reduce
# from math import *
from fractions import *
H, W = map(int, readline().split())
S = [0 for i in range(H)]
for i in range(H):
    S[i] = readline().decode().strip()
 
from collections import deque
def bfs(start, H, W):
    INF = 10 ** 9
    dist = [INF] * (H * W)
    q = deque([start])
    dist[start[0] * W + start[1]] = 0
    max_d = 0
    while q:
        (i, j) = q.popleft()
        d = dist[i * W + j]
        max_d = max(d, max_d)
        for dy in range(-1, 2):
            for dx in range(-1, 2):
                if dx * dy != 0:
                    continue
                if dx == dy:
                    continue
                if i + dy < 0 or i + dy >= H or j + dx < 0 or j + dx >= W:
                    continue
                if S[i + dy][j + dx] == '#':
                    continue
                if dist[(i + dy) * W + j + dx] != INF:
                    continue
                dist[(i + dy) * W + j + dx] = d + 1
                q.append((i + dy, j + dx))
    return max_d
 
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        start = (i, j)
        ans = max(ans, bfs(start, H, W))
print(ans)

Measured memory_bytes: 70376
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

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

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

struct UnionFind{
    vector<int> par;            //親の番号

    UnionFind(int n) : par(n){
        for(int i=0; i<n; i++) par[i]=i;
    }

    int root(int x){
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void merge(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return ;
        par[rx] = ry;
    }

    bool isSame(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind uf(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        uf.merge(a,b);
    }

    vector<int> groupnum(n+1,0);
    int maxmember=0;
    for(int i=0;i<n;i++){
        int num=++groupnum[uf.root(i)];
        if(num>maxmember)maxmember=num;
    }

    cout << maxmember << endl;
}


//Wrong Answer
// int root(int, vector<int>&);

// int main(int argc,char* argv[]){
//     int n,m;
//     cin >> n >> m;

//     vector<int> par(n+1,0);
//     for(int i=0;i<n+1;i++){
//         par[i]=i;
//     }

//     vector<pii> inputdatta(m);
//     for(int i=0;i<m;i++){
//         cin >> inputdatta[i].first >> inputdatta[i].second;
//     }

//     for(int i=0;i<m;i++){
//         int a=inputdatta[i].first,b=inputdatta[i].second;

//         int x=root(a,par),y=root(b,par);
//         if(x==y)continue;
//         else{
//             par[x]=y;
//         }
//         // if(par[a]==a){
//         //     par[a]=b;
//         // }else if(par[b]==b){
//         //     par[b]=a;
//         // }else{
//         //     int r=root(par[b],par);
//         //     par[r]=a;
//         // }

//     }

//     // for(int i=1;i<n+1;i++){
//     //     if(par[i]==i)continue;
//     //     par[i]=root(i,par);
//     // }

//     vector<int> groupmember(n+1,0);
//     int mostpeople=0;
//     for(int i=1;i<n+1;i++){
//         groupmember[par[i]]++;
//         if(groupmember[par[i]]>mostpeople){
//             mostpeople=groupmember[par[i]];
//         }
//     }

//     cout << mostpeople << endl;

//     return 0;
// }

// int root(int child, vector<int> &tree){
//     if(tree[child]==child){
//         return child;
//     }else{
//         return tree[child]=root(tree[child],tree);
//     }

// }


Measured memory_bytes: 11004
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

// https://drken1215.hatenablog.com/entry/2020/03/08/020200
int main() {
    // input, ready
    string S;
    cin >> S;
    const int P = 2019;
    const int N = S.size();

    // resolve
    for (auto c: S) {
        int b = c - '0';

    }
    vector<long long> val(P, 0);
    long long tenfactor = 1;
    long long cur = 0;
    val[cur]++;
    for (int i = 0; i < N; ++i) {
        cur = (cur + (S[N-i-1]-'0') * tenfactor) % P;
        tenfactor = (tenfactor * 10) % P;
        val[cur]++;
    }  
    long long res = 0;
    for (int p = 0; p < P; ++p) res += val[p] * (val[p] - 1) / 2;    

    // output
    cout << res << endl;

    return 0;
}


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

using namespace std;
int n,m,q;
const int MAXN=1e5+1e4;
vector<int> G[MAXN];
int dist[MAXN],v[MAXN],d[MAXN],c[MAXN],color[MAXN];
void dfs(int u,int Dl,int co)
{
    /* cout << u <<" "<< Dl << " "<< co << endl;
    for (int i=0;i<n;i++)cout << dist[i] <<ends;
    puts(""); */
    //if (Dl<=-1) return ;
    if (Dl<=dist[u]) return ;
    dist[u]=Dl;
    if (color[u]==0) color[u]=co;
    for (int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        dfs(v,Dl-1,co);
    }
}
int main()
{
    cin >> n >>m;
    for (int i=0;i<m;i++)
    {
        int x,y;
        cin >> x >> y;
        --x,--y;
        G[x].push_back(y);
        G[y].push_back(x);
        color[i]=0;
    }
    memset(dist,-1,sizeof(dist));
    cin >> q;
    for (int i=0;i<q;i++)
    {
        cin >>v[i]>>d[i]>>c[i];
    }
    for (int i=q-1;i>=0;i--)
    {
        dfs(v[i]-1,d[i],c[i]);
    }
    for (int i=0;i<n;i++)
    {
        cout << color[i] <<endl;
    }
    return 0;
}


Measured memory_bytes: 8696
#include<stdio.h>
#define NIL -1
#define MAX 100000

struct Node{
  int p,l,r;
};

struct Node T[MAX];

int n;

int depth(int a);
int print(int a);

int main(){

  int i,j,x,d,c,l;

  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;

  for(i=0;i<n;i++){
    scanf("%d %d",&x,&d);
    for(j=0;j<d;j++){
      scanf("%d", &c);
      if(j==0) T[x].l=c;
      else T[l].r =c;
      l=c;
      T[c].p=x;
    }
  }

  for ( i=0; i<n; i++ ) print(i);
  return 0;
}

int print(int a){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", a, T[a].p,depth(a));
  if(T[a].p==NIL) printf("root, ");
  else if(T[a].l==NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("["); 

  for(i=0, c=T[a].l; c!=NIL; i++, c=T[c].r){
    if(i==0) printf("%d", c);
    else printf(", %d", c);
  }
  printf("]\n");

  return 0;
}

int depth(int a){
  int num=0,s=T[a].p;
  while(s!=NIL){
    num++;
    s=T[s].p;
  }
  return num;
}

Measured memory_bytes: 1788
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MAX_N=2e5,INF=1e8;

ll x[2],y[2],N;
vector<P> F;

ll dp[MAX_N+1];

int main(){
	REP(i,2){
		cin>>x[i]>>y[i];
	}
	cin>>N;
	ll x1=*min_element(x,x+2),x2=*max_element(x,x+2),y1=*min_element(y,y+2),y2=*max_element(y,y+2);
	REP(i,N){
		ll a,b;
		cin>>a>>b;
		if (x1<=a && a<=x2 && y1<=b && b<=y2){
			F.push_back(P(a,b));
		}
	}
	if (x[0]>x[1]){
		REP(i,2)x[i]*=-1;
		for(auto &ite:F){
			ite.first*=-1;
		}
	}
	if (y[0]>y[1]){
		REP(i,2)y[i]*=-1;
		for(auto &ite:F){
			ite.second*=-1;
		}
	}
	sort(F.begin(),F.end());
	fill(dp,dp+MAX_N+1,INF);
	for(auto ite:F){
		*lower_bound(dp,dp+N+1,ite.second)=ite.second;
	}
	ll lis=lower_bound(dp,dp+N+1,INF)-dp;
	double ans=0;
	if (lis==min(x2-x1,y2-y1)+1){
		ans=(x2-x1+y2-y1)*100-(20-5*M_PI)*(lis-1)+10*M_PI-20;
	}else{
		ans=(x2-x1+y2-y1)*100-(20-5*M_PI)*lis;
	}
	printf("%.18f\n",ans);
	return 0;
}

Measured memory_bytes: 6384
// Date: 2020-03-28

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define D(x) cout << #x << " = " << x << endl;
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n, sz[N];
LL f[N], ans[N], fac[N], inv[N];
VI g[N];

void dfs(int u, int fa) {
    f[u] = 1, sz[u] = 1;
    for(auto v : g[u]) if(v != fa) {
        dfs(v, u);
        f[u] = f[u] * f[v] % mod * inv[sz[v]] % mod;
        sz[u] += sz[v];
    }
    f[u] = f[u] * fac[sz[u]-1] % mod;
}

void dfs2(int u, int fa) {
    for(auto v : g[u]) if(v != fa) {
        ans[v] = ans[u] * fac[sz[v]] % mod * inv[n-sz[v]] % mod * fac[n-sz[v]-1] % mod * inv[sz[v]-1] % mod;
        dfs2(v, u);
    }
}

int main() {
    FIO;
    cin >> n;
    fac[0] = inv[0] = 1;
    rep(i, 1, n) fac[i] = fac[i-1] * i % mod, inv[i] = qpow(fac[i], mod-2, mod);
    rep(i, 1, n-1) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v), g[v].pb(u);
    }
    dfs(1, 0);
    ans[1] = f[1];
    dfs2(1, 0);
    rep(i, 1, n) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 20980
// -*- mode:c++; coding:utf-8; indent-tabs-mode:nil; -*-
// ALDS1_5-A: Exhaustive Search

#include <cstdio>

static bool solve(const int m, const int as[], const unsigned int n) {
  if (m == 0) {
    return true;
  } else if (m < 0 || n == 0) {
    return false;
  } else {
    return solve(m-as[0], as+1, n-1) || solve(m, as+1, n-1);
  }
}

int main(void) {
  unsigned int n;
  std::scanf("%d", &n);
  int as[n];
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%d", &as[i]);
  }

  unsigned int q;
  std::scanf("%d", &q);
  for (auto i = 0u; i < q; ++i) {
    int m;
    std::scanf("%d", &m);
    bool is_solved = solve(m, as, n);
    std::printf("%s\n", is_solved ? "yes" : "no");
  }

  return 0;
}
// end

Measured memory_bytes: 2688
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

using Weight = int;
using Flow = int;
struct Edge {
	int s, d; Weight w; Flow c;
	Edge() {};
	Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
	g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
	addArc(g, a, b, w);
	addArc(g, b, a, w);
}

vector<int> dijkstra(const Graph &g, int s, Array &dist, int M = INF) {
	int n = g.size();
	assert(s < n);
	enum { WHITE, GRAY, BLACK };
	vector<int> color(n, WHITE); color[s] = GRAY;
	vector<int> prev(n, -1);
	dist.assign(n, INF); dist[s] = 0;
	using State = tuple<Weight, int, int>;
	priority_queue<State, vector<State>, greater<State>> pq; pq.emplace(0, s, -1);
	while (pq.size()) {
		Weight d; int v, u; tie(d, v, u) = pq.top(); pq.pop();
		if (dist[v] < d)continue;
		color[v] = BLACK; prev[v] = u;
		for (auto &e : g[v]) {
			if (color[e.d] == BLACK)continue;
			if (dist[e.d] > dist[v] + e.w) {
				if (dist[v] + e.w > M)continue;
				dist[e.d] = dist[v] + e.w;
				pq.emplace(dist[e.d], e.d, v);
				color[e.d] = GRAY;
			}
		}
	}
	return prev;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N, M, L, K, A, H; cin >> N >> M >> L >> K >> A >> H&&N;) {
		vector<int> f(L); rep(i, 0, L) {
			cin >> f[i];
		}

		Graph g(N);
		rep(i, 0, K) {
			int a, b, c; cin >> a >> b >> c;
			addEdge(g, a, b, c);
		}
		Matrix dists(N, Array(N, INF));
		dijkstra(g, A, dists[A], M);
		rep(i, 0, L) {
			dijkstra(g, f[i], dists[f[i]], M);
		}
		Graph g2(N);
		f.push_back(A);
		f.push_back(H);
		rep(i, 0, f.size()) {
			rep(j, 0, f.size()) {
				if (i == j)continue;
				addArc(g2, f[i], f[j], dists[f[i]][f[j]]);
			}
		}
		Array dist;
		dijkstra(g2, A, dist);
		if (dist[H] == INF) {
			cout << "Help!" << endl;
		}
		else if (dist[H] <= M) {
			cout << dist[H] << endl;
		}
		else {
			cout << dist[H] - M + dist[H] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3432
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long A = sc.nextLong();
    long B = sc.nextLong();
    sc.close();
    
    long d = N / (A + B);
    long r = N % (A + B);
    
    long ans = (d * A) + Math.min(r, A);
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N;
	cin >> N;
	ll ans = 1;
	for (int i = 1; i <= N; i++)
	{
		ans = ans * i % 1000000007;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e18
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

template <typename T>
struct SegmentTree{
    typedef function<T(T,T)> F;
    int n;
    F f;
    T unit;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(int newn,F f,T t):f(f),unit(t){
        init(newn);
    }
    SegmentTree(const vector<T> &v,F f,T t):f(f),unit(t){
        int n_ = v.size();
        init(n_);
        for(int i=0;i<n_;i++)dat[n+i]=v[i];
        for(int i=n-1;i;i--){
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
        }
    }
 
    void init(int n_){
        n=1;
        while(n<n_)n<<=1;
        dat.assign(n<<1,unit);
    }
    
    void update(int k,T x){
        dat[k+=n]=x;
        while(k>>=1)
            dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
    }
    T query(int a,int b){
        T vl=unit,vr=unit;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1){
            if(l&1)vl=f(vl,dat[l++]);
            if(r&1)vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }
 
};

int dp[300010];

int main(void){
	int n,k;
	cin>>n>>k;
	vector<int>a(n);
	int m = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		m = max(a[i],m);
	}
	auto f = [](int l,int r){
		return max(l,r);
	};
	SegmentTree<int>seg = SegmentTree<int>(m+1,f,0);
	for(int i=0;i<n;i++){
		int l = a[i]-k;
		int r = a[i]+k;
		l = max(l,0);
		r = min(m,r);
		int t = seg.query(l,r+1);
		//cout<<t+1<<endl;
		if(dp[a[i]]<t+1){
			dp[a[i]] = t+1;
			seg.update(a[i],dp[a[i]]);
		}
	}
	int ans = 0;
	for(int i=0;i<=m;i++){
		ans = max(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 9796
S = input()
ans = 0
if len(S) % 2 == 0:
    a = S[:len(S) // 2]
    b = S[len(S) // 2:]

    for i in range(len(a)):
        if a[i] != b[-i - 1]:
            ans += 1

else:
    mid = len(S) // 2
    a = S[:mid]
    b = S[mid:]
    for i in range(len(a)):
        if a[i] != b[-i - 1]:
            ans += 1

print(ans)

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

struct mint {
  ll x;
  mint(ll x=0) : x(x%mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x -= a.x) < 0) x += mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) {
    mint res(*this);
    return res*=a;
  }
};

const int PRIME_MAX = 1'000'000 + 5;
int prime[PRIME_MAX];
void initSieve() {
  rep(i, PRIME_MAX) prime[i] = i;
  for (int i = 2; i * i <= PRIME_MAX; i++) {
    if (prime[i] < i) continue;
    for (int j = prime[i]*prime[i]; j <= PRIME_MAX; j+=prime[i]) {
      prime[j] = prime[i];
    }
  }
}

const int MAX = 1'000'000 + 5;
ll inv[MAX];

void initModDiv() {
  inv[1] = 1;
  srep(i, 2, MAX) {
    inv[i] = mod - inv[mod%i] * (mod / i) % mod;
  }
}

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

  int n; std::cin >> n;
  vi a(n); rep(i, n) std::cin >> a[i];
  initSieve();
  initModDiv();
  map<int, int> cnt;
  rep(i, n) {
    int tmp = a[i];
    map<int, int> _cnt;
    while (tmp != 1) {
      _cnt[prime[tmp]]++;
      tmp /= prime[tmp];
    }
    for (auto p : _cnt) chmax(cnt[p.fi], _cnt[p.fi]);
  }
  mint fact = 1;
  for (auto p : cnt) {
    rep(i, p.se) fact *= p.fi;
  }
  mint ans = 0;
  rep(i, n) ans += fact * inv[a[i]];
  std::cout << ans.x << "\n";
}


Measured memory_bytes: 12544
import java.util.*;

public class Main {

    private static final long MOD = 1_000_000_007L;

    private static long fact[];

    public static void main(String[] args) {

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

        fact = new long[S+1];
        fact[0] = 1;
        for (int i = 1; i <= S; i++) {
            fact[i] = (fact[i-1]*i)%MOD;
        }

        long ans = 0;
        for (int i = 1; i <= S/3; i++) {
            int remain = S - i*3;
            int separator = i-1;
            ans += comb(remain+separator, separator);
            ans %= MOD;
        }

 
        System.out.println(ans);
    }

    private static long pow(long a, long n) {
        if (n == 0) return 1;
        if (n == 1) return a;

        if (n%2 == 1) {
            return (pow(a, n-1)*a)%MOD;
        } else {
            long half = pow(a, n/2);
            return (half*half)%MOD;
        }
    }

    private static long comb(int a, int b) {
        long lower = (fact[a-b]*fact[b])%MOD;
        return (fact[a]*pow(lower,MOD-2))%MOD;
    }
}


Measured memory_bytes: 35824
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,ans;
int main()
{
	cin>>n;
	if(n>99999)
	{
		ans+=90000;
		ans+=900;
		ans+=9;
	}
	else if(n>999)
	{
		ans+=max(0,n-10000+1);
		ans+=900;
		ans+=9;
	}
	else if(n>9)
	{
		ans+=max(0,n-100+1);
		ans+=9;
	}
	else
	{
		ans=max(0,n);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
using namespace std;

const int INF = 1000000007;

// aとbを掛けた値をmodする(a * b mod p)
int modmulti(int a, int b)
{
    int res = 0;
    int mod = a % INF;
    while (b > 0)
    {
        if ((b & 1) == 1)
        {
            res += mod;
            if (res > INF)
            {
                res -= INF;
            }
        }
        mod <<= 1;
        if (mod > INF)
        {
            mod -= INF;
        }
        b >>= 1;
    }
    return res;
}

int main()
{
    int N;
    if (scanf("%d", &N) < 1) return 0;

    int power = 1;
    for (int i = 1; i <= N; i++)
    {
        power = modmulti(power, i);
    }

    printf("%d\n", power);
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
using namespace std;
const int N=3e3+10;
const int mod=1e9+7;
int n,dp[N],pre[N],suf[N];char s[N];
inline int MOD(int x,int y){x+=y;x-=x>=mod? mod:0;return x;}
int main(){
	scanf("%d",&n);scanf("%s",s+2);
	dp[1]=pre[1]=suf[1]=1;
	for(register int i=2;i<=n;i++){
		if(s[i]=='<')for(register int j=1;j<=i;j++)dp[j]=pre[j-1];
		else for(register int j=1;j<=i;j++)dp[j]=suf[j];
		for(register int j=1;j<=i;j++)pre[j]=MOD(pre[j-1],dp[j]);
		for(register int j=i;j;j--)suf[j]=MOD(suf[j+1],dp[j]);
	}
	printf("%d\n",pre[n]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <string.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define max3(A,B,C) max((A),max((B),(C)))
#define lb lower_bound
#define ub upper_bound

using namespace std;

const int N = 15;
const int INF = 0x3f3f3f3f;

int pd[1 << N][N][N];

int main(void) {
   int n, m;
   int adj[N][N];

   for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
         adj[i][j] = (i == j ? 0 : INF);
      }
   }
   for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) pd[0][i][j] = 0;
   for(int i = 1; i < 1 << N; i++) {
      for(int j = 0; j < N; j++) {
         for(int k = 0; k < N; k++) {
            pd[i][j][k] = INF;
         }
      }
   }

   scanf("%d %d", &n, &m);
   for(int i = 0; i < m; i++) {
      int a, b, c;
      scanf("%d %d %d", &a, &b, &c);
      adj[a][b] = c;
   }

   for(int i = 1; i < 1 << n; i++) {
      for(int j = 0; j < n; j++) {
         if( (i & (1 << j)) == 0) continue;
         for(int w = 0; w < n; w++) {
            if( (i & (1 << w)) == 0) continue;
            for(int k = 0; k < n; k++) {
               if(i & (1 << k)) {
                  if(i - k != 0 || k == w) {
                     pd[i][j][w] = min(pd[i][j][w], pd[i^(1<<j)][k][w] + adj[k][j]);
                  }
               }
            }
         }
      }
   }

   int minn = INF;
   int idx = (1 << n) - 1;
   for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
         minn = min(minn, pd[idx][i][j] + adj[i][j]);
      }
   }

   if(minn == INF) puts("-1");
   else printf("%d\n", minn);

   return 0;
}

Measured memory_bytes: 32024
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<string, ll> msl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
const long double EPS = 1e-9;
 
#define rep(i, n) for(ll (i) = 0; (i) < (n) ; (i)++ )
#define For(i, a, b) for(ll (i) = (a); (i) < (b) ; (i)++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prl2(a,b) cout << (a) << " " << (b) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, d) ctol(ltos((N))[ll(ltos((N)).length()) - (d)])
#define beto(a,b,c) (a) < (b) && (b) < (c)
#define betc(a,b,c) (a) <= (b) && (b) <= (c)
#define rsort(a,n) sort(a,a+n,greater<>())
 
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 100;
 
int main(void){
    ll n,a,b;
    str s,t,u;
    ll cnt = 0;

    in3(n,a,b);
    rep(i, n+1){
        str num = ltos(i);
        ll d = num.length();
        ll ds = 0;
        rep(j, d) ds += ndig(i,j+1);
        if (betc(a,ds,b)) cnt += i;
    }
    prl(cnt);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MOD 1000000007
typedef long long ll;
ll min[200001], max[200001];
int main() {
	int n, k;
	ll sum = 0;
	scanf("%d%d", &n, &k);
	min[0] = 0;
	max[0] = n;
	for (int i = 1; i <= n; i++) {
		min[i] = min[i - 1] + i;
	}
	for (int i = 1; i <= n; i++) {
		max[i] = max[i - 1] + n - i;
	}
	for (int i = k; i <= n + 1; i++) {
		// i個選んだ時の個数+
		sum += max[i - 1] - min[i - 1] + 1;
		sum %= MOD;
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 4848
n=int(input())
p_list=[]
m=1
for i in range(1,n+1):
  m*=i
  if i==1:
    pass
  elif i==2:
    p_list.append(2)
  else:
    div=0
    for j in p_list:
      if i%j==0:
        div+=1
        break
    if div==0:
      p_list.append(i)

ans=1
for i in p_list:
  s=0
  aaa=0
  while aaa==0:
    if m%i==0:
      s+=1
      m=m//i
    else:
      aaa+=1
  s+=1
  ans*=s

print(ans%(10**9+7))

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

int N;
int mod = 1000000007;

int main() {
    int mx = 300000;
    cin >> N;
    vector<int> memoi(mx,0);
    vector<int> memoans(mx,0);

    unsigned int ans = 1;
    int nowc;
    rep(i,N) {
        cin >> nowc;
        int fir = memoi[nowc], sec = memoans[nowc];
        if(sec != 0 && fir != i-1){
            ans += sec;
            ans = ans % mod;
        }
        memoi[nowc] = i;
        memoans[nowc] = ans;
    }

    cout << ans << endl;
}


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

int main() {
    int a,b;
    string s;
    cin >> a >> b;
    if (a < b) {
        s = "a < b";
    } else if (a > b) {
        s = "a > b";
    } else {
        s = "a == b";
    }
    cout << s << "\n"; 
    return 0;
}


Measured memory_bytes: 3088