akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define rep(i,n) for(ll i=0;i<n;i++)
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
// using namespace atcoder;

const ll mod=998244353;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

ll powmod(ll a,ll n,ll m) {
    if(n == 0)
        return 1;

    if(n % 2 ==0){
        ll r = powmod(a,n/2,m);
        return r*r % m;
    }

    return a*powmod(a,n-1,m)%m;
}

ll factmod(ll a,ll b,ll m) {
  if(a<b)return 0;
  ll s=1;
  while(a>=b){
    s = s*a % m;
    a -= 1;
  }
  return s;
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

ll combmod(ll a,ll b,ll m){
  if(b==0)return 1;
  ll c=factmod(a,a-b+1,m);
  ll d=modinv(factmod(b,1,m),m);
  ll e=(c*d)%m;
  return e;
}

void modsum(ll &a,ll b,ll m){
  a+=b;
  a%=m;
}

void modsub(ll &a,ll b,ll m){
  a-=b;
  a+=m;
  a%=m;
}

void modmul(ll &a,ll b,ll m){
  a*=b;
  a%=m;
}

void modquo(ll &a,ll b,ll m){
  a*=modinv(b,m);
  a%=m;
}

int main(){

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

  ll a=1;
  ll ans=0;
  modsum(ans,m*powmod(m-1,n-1,mod)%mod,mod);
  
  for(ll i=1;i<=k;i++){
    modmul(a,n-i,mod);
    modquo(a,i,mod);
    ll b=m;
    modmul(b,powmod(m-1,n-i-1,mod),mod);
    modmul(b,a,mod);
    modsum(ans,b,mod);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
void file() {
    freopen("read.in", "r", stdin);
    freopen("write.out", "w", stdout);
}
const int N = 500010;
inline int read() {
    int sym = 0, res = 0;char ch = getchar();
    while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();
    while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
    return sym ? -res : res;
}
int n, m;
int main() {
    n = read(); m = read();
    if (n == m) printf("Yes"); else printf("No");
    return 0;
}

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

int main(){
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if(i<K) ans+=X;
    else ans+=Y;
  }
  cout << ans << endl;
}

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

template <typename T> std::string tostr(const T& t)
{
    std::ostringstream os; os<<t; return os.str();
}

int main(){
    string s;
    cin>>s;
    int a,b,c,d;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';   
    
    if(a+b+c+d==7){
        cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
    }else if(a-b-c-d==7){
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
    }else if(a+b-c+d==7){
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
    }else if(a+b+c-d==7){
        cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
    }else if(a-b+c+d==7){
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
    }else if(a-b-c+d==7){
        cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
    }else if(a-b+c-d==7){
        cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
    }else if(a+b-c-d==7){
        cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
from string import ascii_lowercase
n = int(input())
ans_l = [100 for i in range(26)]
for i in range(n):
    s = str(input())
    for i, j in enumerate(ascii_lowercase):
        ans_l[i] = min(ans_l[i], s.count(j))
print("".join(i * j for i, j in zip(ascii_lowercase, ans_l)))


Measured memory_bytes: 4216
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  int a, b, c, d, e, k;
  string s = "Yay!";
  cin >> a >> b >> c >> d >> e >> k;
  
  if (e-a > k) s = ":(";
  cout << s << endl;
}

Measured memory_bytes: 256
import scala.annotation.tailrec
import scala.io.StdIn

object Main extends App {

  def f(a:Long, b:Long):Long = {
    @tailrec
    def rec(acc:Long, num:Long):Long = {
      if(num == 0L) acc
      else rec(acc+1L, num/10L)
    }
    math.max(rec(0L,a), rec(0L,b))
  }

  val n =StdIn.readLong
  val r = math.sqrt(n).toLong
  val ans = (2L to r)./:(f(n, 1))((acc,i) => {
    if(n % i == 0) math.min(acc, f(n/i, i))
    else acc
  })
  println(ans)
}

Measured memory_bytes: 30132
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

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

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long S, long long W)
{
  if (S <= W)
    cout << "unsafe" << endl;
  else
    cout << "safe" << endl;
}

int main()
{
  cout << setprecision(10);
  long long S;
  scanf("%lld", &S);
  long long W;
  scanf("%lld", &W);
  solve(S, W);
  return 0;
}


Measured memory_bytes: 3756
/*  -*- coding: utf-8 -*-
 *
 * 2805.cc: Tournament
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  printf("%d\n", n - m - 1);
  return 0;
}



Measured memory_bytes: 3224
a = input().split()
N = int(a[1])
mini = []
maxi = []

for i in range(N):
  b = input().split()
  mini.append(b[0])
  maxi.append(b[1])
  
c = [int(s) for s in mini]
d = [int(s) for s in maxi]

c = sorted(c)
d = sorted(d, reverse=True)
e = min(d) - max(c)

if e >= 0:
  print(e + 1)
else:
  print(0)

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

int main(){
  int n;
  cin>>n;
  vector<double> v(n);
  for(int i=0;i<n;i++){
    cin>>v.at(i);
  }
  sort(v.begin(),v.end());
  double kotae=v.at(0);
  for(int j=1;j<n;j++){
    kotae=(kotae+v.at(j))/2;
  }
   cout << fixed << setprecision(7);
   cout<<kotae<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N, H, W;
	cin >> N >> H >> W;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int A, B;
		cin >> A >> B;
		if (A >= H && B >= W)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 2e5 + 1;
const long long MNN = 5e3 + 100;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n, clr[MXN], cnt[3];
vector<int> q[MXN];

void dfs(int x, int p){
    queue<int> que;
    que.push(1);
    que.push(n);
    for(int i = 1; i <= n; i++) clr[i] = -1;
    clr[1] = 0;
    clr[n] = 1;
    while(que.size() != 0){
        int x = que.front();
        cnt[clr[x]]++;
        que.pop();
        for(int i = 0; i < q[x].size(); i++){
            int to = q[x][i];
            if(clr[to] == -1){
                clr[to] = clr[x];
                que.push(to);
            }
        }
    }
}

int main () {
    cin >> n;
    for(int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        q[u].pb(v);
        q[v].pb(u);
    }
    dfs(1, 0);
    if(cnt[0] > cnt[1]){
        cout << "Fennec";
    }else{
        cout << "Snuke";
    }
    return 0;
}


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

int main(){
	int N, K, Point[3];
	cin >> N >> K >> Point[0] >> Point[2] >> Point[1];
	string T;
	cin >> T;
	vector<int> g(N);
	// グー: 0, パー: 1, チョキ: 2に
	for(int i=0;i<N;i++) {
		if(T[i] == 'r') g[i] = 0;
		if(T[i] == 'p') g[i] = 1;
		if(T[i] == 's') g[i] = 2;
	}

	int ans = 0;
	for(int i=0;i<K;i++) {
		// Kの剰余類においてdp(Kで割った余りが異なる集合とは依存関係がない)
		vector<vector<int>> dp(N/K + 5, vector<int>(3,0));
		int cnt = 0;
		for(int j=i;j<N;j+=K) {
			for(int k=0;k<3;k++) {
				// 今回出す手がk
				int plus = 0;
				// 勝つとき
				if(k == (g[j] + 1) % 3) plus += Point[k];
				// k以外の手のときにkを出せる
				dp[cnt+1][k] = max(dp[cnt][(k+1)%3],dp[cnt][(k+2)%3]) + plus;
			}
			cnt++;
		}
		ans += max(dp[cnt][0], max(dp[cnt][1], dp[cnt][2]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 6144
# -*- coding: utf-8 -*-
n,q = list(map(int,input().split()))
s = input()
s2 = s[1::]
d = [list(map(int,input().split())) for i in range(q)]

#AC開始位置を記録する
ac_idx = []

aci_append = ac_idx.append
for i,v in enumerate(zip(s,s2)):
    if v == ("A","C"):
        aci_append(i)

#2分探索, nibuntansaku,二分探索
from bisect import bisect_left

for l,r in d:
    print(bisect_left(ac_idx,r-1) - bisect_left(ac_idx,l-1))



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

int main()
{
    //データ定義
    int mTestScore; /*中間試験スコア*/
    int fTestScore; /*期末試験スコア*/
    int rTestScore; /*再試験スコア*/
    int w_total;
    //データ取得
    cin >> mTestScore >> fTestScore >> rTestScore;
    
    //結果出力
    while(mTestScore != -1 || fTestScore != -1 || rTestScore != -1){
        
        //成績を決定する
        w_total = mTestScore + fTestScore;
        
        if(mTestScore == -1 || fTestScore == -1){
            cout << 'F';
        }else if(w_total >= 80){
            cout << 'A';
        }else if(w_total >= 65){
            cout << 'B';        
        }else if(w_total >= 50){
            cout << 'C';        
        }else if(w_total >= 30){
            //再試験判定
            if(rTestScore >= 50){
                cout << 'C';
            }else{
                cout << 'D'; 
            }
        }else{
            cout << 'F';
        }
        cout << endl;
        //次のデータを読み込む
        cin >> mTestScore >> fTestScore >> rTestScore;
    }
    
    return 0;
}


Measured memory_bytes: 3092
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <map>
#include <cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int N, Y;
int yen[3] = {10000, 5000, 1000};

void dfs(int depth, int sum, int cnt[3])
{
  if (depth == 0)
  {
    if (sum == Y)
    {
      cout << cnt[0] << " " << cnt[1] << " " << cnt[2] << endl;
      exit(0);
    }
    return;
  }

  rep(i, 3)
  {
    int tmp = sum;
    tmp += yen[i];
    cnt[i]++;
    dfs(depth - 1, tmp, cnt);
    cnt[i]--;
  }
}

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

  int cnt[3] = {0};

  // dfs(N, 0, cnt);

  rep(i, N + 1)
  {
    rep(j, N + 1)
    {
      if (i + j > N)
        continue;
      if (yen[2] * (N - i - j) == Y - yen[0] * i - yen[1] * j)
      {
        cout << i << " " << j << " " << N - i - j << endl;
        exit(0);
      }
    }
  }

  cout << "-1 -1 -1" << endl;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    string s,t;
    cin >> s;
    cin >> t;
    lint ans=0;
    IREP(i,SZ(s)-SZ(t)+1){
        //先頭位置がi
        REP(j,SZ(t)){
            if (s[i+j]=='?'||s[i+j] == t[j])
            {
            }else{
                break;
            }
            if(j==SZ(t)-1){
                //cout << i<< "\n";
                REP(k, SZ(t)){
                    s[i + k] = t[k];
                }
                REP(k,SZ(s)){
                    if(s[k]=='?')
                        s[k] = 'a';
                }
                cout<< s << "\n";
                return 0;
            }
        }
    }

    cout << "UNRESTORABLE" <<"\n ";

        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll ans,c,n;
  string s;
  ans=0;
  c=0;
  cin >> n;
  cin >> s;
  rep(i,s.length()){
    if(s[i]=='I')c++;
    if(s[i]=='D')c--;
    ans=max(ans,c);
  }
  printf("%lld",ans);
}

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

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	int com = N * (N - 1) / 2 + M * (M - 1) / 2;
	cout << com << endl;
	return 0;
}

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

set<string> st;
set<char> l[30010], r[30010];
int main() {
    int n;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++) {
        if (i != 0) l[i] = l[i-1];
        l[i].insert(s[i]);
    }
    for (int i = s.size() - 1; i >= 0; i--) {
        if (i != s.size() - 1) r[i] = r[i+1];
        r[i].insert(s[i]);
    }
    for (int i = 1; i < s.size() - 1; i++) {
        for (auto sl: l[i-1]) {
            string ss = "";
            ss += sl;
            ss += s[i];
            for (auto sr: r[i+1]) {
                st.insert(ss + sr);
            }
        }
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 31360
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	int n=a.size(),i,j,flag=0;
	for(i=0;i<n;i++){
		if(a[i]=='C'&&flag==0){
			flag=1;
		}else if(a[i]=='F'&&flag==1){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int N = s.length();
    string ans;
    for (int i=0; i < N; ++i){
        if (i % 2 == 0){
            ans += s[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    long long x[n];
    for (auto &d : x) cin >> d;
    long long ans = 1e18;
    for (int i = 0; i < n - k + 1; ++i) {
        long long tmp = x[i + k - 1] - x[i] + min(abs(x[i]), abs(x[i + k - 1]));
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
while True:
    a, op, b = map(str,input().split())
    a = int(a)
    b = int(b)
    if op =='-':
        c = a - b
    if op == '+':
        c = a + b
    if op == '/':
        c = a / b
        c = int(c)   
    if op == '*':
        c = a * b
    if op == '?':
        break    
    print(c)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll ans = 1;
  ll n;cin>>n;
  for(ll i=1;i<=n;i++){
    ans *= i;
    ans %= MOD;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
main(){
  ios_base::sync_with_stdio(false);
  int v,e,s,t,lose[10001];
  vector<int> vec[10001];
  queue<int> que;
  cin >> v >> e;
  for(int i=0;i<e;i++){
    cin >> s >> t;
    lose[t]++;
    vec[s].push_back(t);
  }
  for(int i=0;i<v;i++){
    if(lose[i] == 0) que.push(i);
  }
  while(!que.empty()){
    int point = que.front();
    que.pop();
    cout << point << endl;
    for(int i=0;i<vec[point].size();i++){
      lose[vec[point][i]]--;
      if(!lose[vec[point][i]]) que.push(vec[point][i]);
    }
  }
  return(0);
}



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

int main() {
  ll k, a, b;
  cin >> k >> a >> b;
  ll r = 1;
  r += min(k, a - 1);
  k -= r - 1;
  r += -a + b > 2 ? k / 2 * (-a + b) + k % 2 : k;
  cout << r << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import collections


class Node(object):

  def __init__(self):
    self.value = 0
    self.edges = []


def main():
  n = int(input())
  nodes = [Node() for _ in range(n)]

  for _ in range(n - 1):
    a, b = map(int, input().split())
    nodes[a - 1].edges.append(nodes[b - 1])
    nodes[b - 1].edges.append(nodes[a - 1])

  values = list(map(int, input().split()))
  values.sort(reverse=True)

  print(sum(values[1:]))

  queue = collections.deque()
  queue.append(nodes[0])
  index = 0

  while len(queue) != 0:
    node = queue.popleft()
    node.value = values[index]
    index += 1

    queue.extend(n for n in node.edges if n.value == 0)

  print(' '.join(str(n.value) for n in nodes))


if __name__ == '__main__':
  main()



Measured memory_bytes: 7412
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n;
  cin >> n;
  vector<pair<i64, i64>> t(n);
  for (i64 i = 0; i < n; i++)
    cin >> t[i].second >> t[i].first;
  sort(t.begin(), t.end());
  bool ans = true;
  i64 now = 0;
  for (i64 i = 0; i < n; i++)
  {
    now += t[i].second;
    if (t[i].first < now)
      ans = false;
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    vector<int> B(N);
    for(int i=0; i<N; i++)B[A[i]-1]=i+1;
    for(int i=0; i<N; i++)cout<<B[i]<<endl;
    return 0;

}

Measured memory_bytes: 1664
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll n,k;
  cin >> n >> k;
  ll ans=0;
  for(int b=k+1;b<=n;b++){
    ans+=(b-k)*(n/b)+max(0ll,n%b-k+1);
  }
  if(k==0) ans-=n;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n, k;
bool d[10];
vector<int> v, a;
int ans;

int solve(){
	cin >> n >> k;
	for(int i = 0; i < k; ++i){
		int cur;
		cin >> cur;
		d[cur] = 1;
	}
	for(int i = n; i < 1000000; ++i){
		string s = to_string(i);
		bool ok = 1;
		for(int j = 0; j < sz(s); ++j){
			if(d[s[j] - '0']){
				ok = 0;
				break;
			}
		}
		if(ok) return i;
	}
	return n;
}

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << solve() << "\n";
	return 0;
}

Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())
s = input()
rock = 0
brank = 0
rfrag = 0
bfrag = 0
mrock = 0
mbrank = 0
rlist = []
blist = []
for i in range(n):
    if s[i] == "#":
        if bfrag == 1:
            if brank >= 3:
                blist.append(i-brank+1)
            if mbrank < brank:
                mbrank = brank
                brank = 0
            brank = 0
        rock += 1
        rfrag = 1
    if s[i] == ".":
        if rfrag == 1:
            if rock >= 2:
                rlist.append(i-rock+1)
            if mrock < rock:
                mrock = rock
                rock = 0
            rock = 0
        brank += 1
        bfrag = 1
if mrock < mbrank:
    if brank >= 3:
        blist.append(n-brank+1)
    if mbrank < brank:
        mbrank = brank
        brank = 0    
else:
    if mrock < rock:
        mrock = rock
        rock = 0

p = 0
for i in range(len(rlist)):
    if a < rlist[i] < c or b <  rlist[i] < d:
        print("No")
        p = 1
        break

y = 0 
if d < c and p == 0:
    x = 0
    for i in range(len(blist)):
        if b-1 <= blist[i] < d:
            x = 1            
    if x == 1:
        print("Yes")
        y = 1
    elif x == 0:
        print("No")
        y = 1
        
if p == 0 and y == 0:
    print("Yes")

Measured memory_bytes: 3700
N = int(input())
K = int(input())

out =  1
flg = 0
for i in range(N):#Aの回数を数えるためのループ
    if not flg:#フラグが立ってなかったら操作A
        out *= 2
        if out > K:
            flg = 1
    else:#フラグが立ったら操作B
        out += K

print(out)

Measured memory_bytes: 9004
# -*- coding: utf-8 -*-

def abc158b(n, a, b):
    num_b = 0
    if a+b != 0:
        rep = n // (a+b)
        mod = n % (a+b)
        num_b = rep * a
        if mod < a:
            num_b += mod
        else:
            num_b += a

    return num_b

###
# main
if(__name__ == '__main__'):
    # input
    n, a, b = map(int, input().split(" "))
    
    accomplishment = abc158b(n, a, b)
    
    # output
    print(accomplishment)
# else:
    # do nothing


Measured memory_bytes: 3068
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

bool cmp(int a, int b){
    return a > b;
}
int x, y, a, b, c;
const int maxn = 1e5 + 5;
int p[maxn], q[maxn], r[maxn];

int main(){
    cin >> x >> y >> a >> b >> c; 
    for(int i = 1;i <= a;i++){
        scanf("%d", &p[i]);
    }
    sort(p + 1, p + 1 + a, cmp);
    for(int i = 1;i <= b;i++){
        scanf("%d", &q[i]);
    }
    sort(q + 1, q + 1 + b, cmp);
    for(int i = 1;i <= c;i++){
        scanf("%d", &r[i]);
    }
    sort(r + 1, r + 1 + c, cmp);
    long long sum = 0;
    priority_queue<int> pq;
    for(int i = 1;i <= x;i++){
        pq.push(p[i]);
    }
    for(int i = 1;i <= y;i++){
        pq.push(q[i]);
    }
    for(int i = 1;i <= c;i++){
        pq.push(r[i]);
    }
    long long ans = 0;
    for(int i = 1;i <= x + y;i++){
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    ll h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return;
    }
    if (h % 2 == 0) {
        cout << (h / 2) * w << endl;
    } else {
        cout << (h / 2) * w + (w + 1) / 2 << endl;
    }
}


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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// AtCoder Beginner Contest 143
int main(){

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

    int ans = 0;
    rep(i, N)rep(j, i)ans += a[i] * a[j];
    cout << ans << endl;

}

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

int main(){
    int n,m,l;
    cin>>n>>m>>l;
    int d[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=INF;
        }
        d[i][i]=0;
    }
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        if(c>l)continue;
        d[a-1][b-1]=d[b-1][a-1]=c;
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=(d[i][j]<=l)?1:INF;
        }
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int s,t;
        cin>>s>>t;
        if(d[s-1][t-1]==INF)cout<<-1<<endl;
        else cout<<d[s-1][t-1]-1<<endl;
    }
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vp;
typedef set<ll> si;
typedef map<string, ll> msi;
#define REP(i,a,b) \
for(ll i=ll(a);i<=ll(b);i++)
#define DEP(i,a,b) \
for(ll i=ll(a);i>=ll(b);i--)
#define TR(c, it) \
for (auto it = (c).begin(); it != (c).end(); it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
///ll mod 1e9+7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  int T;
  T=1;
  while(T--)
  {
      ll n,i,j,k,l,m;
      cin>>n;
      string s;
      cout<<(1000-n%1000)%1000;
  }
  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
#define int long long
signed main(){
  int K, A, B;
  cin >> K >> A >> B;
  for(int i = A;i <= B;i++){
    if(i % K == 0){cout << "OK";return 0;}
  }
  cout << "NG";
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;




int main(){
  string s;
  cin >> s;
  if(s[0]=='9' || s[1]=='9'){cout << "Yes" << endl;}else{cout << "No" << endl;}
}

Measured memory_bytes: 3528
#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

static const int sentinel = 1000000000;
long int ninvention = 0;

int merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1 + 1], R[n2 + 1];
  for (int i = 0; i < n1; i++)
    L[i] = A[left + i];
  for (int i = 0; i < n2; i++)
    R[i] = A[mid + i];
  L[n1] = sentinel;
  R[n2] = sentinel;

  int i = 0, j = 0;
  for (int k = left; k < right; k++) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      ninvention += max(0, n1 - i);
      A[k] = R[j];
      j++;
    }
  }
}

int mergeSort(int A[], int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int data[MAX];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }
  mergeSort(data, 0, n);

  cout << ninvention << endl;
}

Measured memory_bytes: 4652
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <math.h>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
using namespace std;

const int MOD = 1000000007;

//整数は重複なく書かれていた
int main(){

    int H,W,D;
    cin >> H >> W >> D;
    vector <int> px(H*W+1);
    vector <int> py(H*W+1);
    vector <int> d(H*W+1, 0);
    int cnt = 0;
    REP(i,H)
    {
        REP(j,W)
        {
            int t;
            cin >> t;
            py[t] = j;
            px[t] = i;
        }
    }
    for(int i = D+1; i <= H*W; ++i)
    {
        int ma = abs(py[i] - py[i-D]) + abs(px[i]-px[i-D]);
        //D+1へは1+maが必要
        d[i] = d[i-D] + ma;
    }


    int Q;
    cin >> Q;
    REP(i,Q)
    {
        int l,r;
        cin >> l >> r;
        int res;
        res = d[r] - d[l];

        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int> > all;
int t;
int a[100],b[100],c[100],d[100];
int ans;
int n,m,q;
    vector<int> cur;
void Rec(int index,int mx){
    if(index == n){
        all.push_back(cur);
       return;
    }
    for(int i = m; i>=mx; i--){
        cur.push_back(i);
        Rec(index+1,i);
        cur.pop_back();
    }
}
 main()
{
    cin>>n>>m>>q;
    for(int i =0; i<q; i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;
        b[i]--;
    }
    Rec(0,1);

    for(int i =0; i<all.size(); i++){
        int cur =0;
        for(int j=0; j<q; j++){
            if(all[i][b[j]]-all[i][a[j]] == c[j])
                cur+=d[j];
        }
        ans = max(ans,cur);
    }
    cout<<ans<<endl;



	return 0;
}


Measured memory_bytes: 13816
n,k = gets.chomp.split(" ").map(&:to_i)
x_arr = gets.chomp.split(" ").map(&:to_i)

min = (10 ** 9)
(0..(n - k)).each do |i|
  left = x_arr[i]
  right = x_arr[k - 1 + i]

  d1 = left.abs + (right - left).abs
  d2 = right.abs + (right - left).abs
  d = d1 < d2 ? d1 : d2

  min = d if d < min
end

puts min


Measured memory_bytes: 21760
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n,a,b,c,e=0,r[200001]={0},d[200001]={0};
vector<int> A[200001];
int search(int x){
  r[x]=1;
  for(auto i:A[x]) if(!r[i]) d[i]=d[x]+1,search(i);
}
int main(){
  cin>>n;
  rep(i,n-1) cin>>a>>b,A[a].push_back(b),A[b].push_back(a);
  search(1);
  rep(i,n) if(d[i+1]>e) e=d[i+1],c=i+1;
  rep(i,n) r[i+1]=0;
  d[c]=0,search(c);
  rep(i,n) if(d[i+1]>e) e=d[i+1],c=i+1;
  if(e%3==1) cout<<"Second";
  else cout<<"First";
}


Measured memory_bytes: 18944
#include <stdio.h>

int main(void)
{
	int m,n,start,money,year,system,cost,total[200],interest;
	int interest2[100],interest_total,temp;
	double rate;
	int i,j,k,p,q;
	scanf("%d",&m);
	for(i=0;i<m;i++){
		scanf("%d",&start);
		scanf("%d",&year);
		scanf("%d",&n);
		for(j=0;j<n;j++){
			scanf("%d %lf %d",&system,&rate,&cost);
			interest_total=0;
			money=start;
			if(system==1){
				for(k=0;k<year;k++){
					interest=money*rate;
					money=money+interest-cost;
				}
				total[j]=money;
			}else if(system==0){
				for(k=0;k<year;k++){
					interest2[k]=money*rate;
					money=money-cost;
					interest_total=interest_total+interest2[k];
				}
				total[j]=money+interest_total;
			}
		}
		for(p=0;p<n-1;p++){
			for(q=n-1;q>p;q--){
				if(total[q-1]<total[q]){
					temp=total[q];
					total[q]=total[q-1];
					total[q-1]=temp;
				}
			}
		}
		printf("%d\n",total[0]);
	}
return 0;
}

Measured memory_bytes: 632
import java.util.*;
class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        sc.nextLine();
        String s=sc.nextLine();
        int l=s.length();
        String k="";
        if(l<=n)
        System.out.println(s);
        
        else
        {
            for(int i=0;i<n;i++)
            {
                k=k+s.charAt(i);
            }
            k=k+"...";
            System.out.println(k);
        }
    }
}


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


void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);

    auto dp = new long[][](n + 1, n + 1);
    fillAll(dp, -1);

    // 先手は X - Y の最大化
    // 後手は Y - X の最大化
    // をすると考えれば先手後手の場合分けが不要になる
    long dfs(int l, int r) {
        auto v = &dp[l][r];
        if (*v != -1) {
            return *v;
        }
        if (r - l == 1) {
            return *v = a[l];
        }
        return *v = max(a[l] - dfs(l + 1, r), a[r-1] - dfs(l, r - 1));
    }

    auto ans = dfs(0, n);

    writeln(ans);
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

int main() {
	int n; cin >> n;
    vector<int> a(n), b(n);

    for (int i = 0; i < n; i++) {
    	cin >> a[i];
    	b[i] = a[i];
    }
    sort(b.begin(), b.end());
    for (int i = 0; i < n; i++) {
    	if (a[i] - b[i] >= 2) {
    		cout << "No" << "\n";
    		return 0;
    	}
    }
    cout << "Yes" << "\n";
    return 0;
}

Measured memory_bytes: 1024
/**
 * Motto:   To Become Better Than Me
 * Author: cherry0697
 **/

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

#define rep(i,n) for(i=0;i<n;i++)
#define repc(i,a,n) for(i=a;i<n;i++)
#define repa(i,a,n) for(i=a;i<=n;i++)
#define repb(i,a,n) for(i=a;i>=n;i--)
#define trav(a,x) for(auto a=x.begin();a!=x.end();a++)
#define all(x) x.begin(),x.end()
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef vector <long long int> vi;

void solve()
{
  ll n,k,i;
  cin>>n>>k;

  ll a[n+1];

  rep(i,n+1)
    a[i]=i;

  ll pref[n+1],suff[n+1];

  rep(i,n+1)
  {
    if(i==0)
      pref[i]=a[i];
    else
      pref[i]=pref[i-1]+a[i];
  }

  for(i=n;i>=0;i--)
  {
    if(i==n)
      suff[i]=a[i];
    else
      suff[i]=suff[i+1]+a[i];
  }

  ll ans=0,temp,temp1,temp2,kemp;
  ll mod=1000000007;

  while(k<=(n+1))
  {
    kemp=k-1;
    temp1=pref[kemp];
    temp2=suff[n-kemp];

    temp=abs(temp1-temp2);
    temp++;

    ans=(ans+temp)%mod;
    k++;
  }

  cout<<ans<<"\n";
}

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

  int t;
  t=1;

  while(t--)
    solve();

return 0;
}


Measured memory_bytes: 8272
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

#define equals(a, b) (fabs((a)-(b)) < EPS)
const double EPS = (1e-10);

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(x*a, y*a);
    }
    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;
    }
};

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

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
int ccw(Point p0, Point p1, Point p2) {
    Vector a = p1 - p0;
    Vector b = p2 - p0;

    if (cross(a, b) > EPS) return COUNTER_CLOCKWISE;
    if (cross(a, b) < -EPS) return CLOCKWISE;
    if (dot(a, b) < -EPS) return ONLINE_BACK;
    if (a.norm() < b.norm()) return ONLINE_FRONT;

    return ON_SEGMENT;
}

typedef vector<Point> Polygon;  // 多角形

Polygon andrewScan(Polygon s) {
    Polygon u, l;
    if (s.size() < 3) return s;

    sort(s.begin(), s.end());
    u.push_back(s[0]);
    u.push_back(s[1]);
    l.push_back(s[s.size()-1]);
    l.push_back(s[s.size()-2]);

    for (int i = 2; i < s.size(); i++) {
        for (int n = u.size(); n >= 2 && ccw(u[n-2], u[n-1], s[i]) > CLOCKWISE; n--) {
            u.pop_back();
        }
        u.push_back(s[i]);
    }

    for (int i = s.size() - 3; i >= 0; i--) {
        for (int n = l.size(); n >= 2 && ccw(l[n-2], l[n-1], s[i]) > CLOCKWISE; n--) {
            l.pop_back();
        }
        l.push_back(s[i]);
    }

    reverse(l.begin(), l.end());
    for (int i = u.size() - 2; i >= 1; i--) l.push_back(u[i]);

    return l;
}


int main(void) {
    int n; cin >> n;

    Polygon s;
    double x, y;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        s.push_back(Point(x, y));
    }

    Polygon ans = andrewScan(s);

    cout << ans.size() << endl;
    int pos = 0;
    for (int i = 0; i < ans.size(); i++) {
        if (ans[i].y < ans[pos].y) {
            pos = i;
        } else if (ans[i].y == ans[pos].y) {
            if (ans[i].x < ans[pos].x) {
                pos = i;
            }
        }
    }

    cout << ans[pos].x << " " << ans[pos].y << endl;
    for (int i = (pos+1)%ans.size(); i != pos; i = (i+1)%ans.size()) {
        cout << ans[i].x << " " << ans[i].y << endl;
    }

    return 0;
}

Measured memory_bytes: 7344
#include<iostream>
#define ll long long
#define w(t) int t; cin>>t; while(t--)
#define f(N) long long N; cin>>N; long long a[N]; for(int i=0;i<N;i++){cin>>a[i];}
#define g(N)  for(int i=0;i<N;i++){cout<<a[i]<<" ";}
using namespace std;
int main()
{
    int c=0;
    f(N)
    for(int i=0;i<N;i++)
    {
        if((i+1)%2!=0)
        {
            if(a[i]%2!=0)
                c++;
        }
    }
    cout<<c;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int H,W;
vector<ll> A,B;

int main(){

	scanf("%d %d",&H,&W);

	ll tmp;

	for(int loop = 0; loop < H; loop++){
		scanf("%lld",&tmp);
		A.push_back(tmp);
	}

	for(int loop = 0; loop < W; loop++){
		scanf("%lld",&tmp);
		B.push_back(tmp);
	}

	sort(A.begin(),A.end());
	sort(B.begin(),B.end());

	ll ans = 0;

	int left,right,mid;
	int min_index;

	for(int i = 0; i < A.size(); i++){

		left = 0,right = B.size()-1,mid = (left+right)/2;
		min_index = B.size();

		while(left <= right){

			if(A[i] <= B[mid]){

				min_index = mid;
				right = mid-1;

			}else{

				left = mid+1;
			}
			mid = (left+right)/2;
		}
		ans += A[i]*(B.size()-min_index);
	}

	for(int i = 0; i < B.size(); i++){

		left = 0,right = A.size()-1,mid = (left+right)/2;
		min_index = A.size();

		while(left <= right){

			if(B[i] < A[mid]){

				min_index = mid;
				right = mid-1;

			}else{

				left = mid+1;
			}
			mid = (left+right)/2;
		}
		ans += B[i]*(A.size()-min_index);
	}

	printf("%lld\n",ans);

	return 0;
}



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

int main() {
	int a,b;
	scanf("%d%d", &a, &b);
	
	for(int i=1;i<1010;i++)
		if(a*100<=i*8 && i*8<(a+1)*100 && b*10<=i && i<(b+1)*10) {
			printf("%d\n", i);
			return 0;
		}
	
	puts("-1");
	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,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int a,b,c;
  cin>>a>>b>>c;

  int ans;
  if(a+b<c-1) ans=b+a+b+1;
  else ans=b+c;
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)    scanf("%d",&x)
#define sl(x)    scanf("%lld",&x)
#define ss(s)    scanf("%s",s)
#define pi(x)    printf("%d\n",x)
#define pl(x)    printf("%lld\n",x)
#define ps(s)    printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>    pii;
typedef pair<ll, ll>      pl;
typedef vector<int>       vi;
typedef vector<ll>        vl;
typedef vector<pii>       vpii;
typedef vector<pl>        vpl;
typedef vector<vi>        vvi;
typedef vector<vl>        vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
#define MAXN   20000001 
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}

int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;



void solve(){
    ll n,i;
    cin>>n;
    ll a[n];
    ll xo=0;
    fo(i,n){
     cin>>a[i];
     xo^=a[i];
     }
    fo(i,n){
     cout<<(xo^a[i])<<" ";
    }
    cout<<"\n";
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t = 1;
   // cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}

vl g[N];


int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
    u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}


Measured memory_bytes: 12176
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		String str = "",rts="";
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		if((str=bf.readLine())==null)return;
		bf.close();
		for(int i=str.length()-1;i>=0;i--)rts+=str.charAt(i);
		System.out.println(rts);
	}
}

Measured memory_bytes: 9348