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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}


// end of Template
int f[6],n;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;
    for(int i=1;i<=n;i++){
        int temp; cin>>temp;
        f[temp%4]++;
    }

    if((f[0] >= f[1]+f[3]) || (f[2]==0 && f[0]==(f[1]+f[3]-1))){cout<<"Yes\n";}
    else{cout<<"No\n";}
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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

	ll n, m;
	cin >> n >> m;

	vector<ll> l(m), r(m);
	ll lMax = 0, rMin = INF;
	rep(i, m)
	{
		cin >> l[i] >> r[i];
		lMax = max(lMax, l[i]);
		rMin = min(rMin, r[i]);
	}

	cout << max(rMin - lMax + 1,ll(0)) << endl;

}

Measured memory_bytes: 1792
#pragma GCC optimize("O2")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<limits.h>
#include<ctime>
#define N 100001
typedef long long ll;
const int inf=0x3fffffff;
const int maxn=2017;
using namespace std;
inline int read()
{
    int f=1,x=0;char ch=getchar();
    while(ch>'9'|ch<'0')
    {
        if(ch=='-')
        f=-1;
        ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return f*x;
}
int main()
{
     char a=getchar(),b=getchar(),c=getchar(),d=getchar();
     if(a=='Y'&&b=='A'&&c=='K'&&d=='I')
     cout<<"Yes";
     else cout<<"No";
} 

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7; 
const int MINF = -1050000000;



int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> m;


	rep(i, n) {
		int x;
		cin >> x;
		m[x]++;
		m[x - 1]++;
		m[x + 1]++;
	}

	int ans = MINF;
	for (auto x : m) {
		ans = max(ans, x.second);
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 5120
from math import ceil
from heapq import heappush, heappop, heapify
N, M = map(int, input().split())
A_i = list(map(lambda x: -int(x), input().split()))
heapify(A_i)

for _ in range(M):
    heappush(A_i, ceil(heappop(A_i) / 2))

print(-sum(A_i))
    


Measured memory_bytes: 14380
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  string s,t;
  cin>>s>>t;
  map<char,char> m1,m2;
  int n=s.length();
  rep(i,0,n){
    if(m1.find(s[i])!=m1.end() || m2.find(t[i])!=m2.end()){
      if(m1[s[i]]!=t[i] || m2[t[i]]!=s[i]){
        cout<<"No\n";
        return;
      }
    }
    else m1[s[i]]=t[i],m2[t[i]]=s[i];
  }
  cout<<"Yes\n";
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3744
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int edgeCnt = Integer.parseInt(s.nextLine());
		int[][] input = new int[edgeCnt][edgeCnt];
		for(int i=0 ; i<edgeCnt ; i++) {
			String[] tmp = s.nextLine().split(" ");
			int[] inner = new int[tmp.length];
			for(int j=1 ; j<tmp.length ; j++) {
				inner[j-1] = Integer.parseInt(tmp[j]);
			}
			input[i] = inner;
		}
		int result = 0;
		boolean[] alreadyVisit = new boolean[edgeCnt];
		alreadyVisit[0] = true;

		wh : while(true) {
			int min = Integer.MAX_VALUE;
			boolean flg = false;
			int direction = -1;
			flg = false;
			for(boolean value : alreadyVisit) {
				if(!value) {
					flg = true;
				}
			}
			if(!flg)
				break wh;
			for(int i=0 ; i<edgeCnt ; i++) {
				if(alreadyVisit[i]) {
					for(int j=0 ; j<edgeCnt ; j++) {
						if(min>input[i][j] && !alreadyVisit[j] && input[i][j]!=-1) {
							min = input[i][j];
							direction = j;
						}
					}
				}
			}
			result += min;
			alreadyVisit[direction] = true;
		}
		System.out.println(result);
	}

}

Measured memory_bytes: 26216
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <float.h>
using namespace std;

#define N 100000

int a[N];

int main()
{
	int n;

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

	sort(a, a+n);

	int nn = a[n-1];
	double half = (double)nn/2;
	int b = a[0];
	double mi = DBL_MAX;
	for( int i = 0; i < n - 1; i++ ) {
		double d = abs((double)a[i] - half);
		if( d < mi ) {
			b = a[i];
			mi = d;
		}
	}

	cout << nn << endl;
	cout << b << endl;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int tmp1, tmp2;
    tmp1 = b-a;
    tmp2 = c-b;
    if(tmp1==tmp2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A, B; 
	cin >> A >> B;
	int ans = 0; 
	if(A == B) ans = 0; 
	else if((A < 0 && B > 0) || (A > 0 && B < 0)) ans = abs(A + B) + 1; 
	else if((A >= 0 && B > A) || (A < B && B <= 0)) ans = B - A; 
	else if((B > 0 && A > B) || (B < A && A < 0)) ans = A - B + 2; 
	else if(B < 0 && A == 0) ans = - B + 1; 
	else if(B == 0 && A > 0) ans = A + 1; 
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  vector<vector<int>> vec(3,vector<int>(3));
  rep(i,3){
    rep(j,3) cin>>vec[i][j];
  }
  int n,a;
  cin>>n;
  while(cin>>a){
    rep(i,3){
      rep(j,3){
        if(vec[i][j]==a) vec[i][j]=0;
      }
    }
  }
  bool flag=0;
  rep(i,3){
    if(vec[i][0]==0&&vec[i][1]==0&&vec[i][2]==0) flag=1;
    else if(vec[0][i]==0&&vec[1][i]==0&&vec[2][i]==0) flag=1;
  }
  if(vec[0][0]==0&&vec[1][1]==0&&vec[2][2]==0) flag=1;
  if(vec[0][2]==0&&vec[1][1]==0&&vec[2][0]==0) flag=1;
  puts(flag?"Yes":"No");
}


Measured memory_bytes: 256
// ConsoleApplication9.cpp : アプリケーションのエントリ ポイントを定義します。
//


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define p(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
//#define int long long


using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}

const int MAX = 510000;
const int MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool arr[100000100];
vector<ll>sosuu;
void Eratosthenes() {
	ll N = 10000010;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (ll i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (ll j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int  i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu.pb(i);
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}

ll stoL(string s) {
	ll n = s.length();
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += pow2(10, n - i-1)*(ll)(s[i]-'0');
	}
	return ans;
}


int main() {
	ll N, M; cin >> N >> M;
	ll ans = 0;
	if (N <= M/2) {
		ans += N;
		M -= N * 2;
		ans += M / 4;
		p(ans);
		return 0;
	}
	else {
		ans = M / 2;
		p(ans);
		return 0;
	}

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353

int main(){
	string l;
	cin >> l;
	ll n = l.size();
	vector<ll> li(l.size());
	transform(l.begin(),l.end(),li.begin(),[](char ch){return ch - '0';});
	vector<ll> powe(110001);
	powe.at(0) = 1;
	FOR(i,1,110000) powe.at(i) = (powe.at(i-1)*2) % MOD;
	vector<ll> dp(110000);
	dp.at(0) = 1;
	FOR(i,1,109999) dp.at(i) = (dp.at(i-1)*3) % MOD;
	ll ans = 0;
	ll cnt = 0;
	REP(i,n){
		if (li.at(i) == 1){
			ans = (ans+dp.at(n-i-1)*powe.at(cnt)) % MOD;
			cnt++;
			//cout << "li.at(i)==1, " << dp.at(n-i-1) << " " << powe.at(cnt) << endl;
		}
		
		//cout << i << "桁目finish, cnt=" << cnt << " " << ans << endl;
	}
	ans = (ans+powe.at(cnt)) % MOD;
	cout << ans << endl;
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

int N, A, B;

signed main(void) {
	cin >> N >> A >> B;
	int Max, Min;
	Max = min(A, B);
	Min = (A + B) - N;
	if (Min <= 0) {
		Min = 0;
	}
	cout << Max << " " << Min << endl;
}

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

using namespace std;

double value[45];
int size[45];

double get_value(string &pile){
    bool b_can_move = 0, w_can_move = 0;
    double b_max, w_min;
    double last_value = 0;
    for(int i=0;i<pile.length();i++){
        double value;
        if(pile[i]=='B'){
            if(b_can_move){
                b_max = max(b_max,last_value);
            }
            else{
                b_max = last_value;
            }
            b_can_move = 1;
            if(w_can_move){
                value = (b_max + w_min) / 2;
            }
            else{
                value = b_max + 1;
            }
        }
        if(pile[i]=='W'){
            if(w_can_move){
                w_min = min(w_min,last_value);
            }
            else{
                w_min = last_value;
            }
            w_can_move = 1;
            if(b_can_move){
                value = (b_max + w_min) / 2;
            }
            else{
                value = w_min - 1;
            }
        }
        last_value = value;
    }
    return last_value;
}

#define map unordered_map

void enumerate(int st, int ed,map<double,int> &table ,double value_sum = 0, int size_sum = 0){
    if(st==ed){
        if(table.count(value_sum)){
            table[value_sum] = max(table[value_sum], size_sum);
        }
        else{
            table[value_sum] = size_sum;
        }
    }
    else{
        enumerate(st+1, ed, table, value_sum, size_sum);
        enumerate(st+1, ed, table, value_sum + value[st], size_sum + size[st]);
    }
}

int find_zero_value(int st,int ed,map<double,int> &table ,double value_sum = 0, int size_sum = 0){
    if(st==ed){
        if(table.count(-value_sum)){
            return table[-value_sum] + size_sum;
        }
        else return 0;
    }
    else{
        int get1 = find_zero_value(st+1, ed, table, value_sum, size_sum);
        int get2 = find_zero_value(st+1, ed, table, value_sum + value[st], size_sum + size[st]);
        return max(get1, get2);
    }
}

map<double,int> table, table2;

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        string pile;
        cin>>pile;
        size[i] = pile.length();
        value[i] = get_value(pile);
        //printf("%f\n",value[i]);
    }
    if(n<=20){
        enumerate(0,n,table);
        printf("%d\n",table[0]);
    }
    else{
        /*
        enumerate(0,20,table);
        printf("%d\n",find_zero_value(20,n,table));
        */
        enumerate(0,20,table);
        enumerate(20,n,table2);
        int ans = 0;
        for(map<double,int>::iterator it = table.begin(); it!=table.end(); it++){
            double my_value = it->first;
            if(table2.count(-my_value)){
                int my_size = table[my_value] + table2[-my_value];
                ans = max(ans,my_size);
            }
        }
        printf("%d\n",ans);

    }

    return 0;
}

Measured memory_bytes: 84748
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    ll N, K; cin >> N >> K;
    vector<ll> A(N);
    for(ll &a:A)
        cin >> a;
    
    ll ans = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            if(A[i]>A[j]) ans++;
        }
    }
    
    ans = ans * K % MOD;
    
    
    vector<int> D(N);
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(A[i]<A[j]) D[i]++;
        }
    }
    
    for(int i=0; i<N; i++){
        ans = (ans + (K * (K-1) / 2) % MOD * D[i]) % MOD;
        ans %= MOD;
    }
    
    
    cout << ans << endl;
    
    return 0;
    
}





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

int main()
{
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	
	int five=0;
	int seven=0;
	for(int i=0;i<3;i++)
	{
		if(a[i]==5)
			five++;
		if(a[i]==7)
			seven++;
	}
	if(five==2&&seven==1)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAX = 100010;
int n, m;

int main()
{
    int T;
    long long x, y;
    scanf("%lld%lld",&x,&y);
    if(abs(x-y) > 1)
        puts("Alice");
    else
        puts("Brown");


//printf("%d",'A'-'a');
//    string x, y, z;
//    cin >> x >> y >> z;
//    printf("%c%c%c\n",x[0]-32,y[0]-32,z[0]-32);
    return 0;
}


Measured memory_bytes: 256
import Data.Char (digitToInt)

sumOfDigit :: Int -> Int
sumOfDigit num = sum . map digitToInt $ show num

main :: IO ()
main = do
    [num, min, max] <- map read . words <$> getLine
    let calculated = filter (\x -> sumOfDigit x <= max && min <= sumOfDigit x) [1 .. num]
    print $ sum calculated 

Measured memory_bytes: 1020
#include <stdio.h>
#define N 100000

int A[N],n;

int partition(int p,int r){
  int x,i,j,temp;

  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
      
    }

  }

  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  return i+1;
  
}

int main(void)
{
  int i,p;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  p=partition(0,n-1);

  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==p)printf("[%d]",A[i]);
    else printf("%d",A[i]);
    

  }
  printf("\n");
  return 0;
  
}




Measured memory_bytes: 2132
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

type Weight = i32;
#[allow(dead_code)]
#[derive(Clone, Debug, Eq, PartialEq)]
struct Edge {
    index: usize,
    src: usize,
    dest: usize,
    weight: Weight,
}
#[allow(dead_code)]
impl Edge {
    fn new(index: usize, src: usize, dest: usize, weight: Weight) -> Edge {
        Edge {
            index: index,
            src: src,
            dest: dest,
            weight: weight,
        }
    }
}
impl std::cmp::Ord for Edge {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        (self.weight, self.src, self.dest).cmp(&(other.weight, other.src, other.dest))
    }
}
impl std::cmp::PartialOrd for Edge {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}
type Edges = Vec<Edge>;
type Graph = Vec<Edges>;
#[allow(dead_code)]
fn graph_new(n: usize) -> Graph {
    vec![vec![]; n]
}
#[allow(dead_code)]
fn add_bi_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    graph[dest].push(Edge::new(*index, dest, src, weight));
    *index += 1;
}
#[allow(dead_code)]
fn add_uni_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    *index += 1;
}

// return (cnt, dist_sum, move_max)
fn calc(from: usize, parent: usize, g: &Graph, cnts: &Vec<usize>) -> (usize, usize, usize) {
    let mut ret = (cnts[from], 0, 0);
    for e in g[from].iter() {
        if e.dest == parent {
            continue;
        }
        let mut nret = calc(e.dest, from, g, cnts);
        nret.1 += nret.0;
        // merge
        if nret.1 > ret.1 {
            std::mem::swap(&mut ret, &mut nret);
        }
        ret.0 += nret.0;
        ret.1 += nret.1;
        ret.2 = std::cmp::min(ret.1 / 2, nret.1 + ret.2);
    }
    return ret;
}

fn main() {
    let n = read::<usize>();
    let cnts = read::<String>()
        .chars()
        .map(|c| if c == '1' { 1 } else { 0 })
        .collect::<Vec<usize>>();
    let mut g = graph_new(n);
    let mut index = 0;
    for _i in 0..n - 1 {
        let f = read::<usize>() - 1;
        let t = read::<usize>() - 1;
        add_bi_edge(&mut g, &mut index, f, t, 1);
    }
    let mut ans = 1 << 60;
    for i in 0..n {
        let nret = calc(i, i, &g, &cnts);
        if nret.1 % 2 == 0 && nret.1 <= nret.2 * 2 {
            ans = std::cmp::min(ans, nret.2);
        }
    }
    if ans == 1 << 60 {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 4476
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    int K; double R, L;
    double P, E, T;
    scanf("%d %lf %lf\n", &K, &R, &L);
    scanf("%lf\n", &P);
    scanf("%lf\n", &E);
    scanf("%lf\n", &T);

    bool C(double x) {
        return abs(x - T) <= E;
    }

    double dfs(double lb, double ub, int k) {
        double l = T - E, r = T + E;
        if (ub < l) return 0;
        if (lb > r) return 0;
        if (l <= lb && ub <= r) return 1;
        double mid = (lb + ub) / 2;
        if (k == 0) return cast(double)(C(mid));
        double ret;
        if (T < mid) {
            ret = P * dfs(mid, ub, k - 1) + (1 - P) * dfs(lb, mid, k - 1);
        } else {
            ret = P * dfs(lb, mid, k - 1) + (1 - P) * dfs(mid, ub, k - 1);
        }
        //writeln([k, lb, ub], " -> ", ret);
        return ret;
    }

    writefln("%.10f", dfs(R, L, K));
}

Measured memory_bytes: 1140
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int a, b, k;
	cin >> a >> b >> k;
	if(b-a+1 < k * 2){
		for(int i= a; i<=b; i++) cout << i << endl;
	}
	else{
		REP(i, k) cout << a + i << endl;
		for(int i= k-1; i>= 0; i--) cout << b - i << endl;
	}
	//cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  string A;
  cin >> A;

  if (A[0] != A[1] || A[1] != A[2]) {
    COUT("Yes");
  } else {
    COUT("No");
  }

  return 0;
}

Measured memory_bytes: 256
import sys
from math import ceil, log2

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


n, k = nm()
p = 0
for i in range(1, n + 1):
    if i >= k:
        p += 1 / n
    else:
        num = ceil(log2(k / i))
        p += (1 / n) * (1 / pow(2, num))

print(p)

Measured memory_bytes: 9208
#include <stdio.h>
#include <string.h>
#define MAXLENGTH (20)

int main(void)
{                  
  char str[MAXLENGTH];  	
  int i;

  scanf("%s", str);
  for(i = strlen(str)-1; i>=0; i--)
  {
    printf("%c",str[i]);  	  
  }
  printf("\n");

  return 0;		
}

Measured memory_bytes: 524
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int k,x,y,z,ix,iy,iz;
  long long int sum=0;
  
  scanf("%d", &k);
  
  for(ix=1; ix<=k; ix++){
    for(iy=1; iy<=k; iy++){
      for(iz=1; iz<=k; iz++){
        x=ix;
        y=iy;
         while( x % y != 0 ){
             z = x % y;
             x = y;
             y = z;
         }
        
        x=iz;

         while( x % y != 0 ){
             z = x % y;
             x = y;
             y = z;
         }

         sum+=y;
    }}}
  
  printf("%lld",sum);
  
  return 0;
}



Measured memory_bytes: 1728
import std.stdio, std.string, std.conv;

void main(){
	string str;
	string[] s;
	int q1, b, c1, c2, q2, a1, a2, t;
	while ((str = readln()) != "0\n") {
		s = split(str);
		q1 = s[0].to!int;
		b = s[1].to!int;
		c1 = s[2].to!int;
		c2 = s[3].to!int;
		q2 = s[4].to!int;
		foreach (i; 0..q2+1) {
			a1 = q2 - i;
			t = b - (a1 * c1);
			if (t < 0) continue;
			a2 = t / c2; 
			if (a1 + a2 >= q1) break;
		}
		if (a1 == 0) writeln("NA");
		else writeln(a1, " ", a2);
	}
}

Measured memory_bytes: 1012
import itertools
fi = list(map(int,input().split()))
n = fi[0]
m = fi[1]
x = fi[2]
c = []
cn = []
y = 1
for k in range(n):
  cn.append(k)
for i in range(n):
  a = list(map(int,input().split()))
  c.append(a)
for j in range(m):
  wa = 0
  for s in range(n):
    wa=wa+c[s][j+1]
  if wa < x:
    y=y*0

money = []
if not y==0:
  for s in range(n+1):
    ca = list(itertools.combinations(cn, s+1))
    cb = len(ca)
    for q in range(cb):
      cwa = []
      chan = 0
      for l in range(m+1):
        cwa.append(0)
      for p in range(s+1):
        cwa = list(map(lambda x,y: x+y, c[ca[q][p]], cwa))
      for t in range(m):
        if cwa[t+1]>=x:
          chan = chan+1
        if chan ==m:
          money.append(cwa[0])
  print(min(money))
else:
  print(-1)

Measured memory_bytes: 9504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(b,a*n)<<endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////
const int MAXN = 1e6 + 5;

int spf[MAXN];

void sieve()
{
	spf[1] = 1;
	for (int i = 2; i < MAXN; i++)
		spf[i] = i;

	for (int i = 4; i < MAXN; i += 2)
		spf[i] = 2;

	for (int i = 3; i * i < MAXN; i++)
	{

		if (spf[i] == i)
		{

			for (int j = i * i; j < MAXN; j += i)
				if (spf[j] == j)
					spf[j] = i;
		}
	}
}

set<int> getFactorization(int x)
{
	set<int> ret;
	while (x != 1)
	{
		ret.insert(spf[x]);
		x = x / spf[x];
	}
	return ret;
}


int gcd(int a,int b){

     if(b==0)
       return a;

     return gcd(b,a%b);


}


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

    sieve();

    map<int,int>facto;

    int n;
    cin>>n;

    vector<int>a(n);

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

       set<int>temp=getFactorization(a[i]);

       for(auto it:temp)facto[it]++;


    }

    int ans=0;


    for(int i=0;i<n-1;i++){
        set<int>temp=getFactorization(a[i]);

        for(auto it:temp){
             if(facto[it]>1){
                 ans=1;
             }
        }
    }


    if(ans==0){
        cout<<"pairwise coprime"<<endl;
        return 0;

    }

    int curr=a[0];

    for(int i=1;i<n;i++){

        curr=gcd(curr,a[i]);


    }

    if(curr==1){
        cout<<"setwise coprime"<<endl;
        return 0;
    }


    cout<<"not coprime"<<endl;







}


Measured memory_bytes: 14656
#include <map>
#include <vector>
#include <iostream>
#include <cstring>
using namespace std;
int m[29][29];
main(){
	string s,t;
	int h,w,i,j,x,y;
	for(;cin>>h>>w,h;cout<<s<<endl){
		vector<string>v;
		for(i=0;i<h;i++)cin>>s,v.push_back(s);
		s="0";
		map<string,int>M;
		for(i=0;i<h;i++)for(j=0;j<w;j++)for(x=-1;x<=1;x++)for(y=-1;y<=1;y++){
			if(x==0&&y==0)continue;
			memset(m,0,sizeof(m));
			int Y=i,X=j;
			t=v[Y][X],m[Y][X]=1;X=(X+x+w)%w,Y=(Y+y+h)%h;
			for(;!m[Y][X];X=(X+x+w)%w,Y=(Y+y+h)%h){
				t+=v[Y][X],m[Y][X]=1;
				if(++M[t]>1 && (s.size()<t.size()||(s.size()==t.size()&&s>t)))s=t;
			}
		}
	}
}

Measured memory_bytes: 36032
#include<queue>
#include<cstdio>
#include<iostream>
using namespace std;


int main()
{
	int n;
	int b[300], f[300], r[300], v[300];
	int building[4][3][10] = { 0 };
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> b[i] >> f[i] >> r[i] >> v[i];

	for (int i = 0; i < n; i++)
	{
		switch (b[i])
		{
		case 1:
			building[0][f[i] - 1][r[i] - 1] += v[i];
			break;
		case 2:
			building[1][f[i] - 1][r[i] - 1] += v[i];
			break;
		case 3:
			building[2][f[i] - 1][r[i] - 1] += v[i];
			break;
		case 4:
			building[3][f[i] - 1][r[i] - 1] += v[i];
			break;
		}
	}

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				cout << ' ' << building[i][j][k];
			}
			cout << endl;
		}
		cout << "####################" << endl;
	}

	for (int j = 0; j < 3; j++) {
		for (int k = 0; k < 10; k++) {
			cout << ' ' << building[3][j][k];
		}
		cout << endl;
	}

}

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

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s=="SUN")
        cout<<7;
    if(s=="MON")
        cout<<6;
    if(s=="TUE")
        cout<<5;
    if(s=="WED")
        cout<<4;
    if(s=="THU")
        cout<<3;
    if(s=="FRI")
        cout<<2;
    if(s=="SAT")
        cout<<1;

    cout<<"\n";
    return 0;

}


Measured memory_bytes: 256
import sys 
 
S = int(sys.stdin.readline())
mod = 10**9 + 7
 
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, 2*S+1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)
 
def nCr(n, r, mod=10**9+7):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod
 
ans = 0
n = 1
n_max = S // 3
while n <= n_max:
    res = S - 3 * n
    tmp = nCr(res + n - 1, n - 1)
    # print(n, res, tmp)
    ans += tmp
    ans %= mod
    n += 1
 
print(ans)

Measured memory_bytes: 66096
n = int(input())
lst = list(map(int, input().split()))

dp = [[0] * 2 for _ in range(n+1)]

dp[0][0] = 0
dp[0][1] = -10**10

i = 0
while i < n:
    dp[i+1][0] = max(dp[i][0] + lst[i], dp[i][1] - lst[i])
    dp[i+1][1] = max(dp[i][0] - lst[i], dp[i][1] + lst[i])
    i += 1

print(dp[n][0])

Measured memory_bytes: 25512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;
const int M = 2e6 + 5;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   if(pow < 0) return 0;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;ll c = (a * b)%mod;return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(2e6 + 7)] , inv_fac[(int)(2e6 + 7)];
void precomp_factorial(){fac[0] = 1;for(ll i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(ll i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};

int main(void)
{
   vector <pair<int,int> > vec;
   int n;
   cin >> n;

   for(int i = 0; i < n; i++){
       int a,b;
       cin >> a >> b;
       vec.push_back({b,a});
   }
   int start = 0;
   sort(vec.begin(), vec.end());
   int cond = 1;
   for(int i = 0; i < n; i++){
       if(start+vec[i].second <= vec[i].first){
           start += vec[i].second;
       }
       else{
           cond = 0; break;
       }
   }
   if(cond) cout << "Yes";
   else cout << "No";
}


Measured memory_bytes: 2420
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <limits>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

struct Info {
  int B;
  ll C;

     Info(int input_b, ll input_c)
    {
      
      B = input_b;
      C = input_c; 
    }
    bool operator<(const Info &another) const
    {
        return C > another.C;
    };
};

typedef pair<int, int> P;
const int MOD = 998244353;


int gcd(int a, int b){
  if(b == 0) return a;
  return gcd(b, a%b);
}

int main()
{
  int N,M;
  cin >> N >> M;
  ll A[100000],C,sum,B,max;
  vector<Info> info;
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  sort(A,A+N);
  sum = A[0];
  for(int i=1;i<N;i++){
    sum += A[i];
    A[i] = sum;
  }
  for(int i=0;i<M;i++){
    cin >> B >> C;
    info.push_back(Info(B,C));
  }
  sort(info.begin(), info.end());
  ll valuesum = 0;
  int index=0;
  bool flag = false;
  max = A[0] - info[0].C;
  if(A[0] > info[0].C) max = 0;
  for(int i=0;i<M;i++){
    for(int j=0;j<info[i].B;j++){
      valuesum += info[i].C;
      if(max < valuesum - A[index]) max = valuesum - A[index];
      else{
        flag = true;
        break;
      }
      index++;
    }
    if(flag) break;
  }
  cout << sum + max;
}


Measured memory_bytes: 3188
import bisect


def main():
    N = int(input())
    AArr = list(map(int, input().split()))
    BArr = list(map(int, input().split()))
    CArr = list(map(int, input().split()))

    AArr.sort()
    CArr.sort()
    ans = 0
    for i in range(N):
        a = bisect.bisect_left(AArr, BArr[i])
        c = bisect.bisect_right(CArr, BArr[i])
        c = N-c
        ans += a*c

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 22720
/*
	first part of this solution is based on
	https://maspypy.com/atcoder-%e5%8f%82%e5%8a%a0%e6%84%9f%e6%83%b3-2019-09-21agc-038

	Let f(d) := Sum_{i<j, gcd(a_i,a_j)=d} a_i*a_j.
	The answer is Sum_{d=1}^{10^6} f(d)/d.
	We use the inclusion-exclusion principle to compute f(d):
		Let g(d) := Sum_{i<j, d|a_i, d|a_j} a_i*a_j.
		Then f(d) = g(d) - Sum_{d|e, e>d} f(e). (so called 約数系包除)
		g(d) can be computed by
			(Sum_{d|a_i} a_i)^2 - Sum_{d|a_i} (a_i^2) = 2*g(d).
*/

#include <bits/stdc++.h>

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

using namespace std;
using lint=long long;

const lint MOD=998244353;

lint xgcd(lint a,lint b,lint &x,lint &y){
	if(b==0){ x=1; y=0; return a; }
	lint g=xgcd(b,a%b,y,x); y-=a/b*x;
	return g;
}

lint modinv(lint a,lint m){
	lint x,y;
	if(xgcd(a,m,x,y)==1) return (x+m)%m;
	return -1;
}

// enumerate all divisors
void dfs(int i,int x,const vector<pair<int,int>> &pf,vector<int> &D){
	if(i==pf.size()){
		D.emplace_back(x);
		return;
	}
	rep(j,pf[i].second+1){ dfs(i+1,x,pf,D); x*=pf[i].first; }
}

int main(){
	vector<lint> inv(1e6+1);
	for(int i=1;i<=1e6;i++) inv[i]=modinv(i,MOD);

	vector<int> pf_min(1e6); // pf_min[i] := minimum prime factor of i
	for(int i=2;i*i<=1e6;i++) if(pf_min[i]==0) {
		for(int j=i*i;j<=1e6;j+=i) if(pf_min[j]==0) pf_min[j]=i;
	}
	for(int i=2;i<=1e6;i++) if(pf_min[i]==0) pf_min[i]=i;

	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	vector<lint> asum(1e6+1),asum2(1e6+1);
	rep(i,n){
		int x=a[i];
		vector<pair<int,int>> pf;
		while(x>1){
			int q=pf_min[x];
			int e=0;
			do{
				x/=q;
				e++;
			}while(x%q==0);
			pf.emplace_back(q,e);
		}

		vector<int> D;
		dfs(0,1,pf,D);
		for(int d:D){
			asum[d]=(asum[d]+a[i])%MOD;
			asum2[d]=(asum2[d]+1LL*a[i]*a[i])%MOD;
		}
	}

	vector<lint> g(1e6+1);
	for(int d=1;d<=1e6;d++) g[d]=(asum[d]*asum[d]-asum2[d]+MOD)%MOD*inv[2]%MOD;

	vector<lint> f(1e6+1);
	for(int d=1e6;d>0;d--){
		f[d]=g[d];
		for(int e=2*d;e<=1e6;e+=d) f[d]=(f[d]-f[e]+MOD)%MOD;
	}

	lint ans=0;
	for(int d=1;d<=1e6;d++) ans=(ans+f[d]*inv[d])%MOD;
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 44032
# -*- coding: utf-8 -*-
N, x = map(int, input().split())
an = list(map(int, input().split()))

an.sort()

# print(an)
ans = 0

for ai in an:
    if x >= ai:
        x -= ai
        ans += 1
    else:
        break


if x > 0:
    if ans > 0:
        if ans == len(an):
            ans -=1
        else:
            pass
    else:
        ans = 0

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define ll long long
#define pii pair<int,int>
#define y1 Emilia
#define N 500500
#define dracarys ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);

int n, m;
vector<int> g[N];
int col[N], lvl[N], p[N];

vector<int> path;
void DFS (int v, int l = 0) {
    col[v] = 1;
    lvl[v] = l;
    p[l] = v;
    int mn = -1;
    for (int i = 0; i < (int)g[v].size(); ++i) {
        int to = g[v][i];
        if (col[to] == 1 && (mn == -1 || lvl[mn] < lvl[to]))
            mn = to;
    }
    
    if (mn != -1) {
        set<int> res;
        res.insert(mn);
        for(int j = l; p[j] != mn ; --j) res.insert(p[j]);
        int cnt = 0;
        for (int u : res)
            for (int to : g[u])
                if (res.count(to))
                    ++cnt;
        
        if (cnt == res.size()) {
            cout << cnt << "\n";
            for (int u : res)
                cout << u << "\n";
            exit(0);
        }
    }
    
    for (int i = 0; i < (int)g[v].size(); ++i) {
        int to = g[v][i];
        if (col[to] == 0) DFS (to, l + 1);
    }
    col[v] = 0;
    path.pop_back();
}
int main(){
    dracarys
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
    }
    for (int i = 1; i <= n; ++i) DFS(i);
    
    cout << -1 << "\n";
    return 0;
}


Measured memory_bytes: 16000
n,k = map(int,input().split())
x = list(map(int,input().split()))
mn = float("inf")
for i in range(n-k+1):
  if x[i] <= 0 and 0 <= x[i+k-1]:
    if x[i+k-1]-x[i] + min(abs(x[i+k-1]),abs(x[i])) < mn:
      mn = x[i+k-1]-x[i] + min(abs(x[i+k-1]),abs(x[i]))
  elif x[i+k-1] <= 0:
    if mn > -x[i]:
      mn = -x[i]
  else:
    if mn > x[i+k-1]:
      mn = x[i+k-1]
    break
print(mn)
    
    
    
  

Measured memory_bytes: 62576
// ABC80-C.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <vector>
using namespace std;


int main()
{
	int n;
	cin >> n;
	auto f = vector<vector<int>>(n);
	auto p = vector<vector<int>>(n);
	for (size_t i = 0; i < n; i++)
	{
		f[i] = vector<int>(10);
		for (size_t j = 0; j < 10; j++)
		{
			cin >> f[i][j];
		}
	}
	for (size_t i = 0; i < n; i++)
	{
		p[i] = vector<int>(11);
		for (size_t j = 0; j < 11; j++)
		{
			cin >> p[i][j];
		}
	}

	int res = -(1<<30);
	// 1 から 2^10-1
	for (size_t b = 1; b < (1<<10); b++)
	{
		int cc = 0;
		for (size_t i = 0; i < n; i++)
		{
			int c = 0;
			// b >> j & 1 はbの2進表記一桁目が1かどうか
			for (size_t j = 0; j < 10; j++) if((b >> j & 1) && f[i][j]) c++;
			cc += p[i][c];
		}
		if (res < cc) res = cc;
	}
	cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
n,m=map(int, input().split())
a=list(map(int, input().split()))
g=0
count=0
for i in a:
    g+=i
b = float(1/(4*m))
for i in a:
    t = float(i/g)
    if t>=b:
        count+=1
    if count==m:
        print("Yes")
        exit()
if count < m:
    print("No")

Measured memory_bytes: 3060
a,b,c,d = map(int, input().split())


if(b*d>=a*c and b*d>=b*c and b*d>=a*d):
    print(b*d)
elif(a*c>=b*d and a*c>=a*d and a*c>=b*c):
    print(a*c)
elif(a*d>=a*c and a*d>=b*c and a*d>=b*d):
    print(a*d)
elif(b*c>=a*c and b*c>=b*d and b*c>=a*d):
    print(b*c)

Measured memory_bytes: 9192
import java.util.*;

class Main {
	Scanner sc;
	int N, K, R, S, P;
	String T;
	
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextInt();
		R = sc.nextInt();
		S = sc.nextInt();
		P = sc.nextInt();
		T = sc.next();
		
		final char IV = (char)0;
		int sc = 0;
		for (int i = 0; i < K; i++) {
			char last = IV;
			for (int r = 0; r < N/K+1; r++) {
				int n = i + r * K;
				if (n >= N) break;
				char c = T.charAt(n);
				if (c == last) {
					last = IV;
				} else {
					switch (c) {
					case 'r':
						sc += P;
						break;
					case 's':
						sc += R;
						break;
					case 'p':
						sc += S;
						break;
					default:
					}
					last = c;
				}
			}
		}
		System.out.println(sc);
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}

Measured memory_bytes: 26104
<?php

    $N = intval(trim(fgets(STDIN)));
    
    for($i=1;$i<=$N;$i++){
        list($s,$p) = array_map(null,explode(" ",trim(fgets(STDIN))));
        
        $S[] = [$s,intval(-$p),$i]; 
    }
    // var_dump($S);
    sort($S);
    // var_dump($S);
    
    foreach($S as $value){
        echo $value[2]."\n";
    }
    
    

?>

Measured memory_bytes: 15976
from collections import defaultdict

def getdis(a, b, n, x, y):
    mini = abs(a - b)
    mini = min(mini, abs(a - x) + 1 + abs(b - y))
    mini = min(mini, abs(a - y) + 1 + abs(b - x))
    return mini

def solve(n, x, y):
    dis = [0 for i in xrange(n)]
    for i in xrange(1, n + 1):
        for j in xrange(i + 1, n + 1):
            u = getdis(i, j, n, x, y)
            # print i, j, u
            dis[u] += 1
    return dis[1:]

(n, x, y) = map(int, raw_input().split())

res = solve(n, x, y)
for num in res:
    print num


Measured memory_bytes: 2936
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

double dp[3010][3010] = {};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N; cin >> N;
    vector<double> p(N);
    REP(i,N) cin >> p[i];
    dp[0][0] = 1;
    REP(i,N){
        REP(j,N+1){
            if(j-1 >= 0){
                dp[i+1][j] = dp[i][j]*(1.0-p[i]) + dp[i][j-1] * p[i];
            }else{
                dp[i+1][j] = dp[i][j]*(1.0-p[i]);
            }
        }
    }
    double ans = 0;
    FOR(i,N/2+1,N+1){
        ans += dp[N][i];
    }
    cout << ans << endl;


}


Measured memory_bytes: 70784
#include <algorithm>
#include <iostream>
#include <istream>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <map>


using namespace std;


int mod(int a, int b) {
    int r = a % b;
    return r < 0 ? r + b : r;
}


int main() {
    long long l, r; cin >> l >> r;
    long long cnd, cur_cnds_size;
    bool is_terminate = false;

    int ans;
    int cnt = 0;
    set<int> candidate_set;
    if (r-l > 2019) {
        ans = 0;
    }
    else {
        for (int i=l; i<r; i++) {
            for (int j=i+1; j<=r; j++) {
                cnd = ((i%2019)*(j%2019)%2019);
                candidate_set.insert(cnd);

            }
        }

        ans = *candidate_set.begin();
    }

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



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

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

    string ans = "";

    for (int i = 0; i < s.size(); i++) {
        if (i % 2) continue;
        ans += s[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512