akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long c(int n,int r){
    const int mod=1000000007;
    long long x=1,g=1;
    for(int i=1;i<=r;i++){
        x*=(n-i+1);
        x%=mod;
        g*=i;
        g%=mod;
    }
    long long pow=g;
    g=1;
    for(int i=mod-2;i>0;i/=2){
        if(i%2)g*=pow;
        g%=mod;
        pow*=pow;
        pow%=mod;
    }
    x*=g;
    x%=mod;
    return x;
}
int main(){
    const int mod=1000000007;
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=k;i++){
        //並べ方: n-k+1 C i ,分け方: k-1 C i-1
        if(n-k+1<i)cout<<"0"<<endl;
        else cout<<c(n-k+1,i)*c(k-1,i-1)%mod<<endl;
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &i : a) cin >> i;
  vector<int64_t> p(n + 1, 0);
  for (int i = 0; i < n; ++i) {
    p[i + 1] = p[i] + a[i];
  }
  int64_t ans = numeric_limits<int64_t>::max();
  for (int left_size = 2, l1 = 1, l2 = left_size + 1; left_size <= n - 2; ++left_size) {
    // [0, left_size), [left_size, n)
    // [0, l1), [l1, left_size), [left_size, l2), [l2, n)
    while (l1 + 1 < left_size && abs(2 * p[l1 + 1] - p[left_size]) < abs(2 * p[l1] - p[left_size])) {
      ++l1;
    }
    while (l2 <= left_size || (l2 + 1 < n && abs(p[l2 + 1] - p[left_size] - (p[n] - p[l2 + 1])) < abs(p[l2] - p[left_size] - (p[n] - p[l2])))) {
      ++l2;
    }
    auto k1 = p[l1], k2 = p[left_size] - p[l1], k3 = p[l2] - p[left_size], k4 = p[n] - p[l2];
    ans = min(ans, max({k1,k2,k3,k4}) - min({k1,k2,k3,k4}));
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 5624
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int k, x;
  scanf("%d%d", &k, &x);
  puts(500 * k >= x ? "Yes" : "No");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>//结构体vector排序按第一维？ 第一维年份 第二位编号 
using namespace std;
const int N=1e5+5;
struct P{
	int p,y;
}a[N];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int n,m;
	cin>>n>>m;
	vector<int>g[n+1];
	for(int i=1;i<=m;i++){
		cin>>a[i].p>>a[i].y;
		g[a[i].p].push_back(a[i].y);
	}
	for(int i=1;i<=n;i++)sort(g[i].begin(),g[i].end());
	for(int i=1;i<=m;i++){
		cout<<setw(6)<<setfill('0')<<a[i].p;
		cout<<setw(6)<<setfill('0')<<lower_bound(g[a[i].p].begin(),g[a[i].p].end(),a[i].y)-g[a[i].p].begin()+1<<endl;
	}
}

Measured memory_bytes: 7808
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
LL a[N];
int main() {
    LL n,x;
    scanf("%lld%lld",&n,&x);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);

    LL res=0,before=0;
    for(int i=1; i<=n; i++) {
        if(before+a[i]<=x)
            before=a[i];
        else{
            LL sub=before+a[i]-x;
            res+=sub;
            before=a[i]-sub;
        }
    }
    printf("%lld\n",res);

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n = 0;
    string W, T;
    cin >>W;
    while(1){
        cin >>T;
        if(T == "END_OF_TEXT") break;
        for(int i=0; i<T.size(); i++){
            if(isupper(T[i])){
                T[i] = tolower(T[i]);
            }
        }
        if(W == T){
            n += 1;
        }
    }
    cout <<n << endl;
    return 0;
}


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

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

    ll ans = 0;
    for (int i = 1; i <= N; ++i) {
        if (i % 3 != 0 && i % 5 != 0)
            ans += i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1) {
            System.out.println("Hello World");
        } else if (n == 2) {
            System.out.println(sc.nextInt() + sc.nextInt());
        }
    }
}

Measured memory_bytes: 22996
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    int ret = 0;
    for (int i = 1; i <= n; i++)
    {
        string s = to_string(i);
        if (s.size() % 2)
            ret++;
    }
    cout << ret << endl;
}


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

int main() {
  int N;
  cin >> N;
 vector<int> takoyaki(N);
  int i;
  int j;
  long ans;
  ans = 0;
   for(i=0;i<N;i++){
       cin >> takoyaki.at(i);
   }
  for(i=0;i<N;i++){
    
    for(j=0;j<N;j++){
      if(i > j){
        //cout << takoyaki.at(i)*takoyaki.at(j);
        
       ans += takoyaki.at(i)*takoyaki.at(j);
      }
    }
    }
  cout << ans;
  
  /*
  vector<int> suujivec(10);
  int suuji = std::stoi(S);
  int c =0;
   for(int i=10-S.size();i<10;i++){
    int a = int(S.at(c)- '0');
      suujivec.at(i)=a; 
     c++;
   }
  
  vector<vector<int>> data(512, vector<int>(9,0));
 
  int ccc=0;
  long int answer =0;
  for(int i=0;i<data.size();i++){
  for(int j=0;j<data.at(0).size();j++){
    ccc++;
    if(data.at(i).at(j) == 1){ ccc=0; }
    if(j==0){ answer += suujivec.at(9); }
    cout << kaijou(ccc) << endl;
    answer += suujivec.at(8-j) * kaijou(ccc); 
    
  }
  }
   
   for(int i=0;i<data.size();i++){
     for(int j=0;j<data.at(0).size();j++){
     if(j==data.at(0).size()-1){cout << data.at(i).at(j) <<endl;}else{
     cout << data.at(i).at(j);
     }
   }
   }
  */

}

Measured memory_bytes: 256
import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  val seq1 = for(i<-1 to 9) yield List(i,i,i)
  val seq2 = for(i<-1 to 7) yield List(i,i+1,i+2)

  def check(m:List[Int], count:Int,u:Int,v:Int):Boolean =  {
    if(m.length != count) false
    else if(count==2) {
      val List(x,y) = m
      if(x==y) true else false
    } else {
      if((u to 8).exists( i=> check(m diff seq1(i),count-3,i,v))) {
        true
      } else {
        (v to 6).exists(i=> check(m diff seq2(i),count-3,u,i) )
      }
    }
  }

  Iterator.continually(readLine).takeWhile ( _!=null ).foreach { line =>
    val l = line.map(_.asDigit).toList
    val m = (1 to 9).filter { i=> if(l.count( _==i ) >= 4) false else check(i::l,14,0,0) }
    if(m.length>0) println(m.mkString(" ")) else println(0)
  }
}

Measured memory_bytes: 68100
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=100111;
int n,s,x[maxn];
LL p[maxn],ans;

int calc(int l,int r)
{
	if(x[r]<s)
	{
		ans+=s-x[l];
		return l;
	}
	if(x[l]>s)
	{
		ans+=x[r]-s;
		return r;
	}
	if(p[l]>=p[r])
	{
		p[l]+=p[r];
		ans+=x[r]-x[calc(l,r-1)];
		return r;
	}
	else
	{
		p[r]+=p[l];
		ans+=x[calc(l+1,r)]-x[l];
		return l;
	}
}

int main()
{
	get2(n,s);
	for(int i=1;i<=n;i++)get2(x[i],p[i]);
	calc(1,n);
	printendl(ans);
	return 0;
}

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

using namespace std;

struct Node {
    int vertex, weight;
    Node () : vertex(-1), weight(-1) {}
    Node (int v, int w) : vertex(v), weight(w) {}
};

void dfs (const vector <vector <Node>> &graph, int node,
          vector <int> &color) {
    for (const auto &neighbor : graph[node]) {
        if (color[neighbor.vertex] == -1) {
            if (neighbor.weight == 1) {
                color[neighbor.vertex] = (color[node] + 1) % 2;
            } else {
                color[neighbor.vertex] = color[node];
            } 
            dfs(graph, neighbor.vertex, color);
        }
    }
}

int main() {
    int n;
    cin >> n;   
    vector <vector <Node>> graph(n + 1);
    vector <int> color(n + 1, -1);
    for (int i = 1; i < n; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        w %= 2;
        graph[u].emplace_back(Node {v, w});
        graph[v].emplace_back(Node {u, w});
    }
    for (int node = 1; node <= n; ++node) {
        if (color[node] == -1) {
            color[node] = 0;
            dfs(graph, node, color);
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << color[i] << "\n";
    }
    return 0;
}


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

typedef pair<int, int> pii;
typedef pair<short, short> pss;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#define MAX_V 110
const ll INF = 1e15;

struct edge {
	int to, rev;
	ll cap;
	edge(int to, ll cap, int rev) : to(to), cap(cap), rev(rev) {};
};

vector<edge> G[MAX_V];
ll level[MAX_V]; 
int iter[MAX_V]; 

void add_edge(int from, int to, ll cap)
{
	G[from].push_back(edge(to, cap, (int)G[to].size()));
	G[to].push_back(edge(from, 0, (int)G[from].size() - 1));
}

void bfs(int s)
{
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);

	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (edge &e : G[v]) {
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

ll dfs(int v, int t, ll f)
{
	if (v == t) return f;
	for (int &i = iter[v]; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			ll d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

ll max_flow(int s, int t)
{
	ll flow = 0;
	while (true) {
		bfs(s);
		if (level[t] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		ll f;
		while ((f = dfs(s, t, INF)) > 0) flow += f;
	}
}

int N;
int a[110];
ll ans;

int main() {
	cin >> N;
	int S = N, T = N + 1;

	rep(i, N) {
		cin >> a[i];
		if (a[i] >= 0) {
			add_edge(S, i, a[i]);
			ans += abs(a[i]);
		} else {
			add_edge(i, T, -a[i]);
		}
	}

	rep(i, N) {
		rep(j, i) if ((i+1) % (j+1) == 0) {
			add_edge(i, j, INF);
		}
	}

	ll x = max_flow(S, T);

	cout << ans - x << endl;

	return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)
const int MOD = 1e9 + 7;

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

int main() {
	int N;
	string s;
	cin >> N >> s;
	int L_cnt = 0, R_cnt = 0;
	rep(i, s.size()) {
		if(s[i] == '(') ++L_cnt;
		else {
			if(L_cnt > 0) --L_cnt;
			else ++R_cnt;
		}
	}
	rep(i, R_cnt) cout << "(";
	cout << s;
	rep(i, L_cnt) cout << ")";
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
NUM_MAX = 10**5
is_prime = [True] * NUM_MAX
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(NUM_MAX):
    if is_prime[i]:
        primes.append(i)
        for j in range(2*i, NUM_MAX, i):
            is_prime[j] = False

def prime_fact(n):
    res = {}
    for p in primes:
        while n % p == 0:
            n //= p
            res[p] = res.get(p, 0) + 1
    if n > 1:
        res[n] = 1
    return res

def inv_pow(a, p):
    res = 1
    while p > 0:
        if p % 2 == 1:
            res = (res * a) % MOD
        p //= 2
        a = (a * a) % MOD
    return res

def comb(n, k):
    p, q = 1, 1
    for i in range(k):
        p = p * (n - i) % MOD
        q = q * (i + 1) % MOD
    return p * inv_pow(q, MOD-2) % MOD

def solve(n, m):
    v = prime_fact(m)
    ans = 1
    for k in v.values():
        ans = ans * comb(n+k-1, k) % MOD
    return ans % MOD

assert solve(2, 6) == 4
assert solve(3, 12) == 18
assert solve(100000, 1000000000) == 957870001

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

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

using namespace std;

const int N = 1e5 + 7, MOD = 1e9 + 7;

vector < int > g[N];
int dp[N];
bool ok;

int k;

static int logpow(int b, int e) {
    int ans(1);
    while (e) {
        if (e&1)
            ans = 1LL * ans * b % MOD;
        b = 1LL * b * b % MOD;
        e >>= 1;
    }

    return ans;
}

namespace COMBI {
    int f[N], invf[N];

    void precalc() {
        f[0] = 1;
        for (int i = 1; i < N; ++i)
            f[i] = 1LL * f[i - 1] * i % MOD;
        invf[N - 1] = logpow(f[N - 1], MOD - 2);
        for (int i = N - 2; i >= 0; --i)
            invf[i] = 1LL * invf[i + 1] * (i + 1) % MOD;
    }

    int comb(const int &n, const int &k) {
        assert(n >= k);
        assert(k >= 0);
        return 1LL * f[n] * invf[k] % MOD * invf[n - k] % MOD;
    }

    int aranj(const int &n, const int &k) {
        assert(n >= k);
        assert(k >= 0);
        return 1LL * f[n] * invf[n - k] % MOD;
    }
}

void dfs(int nod, int tata) {
    if (g[nod].size() >= k)
        ok = 1;
    if (ok == 1)
        return;

    int ans(COMBI::aranj(k - (tata != 0) - 1, g[nod].size() - (tata != 0)));///ne "alegem" culoriile copiilor
    if (tata == 0)
        ans = 1LL * ans * k % MOD;///daca suntem radacina ne alegem culoarea

    for (int i : g[nod]) {
        if (i == tata)
            continue;
        dfs(i, nod);
        ans = 1LL * ans * dp[i] % MOD;
    }

    dp[nod] = ans;
}

int main()
{
    COMBI::precalc();

    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);

    int n, a, b;
    cin >> n >> k;

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

    dfs(1, 0);
    if (ok)
        cout << 0;
    else
        cout << dp[1];
    return 0;
}


Measured memory_bytes: 13952
(defun main ()
  (let ((x (read))
        (flg nil))
    (loop for i from 1 upto 10000
          do (if (and (<= (* 100 i) x) (<= x (* 105 i))) (setf flg t)))
    (format t "~A~%" (if flg 1 0))))

(main)


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

int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		int mat[4][4] = {
			{1,  2,  3,  4},
			{2, -1,  4, -3},
			{3, -4, -1,  2},
			{4,  3, -2, -1},
		};
		int num1[4], num2[4], ans[4];
		for(int h = 0;h < n;h++){
			for(int i = 0;i < 4;i++){
				cin >> num1[i];
				ans[i] = 0;
			}
			for(int i = 0;i < 4;i++){
				cin >> num2[i];
			}
			
			for(int x = 0;x < 4;x++){
				for(int y = 0;y < 4;y++){
					ans[abs(mat[x][y]) - 1] += ((mat[x][y] < 0)? -1 : 1) * num1[x] * num2[y];
				}
			}
			for(int i = 0;i < 4;i++){
				cout << ans[i];
				if(i < 3) cout << ' ';
			}
			cout << endl;
		}
	}
	return 0;
}

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

typedef long long ll;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string a,b,d1,d2;
  int i,c1,c2;
  cin>>a>>b;
  d1=a,d2=b;
  stringstream cpy1(b);
  cpy1>>c1;
  stringstream cpy2(a);
  cpy2>>c2;
  for(i=1;i<c1;i++)
  {
    d1+=a;
  }
  for(i=1;i<c2;i++)
  {
    d2+=b;
  }
  cout<<min(d1,d2)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define bada LLONG_MAX
#define chota LLONG_MIN
#define vl vector<ll>
#define pb push_back
#define mod 1000000007
int main()
{
    int n,k;
    cin>>n>>k;

    ll a[n];

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

    sort(a,a+n);
    reverse(a,a+n);

    int neg=1;
    int i=0,j=n-1;
    vl ans;
    if(k&1)
    {
        if(a[0]<0)
        {
            ans.pb(a[0]);
            neg=-1;
        }
        else
            ans.pb(a[0]);
       i=1;
    }
    while(ans.size()<k)
    {
        if(neg*a[i]*a[i+1]<neg*a[j]*a[j-1])
        {
            ans.pb(a[j]);
            ans.pb(a[j-1]);
            j-=2;
        }
        else
        {
            ans.pb(a[i]);
            ans.pb(a[i+1]);
            i+=2;
        }
    }
    ll mul=1;

    for(int i=0;i<k;i++)
    {
        mul*=ans[i];
        mul%=mod;
    }
    if(mul<0)
        cout<<mul+mod<<"\n";
    else
        cout<<mul<<"\n";
 return 0;
}


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

using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    int target = C % B;
    int sum = A;
    bool can = false;
    for (int I = 0; I < B; I++) {
//        cout << sum << " % " << B << " = " << (sum%B) << endl;
        if (sum % B == target) {
            can = true;
            break;
        }
        sum += A;
    }
    if (can)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

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

using namespace std;

int calc(int x, int v) {
    return v * (100+x) / 100;
}

bool solve() {
    int x, y, s;
    if(!(cin >> x >> y >> s)) return false;
    if(!x && !y && !s) return false;

    int ans = 0;
    for(int i = 1; i < s*2; ++i) {
        for(int j = 1; j < s*2; ++j) {
            const int s1 = calc(x, i);
            const int s2 = calc(x, j);
            if(s1 + s2 == s) {
                ans = max(ans, calc(y, i) + calc(y, j));
            }
        }
    }
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define nax 200004
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  ll n;cin>>n;
  ll i,j,k;
  ll a[n];
  repn(i,n) cin>>a[i];
  ll dp=1;
  ll cnt[nax];
  rep(i,nax) cnt[i]=0;
  repn(i,n){
    if(a[i]==a[i-1]) continue;
    else{
      cnt[a[i]]+=dp;
      dp=cnt[a[i]];
      dp%=mod;
    }
  }
  //cout<<" "<<endl;
  //repn(i,n) cout<<dp[i]<<endl;
  cout<<dp<<endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <sstream>

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
void printhoge(set<int> v) {
	ALL(it, v) {
		cout << *it << " ";
	}
	cout << endl;

}

ll pivot(int n) {
	ll tmp = 1;
	ll piv = 0;
	ll count = 0;
	if (n == 0)
		return 0;
	if (n == 1)
		return 1;

	if (n > 0) {
		count = tmp;
		while (1) {
			if (n <= count) {
				break;
			}
			tmp *= 4;
			count += tmp;
			piv++;
		}
		piv = piv * 2 + 1;
	}
	else {
		tmp = -2;
		count = tmp;
		piv = 1;
		while (1) {
			if (count <= n) {
				break;
			}
			tmp *= 4;
			count += tmp;
			piv++;
		}
		piv = piv * 2;
	}
	return piv;
}

int main() {
	ll n; cin >> n;
	ll dp[50];
	ll keta[50];
	keta[0] = 1;
	For(i, 1, 50) {
		keta[i] = keta[i - 1] * -2;
	}
	//ll dp[50];
	rep(i, 50) {
		dp[i] = 0;
	}
	//cout << n << "\t";
	if (n == 0) {
		cout << 0 << endl;
		return 0;
	}
	ll tmp = n;
	while (tmp != 0) {
		ll k = pivot(tmp);
		if (k != 0)
			dp[k - 1] = 1;
		else
			dp[0] = 0;
		tmp -= keta[k - 1];
		//cout << "tmp " << tmp << ":" << k << endl;
	}
	bool flag = false;
	for (ll i = 50; i >= 0; i--) {
		if (dp[i] == 1)
			flag = true;
		if (flag)
			cout << (dp[i] == 1) ? 1 : 0;
	}
	cout << endl;


	//	ll res = 0;
	//	rep(i, 50) {
	//		res += keta[i] * dp[i];
	//}
	//	cout << res << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void fprint() { std::cout << '\n'; }
template <class H, class... T> void fprint(H &&head, T &&... args) {
    std::cout << std::fixed << std::setprecision(10) << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}

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

    int N, K;
    cin >> N >> K;
    double ans = 0;

    REP(i, N) {
        double sum = 0;
        int time   = (i + 1);
        int cnt    = 0;
        while (time < K) {
            time *= 2;
            cnt++;
        }
        sum = (1.0 / N) * pow(0.5, cnt);
        ans += sum;
    }
    fprint(ans);

    return 0;
}

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

using namespace std;

int main()
{
	long long A[100001] = {}, B[100001] = {}, N, g, d = 0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i] >> B[i];
	}
	while (N--)
	{
		if (d + A[N] < B[N])
		{
			d = (d + A[N] ? B[N] - A[N] : 0);
		}
		else
		{
			g = (d + A[N]) % B[N];
			d += (g ? B[N] - g : 0);
		}
	}
	cout << d << "\n";
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>

int main(){
   int s;
   std::cin >> s;

   int n = 1000000;
   int a[n];
   a[0] = s;
   int m = 0;
   for(int i=1; i<n; ++i){
      int f = (a[i-1]%2==0 ? a[i-1]/2 : 3*a[i-1]+1);
      for(int j=0; j<i; ++j){
	 if(f == a[j]){
	    std::cout << i + 1 << std::endl;
	    return 0;
	 }
      }
      a[i] = f;
   }
   return -1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n, m;
    cin>>n>>m;
    vector<int> dig[n];
    rep(i, m){
        int a, b;
        cin>>a>>b;
        --a;--b;
        dig[a].push_back(b);
        dig[b].push_back(a);
    }

    vector<int> v(n);
    rep(i, dig[0].size()){
        v[dig[0][i]]=1;
    }
    rep(i, dig[n-1].size()){
        if(v[dig[n-1][i]]==1){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 12784
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/

	string s;
	cin >> s;
	for (int i = 0; i <= 2; i++) {
		if (s[i] == s[i + 1]) {
			cout << "Bad";
			exit(0);
		}
	}
	cout << "Good";
}

Measured memory_bytes: 256
# coding: utf-8
# 隣接するK個のサイコロの和が大きいものを探す

nk = input().split()
N = int(nk[0])
K = int(nk[1])

Ps = [int(p) for p in input().split()]

# 累積和にしてもいいし、1つずつスライドして求めてもいい気がする

max_sum = sum(Ps[:K])
current_sum = max_sum

# K+1 ~ N-1 までスライドして見ていく
for i in range(K, N):
    current_sum -= Ps[i-K]
    current_sum += Ps[i]

    max_sum = max(max_sum, current_sum)


# 1~pのサイコロの期待値: ((1+p) * p / 2) / p = (1 + p) / 2
ans = 1.0 * (max_sum + K) / 2
print(ans)




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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int, int>;
using ppa = pair<pa, int>;
#define SORT(v, n) sort(v, v + n);
#define ALL(v) v.begin(), v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v), greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)), v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--)
#define rrep(i, n) RFOR(i, 0, n)
#define INF INT_MAX
#define SUP INT_MIN
#define mins(a, b) a = min(a, b)
#define maxs(a, b) a = max(a, b)

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

// 8近傍
// int dy[]={0,0,1,-1,1,1,-1,-1};
// int dx[]={1,-1,0,0,1,-1,1,-1};

// const ll MOD = 1000000007;

ll pow_mod(ll a, ll b, ll mod) {
    ll tmp = 1;
    a %= mod;
    if (b > 0) {
        tmp = pow_mod(a, b / 2, mod);
        if (b % 2)
            tmp = (((tmp * tmp) % mod) * a) % mod;
        else
            tmp = (tmp * tmp) % mod;
    }
    return tmp;
}

void solve() {
    int n; cin >> n;
    string s,t; cin >> s >> t;
    for(int i = 0; i < n; i++){
        bool flag = true;
        for(int j = i; j < n; j++){
            if(s[j] != t[j-i]){
                flag = false;
                break;
            }
        }
        if(flag){
            cout << n + i << endl;
            return;
        }
    }
    cout << n + n << endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
<?php
$s = fgets(STDIN);
for($i=0;$i<1;$i++){
	if(strpos($s,'a') === false){
		echo "a";
		break;
	}
	if(strpos($s,'b') === false){
		echo "b";
		break;
	}
	if(strpos($s,'c') === false){
		echo "c";
		break;
	}
	if(strpos($s,'d') === false){
		echo "d";
		break;
	}
	if(strpos($s,'e') === false){
		echo "e";
		break;
	}
	if(strpos($s,'f') === false){
		echo "f";
		break;
	}
	if(strpos($s,'g') === false){
		echo "g";
		break;
	}
	if(strpos($s,'h') === false){
		echo "h";
		break;
	}
	if(strpos($s,'i') === false){
		echo "i";
		break;
	}
	if(strpos($s,'j') === false){
		echo "j";
		break;
	}
	if(strpos($s,'k') === false){
		echo "k";
		break;
	}
	if(strpos($s,'l') === false){
		echo "l";
		break;
	}
	if(strpos($s,'m') === false){
		echo "m";
		break;
	}
	if(strpos($s,'n') === false){
		echo "n";
		break;
	}
	if(strpos($s,'o') === false){
		echo "o";
		break;
	}
	if(strpos($s,'p') === false){
		echo "p";
		break;
	}
	if(strpos($s,'q') === false){
		echo "q";
		break;
	}
	if(strpos($s,'r') === false){
		echo "r";
		break;
	}
	if(strpos($s,'s') === false){
		echo "s";
		break;
	}
	if(strpos($s,'t') === false){
		echo "t";
		break;
	}
	if(strpos($s,'u') === false){
		echo "u";
		break;
	}
	if(strpos($s,'v') === false){
		echo "v";
		break;
	}
	if(strpos($s,'w') === false){
		echo "w";
		break;
	}
	if(strpos($s,'x') === false){
		echo "x";
		break;
	}
	if(strpos($s,'y') === false){
		echo "y";
		break;
	}
	if(strpos($s,'z') === false){
		echo "z";
		break;
	}

	echo "None";
	break;
}

Measured memory_bytes: 3700
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
        int n = sc.nextInt();
        int count = 0;
        int ans;
        int tmp;
        for(int i = 0;i < n;i++){
          tmp = sc.nextInt();
          if(tmp % 2 == 0){
            count += 1;
          }
        }
        ans = (int)Math.pow(3, n) - (int)Math.pow(2, count);
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 35516
#include <iostream>
using namespace std;
#define int long long
const int MAXN=100005;

signed main()

{
	int h,n;
	cin>>h>>n;
	int sum=0;
	for (int i=1;i<=n;i++){
		int x;
		cin>>x;
		sum+=x;
	}

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

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import re

# 入力値取得
weathers = input()

if (weathers == "RRR"):
  print(3)
  exit()

if (re.match(r'.*RR.*', weathers)):
  print(2)
  exit()

if (re.match(r'.*R.*', weathers)):
  print(1)
  exit()

print(0)

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

int main(void){
    int X,N,max=0;
    cin>>N>>X;
    int m[N];

    for(int i=0;i<N;i++){
        cin>>m[i];
        X-=m[i];
        max++;
    }
    int min=m[0];

    for(int i=0;i<N;i++){
        if(min>m[i])
            min=m[i];
    }

    while(X>=min){
        X-=min;
        max++;
    }

    cout<<max<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
for x in range(N):
    A[x] -= (x+1)

sorted_A = sorted(A)

if len(A) == 1:
    ans = 0
else:
    ans = sum(map(lambda x: abs(x-sorted_A[N//2]),A))

print(ans)

Measured memory_bytes: 26832
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	cin >> N;
	LL a = N % 10;
	if (a == 7)goto Yes;
	N = N / 10;
	a = N % 10;
	if (a == 7)goto Yes;
	N = N / 10;
	a = N % 10;
	if (a == 7)goto Yes;
	goto No;

Yes:
	cout << "Yes\n";
	return 0;
No:
	cout << "No\n";
	return 0;
}


Measured memory_bytes: 3080
(defun split (input stack-string output-list)
  (let ((chara (car input)))
    (case chara
          ((nil) (append output-list (list stack-string)))
          (#\space (split (cdr input)
                                  '()
                                  (append output-list (list stack-string))))
          (otherwise (split (cdr input)
                                    (concatenate 'string stack-string (list chara))
                                    output-list)))))

(defun input-to-list (input)
  (mapcar #'parse-integer (split (concatenate 'list input)
                                 '()
                                 '())))

(defparameter param (input-to-list (read-line)))

(let ((particle (+ (cadr param) (* 3 (car param)))))
  (princ (truncate particle 2)))

Measured memory_bytes: 12776
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  ll l, r;
  cin >> l >> r;
  if (r - l + 1 >= 2019) {
    cout << 0 << endl;
    return 0;
  }
  ll a = l % 2019;
  ll b = r % 2019;
  if (a < b) {
    ll ans = a * (a + 1);
    for (ll i = a; i < b; i++) {
      for (ll j = i + 1; j <= b; j++) {
        ans = min(ans, i * j % 2019);
      }
    }
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int rans=1<<30;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        int ans=0;
        //cout<<a<<endl;
        while(a%2==0){
            //cout<<"W"<<endl;
            ans++;
            a/=2;
        }
        rans=min(ans,rans);
    }
    cout<<rans<<endl;
}


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

int main(){
    int N; cin >> N;
    vector<string> S(N); 
    for(int i=0; i<N; i++){
        cin >> S[i];
    }

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

    int kinds = 1;
    for(int i=1; i<N; i++){
        if(S[i] != S[i-1]) kinds++;
    }

    cout << kinds << endl;
}

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


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

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


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

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

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

    int cnt = 0;
    bool ok = false;
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        if (a == b) cnt++;
        else {
            cnt = 0;
        }

        if (cnt >= 3) {
            ok = true;
        }
    }

    cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3628
import heapq
n, m = map(int, input().split())
A = list(map(int, input().split()))
cost = []
heapq.heapify(cost)
for i in range(n):
    heapq.heappush(cost, -A[i])
for i in range(m):
    target = heapq.heappop(cost) / 2
    heapq.heappush(cost, target)
ans = [int(i) for i in cost]
print(-sum(ans))


Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(auto& v: a) scanf("%d", &v);
	
	sort(begin(a), end(a));
	a.erase(unique(begin(a), end(a)), end(a));

	printf("%s\n", (a.size() == n ? "YES" : "NO"));
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 1e6+5, M = 1e6+6, OO = 0x3f3f3f3f;
int n, m;
int main()
{
    // FIO
    double r;
    cin>>r;
    printf("%0.8lf", 2 * (3.14159265359) * r);
    return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2 * 1e5 + 5)
#define MAXL 20
#define F first
#define S second
#define endl "\n"
#define MOD (lli)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
#define DEBUG if (0) cout << "aqui" << endl;
#define PI 2 * acos(0.0)
typedef pair<int, int> ii;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

lli n, k;

int modFexp(lli x, lli y, lli p){ //Calcula x^y%p em Log Y
	lli ans = 1;
	while(y > 0){
		if(y&1) ans = (ans*x) % p;
		y = y >> 1;
		x = (x*x) % p;
	}
	return ans;
}


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

  cin >> n >> k;

  lli sum = 0;

  lli tot = n + 1;
  for(int i=k;i<=n+1;i++) {
    lli aux = (tot - i + 1);
    // cout << "aux : " << aux << endl;
    sum = (sum%MOD + (1 + ((aux-1)*i)%MOD)%MOD)%MOD;
    // cout << "aux : " << aux << endl;
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
typedef pair<ll,ll> P;
int main(){
  int a[6];
  map<int,int> m;
  for(int i=0;i<6;i++){
    cin>>a[i];
    m[a[i]]++;
  }
  for(int i=1;i<=4;i++){
    if(m[a[i]]==3){
      cout<<"NO";
      return 0;
    }
  }
  cout<<"YES";
}

Measured memory_bytes: 256
use std::cmp;
use std::collections::VecDeque;

const INF: i32 = 1e9 as i32;
const DIR: [(i32, i32); 4] = [(0, -1), (0, 1), (-1, 0), (1, 0)];

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let h: usize = sc.read();
    let w: usize = sc.read();
    let k: i32 = sc.read();
    let board: Vec<_> = (0..h).map(|_| sc.chars()).collect();
    let mut dist = vec![vec![INF; w]; h];

    let mut si = 0;
    let mut sj = 0;
    for i in 0..h {
        for j in 0..w {
            if board[i][j] == 'S' {
                dist[i][j] = 0;
                si = i;
                sj = j;
            }
        }
    }

    let mut q = VecDeque::new();
    q.push_back((0, 0, si, sj));
    for _ in 0.. {
        let mut next_q = VecDeque::new();
        while let Some((time, open, i, j)) = q.pop_front() {
            if i == h - 1 || j == w - 1 || i == 0 || j == 0 {
                let turn = (time + k - 1) / k;
                println!("{}", turn);
                return;
            }
            for (di, dj) in DIR.iter().cloned() {
                let ni = (i as i32) + di;
                let nj = (j as i32) + dj;
                if ni < 0 || nj < 0 {
                    continue;
                }
                let ni = ni as usize;
                let nj = nj as usize;
                if ni >= h || nj >= w {
                    continue;
                }

                if board[ni][nj] == '#' && open > 0 && dist[ni][nj] > time + 1 {
                    dist[ni][nj] = time + 1;
                    if (time + 1) % k == 0 {
                        next_q.push_back((time + 1, k, ni, nj));
                    } else {
                        q.push_back((time + 1, open - 1, ni, nj));
                    }
                } else if board[ni][nj] == '.' && dist[ni][nj] > time + 1 {
                    dist[ni][nj] = time + 1;
                    if (time + 1) % k == 0 {
                        next_q.push_back((time + 1, k, ni, nj));
                    } else {
                        q.push_back((time + 1, open, ni, nj));
                    }
                }
            }

            let next_time = (time + k) / k * k;
            next_q.push_front((next_time, k, i, j));
        }
        q = next_q;
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/12  Problem: 081_arc_c / Link: https://arc081.contest.atcoder.jp/tasks/arc081_c?lang=en  ----- */
/* ------問題------

文字列 S に対して，その文字列を構成する文字を 0 文字以上取り除き，残った文字を元の順番で並べて得られる文字列を S の部分列と呼びます． たとえば，arc や artistic や (空文字列) は artistic の部分列ですが，abc や ci は artistic の部分列ではありません．
英小文字からなる文字列 A が与えられます． このとき，英小文字からなる文字列で，A の部分列ではないようなもののうち，最も短いものを求めてください． ただし，そのようなものが複数ある場合には，辞書順で最小のものを求めてください．

-----問題ここまで----- */
/* -----解説等-----

後ろからやる。
長さ最小を考えたとき、アルファベットが全種出てくる回数＋１文字必要。
このとき、登場していないものが最小のものとなる。
これを後ろから記録していき、復元すれば良い。
復元は登場するまでスキップできる。

----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	string s;
	cin >> s;
	// 長さが最小
	VI alinfo(26, 0);
	VI premin(SZ(s) + 1, 0);
	ans = 1;
	FORR(i, SZ(s) - 1, 0 - 1) {

		LL ret = 0;
		alinfo[s[i] - 'a'] = 1;
		premin[i] = premin[i+1];
		FOR(al, 0, 26) {
			if (alinfo[al])ret++;
			else break;
		}
		if (ret == 26) {
			FOR(al, 0, 26) {
				alinfo[al] = 0;
			}
			ans++;
		}
		premin[i] = ret % 26;

	}
	//FOR(i, 0, 26) {
	//	cout << alinfo[i] << " ";
	//}cout << endl;	
	//debug(ans);
	FOR(i, 0, SZ(s)) {
		char c = 'a' + premin[i];
		cout << c;
		while (i < SZ(s) && s[i] != (c))i++;
	}
	cout << "\n";

	return 0;
}


Measured memory_bytes: 1428
/*****Be Name Khoda*****/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define Size(x) ((int)x.size())
#define All(x) x.begin() , x.end()

using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a , b;
	cin >> a >> b;
	if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		cout << "Possible";
	else
		cout << "Impossible";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	int w, h, x, y; cin >> w >> h >> x >> y;

	double ans = (double) w * h / 2;
	if (x * 2 == w && y * 2 == h) {
		cout << setprecision(10) << ans << " " << 1 << endl;
	}
	else {
		cout << setprecision(10) << ans << " " << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#C
n, m = map(int, input().split())
l = []
r = []
for i in range(m):
    lin = list(map(int, input().split()))
    l.append(lin[0])
    r.append(lin[1])
lma = max(l)
rmi = min(r)
if lma > rmi:
    print(0)
else:
    print(rmi - lma + 1)

Measured memory_bytes: 11040
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <numeric>

using namespace std;

typedef long long int ll;
typedef long int li;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
    string ans;
    ll a,b,c,d,e,f,g,k,n,p,q,x;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a<=k)ans="Yay!";
    else ans=":(";
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define N 10000
int main()
{
  int gyon,numhai[N],i,j,ama=0,cou=0;
  scanf("%d",&gyon);
  for(i=0;i<gyon;i++)
    {
      scanf("%d",&numhai[i]);
    }
  for(i=0;i<gyon;i++)
    {
      if(numhai[i]==2)
	{
	  // printf("prim2\n");
	  cou++;
	}
      else
	{
	  //printf("%d\n",i);
	  for(j=2;j<=sqrt(numhai[i])+1;j++)
	    {
	      ama=numhai[i]%j;
	      if(ama==0)
		break;
	    }
	  if(ama!=0)
	    {
	      // printf("prim%d\n",numhai[i]);
	      cou++;
	    }
	}
    }
  printf("%d\n",cou);
  return 0;
}



Measured memory_bytes: 2048