akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int N;

int countOdd(const vector<lint> &A)
{
    int n = 0;
    for (auto v : A) if (v & 1) n++;
    return n;
}

void waru(vector<lint> &A)
{
    lint gcd = A[0];
    for (auto v : A) gcd = __gcd(gcd, v);
    for (auto &v : A) v /= gcd;
}

lint calcRes(const vector<lint> &A)
{
    lint res = -A.size();
    for (auto v : A) res += v;
    return res;
}

int main()
{
    cin >> N;
    vector<lint> A(N);
    cin >> A;
    sort(A.begin(), A.end());

    for (int turn = 0; ; turn++)
    {
        lint yo = calcRes(A);
        int oddNum = countOdd(A);

        if (yo & 1 || A[0] == 1 || oddNum > 1)
        {
            cout << ((yo + turn) & 1 ? "First" : "Second") << endl;
            return 0;
        }
        else
        {
            for (auto &v : A) v /= 2;
            waru(A);
        }
    }
}


Measured memory_bytes: 1024
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative
import           Debug.Trace
import           Text.Printf


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons
getInt = readLn :: IO Int

main = do
  n <- solve <$> getInt
  putStrLn $ (\n -> if n then "Yes" else "No") $ 7 `elem` n

solve 0 = []
solve n = (n `mod` 10) : (solve $ n `div` 10)


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

int main() {
    int n;
    int count=0;
    cin >> n;
    int b[n-1];

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

    for (int i = n-1; i >= 0 ; i--)
    {
        if (i==0)
        {
            count+=b[i];
        } else if (i == n-1)
        {
            count+=b[i-1];
        } else
        {
            if (b[i]>b[i-1])
            {
                count+=b[i-1];
            } else {
                count+=b[i];
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;
#define EPS 1e-9
int main()
{
//	cut here before submit 
//	freopen("testcase.pl", "r", stdin);
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;

	int i,j;
	for (i = 0; i < n; ++i){
		vector <double> px (4, 0.0);
		vector <double> py (4, 0.0);
		getline (cin, str );
		stringstream ss(str);
		for (j = 0; j < 4; ++j){
			ss >> px[j] >> py[j];
//			cout << "p[" << j << "]: (" << px[j] << ',' << py[j] << ')' << endl;
		} // end for
		vector <double> vx (2, 0.);
		vector <double> vy (2, 0.);

		
		for (j = 0; j < 2; ++j){
			vx[j] = px[2*j + 1] - px[2*j];
			vy[j] = py[2*j + 1] - py[2*j];
//			cout << "v[" << j << "]: (" << vx[j] << ',' << vy[j] << ')' << endl;
		} // end for

		double D = vx[0]*vy[1] - vy[0]*vx[1];
		if (fabs(D) < EPS ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		} // end if


	} // end for
		
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll power(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!

ll cnt[100][30], ans[30];

int main(void){
    ll N;
    char S[100];
    scanf("%lld", &N);
    rep(i, N) {
        scanf("%s", S);
        for(ll j=0; S[j]!='\0'; j++) cnt[i][S[j]-'a']++;
        rep(j, 30) {
            if(i==0) ans[j] = cnt[0][j];
            else chmin(ans[j], cnt[i][j]);
        }
    }
    rep(i, 30) rep(_, ans[i]) printf("%c", 'a'+i);
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <vector>

using namespace std;
using namespace chrono;

#ifdef DEBUG
	#define LOCAL_INPUT_FILE
#else
	//~ #define USE_FILE_IO
#endif

#ifdef USE_FILE_IO
	#define INPUT_FILE "input.txt"
	#define OUTPUT_FILE "output.txt"
	#define cin ____cin
	#define cout ____cout
	ifstream cin(INPUT_FILE);
	ofstream cout(OUTPUT_FILE);
#else
	#ifdef LOCAL_INPUT_FILE
		#define cin ____cin
		ifstream cin("input.txt");
	#endif
#endif

const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7; 
const long double eps = 1e-8;

mt19937_64 randGen(system_clock().now().time_since_epoch().count());

inline void raiseError(string errorCode) {
	cerr << "Error : " << errorCode << endl;
	exit(42);
}

inline bool check(vector<int> a) {
	for (int step = (1 << 21); step > 0; step >>= 1) {
		int n = a.size();
		if (n > step) {
			vector<int> b(n - step);
			for (int i = 0; i < n - step; ++i) {
				b[i] = a[i] ^ a[i+step];
			}
			a = b;
		}
	}
	assert(a.size() == 1);
	return a[0];
}

signed main() {
	#ifndef USE_FILE_IO
		ios_base::sync_with_stdio(false);
	#endif
	
	int n; cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		char c; cin >> c;
		v[i] = c - '0';
	}
	
	--n;
	vector<int> a(n);
	bool h1 = false;
	for (int i = 0; i < n; ++i) {
		a[i] = abs(v[i] - v[i+1]);
		h1 |= (a[i] == 1);
	}
	
	if (h1) {
		for (int &i : a) {
			i &= 1;
		}
		cout << (check(a) ? 1 : 0) << endl;
	} else {
		for (int &i : a) {
			i >>= 1;
		}
		cout << (check(a) ? 2 : 0) << endl;
	}
	
	return 0;
}


Measured memory_bytes: 13824
n = int(input())
ncpy = n
lst = []

while ncpy >= 10:
    lst.append(ncpy%10)
    ncpy //= 10
else:
    lst.append(ncpy)

sn = sum(lst)

if n%sn == 0:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N,M;
  cin>>N>>M;
  vector<ll> A(M);
  rep(i,M) cin>>A[i];

  ll sum=0;
  rep(i,M) sum+=A[i];

  if(N<sum) cout<<-1<<endl;
  else cout<<N-sum<<endl;

  return 0;
}


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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#define ll       long long int
#define fast     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod      1000000007
#define pb       push_back
#define S        second
#define F        first
#define P 		 pair<ll,ll>
#define PI 3.1415926535897932384626433832795028
//#define ordered_set tree<ll, null_type,less_equal<>, rb_tree_tag,tree_order_statistics_node_update>
ll dp[22][(1<<22)];
ll solve(vector<vector<ll>> &com,ll i,ll womensub,ll n){
	if(i==n+1){
		if(womensub==0)
			return 1;
		else return 0;
	}
	ll ans=0;
	if(dp[i][womensub]!=-1)
		return dp[i][womensub];
	for(ll w=0;w<n;w++){
		int avail=((1<<w) & (womensub) )==0 ? 0:1 ;
		if(avail && com[i][w+1]){
			ans=(ans+solve(com,i+1,womensub^(1<<w),n)) % mod;
		}
	}
return dp[i][womensub]=ans;
}
int32_t main()
{	fast


	//cout<<"f";
	//cout<<545<<endl;
	
	ll n;
	cin>>n;
	vector<vector<ll>> com(n+1,vector<ll>(n+1));
	memset(dp,-1,sizeof dp);
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=n;j++){
			cin>>com[i][j];
		}
	}
	cout<<solve(com,1,(1<<n)-1,n);
	return 0;

}

Measured memory_bytes: 721152
import fractions
A=[int(i) for i in input().split()]
A.sort()
g=fractions.gcd(A[1]-A[0],A[2]-A[1])
ans=len(str(bin(g)))-str(bin(g)).rfind("1")-1
print(-1 if A[0]==A[2] and A[0]%2==0 else 0 if A[0]==A[2] and A[0]%2==1 else ans)

Measured memory_bytes: 5596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=998244353;
const ll mod2=2e9+11;

int main() {
    //  ios_base::sync_with_stdio(0);
    //  cin.tie(0);
#ifdef LOCAL
    freopen("a.in","r",stdin);
#endif
    int n;
    cin>>n;
    vector <pii> a(n);
    int SUM=0;
    for (int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        int cnt1=0,cnt=0;
        int now=0;
        int mx=INF;
        for (int j=0;j<s.size();j++)
        {
            if (s[j]=='(')
                cnt1++,now++;
            else
                cnt++,now--;
            mx=min(mx,now);
        }
        SUM+=now;
        a[i]={now,mx};
    }
    if (SUM!=0)
    {
        cout<<"No";
        return 0;
    }
    vector <pii> b,c;
    int sum=0;
    for (int i=0;i<n;i++)
    {
        if (a[i].se>=0)
            sum+=a[i].fi;
        else {
            if (a[i].fi<=0){
                swap(a[i].fi,a[i].se);
                b.pb(a[i]);
            }
            else {
                swap(a[i].fi,a[i].se);
                c.pb(a[i]);
            }
        }
    }
    sort(all(c));
    reverse(all(c));
    int cur=0;
    while (cur<c.size()&&sum+c[cur].fi>=0)
        sum+=c[cur].se,cur++;
    if (cur!=c.size())
    {
        cout<<"No";
        return 0;
    }
    sum=0;
    for (int i=0;i<b.size();i++)
        b[i].fi*=-1,b[i].se*=-1;
    cur=0;
    vector <pair <int,pii> > s(b.size());
    for (int i=0;i<b.size();i++)
        s[i]={b[i].fi-b[i].se,b[i]};
    sort(all(s));
    while (cur<s.size())
    {
        auto to=s[cur];
        if (sum>=to.fi)
        {
            sum+=(to).se.se;
            cur++;
        }
        else
        {
            break;
        }
    }
    if (cur==s.size())
        cout<<"Yes\n";
    else
        cout<<"No\n";



}


Measured memory_bytes: 20828
K=int(input())

from collections import deque
q=deque()

for i in range(1,10):
  q.append(i)
  
cnt=0
while cnt<K:
  num=q.popleft()
  cnt+=1
  one=num%10
  if one!=0:
    q.append(num*10+(one-1))
  q.append(num*10+one)
  if one!=9:
    q.append(num*10+(one+1))
  
print(num)


Measured memory_bytes: 12404
/*
  AUTHOR:SOURABH
  CREATED:25:03:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll t;
    string s;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>s;
        if(s[2]==s[3] && s[4]==s[5])
            cout<<"Yes";
        else
            cout<<"No";
    }
    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  ll x, y;
  cin >> x >> y;
  ll ans = 0;
  while(x<=y) {
    ans++;
    x *= 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return False
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.root(x)]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

n, m = map(int, input().split())

uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.unite(a, b)


print(uf.group_count() - 1)


Measured memory_bytes: 13096
from sys import stdin

n,a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
s = ["."]+list(stdin.readline().rstrip())
for i in range(b,d):
    if s[i] == "#" and s[i+1] == "#":
        print("No")
        exit()
for j in range(a,c):
    if s[j] == "#" and s[j+1] == "#":
        print("No")
        exit()
if c < d:
    print("Yes")
    exit()
for k in range(b,d+1):
    if s[k-1] == "." and s[k] == "." and s[k+1] == ".":
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 6260
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
const int N = 2e5+10;

int main()
{
	_SAD()
	 long long int h,ans=1,p;
	cin>>h;
	int cnt=0;
	  // ans-=h/3;
        while(h>1)
	{ 
	  cnt++;
	  h/=2;
	  
	}
        for(int i=0;i<=cnt;i++) ans*=2;
        cout<<ans-1<<nl;
	return 0;
}


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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int N = 3007, inf = 0x3f3f3f3f, M = 998244353;

ll f[N][N];

ll fast_pow(ll a, ll b) {
	ll ans = 1;
	while(b) {
		if(b&1) ans = ans * a % M;
		b >>= 1;
		a = a * a % M;
	}
	return ans;
}

int a[N];

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

	int n, s; cin >> n >> s;
	ll inv2 = fast_pow(2, M-2);

	f[0][0] = fast_pow(2, n);

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

	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= s; j++) {
			f[i][j] = f[i-1][j];
			if(j - a[i] >= 0) f[i][j] = (f[i][j] + (f[i-1][j-a[i]] * inv2 % M))%M;  
		}
	}

	cout << f[n][s] << endl;

}

Measured memory_bytes: 74136
S = input()
n = len(S) - 1
bool_list = [False] * n

state_list = []

def dfs(i, n, bool_list):
    bool_list = bool_list.copy()
    if i == n:
        state_list.append(bool_list)
    else:
        dfs(i + 1, n, bool_list)
        bool_list[i] = True
        dfs(i + 1, n, bool_list)

dfs(0, n, bool_list)

ans = 0
for state in state_list:
    res_str = ''
    for i in range(n):
        res_str += S[i]
        if state[i]:
            res_str += '+'
    else:
        res_str += S[-1]
    ans += eval(res_str)

print(ans)


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

int main(){
  string s,t;
  string ans = "Yes";
  cin >> s >> t;
  for (int i = 0; i < s.length() ; i++){
    if(s[i] != t[i]) ans ="No";
  }
    
  if (t.length() != s.length() + 1) ans = "No";
  cout << ans;
}

Measured memory_bytes: 3608
N,K=gets.chomp.split(" ").map(&:to_f)

if (K==1)
    puts 1
    exit
end

ret = 0.0
(1..N).each do |n|
    e = K>n ? Math.log(K/n, 2).ceil : 0
    ret += 0.5**e
end
puts ret/N


Measured memory_bytes: 1788
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
 
 
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    double a,b,x,y;
    cin>>a>>b>>x>>y;
    double sum=a*b/2;
    cout<<fixed;
    cout<<sum<<setprecision(9)<<" ";
    if((x==a/2 && y==b/2) )cout<<1;
    else cout<<0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char weather[10];
int main(){
    cin >> weather;

    if(!strcmp(weather, "Sunny"))   cout << "Cloudy" << endl;
    if(!strcmp(weather, "Cloudy"))   cout << "Rainy" << endl;
    if(!strcmp(weather, "Rainy"))   cout << "Sunny" << endl;
    return 0;
}

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

using namespace std;

int main(){
    int x;
    cin >> x;
    vector<bool> a(x+1,false);
    a[1]=true;
    for(int i=2;i<=x;i++){
        int c=i*i;
        while(c <= x){
            a[c]=true;
            c*=i;
        }
    }
    for(int i=x;i>=1;i--){
        if(a[i]){
            cout<<i<<endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 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 mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long 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 digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int n;
	cin >> n;
	string s = to_string(n);
	int ans = 0;
	/*rep(i, s.size()) {
		cout << s[i] - '0' << endl;
	}*/
	for (int i = 1; i <= n; i++) {
		string now = to_string(i);
		int af = now[0] - '0', be = now[now.size() - 1] - '0';
		if (be == 0) continue;
		//cout << now << " " << be << " " << af << endl;
		rep(j, s.size()) {
			if (be != af && j == s.size() - 1) continue;
			int dp[10][2];
			rep(k, 10) {
				rep(l, 2) {
					dp[k][l] = 0;
				}
			}
			dp[0][0] = 1;
			rep(k, s.size()) {
				rep(l, 2) {
					//cout << "k=" << k << " " << "l=" << l << endl;
					if (k < j) {
						for (int d = 0; d <= 0; d++) {
							dp[k + 1][l || (d < s[k] - '0')] += dp[k][l];
						}
					}
					else if (k == j) {
						for (int d = 0; d <= (l ? 9 : s[k] - '0'); d++) {
							if (d == be) {
								//cout << (l ? 9 : int(s[k] - '0')) <<" "<< d << " " << be << endl;
								dp[k + 1][l || (d < s[k] - '0')] += dp[k][l];
							}
						}
					}
					else if (k == s.size() - 1) {
						for (int d = 0; d <= (l ? 9 : s[k] - '0'); d++) {
							if (d == af) {
								dp[k + 1][l || (d < s[k] - '0')] += dp[k][l];
							}
						}
					}
					else {
						for (int d = 0; d <= (l ? 9 : s[k] - '0'); d++) {
							dp[k + 1][l || (d < s[k] - '0')] += dp[k][l];
						}
					}
				}
			}
			/*rep(k, s.size() + 1) {
				rep(l, 2) {
					cout << dp[k][l] << " ";
				}
				cout << endl;
			}*/
			ans += dp[s.size()][0] + dp[s.size()][1];
			//cout << dp[s.size()][0] <<" "<< dp[s.size()][1] << endl;
			//cout << endl;
		}
		//cout << endl;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    int X, A, B;
    std::cin >> X >> A >> B;
    if (B - A <= 0)
    {
        std::cout << "delicious" << std::endl;
    }
    else if (0 < B - A && B - A <= X)
    {
        std::cout << "safe" << std::endl;
    }
    else
    {
        std::cout << "dangerous" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
struct node{
	int ch[2];
	bool vis;
	int dp;
};
node nn[1048576];
int num=0;
int add(int now,char* s)
{
	if(s[0]=='\0')
	{
		return now;
	}
	if(!nn[now].ch[s[0]-'0'])
	{
		num++;
		nn[now].ch[s[0]-'0']=num;
	}
	return add(nn[now].ch[s[0]-'0'],s+1);
}
char s[110][110];
int tmp[110][110];
int dfs(int now)
{
	int wz=add(0,s[now]);
	if(nn[wz].vis)
	{
		return nn[wz].dp;
	}
	int n=strlen(s[now]);
	for(int i=0;i<n;i++)
	{
		s[now+1][i]=s[now][i];
	}
	for(int i=n-1;i>=0;i--)
	{
		s[now+1][i]='\0';
		tmp[now][i]=dfs(now+1);
	}
	int ans=tmp[now][n-1];
	if(s[now][n-1]=='1')
	{
		ans<<=1;
		if(ans>=998244353)
		{
			ans-=998244353;
		}
	}
	for(int i=1;i<n;i++)
	{
		s[now+1][i]='\0';
		for(int j=0;j<i;j++)
		{
			s[now+1][j]='1';
		}
		for(int j=n-1;j>=0;j--)
		{
			int k=i-1-(n-1-j)%i;
			if(s[now][j]=='0')
			{
				s[now+1][k]='0';
			}
			if(k==0&&n-j>i)
			{
				ans+=(long long)tmp[now][j]*dfs(now+1)%998244353;
				if(ans>=998244353)
				{
					ans-=998244353;
				}
			}
		}
	}
	nn[wz].vis=true;
	nn[wz].dp=ans;
	return ans;
}
int main()
{
	nn[0].vis=true;
	nn[0].dp=1;
	scanf("%s",s[0]);
	printf("%d\n",dfs(0));
	return 0;
}

Measured memory_bytes: 1024
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	return tuple( nm[ 0 ], nm[ 1 ] );
}

auto solve( long n, long m )
{
	// 3 * 3 までのパターンは普通にシミュレートする
	auto h = ( 3 < n ) ? 3 : n;
	auto w = ( 3 < m ) ? 3 : m;
	auto table = new bool[][]( h, w );
	foreach( y; 0 .. h )
	{
		foreach( x; 0 .. w )
		{
			table[ y ][ x ] = !table[ y ][ x ];
			if( 0 < x     ) table[ y ][ x - 1 ] = !table[ y ][ x - 1 ];
			if( x < w - 1 ) table[ y ][ x + 1 ] = !table[ y ][ x + 1 ];
			
			if( 0 < y )
			{
				table[ y - 1 ][ x ] = !table[ y - 1 ][ x ];
				if( 0 < x     ) table[ y - 1 ][ x - 1 ] = !table[ y - 1 ][ x - 1 ];
				if( x < w - 1 ) table[ y - 1 ][ x + 1 ] = !table[ y - 1 ][ x + 1 ];
			}
			
			if( y < h - 1 )
			{
				table[ y + 1 ][ x ] = !table[ y + 1 ][ x ];
				if( 0 < x     ) table[ y + 1 ][ x - 1 ] = !table[ y + 1 ][ x - 1 ];
				if( x < w - 1 ) table[ y + 1 ][ x + 1 ] = !table[ y + 1 ][ x + 1 ];
			}
		}
	}
	
	// 表の合計
	auto c = table.joiner.count( true );
	
	// 3 * 3 より大きいパターンは真ん中が広がるだけだから計算で出す
	if( 3 <= n && 3 <= m )
	{
		if( table[ 1 ][ 1 ] ) c += ( n - 2 ) * ( m - 2 ) - 1;		// 真ん中を二重計上しないように注意
	}
	
	// 片方だけ3以上のパターンその1
	if( 3 <= n && m < 3 )
	{
		if( table[ 1 ][ 0 ] ) c += ( n - 2 ) * m - 1;
	}
	
	// 片方だけ3以上のパターンその1
	if( n < 3 && 3 <= m )
	{
		if( table[ 0 ][ 1 ] ) c += n * ( m - 2 ) - 1;
	}
	
	return c;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())


template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

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

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;

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

int main(){
    ll a,b;
    int c,d;
    cin>>a>>b>>c>>d;
    
    int g;
    if (c>d) g=gcd(c,d);
    else g=gcd(d,c);
    
    ll l=(ll)c*(ll)d/g;
    
    
    ll ans;
    a--;
    ans=(b-b/c-b/d+b/l)-(a-a/c-a/d+a/l);
    
    cout<<ans;
    
}



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

int main(int argc, char const* argv[]) {
	int A, B;
	char op;
	scanf("%d %c %d", &A, &op, &B);
	if (op == '+') printf("%d\n", A + B);
	else printf("%d\n", A - B);

	return 0;
}


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

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int c0=0,c1=0;
	for(int i =0;i<n;i++)
	{
		if(s.at(i)=='0')
		{
			c0++;
		}
		else
		{
			c1++;
		}
	}
	int k;
	if(c0>c1)
	{
		k=c1*2;
	}
	else
	{
		k=c0*2;
	}
	cout << k << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

int main() {
  ll n;
  cin >> n;
  vi t(n);
  for (ll i = 0; i < n; i++) {
    cin >> t[i];
  }

  ll ans = t[0];

  for (ll i = 0; i < n; i++) {
    ll gcd = __gcd(ans, t[i]);
    ans = (t[i] / gcd) * ans;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define substr(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vector<pair<ll,pair<ll,ll>>> num(n);
  for(int i=0;i<n;i++){
    ll a,b;cin>>a>>b;
    num[i]=mp(a+b,mp(a,b));
  }
  ll tk=0,ao=0;
  sort(ALL(num),greater<pair<ll,pair<ll,ll>>>());
  for(int i=0;i<n;i++){
    if(i%2==0)tk+=num[i].S.F;
    else ao+=num[i].S.S;
  }
  cout<<tk-ao<<endl;
  return 0;
}


Measured memory_bytes: 2560
#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() {
  ll n;
  cin >> n;
  int ans = 1;
  for (ll k = 2; k * k <= n; k++) {
    ll n_ = n;
    if (n_ % k) continue; 
    while (n_ % k == 0) n_ /= k;
    if (n_ % k == 1) ans++;
  }
  n--;
  if (n > 1) ans++;
  for (ll k = 2; k * k <= n; k++) {
    if (n % k == 0) ans += 2;
    if (k * k == n) ans--;
  }

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

Measured memory_bytes: 3584
N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
if sum(a) == x:
    print(N)
else:
    i = 0
    candy = 0
    while candy <= x and i <= N - 1:
        candy += a[i]
        i += 1
    print(i - 1)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    ll ans = 1000000;
    rep(i,n){
        ll a,cnt=0; cin>>a;
        while(a%2==0){
            cnt++;
            a/=2;
        }
        chmin(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
	string str;
	cin >> str;

	int left = 0, right = str.length() - 1;
	int ans = 0;
	while (left < right) {
		if (str[left] != str[right]) {
			ans++;
		}
		left++;
		right--;
	}

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

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

const ll INF = 1LL << 60;

template <typename T>
void WarshalFloyd(vector<vector<T>>& v) {
  for (int k = 0; k < v.size(); ++k) {
    for (int i = 0; i < v.size(); ++i) {
      for (int j = 0; j < v.size(); ++j) {
        v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
      }
    }
  }
}

int main() {
  in(ll, n, m, l);

  vector<vector<ll>> dist(n, vector<ll>(n, INF));
  rep(i, m) {
    in(ll, a, b, c);
    if (c <= l) {
      --a, --b;
      dist[a][b] = dist[b][a] = c;
    }
  }
  WarshalFloyd(dist);

  vector<vector<ll>> dist2(n, vector<ll>(n, INF));
  rep(i, n) rep(j, n) if (dist[i][j] <= l) dist2[i][j] = 1;
  WarshalFloyd(dist2);

  in(int, q);
  rep(i, q) {
    in(int, s, t);
    --s, --t;
    ll d = dist2[s][t];
    if (d == INF) {
      out(-1);
    } else {
      out(d - 1);
    }
  }
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1e9 + 7

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

    int a,b,c;
    long long k;

    cin >> a >> b >> c >> k;

    if(k%2==0) cout << a-b;
    else cout << b-a;
}


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

bool done = false;

int calculate(vector<int> &ticket, string operands) {
  int result = ticket.at(0);
  for(int i=0; i<3; i++) {
    if(operands[i] == '+') result += ticket.at(i+1);
    if(operands[i] == '-') result -= ticket.at(i+1);      
  }

  return result;
}

string equation(vector<int> &ticket, string operands) {
  string result = to_string(ticket.at(0));
  for(int i=0; i<3; i++) {
    result += operands[i];
    result += to_string(ticket.at(i+1));
  }

  return result;
}
 
void seven(vector<int> &ticket, int depth, string operands) {
  if(depth == 4) {
    if(calculate(ticket, operands) == 7 && done == false) {
      cout << equation(ticket, operands) << "=7" << endl;
      done = true;
    }
  } else {
    seven(ticket, depth+1, operands+"+");
    seven(ticket, depth+1, operands+"-");
  }
}

int main() {
  int input;
  cin >> input;

  vector<int> ticket(4); 

  for(int i=0; i<4; i++) {
    ticket.at(i) = input/pow(10, 3-i);
    input -= ticket.at(i)*pow(10, 3-i);
  }

  seven(ticket, 1, "");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



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

  int x;
  cin >> x;

  cout << __detail::__lcm(x, 360) / x << '\n';

  




  
  return 0;
}


Measured memory_bytes: 3580
#include <vector>
#include <iostream>
#pragma warning(disable : 4996)
using namespace std;
int N, L, Q, a, b, x[100009], p[20][100009];
int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &x[i]);
	scanf("%d%d", &L, &Q);
	for (int i = 0, r = 0; i < N; i++) {
		while (r < N - 1 && x[r + 1] - x[i] <= L) r++;
		p[0][i] = r;
	}
	for (int i = 0; i < 17; i++) {
		for (int j = 0; j < N; j++) {
			p[i + 1][j] = p[i][p[i][j]];
		}
	}
	while (Q--) {
		scanf("%d%d", &a, &b); a--, b--;
		if (a > b) swap(a, b);
		int sum = 0;
		for (int i = 17; i >= 0; i--) {
			if (p[i][a] < b) sum += 1 << i, a = p[i][a];
		}
		printf("%d\n", sum + 1);
	}
	return 0;
}

Measured memory_bytes: 8320
S = input()
index = 1
no_flag = True
for i in S:
    if index % 2 == 1:
        if i != 'R' and i != 'U' and i != 'D':
            no_flag = False
    else:
        if i != 'L' and i != 'U' and i != 'D':
            no_flag = False
    index += 1

if no_flag == True:
    print('Yes')
else:
    print('No')

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

ll DPX[100100];
ll DPY[100100];

int main(){
    string L;
    cin >> L;
    ll N = L.size();

    DPX[0] = 1;

    REP(i,N){
        char c = L[i];
        if(c == '1'){
            //1
            DPX[i+1] += DPX[i] * 2;

            //0, 1
            DPY[i+1] += DPY[i] * 3;
            //0
            DPY[i+1] += DPX[i];
        }
        else{
            //0
            DPX[i+1] += DPX[i];

            //0, 1
            DPY[i+1] += DPY[i] * 3;
        }

        DPX[i+1] %= MOD;
        DPY[i+1] %= MOD;
    }

    ll ans = DPX[N] + DPY[N];
    cout << ans % MOD << endl;
    
    return 0;
}


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

using namespace std;

long long inv(long long a,long long mod){
	long long b=mod,p=1,q=0;
	while(b){
		long long c=a/b,d=a;
		a=b;
		b=d%b;
		d=p;
		p=q;
		q=d-c*q;
	}
	return (p+mod)%mod;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++) cin >> a[i];
	
	vector<vector<int>> divs(1010101);
	for(int i=2;i<divs.size();i++){
		if(divs[i].size()>0) continue;
		for(int j=1;(i*j)<divs.size();j++){
			divs[i*j].push_back(i);
		}
	}
	
	vector<int> ta(1010101);
	for(int i=0;i<n;i++){
		for(int p:divs[a[i]]){
			int kos=0;
			int c=a[i];
			while(c%p==0){
				kos++;
				c/=p;
			}
			ta[p]=max(ta[p],kos);
		}
	}
	
	long long res=0;
	long long mod=1000000007;
	for(int i=0;i<n;i++){
		res+=inv(a[i],mod);
	}
	for(int i=1;i<ta.size();i++){
		for(int j=0;j<ta[i];j++){
			res=res*i%mod;
		}
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 60160
(let* ((n (read))
       (k (read))
       (a (make-array `(,(1+ n))))
       (last-index 0)
       (memo (make-array `(,(1+ n)) :initial-element nil))
       (hist (make-array `(,(1+ n)) :initial-element nil)))
  ;; input
  (loop :for i :from 1 :to n
        :do (setf (aref a i) (read)))
  ;; init
  (setf (aref hist 0) 1)
  (setf (aref memo 1) 0)
  ;; 
  (loop :for m :from 1 :to n
        :for p :from 0
        :for pos := (aref a (aref hist p))
        :until (aref memo pos)
        :do (progn
              (setf (aref memo pos) m)
              (setf (aref hist m) pos)
              (setf last-index m)))
  (let* ((loop-end (aref hist last-index))
         (loop-start (aref a loop-end))
         (loop-end-index (aref memo loop-end))
         (loop-start-index (aref memo loop-start))
         (period (1+ (- loop-end-index loop-start-index))))
    (cond ((<= k loop-start-index)
           (format t "~A~%" (aref hist k)))
          (t
           (format t "~A~%"
                   (aref hist (+ loop-start-index
                                 (mod (- k loop-start-index) period))))))))


Measured memory_bytes: 81924
#include<bits/stdc++.h>
using namespace std;
long long n,i,h[100010];
int main(){
	cin>>n;
	for(i=1;i<=n;i++)cin>>h[i];
	for(i=1;i<=n;i++){
		if(h[i]<h[i-1]){
			cout<<"No";
			return 0;
		}
		else
			if(h[i]>h[i-1])h[i]--;
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			new Main().exec(sc);
		}
	}

	public void exec(Scanner sc) {
		int n = sc.nextInt();
		int l = sc.nextInt();
		List<String> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(sc.next());
		}
		Collections.sort(list);
		System.out.println(String.join("", list));
	}
}


Measured memory_bytes: 21844
/**
 * Author RDP
 * 
**/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bitset>
#include <iomanip>
#define endl '\n'
#define bp(x) __builtin_popcount(x)
#define zf(x) __builtin_clz(x)
#define zl(x) __builtin_ctz(x)
#define par(x) __bultin_parity(x)
#define FAST_IO ios::sync_with_stdio(0); std::cin.tie(0);
typedef long long ll;
using namespace std;

void test_case()
{
    FAST_IO
    int n;
    cin >> n;
    string s;
    set <string> se;
    for(int i = 0; i < n ; i ++)
    {
        cin >> s;
        se.insert(s);
    }
    cout << se.size() <<endl;
    return ;
}
int main()
{
    FAST_IO
    test_case();
    return 0;
}

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

#define sc(a) scanf("%d",&a)
#define scm(a,b) scanf("%d%d",&a,&b)
#define fl(c,i,n) for(int i=c;i<n;i++)
#define f(i,n) for(int i=0;i<n;i++)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long int
#define ull unsigned long long int
#define inf INT_MAX
#define linf LLONG_MAX
#define pb push_back
#define pp pop_back()
#define aov(a) a.begin(),a.end()
//#define mp make_pair
#define nl printf("\n")
#define PI 2.0*acos(0.0) //#define PI acos(-1.0)
#define xx first
#define yy second
#define mxv(a) *max_element(aov(a))
#define mnv(a) *min_element(aov(a))
#define LB(a,x) (lower_bound(aov(a),x)-a.begin())
#define UB(a,x) (upper_bound(aov(a),x)-a.begin())
#define to_c_string(a) a.c_str()
#define strtoint(c) atoi(&c[0])
#define pii pair<int,int>
#define MAXN 500005
#define MOD 1000000007

template <class T> inline T bigmod(T p,T e,T M){
    ll ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
/*int fact[MAXN];
int invfact[MAXN];
int inv(int a, int b){
    if(b==0)
        return 1;
    if(b&1)
        return (long long)a*inv(a, b-1)%MOD;
    else{
        int res = inv(a, b>>1);
        return (long long)res*res%MOD;
    }
}
void init(){
    fact[0] = 1;
    for(int i=1;i<MAXN;i++){
        fact[i] = (long long)fact[i-1]*i%MOD;
    }
    invfact[MAXN-1] = inv(fact[MAXN-1], MOD-2);
    for(int i=MAXN-1;i>0;i--){
        invfact[i-1] = (long long)invfact[i]*i%MOD;
    }
}
int C(int n, int r){
    if(r>n || r<0)
        return 0;
    return (long long)((long long)fact[n]*invfact[r]%MOD)*invfact[n-r]%MOD;
}*/
int n, m;
int x[100005], y[100005], lx[100005], ly[100005];
void solve(){
    sc(n);
    sc(m);
    f(i, n) sc(x[i]);
    f(i, m) sc(y[i]);
    for(int i=1;i<n;i++){
        lx[i-1] = abs(x[i]-x[i-1]);
    }
    for(int i=1;i<m;i++){
        ly[i-1] = abs(y[i]-y[i-1]);
    }
    n = n-1;
    m = m-1;
    ll X = 0, Y = 0;
    f(i, n){
        X += (long long)(n-i)*lx[i]*(i+1);
    }
    f(i, m){
        Y += (long long)(m-i)*ly[i]*(i+1);
    }
    int ans = ((X%1000000007)*(Y%1000000007))%1000000007;
    cout<<ans;
}
int main(){
    /*FILE *fin = freopen("C-small-attempt0.in", "r", stdin);
	assert( fin!=NULL );
	FILE *fout = freopen("C-small.out", "w", stdout);*/
	//init();
    solve();
    return 0;
}


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

int max10(int x){
  return (x+9)/10*10;
}
int sa10(int x){
  return max10(x)-x;
}

int main() {
  int A,B,C,D,E;cin>>A>>B>>C>>D>>E;
  int sum=max10(A)+max10(B)+max10(C)+max10(D)+max10(E);
  int sa=max({sa10(A),sa10(B),sa10(C),sa10(D),sa10(E)});
  cout<<sum-sa<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


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


    for(auto i = m.begin(); i!= m.end(); i++){
        if((i->second == max)) cout << i->first << endl;
    }
}



Measured memory_bytes: 25216
#include <iostream>
void traceALDS11A(int arr[], int max) {
	for (int i = 0; i < max; ++i) {
		if (i)
			std::cout << " ";
		std::cout << arr[i];
	}
	std::cout << std::endl;
}

int main() {

	int N;
	std::cin >> N;

	int arr[N];
	for (int i = 0; i < N; ++i) {
		std::cin >> arr[i];
	}

	traceALDS11A(arr, N);

	for (int i = 1; i < N; ++i) {
		int v = arr[i];
		for (int j = i - 1; j >= 0; --j) {
			if (v < arr[j]) {
				std::swap(arr[j], arr[j + 1]);
			} else {
				break;
			}
		}
		traceALDS11A(arr, N);
	}

	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (ll i = (a); i < (n); i += (s))
#define rep(...) _overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void chmax(T& a, const T& b) {if (a < b) a = b;}
template<typename T> inline void chmin(T& a, const T& b) {if (a > b) a = b;}
template<typename T> inline void print(const T& x) {cout << x << "\n";}
struct Init {Init() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} init;

int main() {
    ll x, y; cin >> x >> y;
    if ((y - 2 * x) % 2 == 0 and (4 * x - y) % 2 == 0) {
        if ((y - 2 * x) / 2 >= 0 and (4 * x - y) / 2 >= 0) {
            print("Yes");
            return 0;
        }
    }
    print("No");
}

Measured memory_bytes: 3700
#include <iostream>
#include <vector>

bool bs(std::vector<int>& S, int t) {
  int left = 0;
  int right = S.size();
  while (left < right) {
    int target = (right + left) / 2;
    if (S[target] == t)
      return true;
    if (S[target] > t)
      right = target;
    else
      left = target + 1;
  }
  return false;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> S;
  for (int i = 0; i < n; ++i) {
    int s;
    std::cin >> s;
    S.push_back(s);
  }
  int q, cnt = 0;
  std::cin >> q;
  for (int i = 0; i < q; ++i) {
    int t;
    std::cin >> t;
    if (bs(S, t))
      ++cnt;
  }
  std::cout << cnt << std::endl;
}

Measured memory_bytes: 3404