akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int n;
int sum=0;
vector<vector<int>> g(10);

void solve(int u,vector<bool> m){
  bool f=0;
  m[u]=1;
  rep(i,n){
    if(!(m[i])) f=1;
  }
  if(f){
    rep(i,g[u].size()){
      int v=g[u][i];
      if(!(m[v])){
        solve(v,m);
      }
    }
  }else sum++;
}

int main(){
  int m; cin>>n>>m;
  rep(i,m){
    int a,b; cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  vector<bool> k(n,0);
  solve(0,k);
  cout<<sum<<endl;

  return 0;
}


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

int main () {
  char x;
  cin >> x;
  if(x == 'A') cout<<"T"<<endl;
  if(x == 'T') cout<<"A"<<endl;
  if(x == 'C') cout<<"G"<<endl;
  if(x == 'G') cout<<"C"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

int main(){
  unsigned long long int x,y;
  unsigned long long int maxl=0,len,num;
  scanf("%llu%llu",&x,&y);
  //for(int i=x;i<=x+100;i++){
  int i=x;
    len=1;
    num=i;
    while(1){
      num*=2;
      if(y<num)break;
      len++;
    }
    maxl=max(maxl,len);
  //}
  cout<<maxl<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n = inp()
a = sorted(inpl())
cnt = collections.Counter(a)
ans = 0
dp = [0] * (10**6 + 1)
for i in a:
    if dp[i] == 0:
        for j in range(1, 10**7):
            if i * j > 10**6:
                break
            dp[i * j] = 1
        if cnt[i] == 1:
            ans += 1
print(ans)


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

#define LL      long long
#define pb      push_back
#define inf     111111111111111
#define READ    freopen("in.txt", "r", stdin)
#define WRITE   freopen("out.txt", "w", stdout);
#define mx      100005

typedef pair<LL, LL>  PII;

vector <PII> v;

bool cmp(PII A, PII B)
{
    return A.second < B.second;
}

int main()
{

    LL n; cin >> n;
    while(n--){
        LL a, b; cin >> a >> b;
        v.push_back(make_pair(a, b));
    }

    sort(v.begin(), v.end(), cmp);

    LL slotPoint = 0;

    bool chk = false;
    for(LL i=0; i<v.size(); i++){
        if(slotPoint + v[i].first > v[i].second){
            chk = true;
            break;
        }

        slotPoint += v[i].first;
    }

    if(chk)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 6512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            sS = Console.ReadLine().Trim().Split(' ');
            List<int> listT = new List<int>();
            for (int i = 0; i < iN; i++) { listT.Add(int.Parse(sS[i])); }
            sS = Console.ReadLine().Trim().Split(' ');
            int iM = int.Parse(sS[0]);
            List<ClsSmp> listM = new List<ClsSmp>();
            for (int i = 0; i < iM; i++)
            {
                sS = Console.ReadLine().Trim().Split(' ');
                ClsSmp oneUsr = new ClsSmp();
                oneUsr.iP = int.Parse(sS[0]) - 1;
                oneUsr.iX = int.Parse(sS[1]);
                listM.Add(oneUsr);
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iSum = listT.Sum();
            for (int i = 0; i < listM.Count; i++)
            {
                listM[i].iS = iSum - listT[listM[i].iP] + listM[i].iX;
            }

            //出力
            for (int i = 0; i < listM.Count; i++)
            {
                Console.WriteLine("{0}", listM[i].iS.ToString().Trim());
            }

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
        private class ClsSmp
        {
            public int iP { get; set; } = 0;
            public int iX { get; set; } = 0;
            public int iS { get; set; } = 0;
        }
}


Measured memory_bytes: 13396
from collections import deque

N,M,P = map(int, input().split())
E = [[] for _ in range(N)]
Ei = [[] for _ in range(N)]
for _ in range(M):
    a,b,c = map(int, input().split())
    E[a-1].append((b-1, -c+P))
    Ei[b-1].append(a-1)
    
q = deque()
q.append(0)
used = [0]*N
used[0] = 1
while q:
    t = q.pop()
    for e in E[t]:
        if used[e[0]] == 1:
            continue
        used[e[0]] = 1
        q.append(e[0])
        
q.append(N-1)
used2 = [0]*N
used2[N-1] = 1
while q:
    t = q.pop()
    for e in Ei[t]:
        if used2[e] == 1:
            continue
        used2[e] = 1
        q.append(e)
        
L = [0]*N
for i in range(N):
    if used[i] == 1 and used2[i] == 1:
        L[i] = 1
    
def BellmanFord(E, N, source):
    inf = 10**10
    d = [inf for _ in range(N)]
    d[source] = 0
    for i in range(N):
        for j in range(N):
            e = E[j]
            if len(e) == 0:
                continue
            for edge in e:
                if d[edge[0]] > d[j]+edge[1]:
                    d[edge[0]] = d[j]+edge[1]
                    if i >= N-1 and L[edge[0]] == 1:
                        return -1
    return d

ans = BellmanFord(E, N, 0)
if ans == -1:
    print(ans)
else:
    print(max(-ans[-1], 0))

Measured memory_bytes: 53228
N, Y = map(int, input().rstrip().split(' '))
n10k = int(Y / 10000)
n10k = min(N, n10k)
n5k = int(Y / 5000)
n5k = min(N, n5k)
n1k = int(Y / 1000)
n1k = min(N, n1k)
cd = None
for i in range(n10k + 1):
    for j in range(n5k + 1):
        k = N - i - j
        if k < 0:
            break

        v = (i * 10000) + (j * 5000) + (k * 1000)
        if v == Y:
            print('{} {} {}'.format(i, j, k))
            exit(0)


print('-1 -1 -1')



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

struct Cell {
    int i, j;
    bool done;
    int cost;
};

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<Cell>> cell(h, vector<Cell>(w));
    queue<Cell> que;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cell[i][j].i = i;
            cell[i][j].j = j;
            char c;
            cin >> c;
            if (c == '.') {
                cell[i][j].done = false;
                cell[i][j].cost = 10000;
            } else {
                cell[i][j].done = true;
                cell[i][j].cost = 0;
                que.push(cell[i][j]);
            }
        }
    }

    vector<int> di = {0, -1, 0, 1}, dj = {-1, 0, 1, 0};
    int ans = 0;
    while (que.size() > 0) {
        Cell c = que.front();
        que.pop();
        int i = c.i;
        int j = c.j;
        for (int k = 0; k < 4; k++) {
            int ni = i + di[k];
            int nj = j + dj[k];
            if (0 <= ni and ni < h and 0 <= nj and nj < w) {
                if (c.cost + 1 < cell[ni][nj].cost) {
                    cell[ni][nj].cost = c.cost + 1;
                    ans = cell[ni][nj].cost;
                    que.push(cell[ni][nj]);
                }
            }
        }
    }

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

Measured memory_bytes: 32308
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,i,now;
signed main() {
    scanf("%d",&n);
    while(i<=10000000)
    {
        i++;
        now=(now*10+7)%n;
        if(now==0)
        {
            printf("%d\n",i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n, m; scanf("%d %d", &n, &m);
	
	int ma = 0;
	for(int i = 1; i * i <= m; i++) {
		if(m % i) continue;
		if(m / i >= n) ma = std::max(ma, i);
		if(m / (m / i) >= n) ma = std::max(ma, m / i);
	}
	printf("%d\n", ma);
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
typedef int Weight;
struct Edge {
	int src, dst;
	Weight weight;
	Edge(int src_, int dst_, Weight weight_) :
		src(src_), dst(dst_), weight(weight_) { }
	Edge(int src_, int dst_) :
		src(src_), dst(dst_) {

	}
};
pair<bool,vector<Weight>> spfa(const int v_num,const vector<vector<Edge>>&es,const int start) {
	vector<Weight>diss(v_num,INT_MAX);
	queue<int>que;
	vector<bool>use(v_num);
	vector<int>count(v_num);
	que.emplace(start);
	diss[start] = 0;
	while (!que.empty()) {
		int src(que.front());
		que.pop();
		use[src] = false;
		for (auto e : es[src]) {
			const int d = e.dst;
			if (diss[src] + e.weight < diss[d]) {
				diss[d] = diss[src] + e.weight;
				if (!use[d]) {
					use[d] = true;
					count[d]++;
					if (count[d] >= v_num)return make_pair(false, vector<Weight>());
					que.emplace(d);
				}
			}
		}
	}
	return make_pair(true, diss);
}
int main() {
	int V, E, R; cin >> V >> E >> R;
	vector<vector<Edge>>edges(V);
	for (int i = 0; i < E; ++i) {
		int s, t, d; cin >> s >> t >> d;
		edges[s].push_back(Edge(s,t,d));
	}
	auto p(spfa(V, edges, R));
	for (auto d : p.second) {
		if (d > INT_MAX / 2)cout << "INF" << endl;
		else cout << d << endl;
	}
	return 0;
}

Measured memory_bytes: 15376
import java.util.*;
import java.util.Map.Entry;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	HashMap<Integer, Integer> map;

	void run(){
		map=new HashMap<Integer, Integer>();
		for(; sc.hasNext();){
			map.clear();
			for(;;){
				int v=sc.nextInt();
				int u=sc.nextInt();
				if((v|u)==0){
					break;
				}
				if(!map.containsKey(v)){
					map.put(v, 0);
				}
				if(!map.containsKey(u)){
					map.put(u, 0);
				}
				map.put(v, map.get(v)+1);
				map.put(u, map.get(u)+1);
			}
			map.put(1, map.get(1)+1);
			map.put(2, map.get(2)+1);
			boolean even=true;
			for(Entry<Integer, Integer> entry : map.entrySet()){
				// debug(entry.getKey(),entry.getValue());
				even&=entry.getValue()%2==0;
			}
			println(even?"OK":"NG");
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int a[100];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int n,k;cin>>n>>k;
    double ans = 0.0;
    for(int t=1; t<=n;t++){
        double p = 1.0;
        int x = t;
        while(x<k){
            p = p/2;
            x*=2;
        }
        ans += (p/n);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	#define PI 3.14159265358979
	#define EPS 1e-8
	#define mod  998244353
	#define fi first
	#define se second
	#define mp make_pair
	#define pb push_back
	#define endl "\n"
	#define NEG_INF -2e18
				 
	const ll INF=1e15;	
	const int N=2e5+50;
			 
	 

	int main()
	{
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);cout.tie(0);
			
		ll n,k;
		cin>>n>>k;
		
		vector<pair<ll,ll> > seg(k);
		
		for(int i=0;i<k;i++)
		{
			cin>>seg[i].fi>>seg[i].se;
		}
		
		ll ans=0;
		vector<ll> dp(n+100,0);
		dp[1]=1;
		
		for(int i=2;i<=n;i++)
		{
			ll val=0;
			for(ll j=0;j<k;j++)
			{
				if(i-seg[j].fi>=1)
				{
					 val+=dp[i-seg[j].fi];
					 val%=mod;
					
				}
				if(i-seg[j].se>1)
				{
					val-=dp[i-seg[j].se-1];
					val%=mod;
					 val+=mod; 	
					 val%=mod;
				}
			}
			dp[i]=val+dp[i-1];
			dp[i]%=mod;
			
			//cout<<i<<" "<<dp[i]<<endl;
		}

		 ans=dp[n]-dp[n-1];
		ans%=mod;
		ans+=mod;
		ans%=mod;
		cout<<ans;
	}


Measured memory_bytes: 4772
from collections import deque,defaultdict
import heapq as hp
def solve():
    h,w,m=map(int,input().strip().split(" "))
    dr=defaultdict(int)
    dc=defaultdict(int)
    s=set()
    for _ in range(m):
        a,b=map(int,input().strip().split(" "))
        dr[a]+=1
        dc[b]+=1
        s.add((a,b))

    kr=max(dr.values())
    kc=max(dc.values())
    rs=[]
    cs=[]
    rs+=[i for i in dr.keys() if dr[i]==kr ]
    cs+=[i for i in dc.keys() if dc[i]==kc ]
    for i in rs:
        for j in cs:
            if (i,j) not in s:
                print(kr+kc)
                exit()

    print(kr+kc-1)






solve()


Measured memory_bytes: 239072
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;
using tdata=pair<datas,ll>;

int main(){
  ll i,j,H,W,N=0,f=0,x,bx=-1,by=-1;
  cin>>H>>W;
  mat v(H*W,vec(4,0));
  vec rev(W);
  rep(i,H){
    f^=1;
    if(f){
      rep(j,W){
        cin>>x;
        if(bx+by>=0){
          v[N][0]=bx+1;
          v[N][1]=by+1;
          v[N][2]=i+1;
          v[N++][3]=j+1;
          if(x%2){
            bx=by=-1;
          }else{
            bx=i;
            by=j; 
          }
        }else if(x%2){
          bx=i;
          by=j;
        }
      }
    }else{
      rep(j,W)cin>>rev[j];
      for(j=W-1;j>=0;j--){
        x=rev[j];
        if(bx+by>=0){
          v[N][0]=bx+1;
          v[N][1]=by+1;
          v[N][2]=i+1;
          v[N++][3]=j+1;
          if(x%2){
            bx=by=-1;
          }else{
            bx=i;
            by=j;
          }
        }else if(x%2){
          bx=i;
          by=j;
        }
      }
    }
  }
  cout<<N<<endl;
  rep(i,N){
    rep(j,4){
      cout<<v[i][j];
      if(j<3)cout<<" ";
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 19840
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int main(){
    set<int> S;
    int n;
    cin >> n;

    int d;

    for(int i = 0; i < n; i++){
        cin >> d;
        S.insert(d);
    }

    printf("%d\n", S.size());

    return 0;

}

Measured memory_bytes: 256
n = int(input())
s = input()
c = 0
sl = 0
lli =[]
rli =[]
k = 0
j = 0
for i in range(n):
    if i == 0:
        if s[i] == "(":
            lli.append(1)
            j = 1
        else:
            sl += 1
            k = 1
    elif s[i] == "(":
        k = 0
        if c == 1 or j == 1:
            lli[-1] += 1
            j = 0
        else:
            lli.append(1)
        c = 1
    else:
        if k == 1:
            sl += 1
        elif c == 2:
            if lli[-1] > 0:
                lli[-1] -= 1
            else:
                for v in range(len(lli)):
                    if lli[-1-v] > 0:
                        lli[-1-v] -= 1
                        break
                else:
                    rli[-1] += 1
        else:
            rli.append(0)
            lli[-1] -= 1
        c = 2

if sum(rli) + sl > 0 and sum(lli) > 0:
    print("(" * (sum(rli) + sl) + s + ")" * sum(lli))
elif sum(rli) + sl <= 0 and sum(lli) > 0:
    print(s + ")" * sum(lli))
elif sum(rli) + sl > 0 and sum(lli) <= 0:
    print("(" * (sum(rli) + sl) + s)
else:
    print(s)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int a, b, k;

signed main() {
	cin >> a >> b >> k;
	repr(i,111) if (a%i==0 && b%i==0) {
		k--;
		if (k==0) return cout << i << endl, 0;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
const ll mod=1e9+7;


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

    double ans;
    double n;
    cin>>n;
    ans=2*3.14159*n;
    cout<<ans;


    return 0;
}

Measured memory_bytes: 3796
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>

using namespace std;

int main() {
	int a;
	cin >> a;
	vector<int> buff; 
	vector<int> v;


	for (int i = 0; i < a; i++) {
		int temp;
		cin >> temp;
		buff.push_back(temp);
	}

	sort(buff.begin(), buff.end());
	
	cout << abs(buff.back() - buff.front()) << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

cur = a[0]
ans = 0
rp = 1

for lp in range(n):
    while rp < n and cur & a[rp] == 0:
        cur += a[rp]
        rp += 1
    ans += rp - lp
    cur -= a[lp]

print(ans)


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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

string S;

int main()
{
	cin >> S;
	if(S [0] == S [2]){
		puts("Yes");
	}
	else{
		puts("No");
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main (String [] args){
        Scanner  sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int cnt=0;
        for (int i=1;i<=N;i++){
            int total=0;
            String s= String.valueOf(i);
            String slist[] = s.split("");
            for (int j =0;j<slist.length;j++){
                total += Integer.parseInt(slist[j]);
            }
            if (total >= A && total <= B){
                cnt += i;
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 34260
x,n = map(int,input().split())
if n != 0:
    p_list = list(map(int,input().split()))
    num_list = []
    num_list.append(x)
    for i in range(1,51):
        num_list.append(x-i)
        num_list.append(x+i)
    flag = True
    for i in num_list:
        if flag == False:
            break
        if i not in p_list:
            ans = i
            flag = False
    print(ans)
else:
    print(x)

Measured memory_bytes: 9224
#include<bits/stdc++.h>
#define REP(i,b,e) for(int i=b; i<e; i++)
const double EPS = 1e-10;

struct Point {
    double x, y;
    Point(double x=0, double y=0): x(x), y(y) {}
    Point(const Point &a): x(a.x), y(a.y) {}
};
inline Point operator+(const Point &p, const Point &q) {return Point(p.x+q.x, p.y+q.y);}
inline Point operator-(const Point &p, const Point &q) {return Point(p.x-q.x, p.y-q.y);}
inline Point operator*(const Point &p, double a) {return Point(p.x*a, p.y*a);}
inline Point operator/(const Point &p, double a) {return Point(p.x/a, p.y/a);}

inline Point rot90(const Point &p){ return Point(-p.y, p.x); }
inline double dot(const Point &a, const Point &b){ return a.x*b.x + a.y*b.y; }
inline double cross(const Point &a, const Point &b){ return a.x*b.y - b.x*a.y; }
inline double abs(const Point &p){ return sqrt(dot(p, p)); }

struct Line {
    Point a, b;
    Line(Point a, Point b): a(a), b(b) {}
};


Point crosspoint(const Line &l, const Line &m){
    double A = cross(m.b - m.a, l.b - l.a);
    double B = cross(m.b - m.a, m.b - l.a);
    if(abs(A)<EPS) return Point(EPS,EPS);
    return l.a + (l.b-l.a) * B/A;
}

Point gaisin(Point a, Point b, Point c){
    Line ab((a+b)/2, (a+b)/2+rot90(a-b));
    Line bc((b+c)/2, (b+c)/2+rot90(b-c));
    return crosspoint(ab, bc);
}

int main(){
	int n;
	scanf("%d", &n);
	std::vector<Point> ps(n);
	REP(i, 0, n) scanf("%lf %lf", &ps[i].x, &ps[i].y);

	double ans = 1000;
	REP(i, 0, n) REP(j, i+1, n) REP(k, j+1, n) {
	    Point gs = gaisin(ps[i], ps[j], ps[k]);
	    if(gs.x==EPS and gs.y==EPS) continue;
	    double R = abs(gs-ps[i]);
	    bool ok = true;
	    REP(l, 0, n){
		if(R<abs(gs-ps[l])) ok = false;
	    }
	    if(ok && ans>R) ans = R;
	}

	REP(i, 0, n) REP(j, i+1, n) {
	    Point o = (ps[i]+ps[j])/2;
	    double R = abs(o-ps[i]);
	    bool ok = true;
	    REP(k, 0, n){
		if(R<abs(o-ps[k])) ok = false;
	    }
	    if(ok && ans>R) ans = R;
	}
	printf("%.10lf\n", ans);
	return 0;
}



Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int i,j,k;string s,t;
int main(){
	getline(cin,s);
	while (s.length()>0){
		t=s.substr(0,5);
		if (t=="dream"){
			s=s.substr(5);
			if (s=="") break;
			if (s.length()==1){printf("NO");return 0;}
			else if (s.length()==2){
				if (s[0]=='e'&&s[1]=='r') s="";
				else {printf("NO");return 0;}
			}
			else {
				if (s[0]=='e'&&s[1]=='r'&&s[2]!='a') s=s.substr(2);
			}
		}
		else if (t=="erase"){
			s=s.substr(5);
			if (s=="") break;
			if (s.length()==1){
				if (s[0]=='r') s="";
				else {printf("NO");return 0;}
			}
			else {
				if (s[0]=='r') s=s.substr(1);
			}
		}
		else {printf("NO");return 0;}
	}
	printf("YES\n");
}

Measured memory_bytes: 3972
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
ll n,k,bit[200005],ans;
P a[200005];
void add(int x){
    x++;
    while(x<=n+1){
        bit[x]++;
        x+=(x&-x);
    }
}
ll sum(int x){
    ll res=0;
    x++;
    while(x>0){
        res+=bit[x];
        x-=(x&-x);
    }
    return res;
}
int main(void){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        x-=k;
        a[i].F+=x;
        a[i+1].F+=a[i].F;
        a[i].S=i+1;
    }
    a[n]=P(0,0);
    sort(a,a+n+1);
    for(int i=0;i<=n;i++){
        ans+=sum(a[i].S);
        add(a[i].S);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4992
N = int(input())
A = [0]*N
#最大値を記録しておく
m = 0
#答えとなる変数
ans = 0
#重なっている数をカウントする変数
count = 0
#入力を受け付ける
for i in range(N):
    A[i] =  int(input())
A.sort()
for i in range(N):
    if(m<A[i]):
        m =A[i]
    elif(m == A[i]):
        count +=1
ans = N - count
print(ans)

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

namespace Atcoder
{
    class Tenka1
    {
        static void Main(string[] args)
        {
            string[] rawinput = Console.ReadLine().Split(' ');
            int A = int.Parse(rawinput[0]); int B = int.Parse(rawinput[1]); int K = int.Parse(rawinput[2]);

            for(int i = 0; i < K; i++)
            {
                if (i % 2 == 0)//Aが施行する番
                {
                    if (A % 2 == 1)//奇数判定
                    {
                        A--;
                    }
                    B += A / 2; A -= A / 2;
                }
                else if (i % 2 == 1)//Bに対しての施行
                {
                    if (B % 2 == 1)//奇数判定
                    {
                        B--;
                    }
                    A += B / 2; B -= B / 2;
                }
                
            }

            Console.Write(A);Console.Write(' ');Console.Write(B);
        }
    }
}


Measured memory_bytes: 11092
fn main() {
    proconio::input! {
        n: usize,
        m: usize,
    }
    for i in 0..m/2 {
        println!("{} {}", 1+i, n-i-1);
    }
    let k=(m+1)/2;
    for i in 0..k {
        let j = m/2+1+i;
        println!("{} {}", j, j+(k-i)*2-1);
    }
}

Measured memory_bytes: 2176
import sys
from collections import deque
s = deque(s for s in sys.stdin.readline().rstrip())

s.append(None)
ans = 0
while s[0] != None:
    l_c = 0
    while s[0] == '<':
        l_c += 1
        s.popleft()
    
    r_c = 0
    while s[0] == '>':
        r_c += 1
        s.popleft()

    if l_c >= r_c:
        ans += (1 + l_c) * l_c // 2 + r_c * (r_c - 1) // 2
    else:
        ans += l_c * (l_c - 1) // 2 + (1 + r_c) * r_c // 2

print(ans)

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


int main(void){

  int input;
  int count;

  count = 0;

  do{
    cin >> input;

    count++;

    if(input != 0){
      cout << "Case " << count << ": " << input << endl;
    }

  }while(input != 0);

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  if(n < 1000) cout << "ABC" << endl;
  else cout << "ABD" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, x, tmp, ans, cur;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        if (cur <= x) {
            ans++;
        }
        cin >> tmp;
        cur = cur + tmp;
    }
    if (cur <= x) {
        ans++;
    }
    cout << ans << "\n";
    //system("pause");
    return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  vector<vector<Pib>> man(n, vector<Pib>());
  rep(i,n) {
    cin >> a[i];
    rep(j, a[i]) {
      int x, y; cin >> x >> y;
      man[i].push_back(make_pair(x-1, y));
    }
  }

  int maxt = 0;
  for (int b = 1; b<(1<<n); b++) {
    vector<int> tf(n, 0);
    bool flag = true;
    rep(i,n) if ((b>>i) & 1) tf[i] = 1;
    rep(i,n){
      rep(j,a[i]) {
        int x = man[i][j].first;
        bool y = man[i][j].second;
        if (tf[i] == 0) continue;
        else if (tf[x] != y) { flag = false; break; }
      }
      if (!flag)  break;
    }
    if (flag) {
      int cnt = 0;
      rep(i, n) if (tf[i] == 1) cnt++;
      maxt = max(cnt, maxt);
    }
  }
  cout << maxt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define sqr(v) ((v)*(v))

using namespace std;
bool vis[1<<20];
double x[21],y[21],z[21],len[1<<20];
double sum(int i,int j)
{
	return sqr(x[i]-x[j])+sqr(y[i]-y[j])+sqr(z[i]-z[j]);

}
int cal(int v)
{
	int res=0;
	for(;v;v-=(v&-v))++res;
	return res;
}
int main()
{
	int i,j,k,p,n,m;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;++i)
	{
		//cout <<n<<" "<<i<<endl;
		scanf("%lf%lf%lf",&x[i],&y[i],&z[i]);
	}
	int full=1<<n;
	len[0]=0;
	double tmp,ans=0;
	for(i=0;i<full;++i)
	{
		for(j=0;(1<<j)<full;++j)
		{
			if(i&(1<<j))continue;
			if(vis[i|(1<<j)])continue;
			tmp=0;
			for(k=0;(1<<k)<full;++k)
				if(i&(1<<k))tmp+=sum(j,k);
			//if((i|(1<<j))==4)cout <<len[i]<<" "<<i<<" "<<j<<" "<<tmp<<endl;
			len[i|(1<<j)]=len[i]+tmp;
			vis[i|(1<<j)]=true;
		}
	}
	for(i=0;i<full;++i)
	{
		//cout <<i<<" "<<m<<" "<<len[i]<<endl;
		if(cal(i)==m)
		{
			ans=max(ans,len[i]);
		}
	}
	printf("%.9f\n",ans);
	return 0;
}

Measured memory_bytes: 10448
n, k = map(int, input().split())
a = list(map(int,input().split()))

ans = 0

for i in range(n-1):
    for j in range(i+1, n):
        if a[i] > a[j]:
            ans += 1

ansk = 0

for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            ansk += 1

print((ans * k + ansk * ((k-1)*k //2)) % (10**9 + 7))


Measured memory_bytes: 3188
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	string S;
	cin>>S;
	int ans=S.size(),sc=0;
	REP(i,S.size()){
		if(S[i]=='S')sc++;
		else if(sc>0){
			ans-=2;
			sc--;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}




















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

using namespace std;

int main(){
  int n;
  scanf("%d", &n);
  vector <int> v(n + 1);
  for (int i = 1; i <= n; i++){
    int x;
    scanf("%d", &x);
    v[x] = i;
  }
  for (int i = 1; i <= n; i++){
    printf("%d ", v[i]);
  }
  printf("\n");
    return 0;
}


Measured memory_bytes: 1152
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

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

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

map < ll, ll > mp;

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n >> m)
    {
		mp.clear();

		for(i = 1; i <= m; i++)
		{
			slld(input);
			mp[input] = 1;
		}

		ll diff = 0;
		j = n;

		while(mp[j]) j++;

		diff = j - n;

		j = n;

		while(mp[j]) j--;

		if(n - j <= diff) cout << j << '\n';
		else cout << n + diff << '\n';



    }


}





Measured memory_bytes: 3676
package main

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

type point struct {
	x, y int
}

func solve() {
	p1 := point{getInt(), getInt()}
	p2 := point{getInt(), getInt()}

	dx, dy := p2.x-p1.x, p2.y-p1.y
	p3 := point{p2.x - dy, p2.y + dx}
	p4 := point{p1.x - dy, p1.y + dx}
	fmt.Fprintln(wr, p3.x, p3.y, p4.x, p4.y)
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;

int main() {
    fastio;

    int h, w;
    cin >> h >> w;
    char A[h][w];
    FOR(i, 0, h) {
        FOR(j, 0, w) {
            cin >> A[i][j];
        }
    }
    FOR(i, 0, h) {
        FOR(j, 0, w) {
            if (A[i][j] == '.') {
                int count = 0;
                for (int a = -1; a <= 1; a++) {
                    for (int b = -1; b <= 1; b++) {
                        if (a+i >= 0 && a+i<h && b+j >=0 && b+j<w) {
                            if (A[a+i][b+j] == '#') {count++;}
                        } 
                    }
                }
                A[i][j] = count + '0';
            }
        }
    }
    FOR(i, 0, h) {
        FOR(j, 0, w) {
            cout << A[i][j];
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
from itertools import permutations
from math import factorial, sqrt

n = int(input())
poses = []
for i in range(n):
    x, y = map(int, input().split())
    poses.append((x, y))

w = 0
for X in permutations(range(n)):
    x0, y0 = poses[X[0]]
    z = 0
    for i in X[1:]:
        x, y = poses[i]
        z += sqrt((x0-x)**2 + (y0-y)**2)
        x0, y0 = x, y
    w += z
print(w / factorial(n))
    

Measured memory_bytes: 3064
import java.math.BigDecimal;
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int A = sc.nextInt();

        int[] values = new int[N];
        for (int i = 0; i < N; i++) {
            values[i] = sc.nextInt();
        }


        long[][][] dp = new long[N + 1][N + 1][3000];// [i][j][s] xiまでからjこ取って合計がsになる選び方

        dp[0][0][0] = 1;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int k = 0; k < N * A; k++) {
                    // i+1番目を拾う場合
                    dp[i+1][j+1][k + values[i]] += dp[i][j][k];
                    // i+1番目を拾わない場合
                    dp[i+1][j][k] += dp[i][j][k];

                }
            }
        }




        long sum = 0;
        for (int i = 1; i < N+1; i++) {
            sum += dp[N][i][i * A];
        }

        System.out.println(sum);
    }

}

Measured memory_bytes: 129224
#define _USE_MATH_DEFINES


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <numeric>
#include <array>
#include <set>
#include <sstream>
#include <cmath>

using namespace std;

typedef long long LL;


vector<vector<LL>> creat_matrix(LL h, LL w) {
	LL _temp;
	vector<vector<LL>> mat;
	for (LL i = 0; i < h; ++i) {
		vector<LL> vec;
		for (LL j = 0; j < w; ++j) {
			cin >> _temp;
			vec.emplace_back(_temp);
		}
		mat.emplace_back(vec);
	}
	return mat;
}


vector<vector<LL>> inner_product(vector<vector<LL>> X, vector<vector<LL>> Y) {
	size_t n = X.size();
	size_t m = X[0].size();
	size_t l = Y[0].size();

	vector<vector<LL>> mat(n, vector<LL>(l, 0));
	for (LL i = 0; i < n; ++i) {
		for (LL j = 0; j < m; ++j) {
			for (LL k = 0; k < l; ++k) {
				mat[i][k] += X[i][j] * Y[j][k];
			}
		}
	}
	return mat;
}


void show_matrix(vector<vector<LL>> mat) {
	size_t len = mat[0].size();
	for (auto&& t : mat) {
		for (LL i = 0; i < len; ++i) {
			printf("%d", t[i]);
			if (i != (len - 1)) printf(" ");
		}
		printf("\n");
	}
}


int main() {
	string st;
	vector<int> nums(26);
	while (getline(cin, st)) {

		for (auto c : st) {
			if (c <= 'z' && c >= 'a') nums[c - 'a']++;
			if (c <= 'Z' && c >= 'A') nums[c - 'A']++;
		}
	}

	for (int i = 0; i < 26; ++i) {
		cout << char('a' + i) << " : " << nums[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 3144
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

    def division(self, n):
        d = collections.defaultdict(int)
        for c in self.T:
            while n % c == 0:
                d[c] += 1
                n //= c
            if n < 2:
                break
        if n > 1:
            d[n] += 1
        return d.items()

    def sowa(self, n):
        r = 1
        for k,v in self.division(n):
            t = 1
            for i in range(1,v+1):
                t += math.pow(k, i)
            r *= t
        return r


def main():
    n = I()
    a = sorted(LI())
    pr = Prime(10**9)
    p = collections.defaultdict(int)

    for b in a:
        r = [1]
        for k, v in pr.division(b):
            for c in r[:]:
                for i in range(1,v+1):
                    r.append(c*(k**i))
        for k in r:
            p[k] += 1
    r = 1
    for k,v in p.items():
        if v >= n-1 and r < k:
            r = k

    return r


print(main())



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

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

const int MOD = 1e9 + 7;

int add(int a, int b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
	return a;
}

int sub(int a, int b) {
	a -= b;
	if (a < 0)
		a += MOD;
	return a;
}

int mul(int a, int b) {
	return (ll)a * b % MOD;
}

int binpow(int a, int n) {
	int ans = 1;
	while (n) {
		if (n & 1) {
			ans = mul(ans, a);
		}
		a = mul(a, a);
		n >>= 1;
	} 
	return ans;
}

int inv(int a) {
	return binpow(a, MOD - 2);
}

const int MAXN = 2e5 + 10;

int fact[MAXN], rfact[MAXN];

void build() {
	fact[0] = rfact[0] = 1;
	for (int i = 1; i < MAXN; i++) {
		fact[i] = mul(i, fact[i - 1]);
		rfact[i] = inv(fact[i]);
	}
}

int get_c_n_k(int n, int k) {
	return mul(fact[n], mul(rfact[k], rfact[n - k]));
}

int n, k;

void read() {
	cin >> n >> k;
}

int ans;

int get(int x) {
	return mul(mul(x, sub(x, 1)), inv(2));
}

int get(int l, int r)  {
	return sub(get(r), get(l - 1));
}

void run() {
	ans = 0;
	for (int i = k; i <= n + 1; i++) {
		ans = add(ans, sub(get(n + 1 - i + 1, n + 1), get(1, i)));
		ans = add(ans, 1);	
	}
}

void write() {
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	build();
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 5212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef pair<int, string> i_S;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int H, W;
string field[72];
i_S dp[72][72];


int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        cin >> W >> H;
        if(W == 0) break;
        for(int h = 1; h <= H; h++) {
            cin >> field[h];
            field[h] = "&" + field[h];
        }
        for(int h = 1; h <= 71; h++) {
            for(int w = 1; w <= 71; w++) {
                dp[h][w] = {0, ""};
            }
        }
        i_S ans = {0, ""};
        for(int h = H; h >= 1; h--) {
            for(int w = W; w >= 1; w--) {
                if(field[h][w] <= 'Z' && field[h][w] >= 'A') continue;
                i_S now = max(dp[h+1][w], dp[h][w+1]);
                now.first++;
                now.second = field[h][w] + now.second;
                if(now.second[0] != '0') ans = max(ans, now);
                dp[h][w] = now;
            }
        }
        cout << ans.second << endl;
    }
    return 0;
}


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

  static const int N = 100;

  int main() {
    int n, p[N + 1], m[N + 1][N + 1];
    cin >> n;
   for ( int i = 1; i <= n; i++ ) {
     cin >> p[i - 1] >> p[i];
   }

   for ( int i = 1; i <= n; i++ ) m[i][i] = 0;
   for ( int l = 2; l <= n; l++ ) {
     for ( int i = 1; i <= n - l + 1; i++ ) {
       int j = i + l - 1;
       m[i][j] = (1 << 21);
       for ( int k = i; k <= j - 1; k++ ) {
         m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
       }
     }
   }

   cout << m[1][n] << endl;

   return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

ll solve[55][15] = {};
ll pena[55][15] = {};

int main(){
	while(1){
		ll T,P,R; cin >> T >> P >> R;
		if(!T && !P && !R) break;
		ll t,p,time; string ver;
		while(R--){
		cin >> t >> p >> time >> ver; t--; p--;
			if(ver == "CORRECT"){
				solve[t][p] = 1;
				pena[t][p] -= time;
			}else{
				pena[t][p] -= 1200;
			}
		}
		vector<tapu> ans(T);
		rep(i,T){
			ll a=0,b=0,c=-i-1;
			rep(j,P){
				if(solve[i][j]){
					a++;
					b += pena[i][j];
				}
			}
			ans[i] = tie(a,b,c);
		}
		sort(rall(ans));
		rep(i,T){
			ll a,b,c; tie(a,b,c) = ans[i];
			print3(-c,a,-b);
		}
		rep(i,T) rep(j,P) solve[i][j] = pena[i][j] = 0;
	}
}


Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

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

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
BBW
)");
#define cin input
#endif

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

	int x = 0;
	ll r = 0;

	for (char c : s)
	{
		if (c == 'W')
		{
			r += x;
			--x;
		}
		++x;
	}

	cout << r << endl;

	return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int n, k; cin >> n >> k;
  if(n%2==0) n = n/2;
  else n = n/2 + 1;
  if(k <= n) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256