akhauriyash/Code-Regression huggingface dataset:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
INF = 10**10
def main(N, K, P, C):
    ans = max(C)
    for i in range(N):
        used = [False] * N
        now = 0
        mx = -INF
        cnt = 0
        while True:
            if used[i] or cnt >= K:
                break
            used[i] = True
            i = P[i] - 1
            now += C[i]
            mx = max(mx, now)
            cnt += 1
        tmp = max(mx, now)
        if now > 0:
            cycle, mod = divmod(K, cnt)
            if cycle > 1:
                tmp = max(tmp, now * (cycle - 1) + mx)
            t = now * cycle
            tmp = max(tmp, t)
            for j in range(mod):
                i = P[i] - 1
                t += C[i]
                tmp = max(tmp, t)
        ans = max(ans, tmp)
    print(ans)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, K = map(int, input().split())
    *P, = map(int, input().split())
    *C, = map(int, input().split())
    main(N, K, P, C)


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

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------
string to_string(string s) {
      return '"' + s + '"';
}
string to_string(const char* s) {
      return to_string((string) s);
}
string to_string(bool b) {
      return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
      return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
      bool first = true;  string res = "{";
      for (const auto &x : v) {
            if (!first) { res += ", "; }
            first = false; res += to_string(x);
      }
      res += "}";	  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
      cerr << " " << to_string(H);
      debug_out(T...);
}

// #define TRACE

#ifdef TRACE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
//============================================================================

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 4e5 + 2;


void solve() {
      int i = 0, j = 0, k = 0, n = 0, a,b,x,y,c;
      cin >> x >> y >> a >> b >> c;
      vi reds(a);
      vi blues(b);
      vi commons(c);
      fr(i,0,a) cin >> reds[i];
      fr(i,0,b) cin >> blues[i];
      fr(i,0,c) cin >> commons[i];

      sort(all(reds));
      sort(all(blues));
      sort(all(commons));

      priority_queue< int, vi, greater<int> > pq;
      for(i = a-1; i >= a-x; i--) {
            pq.push(reds[i]);
      }
      for(i=b-1; i>=b-y; i--) 
            pq.push(blues[i]);

      i = c - 1;
      while(i >= 0 and pq.top() < commons[i]) {
            pq.pop();
            pq.push(commons[i]);
            i--;
      }

      int ans = 0;
      while(!pq.empty()) {
            ans += pq.top();
            pq.pop();
      }
      cout << ans << endl;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }
      return 0;
}

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

using ll = long long;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	int n;
	cin >> n;
	ll sum = 0;
	int a;
	for(int i = 0; i < n; i++){
		cin >> a;
		sum += a - 1;
	}
	cout << sum << endl;
	return 0; 
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
const ll MOD = 1e9 + 7;

int main() {
    fastio;

    int n;
    cin >> n;
    int A[n];
    int values[100005] = {};
    FOR(i, 0, n) {
        cin >> A[i];
        values[A[i]]++;
        values[A[i]+1]++;
        values[A[i]+2]++;
    }
    int answer = 0;
    FOR(i, 0, 100005) {
        answer = max(answer, values[i]);
    }
    cout << answer << "\n";
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  map<int, int> L;
  int l;
  for (int i = 0; i < N; i++) {
    cin >> l;
    L[l]++;
  }
  
  vector<int> leng;
  for (auto m : L) {
    leng.push_back(m.first);
  }
  
  long ans = 0;
  int lim;
  if (leng.size() >= 3) {
  for (size_t i = 0; i < leng.size() - 2; i++) {
    for (size_t j = i+1; j < leng.size() - 1; j++) {
      lim = leng[i] + leng[j];
      for (size_t k = j+1; k < leng.size(); k++) {
        if (leng[k] >= lim) {
          break;
        }
        ans += L[leng[i]] * L[leng[j]] * L[leng[k]];
      }
    }
  }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef long double ld;


int main() {
    ll N, K;
    cin >> N;

    if(N >= 30){
        cout << "Yes" << endl;
        return 0;
    }
    else{
        cout << "No" << endl;
    }
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    while(true){
        string enc;
        cin >> enc;
        if(enc=="#") break;

        int num=0;
        set<string> s1,s2;
        function<void(const int,string&,vector<bool>&)> rec=[&](const int k,string &res,vector<bool> &done){
            if(k==enc.size()){
                ++num;
                s1.insert(res);
                s2.insert(res);
                if(s1.size()>10){
                    auto it=s1.end();
                    --it;
                    s1.erase(it);
                }
                if(s2.size()>10) s2.erase(s2.begin());
                return;
            }
            if(!done[enc[k]-'a'] and enc[k]!='z'){
                ++res[k];
                done[enc[k]-'a']=true;
                rec(k+1,res,done);
                --res[k];
                done[enc[k]-'a']=false;
            }
            if(enc[k]=='a' or done[enc[k]-'a'-1]) rec(k+1,res,done);
        };
        {
            string res=enc;
            vector<bool> done(26,false);
            rec(0,res,done);
        }

        cout << num << endl;
        if(num<=10) for(const auto &dec:s1) cout << dec << endl;
        else{
            {
                int i=0;
                for(auto it=s1.begin(); i!=5; ++i,++it) cout << *it << endl;
            }
            {
                int i=0;
                vector<string> ans;
                for(auto it=s2.rbegin(); i!=5; ++i,++it) ans.emplace_back(*it);
                reverse(ans.begin(),ans.end());
                for(const auto &tmp:ans) cout << tmp << endl;
            }
        }
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define MAX_K 7500000
int SIZE=7500000;
bool f[MAX_K];
int M,N;
int main()
{
	while(true){
		f[0]=1;f[1]=1;
		for(int i=2;i<7500000;i++){
			f[i]=0;
		}
		scanf("%d%d",&M,&N);
		if(M==0&&N==0){break;}
		while(true){
			if(!f[M]){
				N--;
				if(N<0){break;}
				for(int j=1;M*j<SIZE;j++){
					if(!f[M*j]){f[M*j]=true;}
				}
			}
			M++;
		}
		printf("%d\n",M);
	}
	return 0;
}



Measured memory_bytes: 10532
using System;


namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,,] Total = new int[4, 3, 10];
            for (int z = 0; z < 4; z++)
            {
                for (int y = 0; y < 3; y++)
                {
                    for (int x = 0; x < 10; x++)
                    {
                        Total[z, y, x] = 0;
                    }
                }
            }
            String N = Console.ReadLine();
            int n = int.Parse(N);
            for (int i = 0; i < n; i++)
            {
                String[] input = Console.ReadLine().Split(' ');
                 int b = int.Parse(input[0]) - 1;
                 int f = int.Parse(input[1]) - 1;
                 int r = int.Parse(input[2]) - 1;
                 int V = Total[b, f, r];
                 int v = int.Parse(input[3]);
                Total[b, f, r] = V + v;
            }
            for (int z = 0; z <4; z++)
            {
                for (int y = 0; y < 3; y++)
                {
                    for (int x = 0; x < 10; x++)
                    {
                        switch (z)
                        {
                            case 0:
                                Console.Write(" " + Total[z, y, x]);
                                break;
                            case 1:
                                Console.Write(" " + Total[z, y, x]);
                                break;
                            case 2:
                                Console.Write(" " + Total[z, y, x]);
                                break;
                            case 3:
                                Console.Write(" " + Total[z, y, x]);
                                break;
                        }
                    }
                    Console.WriteLine("");
                }
                if (z !=3)
                Console.WriteLine("####################");
            }
        }
    }
}

Measured memory_bytes: 9084
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	int work[8],count;
};

int H,W,word_num,loc[128];
char map[50][51],word_table[8];
bool isOK;


void func(){

	for(int i = 0; i < 128; i++)loc[i] = -1;
	word_num = 0;

	scanf("%d %d",&H,&W);
	for(int i = 0; i < H; i++){
		scanf("%s",map[i]);
		for(int k = 0; k < W; k++){
			if(map[i][k] != '.'){
				if(loc[map[i][k]-'0'] == -1){ //????????´?????´???
					loc[map[i][k]-'0'] = word_num;
					word_table[word_num] = map[i][k];
					word_num++;
				}
			}
		}
	}

	bool FLG = true;
	int most_left,most_right,most_top,most_bottom;
	char ch;

	for(int i = 0; i < word_num; i++){
		ch = word_table[i];

		most_left = 51,most_right = -1,most_top = 51,most_bottom = -1;

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				if(map[row][col] == ch){
					most_left = min(most_left,col);
					most_right = max(most_right,col);
					most_top = min(most_top,row);
					most_bottom = max(most_bottom,row);
				}
			}
		}

		for(int row = most_top; row <= most_bottom; row++){
			for(int col = most_left; col <= most_right; col++){
				if(map[row][col] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)break;
		}
	}

	if(!FLG){
		printf("SUSPICIOUS\n");
		return;
	}

	isOK = false;

	queue<Info> Q;

	Info first;
	first.count = 0;
	for(int i = 0; i < word_num; i++)first.work[i] = -1;
	Q.push(first);
	int rank;

	while(!Q.empty()){

		if(Q.front().count == word_num){

			FLG = true;

			for(int i = 0; i < word_num; i++){
				ch = word_table[i];
				rank = Q.front().work[i];

				most_left = 51,most_right = -1,most_top = 51,most_bottom = -1;

				for(int row = 0; row < H; row++){
					for(int col = 0; col < W; col++){
						if(map[row][col] == ch){
							most_left = min(most_left,col);
							most_right = max(most_right,col);
							most_top = min(most_top,row);
							most_bottom = max(most_bottom,row);
						}
					}
				}

				for(int row = most_top; row <= most_bottom; row++){
					for(int col = most_left; col <= most_right; col++){
						if(map[row][col] != ch){
							if(rank > Q.front().work[loc[map[row][col]-'0']]){
								FLG = false;
								break;
							}
						}
					}
					if(!FLG)break;
				}
			}

			if(FLG){
				isOK = true;
				break;
			}
		}

		for(int i = 0; i < word_num; i++){
			if(Q.front().work[i] == -1){
				Info next;
				for(int k = 0; k < 8; k++)next.work[k] = Q.front().work[k];
				next.work[i] = Q.front().count;
				next.count = Q.front().count+1;

				Q.push(next);
			}
		}

		Q.pop();
	}

	if(isOK){
		printf("SAFE\n");
	}else{
		printf("SUSPICIOUS\n");
	}
}


int main(){

	int num;
	scanf("%d",&num);

	for(int i = 0; i < num; i++)func();

	return 0;
}

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

int main() {
  ll H,N,sum;cin>>H>>N;
  sum = 0;
  int A[N];
  rep(i,N){
    cin>>A[i];
    sum += A[i];
  }
  if(sum>=H) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 640
n, m = list(map(int, input().split(" ")))
h_list = list(map(int, input().split(" ")))
t = [[0] for _ in range(n)]
for i in range(m):
    a, b = list(map(int, input().split(" ")))
    t[a - 1].append(h_list[b - 1])
    t[b - 1].append(h_list[a - 1])
cnt = 0
for h, others in zip(h_list, t):
   if h > max(others):
       cnt += 1
print(cnt)

Measured memory_bytes: 25908
#include <cmath>
    #include <iostream>
    #include <algorithm>
    #include <vector>
     
    #define INT_MAX 1000000
     
    using namespace std;
     
    /*vector<int> getallCoins()
    {
    	vector<int> ans;
    	ans.push_back(1);
    	ans.push_back(6);
    	int number{6 };
    	while (ans.back() < 100000)
    	{
    		ans.push_back(ans.back()*number);
    	}
    	ans.push_back(9);
    	number = 9;
    	while (ans.back() < 100000)
    	{
    		ans.push_back(ans.back()*number);
    	}
    	return ans;
    }*/
     
    int minCoins(vector<int> coins, int m, int V)
    {
    	vector<int> table(V + 1);
    	table[0] = 0;
    	for (int i = 1; i <= V; i++)
    		table[i] = INT_MAX;
    	for (int i = 1; i <= V; i++)
    	{
    		for (int j = 0; j<m; j++)
    			if (coins[j] <= i)
    			{
    				int sub_res = table[i - coins[j]];
    				if (sub_res != INT_MAX && sub_res + 1 < table[i])
    					table[i] = sub_res + 1;
    			}
    	}
    	return table[V];
    }
     
    int main()
    {
    	//vector <int> coins2 = getallCoins();
    	vector<int> coins = { 1,6,9,36,81,216,729,1296,6561,7776,46656,59049,279936,531441 };
    	int m = coins.size();
    	int V;
    	cin >> V;
    	cout << minCoins(coins, m, V) << "\n";
    	
    	return 0;
    }

Measured memory_bytes: 640
#define DEBUG 0

/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-5-28 11:35:20
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

map<char, char> M;

int main()
{
  M['A'] = 'T';
  M['T'] = 'A';
  M['G'] = 'C';
  M['C'] = 'G';
  char c;
  cin >> c;
  cout << M[c] << endl;
}

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

int main(){
  string s;
  std::cin >> s;
  if((s[0]==s[1] && s[0]==s[2])||(s[1]==s[2] && s[1]==s[3])) return 0*printf("Yes\n");
  printf("No\n");
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a1(n);
    vector<int> a2(n);
    for(int i = 0; i < n; i++){
        cin >> a1[i];
        if(i == 0){
            continue;
        }
        else{
            a1[i] += a1[i - 1];
        }
    }
    for(int i = 0; i < n; i++){
        cin >> a2[i];
    }

    for(int i = 0; i < n - 1; i++){
        a2[n - 2 - i] += a2[n - 1 - i];
    }
    int result = 0;
    for(int i = 0; i < n; i++){
        result = max(result, a1[i] + a2[i]);
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

template<int mod> struct ModInt{
    long long x=0; 
    constexpr ModInt(long long x=0):x((x%mod+mod)%mod){}
    constexpr ModInt operator+(const ModInt& r)const{return ModInt(*this)+=r;}
    constexpr ModInt operator-(const ModInt& r)const{return ModInt(*this)-=r;}
    constexpr ModInt operator*(const ModInt& r)const{return ModInt(*this)*=r;}
    constexpr ModInt operator/(const ModInt& r)const{return ModInt(*this)/=r;}
    constexpr ModInt& operator+=(const ModInt& r){ if((x+=r.x)>=mod) x-=mod; return *this;}
    constexpr ModInt& operator-=(const ModInt& r){ if((x-=r.x)<0) x+=mod; return *this;}
    constexpr ModInt& operator*=(const ModInt& r){ if((x*=r.x)>=mod) x%=mod; return *this;}
    constexpr ModInt& operator/=(const ModInt& r){ return *this*=r.inv();}
    ModInt inv() const {
        long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1;
        while(s%t!=0){
            long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty;
            s=t;sx=tx;sy=ty;
            t=u;tx=ux;ty=uy;
        }
        return ModInt(tx);
    }
    ModInt pow(long long n) const {
        ModInt a=1;
        while(n>0){
            if(n&1) a*=*this;
            *this*=*this;
            n>>=1;
        }
        return a;
    }
    friend constexpr ostream& operator<<(ostream& os,const ModInt<mod>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<mod>& a) {return is >> a.x;}
};
using mint = ModInt<MOD>;

struct combination{
    int N;
    vector<mint> fac,finv,inverse;
    combination(int N):N(N){
        fac.resize(N+1);finv.resize(N+1);
        fac[0]=1;
        for(int i=1;i<=N;++i){fac[i]=fac[i-1]*i;}
        finv[N]=fac[N].inv();
        for(int i=N-1;i>=0;--i){finv[i]=finv[i+1]*(i+1);}
    }
    void inverse_build(){
        inverse.resize(N+1);
        inverse[1]=1;
        for(int i=2;i<=N;++i){inverse[i]=finv[i]*fac[i-1];}
    }
    mint c(int n,int k){
        if(n<k||n<0||k<0) return 0;
        return fac[n]*finv[n-k]*finv[k];
    }
    mint p(int n,int k){
        if(n<k||n<0||k<0) return 0;
        return fac[n]*finv[n-k];
    }
};

int main(){
    combination com(1000000);
    int x,y;
    cin >> x >> y;
    mint ans = 0;
    if(2*y-x<0||2*x-y<0);
    else if((2*y-x)%3 != 0 || (2*x-y)%3 != 0);
    else{
        int s = (2*x-y)/3;
        int t = (2*y-x)/3;
        ans = com.c(s+t,s);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18660
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

int main() {
	ll N, M; cin >> N >> M;
	vector<ll> X(M); rep(i, M)cin >> X[i];
	sort(ALL(X));

	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}

	vector<ll> dis(M - 1);
	rep(i, M - 1) dis[i] = X[i + 1] - X[i];

	sort(ALL(dis));
	reverse(ALL(dis));

	ll a = X[M - 1] - X[0];
	ll b = 0;
	for (int i = 0; i < N -1; i++) b += dis[i];

	cout << a - b << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main(){
    cin>>a>>b>>c>>d;
    if(min(max(max(b-a,a-b),max(c-b,b-c)), max(c-a,a-c)) <= d)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    int ans = 0;
    while (n > 0) {
        n /= k;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using ll = long long;
const int maxn = 2020, mod = 924844033;
int n, k, dp[maxn][maxn][4], np[maxn], f1[maxn], f2[maxn], bp[maxn], fact[maxn];
void calc1() {
	fact[0] = 1;
	for(int i = 1; i < maxn; i++) fact[i] = fact[i-1]*1ll*i%mod;
}
void add(int &a, int b) {
	a += b;
	if(a >= mod) a -= mod;
}
void calc2() {
	dp[0][0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int tk = 0; tk <= i; tk++) {
			for(int m = 0; m < 4; m++) {
				add(dp[i+1][tk][m/2], dp[i][tk][m]);
				add(dp[i+1][tk+1][2 + m/2], dp[i][tk][m]);
				if((m&1) == 0 && i) add(dp[i+1][tk+1][m/2], dp[i][tk][m]);
			}
		}
	}
	int a = n/k;
	for(int tk = 0; tk <= a; tk++)
		for(int m = 0; m < 2; m++)
			add(f1[tk], dp[a][tk][m]);
	a = (n+k-1)/k;
	for(int tk = 0; tk <= a; tk++)
		for(int m = 0; m < 2; m++)
			add(f2[tk], dp[a][tk][m]);
	swap(f1, f2), a = (n+k-1)/k;
	bp[0] = 1;
	for(int f = 0, i = 0; i < k; i++) {
		if(i == (n%k)) swap(f1, f2), a = (n+k-1)/k;
		//cout << i << " " << a << '\n';
		for(int j = n; j >= 0; j--) 
		for(int k = a; k >= 0; k--)
			if(bp[j]) add(np[j+k], bp[j]*1ll*f1[k]%mod);
		for(int i = 0; i <= n; i++) {
			bp[i] = np[i];
			np[i] = 0;
		}
	}
	for(int i = 0; i <= n; i++) {
		//cout << i << " - " << bp[i] << '\n';
		bp[i] = bp[i]*1ll*fact[n-i]%mod;
		//cout << i << " " << bp[i] << '\n';
	}
}
void calc3() {
	int ans = 0;
	for(int i = 0; i <= n; i++) {
		if(i&1) ans = (mod + ans - bp[i])%mod;
		else ans = (ans + bp[i])%mod;
	}
	cout << ans;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> k;
	calc1();
	calc2();
	calc3();
}


Measured memory_bytes: 62080
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll n, q;
    cin >> n >> q;
    const ll mod = 998244353;
    vector<vector<ll>> acc(10, vector<ll>(n + 2));

    REP(i, 1, 10)
    {
        REPR(j, n, 0)
        {
            acc[i][j] = (acc[i][j + 1] * 10 + i) % mod;
        }
    }

    ll ans = acc[1][1];

    set<ll> seg_r;
    map<ll, pair<ll, ll>> seg;
    seg_r.insert(n + 1);
    seg[n + 1] = make_pair(1, 1);

    REP(_, 0, q)
    {
        ll l, r, d;
        cin >> l >> r >> d;
        ++r;

        auto itr = seg_r.upper_bound(l);
        while (itr != seg_r.end() && seg[*itr].first < r)
        {
            ll l2 = seg[*itr].first, r2 = *itr, d2 = seg[*itr].second;
            ans = (ans - (acc[d2][l2] - acc[d2][r2]) + mod) % mod;
            seg.erase(*itr);
            seg_r.erase(*itr);

            if (l2 < l)
            {
                ll nr = l;
                seg_r.insert(nr);
                seg[nr] = make_pair(l2, d2);
                ans = (ans + (acc[d2][l2] - acc[d2][nr]) + mod) % mod;
            }
            if (r < r2)
            {
                ll nl = r;
                seg_r.insert(r2);
                seg[r2] = make_pair(nl, d2);
                ans = (ans + (acc[d2][nl] - acc[d2][r2]) + mod) % mod;
            }

            itr = seg_r.upper_bound(l);
        }

        seg_r.insert(r);
        seg[r] = make_pair(l, d);
        ans = (ans + (acc[d][l] - acc[d][r]) + mod) % mod;
        cout << ans << "\n";
    }
}

Measured memory_bytes: 40644
import java.util.Scanner;

class Solver {
    public void Solve() {
        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            System.out.print("x");
        }
        System.out.println();
    }

    Scanner sc;

    Solver(Scanner in) {
        this.sc = in;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Solver s = new Solver(sc);
        s.Solve();
        sc.close();
    }
}

Measured memory_bytes: 22996
#include<stdio.h>
int main(){
	int t,h,m,s;
	scanf("%d",&t);
	h=t/3600;
	m= (t-h*3600)/60;
	s=t-h*3600-m*60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func NextStr() string {
	scanner.Scan()
	return scanner.Text()
}

func NextInt() int {
	i, _ := strconv.Atoi(NextStr())
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

type UnionFind struct {
	roots []int
	sizes []int
	ranks []int
}

func NewUnionFind(n int) UnionFind {
	roots := make([]int, n)
	sizes := make([]int, n)
	ranks := make([]int, n)
	for i := 0; i < n; i++ {
		roots[i] = i
		sizes[i] = 1
		ranks[i] = 1
	}
	return UnionFind{roots, sizes, ranks}
}

func (u *UnionFind) Root(x int) int {
	if u.roots[x] == x {
		return x
	}
	u.roots[x] = u.Root(u.roots[x])
	return u.roots[x]
}

func (u *UnionFind) Unite(x, y int) {
	if u.Same(x, y) {
		return
	}

	x = u.Root(x)
	y = u.Root(y)

	if u.Rank(x) > u.Rank(y) {
		x, y = y, x
	}

	u.sizes[x] += u.Size(y)

	u.roots[y] = x
	if u.Rank(x) == u.Rank(y) {
		u.ranks[x]++
	}
}

func (u *UnionFind) Rank(x int) int {
	return u.ranks[u.Root(x)]
}

func (u *UnionFind) Size(x int) int {
	return u.sizes[u.Root(x)]
}

func (u *UnionFind) Same(x, y int) bool {
	if u.Root(x) == u.Root(y) {
		return true
	}
	return false
}

func main() {
	scanner.Split(bufio.ScanWords)
	n, m := NextInt(), NextInt()
	u := NewUnionFind(n)
	for i := 0; i < m; i++ {
		a, b := NextInt()-1, NextInt()-1
		u.Unite(a, b)
	}
	var ans int

	for i := 0; i < n; i++ {
		ans = max(ans, u.Size(i))
	}
	fmt.Println(ans)
}


Measured memory_bytes: 25384
#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 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);
    string s,t; cin>>s>>t;
    int ans=0;
    rep (i,3) if (s[i]==t[i]) ans++;
    cout<<ans<<endl;
    return 0;
}


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

#define int long long int
#define main signed main()
#define bye return 0

#define rep(i, n) for (int i = 0; i < (n); i++)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define sum(v) accumulate(all(v), 0)
#define cinv(v, n) rep(i, n) cin >> v[i]
#define prec(n) fixed << setprecision(n)
#define odd(n) ((n) % 2)
#define even(n) (!((n) % 2))

#define INF 1e9
#define MOD (1e9 + 7)

#define pb push_back
#define mt make_tuple
#define fi first
#define se second
#define str string
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<str>

using namespace std;

main {
  int a, b, c;
  cin >> a >> b >> c;
  cout << ((even(a) || even(b) || even(c)) ? 0 : min({a * b, b * c, c * a}))
       << endl;
  bye;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()


int main(){
  int x,y;
  cin >> x >> y;

  cout << x+(y/2);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=0 && a<=5)
        cout<<"0\n";
    else if(a>=6 && a<=12)
        cout<<b/2<<endl;
    else
        cout<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
K = int(input())
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
tmp_sum = 0
for i in range(1,K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      if i != j and j != k:
        tmp_list = [i,j,k]
        tmp_sum += gcd_list(tmp_list)*6
      elif i == j and j == k:
        tmp_list = [i,j,k]
        tmp_sum += gcd_list(tmp_list)
      else:
        tmp_list = [i,j,k]
        tmp_sum += gcd_list(tmp_list)*3
print(tmp_sum)


Measured memory_bytes: 9632
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    int n;
    while(sf("%d",&n)==1)
    {
        int h[n+5];
        for(int i=0;i<n;i++)sf("%d",&h[i]);

        int ini[n+5];
        memset(ini,0,sizeof ini);
        int op=0;
        while(1)
        {
            //for(int i=0;i<n;i++)pf("%d ",ini[i]);
            //nl;
            bool f=true;
            for(int i=0;i<n;i++)
            {
                if(h[i]!=ini[i])
                {
                    f=false;
                    break;
                }
            }
            if(f)break;


            int l=0,r=0,mn=500;
            for(int i=0;i<=n;i++)
            {
                if(i==n || ini[i]==h[i])
                {
                    for(int j=l;j<=r;j++)
                    {
                        if(mn!=500)ini[j]+=mn;
                    }
                    if(mn!=500)op+=mn;
                    mn=500;
                    l=i+1;
                    r=i+1;
                }
                else
                {
                    r=i;
                    mn=min(mn,h[i]-ini[i]);
                }
            }
        }
        pf("%d\n",op);
    }   
    return 0;
}
 









 




























Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define ld          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define pi          3.14159265358979323

bool comp(pair<string,ll>a, pair<string,ll>b)
{
       if(a.F != b.F) return a.F < b.F;
       else return a.S > b.S;
}


void solve()
{
       ll n;
       cin>>n;
       pair<string,ll>res[n],tmp[n];
       rep(i,0,n)
       {
              cin>>res[i].F>>res[i].S;
              tmp[i] = res[i];
       }
       sort(res, res+n, comp);
       ll ans[n];
       for(ll i=0; i<n; i++)
       {
              for(ll j=0; j<n; j++)
              {
                     if(res[j]==tmp[i])
                     { ans[j] = i+1; break;}
              }
       }
       rep(i,0,n) cout<<ans[i]<<endl;
}

int main()
{
       speed_up;
       //pre();
       ll T=1;
       //cin>>T;
       while(T--) solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define forn(i,n) for(int i = 0; i< n;++i)
ll MOD = 1e9 + 7;
ll dp(int mask,int women_num,vector<vector<int>>& comp,int target,int n,vector<vector<int>>& save){
		if (save[mask][women_num] != -1){
			return save[mask][women_num];
		}
		if (mask == target){
			save[mask][women_num] = 1;
			return 1;
		}
		if(women_num == n){
			return 0;
		}
		ll ans = 0;
		for(int men =  0;men < n; ++men){
			if(((mask >> men) & 1 )== 0 && comp[men][women_num] == 1){
					ans += dp(mask | (1 << men), women_num+1,comp,target,n,save);
					ans %= MOD;
				}
			}
		save[mask][women_num] = ans%MOD;
		return ans%MOD;
	}

int main() {
	int n;
	cin >> n;
	vector<vector<int>> comp;
	vector<int> app;
	for(int men =0 ;men < n; ++men){
		for(int women = 0; women < n; ++women){
			int temp;
			cin >> temp;
			app.push_back(temp);
		 }
		 comp.push_back(app);
		 app.clear();
	 }
	 //cout << "done";
	vector<vector<int>> save(((1<<n) + 1),vector<int>(n+1,-1));
	int target = (1 << n) - 1; 
	cout << dp(0,0,comp,target,n,save)%MOD << endl;
}


Measured memory_bytes: 246144
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cstring>
#include <functional>
#include <iostream>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <array>
#include <complex>

#define endl '\n'

using namespace std;

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

    int n;
    cin >> n;

    cout << 360 / gcd(n, 360) << endl;

    return 0;
}


Measured memory_bytes: 3196
#include <iostream>
using namespace std;
int a,b,cnt=1;
int main(){
	cin>>a>>b;
  	if (a<b){
    	cout<<cnt;
      	return 0;
    }
  	else{
  	while(a>b){
    	a = a-b;
      	cnt++;
    }
   }
  	cout<<cnt;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      k: usize,
      aa: [usize; n],
    }
    let half = n/2 + n%2;
    let mut d = 0;
    while 1 << (d+1) <= k {
        d += 1;
    }

    let mut v_max = 0;
    for dd in (0..d+1).rev() {
        let v = 1 << dd;
        let mut cnt = 0;
        for i in 0..n {
            if aa[i] & v > 0 {
                cnt += 1;
            }
        }

        if cnt < half {
            if v + v_max <= k {
                v_max += v;
            }
        }
    }

    let mut ans = 0;
    for i in 0..n {
        ans += aa[i] ^ v_max;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n;
int as=0;
int solve(int x){
    int m=n;
    while(m%x==0)m/=x;
    return (m%x==1?1:0);
}
signed main(){
    cin>>n;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            if(i!=1)as+=solve(i);
            if(i*i!=n)as+=solve(n/i);
        }
    }
    for(int i=1;i*i<=n-1;i++){
        if((n-1)%i==0){
            if(i!=1)as+=solve(i);
            if(i*i!=(n-1))as+=solve((n-1)/i);
        }
    }
    cout<<as<<endl;
    return 0;
}


Measured memory_bytes: 256
def pow_mod(x, y, mod=10**9 + 7):
    if y == 0:
        return 1
    res = 1
    for i in range(y.bit_length()):
        if y & (1 << i):
            res *= x
            res %= mod
        x *= x
        x %= mod
    return res


def calc(r):
    if r <= 1:
        return 3
    return pow_mod(3, r-1) * 2

l = input()
n = len(l)
mod = 10**9 + 7

count = [0] * (n+1)
for i in range(1, n+1):
    count[i] = calc(i) + count[i-1]

ans = 0
cnt = 0
u = n
for i in range(n):
    u -= 1
    if i == n-1:
        if l[i] == "1":
            ans += 3 * pow_mod(2, cnt) % mod
            ans %= mod
        else:
            ans += pow_mod(2, cnt) % mod
            ans %= mod
        continue
    if l[i] == "1":
        # 0
        ans += count[u] % mod * pow_mod(2, cnt) % mod
        ans %= mod
        # 1
        cnt += 1
        pass
    else:
        pass

print(ans%mod)





Measured memory_bytes: 14576
/*
          Life before Death
          Strength before Weakness
          Journey before Destination
    */
    
    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define rep(i,a,n) for(ll i=a;i<n;i++)
    #define per(i,n,a) for (ll i=n;i>a;i--)
    #define te ll t; std::cin >> t; while(t--)
    #define SZ 1000010
    //#define M_PI  3.141592653589793238462643383279502884L
    /*------Just DO IT--------------------------------------*/

    ll solve(){
      ll a,b,c;
      cin>>a>>b>>c;
      ll ans = b + min(a+b+1 , c);
      cout<<ans<<endl;
    } 
    
   int main() {
       fastio
       solve();
    }

Measured memory_bytes: 256
#include <stdio.h>

int exchanges(int A, int B, int C)
{
  int count = 0;
  int tempA,tempB,tempC;
  while((A % 2 == 0 && B % 2 == 0) && (C % 2 == 0))
  {
    tempA = A/2;
    tempB = B/2;
    tempC = C/2;
    A = tempB + tempC;
    B = tempA + tempC;
    C = tempA + tempB;
    count++;
    if (A == B && B == C){
      count = -1;
      break;
    }
  }
  return count;
}

int main()
{
  int A,B,C,result;
  scanf("%d %d %d", &A, &B, &C);
  result = exchanges(A,B,C);
  printf("%d\n",result);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int n, q; cin >> n >> q;
    int a, v;
    int d[1000001]; memset(d, 0, sizeof(d));
    priority_queue<pii> pq;
    rep(i,0,q) {
        cin >> a >> v;
        d[a] += v;

        pq.push(pii(d[a], -a));

        // ?????¨?????????????????????????´?????¶????
        while(!pq.empty()) {
            pii p = pq.top();
            if(p.first == d[-p.second]) {
                cout << -p.second << " " << p.first << endl;
                break;
            }
            pq.pop();
        }
    }
    return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  vll a(n), b(n), c(n);
  rep(i,n){
    cin>>a[i]>>b[i]>>c[i];
  }
  
  ll ans=0;
  rep(i,2){
    rep(j,2){
      rep(k,2){
        vll d(n);
        rep(ki,n){
          ll sum=0;
          sum+=i?-a[ki]:a[ki];
          sum+=j?-b[ki]:b[ki];
          sum+=k?-c[ki]:c[ki];
          d[ki]=sum;
        }
        sort(d.rbegin(),d.rend());
        ll tmp=0;
        rep(i,m) tmp+=d[i];
        chmax(ans,tmp);
      }
    }
  }
  
  cout<<ans<<endl;
  
 }

Measured memory_bytes: 256