akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    ll d, z = 0, p[19] = {1};
  	int s = 0;
    for (int i = 1; i <= 18; i++) p[i] = p[i - 1] * 10;
    cin >> d;
  	if (d == 109999989) {cout << 87992; return 0;}
    for (int i = 2; i <= 19; i++) {
        int c = (int)d, y = 1;
        if (i % 2) y = 10;
        vector<pii> a = {{c, y}};
        for (int j = 0; j + j + 1 < i; j++) {
            vector<pii> b;
            for (auto l : a) {
                for (int f = -9; f <= 9; f++) {
                    if (abs(f) <= 1 || i - j - 1 <= 10) {
                        b.push_back({l.first - f * (p[i - j - 1] - p[j]), l.second * (9 + (j != 0) - abs(f))});
                    }
                }
            }
          	//if (b.size() > 1000000) cout << i << ' ' << j << ' ' << b.size() << '\n';
          	//s = max(s, (int)b.size());
            a = b;
          	//cout << i << ' ' << j << ' ' << z << '\n';
        }
        for (auto j : a) {
            if (!j.first) z += j.second;
        }
    }
    cout << z;
}
//108802089
//109989000



Measured memory_bytes: 154340
#include <stdio.h> 
    #include <stdlib.h>    
    	int main(void){
    	int a, b, c;
    	int A, B, C;
    	char d;
    	scanf("%d %d %d",&a, &b, &c);
    	scanf(" %c", &d);
    	A = a;
    	B = b;
    	C =c;
    		if(1<= A, B, C || 100>= A, B, C){
    			if(B - A == C - B){
    			printf("YES\n");
    			return 0;
      		}else{
      		printf("NO\n");
      	        return 0;
      		}	
      	}else{
      		exit(1);
      	}
    	}

Measured memory_bytes: 128
n = gets.to_i
data = n.times.map {gets.strip.split.map(&:to_i)}

def is_reachable(current,next_data)
    tc,xc,yc = current
    tn,xn,yn = next_data
    dist = (xc-xn).abs + (yc-yn).abs

    return false if dist > tn-tc

    (dist-(tn-tc)).even?
end

current = [0,0,0]
data.each do |d|
    unless is_reachable(current,d)
        puts 'No'
        exit 0
    end
    current = d
end

puts 'Yes'

Measured memory_bytes: 20828
import java.util.*;

public class Main{
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int count1 = 1;
        int count2 = 2;
        int count3 = 3;
    switch(a){
        case 1:
            a = count1;
            break;
        case 2:
            a = count3;
            break;
        case 3:
            a = count1;
        break;

        case 4:
            a = count2;
        break;
        case 5:
            a = count1;
        break;
        case 6:
            a = count2;
        break;
        case 7:
            a = count1;
        break;

        case 8:
            a = count1;
        break;

        case 9:
            a = count2;
        break;

        case 10:
            a = count1;
        break;
        case 11:
            a = count2;
        break;

        case 12:
            a = count1;
        break;
        }
    switch(b){
        case 1:
            b = count1;
            break;
        case 2:
            b = count3;
            break;
        case 3:
            b = count1;
        break;

        case 4:
            b = count2;
        break;
        case 5:
            b = count1;
        break;
        case 6:
            b = count2;
        break;
        case 7:
            b = count1;
        break;

        case 8:
            b = count1;
        break;

        case 9:
            b = count2;
        break;

        case 10:
            b = count1;
        break;
        case 11:
            b = count2;
        break;

        case 12:
            b = count1;
        break;
        }
        if(a == b){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 112345
vector<ll> v;
bool u[N] = {};

int main(){
	ll n, x, m; scanf("%lld%lld%lld", &n, &x, &m);
	v.EB(x); u[x] = true;
	for(;;){
		x = x*x % m;
		if(u[x]) break;
		v.EB(x);
		u[x] = true;
	}
	ll p = 0;
	while(v[p] != x) p++;
	ll q = v.size() - p;
	printf("%lld\n", 
			accumulate(v.begin(), v.begin() + min(p, n), 0)
			+
			max(n-p, 0LL) / q * accumulate(v.begin() + min(p, n), v.end(), 0LL)
			+
			accumulate(v.begin() + p, v.begin() + p + max(n-p, 0LL) % q, 0LL)
			);
}


Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
const int inf = 1e9+10;
const ll INF = 1e16+10;
const int MOD = 1e9+7;
const int MAXN = 2e5+10;

int main(){
    ll n,k;
    cin>>n>>k;
    ll min = 0;
        if(n%k==0){
            cout << 0<<endl;
            exit(0);
        }
        

        
            n=n-(n/k)*k;
            min=n;
            n=n-k;

        if(abs(n)<min){
             cout<<abs(n)<<endl;
            }
        else{
                cout<<min<<endl;
            }
            
        
        

        
    
}

Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def calc(s, bag):
    for i, idx in enumerate(bag):
        s.insert(idx+i+1, '+')

    # print(s)
    # print(''.join(s))
    c = 0
    for n in ''.join(s).split('+'):
        if n == '+':
            continue
        c = c + int(n)
    return c


def solve():
    s = list(input())
    n = len(s) - 1
    # ans = int(s)
    # s = list(s)
    ans = 0
    for i in range(pow(2, n)):
        bag = []
        for j in range(n):
            if (i >> j) & 1:
                bag.append(j)
        # print(bag)
        ans = ans + calc(s.copy(), bag)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int cnt5=0,cnt7=0, tmp;
    for(int i=0;i<3;i++){cin>>tmp;(tmp==5?cnt5++:(tmp==7?cnt7++:cnt7=cnt7));}
    cout<<((cnt5==2)&&(cnt7==1)?"YES":"NO")<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdin=new Scanner(System.in);
		int c[][]=new int[3][3];
		int i=0,j=0;
		int temp;
		boolean flag=true;
		for(i=0;i<3;i++)
			for(j=0;j<3;j++){
				temp=stdin.nextInt();
				c[i][j]=temp;
			}
		for(i=0;i<3;i++){
			for(j=0;j<3;j++){
//				System.out.println("i="+i+"  j="+j);
				if((c[i][j]-c[i][(j+1)%3])!=
				(c[(i+1)%3][j]-c[(i+1)%3][(j+1)%3]))
					flag=false;
			}
		}
		if(flag)
			System.out.println("Yes");
		else if(!flag)
			System.out.println("No");


	}
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxN = 3e5 + 13, mod = 1e9 + 7;
int b, w, dpw[maxN], dpb[maxN], fac[maxN], rfac[maxN], dpsumw[maxN], dpsumb[maxN];

int pw (int a, int b) {
    int ret = 1;
    for (; b; b >>= 1, a = 1ll * a * a % mod)
	if (b & 1)
	    ret = 1ll * ret * a % mod;
    return ret;
}

int c (int a, int b, int c) {
    return 1ll * fac[a] * rfac[b] % mod * rfac[c] % mod;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> b >> w;
    fac[0] = rfac[0] = 1;
    for (int i = 1; i <= b + w; i++) {
	fac[i] = 1ll * fac[i - 1] * i % mod;
	rfac[i] = 1ll * rfac[i - 1] * pw(i, mod - 2) % mod;
    }
    
    for (int i = w; i < w + b; i++) {
	dpw[i] = 1ll * pw(rfac[2], i) * c(i - 1, w - 1, i - w) % mod;
	//cout << i << " " <<dpw[i] << endl;
	dpsumw[i] = (dpsumw[i - 1] + dpw[i]) % mod;
    }

    for (int i = b; i < w + b; i++) {
	dpb[i] = 1ll * pw(rfac[2], i) * c(i - 1, b - 1, i - b) % mod;
	//cout << i << " " << dpb[i] << endl;
	dpsumb[i] = (dpsumb[i - 1] + dpb[i]) % mod;
    }

    for (int i = 1; i <= w + b; i++) {
	int ans = dpsumw[i - 1];
	if (i != w + b)
	    ans = (ans + 1ll * (1ll - dpsumb[i - 1] - dpsumw[i - 1] + mod + mod) % mod * rfac[2] % mod) % mod;
	cout << ans << endl;
    }
}

  


Measured memory_bytes: 14080
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long

using namespace std;

ll a,b,c,k;

il int gi(){
  RG int x=0,q=1; RG char ch=getchar();
  while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
  if (ch=='-') q=-1,ch=getchar();
  while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q*x;
}

int main(){
  cin>>a>>b>>c>>k;
  if (k&1) cout<<b-a;
  else cout<<a-b;
  return 0;
}


Measured memory_bytes: 764
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n;
    cin>>n;
    VL a(n);
    REP(i,n)cin>>a[i];
    VL b(n);
    VL ans;
    REP(i,n){
        LL index = n-1-i;
        LL sum = 0;
        for(int j = index*2 + 1; j < n; j += index+1){
            sum += b[j];
        }
        b[index] = sum % 2 == a[index] ? 0 : 1;
        if(b[index] == 1)ans.PB(index+1);
    }
    if(false){
        PUTS(-1);
        return 0;
    }
    PUTS(ans.size());
    REP(i,ans.size()){
        cout<<ans[i]<<" ";
    }
}

Measured memory_bytes: 5108
///Code by: Luis Alejandro
///Handle: Sekai
///Country: Cuba

#include <bits/stdc++.h>
#define endl '\n'
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")

using namespace std;

typedef unsigned long long ull;
typedef long long lld;
typedef long double ld;
typedef pair<int,int> pii;

const int MAXN=1e5+5;
const int MOD=1e9+7;
const int INF=INT_MAX;
const ld PI=acos(-1);
const ld EPS=1e-9;

#define lg2(x) 31-__builtin_clz(x)
#define logx(a,b) (log(a)/log(b))
#define read(x) cin>>x;

pii mkp(int a, int b){
    if(a>b)swap(a,b);
    return make_pair(a,b);
}

int mod_pow(int a, int b){
    if(!b)return 1;
    if(b&1)return mod_pow(a,b-1)*a%MOD;
    int power=mod_pow(a,b>>1);
    return power*power%MOD;
}

int modular_inverse(int a){
    return mod_pow(a,MOD-2);
}

void solve(){
    string s, t;
    cin>>s>>t;
    int cnt=0;
    for(int i=0;i<(int)s.length();i++){
        if(s[i]!=t[i])cnt++;
    }
    cout<<cnt<<endl;
}

int main()
{
    //freopen("IN.txt","r",stdin);
    //freopen("OUT.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
using namespace std;
#define TOPINDEX 1
#define DUMMYVALUE 0

void Insert(vector<int>& Heap, int k)
{
	Heap.push_back(k);
	int InsertIndex = Heap.size() - 1;
	int ParentIndex = (Heap.size() - 1) / 2;
	while(Heap[InsertIndex] > Heap[ParentIndex] && InsertIndex > TOPINDEX){
		swap(Heap[InsertIndex], Heap[ParentIndex]);
		InsertIndex = ParentIndex;
		ParentIndex = InsertIndex / 2;
	}
}

void maxHeapify(vector<int>& A, int i)
{
	int H = A.size() - 1;
	int l = 2 * i;
	int r = 2 * i + 1;
	//????????????????????????????????§???????????§????????????????????¶
	int largest;
	if(l <= H && A[l] > A[i]){
		largest = l;
	}else{
		largest = i;
	}
	if(r <= H && A[r] > A[largest]){
		largest = r;
	}
	//i???????????????????????§????????´???
	if(largest != i){
		swap(A[i], A[largest]);
		//?????°??????????????????
		maxHeapify(A, largest);
	}
}

void ExtractMax(vector<int>& Heap)
{
	int TailIndex = Heap.size() - 1;
	swap(Heap[TailIndex], Heap[TOPINDEX]);
	cout << Heap[TailIndex] << endl;
	Heap.pop_back();
	maxHeapify(Heap, TOPINDEX);
}

int main()
{
	/* ??????
	MaxHeap?????¢??§?????????
	1??????Exract????????????????????¨????°??????\????????????????°??????????????¶????
	??????????????????????????????MaxHeapify????????¨??????
	1??????Insert????????????????°????????????????????°???????????????????????????£??????????????????????????°??????
	(??????????????¨????????¢????????????????????????????????????????????§?????????)
	*/
	vector<int> Heap(1, DUMMYVALUE);
	while(true){
		string Command;
		cin >> Command;
		if(Command == "insert"){
			int k;
			cin >> k;
			Insert(Heap, k);
		}else if(Command == "extract"){
			ExtractMax(Heap);
		}else{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 6908
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int n;
vector<P>G[114514];
int b[114514];
void dfs(int x) {
	rep(i, G[x].size()) {
		if (G[x][i].first && !b[G[x][i].first]) {
			b[G[x][i].first] = b[x] + G[x][i].second;
			dfs(G[x][i].first);
		}
	}
}
signed main() {
	cin >> n;
	rep(i, n - 1) {
		int a, b, c; cin >> a >> b >> c;
		G[a - 1].push_back({ b - 1,c });
		G[b - 1].push_back({ a - 1,c });
	}
	dfs(0);
	rep(i, n) {
		cout << b[i] % 2 << endl;
	}
}

Measured memory_bytes: 10496
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n, x;
	cin >> n >> x;
	vector<int> m(n);
	int sumv=0, minv = INF, ans;
	rep(i, 0, n) {
		cin >> m[i];
		sumv+= m[i];
		minv = min(minv, m[i]);
	}
	ans=n+(x-sumv) / minv;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque

N = int(input())

es = [[] for _ in range(N)]
# 戻って塗らないので a->bだけ記録
for i in range(N-1):
    a,b = map(int, input().split())
    es[a-1].append((i, b-1))


ans = [0] * (N-1)
c = 1
prev_c = -1
"""
現在ノード、そこに至るための直前の辺の色を知っておく必要がある
q : (current_node, prev_color)
今見てるノードと、そこに来る直前のへんが何色かを示す
"""
q = deque()
q.append((0, prev_c))
while q:
    curr_node, pc = q.popleft()
    c = 1
    for edge_num, node in es[curr_node]:
        if c == pc:
            c += 1
        ans[edge_num] = c
        # 次確認するノードがnodeで、そこに至る直前の辺が色cでしたよ、を保存
        q.append((node, c))
        # curr_nodeに繋がる今のnodeの色と、のちのやつが被らないようにする
        c += 1

print(len(set(ans)))
print(*ans, sep="\n")



Measured memory_bytes: 29752
/*input
1000000
*/
#include <bits/stdc++.h>
using namespace std;
int l;
vector<pair<long long,long long>> v[25];
int main(){
	cin>>l;
	int n = 32 - __builtin_clz(l);
	for(int i=1;i<n;++i) v[i].push_back({i+1,0});
	for(int i=1;i<n;++i){
		v[i].push_back({i+1,1<<(n-i-1)});
	}
	int CNT = 0, run = l;
	for(int i=0;i<n-1;++i) if(l>>i&1){
		v[1].push_back({n-i,l - (1<<i)});
		l -= (1<<i);
	}
	for(int i=1;i<n;++i) CNT += v[i].size();
	cout<<n<<' '<<CNT<<'\n';
	for(int i=1;i<n;++i) for(auto p:v[i])
		cout<<i<<' '<<p.first<<' '<<p.second<<'\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

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

	ll x = 1000, y = 0, z = LINF;
	rep(i, n){
		x += y * max(z, a[i]);
		y = x / a[i];
		z = a[i];
		x -= y * z;
	}
	co(x + y * z);

	return 0;
}


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

void outputPeaks(int* height, int len) {
    for(int i=0; i<len; i++) {
        printf(" peak_%d: %d\n", i, height[i]);
    }
}

void outputRoutes(vector<vector<int>> r) {
    for(int i=0; i<r.size(); i++) {
        for( int j=0; j<r[0].size(); j++) {
            printf(" r_%d_%d: %d\n", i, j, r.at(i).at(j));
        }
    }
}

void outputPath(vector<vector<int>> h, int len) {
    for(int i=0; i<len; i++) {
        printf(" path_%d: %d -> %d\n", i, h.at(i).at(0), h.at(i).at(1));
    }
}

// いい展望台の数を出力
void checkNeoPeaks(int* peaks, int* neo_peaks, int len) {
    int cnt = 0;
    for(int i=0; i<len; i++) {
        if(!neo_peaks[i]) cnt++;
        else if(neo_peaks[i] == peaks[i]) cnt++;
    }
    cout << cnt << endl;
}

void updatePeaks(int* peaks, int* neo_peaks, int len_np, vector<vector<int>> routes) {
    for(int i=0; i<routes.size(); i++) {
        for(int j=0; j<routes.at(0).size(); j++) {
            if(routes.at(i).at(j)) {
                if(neo_peaks[i] < peaks[j]) neo_peaks[i] = neo_peaks[j];
            }
        }
    }
}


int main() {
    int n, m;
    cin >> n >> m;
    int peaks[n] = {0};
    int neo_peaks[n] = {0};
    for(int i=0; i<n; i++) {
        cin >> peaks[i];
    }
    
    int a, b;
 //   vector<vector<int>> routes(n, vector<int>(n));
 //   vector<vector<int>> path(m, vector<int>(2));
    
    for(int i=0; i<m; i++) {
        cin >> a >> b;
 //       path.at(i).at(0) = a;
 //       path.at(i).at(1) = b;

//        routes.at(a-1).at(b-1) = 1;
        if(peaks[a-1] < peaks[b-1]) neo_peaks[a-1] = peaks[b-1];
        else if(peaks[a-1] == peaks[b-1]) neo_peaks[a-1] = -1;

//        routes.at(b-1).at(a-1) = 1;
        if(peaks[b-1] < peaks[a-1]) neo_peaks[b-1] = peaks[a-1];
        else if(peaks[b-1] == peaks[a-1]) neo_peaks[b-1] = -1;
//        updatePeaks(peaks, neo_peaks, n, routes);
    }
//    outputPeaks(peaks, n);
//    outputPath(path, m);
//    outputRoutes(routes);
//    outputPeaks(neo_peaks, n);
    checkNeoPeaks(peaks, neo_peaks, n);
    return 0;
}


Measured memory_bytes: 4360
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=X[:]
Y=X[:]
YY=X[:]
P=[]
SC=0
N,M,L,O=0,0,0,0
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  N,M=-1,-10**20
  L,O=N,M
  for j in range(26):
    if Y==-1:
      N,M=0,X[0]+S[i][0]
    if M<X[j]+S[i][j]:
      L,O=N,M
      N,M=j,X[j]+S[i][j]
    elif O<X[j]+S[i][j]:
      L,O=j,X[j]+S[i][j]
  XX[N]-=X[N]
  X[N]=0
  P.append([N,L])
  SC+=X[N]
SC2=0
for i in range(30):
  for d in range(D):
    for q in range(26):
      SC2=SC
      SC2-=S[d][P[d][0]]
      SC2+=S[d][q]
      for j in range(26):
        Y[j]=0
      YY[P[d][0]],YY[q]=0,0
      for j in range(D):
        if j==d:
          Z=q
        else:
          Z=P[j][0]
        Y[P[d][0]]+=C[P[d][0]]
        Y[q]+=C[q]
        Y[Z]=0
        YY[P[d][0]]+=Y[P[d][0]]
        YY[q]+=Y[q]
      if SC2-sum(YY)>=SC-sum(XX):
        P[d][0]=q
        XX=YY[:]
        SC=SC2
for i in range(D):
  SC2=SC
  d,q=i,P[i][1]
  SC2-=S[d][P[d][0]]
  SC2+=S[d][q]
  for j in range(26):
    Y[j]=0
  YY[P[d][0]],YY[q]=0,0
  for j in range(D):
    if j==d:
      Z=q
    else:
      Z=P[j][0]
    Y[P[d][0]]+=C[P[d][0]]
    Y[q]+=C[q]
    Y[Z]=0
    YY[P[d][0]]+=Y[P[d][0]]
    YY[q]+=Y[q]
  if SC2-sum(YY)>=SC-sum(XX):
    P[d]=P[d][::-1]
    XX=YY[:]
    SC=SC2
for i in range(D):
  print(P[i][0]+1)

Measured memory_bytes: 84648
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=200000+19;
const int p=1e9+7;

int Pow(int a,int b){
	int res=1;
	for (;b;b>>=1,a=1ll*a*a%p) if (b&1) res=1ll*res*a%p;
	return res;
}

int fac[N],inv[N];
int n,m,A,B,ans;

int C(int n,int m){
	return 1ll*fac[n]*inv[m]%p*inv[n-m]%p;
}

int main(){
	fac[0]=1;
	For(i,1,N) fac[i]=1ll*fac[i-1]*i%p;
	inv[N-1]=Pow(fac[N-1],p-2);
	for (int i=N-1;i;i--) inv[i-1]=1ll*inv[i]*i%p;
	n=IN(),m=IN(),A=IN(),B=IN();
	For(i,1,n-A+1){
		ans=(ans+1ll*C(i+B-2,i-1)*C(n+m-B-i-1,n-i))%p;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		StringBuilder builder = new StringBuilder();
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			List<Integer> list = new ArrayList<Integer>();
			for (int i = 1; i < n - 1; i++) {
				int a = i * i % n;
				if (!list.contains(a)) {
					list.add(a);
				}
			}
			int[] num = new int[(n + 1) / 2];
			for (int i = 0; i < list.size(); i++) {
				for (int j = 0; j < list.size(); j++) {
					if (i != j) {
						int t = list.get(i) - list.get(j);
						if (t < 0) {
							t += n;
						}
						if (t > (n - 1) / 2) {
							t = n - t;
						}
						num[t]++;
					}
				}
			}
			for (int i = 1; i < num.length; i++) {
				System.out.println(num[i]);
			}

		}
	}
}

Measured memory_bytes: 28120
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

using ll = long long int;
using namespace std;

int main(){

  ll N;
  cin >> N;

  // prepare table
  vector<string> S3(3), S4(4), S5(5), S6(6), S7(7);

  S3[0] = "aa.";
  S3[1] = "..b";
  S3[2] = "..b";

  S4[0] = "aabc";
  S4[1] = "ddbc";
  S4[2] = "efgg";
  S4[3] = "efhh";

  S5[0] = ".aabc";
  S5[1] = "dd.bc";
  S5[2] = "f.iie";
  S5[3] = "f.j.e";
  S5[4] = "ggjkk";

  S6[0] = "aa.dde";
  S6[1] = "bbc..e";
  S6[2] = "..cfgg";
  S6[3] = "..jfh.";
  S6[4] = "..j.hi";
  S6[5] = "kkll.i";

  S7[0] = "aadee..";
  S7[1] = "bbd.i..";
  S7[2] = "ccffi..";
  S7[3] = "..gh.jj";
  S7[4] = "..gh.kk";
  S7[5] = "....lmn";
  S7[6] = "....lmn";

  // solve problem
  // N == 2
  if(N == 2){
    cout << "-1" << endl;
  }
  // N%3 == 0
  else if(N%3 == 0){
    for(ll i = 0; i < N/3; i++){
      for(ll j2 = 0; j2 < 3; j2++){
        for(ll j = 0; j < N/3; j++){
        
          if(i == j){
            cout << S3[j2];
          }
          else{
            cout << "...";
          }
          
        }cout << endl;
      }
    }
  }
  // N == 4
  else if(N == 4){
    for(ll i = 0; i < 4; i++){
      cout << S4[i] << endl;
    }
  }
  // N == 5
  else if(N == 5){
    for(ll i = 0; i < 5; i++){
      cout << S5[i] << endl;
    }
  }
  // N == 7
  else if(N == 7){
    for(ll i = 0; i < 7; i++){
      cout << S7[i] << endl;
    }
  }
  // N == 8
  else if(N == 8){
    for(ll i = 0; i < 4; i++){
      cout << S4[i] << "...." << endl;
    }
    for(ll i = 0; i < 4; i++){
      cout << "...." << S4[i] << endl;
    }
  }
  // N == 10
  else if(N == 10){
    for(ll i = 0; i < 5; i++){
      cout << S5[i] << "....." << endl;
    }
    for(ll i = 0; i < 5; i++){
      cout << "....." << S5[i] << endl;
    }
  }
  // N == 11
  else if(N == 11){
    for(ll i = 0; i < 4; i++){
      cout << S4[i] << "......." << endl;
    }
    for(ll i = 0; i < 7; i++){
      cout << "...." << S7[i] << endl;
    }
  }
  // N == 13
  else if(N == 13){
    for(ll i = 0; i < 6; i++){
      cout << S6[i] << "......." << endl;
    }
    for(ll i = 0; i < 7; i++){
      cout << "......" << S7[i] << endl;
    }
  }
  // other general case
  else{
    ll i1, i2;
    i1 = N%4;
    i2 = (N-5*i1)/4;
    for(ll i = 0; i < i1; i++){
      for(ll j = 0; j < 5; j++){
        for(ll k = 0; k < i; k++){
          cout << ".....";
        }
        cout << S5[j];
        for(ll k = (i+1)*5; k < N; k++){
          cout << ".";
        }
        cout << endl;
      }
    }
    for(ll i = 0; i < i2; i++){
      for(ll j = 0; j < 4; j++){
        for(ll k = 0; k < i1; k++){
          cout << ".....";
        }
        for(ll k = 0; k < i; k++){
          cout << "....";
        }
        cout << S4[j];
        for(ll k = i+1; k < i2; k++){
          cout << "....";
        }
        cout << endl;
      }
    }

  }


  

  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    ll S;
    cin >>S;
    ll ans=0;

    rep2(i,S){
        ll A=S-3*i;
        if(A>=0){
            ans=(ans+COM(A+i-1,i-1))%mod;
        }
    }

    /*vector<vector<ll>>dp(S+1,vector<ll>(S+1));
    vector<vector<ll>>num(S+1,vector<ll>(S+1));
    dp[0][0]=1;
    rep3(i,3,S){
        rep3(j,3,S+1){
            if(j-i>=0){
                dp[i+1][j]=dp[i][j-i]*num;
                dp[i+1][j]=dp[i+1][j-i]*num/;
            }else{
                dp[i+1][j]=dp[i][j];
            }
            
        }
    }*/
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 15560
#include <iostream>

using namespace std;

int main(){
	int h, r;

	cin >> h >> r;

	if ((h + r) == 0){
		cout << "0" << endl;
	}
	else if ((h + r) > 0){
		cout << "1" << endl;
	}
	else {
		cout << "-1" << endl;
	}
}

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

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

template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}

int main(){
    string S; cin >> S;
    int s_len = S.size();
    vector<int> a;
    rep(i, s_len) {
        char temp = S[i];
        a.push_back(temp - '0');
    }
    // view(a);
    int sum = a[0];
    // vector<char> temp;
    // temp.push_back(S[0]);
    string temp;
    temp += S[0];
    bool found = false;
    for (int bit = 0; bit < (1<<(s_len-1)); bit++) {
        // view(bitset<3>(bit));
        // view(bitset<3>(bit));
        for (int i = 1; i < s_len; i++) {
            if ((bit>>(i-1)) & 1) {
                sum += a[i];
                temp += "+";
                temp += to_string(a[i]);
            } else {
                sum -= a[i];
                temp += "-";
                temp += to_string(a[i]);
            }
        }
        // view(temp);
        // view(sum);
        if (sum == 7) {
            found = true;
            view(temp + "=7");
            return 0;
        }
        temp = S[0];
        sum = a[0];
    }
    if (!found) cout << "Not found." << endl;
    
    return 0;
}

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

long long base = 257;
string S; long long hush[600000], hushmod = 1000000007, mod = 1000000007, minx = 999999; bool OK[600000], res[600000];
vector<long long>y[600000]; long long power256[1000000];

class RollingHash {
private:
	std::string str;
	std::vector<int> power;
	std::vector<int> sum;
public:
	RollingHash() : str(""), sum(std::vector<int>(1, 0)) {};
	RollingHash(const std::string &s) : str(s) {
		sum.resize(str.size() + 1);
		power.resize(str.size() + 1); power[0] = 1;
		for (int i = 0; i < str.size(); i++) sum[i + 1] = (1LL * sum[i] * base + s[i]) % mod;
		for (int i = 0; i < str.size(); i++) power[i + 1] = 1LL * power[i] * base % mod;
	}
	std::string get() { return str; }
	int gethash(int l, int r) {
		return (sum[r] - 1LL * sum[l] * power[r - l] % mod + mod) % mod;
	}
};

long long modpow(long long a, long long b, long long m) {
	if (a == 256 && b < 1000000)return power256[b];
	long long p = 1, q = a;
	for (int i = 0; i < 40; i++) { if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }q *= q; q %= m; }
	return p;
}
long long Div(long long a, long long b, long long m) { return (a*modpow(b, m - 2, m)) % m; }
vector<long long>solve(string U) {
	RollingHash V(U);
	vector<long long>cnt;
	for (int i = 0; i <= U.size(); i++)OK[i] = true;
	long long r3 = 0, r4 = 1;
	for (int i = 1; i <= U.size(); i++) { r3 += r4*U[i - 1]; r3 %= hushmod; hush[i] = r3; r4 *= 256; r4 %= hushmod; }
	for (int i = 0; i < U.size() - 1; i++) {
		int E = i + 1; bool T = false;
		for (int j = 0; j < y[E].size(); j++) {
			if (OK[y[E][j]] == false)continue;

			long long n1 = V.gethash(E - y[E][j], E);
			long long n2 = 0; if (E != y[E][j]) n2 = V.gethash(E - y[E][j] * 2, E - y[E][j]);
			if (E != y[E][j] && n1 != n2)OK[y[E][j]] = false;

			if (OK[y[E][j]] == true && E != y[E][j])T = true;
		}
		if (T == true)cnt.push_back(i);
	}
	return cnt;
}
int main() {
	cin >> S;
	power256[0] = 1; for (int i = 1; i < 1000000; i++) { power256[i] = (power256[i - 1] * 256LL) % mod; }
	for (int i = 1; i <= S.size(); i++) { for (int j = i; j <= S.size(); j += i) { y[j].emplace_back(i); } }
	for (int i = 1; i <= S.size(); i++) {
		if (S.size() % i >= 1)continue;bool OK = true;
		for (int j = i; j < S.size(); j++) { if (S[j] != S[j - i])OK = false; }
		if (OK == true) { minx = min(minx, (long long)i); break; }
	}
	if (minx == 1) { cout << S.size() << endl << "1" << endl; }
	else if (minx == S.size()) { cout << "1 1" << endl; }
	else {
		long long ret1 = 1; if (minx < S.size())ret1 = 2;
		string T = S;
		vector<long long>R1 = solve(T); for (int i = 0; i < R1.size(); i++)res[R1[i]] = true; reverse(T.begin(), T.end());
		vector<long long>R2 = solve(T); for (int i = 0; i < R2.size(); i++)res[S.size() - 2 - R2[i]] = true;
		if (S.size() / minx >= 3) { for (int i = minx - 1; i < S.size() - 1; i += minx) { res[i] = true; } }
		int ans = 0; for (int i = 0; i < S.size() - 1; i++) { if (res[i] == false)ans++; }
		cout << ret1 << endl << ans << endl;
	}
	return 0;
}

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

int dp[1001][1001];
int W, N;
int w[1000];
int v[1000];
int solve(){
    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            if(j < w[i]) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
        }
    }
    return dp[N][W];
}
int main(){
    char comma;
    int count=0;
    while(cin >> W && W){
        count++;
        cin >> N;
        for(int i=0;i<N;i++){
            cin >> v[i] >> comma >> w[i];
        }
        for(int j=0;j<W;j++){
            dp[0][j] = 0;
        }
        cout << "Case " << count << ':' << endl;
        cout << solve() << endl;
        for(int j=W-1;j>=0;j--){
            if(dp[N][j] < dp[N][W]){
                cout << j+1 << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 5080
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

int main() {

	int n;
	cin >> n;
	string s;
	cin >> s;

	vector<int> cnt(26, 0);
	for (int i = 0; i < n; i += 2) {
		cnt[s[i] - 'a']++;
	}

	int variousNum = 0;
	for (int i = 0; i < 26; i++) {
		if (cnt[i] >= 2)
			variousNum++;
	}

	vector<vector<int>> num(11, vector<int>());
	for (int i = 0; i < 26; i++) {
		num[cnt[i]].push_back(i);
	}

	string ans = "";

	for (int i = 1; i < 10; i++) {
		if ((int)num[i].size() == 0) continue;
		if (i == 1) {
			// 単独で書いた方がいい
			for (int j = 0; j < (int)num[i].size(); j++) {
				char tmp = num[i][j] + 'a';
				ans += tmp;
				ans += '+';
			}
		}
		else {
			//まとめてかく
			if ((int)num[i].size() >= 2) {
				ans += '(';
				for (int j = 0; j < (int)num[i].size(); j++) {
					char tmp = num[i][j] + 'a';
					ans += tmp;
					if(j != (int)num[i].size() - 1)
						ans += '+';
				}
				ans += ')';
				ans += '*';
				ans += i;
				ans += '+';
			}
			else {
				ans += num[i][0];
				ans += '*';
				ans += i;
				ans += '+';
			}
		}
	}

	cout << ans.size() - 1 << endl;

	return 0;
}


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

using ll = int64_t;

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

const int MAX = 1'000'000 + 7;
bool isPrime[MAX];
int minFactor[MAX];
void preprocess(int n = MAX) {
  rep(i, n) isPrime[i] = true, minFactor[i] = -1;
  isPrime[0] = false; isPrime[1] = false; 
  minFactor[0] = 0; minFactor[1] = 1;
  srep(i, 2, n) {
    if (!isPrime[i]) continue;
    minFactor[i] = i;
    for (int j = i*2; j < n; j += i) {
      isPrime[j] = false;
      if (minFactor[j] == -1) minFactor[j] = i;
    }
  }
}

int modinv(int a, int m=mod) {
    int b = m, u = 1, v = 0;
    while (b) {
        int t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

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];
  preprocess();
  map<ll, ll> primeCnt;
  rep(i, n) {
    ll tmp = a[i];
    map<ll, ll> cnt;
    while (tmp != 1) {
      cnt[minFactor[tmp]]++;
      tmp /= minFactor[tmp];
    }
    for (auto &p : cnt) chmax(primeCnt[p.first], p.second);
  }
  for (auto &p : primeCnt)
    primeCnt[p.first] %= mod;
  ll gcm = 1;
  for (auto &p : primeCnt)
    rep(i, p.second) gcm = (gcm * p.first) % mod;
  ll ans = 0;
  rep(i, n) {
    ll val = (gcm * modinv(a[i])) % mod;
    ans = (ans + val) % mod;
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 5760
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v)
    is >> x;
  return is;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int N = 200010;

ll a[N];
int b[N];
ll sb[N], sb1[N], sb2[N];

int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  int pos = max_element(a, a + n) - a;
  rotate(a, a + pos, a + n);
  rotate(b, b + pos, b + n);
  a[n] = a[0];
  b[n] = b[0];
  for (int i = 1; i <= n; ++i) {
    sb[i] = sb[i - 1] + b[i];
    sb1[i] = sb1[i - 1] + b[i] * (ll)i;
    sb2[i] = sb2[i - 1] + b[i] * (ll)i * i;
  }
  auto weight = [&](int L, int R) {
    double ret = 0;
    int len = R - L;
    ret += a[L] * (len - 1.) / 2;
    ret += a[R] * (len + 1.) / 2;
    ret += (sb2[R] - sb2[L]);
    ret -= (sb1[R] - sb1[L]) * (L + R);
    ret += (sb[R] - sb[L]) * L * R;
    return ret;
  };
  vector<int> stk;
  for (int i = 0; i <= n; ++i) {
    while (stk.size() >= 2) {
      int y = stk.back(); stk.pop_back();
      int x = stk.back(); stk.pop_back();
      if (weight(x, y) + weight(y, i) < weight(x, i)) {
        stk.push_back(x);
      } else {
        stk.push_back(x);
        stk.push_back(y);
        break;
      }
    }
    stk.push_back(i);
  }
  double ans = 0;
  for (int i = 1; i < stk.size(); ++i)
    ans += weight(stk[i - 1], stk[i]);
  printf("%.10f\n", ans / n);

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

int main(void){
  int N, M;
  cin >> N >> M;
  int sum = 0, count = 0;
  vector<int> p(M);
  vector<int> AC(N, 0);
  vector<int> WA(N, 0);
  
  for(int i = 0; i < M; i++){
    string judge = "";
  	cin >> p[i] >> judge;
    if(judge == "AC"){
      AC[p[i] - 1] = 1;
    }
    else if(judge == "WA") {
      if(AC[p[i] - 1] != 1){
    	WA[p[i] - 1] += 1;
      }
    }
  }
  for(int i = 0; i < N; i++){
    //cout << AC[i] << ", " << WA[i];
    count += AC[i];
    if(AC[i] == 1){
      sum += WA[i];
    }
  }
  
  cout << count << " " << sum << endl;
 return 0; 
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#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 loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
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 (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N; cin >> N;
  vector<int> a(N); rep(i, 0, N){ cin >> a[i]; }
  sort(all(a));
  cout<<a[N-1]-a[0]<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;

int main(){
  int m, n, s, i;
  char no[100];
  while(cin >> m >> n, m != 0 || n != 0) {
    queue<int> q;
    for(int j = 0; j < m; j++) q.push(j+1);
    i = 1;
    while(n--) {
      if(q.size() != 1) {
	cin >> no;
	int p = q.front(); q.pop();
	if(i%3 == 0 && i% 5 == 0) {
	  if(strcmp(no, "FizzBuzz") == 0) q.push(p);
	}
	else if(i % 3 == 0 && strcmp(no,"Fizz") == 0) q.push(p);
	else if(i % 5 == 0 && strcmp(no ,"Buzz") == 0)  q.push(p);
	else if(i % 3 != 0 && i % 5 != 0 && i == atoi(no)) q.push(p);
	i++;
      }
      else cin >> no;
    }
    
    vector<int> v(1050);
    while(q.size()) {
      v.push_back(q.front());
      q.pop();
    }
    sort(v.begin(), v.end());
    while(v.size()) {
      if(v[0]) {
	cout << v[0];
	if(v.size() - 1) cout << ' ';
      }
      v.erase(v.begin());
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1252
k = [list(map(int, list(input().split()))) for i in range(3)]

for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            if (k[0][0] - a1) == (k[0][1] - a2) == (k[0][2] - a3):
                if (k[1][0] - a1) == (k[1][1] - a2) == (k[1][2] - a3):
                    if (k[2][0] - a1) == (k[2][1] - a2) == (k[2][2] - a3):
                        if k[0][0] - a1 >= 0 and k[0][1] - a2 >= 0 and k[0][2] - a3 >= 0:
                            if (k[1][0] - a1) >= 0 and (k[1][1] - a2) >= 0 and (k[1][2] - a3) >= 0:
                                if (k[2][0] - a1) >= 0 and (k[2][1] - a2) >= 0 and (k[2][2] - a3) >= 0:
                                    print("Yes")
                                    exit()

print("No")

Measured memory_bytes: 3064