akhauriyash/Code-Regression huggingface dataset:
package main

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

var X, answer int

func readVariables() {
	X = nextInt()
	answer = 1
}

func main() {
	readVariables()
	for b := 2; b <= X; b++ {
		v := b * b
		for v <= X {
			answer = MaxInt(v, answer)
			v *= b
		}
	}
	fmt.Println(answer)
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int n;
	cin>>n;

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

	vector<int> dp(n);

	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for(int i=2;i<n;i++) {
		dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
using namespace std;
#define mod 1000000007;
long long fuc(int a){
    long long r=1;
    for(int i=1;i<=a;i++){
        r*=i;
        if(r>1e9)r%=mod;
    }
    return r;
}
int n,m;
long long ans;
main(){
    cin>>n>>m;
    if(abs(n-m)==0)ans=fuc(n)*fuc(m)*2;
    else if(abs(n-m)==1)ans=fuc(n)*fuc(m);
    ans%=mod;
  	cout<< ans <<endl;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
  n = ni()
  res = set()
  for i in range(1, n // 2 + 1):
    a, b = n - i, i
    if a == b:
        continue
    if (a, b) not in res and (b, a) not in res:
      res.add((a, b))
  print(len(res))
  
if __name__ == '__main__':
  main()

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

const int INF = 1e9 + 7;

struct segtree{
    static const int SEG=1<<18;
    vector<P> dat;
    segtree():dat(SEG*2, P(INF,INF)){}
    void update(int k, P p){
        k+=SEG-1;
        dat[k]=p;
        while(k){
            k=(k-1)/2;
            dat[k]=min(dat[k*2+1],dat[k*2+2]);
        }
    }
    P query(int a,int b,int k=0,int l=0,int r=SEG){
        if(r<=a||b<=l)return P(INF,INF);
        if(a<=l&&r<=b)return dat[k];
        return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
};

int n;
int p[200005];
 
segtree odd,even;
 
typedef tuple<P,P,P> T;

T calc(int l, int r) {
    int ll, rr;
    if (l%2 == 1) {
        ll = odd.query(l,r).second;
        rr = even.query(ll,r).second;
    } else {
        ll = even.query(l,r).second;
        rr = odd.query(ll,r).second;
    }
    return T({p[ll], p[rr]}, {ll,rr}, {l,r});
}

int main() {
    cin >> n;
    rep(i,n){
        cin>>p[i];
        if(i&1)odd.update(i,P(p[i],i));
        else even.update(i,P(p[i],i));
    }

    vector<int> ans;
    priority_queue<T,vector<T>,greater<T>>que;
    que.push(calc(0,n));

    while(!que.empty()) {
        P a, b, c;
        tie(a,b,c) = que.top();
        que.pop();

        ans.push_back(a.first);
        ans.push_back(a.second);

        int l,r,ll,rr;
        tie(l,r) = c;
        tie(ll,rr) = b;

        if (l!=ll) que.push(calc(l,ll));
        if (ll + 1 != rr) que.push(calc(ll+1,rr));
        if (rr+1!=r) que.push(calc(rr+1,r));
    }

    rep(i,ans.size()){
        if(i)cout<<" ";
        cout<<ans[i];
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 14756
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1e15+7;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    vector<int> a(26,0);
    rep(i,0,s.size()){
      a[s[i]-'a']++;
    }
    if(s.size()<26){
      rep(i,0,26){
        if(a[i]==0){
          cout << s << char('a'+i) << endl;
          return 0;
        }
      }
    }
    rrep(i,0,s.size()-1){
      if(s[i+1]>s[i]){
        int ans = 26;
        rep(j,i+1,s.size()){
          if(s[i]<s[j]){
            chmin(ans,s[j]-'a');
          }
        }
        cout << s.substr(0,i) << char('a'+ans) << endl;
        return 0;
      }
    }
    cout << -1 << endl;
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  int n;
  cin>>n;
  while(1){
  if(n/100==(n%100)/10 && (n%100)/10==n%10){
    cout<<n<<endl;break;
  }else{
    n++;
  }}


return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n-1); i >= 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main(){
	int a,b;
	cin >> a >> b;
	if(b<10) a*=10;
	else if(b<100) a*=100;
	else a*=1000;
	a+=b;
	rep(i,10000) {
		if(i*i==a) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  ll n, k;
  cin >> n >> k;
  n %= k;
  chmin(n, abs(n - k));
  cout << n << endl;
}


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

using namespace std;

#define LL long long
#define MOD 1000000007

int n, d, x[11][11], ans = 0;

int main() {
	cin >> n >> d;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}
	for (int i = 0; i < n; i++){
		for (int j = i + 1; j < n; j++) {
			int tmp = 0;
			for (int k = 0; k < d; k++) {
				int t = 0;
				t = x[i][k] - x[j][k];
				t *= t;
				tmp += t;
			}
			for (int k = 0; k * k <= tmp; k++) {
				if (k*k == tmp)ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (unsigned n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif /* __DEBUG__ */

int main()
{
  ulli Q, H, S, D, N;
  std::cin >> Q >> H >> S >> D >> N;
  
  std::vector<ulli> v;
  v.push_back(D * 1);
  v.push_back(S * 2);
  v.push_back(H * 4);
  v.push_back(Q * 8);
  std::sort(v.begin(), v.end());
  
  ulli C = (N / 2) * v[0];
  
  if (N % 2 == 1) {
    std::vector<ulli> u;
    u.push_back(S * 1);
    u.push_back(H * 2);
    u.push_back(Q * 4);
    std::sort(u.begin(), u.end());
    
    C += u[0];
  }
  
  std::cout << C << std::endl;
  
  return 0;
}

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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define MOD 998244353

uint add(uint a, uint b) { return a+b < MOD ? a+b : a+b-MOD; }
uint sub(uint a, uint b) { return a < b ? a+MOD-b : a-b; }
uint mul(uint a, uint b) { return (ull)a*b%MOD; }
uint sqr(uint a) { return mul(a, a); }

uint modpow(uint b, uint e)
{
    uint r = 1;
    for (; e; e >>= 1) {
        if (e&1) r = mul(r, b);
        b = sqr(b);
    }
    return r;
}

uint modpowll(uint b, ull e)
{
    uint r = 1;
    for (; e; e >>= 1) {
        if (e&1) r = mul(r, b);
        b = sqr(b);
    }
    return r;
}

uint modinv(uint n) { return modpow(n, MOD-2); }
uint moddiv(uint n, uint d) { return mul(n, modinv(d)); }

void uadd(uint &a, uint b) { a = add(a, b); }
void usub(uint &a, uint b) { a = sub(a, b); }

#define MX 3072

uint dp[MX][MX];

int main()
{
    canhazfast();

    int a, b, c, d;

    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for (int i = a; i <= c; ++i) {
        for (int j = b; j <= d; ++j) {
            if (i > a) uadd(dp[i][j], mul(dp[i-1][j], j));
            if (j > b) uadd(dp[i][j], mul(dp[i][j-1], i));
            if (i > a && j > b) usub(dp[i][j], mul(dp[i-1][j-1], (i-1)*(j-1)));
        }
    }
    cout << dp[c][d] << '\n';

    return 0;
}


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


int main(){
	std::vector<int> vegetable; //dataset
	int n; //number of purchase
	int m; //capacity of bag

	while(std::cin >> n >> m){ //input dataset
		if(n == 0 && m == 0) //end of input
			break;

		std::vector<int> price; //price of vegetable
		for(int i = 0; i < n; ++i){ //input price
			int data;
			std::cin >> data;
			price.push_back(data);
		}

		
		std::sort(price.begin(), price.end(), std::greater<int>()); //sort price in descending order


		for(int i = 0; i < n; ++i){
			vegetable.push_back(price[i]);
		}

		int ans = 0; //minimum cost
		int count = 1; //counter
		while(!vegetable.empty()){
			if(count % m == 0){ //cheapst vegetable
				vegetable.erase(vegetable.begin());
				++count;
			} else if(count % m != 0){ //not cheapst vegetable
				ans += (int)vegetable.front();
				vegetable.erase(vegetable.begin());
				++count;
			}
		}
		std::cout << ans << std::endl; //output answer
		
	}


	return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <map>
using namespace std;

#define p_var(var) cout << #var << " = " << var << endl

int num_val;
string input;
int idx;
int variable;

bool formula();
bool inpar();
bool equation();

bool formula() {
	switch(input[idx++]) {
	case 'T':
		return true;
	case 'F':
		return false;
	case '-':
		return !formula();
	case '(':
		return inpar();
	default:
		return ((variable >> (input[idx-1] - 'a')) & 1);
	}
}

bool inpar() {
	bool left = formula();
	char ope = input[idx++];
	if(ope == '-')
		++idx;
	bool right = formula();
	++idx;
	switch(ope) {
	case '*':
		return (left & right);
	case '+':
		return (left | right);
	default:
		return ((!left) | right);
	}
}

bool equation() {
	for(variable = 0; variable < (1<<num_val); ++variable) {
		idx = 0;
		bool left = formula();
		++idx;
		bool right = formula();
		if(left != right)
			return false;
	}
	return true;
}

int main() {
	cin.tie(false);
	ios::sync_with_stdio(false);
	
	while(cin >> input, input != "#") {
		num_val = 0;
		map<char, char> trans;
		trans.clear();
		for(int i=0; i<input.size(); i++) {
			if('a' <= input[i] && input[i] <= 'k') {
				map<char, char>::iterator it = trans.find(input[i]);
				if(it != trans.end())
					input[i] = (*it).second;
				else {
					trans.insert(pair<char, char>(input[i], 'a'+(num_val)));
					input[i] = 'a'+num_val++;
				}
			}
		}
				
		if(equation())
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>

using namespace std;
using PIC = pair<int, char>;

const vector<int> num_match = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

vector<PIC> nums;
string s_cand;

bool bigger(const string &s, const string &t) {
	if (s.size() == t.size()) {
		return s > t;
	} else {
		return s.size() > t.size();
	}
}

void make_str(int n, string s) {
	if (n == 0) {
		if (bigger(s, s_cand)) {
			s_cand = s;
		}
		return;
	}

	for (auto p: nums) {
		if (n >= p.first) {
			make_str(n - p.first, s + p.second);
		}
	}
}

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


	vector<int> a(m, 0);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	map<int, int> tmp;
	for (auto x: a) {
		tmp[num_match[x]] = x;
	}
	for (auto p: tmp) {
		nums.emplace_back(p.first, '0' + p.second);
	}

	auto nums_head = nums[0];
	reverse(nums.begin(), nums.end());
	nums.pop_back();
	reverse(nums.begin(), nums.end());

	string ans;
	int n2 = n % nums_head.first;
	int n1 = n - n2;
	if (n2 == 0) {
		ans = string(n1 / nums_head.first, nums_head.second);
	} else {
		for (int i = 0; i < 20; i++) {
			s_cand.clear();
			make_str(n2, "");
			if (!s_cand.empty()) {
				string t = s_cand + string(n1 / nums_head.first, nums_head.second);
				sort(t.begin(), t.end(), greater<char>());
				if (bigger(t, ans)) {
					ans = t;
				}

			}
			// printf("i %2d: %s\n", i, s_cand.c_str());

			n1 -= nums_head.first;
			n2 += nums_head.first;

			if (n1 < 0) {
				break;
			}
		}
	}

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


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) { //Simply store all segment starts and ends 
		//in array list and iterate through all possibilities accordingly
		Scanner input = new Scanner(System.in);
		long N = input.nextLong();
		long sub = 1;
		while (N>0) {
			N-=sub;
			sub++;
		}
		long bad = Math.abs(N);
		for (long i = 1; i < sub; i++) {
			if (i!=bad) System.out.println(i);
		}
	}
}

Measured memory_bytes: 22484
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    vector<int> vec{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K = 0;
    cin >> K;
    cout << vec[K - 1] << endl;
    
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int l=-1, r=-1;
    for(int i=0;i<s.size()-1;++i){
        if(s[i] == s[i+1]){
            l = i+1;
            r = i+2;
            break;
        }
        if(i < s.size() - 2 && s[i] == s[i+2]){
            l = i+1;
            r = i+3;
            break;
        }
    }
    cout << l << ' ' << r << endl;

    return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a[3];
    string ss;cin>>ss;
    rep(i,(int)ss.size()){
      if(ss[i]=='R')a[0].push_back(i);
      else if(ss[i]=='G')a[1].push_back(i);
      else a[2].push_back(i);
    }
    ll tot=a[0].size()*a[1].size()*a[2].size();
    rep(i,(int)ss.size())for(int j=i+1;j<(int)ss.size();j++){
          if(ss[j]==ss[i])continue;
          if((ss[i]=='R'&&ss[j]=='G')||(ss[i]=='G'&&ss[j]=='R')){
            if(2*j-i<(int)ss.size()&&ss[2*j-i]=='B')tot--;
          }
          else if((ss[i]=='R'&&ss[j]=='B')||(ss[i]=='B'&&ss[j]=='R')){
            if(2*j-i<(int)ss.size()&&ss[2*j-i]=='G')tot--;
          }
          else if((ss[i]=='G'&&ss[j]=='B')||(ss[i]=='B'&&ss[j]=='G')){
            if(2*j-i<(int)ss.size()&&ss[2*j-i]=='R')tot--;
          }
    }
    cout<<tot<<endl;
    return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    ll n, a, b; cin >> n >> a >> b;
    if((b - a) % 2 == 0) cout << (b - a) / 2 << endl;
    else cout << min(a - 1, n - b) + 1 + (b - a - 1) / 2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    long long n,k,a,b,ans;
    cin>>n>>k;
    a=n/k;
    if(k&1) ans=a*a*a;
    else {
        b=(n+k/2)/k;
        ans=a*a*a+b*b*b;
    }
    cout<<ans;
}

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

using namespace std;

int f (int x, int y, int z)
{
    return x*x + y*y + z*z + x*y + y*z + z*x;
}

int main()
{
    const int MM = 10000;    
    int N;    
    cin >> N;
    vector<size_t> n(N+1, 0);

    int x, y, z;

    for(x = 1; x <= MM; ++x)
    {
        int a = f(x, 1, 1);
        if(a > N) { break;}

        for(y = 1; y <= x; ++y)    
        {
            int b = f(x, y, 1);
            if(b > N) { break;}

            for(z = 1; z <= y; ++z)    
            {
                int c = f(x, y, z);
                if(c <= N) 
                { 
                    int add = 0;    

                    if( (x == y) && (y == z) )    { add = 1;}  // x = y = z
                    else if((x != y) && (y == z)) { add = 3;}  // x > y = z
                    else if((x == y) && (y != z)) { add = 3;}  // x = y > z
                    else if((x != y) && (y != z)) { add = 6;}  // x > y > z
                    n[c] += add;
                }
                else
                {
                    break;    
                }
            }
        }
    }

    for(int i = 1; i <= N; ++i)
    {
        cout << n[i] << endl;
    }
    //cout << 

    return 0;    
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define LINF		((ll)1 << 63 -1)
#define INF 		(1<<29)
#define MINF		-2000000007
#define MAX 		200050

const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

int DP[MAX];
int prime[MAX];
bool is_prime[MAX+1];

int sieve(int n){
	int p=0;
	REP(i,n+1)is_prime[i]=true;
	is_prime[0] = is_prime[1] = false;
	REPS(i,2,n+1){
		if(is_prime[i]){
			prime[p++] = i;
			REPS(j,2*i,n+1)is_prime[j] = false;
		}
	}
}


//
int main(){
	int N;
	cin >> N;
	V a(N);
	REP(i,N)cin>>a[i];

	//sieve(N);

	V ans;
	for(int i=N;i>0;--i){
		//cout << i << " " << DP[i] << " ";
		DP[i] = a[i-1]^DP[i];
		//cout << DP[i] << " " << a[i-1] << endl;
		if(DP[i]){
			ans.push_back(i);
			for(int j=1;j*j <= i; ++j)
				if(i % j == 0){
					DP[j] ^= DP[i];
					//printf("[%d : %d]",j,DP[j]);
					if(j!=1 && j!=(i/j)){DP[i/j] ^= DP[i];
					//printf("[%d : %d]",i/j,DP[i/j]);
					}
					//cout << endl;
				}
		}
	}

	cout << ans.size() << endl;
	if(ans.size()==0)return 0;
	REP(i,ans.size())cout << ans[ans.size()-i-1] << " ";
	cout << endl;

	return 0;
}




Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#ifdef TEST
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#endif
#define ins insert
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int v, m;
string S;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> S;
	for (char c : S) {
		if (c == 'S') v = 0;
		else v++;
		m = max(m, v);
	}
	cout << m << '\n';
}


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

using namespace std;
int main() {
    int n;
    int sum = 0;
    int max_v = 0;

    cin >> n;

    vector<int> v;

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

    if (v[0] == 1) sum++;
    for (int i = 1; i < n; i++) {
        if (v[i-1] == 1 && v[i] == 1) {
            sum++;
        } else if (v[i-1] == 0 && v[i] == 1) {
            sum = 1;
        }

        if (max_v < sum) {
            max_v = sum;
        }
    }

    cout << (max_v+1) <<endl;

    return 0;
}


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

int main(){
    int num1;
    int num0;
    int nummin;
    int choice;
    int r;

    cin>>num1>>num0>>nummin>>choice;
    
    if(num1>=choice){
        r=choice;
    }else if(num1+num0>=choice){
        r=num1;
    }else{
        int k=choice-num1-num0;
        r=num1-k;
    }

    cout<<r<<endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)

const ll MOD = 1e9+7;

int main(){

    ll n, k; cin >> n >> k;

    ll a[n];
    rep(i, n){
        cin >> a[i];
    }

    ll cnt1 = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(a[i] > a[j]) cnt1++;
        }
    }

    ll cnt2 = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(a[i] > a[j]) cnt2++;
        }
    }

    ll cnt1d = (cnt1 * k) % MOD;
    ll cnt2d = 0;
    if(k % 2 == 0){
        cnt2d = ((k/2*(k-1) % MOD) * cnt2) % MOD;
    }
    else{
        cnt2d = ((((k-1)/2*k) % MOD) * cnt2) % MOD;
    }

    cout << (cnt1d + cnt2d) % MOD;

    // cout << cnt1 << " " << cnt2;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    String[] strs = {"dream", "dreamer", "erase", "eraser"};
    if(ans(0, str,strs)){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
  
  public static boolean ans(int index, String str, String[] strs){
    if(str.length() == index){
      return true;
    }
    for(int i = 0; i < strs.length; i++){
      if(str.indexOf(strs[i], index) == index){
        if(ans(index + strs[i].length(), str, strs)){
          return true;
        }
      }
    }
    return false;
  }
}

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

long long taj(long long H)
{
    if(H==1)return 1;
    else
    {
        long long n=taj(H/2);
        return n*2+1;
    }
}

int main()
{
    long long H;
    cin>>H;
    cout<<taj(H)<<endl;

    return 0;
}


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

using namespace std;

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

    int n;
    while(cin>>n,n){
        vector<int> v(n);
        for(int i=0;i<n;i++) cin>>v[i];
        sort(v.begin(),v.end());
        int s=0;
        for(int i=1;i<n-1;i++) s+=v[i];
        cout<<s/(n-2)<<endl;
    }
}

Measured memory_bytes: 3140
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

const ll MOD = pow(10, 9) + 7;

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

	vector<ll> pa(n);
	for (int i = 0; i < n; i++)
		cin >> pa[i];

	vector<ll> na = pa;


	sort(pa.begin(), pa.end(), greater<ll>());
	sort(na.begin(), na.end());

	int pi = 0;
	int ni = 0;

	ll ps, ns;

	int cnt = k;
	ll ans = 1;

	while (cnt > 1)
	{
		ps = pa[pi] * pa[pi + 1];
		ns = na[ni] * na[ni + 1];

		if (ps > ns) {
			ans = ans * pa[pi++] % MOD;
			ans = ans * pa[pi++] % MOD;
		}
		else {
			ans = ans * na[ni++] % MOD;
			ans = ans * na[ni++] % MOD;
		}
		cnt -= 2;
	}

	if (cnt) {
		ans = ans * pa[pi] % MOD;
	}

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

	ll min = abs(pa[0]);
	int id = 0;

	sort(pa.begin(), pa.end());
	sort(na.begin(), na.end(), greater<ll>());

	for (int i = 0; i < n; i++) {
		if (pa[i] > 0) {
			pa.erase(pa.begin(), pa.begin() + i);
			break;
		}
		if (i == n - 1) {
			pa.erase(pa.begin(), pa.end());
		}
	}

	for (int i = 0; i < n; i++) {
		if (na[i] < 0) {
			na.erase(na.begin(), na.begin() + i);
			break;
		}
		if (i == n - 1) {
			na.erase(na.begin(), na.end());
		}
	}

	pi = 0;
	ni = 0;

	cnt = 0;
	ans = 1;
	
	while (cnt < k)
	{
		if (pi >= pa.size() ) {
			ans = ans * na[ni++] % MOD;
		}

		else if (ni >= na.size()) {
			ans = ans * pa[pi++] % MOD;
		}

		else {
			ps = pa[pi];
			ns = na[ni] * (-1);

			if (ps < ns) {
				ans = ans * pa[pi++] % MOD;
			}
			else {
				ans = ans * na[ni++] % MOD;
			}
		}

		cnt++;
	}

	cout << (ans + MOD) % MOD << endl;
	return 0;
}


Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

vector<ll> a;
vector<ll> p;

ll F(ll i, ll j){
    if(i<=0){
        return 1;
    }else{
        if(j<=1) return 0;
        else if(j <= 1+a[i-1]) return F(i-1,j-1);
        else if(j == 2+a[i-1]) return p[i-1]+1;
        else if(j <= 2+2*a[i-1]) return p[i-1]+1+F(i-1,j-2-a[i-1]);
        else return 2*p[i-1]+1;
    }
}

int main(){
    ll n,x;
    cin>>n>>x;
    a.resize(n+1,0);
    p.resize(n+1,0);
    a[0]=1; p[0]=1;
    rep(i,0,n){
        a[i+1]=2*a[i]+3;
        p[i+1]=2*p[i]+1;
    }
    ll ans=F(n,x);
    cout<<ans<<endl;
}

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

typedef long long int ll;
ll w[101];
ll val[101];
ll dp[101][100001];
ll func(ll n,ll W)
{
    if(n==0 || W==0)
    return 0;
    if(dp[n][W]!=-1)
    return dp[n][W];
    if(W>=w[n-1])
    return dp[n][W]=max(val[n-1]+func(n-1,W-w[n-1]),func(n-1,W));
    else 
    return dp[n][W]=func(n-1,W);
}
int main() {
	ll n,W;
	cin>>n>>W;
	
	for(int i=0;i<n;i++)
	{
	    cin>>w[i];
	    cin>>val[i];
	}
	memset(dp,-1,sizeof(dp));
	
	cout<<func(n,W)<<"\n";
	return 0;
}

Measured memory_bytes: 82508
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define o 1000005
#define re register int
#define ll long long
#define g0(a) memset(a,0,sizeof(a))
#define gc(a,b) memcpy(a,b,sizeof(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define pa pair<int,int>
#define mpp make_pair
#define s1 first
#define s2 second
#define go(x) for(ll i=h[x];i;i=w[i].next)
using namespace std;
inline int read()
{
	register int data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar();
	return data*w;
}
int n,f[o],g[o],dp[5005][5005],s[o];
const int mod=1e9+7;
int h[o],cnt;
struct node{
	int to,next;
}w[o];
void add(int x,int y){++cnt;w[cnt].to=y;w[cnt].next=h[x];h[x]=cnt;}
void fix(int &x){x-=mod;x+=x>>31&mod;}
void dfs(int x,int fa)
{
	s[x]=1;dp[x][1]=1;
	for(int i=h[x];i;i=w[i].next)
	{
		int y=w[i].to;
		if(y==fa)continue;
		dfs(y,x);	
		memset(g,0,sizeof(int)*(s[x]+s[y]+1));
		FOR(j,0,s[x])FOR(k,0,s[y])if(dp[x][j]&&dp[y][k])fix(g[j+k]+=1ll*dp[x][j]*dp[y][k]%mod),fix(g[j]+=(k&1)?0:mod-1ll*dp[x][j]*dp[y][k]%mod*f[k>>1]%mod);
		s[x]+=s[y];
		memcpy(dp[x],g,sizeof(int)*(s[x]+1));
	}
}
int main()
{
	n=read();
	FOR(i,1,n-1)
	{
		int x=read(),y=read();
		add(x,y);add(y,x);
	}
	f[0]=1;
	FOR(i,1,n)f[i]=1ll*f[i-1]*(2*i-1)%mod;
	dfs(1,0);
	int ans=0;
	FOR(i,1,n/2)fix(ans+=1ll*dp[1][2*i]*f[i]%mod);
	cout<<ans<<'\n';
	return 0;
}

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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = min(a, b); i > 0; i--) {
        if (a % i == 0 && b % i == 0) k--;
        if (k == 0) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    A, B, K = map(int, input().split())
    if K > A:
        B -= K - A
    A -= K
    print(max(0, A), max(0, B))


def main():
    solve()


if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define dbg(S) { int f=1; for(auto x:S) cerr<<(f?"[":", ")<<x, f=0; cerr<<"]\n"; }

using namespace std;

class mint{
	static const int MOD=998244353;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=m.inverse(); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	mint inverse()const{
		int a=x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

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

	if(a[0]!=0 || count(a.begin(),a.end(),0)!=1){
		cout<<"0\n";
		return 0;
	}

	vector<int> hist(n+1);
	rep(i,n) hist[a[i]]++;

	mint ans=1;
	rep(i,n){
		ans*=pow(mint(hist[i]),hist[i+1]);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int m=1000005;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  vector<int> cnt(m);
  for(auto x:a){
    if(cnt[x]!=0){
      cnt[x]=2;
    }else{
      for(int i=x;i<m;i+=x)cnt[i]++;
    }
  }
  int ans=0;
  for(auto x:a){
    if(cnt[x]==1)ans++;
  }
  cout<<ans<<endl;
  return 0;
}
  


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)
#define SUM(v) accumulate((v).begin(),(v).end(),0ll)
#define range(i,left,right) (left<=i && i<right)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int iscount(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int n,k;
    cin>>n>>k;
    int ans=0;
    REP(i,k,n+2){
        ans = (ans + ((2*n-i+1)*i-(i-1)*i)/2+1)%MOD;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3656
using System;

class AOJ
{
  static int gcd(int x, int y)
  {
    if (y == 0) return x;

    else return gcd(y, x % y);
  }

  static void Main(string[] args)
  {
    string s;

    while ((s = Console.ReadLine()) != null){

      int[] x = Array.ConvertAll(s.Split(' '), int.Parse);

      Console.WriteLine("{0} {1}", gcd(x[0], x[1]), x[0] / gcd(x[0], x[1]) * x[1]);
    }
  }
}

Measured memory_bytes: 9240
import random
import string
N = int(input())
S = input()
l, r = 0, N

def pow_mod(a, b, m):
  ab = 1
  for _ in range(b):
    ab = (ab * a) % m
  return ab

def c2n(c):
  return ord(c) - 97

def hash(s, B, H):
  sh = 0
  for c in s:
    sh = (sh * B + c2n(c)) % H
  return sh

def t(n):
  B, H = 10 ** 8 + 7, 2 ** 64

  if n*2 > N:
    return False
  s, t = S[:n], S[n:n*2]
  sh, th = hash(s, B, H), hash(t, B, H)
  if sh == th:
    return True
  ss = set([sh])
  Bn = pow_mod(B, n, H)
  for i in range(0, N-2*n):
    sh = (sh * B - c2n(S[i]) * Bn + c2n(S[i+n])) % H
    th = (th * B - c2n(S[i+n]) * Bn + c2n(S[i+2*n])) % H
    ss.add(sh)
    if th in ss:
      return True
  return False

while l+1<r:
  m = (l+r)//2
  if t(m):
    l=m
  else:
    r=m

print(l)

Measured memory_bytes: 44764
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = []
for i in range(n):
    lst1.append(int(readline()))
lst1.sort(reverse=True)
if n % 2 == 1:
    minority = n//2
    majority = n - minority
    A = sum(lst1[:minority])*2 - sum(lst1[minority:])*2+sum(lst1[minority:minority+2])
    B = sum(lst1[:majority])*2 - sum(lst1[majority:])*2 - sum(lst1[majority-2:majority])
    ans = max(A, B)
else:
    C = sum(lst1[:n//2])*2 - sum(lst1[n//2:])*2 + lst1[n//2]-lst1[n//2-1]
    D = -C
    ans = max(C, D)
print(ans)


Measured memory_bytes: 44252
#include "stdio.h"
#include<iostream>

using namespace std;

int main(void){

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

  int node_num, dimention, adjacency_node_num;  
  
  int** matrix = new int* [N];
  for(int i=0;i<N;i++){
    matrix[i] = new int [N];
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      matrix[i][j] = 0;
    }
  }

  for(int i=0;i<N;i++){
    cin >> node_num >> dimention;

    for(int i=0;i<dimention;i++){
      cin >> adjacency_node_num;
      matrix[node_num-1][adjacency_node_num-1] = 1;
    } 
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(j != 0){
        printf(" ");
      }
      printf("%d", matrix[i][j]);
    }
    printf("\n");
  }

  for(int i=0;i<N;i++){
    delete [] matrix[i];
  }

  delete [] matrix;  

  return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;



int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int ans = 0;

  // 
  for (int i = 1; i <= N; i++){  // Nが20のとき、1〜20
    int sum = 0; // 合計値の初期設定
    int x = i ; // iが11なら11
    for (int j = 0; j < 5; j++){ //
      sum += x % 10; // 11のあまりは1
      x /= 10; // xを10で割っていくと、
    }

    if (sum >= A and sum <= B){ //sumがA以上かつB以下
      ans += i;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    vector<char> pon= {'0','1', '6','8'};
    vector<char> bon= {'3'};
    string str;
    cin >> str;
    for(auto p : pon){
        if(p == str.back()){
            cout << "pon";
            return 0;
        }
    }
    if(str.back() == '3'){
        cout << "bon";
        return 0;
    }
    else{
        cout << "hon";
    }
    return 0;
}

Measured memory_bytes: 3632
n = int(input())
d = []
for i in range(n):
    s = list(input())
    s.sort()
    d.append(s)
d.sort()
d.append("")
cnt = []    
c = 1
for i in range(n):
    if d[i+1] == d[i]:
        c += 1    
    else:
        if c > 1:
            cnt.append(c)
        c = 1
ans = 0
for c in cnt:
    ans += c*(c-1)//2
print(ans)


Measured memory_bytes: 26512
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define PI 3.141592653589793
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string L;
  cin >> L;
  ll N = L.size();
  vvll dp(N+1, vll(2, 0LL));
  if(L.at(0) == '1'){
    dp.at(1).at(0) = 2LL;
    dp.at(1).at(1) = 1LL;
  }
  else{
    dp.at(1).at(0) = 1LL;
    dp.at(1).at(1) = 0LL;
  }
  for(int i = 1; i < N; i++){
    if(L.at(i) == '1'){
      dp.at(i+1).at(0) = dp.at(i).at(0) * 2LL % MOD;
      dp.at(i+1).at(1) = (dp.at(i).at(1) * 3LL % MOD + dp.at(i).at(0)) % MOD;
    }
    else{
      dp.at(i+1).at(0) = dp.at(i).at(0);
      dp.at(i+1).at(1) = dp.at(i).at(1) * 3 % MOD;
    }
  }
  cout << (dp.at(N).at(0) + dp.at(N).at(1)) % MOD << endl;
}

Measured memory_bytes: 5840
#include<cstdio>
#include<math.h>
#include<algorithm>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001;
#define LLINF 1001001001001001001001;
#define LL long long

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

Measured memory_bytes: 128
def main():
     MOD=10**9+7
     n,k=map(int,input().split())
     t=[]#ｔ＝n//jの種類を数えるのに使う
     t_cnt=[]#tとなるjの個数
     cnt=[0]
     for i in range(1,int(n**0.5)+1):
          tmp=n//i
          if tmp not in t:
               t.append(tmp)
               t_cnt.append(1)
          else:
               cnt[-1]+=tmp
               t_cnt[-1]+=1
     for tmp in range(t[-1]-1,0,-1):
          tmp_j=n//(tmp)-n//(tmp+1)
          if tmp_j!=0:
               t.append(tmp)
               t_cnt.append(tmp_j)
     
     cnt=[]
     now=0
     for i in range(len(t)):
          now+=t[i]*t_cnt[i]
          cnt.append(now)
     kind=len(cnt)
     dp=[cnt]+[[0]*kind for i in range(k-2)]
     
     for i in range(1,k-1):
          for j in range(kind):
               dp[i][j]=(dp[i-1][kind-j-1]*t_cnt[j]+dp[i][j-1])%MOD
     print(dp[-1][-1])
     return
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 93424