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

#define ll long long
#define ld long double
#define PI 3.14159265


int main() {
	ld a, b, x;
	cin >> a >> b >> x;
	
	x /= a;
	
	ld luas = a*b-x;
	cout << fixed << setprecision(7);
	
	if(luas <= a*b/2) {
		ld b2 = luas/a*2;
		
		cout << (ld)90-((ld)atan(a/b2)*(ld)((ld)180.0/(ld)PI)) << "\n";
	} else {
		ld luasair = a*b-luas;
		
		ld a2 = luasair/b*2;
		
		cout << (ld)90-((ld)atan(a2/b)*(ld)((ld)180.0/(ld)PI)) << "\n";
	}
	
}

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

using namespace std;

int main() {
	int i;
	stack<int> s;
	while (cin >> i) {
		if (i==0) {
			int o = s.top(); s.pop();
			cout << o << endl;
		} else {
			s.push(i);
		}		
	}
	return 0;
}

Measured memory_bytes: 1200
while True:
    m,f,r=map(int,input().split())
    x=m+f
    if m == -1 and f == -1 and r == -1:
       break
    elif x < 30 or m == -1 or f == -1:
       print('F')
    elif x >= 80:
       print('A')
    elif x >= 65:
       print('B')
    elif x >= 50:
       print('C')
    elif x >= 30:
        if r >= 50:
           print('C')
        else:
           print('D')



Measured memory_bytes: 5596
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}
const int N = 1e5 + 6;
int cnt[N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  Long n;
  cin >> n;
  string res;
  while (n > 0) {
    res += 'a' + ((n % 26) - 1 + 26) % 26;
    n = (n - 1) / 26;
  }
  reverse(all(res));
  cout << res << endl;
  return 0;
}

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

int main(void){
    int n;
    cin >> n;
    n = n % 10;
    if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
        cout << "hon" << endl;
    } else if(n == 3){
        cout << "bon" << endl;
    } else {
        cout << "pon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3

from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


N, M = map(int, input().split())
edges = []
for _ in range(M):
    u, v = map(int, input().split())
    edges.append([u-1, v-1])

# どの島も繋がっていないとき、不便さは最大値 N * (N-1) / 2 を取る
# 1 本ずつ減らすのではなく、最悪のケースから順に辺を追加していくことを考える
# ある辺 u <-> v を追加したときに、島の集合 a と島の集合 b が連結になったとすると、
# 不便さは size(a) * size(b) だけ減る
# disjoint set として島を管理し、最悪のケースから各辺を追加したときの不便さを計算すればよい


def has_same_root(u, v):
    return root(u) == root(v)


def root(u):
    if parents[u] < 0:
        return u
    parents[u] = root(parents[u])
    return parents[u]


def unite(u, v):
    # print(f'unite {u}, {v}')
    u_root = root(u)
    v_root = root(v)
    # pprint(parents)
    # print(f'u_root = {u_root}, v_root = {v_root}')
    # print(f'size(u_root) = {size(u_root)}, size(v_root) = {size(v_root)}')
    if size(u_root) > size(v_root):
        u_root, v_root = v_root, u_root
    parents[u_root] -= size(v_root)
    parents[v_root] = u_root
    # pprint(parents)


def size(u):
    return -parents[root(u)]


parents = [-1 for _ in range(N)]
inconvenience = N * (N-1) // 2
ans = [inconvenience]

for u, v in reversed(edges):
    # print(f'\nu = {u}, v = {v}')
    if not has_same_root(u, v):
        inconvenience -= size(u) * size(v)
        unite(u, v)
    ans.append(inconvenience)

for i in reversed(range(M)):
    print(ans[i])


Measured memory_bytes: 165968
#include <stdio.h>
typedef long long ll;

ll DigitSum(ll b,ll x){
    return x<b?x:DigitSum(b,x/b)+x%b;
}

int main(void){
    ll n,s,ans=-1;
    scanf("%lld%lld",&n,&s);
    if (n<s){
        ans=-1;
    } else if (n==s){
        ans=n+1;
    } else {
        for (ll i=2; i*i<=n; i++){
            if (DigitSum(i,n)==s){
                ans=i;
                break;
            }
        }
        if (ans==-1){
            for (ll i=1; i*i<=n; i++){
                ll b=(n-s)/i+1;
                if ((n-s)%i==0 && DigitSum(b,n)==s){
                    ans=b;
                }
            }
        }
    }
    printf("%lld\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
import bisect

n = int(input())
inp = lambda: sorted(list(map(int, input().split())))
a = inp()
b = inp()
c = inp()

o = 0
for i in b:
    o += bisect.bisect_left(a, i) * (n - bisect.bisect_right(c, i))
print(o)

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

// 解説放送より：1つ目の山の値2*Xを求める方程式を立てて計算する方法

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    ll x = 0;
    rep(i, n) {
        if (i%2==0) x += a[i];
        else x -= a[i];
    }
    vll ans(n);
    ans[0] = x / 2;
    rep1(i, n-1) ans[i] = a[i-1] - ans[i-1];
    rep(i, n) ans[i] *= 2;
    rep(i, n) printf("%lld%c", ans[i], (i<n-1?' ':'\n'));
    return 0;
}


Measured memory_bytes: 4636
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a, b ;
  cin >> a >> b;
  if (a%3==0 || b%3==0 ||(a+b)%3==0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}

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

long long com(long long N, long long R) {
    if (R < 0 || R > N) return 0;
    if (R == 1) return N;
    else if (R == 2) return N * (N-1) / 2;
    else return N * (N-1) * (N-2) / 6;
}

long long pow(long long N, long long k) {
    long long res = 1;
    for (int i = 0; i < k; ++i) res *= N;
    return res;
}

string S;
int N, K;

long long solve(int i, int k, int smaller) {
    if (i == N) {
        if (k == 0) return 1;
        else return 0;
    }
    if (k == 0) return 1;
    
    if (smaller) return com(N-i, k) * pow(9, k);
    else {
        if (S[i] == '0') return solve(i+1, k, false);
        else {
            long long zero = solve(i+1, k, true);
            long long aida = solve(i+1, k-1, true) * (S[i] - '1');
            long long icchi = solve(i+1, k-1, false);
            return zero + aida + icchi;
        }
    }
}

int main() {
    cin >> S >> K;
    N = S.size();
    cout << solve(0, K, false) << endl;
}

Measured memory_bytes: 256
# Problem https://atcoder.jp/contests/abc102/tasks/abc102_b
# Ruby 3rd Try
n = gets.chomp.to_i
ai = gets.chomp.split(' ').map(&:to_i)
maxnum = 1
minnum =  10**9
# p minnum
for j in 0..(n-1) do
    if maxnum <= ai[j]
        maxnum = ai[j]
    end
    if ai[j] <= minnum
        minnum = ai[j]
    end
end
answer = (maxnum-minnum).abs
puts(answer)

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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 N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  rep(i, N)
    cin >> w[i] >> v[i];
  vector<vector<vector<int>>> dp(N+1, vector<vector<int>>(N+1, vector<int>(500)));
  for(int i=1; i<=N; i++) {
    for(int j=1; j<=i; j++) {
      rep(k, 500) {
        chmax(dp[i][j][k], dp[i-1][j][k]);
        if(k-(w[i-1]-w[0]) >= 0)
          chmax(dp[i][j][k], dp[i-1][j-1][k-(w[i-1]-w[0])]+v[i-1]);
      }
    }
  }
  int ans = 0;
  rep(i, N+1) rep(j, 500) {
    if((ll)j+w[0]*i <= W)
      chmax(ans, dp[N][i][j]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 20736
#include <iostream>

using namespace std;

int n, a[2010];
int dp[21][2010];

// i番目以降の要素を使って、mを作れれば1、作れなければ0
int solve(int i, int m) {
  if (dp[i][m] == 2 or dp[i][m] == 1) {
    //cout << "cached" << endl;
    return dp[i][m];
  } else {
    //cout << "not cached" << endl;
  }
  //cout << i << "," << m << endl;
  if (m == 0) {
    dp[i][m] = 2;
    return 2;
  }
  if (i >= n) {
    dp[i][m] = 1;
    return 1;
  }
  if (solve(i+1, m) == 2 || solve(i+1, m-a[i]) == 2) {
    dp[i][m] = 2;
    return 2;
  } else {
    dp[i][m] = 1;
    return 1;
  }
}

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

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int m ;
    cin >> m;
    if (solve(0, m) == 2) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
int main()
{
  //整数iを導入
  int si, s1, s2, s3;
  //入力を求める
  cin >> si;
  s1 = si / 100;
  s2 = (si - 100 * s1) / 10;
  s3 = si - 100 * s1 - 10 * s2;
  //画面にiを表示
  cout << s1 + s2 + s3 << endl;
}


Measured memory_bytes: 256
// SegmentTree
package main

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

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

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

type segmentTree struct {
	data   []int
	offset int
}

func newSegmentTree(n int) segmentTree {
	var result segmentTree
	t := 1
	for t < n {
		t *= 2
	}
	result.offset = t - 1
	result.data = make([]int, 2*t-1)
	return result
}

func (st segmentTree) updateAll(a []int) {
	for i, v := range a {
		st.data[st.offset+i] = v
	}
	for i := st.offset - 1; i > -1; i-- {
		st.data[i] = gcd(st.data[i*2+1], st.data[i*2+2])
	}
}

func (st segmentTree) update(index, value int) {
	i := st.offset + index
	st.data[i] = value
	for i >= 1 {
		i = (i - 1) / 2
		st.data[i] = gcd(st.data[i*2+1], st.data[i*2+2])
	}
}

func (st segmentTree) query(start, stop int) int {
	result := 0
	l := start + st.offset
	r := stop + st.offset
	for l < r {
		if l&1 == 0 {
			result = gcd(result, st.data[l])
		}
		if r&1 == 0 {
			result = gcd(result, st.data[r-1])
		}
		l = l / 2
		r = (r - 1) / 2
	}
	return result
}

func main() {
	N := readInt()
	A := readInts(N)

	st := newSegmentTree(N)
	st.updateAll(A)

	result := st.query(1, N)
	for i := 1; i < N-1; i++ {
		result = max(result, gcd(st.query(0, i), st.query(i+1, N)))
	}
	result = max(result, st.query(0, N-1))

	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

func readInts(n int) []int {
	result := make([]int, n)
	for i := 0; i < n; i++ {
		result[i] = readInt()
	}
	return result
}


Measured memory_bytes: 7184
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
	int N, K,i=1,num=1;
	cin >> N >> K;
	for (i = 1; i <= N; i++)
	{
		if (num > K)
			num += K;
		else
			num *= 2;
	}
	cout << num << endl;
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    long long ans=0;
    int i=0;
    long long mod=1000000007
  ;
    string adjacent;
    if (s[0]==t[0]){
        ans=3;
        i=1;
        adjacent="tate";
    }
    else {
        ans=6;
        i=2;
        adjacent="yoko";
    }
    while (i<n){
        if (adjacent=="tate"){
            if (s[i]==t[i]){
                ans=(ans*2)%mod;
                i++;
                adjacent="tate";
            }else {
                ans=(ans*2)%mod;
                i+=2;
                adjacent="yoko";
            }
        }else {
            if (s[i]==t[i]){
                i++;
                adjacent="tate";
            }else {
                ans=(ans*3)%mod;
                i+=2;
                adjacent="yoko";
            }
        }
    }
    cout << ans << endl;
}
    

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

long long n;
vector<int> a;
vector<vector<vector<int>>> dp;

int main() {
  cin >> n;
  a.resize(1 << n);
  for (int i = 0; i < (1 << n); ++i) cin >> a[i];
  dp.assign(1 << n, vector<vector<int>>(n + 1, vector<int>(2, -1)));
  for (int i = 0; i < (1 << n); ++i) dp[i][0] = {a[i], -1};
  for (int j = 0; j < n; ++j)
    for (int i = 0; i < (1 << n); ++i) {
      if (i >> j & 1) {
        int to = i & ~(1 << j);
        vector<int> v = dp[i][j];
        for (auto p : dp[to][j]) v.push_back(p);
        sort(v.begin(), v.end(), greater<int>());
        while (v.size() > 2) v.pop_back();
        dp[i][j + 1] = v;
      } else
        dp[i][j + 1] = dp[i][j];
    }
  int res = 0;
  for (int i = 1; i < (1 << n); ++i) {
    res = max(res, dp[i][n][0] + dp[i][n][1]);
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 284800
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,n,ans=0;
	cin>>a>>b>>c>>n;
	for (int i=0;i<=3000;i++)
		for (int j=0;j<=3000;j++){
			if (i*a+j*b>n || (i*a+j*b-n)%c) continue;
			ans++;
		}
	cout<<ans;
}

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

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

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

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

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

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

int const MOD = 1000000007;

int main() {
    string s[] = {"1100000011", "1000000010000000100000001", "1111", "1000000110000001", "11000000011", "100000001100000001", "110000011"};
    char c[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G'};
    string a[8];
    while(cin >> a[0]) {
        rep(i,1,8) cin >> a[i];
        string merge;
        rep(i,0,8) merge += a[i];

        rep(i,0,7) {
            if(merge.find(s[i]) != string::npos) cout << c[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1192
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

int solve()
{
	ll x,n;cin>>x>>n;
	vi a(n);
	rep(i,0,n) cin>>a[i];	

	ll mn = inf;
	ll el = -1;

	rep(i,-1000,1000)
	{
		ll pos=1;
		rep(j,0,n) if(a[j]==i) pos=0;
		// whatis(pos);
		if(pos==1 && abs(i-x)<mn){
			mn=abs(i-x);
			el = i;
		} 
	}
	cout<<el<<"\n"; 
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

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

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 3656
#include <string>
#include <vector>
#include <iostream>
#pragma warning(disable : 4996)
using namespace std;
string s, t; int q, a, b, c, d, ssum[100009], tsum[100009];
int main() {
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) ssum[i + 1] = s[i] == 'A' ? 1 : 2;
	for (int i = 0; i < t.size(); i++) tsum[i + 1] = t[i] == 'A' ? 1 : 2;
	for (int i = 0; i < s.size(); i++) ssum[i + 1] += ssum[i];
	for (int i = 0; i < t.size(); i++) tsum[i + 1] += tsum[i];
	scanf("%d", &q);
	while (q--) {
		scanf("%d %d %d %d", &a, &b, &c, &d); a--, c--;
		int lc = (ssum[b] - ssum[a] + 123456789 * 3) % 3;
		int rc = (tsum[d] - tsum[c] + 123456789 * 3) % 3;
		puts(lc == rc ? "YES" : "NO");
	}
	return 0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b > c + d) {
        cout << "Left" << endl;
    } else if (a + b == c + d) {
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

  int N,Q;
  int M,date;
  int com_num[100];
  
  while(1){
    
    cin >>N>>Q;
    if(N==0 && Q==0)break;

    for(int i=0 ; i < 100 ; i++)com_num[i]=0;
    
    for(int i=0 ; i < N ; i++){
      cin >>M;
      for(int j=0 ; j < M ; j++){
	cin >>date;
	com_num[date-1]++;
      }
    }
    
    int max_num=0;
    int best_date=0;
    
    for(int i=0 ; i < 100 ; i++){
      if(com_num[i] >= Q && com_num[i] > max_num){
	max_num=com_num[i];
	best_date=i+1;
      }
    }
    
    cout <<best_date<<endl;
    
  }
  
  
  return 0;
}

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

#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=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;

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

	int n;
	cin >> n;

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

	ll mx = -1e8;
	ll mn = 1e8;

	int mxid = -1;
	int mnid = -1;

	rep(i,n){
		if(a[i] > mx){
			mx = a[i];
			mxid = i;
		}
		if(a[i] < mn){
			mn = a[i];
			mnid = i;
		}
	}

	if(mn >= 0){
		cout << (n-1) << endl;
		rep(i,n-1){
			cout << (i+1) << " " << (i+2) << endl;
		}
	}else{
		if(abs(mx) >= abs(mn)){
			cout << (2*n-1) << endl;
			rep(i,n){
				cout << (mxid+1) << " " << (i+1) << endl; 
			}
			rep(i,n-1){
				cout << (i+1) << " " << (i+2) << endl;
			}
		}else{
			cout << (2*n-1) << endl;
			rep(i,n){
				cout << (mnid+1) << " " << (i+1) << endl; 
			}
			rrep(i,n-1){
				cout << (i+2) << " " << (i+1) << endl;
			}
		}
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL MOD =1e9+7;
const LL maxn = 100000+100;
LL a[maxn];
LL b[maxn];
LL pow_mod(LL a, LL n, LL m)
{
    if(n == 0) return 1;
    LL x = pow_mod(a, n/2, m);
    long long ans = (long long)x * x % m;
    if(n % 2 == 1) ans = ans *a % m;
    return ans;//
}
int main()
{
    int n,m;
    cin>>n>>m;
    LL minx=1000000000;
    LL maxx=-1000000000;
    LL miny=1000000000;
    LL maxy=-1000000000;
    LL X;
   // cout<<minx<<endl;
    for(int i=1;i<=n;i++)
    {
        cin>>X;
        a[i]=X;
        //
       // cout<<X<<"dd"<<endl;

       // cout<<minx<<endl;
       // cout<<minx<<" "<<maxx<<endl;
    }
    for(int j=1;j<=m;j++)
    {
        cin>>X;
        b[j]=X;

       // cout<<miny<<" "<<maxy<<endl;
    }
   // cout<<miny<<" "<<maxy<<endl;
   //////////////
   LL ans1=0;
   for(int l=1,r=n;l<=r;l++,r--)
   {
       ans1+=(r-l)*(a[r]-a[l])%MOD;
       ans1%=MOD;
   }
   LL ans2=0;
   for(int l=1,r=m;l<=r;r--,l++)
   {
       ans2+=(r-l)*(b[r]-b[l])%MOD;
       ans2%=MOD;
   }
//    LL ans=((maxx-minx)%MOD*(maxy-miny)%MOD)%MOD;//---
//    if(n==m)
//    {
//        ans*=pow_mod(2,n-1,MOD);
//    }
//    else
//    {
//        int k=min(n,m);
//        ans*=pow_mod(2,k-1,MOD);
//    }
    cout<<ans1*ans2%MOD;//

}


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

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

  for (int i = 1; i <= B; i++) {
    if (i * A % B == C) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF 1000000000 //
#define LINF (ll)4000000000000000000 //
#define MOD (ll)1000000007
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define PI 3.1415926535898
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

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

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

    int Max = -1;
    int a[n];

    rep(i, n) {
        cin >> a[i];
        if (a[i] == k) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
        Max = max(Max, a[i]);
    }
    
    if (n == 1) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    int GCD = a[n - 1];

    rep(i, n - 1) {
        GCD = gcd(GCD, a[i]);
    }


    POSSIBLE(Max >= k && k % GCD == 0);

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    string S;
    cin >> S;
    int N = sz(S);
    if(N&1){
        int cnt = 0;
        int n = (N-1)/2;
        rep(i, n+1){
            if(S[n+i] == S[n] && S[n-i] == S[n]) cnt++;
            else break;
        }
        cout << n+cnt << endl;
    }
    else{
        int l = N/2-1, r = N/2;
        if(S[l] != S[r]) {cout << r << endl; return 0;}
        int cnt = 0;
        rep(i, r){
            if(S[r+i] == S[r] && S[l-i] == S[l]) cnt++;
            else break;
        }
        cout << r+cnt << endl;
    }
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while (true) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			return 0;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3540
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();

        for(int i = x - (k - 1); i <= x + (k - 1); i++) {
        	System.out.print(i);
        	if(i != x + (k -1)) System.out.print(" ");
        	
        }


    }

    static char[] toCharArray(String str) {
    	char[] chAr = new char[str.length()];
    	chAr = str.toCharArray();
    	return chAr;
    }

    static String[] toStringArray(String str, String delim) {
    	String[] stAr = str.split(delim);
    	return stAr;
    }

    static int[] toIntArray(String str, String delim) {
    	String[] strAr = str.split(delim);
    	int[] intAr = new int[strAr.length];
    	for(int i = 0; i < strAr.length; i++) {
    		intAr[i] = Integer.parseInt(strAr[i]);
    	}
    	return intAr;
    }

    static int toInt(String str) {
    	int num = Integer.parseInt(str);
    	return num;
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	int n, a[101];
	cin >> n;
	rep(i,n) cin >> a[i];
	int cnt = 0;
	rep(i,n) {
		if (i%2==0 && a[i]%2!=0) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

int main(){
    int N; cin >> N;
    int prev; cin >> prev;
    for (int i = 1; i < N; i++)
    {
        int h; cin >> h;
        if(h - prev > 0){
            prev = h-1;
        } else if (h - prev == 0) {
            prev = h;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC085B {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());//2つ以上のスペース区切り入力の取得
            int[] mochi = new int[N];
            for (int i = 0; i < N; i++) {
                mochi[i] = int.Parse(Console.ReadLine());
            }
            int[] dMochi = mochi.Distinct().ToArray();
            // Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
            // Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
            Console.WriteLine(dMochi.Count());
        }
    }
}

Measured memory_bytes: 13280
#define KAKUSUKO

#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X, Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%(m))
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_H = 300, MAX_W = 300;
int H, W, K;
string field[MAX_H];
int ans[MAX_H][MAX_W];

int main() {
    cin >> H >> W >> K;
    rep(i, H) {
        cin >> field[i];
    }

    set<int> vertical_splits;
    rep(i, H) {
        rep(j, W) {
            if (field[i][j] == '#') {
                vertical_splits.insert(j);
            }
        }
    }
    vertical_splits.insert(W - 1);

    int c = 1;
    int lb = 0;
    for (int ub : vertical_splits) {
        bool showed = false;
        rep(i, H) {
            for (int j = ub; j >= lb; --j) {
                if (field[i][j] == '#') {
                    if (showed) {
                        ++c;
                    } else {
                        showed = true;
                    }
                }
                ans[i][j] = c;
            }
        }
        lb = ub + 1;
        ++c;
    }

    rep(i, H) {
        rep(j, W) {
            if (ans[i][j] > K) {
                ans[i][j] = ans[i][j - 1];
            }
        }
    }

    rep(i, H) {
        rep(j, W) {
            cout << ans[i][j] << (j + 1 == W ? '\n' : ' ');
        }
    }

    return 0;
}


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

int main() {
    string S,T;
    cin >> S;
    cin >> T;
    int count = 0;
    for (int i = 0; i < 3; i++) {
        if (S.at(i) == T.at(i)) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,c,d,beg,end;
	cin>>a>>b>>c>>d;
	if(a>c)beg=a;
	else beg=c;
	if(b<d)end=b;
	else end=d;
	if(end-beg<0)cout<<"0"<<endl;
	else cout<<end-beg<<endl;
}

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

RL = s.count('RL')
LR = s.count('LR')
diff = RL + LR

cnt = (N-1) - diff

for i in range(K):
    if diff >= 2:
        diff -= 2
        cnt += 2
    elif diff == 1:
        diff -= 1
        cnt += 1

print(cnt)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

    int ave = ceil((double) sum / n);
    int tmp = floor((double) sum / n);
    int ans = 0, w = 0;
    for(int i=0; i<n; i++){
        ans += pow((a[i] - ave), 2);
        w += pow((a[i] - tmp), 2);
    }
    ans = min(ans, w);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():

    n = int(input())
    s = input()
    ans = 0
    for i in range(n-2):
        if s[i] == "A" and s[i+1]=="B" and s[i+2] =="C":
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 13428
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
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; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll N;
    cin >> N;
    VLL L(N);
    rep(i,N){
        cin >> L[i];
    }
    ll count=0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            for(int k=j+1; k<N; k++){
                if(L[i]<L[j]+L[k] && L[j]<L[i]+L[k] && L[k]<L[i]+L[j]){
                    if(L[i]!=L[j] && L[j]!=L[k] && L[i]!=L[k]){
                        count++;
                    }
                }
            }
        }
    }
    cout << count << endl;
}

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

int main() {
  int N;
  string color;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> color;
    if(color=="Y"){
      cout << "Four" << endl;
      break;
    }
    else if(i==N-1){
      cout << "Three" << endl;
    }
  }
}

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;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

vector<pair<ll,int>> prime_factor(ll n) {
  vector<pair<ll,int>>res;
  for(ll i = 2; i * i <= n; i++) {
    if(n % i == 0) {
      int t = 1;
      n /= i;
      while(n%i==0){
        t++;
        n/=i;
      }
      res.push_back(pair<ll,int>(i,t));
    }
  }
  if(n != 1) res.push_back(pair<ll,int>(n,1));
  return res;
}

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint mpow(int n,int m) {
  if (n == 0) return 1;
  mint x = mpow(n/2,m);
  x *= x;
  if (n%2 == 1) x *= m;
  return x;
}

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];
  map<int,int> lcm;
  rep(i,n){
    auto f = prime_factor(a[i]);
    for(auto p:f){
      chmax(lcm[p.first],p.second);
    }
  }
  mint tot = 1;
  for(auto p:lcm){
    tot *= mpow(p.second,p.first);
  }
  //cout << tot.x << endl;
  mint ans = 0;
  rep(i,n){
    ans += tot/a[i];
  }
  cout << ans.x << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

// M: 初項, N: 項数
ll calc(ll M, ll N){
    return N*(2*M+N-1)/2;
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int mod = 1000000007;

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

    int N,K; cin >> N >> K;
    vector<ll> res(N+2, 0LL);

    ll ans = 0LL;
    FOR(i, K, N+2){
        ll big = calc(N-i+1,i);
        ll small = calc(0,i);
        //cout << "big= " << big << " small= " << small << endl;
        ans += (big - small + 1) % mod;
    }

    cout << ans % mod << endl;

    return 0;
}


Measured memory_bytes: 4760
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


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

	ll saidai = (ll)A * B;
	int saishou = A + B - 1;
	if (N < saishou || N > saidai) {
		printf("-1");
		return 0;
	}

	int n = N;
	rep1(i, A) {
		putint(n - A + i);
	}
	n -= A;
	if (B > 1) {
		int dv = (N - A) / (B - 1);
		int rd = (N - A) % (B - 1);
		rep(i, B - 1) {
			int k = dv + (i < rd);
			rep1(j, k) {
				putint(n - k + j);
			}
			n -= k;
		}
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
int main()
{
  IOS;
   string s;
  cin>>s;
   ll q;
  cin>> q;
  ll rev=0;
  string r1="";
  string r2="";
  while(q--)
  {
     ll k;
    cin>>k;
     if(k==1)
     {
        rev=(rev+1)%2;
     }
    else
    {
       ll p;
      cin>>p;
       if((p+rev)%2==1)
       {
          char c;
         cin>>c;
          //s=c+s;
          r1=c+r1;
       }
      else
      {
        char c;
        cin>>c;
        //s=s+c;
        r2=r2+c;
      }
    }
  }
  if(rev==1)
    {reverse(s.begin(),s.end());
      reverse(r1.begin(),r1.end());
      reverse(r2.begin(),r2.end());
      s=r2+s+r1;
    }
    else
    {
      s=r1+s+r2;
    }
  cout<<s<<endl;
}

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

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

  int sLen = s.length();
  int n = 0;
  for (int i = 0; i < sLen; i++) {
    if (s[i] == '?') {
      if (i > 0 && s[i-1] == 'P') {
        s[i] = 'D';
        continue;
      }
      if (i + 1 < sLen) {
        if (s[i + 1] == 'D') {
          s[i] = 'P';
          continue;
        } else if (s[i + 1] == '?') {
          s[i] = 'P';
          continue;
        }
      }
      s[i] = 'D';
      continue;
    }
  }

  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1e9+7;

void solve()
{
	ll n,a,b,ans=0,k=0;;
	cin>>n>>a>>b;
	ll c[n];
	for(ll i=0;i<n;i++)
		cin>>c[i];
	for(ll i=1;i<n;i++)
	{
		// cout<<(c[i]-c[i-1])*a<<" "<<ans<<endl;
		ans+=min(b,(c[i]-c[i-1])*a);
	}
	cout<<ans;
	return;
}
int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}


Measured memory_bytes: 4416
use std::io::Read;
use std::collections::VecDeque;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: String = iterator.next().unwrap().to_string();
    let q: usize = iterator.next().unwrap().parse().unwrap();

    let mut vec: VecDeque<char> = s.chars().collect::<VecDeque<char>>();

    let mut is_reverse = false;
    for _i in 0..q {
        let t = iterator.next().unwrap();
        if t == "1" {
            is_reverse = !is_reverse;
        } else {
            let f = iterator.next().unwrap();
            let c = iterator.next().unwrap().chars().next().unwrap();
            if f == "1" {
                if is_reverse {
                    vec.push_back(c);
                } else {
                    vec.push_front(c);
                }
            } else {
                if is_reverse {
                    vec.push_front(c);
                } else {
                    vec.push_back(c);
                }
            }
        }
    }

    if is_reverse {
        vec.into_iter().rev().collect::<String>()
    } else {
        vec.into_iter().collect::<String>()
    }
}


Measured memory_bytes: 10492