akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <queue>
#include <list>
#include <functional>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;


//ノードkについて，親ノードはk/2,子ノードは2k,2k+1
template< typename Monoid >
struct SegmentTree {
    using F = function< Monoid(Monoid, Monoid) >;
    
    int sz;
    vector< Monoid > seg;
    
    const F f;
    const Monoid M1;
    
    //コンストラクタ
    //サイズn，区間の要素をマージする関数f,単位元M1
    //単位元　演算に関して値が変わらないやつ　x * 1 = 1 * x = x, x + 0 = 0 + x = x　
    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while(sz < n) sz <<= 1; //シフト演算子 左に1ビットずらすから2倍
        seg.assign(2 * sz, M1);
    }
    
    // k番目の要素にxを代入
    void set(int k, const Monoid &x) {
        seg[k + sz] = x;
    }
    
    // セグメント木を構築
    void build() {
        for(int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }
    
    // k番目の要素をxに変更
    void update(int k, const Monoid &x) {
        k += sz;
        seg[k] = x;
        while(k >>= 1) {
        seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }
    
    // 区間[a,b)に関して演算fをした結果を返す
    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
        if(a & 1) L = f(L, seg[a++]);
        if(b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }
    
    // k番目の要素を返す
    Monoid operator[](const int &k) const {
        return seg[k + sz];
    }
};

int main(){
    ll N, K;
    cin >> N >> K;
    SegmentTree <ll> seg1(N, [](ll a, ll b){return min(a, b); }, 300000 );
    SegmentTree <ll> seg2(N, [](ll a, ll b){return max(a, b); }, 0 );

    vector<ll> v(N);
    for(int i = 0; i < N; i++){
        cin >> v[i];
        seg1.update(i, v[i]);
        seg2.update(i, v[i]);
    }

    // 単調増加区間の確認
    vector <ll> add(N);
    //cout << add[0] << " ";
    for(int i = 1; i < N ; i++){
        add[i] = add[i-1];
        if(v[i] > v[i-1] ) add[i] ++;
        //cout << add[i] << " ";
    }
    //cout << endl;



    ll ans = 1;
    bool flag = false;
    if(add[K - 1]  - add[0] == K - 1) flag = true;
    for(int i = 1; i < N - K + 1; i++){
        ll out = v[i - 1];
        ll in  = v[i + K - 1];
        ll mini = seg1.query(i, i + K);
        ll maxi = seg2.query(i, i + K);
        if(mini > out && maxi == in) continue;
        if(add[i + K - 1] - add[i] == K - 1) {
            if(flag) continue;
            else {
                ans ++;
                flag = true;
                continue;

            }
        }
        ans ++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 11520
def getlist():
	return list(map(int, input().split()))

#初期化
N, K = getlist()
A = getlist()
S = sum(A)
n = int((S ** 0.5) // 1) + 1
gcd = []
for i in range(1, n):
	if S % i == 0:
		gcd.append(i)
x = len(gcd)
for i in range(x):
	gcd.append(S // gcd[i])
gcd = sorted(gcd)

#計算
ans = 1
for i in gcd:
	P = []
	for j in A:
		x = j % i
		if x != 0:
			P.append([x, i - x])
	P = sorted(P)
	a = 0
	b = 0
	for j in range(len(P)):
		a += P[j][0]
	s = 0
	for j in range(len(P)):
		a -= P[-1 - j][0]
		b += P[-1 - j][1]
		s += P[-1 - j][1]
		if a == b:
			break
	if s <= K:
		ans = i

print(ans)

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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    double n, m, d, k = 2.0; cin >> n >> m >> d;
    if(!d) k = 1.0;
    cout << fixed << setprecision(12) << (m-1) * ((k * (n - d)) / (n * n));    
}

Measured memory_bytes: 3796
# vim: fileencoding=utf-8


def main():
    s = input()
    c = ["dreamer", "dream", "erase", "eraser"]
    n = [7, 5, 5, 6]
    while True:
        f = True
        for i in range(4):
            if s[-n[i] :] == c[i]:
                f = False
                s = s[: -n[i]]
                break
        if f:
            if len(s) == 0:
                print("YES")
            else:
                print("NO")
            return


if __name__ == "__main__":
    main()


Measured memory_bytes: 78128
s = input()

cont=0

if s[0]=="R" and s[1]=="R" and s[2]=="R":
    cont=3
elif s[0]=="R" and s[1]=="R":
    cont=2
elif s[1]=="R" and s[2]=="R":
    cont=2

elif s[0]=="R" or s[1]=="R" or s[2]=="R":
    cont=1
else:
    cont=0
print(cont)


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n;
	cin>>n;

	set<lli> s;
	REP(i,0,n){
		lli a;
		cin>>a;
		s.insert(a);
	}

	if(s.size()%2==0)cout<<s.size()-1<<endl;
	else cout<<s.size()<<endl;

	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e5+10;
int main()
{
    FASTINOUT;
    ll x;
    cin>>x;
    ll m=log2(x)+1;
    cout<<fixed<<setprecision(0)<<powl(2,m)-1<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>

using namespace std;

int main(int argc, char *argv[]) {
	int n, m;
	cin >> n >> m;
	cout << (n - 1) * n / 2 + (m - 1) * m / 2 << endl;
}









Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	ans := 0
	var dfs func(i, cur, tmp int)
	dfs = func(i, cur, tmp int) {
		if i > len(s)-1 {
			ans += (cur + tmp)
			return
		}
		dfs(i+1, cur, (tmp*10)+int(s[i]-'0'))
		dfs(i+1, cur+tmp, int(s[i]-'0'))
	}

	dfs(1, 0, int(s[0]-'0'))
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int H, W, K; cin >> H >> W >> K;
	vector<vector<int> > a(H, vector<int>(W));
	rep(y, H) {
		string s; cin >> s;
		rep(x, W) a[y][x] = s[x] - '0';
	}
	ll ma = 0;
	rep(y0, H) rep(x0, W) {
		vector<vector<int> > b = a;
		b[y0][x0] = 0;
		ll ans = 0;
		rep(t, 32) {
			rep(x, W) {
				int _y = H - 1;
				for (int y = H - 1; y >= 0; y--)
					if (b[y][x]) {
						int tmp = b[y][x];
						b[y][x] = 0;
						b[_y--][x] = tmp;
					}
			}
			rep(y, H) {
				vector<int> v;
				v.pb(0);
				for (int x = 1; x <= W - 1; x++)
					if (!b[y][x - 1] || !b[y][x] || b[y][x - 1] != b[y][x])
						v.pb(x);
				v.pb(W);
				for (int k = 0; k + 1 < v.size(); k++) {
					int l = v[k], r = v[k + 1];
					if (r - l < K) continue;
					for (int x = l; x < r; x++) {
						ans += b[y][x] * (1LL<<t);
						b[y][x] = 0;
					}
				}
			}
		}
		ma = max(ma, ans);
	}
	cout << ma << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <queue>

using namespace std;

	int TIME = 0;
	int d[101];
	int num;
	int graph[101][101] = {0};

int main(){
	int hon;
	int eda;
	int ver;
	queue<int> QUE;

	cin>>num;

	for(int i=1;i<=num;i++)
		d[i] = -1;

	for(int i=0;i<num;i++){
		cin>>eda;
		cin>>hon;
		for(int j=0;j<hon;j++){
			cin>>ver;
			graph[eda][ver]++;
		}
	}
	QUE.push(1); //start
	d[1] = 0;

	do{
		ver = QUE.front();
		QUE.pop();
		for(int i=1;i<=num;i++){
			if(graph[ver][i] == 1 && d[i]==-1){
				d[i] = d[ver] + 1;
				QUE.push(i);
			}
		}
	}while(!QUE.empty());
		
	for(int i=1;i<=num;i++){
		cout<<i<<" "<<d[i]<<endl;
	}

	return 0;
}

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

int main() {
  long long N;
  long long A, B;
  
  cin >> N >> A >> B;
  
  long long m = N/(A+B);
  
  long long ans;
  if(N%(A+B)<=A){
  	ans = A*m + N%(A+B);
  }else{
    ans = A*m+A;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
flag = "Yes"
#print(h)

h[0] -= 1

for i in range(0, n-1):
    if h[i+1] - h[i] > 0:
        h[i+1] -= 1

#print(h)

for j in range(0, n-1):
    if h[j+1] - h[j] < 0:
        flag = "No"

print(flag)


Measured memory_bytes: 14396
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#pragma GCC optimize("unroll-loops")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define ST string
#define BS bitset
#define VE vector
#define VL vector<LL>
#define VP vector<pair<LL,LL>>
#define VVL vector<vector<LL>>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define EB emplace_back
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define LB(a,n) *lower_bound(ALL(a),n)
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
//#define ERR 0.00000000000001
#define NUM 200010
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)printf("Yes\n");else printf("No\n");}
void YN(LL a){if(a)printf("YES\n");else printf("NO\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(m,d);x-=k*y;swap(x,y);}return mod(a*mod(x,MOD),MOD);}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(pair<LL,LL> a,pair<LL,LL> b){if(a.second!=b.second)return a.second<b.second;return a.first<b.first;}

int main(){
  FAST;
  LL i,j,N,K,C,f;
  string S;
  VL a,b;
  cin>>N>>K>>C>>S;
  rep(i,N)if(S[i]=='o'){
    a.EB(i+1);
    i+=C;
  }
  if(K<a.size())return 0;
  for(i=N-1;i>=0;i--)if(S[i]=='o'){
    b.EB(i+1);
    i-=C;
  }
  SORT(b);
  rep(i,a.size())if(a[i]==b[i])cout<<a[i]<<endl;
}


Measured memory_bytes: 5128
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 4e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


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

int a, b;
main() {
  file("threesum");
  ios;
  cin >> a >> b;
  fo(i, 1, 1e5, 1) {
    double A = (i * 0.08);
    double B = (i * 0.1);
    if (floor(A) == a and floor(B) == b) return !(cout<<i);
  }
  cout<<-1;
  return 0;
}
/**

*/


Measured memory_bytes: 256
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main(){
	ll N, A, B;
	cin >> N >> A >> B;

	ll d = N / (A + B);
	ll m = N % (A + B);

	if (m > A) m = A;

	ll ans = d * A + m;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Reader sc = new Reader();
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            int n = sc.nextInt();
            int[] a = new int[n];
            for(int i=0 ; i<n ; i++) {
                a[i] = sc.nextInt();
            }

            Arrays.sort(a);

            int count = 0;
            for(int i=0 ; i<n ; i++) {
                for(int j=i+1 ; j<n ; j++) {
                    for(int k=j+1 ; k<n ; k++) {
                        if(a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) {
                            if(a[i] + a[j] > a[k]) {
                                count++;
                            }
                        }
                    }
                }
            }

            pw.println(count);
        }
        finally {
            pw.flush();
            pw.close();
        }
    }
    
    static class Reader {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while(!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException io) {
                    io.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 33512
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int N = 105, V = 1e5+10;
inline char get() {
	static char buf[10000], *S = buf, *T = buf;
	if (S == T) {
		T = (S = buf) + fread(buf, 1, 10000, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}
inline void read(int &x) {
	static char c; x = 0; int sgn = 0;
	for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
	for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
	if (sgn) x = -x;
}

int n, totw;
ll dp[V];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  read(n); read(totw);
  memset(dp, INFLL, sizeof dp);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    int w, v; read(w); read(v);
    for (int j = V-1; j >= v; j--) {
      dp[j] = min(dp[j], dp[j-v] + w);
    }
  }
  int ans = 0;
  for (int i = 0; i < V; i++) {
    if (dp[i] <= totw) ans = i;
  }
  cout << ans << nl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    map<int, int> v;
    vector<int> vv(m);
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        v[x] = i+1;
        vv[i] = x-1;
    }
    vector<vector<int>> G(n, vector<int>(k, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < k; ++j) {
            cin >> G[i][j];
        }
    }
    vector<vector<int>> u(1<<m);
    for (int i = (1<<m)-1; i >= 0; --i) {
        for (int j = 0; j < k; ++j) {
            int to = 0;
            for (int l = 0; l < m; ++l) {
                if((i & (1<<l)) && v[G[vv[l]][j]]){
                    to |= (1 << (v[G[vv[l]][j]]-1));
                }
            }
            u[i].emplace_back(to);
        }
    }
    vector<int> dp(1<<m, MOD);
    queue<int> Q;
    Q.emplace((1<<m)-1);
    dp.back() = 0;
    while(!Q.empty()){
        int x = Q.front(); Q.pop();
        for (auto &&i : u[x]) {
            if(dp[x]+1 < dp[i]){
                dp[i] = dp[x]+1;
                Q.emplace(i);
            }
        }
    }
    cout << dp.front() << "\n";
    return 0;
}


Measured memory_bytes: 38788
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	limit := 22

	for i := 0; i < 3; i++ {
		scanner.Scan()
		target, err := strconv.Atoi(scanner.Text())
		if err != nil {
			log.Fatal(err)
		}
		limit -= target

		if limit <= 0 {
			fmt.Println("bust")
			os.Exit(0)
		}
	}

	fmt.Println("win")
}


Measured memory_bytes: 1836
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    vector<long int> a,b;
    for(int i=0,j; i<n; i++){
      cin >>j;
      a.push_back(j);
      if(i != 0) a[i]+=a[i-1];
    }
    b.push_back(0);
    for(int i=0; i<n; i++) b.push_back(min(b[i],a[i]));
    long int ans = a[0];
    for(int i=1; i<n; i++) ans = max(ans,a[i]-b[i]);
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1300
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

const MOD: u64 = 1_000_000_007;

fn main() {
    input! {
        n: u64,
        k: u64,
    }

    let mut ans = 0;

    for i in k..=n + 1 {
        let a = i * n % MOD;
        let b = i * (i - 1) % MOD;

        let ptn = if a > b {
            (a - b + 1) % MOD
        } else {
            (MOD + a - b + 1) % MOD
        };

        ans = (ans + ptn) % MOD;
    }

    println!("{}", ans);
}

// aのn乗を求める。繰り返し二乗法によりO(logN)で計算できる
fn mod_pow(a: u64, n: u64, mod_n: u64) -> u64 {
    if n == 0 {
        return 1;
    }

    let mut res = mod_pow(a, n / 2, mod_n);
    res = res * res % mod_n;

    if n % 2 == 1 {
        res = res * a % mod_n;
    }

    res
}

// mod_nにおける逆元(1/x)を求める。modで割り算するときは逆元をかける。
// フェルマーの小定理 x^(p-1) ≡ 1 (mod p: pは素数)より
fn inv(a: u64, mod_n: u64) -> u64 {
    mod_pow(a, mod_n - 2, mod_n)
}

// nCkを求める
fn choose(n: u64, k: u64, md: u64) -> u64 {
    let mut res1 = 1;
    let mut res2 = 1;
    let mut i = 1;
    while i <= k {
        res1 = (res1 * (n - (i - 1))) % md;
        res2 = (res2 * i) % md;
        i += 1;
    }

    res1 * inv(res2, md) % md
}


Measured memory_bytes: 2144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <numeric>
#define rep(i,s,n) for (int i = s; i < n; ++i)
#define drep(i,s,n) for (int i = n; i >= s; --i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;

int gcd(int a, int b)
{
   if (a%b == 0) return(b);
   else          return(gcd(b, a%b));
}
int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
void printvv(vector<vector<auto>> vv, int n)
{
  cout << '[' << endl;
  rep(q, 0, n)
  {
    cout << '[';
    rep(p, 0, n)
    {
      cout << vv.at(q).at(p) << ',';
    }
    cout << ']' << endl;
  }
  cout << ']' << endl;
}

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

//------------------------------------------------------------
void solve() {
  bool bl1=false,bl2=false;
  int n,i=1,sum=0;
  cin>>n;

  vector<int> v(n);
  rep(j,0,n) {cin>>v.at(j); if(v.at(j)==2) bl1=true;}
  if(!bl1) {print(-1); return;}

  while (sum<=n)
  {
    if(i==2) break;
    i=v.at(i-1);
    ++sum;
  }

  if(sum==n+1) print(-1);
  else print(sum);

  return;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define int  long long 
#define loop(i,a,b) for(i=a;i<b;i++)
#define mod 1000000007
#define INF 1000000000000
#define pb push_back
#define lim 1000001
using namespace std;

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

    cin>>temp;

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

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<ll,ll>;

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

int N;
P A[100100];
ll res[100100];

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> fst(A[i]);
        fst(A[i]) = -fst(A[i]);
        snd(A[i]) = i;
    }

    sort(A, A+N);

    int mn = snd(A[0]);
    for(int i=0,j=0;i<N;i=j){
        mn = min<int>(mn, snd(A[i]));
        
        while(j < N && fst(A[j]) == fst(A[i])){
            ++j;
        }
        
        if(j == N){
            res[mn] += -fst(A[i]) * j;
            break;
        }

        ll diff = fst(A[j]) - fst(A[i]);
        res[mn] += diff * j;
    }

    for(int i=0;i<N;++i){
        std::cout << res[i] << std::endl;
    }
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long A, long long B, long long C, long long K){
    if(K%2 == 1) {
        cout << B - A << endl;
    } else {
        cout << A - B << endl;
    }
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    solve(A, B, C, K);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
    using namespace std;
    #define pii pair<int,int>
    #define fir first
    #define sec second
    #define MP make_pair
    #define rep(i,x,y) for (int i=(x);i<=(y);i++)
    #define drep(i,x,y) for (int i=(x);i>=(y);i--)
    #define go(x) for (int i=head[x];i;i=edge[i].nxt)
    #define templ template<typename T>
    #define sz 1010010
    #define mod 1000000007ll
    typedef long long ll;
    typedef double db;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
    templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
    templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
    templ inline void read(T& t)
    {
        t=0;char f=0,ch=getchar();double d=0.1;
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
        if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
        t=(f?-t:t);
    }
    template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
    char __sr[1<<21],__z[20];int __C=-1,__zz=0;
    inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
    inline void print(register int x)
    {
        if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
        while(__z[++__zz]=x%10+48,x/=10);
        while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
    }
    void file()
    {
        #ifdef NTFOrz
        freopen("a.in","r",stdin);
        #endif
    }
    inline void chktime()
    {
        #ifndef ONLINE_JUDGE
        cout<<(clock()-t)/1000.0<<'\n';
        #endif
    }
    #ifdef mod
    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
    ll inv(ll x){return ksm(x,mod-2);}
    #else
    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
    #endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n;
ll dp[sz],sum[sz];

int main()
{
    file();
	read(n);
	dp[0]=sum[0]=1;
	rep(i,1,n)
	{
		dp[i]=(dp[i-1]+sum[i-3])%mod;
		sum[i]=(sum[i-1]+dp[i])%mod;
	}
	ll ans=dp[n];
	rep(i,1,n-1) (ans+=dp[n-i-1]*(n-i)%mod)%=mod;
	rep(i,1,n) (ans+=(i==n?0:dp[n-i-1]*(n-2)%mod*(n-1)%mod)+dp[n-i]*(n-1)%mod)%=mod;
	cout<<ans;
	return 0;
}

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

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


int N, K;
int[] P, Q;

int[] inv(in int[] a) {
  int[] b = new int[N];
  foreach (i; 0 .. N) {
    b[a[i]] = i;
  }
  return b;
}

int[] mul(in int[] a, in int[] b) {
  int[] c = new int[N];
  foreach (i; 0 .. N) {
    c[i] = a[b[i]];
  }
  return c;
}

int[] power(in int[] a, int e) {
  int[] b = a.dup;
  int[] c = new int[N];
  foreach (i; 0 .. N) {
    c[i] = i;
  }
  for (; e; e >>= 1) {
    if (e & 1) {
      c = c.mul(b);
    }
    b = b.mul(b);
  }
  return c;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      K = readInt();
      P = new int[N];
      foreach (i; 0 .. N) {
        P[i] = readInt() - 1;
      }
      Q = new int[N];
      foreach (i; 0 .. N) {
        Q[i] = readInt() - 1;
      }
      
      int[] ans;
      if (K == 1) {
        ans = P;
      } else if (K == 2) {
        ans = Q;
      } else {
        const x = (K + 1) * 2 / 3;
        const y = (K - 3) * 2 / 3;
        debug {
          writefln("x = %s, y = %s", x, y);
        }
        int[] invP = P.inv;
        int[] invQ = Q.inv;
        int[] R = Q.mul(invP).mul(invQ).mul(P);
        int[] a = R.power(x / 4);
        foreach (i; 0 .. x % 4) {
          a = a.mul([Q, invP, invQ, P][i]);
        }
        int[] b = R.power(y / 4);
        foreach (i; 0 .. y % 4) {
          b = b.mul([Q, invP, invQ, P][i]);
        }
        ans = a.mul(b.inv);
      }
      foreach (i; 0 .. N) {
        if (i > 0) {
          write(" ");
        }
        write(ans[i] + 1);
      }
      writeln();
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 22740
#include <iostream>

using namespace std;

int main(void){
  int N,T,t[200000];
  int total=0;
  cin >> N >> T;
  for(int i=0; i<N; i++) cin >> t[i];
  for(int i=0; i<N-1; i++){
    total += min(t[i+1]-t[i], T);
  }
  total += T;
  cout << total << endl;
  return 0;
}


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

using namespace std;

int main()
{
    string s ;
    cin>>s ;
    string s1 = "keyence" ;
    if(s == s1)
        return cout<<"YES\n" , 0 ;
    int n = s.size() ;
    for(int i = 0 ; i < n ; ++i)
    {
        for(int j = i ; j < n ; ++j)
        {
            string s2 = "" ;
            for(int k = 0 ; k < n ; ++k)
            {
                if(k >= i && k <= j)
                    continue;
                s2 += s[k] ;
            }
            if(s2 == s1)
                return cout<<"YES\n" , 0 ;
        }
    }
    return cout<<"NO\n" , 0 ;
}


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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  REPS(x,max(0, s-(2*k)), min(k,s)+1) {
    int x_rest = s - x;
    REPS(y, max(0, x_rest-k), min(k,x_rest)+1) {
      int y_rest = x_rest - y;
      int z_rest = min(k,y_rest)+1 - max(0, y_rest);
      ans += max(0,z_rest);
    }
  }
  
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<fstream>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define mod 1000000007
#define All(v) v.begin(),v.end()

using namespace std;

int main()
{
    ll x;
    cin >> x;
    /// odd 6
    /// even 5
    ll ans = x/11 * 2;
    ll rem = x%11;

    if(rem)
    ans += (rem > 6 ? 2:1);



    cout << ans << endl;












    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, 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;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e17;
#define int long long


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	double a, b, x; cin >> a >> b >> x;
	cout << fixed << setprecision(15);
	double s = x / a; //平面での面積
	double radian = 0; //ラジアン
	if (s >= a * b / 2) {
		double h = (a*b - s) * 2 / a;
		radian = atan2(h, a);
	}
	else {
		double w = s * 2 / b;
		radian = atan2(b, w);
	}
	double PI = acos(-1);
	double deg = radian / (2 * PI) * 360;
	cout << deg << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int solve(){
    int n;
    cin >>n;

    vector<int> a(n);
    rep(i,n) cin >>a[i];

    vector<int> s(a);
    sort(all(s));

    int q;
    cin >>q;
    vector<int> x(q),y(q);
    rep(i,q){
        cin >>x[i] >>y[i];
        --x[i];
        --y[i];
    }

    int ct = 0;
    vector<int> e(n);
    rep(i,n){
        e[i] = (a[i]==s[i]);
        ct += e[i];
    }
    if(ct == n) return 0;

    rep(i,q){
        ct -= e[x[i]];
        ct -= e[y[i]];

        swap(a[x[i]], a[y[i]]);
        e[x[i]] = (a[x[i]] == s[x[i]]);
        e[y[i]] = (a[y[i]] == s[y[i]]);

        ct += e[x[i]];
        ct += e[y[i]];

        if(ct == n) return i+1;
    }
    return -1;
}

int main(){
    cout << solve() << endl;
    return 0;
}



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

int main() {

  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;

  for(int i = 0; i < a+1; i++) {
    for(int j = 0; j < b+1; j++) {
      for(int l = 0; l < c+1; l++) {
        if((500*i) + (100*j) + (50*l) == x) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100
#define INF 1000000007
int n,res,arr[MAXN+5][12],p[MAXN+5][12],cek[12];
int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 10; j++){
            scanf("%d", &arr[i][j]);
        }
    }
    res = -INF;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= 10; j++){
            scanf("%d", &p[i][j]);
            //cout<<i<< " "<<j<<p[i][j]<<endl;
            //cout<<p[i][j]<<endl;
        }
    }
    //cout<<p[1][1]<<endl;
    for(int i = 1; i < (1<<10); i++){
        int temp = i;
        //cout<<i<<endl;
        for(int j = 0; j < 10; j++)cek[j] = 0;
        int cur = 0;
        while(temp){
            if(temp%2==1)cek[cur] = 1;
            cur++;
            temp /= 2;
        }
        int xam = 0;
        for(int j = 0; j < n; j++){
            int now = 0;
            for(int k = 0; k < 10; k++){
                if(arr[j][k] == 1 and cek[k] == 1)now++;
            }
            xam += p[j][now];
            //if(i == 32)cout<<p[j][now]<<endl;
            //cout<<now<<endl;
        }
        res = max(xam,res);
        if(xam == 0){
        //    cout<<i<<endl;
        }
        //if(res==0)cout<<i<<endl;
    }
    printf("%d\n", res);
}


Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

from collections import deque 
s=s0()
n=n0()
q=s2(n)

d1=deque()
d2=deque()

f=False
for a in q:
    if a[0]=="1":
        f=not(f)
    else:
        if a[2]=="1":
            if f==False:
                d1.appendleft(a[4])
            else:
                d2.append(a[4])                
        else:
            if f==False:
                d2.append(a[4])
            else:
                d1.appendleft(a[4])
ss=''.join(list(d1))+s+''.join(list(d2))
print(ss[::-1] if f else ss)

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    ll N; cin >> N;
    ll res = 0;
    rep1(i, N){
        ll tmp = N/i;
        res += i*tmp*(tmp+1)/2;
    }
    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7712
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a + b  >= c) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> find_divisors(int x) {
	vector<int> d;
	for (int i = 1; i * i <= x; ++i) {
		if (x % i == 0) {
			d.push_back(i);
			if (i * i != x) {
				d.push_back(x / i);
			}
		}
	}
	sort(d.begin(), d.end());
	return d;
}
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	int sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		sum += A[i];
	}
	vector<int> d = find_divisors(sum);
	int ans = 1;
	for (int i : d) {
		vector<int> lv(N), rv(N);
		for (int j = 0; j < N; ++j) {
			lv[j] = A[j] / i * i;
			rv[j] = lv[j] + i;
		}
		vector<bool> sel(N);
		int gsum = 0, cost = 0;
		for (int j = 0; j < N; ++j) {
			if (A[j] - lv[j] <= rv[j] - A[j]) {
				gsum += lv[j];
				cost += A[j] - lv[j];
			}
			else {
				gsum += rv[j];
				cost += rv[j] - A[j];
				sel[j] = true;
			}
		}
		if (gsum <= sum) {
			vector<int> turn;
			for (int j = 0; j < N; ++j) {
				if (!sel[j]) {
					turn.push_back((rv[j] - A[j]) - (A[j] - lv[j]));
				}
			}
			sort(turn.begin(), turn.end());
			for (int j = 0; gsum < sum; ++j) {
				cost += turn[j];
				gsum += i;
			}
			if (cost <= 2 * K) {
				ans = i;
			}
		}
		else {
			vector<int> turn;
			for (int j = 0; j < N; ++j) {
				if (sel[j]) {
					turn.push_back(-((rv[j] - A[j]) - (A[j] - lv[j])));
				}
			}
			sort(turn.begin(), turn.end());
			for (int j = 0; gsum > sum; ++j) {
				cost += turn[j];
				gsum -= i;
			}
			if (cost <= 2 * K) {
				ans = i;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

long long lmax(long long a, long long b) {
  if (a > b) return a;
  else return b;
}

long long lmin(long long a, long long b) {
  if (a > b) return b;
  else return a;
}

long long keta(long long a) {
  long long res = 0;
  while (a != 0) {
    a /= 10;
    res++;
  }
  return res;
}
ll F(ll a, ll b) {
  return lmax(keta(a), keta(b));
}


int main() {
  ll N;
  cin >> N;
  ll res = 1000;

  for (ll i = 1 ; i * i <= N; i++) {
    if (N % i == 0) {
      res = lmin(res, F(i, N / i));
    }
  }

  cout << res << endl;

}


Measured memory_bytes: 256
N,K = map(int,input().split())
X = list(map(int,input().split()))

min_time = float('inf')
for i in range(N-K+1):
  cost1 = abs(X[i]-X[i+K-1]) + abs(X[i])
  cost2 = abs(X[i]-X[i+K-1]) + abs(X[i+K-1])
  min_time = min(min_time,cost1,cost2)
print(min_time)

Measured memory_bytes: 15020
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let q: u32 = read();

    for _ in 0..q {
        let v: Vec<i32> = read_vec();
        let x1 = v[2] - v[0];
        let y1 = v[3] - v[1];
        let x2 = v[6] - v[4];
        let y2 = v[7] - v[5];
        if x1 * y2 == x2 * y1 {
            println!("2");
        } else if x1 * x2 + y1 * y2 == 0 {
            println!("1");
        } else {
            println!("0");
        }
    }
}



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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    ans += (r - l + 1);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,m;
	while(~scanf("%d%d",&n,&m))
	{
		if(m<10&&m>=0&&n<10&&n>=0)
		{
			if(n<m)
			printf("0\n");
			else
			printf("10\n");
		}
	}
	return 0;
 } 

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; 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(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
ll d[110][2];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	ll res = 0;
	rep(i, n) {
		rep(j, 2) {
			cin >> d[i][j];
		}
		if (d[i][0] == d[i][1])res++;
		else res = 0;
		if (res == 3) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
	
	string S;
	cin >> S;
	int ans = 700;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'o') {
			ans += 100;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3568
#include <cstdio>

using namespace std;

int a[100010];
int main() {
  int N;
  scanf("%d", &N);
  for(int i=0;i<N;++i) {
    scanf("%d", &a[i]);
  }
  int ans=0;
  for(int i=0;i<N;++i) {
    if (a[a[i]-1]-1==i) ans++;
  }
  printf("%d\n",ans/2);
  return 0;
}


Measured memory_bytes: 512