akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define for(I,N) for(int I=0; I < N; I++)
using ll=long long int;
using namespace std;

ll sik = 1e18;
bool zero = false;

int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(i,n){
		cin>>a[i];
		if(a[i]==0)zero = true;
	}
	if(zero){cout<<'0';return 0;}
	
	for(i,n){
		sik/=a[i];
	}
	if(sik<1)cout<<-1;
	else{
		ll it =1;
		for(i,n){it*=a[i];}
			cout<<it;
	}

}


Measured memory_bytes: 4412
using System;

namespace ALDS1_1_A
{
    class Program
    {
        static int Main(string[] args)
        {
            //入力
            int inputCount = int.Parse(Console.ReadLine().Trim());
            string str = Console.ReadLine().Trim();
            var datas = str.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            int[] inputNum = new int[inputCount];
            for (int lp = 0; lp < inputCount; lp++)
            {
                inputNum[lp] = int.Parse(datas[lp]);
            }

            //処理
            Output(inputNum);
            for (int i = 1; i < inputCount; i++)
            {
                var key = inputNum[i];
                var j = i - 1;
                while (j >= 0 && inputNum[j] > key)
                {
                    inputNum[j + 1] = inputNum[j];
                    j--;
                }
                inputNum[j + 1] = key;
                Output(inputNum);
            }

            return 0;
        }

        static void Output(int[] inputNum)
        {
            Console.WriteLine(String.Join(" ", inputNum));
        }
    }
}



Measured memory_bytes: 17920
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
char s[maxn];
bool judge(int x,int y)
{
    if(s[x]=='#'||s[y]=='#') return 0;
    int lst=x;
    for(int i=x+1;i<=y;i++)
    {
        if(s[i]=='#') continue;
        if(i-lst>2) return 0; lst=i;
    }
    return 1;
}
bool vis[maxn];
int main ()
{
    int n,a,b,c,d;
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    scanf("%s",s+1);
    if(!judge(a,c)) return printf("No\n"),0;
    if(!judge(b,d)) return printf("No\n"),0;
    if(c<d) return printf("Yes\n"),0;
    for(int i=b-1;i<=d+1;i++) if(s[i]=='.') vis[i]=1;
    for(int i=1;i<=n-2;i++)
        if(vis[i]&&vis[i+1]&&vis[i+2]) return printf("Yes\n"),0;
    printf("No\n");
    return 0;
}
/*
15 1 3 15 13
...#.#.#.#.#...
*/

Measured memory_bytes: 512
import math
a,b,h,m=map(int,input().split())
h_=h*30+m*30/60
m_=m*6
p=abs(h_-m_)
if p>=180:
    p=360-p
ans=a**2+b**2-2*a*b*math.cos(math.radians(p))
print((ans)**0.5)

Measured memory_bytes: 9572
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}


	class P{
		int s;
		int t;
		public P(int s, int t) {
			this.s=s;
			this.t=t;
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		ArrayList<P> ans = new ArrayList<>();
		for(int i=0; i<n-1; i++) {
			ans.add(new P(i+1, n));
		}

		ArrayList<P> tmp = new ArrayList<>();
		for(int i=0; i<n-1;i++) {
			for(int j=0; j<i; j++) {
				tmp.add(new P(i+1, j+1));
			}
		}

		int cnt = (n-1)*(n-2)/2;

		for(int i=0; i<tmp.size(); i++) {
			if(k==cnt) {
				break;
			}
			ans.add(tmp.get(i));
			cnt--;
		}

		if(cnt<k) {
			System.out.println(-1);
			sc.close();
			return;
		}

		System.out.println(ans.size());
		for(P p : ans) {
			System.out.println(p.s+" "+p.t);
		}
		sc.close();
	}


}


Measured memory_bytes: 40148
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> A >> B;
    cout << max(0LL, A - 2 * B) << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
const int N = 1e5+9;
using namespace std;
deque<pair<int, long long> > q;
int k;
bool vis[N];
 
int main() {
  scanf("%d", &k);
  q.push_back({1, 1});
  while(!q.empty()) {
    pair<int, long long> tp = q.front(); q.pop_front();
    if(!tp.first) {
      printf("%d\n", tp.second);
      break;
    }
    if(vis[tp.first]) continue;
    vis[tp.first] = 1;
    q.push_front({tp.first*10%k, tp.second});
    q.push_back({(tp.first+1)%k, tp.second+1});
  }
  return 0;
}

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

using namespace std;

int key;
long long  n,k,a[1005],b[1005],c[1005],tot[1005],maxim=-1;
int FormTot(int key)
{
    for(int i=1;i<=n;i++)
        tot[i]=0;
    for(int i=1;i<=n;i++)
    {
        if((key&1)==1)
            tot[i]+=a[i];
        else tot[i]-=a[i];
        if((key&2)==2)
            tot[i]+=b[i];
        else tot[i]-=b[i];
        if((key&4)==4)
            tot[i]+=c[i];
        else tot[i]-=c[i];
    }

    sort(tot+1,tot+n+1,greater<long long>());
    long long x=0;
    for(int i=1;i<=k;i++)
    {
        x+=tot[i];
    }
    maxim=max(maxim,x);
}



int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];
    for(key=0;key<=7;key++)
        FormTot(key);
    cout<<maxim<<"\n";
    return 0;
}


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

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

    int res = a * b;

    if(a<0 || 9<a)  res = -1;
    if(b<0 || 9<b)  res = -1;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string N;
    int K;
    cin >> N >> K;
    vector<char> D(K);
    unordered_map<char, int> mp;
    for (int i = 0; i < K; i++) {
        cin >> D.at(i);
        mp[D.at(i)] = 1;
    }
    char m = '-', mm = '-';
    for (char i = '0'; i <= '9'; i++) {
        if (mp[i] == 0) {
            if (m == '-') {
                m = i;
            }
            else {
                mm = i;
            }
            if (m != '-') {
                if (m != '0' || mm != '-') {
                    break;
                }
            }
        }
    }
    bool KRAG = false;
    for (int i = 1; i <= (int) N.size(); i++) {
        int j = (int) N.size() - i;
        int check = 0;
        if (KRAG) {
            int memo = N.at(j) - '0';
            for (int k = (int) N.size() - 1; k > j; k--) {
                N.at(k) = m;
            }
            if (memo == 9) {
                N.at(j) = m;
                continue;
            }
            memo++;
            N.at(j) = memo + 0x30;
            //cout << j  <<"    "<<N.at(j)<<endl;
        }
        char memo2;
        memo2 = N.at(j);
        for (char k = N.at(j); k <= '9'; k++) {
            if (mp[k] == 0) {
                N.at(j) = k;
                check = 1;
                break;
            }
        }
        if (check == 0) {
            N.at(j) = m;
            KRAG = true;
        }
        else {
            KRAG = false;
        }
        if (memo2 != N.at(j)) {
            for (int k = (int) N.size() - 1; k > j; k--) {
                N.at(k) = m;
            }
        }
    }
    if (KRAG) {
        for (int k = (int) N.size() - 1; k > 0; k--) {
            N.at(k) = m;
        }
        if (m != '0') {
            N = m + N;
        }
        else {
            N = mm + N;
        }
    }
    cout << N << endl;
}

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <list>
#include <algorithm>

using namespace std;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

#define LengthOf(x)    (sizeof(x) / sizeof(x[0]))
#define PI 3.14159265358979323846

#if 1
//No.4
typedef struct {
	INT dist;
	INT prevRoom;
	vector<INT> link;
} NODE;

//深さ優先
void update(NODE* node, INT curRoom, INT prevRoom, INT dist, INT* roomCnt)
{
	//update dist
	if (dist < node[curRoom].dist) {
		if (node[curRoom].dist == 0x7FFFFFFF) { *roomCnt += 1; }	//reached room count.

		node[curRoom].dist = dist;
		node[curRoom].prevRoom = prevRoom;

		//next room
		for (int i = 0; i < node[curRoom].link.size(); ++i) {
			update(node, node[curRoom].link[i], curRoom, dist + 1, roomCnt);
		}
	}
}

//幅優先
typedef struct {
	INT curRoom;
	INT prevRoom;
	INT dist;
} QUERY;

void update2(NODE* node, INT curRoom, INT prevRoom, INT dist, INT* roomCnt, list<QUERY>* query)
{
	//update dist
	if (dist < node[curRoom].dist) {
		if (node[curRoom].dist == 0x7FFFFFFF) { *roomCnt += 1; }	//reached room count.

		node[curRoom].dist = dist;
		node[curRoom].prevRoom = prevRoom;

		//next room
		for (int i = 0; i < node[curRoom].link.size(); ++i) {
			//update(node, node[curRoom].link[i], curRoom, dist + 1, roomCnt);
			QUERY newQuery;
			newQuery.curRoom = node[curRoom].link[i];
			newQuery.prevRoom = curRoom;
			newQuery.dist = dist + 1;
			query->push_back(newQuery);
		}
	}

	if (query->empty() == false) {
		QUERY proc = query->front();
		query->pop_front();
		update2(node, proc.curRoom, proc.prevRoom, proc.dist, roomCnt, query);
	}
}

int main()
{
	INT N, M;
	cin >> N >> M;

	NODE* node = new NODE[N + 1];
	for (int i = 0; i < N + 1; ++i) {
		node[i].prevRoom = 0;
		node[i].dist = 0x7FFFFFFF;
	}

	for (int i = 0; i < M; ++i) {
		INT a, b;
		cin >> a >> b;
		node[a].link.push_back(b);
		node[b].link.push_back(a);
	}

	INT roomCnt = 0;
	//update(node, 1, 0, 0, &roomCnt);
	list<QUERY> query;
	update2(node, 1, 0, 0, &roomCnt, &query);

	if (roomCnt != N) {
		cout << "No";
	}
	else {
		cout << "Yes" << endl;
		for (int i = 2; i < N + 1; ++i) {
			cout << node[i].prevRoom << endl;
		}
	}

	return 0;
}
#endif

Measured memory_bytes: 24732
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

line = require('fs').readFileSync(config.input, 'ascii')
  .split(config.newline);
T = line[0];
Q = Number(line[1]);
P = line.slice(2, 2+Q);
line = null; // dispose

for (i in P) console.log((T.indexOf(P[i]) !== -1) ? 1 : 0);

Measured memory_bytes: 37888
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void) {
  int len, kari, ans = 1000000;
  char s[12], s2[4];

  if(scanf("%s", s) != 0);

  len = strlen(s);

  for(int i = 0; i < len - 2; i++) {
    for(int j = 0; j < 3; j++) {
      s2[j] = s[j + i];
    }
    kari = atoi(s2);
    if(ans > abs(753 - kari)) {
      ans = abs(753 - kari);
    }
  }

  printf("%d", ans);

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

#define MAX 10*10*10*10*10*10*10*10*10

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int S[500000];
int count=0;

int main(){
  int n, i, j;

  scanf("%d",&n);
  if(n > 500000) exit(1);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
    if(S[i] < 0 || MAX < S[i]) exit(2);
  }

  mergeSort(S,0,n);

  for(j=0; j<n; j++){
    printf("%d", S[j]);
    if(j<n-1) printf(" ");
  }
  printf("\n%d\n", count);

  return 0;
}

void merge(int *A, int left, int mid, int right){
  int n1, n2, i, j, k;
  int L[500000], R[500000];

  n1=mid-left;
  n2=right-mid;
  for(i=0; i<n1; i++){
    L[i]=A[left+i];
  }
  for(j=0; j<n2; j++){
    R[j]=A[mid+j];
  }
  L[n1]=R[n2]=MAX;
  i=j=0;
  for(k=left; k<right; k++){
    if(L[i] <= R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      j++;
    }
    count++;
  }
}

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



Measured memory_bytes: 5648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll N;
  cin >> N;
  vector<ll> B(N-1);
  for (ll i = 0; i < N-1; i++) {
    cin >> B[i];
  }
  vector<ll> A(N);
  for (ll i = 0; i < N-1; i++) {
    if (i == 0) {
      A[i] = A[i+1] = B[i];
    }
    else if (B[i] >= B[i-1]) {
      A[i+1] = B[i];
    }
    else {
      A[i] = A[i+1] = B[i];
    }
  }
  ll sum;
  for (ll i = 0; i < N; i++) {
    sum += A[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
//abc076_a.cpp
//Sat Jul 21 20:52:20 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INF 100000000
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int r,g;
	cin >> r >> g;
	cout << 2*g-r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

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

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

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(510000);

int main() {
  long long N, M, K; cin >> N >> M >> K;
  combination C(510000);
  mint sum = 0;
  for(int i = 0; i <= N-1; ++i) {
    for(int j = 0; j <= M-1; ++j) {
      mint tmp = mint(N-i) * mint(M-j) * mint(i+j);
      if(i!=0 && j != 0) tmp *= 2;
      sum += tmp;
    }
  }
  sum *= C(N*M-2, K-2);
  cout << sum.x << endl;
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

void solve(){
   int n,x,t;
   cin >> n >> x >> t;

   int ans =  t * ((n + x - 1)/x);
   cout << ans << "\n";
}

int32_t main(){
   fast;
   int t = 1;
   // cin >> t;
   while(t--)  solve();   
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    long long n,a[1000005];
    cin>>n;
    a[0]=7%n;
    for(int i=1;i<=n;i++){
        a[i]=(a[i-1]*10+7)%n;
    }
    for(int i=0;i<=n;i++){
        if(a[i]==0){
            cout<<i+1<<endl;
            return(0);
        }
    }
    cout<<"-1"<<endl;
    return(0);
}

Measured memory_bytes: 11348
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;

int main(){
	cin >> n;
	ll g = 0;
	ll ans = 0;
	rep(i,n){
		ll a,b;
		cin >> a >> b;
		if(a > g){
			g = a;
			ans = a + b;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long K = sc.nextLong();
		long ans = N;
		if(N > K){
			N = N - (K * (N / K));
		}
		for(int i = 0;i < 2;i++){
			N = Math.abs(N - K);
			if(N < ans){
				ans = N;
			}
		}
		System.out.println(ans);
	}
}

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  const int MAXN = 1e6;
  vector<int> cnt(MAXN + 1);
  for (int& p : a)
    ++cnt[p];
  vector<bool> vis(MAXN + 1);
  // n log n
  for (int i = 1; i <= MAXN; i++) {
    if (cnt[i] && !vis[i]) {
      for (int j = 2 * i; j <= MAXN; j += i)
        vis[j] = true;
    }
  } 
  int res = 0;
  for (int& p : a)
    res += (!vis[p] && cnt[p] == 1);
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 8208
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll deg[105];
void solve(){
	ll n;
	cin>>n;
	vector<vector<ll>> v;
	vector<p2> res;
	if(n&1){
		v.push_back(vector<ll>());
		v.back().push_back(n);
		n--;
	}
	for(ll i=1;i<=n/2;i++){
		v.push_back(vector<ll>());
		v.back().push_back(i);
		v.back().push_back(n-i+1);
	}
	for(ll i=0;i<sz(v);i++)
		for(ll j=i+1;j<sz(v);j++)
			if(i!=j)
				for(ll k=0;k<sz(v[i]);k++)
					for(ll t=0;t<sz(v[j]);t++)
						res.push_back({v[i][k],v[j][t]});
	cout<<sz(res)<<"\n";
	for(ll i=0;i<sz(res);i++)
		cout<<res[i].first<<" "<<res[i].second<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
        solve();
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 3836
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int a[3000];
ll dp[3000][3000];

int main(){
	int n;cin>>n;
	vector<P>v;
	rep(i,n){
		scanf("%d",&a[i]);
		v.push_back(P(a[i],i));
	}
	sort(v.begin(),v.end(),greater<>());
	memset(dp,-1,sizeof(dp));
	dp[0][0]=0;
	rep(i,n)rep(j,i+1){
		if(dp[i][j]==-1)continue;
		dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+v[i].first*(ll)abs(v[i].second-j));
		dp[i+1][j]=max(dp[i+1][j],dp[i][j]+v[i].first*(ll)abs(v[i].second-(n-(i-j)-1)));
	}
	cout<<*max_element(dp[n],dp[n]+n+1)<<endl;
}

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

using namespace std;

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

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

    int n, q;
    cin >> n >> q;
    queue<pair<string, int>> Q;
    REP(i, n) {
        string name;
        int time;
        cin >> name >> time;
        Q.emplace(name, time);
    }

    int k = 0;
    while (!Q.empty()) {
        auto p = Q.front();
        Q.pop();
        k += min(p.second, q);
        p.second -= min(p.second, q);
        if (p.second == 0) {
            cout << p.first << " " << k << endl;
        } else {
            Q.push(p);
        }
    }
}

Measured memory_bytes: 6352
b = input()
B = b[::-1]
n = len(b)
dp = [0]*n
cl = ["R","L"]
c = 0
def cal(q):
    return q//2 , q//2 + q%2

def cal2(a,p):
    c=0
    for i ,(j,k) in enumerate(zip(a,a[1:])):
        if j == cl[p]:
            c +=1
        if k == cl[(p+1)%2]:
            if p == 0:
                # print(c)
                e,f = cal(c)
                # print(e,f)
                dp[i] +=  f
                dp[i+1] += e
            else:
                # print(c)
                e,f = cal(c)
                # print(e,f)
                dp[~i] +=  f
                dp[~(i+1)] += e 
            c=0
cal2(b,0)
# print(dp)

cal2(B,1)

print(*dp)



Measured memory_bytes: 6528
import java.awt.geom.Point2D;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class Main {	
	Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){		
		new AOJ0117();
	}
	
	class AOJ0117{
		int cost[][]; //コスト
		int d[];//頂点sからの最短距離
		boolean used[];//素手に使用されたかのフラグ
		int V;//頂点数
		int INF;
		
		void dijkstra(int s){
			//list = new int[V];前の頂点を保存したいとき
			d = new int[V+1];
			used = new boolean[V+1];
			Arrays.fill(d,INF);
			Arrays.fill(used, false);
			d[s] = 0;
			while(true){
				int v=-1;
				for(int u=0;u<=V;u++){//まだ使われていない頂点のうち最小のものを探す
					if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
				}
				if(v==-1)break;
				used[v]=true;
				for(int u=0;u<=V;u++){
					d[u] = Math.min(d[u],d[v]+cost[v][u]);
//					if(d[u]>d[v]+cost[v][u]){   前の頂点を保存したい時は更新された時に
//						d[u]=d[v]+cost[v][u];
//						list[u] = v;
//					}
				}
			}
		}
		
		
		public AOJ0117() {
			INF = Integer.MAX_VALUE/2;
			V = in.nextInt();
			int m = in.nextInt();
			cost = new int[V+1][V+1];//[from][to]
			for(int i=0;i<=V;i++)Arrays.fill(cost[i],Integer.MAX_VALUE/2);
			for(int i=0;i<m;i++){
				String input[] = in.next().split(",");
				cost[Integer.parseInt(input[0])][Integer.parseInt(input[1])] = Integer.parseInt(input[2]);
				cost[Integer.parseInt(input[1])][Integer.parseInt(input[0])] = Integer.parseInt(input[3]);
			}
			String input[] = in.next().split(",");
			int start = Integer.parseInt(input[0]),goal = Integer.parseInt(input[1]);
			int money = Integer.parseInt(input[2]),hasira = Integer.parseInt(input[3]);
			dijkstra(start);
			int result = d[goal];
			dijkstra(goal);
			result += d[start];
			System.out.println(money-(result+hasira));
		}
	}
	

	class AOJ2503{
		int MAX = 0;
		public AOJ2503() {
			Scanner in = new Scanner(System.in);
			int n = in.nextInt();
			int m = in.nextInt();

			int[][] cost = new int[n][n];

			int[] dp = new int[n];
			for(int i=0;i<n*n;i++){
				cost[i/n][i%n]=MAX;
			}
			for(int i=0;i<m;i++){
				int a = in.nextInt();
				int b = in.nextInt();
				cost[a][b]=in.nextInt();
			}	
			//			TODO 一番大きいパスを0のポイントからn-1のポイントまでの

			for(int s=1;s<n;s++){
				for(int i=0;i<=s;i++){
					if(cost[i][s]==MAX)continue;
					dp[s]=Math.max(dp[s],dp[i]+cost[i][s]);
				}
			}
			for(int s=0;s<n;s++)for(int i=0;i<n;i++){
				if(cost[s][i]==MAX)continue;
				dp[i]=Math.max(dp[s]+cost[s][i],dp[i]);
			}
			for(int i=0;i<n;i++)System.out.print(dp[i]+" ");
			System.out.println();
			System.out.println(dp[n-1]);
		}
	}
}

Measured memory_bytes: 17348
#include<stdio.h>
#define INF 1000000000

int matrixChainOrder(int *,int);
int min(int,int);
int p[101];
int m[101][101];
int main(){
  int n,i,cos,b;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }
  cos=matrixChainOrder(p,n);
  printf("%d\n",cos);
  return 0;
}
int matrixChainOrder(int *p,int n){
  int i,j,l,k,q;
  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){

      j=i+l-1;
      m[i][j]=INF;
      for(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]);
      }
    }
  }
  return m[1][j];
}
int min(int m,int q){
  if(m>=q){
    return q;
  }
  else if(m<=q)return m;
}

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

int main() {
    int k, x;
    cin >> k >> x;
    cout << (k * 500 >= x ? "Yes\n" : "No\n");
}

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

int main(){
	int A,i,j,s=0;
	cin >> A;
	vector<int> tako(A);
	for ( i = 0; i < A; i++ ) {
		cin >> tako.at(i);
	}

    for(i=0;i<A;i++){
	    for(j=i+1;j<A;j++) s+=tako.at(i)*tako.at(j);
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (int)(n); i++)
const ld pi=3.14159265358979323846;
 
int main() {
    string s;
    cin>>s;
    if (s=="ABC"){
        cout<<"ARC"<<endl;
    }
    else{
        cout<<"ABC"<<endl;
    }
}

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

typedef long long ll;

int main() {
	int n, m;
	while(cin >> m >> n, n || m) {
		vector<int> v;
		v.resize(n);
		for(int i = 0; i < n; i++)
			cin >> v[i];

		ll l, r, res;
		l = 0; r = 1600000;
		res = -1;
		while(l <= r) {
			int mid = (l + r) / 2;
			int d = 0;
			int cnt = 0;
			for(int i = 0; i < v.size(); i++) {
				if(d + v[i] > mid) {
					if(d == 0) {
						cnt = 1e9;
						break;
					}
					d = 0;
					i--;
					cnt++;
				}
				else
					d += v[i];
			}

			if(cnt < m) {
				res = mid;
				r = mid-1;
			}
			else {
				l = mid+1;
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1196
from numpy import sign

n = int(input())
a = list(map(int,input().split()))
b = [sign(a[i+1]-a[i]) for i in range(n-1)]

c = 1
f = 0
for t in b:
  if f == 0:
    f = t
  elif f*t == -1:
    c += 1
    f = 0
print(c) 

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

int main(){
  int N,M,a,b;
  int count[60] = {0};
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    cin >> a >> b;
    for(int j = 1; j <= N; j++){
      if((a==j) || (b==j)) count[j]++;
    }
  }
  for(int i = 1; i <= N; i++) printf("%d\n",count[i]);
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/timeb.h>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll LINF = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;

int main(){
	int n,ans=0;
	cin >> n;
	vector<int> a(n);
	REP(i,n)cin >> a[i];
	
	REP(i,n-2){
		int maxi=max(a[i],max(a[i+1],a[i+2]));
		int miny=min(a[i],min(a[i+1],a[i+2]));
		if(a[i+1]!=maxi && a[i+1]!=miny)
			ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int int_vector_find(std::vector<int> vec, int num) {
	auto itr = std::find(vec.begin(), vec.end(), num);
	int index = std::distance(vec.begin(), itr);

	if (index != vec.size()) {
		return 1;
	}
	else {
		return 0;
	}
}

int main() {
	LL ans = 0;
	int n;
	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		int a;
		std::cin >> a;
		ans += a;
	}

	std::cout << ans - n << std::endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 764
import bisect
N = int(input())
L = [int(i) for i in input().split()]

SL = sorted(L)
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        right = bisect.bisect_left(SL, SL[i] + SL[j])
        left = j + 1
        ans += right - left

print(ans)


Measured memory_bytes: 3188
n ,k = [int(x) for x in input().split()]
dg = [0]*(n+1)
while(k):
    di = int(input())
    a = [int(x) for x in input().split()]
    for i in a:
        dg[i]+=1
    k-=1

cnt = -1
for i in dg:
    cnt+=(i==0)
print(cnt)


Measured memory_bytes: 9176
import scala.io.StdIn._
object Main extends App {
  val n = readInt()
  println((1 until 100000).find(i ⇒ i * (i + 1) / 2 >= n).map(makePair(_, n)).get)
  def makePair(length: Int, n: Int): String = {
    val rest = (length + 1) * length / 2 - n
    if (rest == 0) ")" * length + "(" * length
    else ")" * (length - rest) + "(" + ")" * rest + "(" * (length - 1)
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<int64_t> x(n + 1);
  for (int i = 1; i <= n; i++) cin >> x[i];

  int64_t ans = 1000000000;
  for (int64_t p = -90; p <= n + 90; p++) {
    int64_t sum = 0;
    for (int i = 1; i <= n; i++) {
      sum += pow(p - x[i], 2);
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
void bottomupdp(int a[][3],int n,int dp[][3])
{
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<=n;i++)
	{
		dp[i][0] = a[i][0] + max(dp[i	-1][1], dp[i-1][2]);
        dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = a[i][2] + max(dp[i-1][0], dp[i-1][1]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}
int main()
{
	int i,j;
	int n;
	cin>>n;
	int a[n][3];
	int dp[n+2][3];
	memset(dp,0,sizeof(dp));
	for(i=0;i<n;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	}
	bottomupdp(a,n,dp);
}

Measured memory_bytes: 5920
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,k,i,j,mp[105][105],x,y,z;
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m>>k;
	x=1;y=1;
	for (i=1;i<=k;i++)
	{
		cin>>z;
		while (z--)
		{
			mp[x][y]=i;
			if (x&1)
			{
				if (y<m) y++;
				else x++;
			}
			else
			{
				if (y>1) y--;
				else x++;
			}
		}
	}
	for (i=1;i<=n;i++)
	{
		for (j=1;j<m;j++)
		{
			cout<<mp[i][j]<<' ';
		}
		cout<<mp[i][m]<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
N, L = map(int, input().split())
apple = [L+i for i in range(N)]

pos = [10000]
neg = [10000]
for a in apple:
    if a>=0:
        pos.append(a)
    else:
        neg.append(-a)
        
pos.sort()
neg.sort()

m = pos[0] if pos[0]<=neg[0] else -neg[0]

print(sum(apple) - m)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n = 0, ans = 1;
	string s; cin >> s;
	for (int h = 0; h < s.size(); h++) {
		if (s[h] == 'd'&&s[h + 1] == 'r'&&s[h + 2] == 'e'&&s[h + 3] == 'a'&&s[h + 4] == 'm') {
			if (s[h + 5] == 'e'&&s[h + 6] == 'r'&&s[h + 7] != 'a') { h += 6; }
			else { h += 4; }
		}
		else if (s[h] == 'e'&&s[h + 1] == 'r'&&s[h + 2] == 'a'&&s[h + 3] == 's'&&s[h + 4] == 'e') {
			if (s[h + 5] == 'r') { h += 5; }
			else { h += 4; }
		}
		else {
			cout << "NO" << endl; cin >> n; return 0;
		}
	}
	cout << "YES" << endl;
	cin >> n;
}

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

#define asc(v) sort(v.begin(), v.end())
#define desc(v) sort(v.begin(), v.end(), greater<int>())
#define vi vector<int>
#define vvi vector<vi>

using namespace std;

typedef long long ll;

int main() {
  string s, t;
  cin >> s >> t;
  asc(s);
  asc(t);
  if (s.size() < t.size()) {
    bool flag = true;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] != t[i]) flag = false;
    }
    if (flag) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      if (s[i] < t[j]) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n,*a=$<.map &:to_i
a.sort!

def d(b)
  c=(0...b.size).map{|i|(b[i-1]-b[i]).abs}
  c.reduce(:+)-c.min
end

if n%2==0
  b=(0...n).map{|i|i%2==0 ? a[i/2] : a[n-i/2-1]}
  p d(b)
else
  b=(0...n).map{|i|i%2==0 ? a[i/2] : a[n-i/2-1]}
  c=(0...n).map{|i|i%2==1 ? a[i/2] : a[n-i/2-1]}
  p [d(b),d(c)].max
end


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

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

   int N;
   cin>>N;
   vector<int>t(N),x(N),y(N);
   for(int i=0;i<N;i++)cin>>t[i]>>x[i]>>y[i];

   int now[] = {0,0};
   int now_t = 0;
   for(int i=0;i<N;i++){
      int d = abs(now[0]-x[i]) + abs(now[1]-y[i]);
      int T = t[i] - now_t;
      if(d > T){
         cout<<"No"<<endl;
         return 0;
      }
      else if(d < T){
         if((T-d)%2){
            cout<<"No"<<endl;
            return 0;
         }
      }
      now_t = t[i];
      now[0] = x[i];
      now[1] = y[i];
   }
   cout<<"Yes"<<endl;
   return 0;
}


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

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

  string ans="";
  if (b <= a) {
    ans = "delicious";
  } else if (b <= a + x) {
    ans = "safe";
  } else {
    ans = "dangerous";
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;

int main(int argc, char* argv[]){

	int K;
	char S[105];

	scanf("%d", &K);
	scanf("%s", S);

	string S_str = S;
	if(int(S_str.size()) <= K){
		printf("%s", S);
	}else{
		string S_cut;
		for(int i=0; i<K; i++){
			S_cut.push_back(S[i]);
		}
		S_cut+="...";
		printf("%s\n", S_cut.c_str());
	}


	return 0;
}







Measured memory_bytes: 3784
#include <iostream>
#include <vector>
#define int long long int
using namespace std;

const int maxN = 1e6 + 10;

vector<int> primes;
bool isPrime[maxN];

void sieve(){
    for(int i = 0; i < maxN; i++) isPrime[i] = true;
    for(int i = 2; i < maxN; i++){
        if(isPrime[i]) primes.push_back(i);
        for(int j : primes){
            if(i * j >= maxN) break;
            isPrime[i * j] = false;
            if(!(i % j)) break;
        }
    }
}

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

int A, B;

signed main(){
    sieve();
    cin >> A >> B;
    int g = gcd(A, B), cnt = 1;
    for(int p : primes){
        if(p * p > g) break;
        if(!(g % p)){
            cnt++;
            while(!(g % p)) g /= p;
        }
    }
    cnt += (g > 1);
    cout << cnt << endl;
}


Measured memory_bytes: 2424
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

void solve(){
	int n; cin>>n;
	int sum = 0;
	int val;
	for(int i=0; i<n; i++){
		cin>>val;
		sum+=val;
	}
	cout<<sum-n;
}

int main(){
	fast;
	solve();
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
k = int(input())

count = 0

while True:
  if b > a:
    break
  else:
    b *= 2
    count += 1

while True:
  if c > b:
    break
  else:
    c *= 2
    count += 1

if k >= count:
  print("Yes")
else:
  print("No")

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

int main()
{
    int n, x = 0, mx = 0;
    string s;
    cin >> n >> s;
    rep(i, n) {
        if (s[i] == 'I') {
            x++;
            mx = max(mx, x);
        }
        else 
            x--;
    }
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
int main()
{
    int A,B,a,ans;
    scanf("%d%d",&A,&B);
    a=1;
    ans=0;
    while(a<B)
    {
        ans++;
        a--;
        a+=A;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
s=input()
a=[]
b=[]
now=True
q=int(input())
for i in range(q):
    x=list(input().split())
    if x[0]=="1":
        now=not now
    else:
        if now and x[1]=="2" or not now and x[1]=="1":
            b.append(x[2])
        else:
            a.append(x[2])
if now:
    ans=a[::-1]+list(s)+b
else:
    ans=b[::-1]+list(s[::-1])+a
print(*ans,sep="")

Measured memory_bytes: 13412
#include <stdio.h>
#include <math.h>
#include <string.h>

int gcd(int a,int b){
    if(a<b){
        int now=a;
        a=b;
        b=a;
    }

    int r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }

    return b;
}




int main(void){
  int n;
  scanf("%d",&n);
  int g=0;
  int f=1000;
  int i;
  for(i=0;i<n;i++){
      int a;
      scanf("%d",&a);
      if(a<f){
          f=a;
      }
      if(g<a){
          g=a;
      }
  }

  printf("%d\n",g-f);

  return 0;
}

Measured memory_bytes: 1712
n = int(input())
flag = 0
l = []
for i in range(n):
    w = input()
    # print(w)
    if i != 0:
        if (w[0] != before[-1]) or (w in l):
            flag = 1

    l.append(w)
    before = w
    # print(flag, l)


if flag == 1:
    print("No")
else:
    print("Yes")



Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPE(i,a,n) for(int i=a;i<=n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}

int atcoder(){
    ll n,y;
    cin >> n >> y;
    ll ans[3]={-1,-1,-1};
    REPE(i,0,n){
        REPE(j,0,n-i){
            if(10000*i+5000*j+1000*(n-i-j)==y){
                ans[0]=i;
                ans[1]=j;
                ans[2]=n-i-j;
            }
        }
    }
    REP(i,0,3) cout << ans[i] << " ";
    
    return 0;
}

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


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, d; cin >> n >> d;

    int t = d + d + 1;

    cout << (n + (t - 1)) / t << endl;
}

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

using namespace std;

const int MAXN = 1e5 + 5;
int n;
int dp[MAXN];
int h[MAXN];

int main()
{
    cin >> n;
    if(n == 1){
        cout << 0; return 0;
    }
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; i++){
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
    }
    cout << dp[n - 1];
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

vector<ll> k(500001);//kの階乗
vector<ll> f(500001);//kの逆元

ll mod_pow(ll x, ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x*x % mod, n / 2);
	if (n & 1) res = res * x % mod;
	return res;
}

void comb_init(void) {
	ll cur = 1;
	k[0] = f[0] = 1;
	FOR(i, 1, 500001) {
		cur = (cur * i) % mod;
		k[i] = cur;
		f[i] = mod_pow(cur, mod - 2);
	}
}

ll combination(ll n, ll s) {
	ll ret = (((k[n] * f[n - s]) % mod) * f[s]) % mod;
	return ret;
}

ll permutation(ll n, ll s) {
	ll ret = (k[n] * f[n - s]) % mod;
	return ret;
}


ll N, M;

int main() {


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

	comb_init();
	
	cin >> N >> M;
	ll ans = 0;
	FOR(i, 0, N+1) {
		ans = (ans+((mod_pow(-1, i)*permutation(M - i, N - i))%mod*combination(N, i))%mod+mod)%mod;
		
	}
	cout << (ans*permutation(M,N)+mod) % mod << endl;


	return 0;
}


Measured memory_bytes: 10964
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{ 
    cool;
    long long int n,m;
    cin>>n>>m;
    if(n==1&&m==1)
    cout<<"1";
    else if(n==1||m==1)
    cout<<(max(n,m)-2);
    else
    cout<<((n-2)*(m-2));
	return 0;
}

Measured memory_bytes: 256
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<long long> vll;

//define
#define i(X) cin>>X;
#define ol(X) cout<<X<<endl;
#define os(X) cout<<X<<" ";
#define inpv(a,n) vector<ll> a(n); for(ll i=0;i<n;i++){cin>>a[i];}
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define iniv(A,n,p) vector<ll> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(ll i=a;i<=b;i++)
#define forde(i,a,b) for(ll i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
long long MOD=(long long)(1e9+7);
ll mod=MOD;

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll vis[200001]={0};
vector<vector<ll> >adj(200001);
ll ans=0;
void bfs(ll s)
{
	ans++;
	vis[s]=1;
	forin(j,0,adj[s].size()-1)
	{
		if(!vis[adj[s][j]])
		{
			bfs(adj[s][j]);
		}
	}
}
int main() 
{
	// #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
	// 	// freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
	forin(i,0,200000) vis[i]=0;
	fio;
	ll testcase=1;
	//cin>>testcase;
	while(testcase--)
	{
		// string s,t;
		// cin>>s>>t;
		// ll len=0;
		// forde(j,t.length()-1,0)
		// {
		// 	if(s.find(t.substr(0,j))!=-1)
		// 	{
		// 		len=max(len,j);
		// 		//cout<<len<<" ";
		// 		break;
		// 	}
		// }
		// ll ans=t.length()-len;
		// cout<<ans<<endl;
		ll n,m;
		cin>>n>>m;
		forin(i,1,m)
		{
			ll u,v;
			cin>>u>>v;
			adj[u].pb(v);
			adj[v].pb(u);
		}
		ll bt=1;
		forin(i,1,n)
		{
			if(adj[i].size() && !vis[i])
			{
				ans=0;
				bfs(i);
				//cout<<ans<<" ";
				bt=max(bt,ans);
			}
		}
		ol(bt);
	}
}

Measured memory_bytes: 25108
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  int a, b, c, X, Y;
  int D, G;
  char s[101]={};
  char s_temp[101]={};
  char t[101]={};
  int len=0;
  int N, M;
  int A[20000]={};
  int B[20000]={};
  int C[20000]={};
  int i,j,k;
  int flag=0;
  int tmp=0;
  int min=101;
  int cnt=0;
  int max=0;
  int ans=0;

//  long cnt =0;
  long long A_temp;
//    int k=0;

  scanf("%d %d", &a, &b);
//  printf("%d %d\n",D,G);

//  for(i=0;i<D;i++){
//    scanf("%d %d", &A[i], &B[i]);
//    printf("%d %d", A[i], B[i]);
//  }
    printf("%d\n", (a-1)*(b-1));
  
  
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int a[5];
int main()
{
    int n;
    cin >> n;
    char x;
    for(int i=1; i<=n; i++)
    {
        cin >> x;
        if(x == 'G')a[1]++;
        if(x == 'W')a[2]++;
        if(x == 'P')a[3]++;
        if(x == 'Y')a[4]++;
    }
    int cnt=0;
    if(a[1] >= 1)cnt ++;
    if(a[2] >= 1)cnt ++;
    if(a[3] >= 1)cnt ++;
    if(a[4] >= 1)cnt ++;
    if(cnt == 3)cout << "Three";
    else if(cnt == 4)cout << "Four";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pll pair<ll,ll>
#define vi vector < int >
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define s(x) scanf("%d",&x)
#define sll(x) scanf("%lld",&x)
#define pf(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define flash ios_base::sync_with_stdio(false);cin.tie(0)
#define goog(x) cout << "Case #" << x << ": "
#define MAX5 200005
#define MAX6 2000005
#define MLOG 18
#define limit 1e18
#define mod 1000000007   
void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int power(int x, int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}


void solve(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = k; i <= n+1; i++){
        int st = (((i-1)*(i))/2)%mod;
        int en = ((n*(n+1))/2 - ((n-i)*(n-i+1))/2)%mod;
        ans = (ans + en + 1)%mod;
        //debug(st, en, ans);
        ans = (ans - st + mod)%mod;
        //debug(st, en, ans);
    }
    cout << ans << endl;
}

signed main(){  
//  freopen("ii.txt", "w", stdin);
    // flash;
    int t = 1;
    // cin >> t;  
    for(int tc = 1; tc <= t; tc++){
    // goog(tc);
        solve();
    }
}

Measured memory_bytes: 3624