akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

const int mod = 998244353;
class mint {
    long long x;
public:
    mint(long long 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;
    }
 
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/*
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(200010);*/

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> L(K), R(K);
    rep(i,K){
        cin >> L[i] >> R[i];
    }
    vector<mint> dp(N+1), dpsum(N+2);
    dp[1] = mint(1);
    dpsum[1] = mint(1);
    REP(i,2,N+1){
        rep(j,K){
            ll li = i - R[j];
            ll ri = i - L[j];
            li = max(li,1LL);
            ri = max(ri,0LL);
            dp[i] = dp[i] + dpsum[ri] - dpsum[li-1];
        }
        dpsum[i] = dpsum[i-1] + dp[i]; 
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 6416
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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; }

int main() {
    ll A, B, K; cin >> A >> B >> K;
    set<int> ch;
    for (ll i = 0; i < K; i++) {
        if (A + i >= ((double)A + B) / 2) break;
        cout << A + i << endl;
    }
    for (ll i = K - 1; i >= 0; i--) {
        if (B - i < ((double)A + B) / 2) continue;
        cout << B - i << endl;
    }
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

const int MAX_N = 55;

int arr [MAX_N];

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  pair<int, int> max_abs = make_pair(-1, -1);
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    max_abs = max(max_abs, make_pair(abs(arr[i]), i));
  }

  cout << 2 * n - 2 << '\n';
  
  int ma = max_abs.second;
  for (int i = 1; i <= n; i++) {
    if (i != ma) {
      cout << ma << " " << i << '\n';
    }
  }

  if (arr[ma] < 0) {
    for (int i = n - 1; i >= 1; i--) {
      cout << i + 1 << " " << i << '\n';
    }
  } else {
    for (int i = 2; i <= n; i++) {
      cout << i - 1 << " " << i << '\n';
    }
  }
}


Measured memory_bytes: 256
N,M = map(int,input().split())
x_str = input().split()
X = [0]*M
for i in range(M):
    X[i] = int(x_str[i])
X.sort()
if N >= M:
    print("0")
else:
    #隣の点との差分
    dx = [0]*(M-1)
    for j in range(M-1):
        dx[j] = X[j+1] - X[j]
    dx.sort()
    dx.reverse()
    length = 0
    for k in range(N-1,M-1):
        length += dx[k]
    print(length)

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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read() 	        freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n) 	        scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n) 	        scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%ull",&n)
#define ull             unsigned long long int
#define endll           pf("\n")
#define pf              printf
#define pi              acos(-1.0)
#define eps 	        1e-10
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod 1000000007
#define smod 2147483629
#define var    int ii,i,j,k,n,m,z=0,c=0,t,x,y,l,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

ll int a[105][2];
ll int zz=0;
ll int fn(ll int n,ll int c,ll int k)
{
    ll int x=0;
    if(a[n][c])return a[n][c];
    if(c==1)
    {
        if(n-1>=0)
        {
            x+=1+fn(n-1,0,k);
            //cout<<x<<endl;
        }
        if(n-k>=0)
        {
            x+=1+fn(n-k,0,k);
        }
    }
    if(c==0)
    {
        if(n-1>=0)x=fn(n-1,1,k);
    }
    a[n][c]=x;
    return x;
}
int main()
{
    ll var;
    cin>>n>>k;
    z=fn(n,1,k);
    cout<<z<<endl;
}



Measured memory_bytes: 3096
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		//String N = in.nextLine();
		int N = in.nextInt();
		int D = N%10;
		N = N/10;
		int C = N%10;
		N = N/10;
		int B = N%10;
		N = N/10;
		int A = N;
		if(A+B+C+D==7) {
			System.out.println(A+"+"+B+"+"+C+"+"+D+"=7");
		}else if(A+B+C-D == 7) {
			System.out.println(A+"+"+B+"+"+C+"-"+D+"=7");
		}else if(A+B-C+D == 7) {
			System.out.println(A+"+"+B+"-"+C+"+"+D+"=7");
		}else if(A+B-C-D == 7) {
			System.out.println(A+"+"+B+"-"+C+"-"+D+"=7");
		}else if(A-B+C+D == 7) {
			System.out.println(A+"-"+B+"+"+C+"+"+D+"=7");
		}else if(A-B+C-D == 7) {
			System.out.println(A+"-"+B+"+"+C+"-"+D+"=7");
		}else if(A-B-C+D == 7) {
			System.out.println(A+"-"+B+"-"+C+"+"+D+"=7");
		}else if(A-B-C-D == 7) {
			System.out.println(A+"-"+B+"-"+C+"-"+D+"=7");
		}
		in.close();
	}
}


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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N,K;
    cin >>N>>K;

    vector<int> h(N);
    rep(i,N) cin >> h[i];
    //-----------------------------------
    int ans=0;
    rep(i,N) if(h[i]>=K)ans++;


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

Measured memory_bytes: 640
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,k = lr()
dic = {}
for i in range(n):
    a,b = lr()
    if a in dic:
        dic[a]+=b
    else:
        dic[a]=b
dic = sorted(dic.items())
for K,v in dic:
    if k > v:
        k -= v
    else:
        print(K)
        sys.exit()

Measured memory_bytes: 91108
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,s[SZ];
int qaq(int x) {return (x%10)?x:0;}
int main()
{
	scanf("%d",&n);
	int mx=0,sum=0;
	for(int i=1;i<=n;i++)
		scanf("%d",s+i),sum+=s[i];
	mx=max(mx,qaq(sum));
	for(int i=1;i<=n;i++)
		mx=max(mx,qaq(sum-s[i]));
	printf("%d\n",mx);
}


Measured memory_bytes: 764
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main() {
    int grid[3][3];
    bool flag = false;
    REP(i, 3) {
        REP(j, 3) {
            cin >> grid[i][j];
        }
    }

    int a2, a3, b1, b2, b3;
    REP(i, grid[0][0] + 1) {
        b1 = grid[0][0] - i;
        b2 = grid[0][1] - i;
        b3 = grid[0][2] - i;
        a2 = grid[1][0] - b1;
        a3 = grid[2][0] - b1;
        if (a2 + b2 == grid[1][1] && a2 + b3 == grid[1][2] && a3 + b2 == grid[2][1] && a3 + b3 == grid[2][2]) {
            flag = true;
            break;
        }
    }
    if (! flag) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

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

int main(){
  ll n, x;
  cin >> n;
  cin >> x;
  if (x * 2 > n) {
    x = n - x;
  }
  ll res = 0;
  ll a = n - x;
  ll b = x;
  while(true) {
    if (a % b == 0) {
      res += (a / b) * b * 3;
      break;
    } else {
      res += (a / b) * b * 3;
    }
    ll tmp = a;
    a = b;
    b = tmp % b;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n,a,sum=0,i,j;

    scanf("%d",&n);

    for( i=0;i<n;i++){
        scanf("%d",&a);
        for( j=2;j*j<=a;j++){
            if(a%j==0)break;
        }
        if(j*j>a)sum++;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 2724
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=1e5+7;
int n,a,b,h[N];

il bool check(int times){
	ll tot=(ll)times*b;
	per(i,n,1){
		if(h[i]<=tot) return true;
		ll need=(h[i]-tot)/a;
		if(need*a<h[i]-tot) ++need;
		if(need>times) return false;
		times-=need; 
	}
	return true;
}

int main(){
	scanf("%d%d%d",&n,&a,&b),a-=b;
	rep(i,1,n) scanf("%d",h+i);
	sort(h+1,h+n+1);
	int ul=0,ur=h[n]/b+1;
	while(ur-ul>1){
		int mid=ul+ur>>1;
		if(check(mid)) ur=mid;else ul=mid;
	} 
	printf("%d\n",ur);
	return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys

def main():
	a, b, c, d = map(int, input().split(" "))
	
	if c >= b or a >= d:
		print(0)
		sys.exit()
		
	bb = min(b, d)
	aa = max(a, c)
	
	print(bb - aa)
	
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 2940
N = int(input())
S = [input() for _ in range(N)]

cnt = sum(map(lambda x: x.count('AB'), S))
B_A = len(list(filter(lambda x: x[0] == 'B' and x[-1] == 'A', S)))
B__ = len(list(filter(lambda x: x[0] == 'B' and x[-1] != 'A', S)))
__A = len(list(filter(lambda x: x[0] != 'B' and x[-1] == 'A', S)))

if B_A == 0:
    print(cnt + min(B__, __A))
else:
    if B__ + __A > 0:
        print(cnt + B_A + min(B__, __A))
    else:
        print(cnt + B_A - 1)


Measured memory_bytes: 3700
#include <stdio.h>

int main() {

  int array[100][100] = {0};
  int vector[100] = {0};
  int product[100] = {0};
  int i = 0, j = 0;
  int a, b;
  char c;

  scanf("%d %d", &a, &b);

  while(j < b) {
    scanf("%d%c", &array[i][j], &c);
    j++;
    if(c == '\n') {
      i++;
      j = 0;
      if(i == a)
	break;
    }
  }

  i = 0;
  while(i < b) {
    scanf("%d", &vector[i]);
    i++;
  }

  for(i = 0; i < a; i++)
    for(j = 0; j < b; j++)
      product[i] += array[i][j] * vector[j];

  for(i = 0; i < a; i++)
    printf("%d\n", product[i]);
  
  return 0;
}
  

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

using namespace std;
typedef long long ll;


int main()
{
    int l, r, d, cnt = 0;
    cin >> l >> r >> d;

    for (int i = l; i <= r; i++) {
        if (i%d==0) cnt++;
    }
    cout << cnt;

    return 0;
}



Measured memory_bytes: 3548
package main

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

func main() {
	N := 0
	sc := bufio.NewScanner(os.Stdin)
	if sc.Scan() {
		N, _ = strconv.Atoi(sc.Text())
	}
	A := make([]int, N)
	if sc.Scan() {
		for i, val := range strings.Fields(sc.Text()) {
			A[i], _ = strconv.Atoi(val)
		}
	}
	result, count := bubbleSort(A, N)
	fmt.Println(String(result))
	fmt.Println(count)
}

func bubbleSort(A []int, N int) ([]int, int) {
	flag := true
	count := 0
	for flag {
		flag = false
		for j := N - 1; j > 0; j-- {
			if A[j] < A[j-1] {
				A[j], A[j-1] = A[j-1], A[j]
				count++
				flag = true
			}
		}
	}
	return A, count
}

func String(A []int) string {
	text := ""
	for i, val := range A {
		if i > 0 {
			text += " "
		}
		text += fmt.Sprint(val)
	}
	return text
}



Measured memory_bytes: 1120
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/math/tools/minima.hpp>

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

namespace adaptor = boost::adaptors;
using namespace std;
using boost::math::tools::brent_find_minima;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::split;
using boost::algorithm::replace_all;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;

// TOP

void	Main()
{
	string	s;
	ll		k;
	cin >> s >> k;
	ll	i = 0;
	while (i < s.size() && s.at(i) == '1')
		i++;
	if (k <= i)
		cout << "1" << endl;
	else
		cout << s.at(i) << endl;
}
// END

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


Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int m;
    cin>>s>>m;
    string ans="";
    for(int i=0;i<s.size();i+=m){
        ans+=s[i];
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
n,m=map(int,input().split())
li = []
h=list(map(int,input().split()))
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]<h[b-1]:
        li.append(a)
    elif h[a-1]==h[b-1]:
        li.append(a)
        li.append(b)
    else:
        li.append(b)
print(n-len(set(li)))


Measured memory_bytes: 91200
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    k = I()
    a, b = MI()

    for i in range(a, b + 1):
        if i % k == 0:
            print("OK")
            exit()

    print("NG")


if __name__ == "__main__":
    main()


Measured memory_bytes: 65092
#include <iostream>

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

using namespace std;

long long MOD = 1000000007;

int main(){
  long long N;
  string S;
  cin >> N >> S;
  // 入力終了

  // アルファベットが何回出現したか
  long long cnt[26] = {0};
  rep(i, N){
    cnt[ S[i]-'a' ]++;
  }

  // 各アルファベットがcnt[i]回出現するので，
  // それを選ぶならcnt[i]通りと，選ばないという1通りがある
  long long ans = 1;
  rep(i, 26)
    ans = ( ans*(cnt[i]+1) )%MOD;

  // 何も選ばないときと，初期化の1を引く
  cout << (ans-1)%MOD << endl;
    
  return 0;
}


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

int A, B, X;

int main()
{
	cin >> A;
	cin >> B;
	cin >> X;

	bool i;
	i = (X >= A && X <= (A + B));

	if (i)
	{
		cout << "YES";
	}
	else 
	{
		cout << "NO";
	}

    return 0;
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;

int main(){

	string s;
	cin>>s;

	int ans=0;
	rep(i,s.size()-1){
		if(s[i]!=s[i+1])ans++;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main()
{
    string s;
    cin>>s;
    int count=0;
    if(s[0]==s[1]){
        count++;
    }
    if(s[2]==s[1]){
        count++;
    }
    if(s[2]==s[3]){
        count++;
    }

    if(count==0){
        cout<<"Good";
    }
    else{
        cout<<"Bad";
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# coding=utf-8

import sys

n = int(sys.stdin.readline().strip())

txy = [(0,0,0)]+[tuple(map(int, l.strip().split(" "))) for l in sys.stdin.readlines()]
check_txy = [abs(_x - _xp) + abs(_y - _yp) <= _t - _tp and (_t + _x + _y) % 2 == 0 for (_t, _x, _y), (_tp, _xp, _yp) in zip(txy[1:], txy)]
if all(check_txy):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 29596
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 100010
using namespace std;
ll n,fa[N],dp[N];
vector<ll> vt[N],child[N];
ll dfs(ll x)
{
	if(dp[x]!=-1)
	{
		return dp[x];
	}
	if(child[x].size()==0)
	{
		return 2;
	}
	dp[x]=0;
	ll i,j,c1=1,c2=1;
	for(i=0;i<child[x].size();i++)
	{
		c1=(c1*dfs(child[x][i]))%MOD;
		for(j=0;j<child[child[x][i]].size();j++)
		{
			c2=(c2*dfs(child[child[x][i]][j]))%MOD;
		}
	}
	return dp[x]=(c1+c2)%MOD;
}
int main(){
	ll i,j,x,y;
	memset(dp,-1,sizeof(dp));
	memset(fa,-1,sizeof(fa));
	cin>>n;
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		x--;
		y--;
		vt[x].push_back(y);
		vt[y].push_back(x);
	}
	bool book[N];
	queue<ll> q;
	memset(book,false,sizeof(book));
	book[0]=true;
	q.push(0);
	for(i=0;i<n;i++)
	{
		child[i].clear();
	}
	while(q.size())	
	{
		x=q.front();
		q.pop();
		for(i=0;i<vt[x].size();i++)
		{
			if(!book[vt[x][i]])
			{
				q.push(vt[x][i]);
				book[vt[x][i]]=true;
				child[x].push_back(vt[x][i]);
			}
		}
	}
	cout<<dfs(0)<<endl;
	return 0;
}

Measured memory_bytes: 21248
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <string>
using namespace std;
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long int ll;
const ll MOD = 1000000007LL;

//This source code is in the case of n, k <= 2020 (in nCk)

ll fact[4040404], frev[4040404];
ll invs[4040404];
//fact[n] = n! mod MOD
//frev[n] = 1 / n! mod MOD
//invs[n] = 


ll C(int a, int b)
{
	if (a < b) return 0;
	return fact[a] * frev[b] % MOD * frev[a - b] % MOD;
}
ll P(int a, int b){
    if(a<b) return 0;
    return fact[a] * frev[a - b] % MOD;
}

ll modpow(ll a, ll p = MOD - 2)
{
	if (p == 0) return 1;
	ll tmp = modpow(a, p / 2);
	tmp = tmp * tmp % MOD;
	if (p % 2) tmp = tmp * a % MOD;
	return tmp;
}

void fill_combination_table(){
	fact[0] = 1; frev[0] = 1;
	invs[0] = 1;
	invs[1] = 1;
	for (int i = 2; i < 4040404; ++i) invs[i] = MOD - MOD / i * invs[MOD % i] % MOD;
	for (int i = 1; i < 4040404; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
		frev[i] = frev[i - 1] * invs[i] % MOD;
	}
}

ll dp[1005][1005];
bool ch[1005][1005];
int n,a,b,c,d;
ll func(int i, int j){
    if(ch[i][j]) return dp[i][j];
    if(i<a && j==0) return 1;
    if(j>n || i<a) return 0;
    ll &ret = dp[i][j];
    ret = 0;
    //k = 0
    ret += func(i-1, j);
    for(int k=c; k<= min(d, j/i); k++){
        ret += func(i-1,j - i*k) * P(n - j+i*k, i*k) % MOD * frev[k] % MOD * modpow(frev[i], k) % MOD;
        ret %= MOD;
    }
    ch[i][j] = true;
    return ret;
}

int main(){
    cin >> n >> a >> b >> c >> d;
    for(int i=0;i<1005; i++) for(int j=0;j<1005;j++) ch[i][j] = false;
    fill_combination_table();
    cout << func(b,n) << endl;
    return 0;
}

Measured memory_bytes: 103808
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long k = scanner.nextLong();
        scanner.close();

        if (k % 2 == 0) {
            System.out.println((n / k) * (n / k) * (n / k)
                    + ((n % k < k / 2) ? n / k : n / k + 1) * ((n % k < k / 2) ? n / k : n / k + 1)
                            * ((n % k < k / 2) ? n / k : n / k + 1));

        } else {
            System.out.println((n / k) * (n / k) * (n / k));

        }

    }
}


Measured memory_bytes: 23892
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    BigDecimal a = new BigDecimal(sc.next());
    BigDecimal b = new BigDecimal(sc.next());
    System.out.println(a.multiply(b).toBigInteger());
  }
}

Measured memory_bytes: 27232
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int N;
std::vector<int> a;
int main() {
	std::cin>>N;
	a.resize(N);
	for(int i=0;i<N;i++)std::cin>>a[i];
	int p=std::unique(a.begin(),a.end())-a.begin();
	int flag=0,ans=0;
	for(int i=1;i<p;i++){
		if(a[i-1]<a[i]){
			if(flag==0)flag=2;
			if(flag==1){
				ans++;
				flag=0;
			}
		}
		else{
			if(flag==0)flag=1;
			if(flag==2){
				ans++;
				flag=0;
			}
		}
	}
	ans++;
	std::cout<<ans<<std::endl;
	return 0;
}

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

int main() {
	int d;
	cin >> d;
	const int n = 26;
	vector<int> c(n);
	vector<vector<int>> s(d, vector<int>(n));
	rep(i, n) cin >> c[i];
	rep(i, d) rep(j, n) cin >> s[i][j];
	vector<int> t(d);
	
	random_device rnd;
    mt19937 mt(rnd());
	rep (i, d) t[i] = mt()%n + 1;
	int ans = -1;
	int cnt = 0;
	while(1) {
		// 局所探索法
		cnt++;
		if(cnt > 200000) break;
		vector<int> old = t;
		const int CH = mt()%5 + 1; // CH箇所変える
		rep(i, CH) {
			int nd = mt()%d;
			int nq = mt()%n + 1;
			t[nd] = nq;
		}
		
		// 点数の再計算
		vector<int> nlast(n);
		ll now = 0;
		rep(i, d) {
			now += s[i][t[i]-1];
			nlast[t[i]-1] = i+1;
			rep(j, n) {
				now -= c[j] * (i+1-nlast[j-1]);
			}
		}
		
		// 良くなれば更新
		if(now > ans) {
			ans = now;
			// cout << cnt << " :" << ans << endl;
		} else {
			t = old;
		}
	}
	
	rep(i, d) printf("%d\n", t[i]);
	return 0;
}

Measured memory_bytes: 3764
#include<stdio.h>
 
struct person {
    int a;
    int v;
};
int main(void) {
    struct person man[25],max;
    max.a=max.v=-1;
    int n,i;
    scanf("%d",&n);
    while(n--){
    	scanf("%d %d",&man[n].a,&man[n].v);
        if(max.v<man[n].v||(max.v==man[n].v && max.a>man[n].a))max=man[n];
    }
    printf("%d %d\n",max.a,max.v);
     
    return 0;
}

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

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

    int n,k;
    string s;

    cin >> n >> k;
    cin >> s;
    
    for(int i=1;i<=n;i++)
    {
        if(i==k)
        {
            cout << (char)(s[i-1]-'A'+'a');
        }
        else
        {
            cout << s[i-1];
        }
    }
    cout << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int x,a;
    cin >> x>>a;

    cout << (x<a?0:10) << endl;

   return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) begin(n),end(n)

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

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int a, b;
	cin >> a >> b;
	if(a == b) cout << "Draw" << endl;
	else if(a == 1) cout << "Alice" << endl;
	else if(b == 1) cout << "Bob" << endl;
	else if(a > b) cout << "Alice" << endl;
	else cout << "Bob" << endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> W(N);
  int sum_all=0;
  for(int i=0;i<N;i++){
    cin >> W.at(i);
    sum_all+=W.at(i);
  }
  
  int dif_min=100000;
  for(int T=1;T<=N;T++){
    int sum_left=0,sum_right;
    for(int j=0;j<T;j++){
      sum_left+=W.at(j);
    }
    sum_right=sum_all-sum_left;
    dif_min=min(dif_min,abs(sum_right-sum_left));
  }
  cout << dif_min << endl;
}
  

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    ll N; cin >> N;
    vl A(N+1,0); FOR(i, 1, N+1) cin >> A[i];

    vl s(N + 1, 0);
    set<ll> st;
    FOR(i,1,N+1) {
        s[i] = s[i - 1] + A[i];
        st.insert(s[i]);
    }

    map<ll, ll> mp;
    FOR(i,0,N+1) {
        mp[s[i]]++;
    }

    ll ans = 0;
    for (ll i : st) {
        ll k = mp[i];
        ans += k * (k - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;

int main() {
    LL N, A, B; cin >> N >> A >> B;
    LL tmp = N / (A + B);
    cout << tmp * A + min(N - tmp * (A + B), A) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 310000
ll MOD=998244353;
ll inv[N];

vector<vec> G(N);
main(){
    int k=in(),n=in();
    cout<<k-n+1;
}



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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF (1 << 29)

using namespace std;

/*class Point{
	public:
		double x, y;

		Point(double x = 0, double y = 0): x(x), y(y) {}

		Point operator + (Point p){ return Point(x + p.x, y + p.y); }
		Point operator - (Point p){ return Point(x - p.x, y - p.y); }
		Point operator * (double a){ return Point(a * x, a * y); }
		Point operator / (double a){ return Point (x / a, y / a); }

		double abs(){ return sqrt(norm()); }
		double norm(){ return x * x + y * y; }

		bool operator < (const Point &p) const{
			return x != p.x ? x < p.x : y < p.y;
		}

		bool operator == (const Point &p) const{
			return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
		}
};

class Segment{
	public:
		Point p1, p2;
		Segment(Point p1 = Point(), Point p2 = Point()): 
			p1(p1), p2(p2) {}
};

class Circle{
	public:
		Point c;
		double r;
		Circle(Point c = Point(), double r = 0.0): c(c) , r(r) {}
};

typedef Segment Line;
typedef vector<Point> Polygon;
typedef Point Vector;

double dot(Vector a, Vector b){
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
	return a.x * b.y - a.y * b.x;
}
*/

int main(){
	long n, k;
	long ans = 0;

	cin >> n >> k;
	
	for(long i = k; i <= n + 1; i++){
		long l = 0, u = 0;
		//for(int j = 0; j < i; j++) l += j;
		l = i * (i - 1) / 2;
		//for(int j = n - i; j <= n; j++) u += j;
		u = i * (2 * n - i + 1) / 2;
		//cout << "l:" << l << " u:" << u << endl;
		ans += u - l + 1;
		//ans %= 1000000007;
	}

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


Measured memory_bytes: 3624
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin>>n;
  
  map<int,int> m1,m2;
  
  int v;
  rep(i,n){
    cin>>v;
    if(i%2==0) m1[v]++;
    else m2[v]++;
  }
  
  int a=0,b=0,c=0,d=0,an,bn,cn,dn;
  for(auto x:m1){
    if(x.second>a){
      b=a;
      a=x.second;
      an=x.first;
    }
    else if(x.second>b){
      b=x.second;
      bn=x.first;
    }
  }
  for(auto x:m2){
    if(x.second>c){
      d=c;
      c=x.second;
      cn=x.first;
    }
    else if(x.second>d){
      d=x.second;
      dn=x.first;
    }
  }
  
  if(an!=cn) cout<<n-a-c<<endl;
  else cout<<n-max(a+d,b+c)<<endl;

  return 0;
}


Measured memory_bytes: 8248
a,b=map(int,input().split())
li=[2,3,4,5,6,7,8,9,10,11,12,13,1]
if li.index(a)<li.index(b):
    print("Bob")
elif li.index(a)>li.index(b):
    print("Alice")
else:
    print("Draw")

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
// const int MOD = 1000000007;
const int MOD = 998244353;

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

   int n, s;
   cin >> n >> s;
   vector<int> dp(s + 1);
   dp[0] = 1;
   rep(i, 0, n) {
      int a;
      cin >> a;
      vector<int> p(s + 1);
      swap(dp, p);
      rep(j, 0, s + 1) {
         (dp[j] += p[j] * 2) %= MOD;
         if (j >= a) (dp[j] += p[j - a]) %= MOD;
      }
   }
   cout << dp[s] << endl;
   return 0;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}

#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;

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

	int n, l;
	cin >> n;
	vector<int> x(n);
	REP(i, n) cin >> x[i];
	cin >> l;

	vector<int> f(n);
	int pos = 0;
	REP(i, n) {
		while(pos < n - 1 && x[pos + 1] - x[i] <= l)
			pos++;
		f[i] = pos;
	}

	int log = 0;
	while((1 << log) < n) log++;
	vector<vector<int>> jump(log, vector<int>(n));
	jump[0] = f;

	FOR(i, 1, log - 1) REP(j, n) {
		if(jump[i - 1][j] == n - 1) jump[i][j] = n - 1;
		else jump[i][j] = jump[i - 1][jump[i - 1][j]];
	}

	int q;
	cin >> q;
	REP(i, q) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		if(a > b) swap(a, b);

		int ans = 1;
		for(int j = log - 1; j >= 0; j--) {
			if(jump[j][a] < b) {
				a = jump[j][a];
				ans += (1 << j);
			}
		}
		cout << ans << "\n";
	}
}


Measured memory_bytes: 8312
mod = 1000000007


def sub(a, b):
    return (a - b + mod) % mod


def mul(a, b):
    return a * b % mod


def div(a, b):
    return mul(a, pow(b, mod - 2, mod))


def comb(n, r):
    """ nCr % mod
    Equivalent to comb(n, r) in Python 3.8
    """
    num = 1
    den = 1
    for i in range(r):
        num = mul(num, n - i)
        den = mul(den, i + 1)
    return div(num, den)


n, a, b = map(int, input().split())

print(sub(sub(pow(2, n, mod) - 1, comb(n, a)), comb(n, b)) % mod)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define maxn 120
#define name "bai1"
ll m,d,res;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(name".inp","r",stdin);
    //freopen(name".out","w",stdout);

    cin>>m>>d;
    f(i,1,m)
    {
        f(j,1,d)
        {
            ll x=j%10;
            ll y=(j-x)/10;
            if(x>=2 && y>=2 && x*y==i)
            {
                res++;
            }
        }
    }
    cout<<res;
}


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

int main(){
	int x; cin>>x;
	int ans=1;
	for(int i=1; i<x; i++){
		for(int j=2; j<x; j++){
			int y=pow(i,j);
			if(y<=x) ans=max(ans,y);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4232
#include<iostream>

using namespace std;

int main(){
    int n,m,a,ans=0;
    cin >> n >> m;
    for (int i=0 ; i<m; i++) {
        cin >> a;
        ans += a;
    }
    if (n < ans ) cout << -1 << endl;
    else cout << n - ans << endl;

    return 0;

}

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


int main(){
    int N;
    cin >> N;
    vector<vector<int> > v(N,vector<int>(3)); 
    rep(i,N)cin >> v[i][0] >> v[i][1] >> v[i][2];

    vector<vector<int> > dp(N+1,vector<int>(3));
    dp[0][0] = dp[0][1] = dp[0][2] = 0;

    for(int i = 0; i < N; i++){
        for(int j = 0; j < 3; j++){
            dp[i+1][(j+1)%3] = max(dp[i+1][(j+1)%3],dp[i][j] + v[i][(j+1)%3]);
            dp[i+1][(j+2)%3] = max(dp[i+1][(j+2)%3],dp[i][j] + v[i][(j+2)%3]);
        }
    }
    int res = 0;
    rep(i,3){
        res = max(res,dp[N][i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 11136
# B - K-th Common Divisor
# https://atcoder.jp/contests/abc120/tasks/abc120_b
# 1WA
MAX = 100

def gcd(m, n):
    return m if n == 0 else gcd(n, m % n)

A, B, K = map(int, raw_input().split())
gcdAB = gcd(A, B)

cnt = 0
for n in range(gcdAB, 0, -1):
    if gcdAB % n == 0:
        cnt += 1
        if cnt == K:
            print '{}'.format(n)
            break


Measured memory_bytes: 2568
//by The_One_Solver
#include<bits/stdc++.h>
using namespace std;
int n,m,c;
int main()
{
    cin>>n>>m;
    if(n>=2)
        c+=(n*(n-1))/2;
    if(m>=2)c+=(m*(m-1))/2;
    cout<<c;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o' ,'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' ,'x' ,'y' ,'z')

S = []

if N <= 26:
    amari = N % 26
    S.append(amari)
else:
    while N != 0:
        amari = N % 26
        if amari == 0:
            S.append(26)
            N = (N-1)//26
        else:
            S.append(amari)
            N = N//26

S.reverse()
Moji = ''
for i in range(len(S)):
    Moji = Moji + A[S[i]-1] 
print(Moji)

Measured memory_bytes: 9220
N = int(input())
A = [0] * N

for i in range(N):
  A[i] = int(input())
A.sort()
n = 1
ans = 0

for i in range(N-1):
  if A[i] == A[i+1]:
    n += 1
  else:
    if n % 2:
      ans += 1
    n = 1

if n % 2:
  ans += 1

print(ans)

Measured memory_bytes: 45016
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	long long int a,b,c,d=10,e;
	cin>>a>>b;
	string s="No";
	c=b;
	for(int i=0;c>=10;i++){
		c=c/10;
		d=10*d;
	}
	e=d*a+b;
	for(int i=0;i*i<=e;i++){
		if(e==i*i){
			s="Yes";
		}
	}
	cout<<s<<endl;
	return 0;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

signed main(){
	int N;
	int A[110];
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	bool flag=false;
	int sum=0;
	int Max=*max_element(A,A+N);
	REP(i,N){
		if(flag==false&&Max==A[i]){
			flag=true;
		}
		else{
			sum+=A[i];
		}
	}
	if(sum>Max){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256