akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
#define N 400000
int a[N], b[N], n;
long long bt[N];
void add(int x, int v){
        x++;
        for (int i = x; i > 0; i -= i & -i)
                bt[i] += v;
}
long long que(int x){
        long long ret = 0;
        x++;
        for (int i = x; i <= 2 * n; i += i & -i)
                ret += bt[i];
        return ret;
}
int main(){
        ios_base::sync_with_stdio(false);
        cin >> n;
        for (int i = 0; i < n; i++)
                cin >> a[i] >> b[i];
        for (int i = 0; i < n; i++){
                add(i, a[i]);
                add(i - 1, -a[i]);
        }
        long long ans = 0;
        for (int i = n - 1; i >= 0; i--){
                long long tmp = que(i);
                tmp = tmp % b[i];
                if (tmp) tmp = b[i] - tmp;
                add(i - 1, tmp);
                ans += tmp;
        }
        cout << ans << '\n';
        return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string.h>
using namespace std;
 
struct Disc{
    int x,y,r,c;
    Disc(int p_x,int p_y,int p_r,int p_c){
        x=p_x;y=p_y;r=p_r;c=p_c;
    }
    Disc(){};
};
 
int n;
char memo[1<<24];
bool exist[24];
Disc D[24];
int ans;
 
bool touch(Disc a,Disc b){
    return (a.r+b.r)*(a.r+b.r)>(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
 
bool top(int k){
    for(int i=k-1;i>=0;i--){
        if(exist[i]){
            if(touch(D[k],D[i])){return false;}
        }
    }
    return true;
}
 
int dfs(int bit,int num){
    if(memo[bit]>=0) return memo[bit];
    int res=num;
 
    for(int i=0;i<n;i++){
        if(exist[i] && top(i)){
            for(int j=i+1;j<n;j++){
                if(exist[j] && top(j) && i!=j && D[i].c==D[j].c){
                    exist[i]=false;
                    exist[j]=false;
                    res=dfs((bit&(~(1<<i)))&(~(1<<j)),num+2);
                    exist[i]=true;
                    exist[j]=true;
                }
            }
        }
    }
    memo[bit]=res;
    ans=max(ans,res);
    return res;
}
 
int main()
{
    while(cin>>n && n!=0){
        ans=0;
        memset(memo,-1,sizeof(memo));
        memset(exist,true,sizeof(exist));
        for(int i=0;i<n;i++){
            int x,y,r,c;
            cin>>x>>y>>r>>c;
        D[i]=Disc(x,y,r,c);
        }
        ans=0;
        dfs((1<<24)-1,0);
        cout<<ans<<endl;
    }
    return 0;
}

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

int main() {
  long long n;
  cin>>n;
  long long ans=0;
  vector<long long>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  vector<int>b(n);
  vector<int>c(n);
  for(int i=0;i<n;i++) b[i]=a[i]+i;
  for(int i=0;i<n;i++) c[i]=i-a[i];
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  long long i=0;
  long long j=1;
  while(i<n && j<n){
    long long num1=0;
    long long num2=0;
    long long d=b[i];
    while(i<n){
      if(b[i]==d) num1++;
      else break;
      i++;
    }
    while(j<n){
      if(c[j]>d) break;
      else if(c[j]==d) num2++;
      j++;
    }
    ans+=num1*num2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6396
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;

using namespace std;
char ch[5][5];
int main()
{
    for(int i = 0; i < 2; i++)
    cin >> ch[i];
    int sum = 0;
    for(int i = 0; i < 2; i++)
    for(int j = 0; j < 3; j++)
    {
        if(ch[i][j] == ch[1-i][2-j])sum++;
    }
    if(sum == 6)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
static int D[10]; 
bool check(int n){
	int num=n;
	while(n){
		if(D[n%10]==1)	return true;
		n/=10;
	}
	cout<<num<<endl;
	return false;
}
int main()
{
	int N,K;
	int num;
	cin>>N>>K;
	for(int i=1;i<=K;i++){
		int num;
		cin>>num;
		D[num]=1;
	}
	num=N;
	while(check(num)){
		num++;
	}
		
}


Measured memory_bytes: 256
H,W = list(map(int,input().split()))
table = []
for i in range(H):
    table.append(list(input()))
for i in range(H):
    for j in range(W):
        A = table[i][j]
        if A == "#":
            try:
                if table[i-1][j] == "#":
                    continue
            except IndexError:
                pass
            try:
                if table[i+1][j] == "#":
                    continue
            except IndexError:
                pass
            try:
                if table[i][j-1] == "#":
                    continue
            except IndexError:
                pass
            try:
                if table[i][j+1] == "#":
                    continue
            except IndexError:
                pass
            print("No")
            exit()
        else:
            continue
print("Yes")

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define TMP 1000000007

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main() {
	string s;
	int a, z;
	cin >> s;
	rep(i, s.size()) {
		if(s[i] == 'A') {
			a = i;
			break;
		}
	}
	repr(i, s.size() - 1) {
		if(s[i] == 'Z') {
			z = i;
			break;
		}
	}
	printf("%d\n", z - a + 1);
	return 0;
} 

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

const ll MX = 1e18;

int main(){
  //整数をN個もらうが、積の合計が10^18を超えると-1を表示
  int n;
  cin >> n;
  ll ans = 1;
  bool ng = false;
  for (int i = 0; i < n;i++){
    ll a;
    cin >> a;
    if (a == 0){
      cout << 0 << endl;
      return 0;
    }
    if ( ng || (MX+1)/ans < a || ans*a > MX){
      ng = true;
    }
    ans *= a;
  }
  if (ng) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n,m;
	cin>>n>>m;
	vector<ll> vec(n+1,0);
	for(ll i=1;i<=n;i++){
		cin>>vec[i];
	}
	vector<vector<ll> > vec2(n+1);
	map<ll,ll> map;
	for(ll i=1;i<=m;i++){
		ll u,v;
		cin>>u>>v;
		vec2[u].push_back(vec[v]);
		vec2[v].push_back(vec[u]);
	}
	
	for(ll i=1;i<=n;i++){
		sort(vec2[i].begin(),vec2[i].end());
		reverse(vec2[i].begin(),vec2[i].end());
	}
	
	for(ll i=1;i<=n;i++){
		if(vec2[i].size()==0||vec[i]>vec2[i][0]){
			map[i]=1;
		}
	}
	cout<<map.size()<<endl;
}


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

public class Main {
	static class Person{
		int x[];
		int y[];
		Person(int N){
			x = new int[N];
			y = new int[N];
		}
	}
	static boolean can(Person ps[] , int bit){
		int N = ps.length;
		int bs[] = new int[N];
		for(int i = 0 ; i < N ; ++i){
			bs[i] = (bit & (1 << i) ) == 0 ? 0 : 1;
		}
//		System.out.println(Arrays.toString(bs));
		for(int i = 0 ; i < N ; ++i){
			Person p = ps[i];
			int py = bs[i];
			for(int a = 0 ; a < p.x.length ; ++a){
				int x = p.x[a];
				int y = p.y[a];
				if(py == 0){
					
				}else{
					if(bs[x] == y){
						
					}else{
						return false;
					}
				}
			}
		}
		return true;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Person ps[] = new Person[N];
		for(int i = 0 ; i < N ; ++i){
			int A = sc.nextInt();
			Person p = new Person(A);
			for(int a = 0 ; a < A ; ++a){
				p.x[a] = sc.nextInt() - 1;
				p.y[a] = sc.nextInt();
			}
			ps[i] = p;
		}
		int ret = 0;
		for(int bit = 0 ; bit < (1 << N) ; ++bit){
			if(can(ps , bit)){
//				System.out.println(bit);
				ret = Math.max(ret, Integer.bitCount(bit));
			}
		}
		System.out.println(ret);
	}
}


Measured memory_bytes: 24660
#include <map>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

map<vector<int>, int> m;
vector<vector<int> > mp;

int getMax(vector<int> &p, int sum)
{
	int a;
	if (m.find(p) != m.end()){
		return (m[p]);
	}
	
	if (sum < 10){
		return (m[p] = 0);
	}
	
	a = 0;
	for (int i = 0; i < (int)mp.size(); i++){
		vector<int> c = p;
		bool flag;
		flag = true;
		
		for (int j = 1; j < (int)mp[i].size(); j++){
			c[j] -= mp[i][j];
			if (c[j] < 0){
				flag = false;
				break;
			}
		}
		
		if (flag == true){
			a = max(a, 1 + getMax(c, sum - 10));
		}
	}
	
	return (m[p] = a);
}


void make(vector<int> &t, int n, int lim)
{
	if (lim == 0 || n == 10){
		if (!lim){
			mp.push_back(t);
			m[t] = 1;
		}
		return;
	}
	
	for (int i = 0; i * n <= lim; i++){
		vector<int> tn = t;
		tn.push_back(i);
		make(tn, n + 1, lim - i * n);
	}
	
	return;
}

int main(void)
{
	int n;
	int ans;
	vector<int> num(10);
	vector<int> t;
	
	t.push_back(0);
	make(t, 1, 10);
	
	while (scanf("%d", &n) && n){
		
		fill(num.begin(), num.end(), 0);
		
		for (int i = 0; i < n; i++){
			int t;
			scanf("%d", &t);
			num[t]++;
		}
		
		ans = 0;
		
		for (int i = 1; i <= 4; i++){
			int m = min(num[i], num[10 - i]);
			ans += m;
			num[i] -= m; num[10 - i] -= m;
		}
		ans += num[5] / 2; num[5] %= 2;
		
		int s = 0;
		for (int i = 1; i <= 9; i++){
			s += i * num[i];
		}
		
		printf("%d\n", ans + getMax(num, s));
	}
	
	return (0);
}

Measured memory_bytes: 20492
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double pi = Math.PI;
        double area = r*r*pi;
        double length = 2*r*pi;
        System.out.printf("%f %f",area,length);
    }
}


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

int main(){
    int n;
    cin >> n;
    long long ans = 0;
    int N = n-1;
    // 積が n-1 以下の掛け算の個数を求める O(n log n)
    for(int a = 1; a < n; a++){
        ans += N / a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3664
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>

#define PI 3.1415926
void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
void dainyu(int X[], int Y[ ],int n,int m) {
	for (int i = n; i <= m; i++) {
		Y[i] = X[i];
	}
}
void Dscanf(int X[], int n, int m) {
	for (int i = n; i <= m;i++) {
		scanf("%d", &X[i]);
	}
}
void Dprintf(int X[], int n, int m) {
	for (int i = n; i <= m; i++) {
		printf("%d\n", X[i]);
	}
}
void reverse(int X[], int Y[],int n,int m) {
	for (int i = n; i <= m; i++) {
		Y[i] = X[n + m - i];
	}
}

int factorial(int n);
int sum(int n, int*);
int ave(int n, int*);
int min(int n, int*), min(int n, int m);
int max(int n, int*), max(int n, int m);

int main() {
	int N, M, D;
	char x[200][200];
	scanf("%d %d %d", &N, &M,&D);
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			scanf(" %c", &x[i][j]);
		}
	}
	/*
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			printf("%c", x[i][j]);
		}
		printf("\n");
	}
	*/
	int ans=0;
	int flag = 0;
	for (int i = 1; i <= N;i++) {
		for (int j = 1; j <= M; j++) {
			flag = 0;
			if (i <= N - D + 1) {
				for (int k = 0; k < D; k++) {
					if (x[i + k][j] == '#') {
						flag = 1;
						break;
					}
				}
				if (flag == 0)ans++;
			}
			flag = 0;
			if (j <= M - D + 1) {
				for (int k = 0; k < D; k++) {
					if (x[i][j + k] == '#') {
						flag = 1;
						break;
					}
				}
				if (flag == 0)ans++;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}
int sum(int n, int *all) {
	int total = 0;
	for (int i = 0; i < n; ++i) {
		total += all[i];
	}
	return total;
}
int ave(int n, int *all) {
	int total = 0;
	for (int i = 0; i<n; ++i) {
		total += all[i];
	}
	return total / n;
}
int min(int n, int *all) {

	int min = all[1];
	for (int i = 2; i <= n; ++i) {
		if (min > all[i]) {
			min = all[i];
		}
	}
	return min;
}
int max(int n, int *all) {
	int max = all[1];
	for (int i = 2; i<=n; ++i) {
		if (max<all[i]) {
			max = all[i];
		}
	}
	return max;
}
int max(int n, int m) {
	if (n >= m) {
		return n;
	}
	else {
		return m;
	}
}
int min(int n, int m) {
	if (n >= m) {
		return m;
	}
	else {
		return n;
	}
}

Measured memory_bytes: 2724
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int n, d;
  cin >> n >> d;
  cout << (n + 2 * d) / (2 * d + 1) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

const int MAXN = 50;
bool visited[MAXN];


int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    //e.resize(n);
    REP(i,m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    int res = 0;
    REP(i,m){
        REP(j,n){
            visited[j]=false;
        }
        vector<vector<int>> e(n);
        REP(j,m){
            if(j!=i){
                e[a[j]].push_back(b[j]);
                e[b[j]].push_back(a[j]);
            }
        }
        queue<int> q;
        q.push(0);
        while(!q.empty()){
            int p = q.front();q.pop();
            visited[p]=true;
            REP(j,e[p].size()){
                if(!visited[e[p][j]]){
                    q.push(e[p][j]);
                }
            }
        }
        bool flag = true;
        REP(j,n){
            flag = flag&&visited[j];
        }
        if(!flag){
            res++;
        }
    }
    put(res);
    return 0;
}


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

using namespace std;

int main() {
	long long N, K;
	cin >> N >> K;
	if (N >= K) {
		N = N % K;
	}
	long long N_ = K - N;
	if (N == 0) {
		cout << N << endl;
	}
	else {
		if (N_ < N) {
			cout << N_ << endl;
		}
		else {
			cout << N << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 105
using namespace std;
typedef pair<int,int> P;
int n,a,b,c,d,ans[N],cnt,prevx;
P x[N];

int main(){
  cin>>n;
  for(int i=0;i<n;i++)x[i].second=i+1;
  for(int i=0;i<n*(n-1)/2;i++){
    cin>>a>>b>>c>>d;
    if(c==d)x[a-1].first++,x[b-1].first++;
    else if(c<d)x[b-1].first+=3;
    else x[a-1].first+=3;
  }
  sort(x,x+N,greater<P>());
  cnt=1;
  prevx=x[0].first;
  for(int i=0;i<n;i++){
    if(prevx>x[i].first){
      cnt=i+1;
      prevx=x[i].first;
    }
    ans[x[i].second-1]=cnt;
  }
  for(int i=0;i<n;i++)
    cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 1164
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //Compute c1 = new Compute();//計算系
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //int answer = 0;
        //String answer="No";
        //StringBuilder answer=new StringBuilder();

        //入力
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[]=new int[n];
        for (int i=0;i<n;++i)  a[i]=sc.nextInt();

        int b[]=new int[n];
        System.arraycopy(a,0,b,0,n);
        Arrays.sort(b);
        int bMax=b[n-1];
        int bnMax=b[n-2];
        for (int i=0;i<n;++i)
        {
            if (a[i]==bMax) System.out.println(bnMax);
            else System.out.println(bMax);
        }

        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        //System.out.println(answer);
    }
}

Measured memory_bytes: 114196
# -*- coding: utf 8 -*-
# Binary Search
# 2019. 4/30

global A
global n

def binarySearch(key):
    left = 0
    right = n
    key = int(key)

    while (left < right):
        mid = (left + right) // 2
        if (key == A[mid]):
            return 1
        if (key < A[mid]):
            right = mid
        elif (key > A[mid]):
            left = mid + 1
    return 0

if __name__ == '__main__':
    sum = 0
    n = int(input())
    A = list(map(int, input().split()))

    q = int(input())
    B = list(map(int, input().split()))

    for i in range(q):
        if binarySearch(B[i]) == 1:
            sum = sum + 1

    print("{}".format(sum))



Measured memory_bytes: 16716
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
#define repD(i, m, n) for(int i = m; i >= n; i--)

int nums[100][100];

int main(){
	int n;
	int t = 1;
	while(cin >> n && n){
		memset(nums, -1, sizeof(nums));
		int cnt = nums[0][0] = 1;
		int x = 0, y = 0;
		bool cr = false;
		rep(i,n*n-1){
			if(cr){
				int y0 = y + 1;
				int x0 = x - 1;
				int y1 = y - 1;
				int x1 = x + 1;
				if(0 <= y0 && y0 < n && 0 <= x0 && x0 < n && nums[y0][x0] == -1){
					x = x0;
					y = y0;
				}else{
					x = x1;
					y = y1;
				}
				if(x == 0 || x == n - 1 || y == 0 || y == n - 1) cr = false;
			}else{
				if(y == 0 && x != n - 1|| y == n - 1){
					x++;
				}else{
					y++;
				}
				cr = true;
			}
			nums[y][x] = ++cnt;
		}
		cout << "Case " << t++ << ":" << endl;
		rep(i, n){
			rep(j,n) cout << setw(3) << nums[i][j];
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};

int main(){
    int N; cin >> N;
    int H[N];
    for(int i = 0; i < N; i++) cin >> H[i];
    int dp[100100];
    dp[0] = 0; dp[1] = abs(H[1]-H[0]);
    for(int i = 2; i < N; i++){
        dp[i] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]));
    }
    cout << dp[N-1] << endl;
}



Measured memory_bytes: 1024
#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

bool u[1000002];
ll d[1000002];

int main()
{
    int n, m;
    cin >> n >> m;
    ll a[1002], b[1002];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) if(a[i] == a[j]){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i < m; i++) for(int j = i + 1; j < m; j++) if(b[i] == b[j]){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    for(int i = 0; i < n; i++){
        u[a[i]] = true;
        ll r = 0;
        bool s = false;
        for(int j = 0; j < m; j++){
            if(a[i] == b[j]) s = true;
            if(a[i] < b[j]) r++;
        }
        if(!s) ans = ans * r % MOD;
    }
    for(int j = 0; j < m; j++){
        u[b[j]] = true;
        ll r = 0;
        bool s = false;
        for(int i = 0; i < n; i++){
            if(b[j] == a[i]) s = true;
            if(b[j] < a[i]) r++;
        }
        if(!s) ans = ans * r % MOD;
    }
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) d[min(a[i], b[j])]++;
    for(int i = n * m; i > 0; i--) d[i - 1] += d[i];
    for(ll i = 1; i <= n * m; i++){
        if(u[i]) continue;
        ans = ans * max(0ll, d[i] - (n * m - i)) % MOD;
    }
    cout << ans << endl;
}

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

const double eps = 1e-9;
inline bool equals(double a, double b) { return fabs(a - b) < eps ;}

class Point {
public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {};

    Point operator + (Point p) { return Point(x + p.x, y + p.y); }
    Point operator - (Point p) { return Point(x - p.x, y - p.y); }
    Point operator * (double a) { return Point(a * x, a * y); }
    Point operator / (double a) { return Point(x / a, y / a); }

    double abs() { return sqrt(norm()); }
    double norm() { return x * x + y * y; }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x - p.x) < eps && fabs(y - p.y) < eps;
    }
};
typedef Point Vector;

double dot(const Vector& a, const Vector& b) {
    return a.x * b.x + a.y * b.y;
}

// return abs of closs product
double cross(const Vector& a, const Vector& b) {
    return a.x * b.y - a.y * b.x;
}

int ccw(Point p0, Point p1, Point p2) {
    const int COUNTER_CLOCKWISE = 1, CLOCKWISE = -1;
    const int ONLINE_BACK = 2, ONLINE_FRONT = -2, ON_SEGMENT = 0;
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if (cross(a, b) >  eps) return COUNTER_CLOCKWISE;
    if (cross(a, b) < -eps) return CLOCKWISE;
    if (dot(a, b)   < -eps) return ONLINE_BACK;
    if (a.norm() < b.norm()) return ONLINE_FRONT;
    return ON_SEGMENT;
}

int main(void) {
    double x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    Point a(x0, y0), b(x1, y1);
    int q;
    cin >> q;
    while (q--) {
        double x, y;
        cin >> x >> y;
        int judge = ccw(a, b, Point(x, y));
        if (judge == -2) cout << "ONLINE_FRONT";
        if (judge == -1) cout << "CLOCKWISE";
        if (judge == 0) cout << "ON_SEGMENT";
        if (judge == 1) cout << "COUNTER_CLOCKWISE";
        if (judge == 2) cout << "ONLINE_BACK";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def EulerTour(graph, root=1):
    global ind_L, ind_R, parent
    N = len(graph) - 1
    stack = [-root, root]
    tour = []
    i = -1
    while stack:
        v = stack.pop()
        i += 1
        if v > 0:
            ind_L[v] = i
            p = parent[v]
            for w in graph[v]:
                if w == p:
                    continue
                parent[w] = v
                stack.append(-w)
                stack.append(w)
        else:
            ind_R[-v] = i
        yield v
    return tour, ind_L, ind_R, parent


N = int(readline())
graph = [[] for _ in range(N + 1)]
parent = [0] * (N + 1)
ind_L = [0] * (N + 1)
ind_R = [0] * (N + 1)
C = (0,) + tuple(map(int, readline().split()))
m = map(int, read().split())
for a, b in zip(m, m):
    graph[a].append(b)
    graph[b].append(a)

removed = [0] * (N + 1)
answer = [N * (N + 1) // 2] * (N + 1)
memo = [0] * (N + 1)

for v in EulerTour(graph):
    if v > 0:
        memo[v] = removed[C[parent[v]]]
    else:
        v = -v
        removed[C[v]] += 1
        c = C[parent[v]]
        x = (ind_R[v] - ind_L[v]) // 2 + 1  # subtree size
        x -= removed[c] - memo[v]
        answer[c] -= x * (x + 1) // 2
        removed[c] += x

for i, x in enumerate(removed):
    x = N - x
    answer[i] -= x * (x + 1) // 2
print('\n'.join(map(str, answer[1:])))


Measured memory_bytes: 171204
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s.find('A')==string::npos)cout<<"No"<<endl;
	else if(s.find('B')==string::npos)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

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

const int N = 12;
const int INF = INT_MAX;
int c[N];
int a[N][N];

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

    int n, m, X;
    cin >> n >> m >> X;
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        for (int j = 0; j < m; ++j)
          cin >> a[i][j];
    }
    vector<int> cnt(m);
    int ret = INF;
    for (int k = 1; k < (1 << n); ++k) {
        fill(cnt.begin(), cnt.end(), 0);
        int cur = 0;
        for (int i = 0; i < n; ++i) {
          if (k & (1 << i)) {
            cur += c[i];
            for (int j = 0; j < m; ++j) {
              cnt[j] += a[i][j];
            }
          }
        }
        bool found = false;
        for (int j = 0; j < m; ++j) {
            if (cnt[j] < X) found = true;
        }
        if (!found) ret = min(ret, cur);
    }
    if (ret == INF) ret = -1;
    cout << ret << endl;
    return 0;
}


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

int main(){
    string s1, s2;
    cin >> s1 >> s2;
    int n1, n2;
    n1 = s1.size();
    n2 = s2.size();
    vector<vector<int> > dp(n1+1, vector<int>(n2+1));
    rep(i, n1){
        dp[i+1][0] = i+1;
    }
    rep(i, n2){
        dp[0][i+1] = i+1;
    }
    rep(i, n1){
        rep(j, n2){
            if(s1[i] == s2[j]){
                dp[i+1][j+1] = dp[i][j];
            }else{
                dp[i+1][j+1] = min(dp[i][j]+1,min(dp[i+1][j]+1, dp[i][j+1]+1));
            }
        }
    }
    cout << dp[n1][n2] << endl;
    return 0;
}



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


int main()
{
 
 int n;
 cin>>n;
 
 vector<int> myVector;
 for(int i=0; i<n; i++)
 {
     int x;
     cin>>x;
     myVector.push_back(x);
 }
   ///////////////////
   
   int count=1;
   
  int smallest_soFar=myVector.at(0);
    
 for(int i=0; i<n; i++)
 {
    
   if(smallest_soFar > myVector.at(i))
    {
        count++;
        smallest_soFar=myVector.at(i);
    }
     
 }
   
   cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 1400
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

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

bool predication(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b){
    return a.first.second < b.first.second;
}

int main(){
    std::ios::sync_with_stdio(false);
    int n, d, a;
    cin >> n >> d >> a;
    vector<pair<pair<int,int>,int>> enemies;
    for(int i=0;i<n;++i) {
        int x, h;
        cin >> x >> h;
        enemies.push_back(MP(MP(x-d, x+d), h));
    }
    sort(enemies.begin(), enemies.end(), predication);

    ll ret = 0;
    ll dam = 0;
    ll cur_pos = -1 * (1 << 30);
    queue<pair<int,int>> q;
    for(int i=0;i<n;++i) {
        while(!q.empty() && q.front().first < enemies[i].first.first) {
            dam -= q.front().second;
            q.pop();
        }
        if (dam < enemies[i].second)
        {
            int bomb_count = ceil((enemies[i].second - dam) * 1.0 / a);
            ret += bomb_count;
            dam += bomb_count * a;
            q.push(MP(enemies[i].first.second, bomb_count * a));
        }        
    }

    cout << ret << endl;
}

Measured memory_bytes: 4980
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cmath>

using namespace std;

int main() {
  int a, b;
  scanf("%d %d", &a, &b);

  int l = (int) ceil(((double) a) / 0.08);
  int h = (int) floor(((double) b) / 0.1);

  // cout << "l: " << l << ", h: " << h << endl;

  int left = min(l, h) - 1;
  int right = max(l, h) + 1;

  for (int i = left ; i <= right; i++) {
    if ( (((int) floor(((double) i) * 0.08)) == a) && (((int) floor(((double) i) * 0.1)) == b)) {
      cout << i << endl;
      return 0;
    }
    // } else {
    //   cout << "a: " << ((int) ((double) i) * 0.08) << endl;
    //   cout << (((int) ((double) i) * 0.08) == a) << endl;
    //   cout << "b: " << ((int) ((double) i) * 0.1) << endl;
    //   cout << (((int) ((double) i) * 0.1) == b) << endl;
    // }
  }

  cout << "-1" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main()
{
  while(1){
    int N;
    cin >> N;
    if(N == 0) break;
    vector<int> info[N];
    REP(i,N){
      int M;
      cin >> M;
      REP(j,M){
        int x;
        cin >> x;
        info[i].push_back(x);
      }
    }
    int K;
    cin >> K;
    int leak[K];
    REP(i,K)
      cin >> leak[i];
    int c;
    int ans = -1;
    bool flag = true;
    REP(i,N){
      c = 0;
      REP(j,K){
        if(find(info[i].begin(), info[i].end(), leak[j]) != info[i].end())
          c++;
      }
      if(c == K){
        if(ans == -1){
          ans = i + 1;
        }else{
          flag = false;
          cout << "-1" << endl;
          break;
        }
      }
    }
    if(flag)
      cout << ans << endl;
  }
}  

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N; 
    cin >> N;

    vector<ll> A(N);

    REP(i, N){
        cin >> A[i];
    }

    bool pairwise = true;
    bool setwise = false;

    // 簡単なsetwiseのチェック
    ll setcheck = A[0];
    for(ll i=1; i<N; i++){
        setcheck = gcd(setcheck, A[i]);
    }
    if(setcheck == 1) setwise = true;

    // cout << "setwise:" << setwise << endl;

    // pairwiseのチェック

    map<ll, ll> paircheck;

    REP(i, N){
        map<ll, ll> temp = prime_factor(A[i]);

        for(auto iter=temp.begin(); iter!=temp.end(); iter++){
            if(paircheck[iter->first] > 0){
                pairwise = false;
            }
            else{
                paircheck[iter->first] = 1;
            }
        }
        if(pairwise == false) break;
    }
    
    // cout << "setwise:" << setwise << endl;
    // cout << "pairwise:" << pairwise << endl;

    if(pairwise){
        cout << "pairwise coprime" << endl;
        return 0;
    }
    if(setwise){
        cout << "setwise coprime" << endl;
        return 0;
    }

    cout << "not coprime" << endl;
    return 0;
}

Measured memory_bytes: 11004
#include<iostream>
#include<cmath>
using namespace std;
#define ll long long
#define mod 1000000007
#define for(i,n) for(int i=0;i<(int)n;i++)
int main(){
	int a,b,c;
  int c_5 = 0,c_7 =0;
  cin>>a>>b>>c;
  if(a==5)c_5++;
    if(a==7)c_7++;
    if(b==5)c_5++;
    if(b==7)c_7++;
    if(c==5)c_5++;
    if(c==7)c_7++;
  if(c_5==2&&c_7==1)cout<<"YES";
  else cout<<"NO";
  return 0;
  
}

Measured memory_bytes: 3632
#include<iostream>
int main()
{
	int r, c;
	std::cin >> r >> c;
	int**val = new int*[r + 1];
	for(int i = 0; i < r + 1; i++)
	{
		val[i] = new int[c + 1];
		if(i != r)
		{
			val[i][c] = 0;
			for(int j = 0; j < c; j++)
			{
				std::cin >> val[i][j];
				val[i][c] += val[i][j];
			}
		}
	}
	for(int i = 0; i < c + 1; i++)
	{
		val[r][i] = 0;
		for(int j = 0; j < r; j++)
		{
			val[r][i] += val[j][i];
		}
	}
	for(int i = 0; i < r + 1; i++)
	{
		for(int j = 0; j < c + 1; j++)
		{
			std::cout << val[i][j];
			if(j != c)
			{
				std::cout << ' ';
			}
		}
		std::cout << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3108
n = str(input())

a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
l = [b,c,d]
s = a+b+c+d
ans = 1

if s == 7:
  h_1,h_2,h_3 = "+","+","+"
elif s-b*2 == 7:
  h_1,h_2,h_3 = "-","+","+"
elif s-c*2 == 7:
  h_1,h_2,h_3 = "+","-","+"
elif s-d*2 == 7:
  h_1,h_2,h_3 = "+","+","-"
elif s-b*2-c*2 == 7:
  h_1,h_2,h_3 = "-","-","+"
elif s-b*2-d*2 == 7:
  h_1,h_2,h_3 = "-","+","-"
elif s-c*2-d*2 == 7:
  h_1,h_2,h_3 = "+","-","-"
elif s-b*2-c*2-d*2 == 7:
  h_1,h_2,h_3 = "-","-","-"
else:
  ans = 0

if ans == 0:
  print("")
else:
  ans = "{0}{1}{2}{3}{4}{5}{6}{7}{8}".format(a,h_1,b,h_2,c,h_3,d,"=",7)
  print(ans)

Measured memory_bytes: 3064
N,M=list(map(int,input().split()))
A=[]
for i in range(N):
    A.append(list(map(int,input().split())))
A.sort()
ans=0
for i in range(N):
    if M > A[i][1]:
        ans+=A[i][0]*A[i][1]
        M -= A[i][1]
    else:
        ans+=A[i][0]*M
        break
print(ans)

Measured memory_bytes: 27760
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    string s;
    scan(s);

    foreach (cmd ; 0 .. 8) {
        int ans = s[0] - '0';

        foreach (k ; 0 .. 3) {
            if (cmd & (1 << k)) {
                ans += s[k + 1] - '0';
            }
            else {
                ans -= s[k + 1] - '0';
            }
        }

        debug {
            writeln(ans);
        }

        if (ans == 7) {
            writefln("%c%c%c%c%c%c%c=7", s[0], cmd & 1 ? '+' : '-', s[1], cmd & 2 ? '+' : '-', s[2], cmd & 4 ? '+' : '-', s[3]);
            return;
        }
    }
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}



struct Queue(T) {
    private {
        int N, head, tail;
        T[] data;
    }

    this(int n) {
        N = n + 1;
        data = new T[](N);
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return (tail + 1) % N == head;
    }

    T front() {
        return data[head];
    }

    void push(T x) {
        assert(!full);
        data[tail++] = x;
        tail %= N;
    }

    void pop() {
        assert(!empty);
        head = (head + 1) % N;
    }

    void clear() {
        head = tail = 0;
    }
}

Measured memory_bytes: 256
if __name__ == '__main__':
    MODULO = 10**9 + 7
    N = int(input())
    res = 2 * pow(9, N, MODULO)#(9*9) % MODULO
    res = (pow(10,N, MODULO) + pow(8, N, MODULO) - res) % MODULO# (res * pow(10, N-2, MODULO)) % MODULO
    # for i in range(N-2):
    #     res = (res * 10) % MODULO
    print(res)


Measured memory_bytes: 61752
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

vector<string> rows;
vector<string> cols;

int h, w;

vector<int> prev_enc(string& s) {
    vector<int> result;
    for (auto si : s) {
        if (si == '#') {
            result.push_back(-1);
        } else {
            if (result.size() == 0) result.push_back(0);
            else result.push_back(*result.rbegin() + 1);
        }
    }
    return result;
}

vector<vector<int>> cnt_r;
vector<vector<int>> cnt_l;
vector<vector<int>> cnt_d;
vector<vector<int>> cnt_u;
int main()
{
    cin >> h >> w;
    REP(i, h) {
        string s;
        cin >> s;
        rows.push_back(s);
    }
    cols = vector<string>(w, "");
    REP(i, h) {
        REP(j , w) {
            cols[j] += rows[i][j];
        }
    }
    REP(i, h) cnt_r.push_back(prev_enc(rows[i]));
    REP(i, h) reverse(rows[i].begin(), rows[i].end());
    REP(i, h) {cnt_l.push_back(prev_enc(rows[i])); reverse(cnt_l[i].begin(), cnt_l[i].end());}
    REP(i, h) reverse(rows[i].begin(), rows[i].end());

    REP(i, w) cnt_d.push_back(prev_enc(cols[i]));
    REP(i, w) reverse(cols[i].begin(), cols[i].end());
    REP(i, w) {cnt_u.push_back(prev_enc(cols[i])); reverse(cnt_u[i].begin(), cnt_u[i].end());}

    // REP(i, h) {DV(cnt_l[i]);}
    int ans = 0;
    // D(ans);
    REP(i, h) {
        REP(j, w) {
            if (rows[i][j] == '#') continue;
            ans = max(ans, cnt_l[i][j] + cnt_r[i][j] + cnt_d[j][i] + cnt_u[j][i] + 1);
            // DDD(i, j, ans);
        }
    }
    cout << ans << endl;
}


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

int main(){
string O, E;
  cin >> O >> E;
  
  for(int i = 0;i < E.size();i++){
  cout << O.at(i);
  cout << E.at(i);
  }
  if(O.size() > E.size()){
  cout << O.at(O.size() - 1);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
const int NMAX = 3000200;
//小数点の表し方 cout << fixed << setprecision(5);
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);

    vector<int> ma(NMAX,0);
    for(int i=0;i<n;i++){
        cin >> a[i];
        ma[a[i]]++;
    }

    int cnt = 0;
    for(int i=0;i<n;i++){
        if(ma[a[i]] > 1) continue;
        vector<ll> p = enum_divisors(a[i]);
        bool ok = true;
        for(auto x:p){
            if(x==a[i]) continue;   
            if(ma[x] != 0) ok = false;
        }
        if(ok){cnt++;}
    }
    cout << cnt << endl;
    
}

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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

struct Sieve{
  ll n;
  vll table;
  Sieve(ll n):n(n), table(n+1,0){
    for(ll i = 2; i<=n; i++){
      if(table[i])
        continue;

      table[i] = i;
      for(ll j = i*i; j<=n; j+=i)
        table[j] = i;
    }
  }

  vll factorList(ll x){
    vll res;
    while(x>1){
      res.push_back(table[x]);
      x /= table[x];
    }

    return res;
  }


  vpl getFact(ll x){
    map<ll, ll> m;
    vll fa = factorList(x);
    for(auto p:fa)
      m[p] += 1;

    SORT_UNIQUE(fa);
    vpl res;
    for(auto p:fa)
      res.push_back(pll(p, m[p]));

    return res;
  }
};

ll modPow(ll a, ll b){
  if(!b)
    return 1;

  ll power = a;
  ll res = 1;
  while(b>0){
    if(b&1)
      res = (res*a)%MOD;
    a = a*a%MOD;
    b >>= 1;
  }
  return res;


}

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

  ll n;
  cin >> n;
  vll a(n);
  REP(i, n)
    cin >> a[i];

  sort(a.begin(), a.end());

  Sieve s = Sieve(1000005);
  map<ll, ll> m;
  REP(i, n){
    vpl fa = s.getFact(a[i]);
    for(auto p:fa)
      m[p.FI] = max(m[p.FI], p.SE);
  }

  ll lcd = 1;
  for(auto p:m){
    REP(i, p.SE)
      lcd = lcd*p.FI%MOD;
  }


  ll ans = 0;
  REP(i, n){
    ll b = lcd * modPow(a[i], MOD-2);
    ans = (ans+b)%MOD;
  }

  cout << ans << endl;


}


Measured memory_bytes: 8832
#include<stdio.h>

int main(){
    double W,H,x,y;
    int s;
    scanf("%lf %lf %lf %lf",&W,&H,&x,&y);
    if((W/2.0==x)&&(H/2.0==y)){
        s=1;
    }
    else{
        s=0;
    }
    printf("%lf %d\n",W*H/2,s);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    long long ans = 0;
    for(int bit = 0; bit < (1 << s.size() - 1); ++bit){
        int l = 0;
        for(int i = 0; i < s.size(); i++){
            l++;
            if(bit & (1 << i)){
                string t = s.substr(s.size() - 1 - i, l);
                ans = ans + stoll(t.c_str());
                l = 0;
            }
            if(i == s.size() - 1){
                string t = s.substr(0, l);
                ans = ans + stoll(t.c_str());
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
char b;
cin >> b;
if (b == 'A'){
  cout << 'T' << endl;
}
if (b == 'T'){
  cout << 'A' << endl;
}
if (b == 'G'){
  cout << 'C' << endl;
}
if (b == 'C'){
  cout << 'G' << endl;
}
}


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

using namespace std;

int main()
{
  int a,b;
  cin >> a >> b;
  int ans = -1;
  for( int i = 1; i <= 10000; i++ )
  {
    if( int(i * 0.08) == a && int(i * 0.10) == b )
    {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    int h,w,n;
    cin>>h>>w>>n;
    int k=0,i=0;
    while(k<n){
        k=k+w;
        i++;
    }
    int j=0;
    k=0;
    while(k<n){
        k+=h;
        j++;
    }
    cout<<min(i,j);
    return 0;
}


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

using namespace std;

const int N = 300005;
int E[N];

int main() {
    int n;
    string s;
    cin >> n >> s;
    for (int i = n - 1; i >= 0; i--) {
		E[i] = E[i+1] + (s[i] == 'E');
	}
	int W = 0, res = n;
	for (int i = 0; i < n; i++) {
		res = min(res, W + E[i+1]);
		W += s[i] == 'W';
	}
	cout << res;
    return 0;
}


Measured memory_bytes: 4928
#include <stdio.h>
#include <string.h>
 
int main()
{
    int sl, pl;
    char s[256], p[128];
    scanf("%s %s", s, p);
    sl=strlen(s);
    pl=strlen(p);
    pl=pl;
    memcpy(s+sl, s, sl);
    sl+=sl;
    s[sl]='\0';
 
    int i, ans=0;
    for(i=0; i<=sl-pl; i++) {
        if( (ans=strncmp(s+i, p, pl))==0) break;;
    }
    puts(ans?"No":"Yes");
    return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <cmath>

using namespace std;
typedef unsigned long ul;
int b(int i, int k, int *a, int size) {
  int mini = a[i];
  for (int ii = 1; ii <= k; ii++) {
    int j = i-ii < 0 ? i-ii+size : i-ii;
    mini = mini > a[j] ? a[j] : mini;
  }
  return mini;
}

int main() {
  int N, x;
  cin >> N >> x;
  int a[N];
  for (int i = 0; i < N; i++)
    cin >> a[i];

  ul ans = 0;
  int biktemp[N];
  for (int i = 0; i < N; i++) {
    //ans += b(i,0,a,N);
    biktemp[i] = b(i,0,a,N);
    ans += biktemp[i];
  }
  
  for (int k = 1; k < N; k++) {
    ul temp = x*k;
    for (int i = 0; i < N; i++) {
      biktemp[i] = min(biktemp[i],a[i-k<0?i-k+N:i-k]); // <- bi(k) = min(bi(k-1),a[i-k])
      temp += biktemp[i];
      //temp += b(i,k,a,N); //<- O(N^3)
    }
    ans = ans > temp ? temp : ans;
  }

  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 char s[30];
 cin>>s;
 ll n=strlen(s);
 map<char,ll>map;
 if(n!=26){
  rep(i,0,n){
   map[s[i]]++;
  }
  cout<<s;
  rep(i,0,26){
   if(map[i+'a']==0){
    char c='a'+i;
    cout<<c<<endl;
    return 0;
   }
  }
 }
 
 char t[30]="zyxwvutsrqponmlkjihgfedcba";

 if(!strcmp(s,t)){
  char c[5]="-1";
  pr(c);
  return 0;
 }

 ll k=0,m;
 rrp(i,n,0){
  map[s[i]]++;
  ll mx=s[i]-'a';
  rep(j,mx+1,26){
   if(map['a'+j]!=0){
    s[i]='a'+j;
    rep(k,0,i+1){
     cout<<s[k];
    }
    pnn;return 0;
   }
  }
 }
return 0;}



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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2097162
#define inf 1e9
#define MOD 1000000007

int main()
{

    ll a, b, c, d;
    cin >> a >> b>> c >> d;
    ll lcm = (c*d)/ __gcd(c,d);

    ll bc = b/c;
    ll bd = b/d;
    ll bcd = b/lcm;

    ll ac = (a-1)/c;
    ll ad = (a-1)/d;
    ll acd = (a-1)/lcm;

    ll up = bc+bd-bcd;
    ll dn = ac+ad-acd;

    cout << (b-a+1)-(up-dn);
}


Measured memory_bytes: 256