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

using namespace std;

static const int MAX = 1000000;
static const int NIL = -1;

int n;

struct Node{
  int location, p, l, r;
};

struct Point{
  int id,x,y;
  bool operator < (const Point &p) const {
    return id < p.id;
  }
};

Point P[MAX];
Node T[MAX];


bool lessX(const Point &p1, const Point &p2){ return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2){ return p1.y < p2.y; }

int treeIndex = 0;

int makeTree(int l, int r, int depth){
  if(l >= r) return NIL;
  int mid = (l + r) / 2;
  int index = treeIndex++;
  if(depth % 2 == 0){
    sort(P+l, P+r, lessX);
    T[index].location = mid;
  }else{
    sort(P+l, P+r, lessY);
    T[index].location = mid;
  }
  T[index].r = makeTree(mid+1, r, depth + 1);
  T[index].l = makeTree(l, mid, depth + 1);
  return index;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<int> &ans){
  int x = P[T[v].location].x, y = P[T[v].location].y;
  if(sx <= x && x <= tx && sy <= y && y <= ty){
    ans.push_back(P[T[v].location].id);
  }
  if(T[v].l != NIL){
    if(depth % 2 == 0){
      if(sx <= x) find(T[v].l, sx, tx, sy, ty, depth+1, ans);
    }else{
      if(sy <= y) find(T[v].l ,sx, tx, sy, ty, depth+1, ans);
    }
  }
  if(T[v].r != NIL){
    if(depth % 2 == 0){
      if(x <= tx) find(T[v].r, sx, tx, sy, ty, depth+1, ans);
    }else{
      if(y <= ty) find(T[v].r, sx, tx, sy, ty, depth+1, ans);
    }
  }
}

int main(){
  scanf("%d" ,&n);
  for(int i = 0; i < n; i++){
    scanf("%d %d", &P[i].x, &P[i].y);
    P[i].id = i;
  }
  int root = makeTree(0, n, 0);

  int q;
  scanf("%d", &q);
  int sx, tx, sy, ty;
  vector<int> ans;
  for(int i = 0; i < q; i++){
    scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
    ans.clear();
    find(root, sx, tx, sy, ty, 0, ans);
    sort(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); i++){
      printf("%d\n", ans[i]);
    }
    printf("\n");
  }
}

Measured memory_bytes: 16488
/**
 * C - Scc Puzzle
 * https://atcoder.jp/contests/abc055/tasks/arc069_a
 **/
#include<iostream>

#define ll long long

using namespace std;

int main() {
    ll N, M; cin >> N >> M;
    if(2*N>=M) {
        cout << M/2 << endl;
    } else {
        cout << N + (M-2*N)/4 << endl;
    }
    return 0;
}

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

left = [0]
right = [w]
down = [0]
up = [h]

for _ in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        left.append(x)
    elif a == 2:
        right.append(x)
    elif a == 3:
        down.append(y)
    elif a == 4:
        up.append(y)
        
if min(right) - max(left) <= 0 or min(up) - max(down) <= 0:
    print(0)
else:
    print((min(right) - max(left)) * (min(up) - max(down)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

int a[2020], b[2020];

int main() {
	int n,x;
	scanf("%d%d", &n, &x);
	long long res = 0;
	FOR(i,n) scanf("%d", &a[i]);
	FOR(i,n) b[i] = a[i];
	FOR(i,n) res += a[i];
	FOR(d,n) {
		long long cur = 1LL * x * d;
		FOR(i,n) b[i] = min(b[i], a[(i-d+n)%n]);
		FOR(i,n) cur += b[i];
		res = min(res, cur);
	}
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[10];
  int t;
}P;

int isFull(int);

int main(){
  P Q[LEN+1];
  int num,time,sum=0;
  int i,head=1,tail;

  scanf("%d%d",&num,&time);
  for(i=1; i<=num; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  
  tail = num + 1;

  while(head != tail){
    if(time < Q[head].t){
      sum+=time;
      strcpy(Q[tail].name,Q[head].name);
      Q[tail].t =Q[head].t -  time;
      head = isFull(head);
      tail = isFull(tail);
    }
    else if(time >= Q[head].t){
      sum+=Q[head].t;
      printf("%s %d\n",Q[head].name,sum);
      head = isFull(head);
    }
  }

  return 0;
}

int isFull(int x){
  if(x < LEN) return x+1;
  else return 1;
}

Measured memory_bytes: 2172
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long 
using namespace std;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	int g = 0;
	int k = 0;
	for(int i = 0;i < N;i++) {
		if(vec.at(i) % 2 == 0) {
			g++;
		}
		else {
			k++;
		}
	}
	if(k % 2 != 0) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin>>a.at(i);
    }
    bool check=false;
    int count = 0;
    int tmp = a.at(0);
    for(int i=0; i<n; i++){
        count++;
        if(tmp==2){
            check = true;
            break;
        }
        tmp=a.at(tmp-1);
    }
    if(check)cout<<count<<endl;
    else cout<<"-1"<<endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
vector<int> v(101);
int n,k,menor = inf;
int vis[100100][2];
bool dfs(int qnt,bool pl){
    if(vis[qnt][pl]!=-1){
        return vis[qnt][pl];
    }
    for(int i=0;i<n;i++){
        if(qnt - v[i] >= 0){
            if(qnt-v[i] < menor){
                return vis[qnt][pl] = pl;
            }
            bool x = dfs(qnt-v[i],!pl);
            if(x == pl){
                return vis[qnt][pl] = pl;
            }
        }
    }
    return vis[qnt][pl] = !pl;
}
int32_t main(){
    ms(vis,-1);
    fastio;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> v[i];
        menor = min(menor,v[i]);
    }
    string res[] = {"First\n","Second\n"};
    cout << res[dfs(k,0)] << endl;
} 

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

#define ll long long int
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>

int main() {

    int H, W;
    cin >> H >> W;

    vector<string> S;
    string tmp;
    for (int i = 0; i < H; i++) {
        cin >> tmp;
        S.push_back(tmp);
    }

    vvi MW(3000, vi(3000, 0));

    int itr;
    for (int i = 0; i < H; i++) {
        itr = 0;
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '#') {
                MW[i][itr] = j - itr;
                MW[i][j] = -(j - itr);
                itr = j + 1;
            }
            if (j == W - 1) {
                MW[i][itr] = W - itr;
            }
        }
    }


    for (int i = 0; i < H; i++) {
        for (int j = 1; j < W; j++) {
            MW[i][j] += MW[i][j-1];
        }
    }

    vvi MH(3000, vi(3000, 0));
    for (int j = 0; j < W; j++) {
        itr = 0;
        for (int i = 0; i < H; i++) {
            if (S[i][j] == '#') {
                MH[itr][j] = i - itr;
                MH[i][j] = -(i - itr);
                itr = i + 1;
            }
            if (i == H - 1) {
                MH[itr][j] = H - itr;
            }
        }
    }


    for (int j = 0; j < W; j++) {
        for (int i = 1; i < H; i++) {
            MH[i][j] += MH[i-1][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (MW[i][j] + MH[i][j] > ans) {
                ans = MW[i][j] + MH[i][j];
            }
        }
    }

    // int top, mx;
    // int ans = 0;
    // int mx_i;
    // for (int j = 0; j < W; j++) {
    //     top = 0;
    //     mx = 0;
    //     for (int i = 0; i < H; i++) {
    //         if (M[i][j] > 0) {
    //             if (M[i][j] > mx) {
    //                 mx = M[i][j];
    //                 mx_i = i;
    //             }
    //         }
    //         else {
    //             if (mx + i - top - 1 > ans) {
    //                 ans = mx + i - top - 1;
    //                 // cout << "i " << mx_i << "  j " << j << "  mx " << mx << "  ans " << ans << endl;
    //             }
    //             top = i + 1;
    //         }
    //         if (i == H - 1) {
    //             if (mx + H - top > ans) {
    //                 ans = mx + i - top;
    //                 // cout << "i " << mx_i << "  j " << j << "  mx " << mx << "  ans " << ans << endl;
    //             }
    //         }
    //     }
    // }

    // for (int i = 0; i < H; i++) {
    //     for (int j = 0; j < W; j++) {
    //         cout << M[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    cout << ans - 1 << endl;

    return 0;
}


Measured memory_bytes: 74880
import heapq as hq
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a.sort()
for i in range(n):
    a[i][1]*=-1
b=[]
hq.heapify(b)
k,ans,i=1,0,0
while k<=m:
    while i<n and a[i][0]<=k:
        hq.heappush(b,a[i][1])
        i+=1
    if b:
        ans-=hq.heappop(b)
    k+=1
print(ans)

Measured memory_bytes: 28524
S = str(input())

s_front = S[:len(S)//2]
s_rear = S[len(S)//2:]
if len(s_front) != len(s_rear):
    s_front = s_front + s_rear[0]
s_front = s_front[::-1]

count = 0
for i, j in zip(s_front, s_rear):
    if i != j:
        count += 1

print(count)



Measured memory_bytes: 38256
import numpy as np
from collections import Counter
n,m = map(int,input().split())
A = np.cumsum([0]+list(map(int,input().split())),dtype="int64")%m

C = Counter(A)
ans = 0
for c in C.values():
	c -= 1
	ans += c*(c+1)//2
print(ans)

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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define sz(c) int((c).size())
#define all(c) (c).begin(), (c).end()
#define pb push_back

#define INF int(1e9)
#define EPS 1e-9
#define MOD int(1e9 + 7)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, d;
	cin >> n >> d;
	d *= 2;
	d++;
	cout << (n + (d - 1)) / d << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
const ll mod=1e9+7;
#define loop(i,a,n) for(i=a;i<n;i++)
#define pool(i,n,a) for(i=n;i>=a;i--)
#define fastinout     ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

void myfun()
{
	ll n,i,ans=0,res=0;
	string s;
	cin>>s;
	s.push_back('S');
	for(i=0;i<4;i++)
	{
		if(s[i]=='R')
		ans++;
		else
		{
		if(res<ans)
		res=ans;
		ans=0;	
		}
	}
	cout<<res;
	
}


int main()
{
	 fastinout;
	ll t=1;
	//cin>>t;
	while(t--)
	myfun();
	return 0;
}

Measured memory_bytes: 3648
function Main(input) {
    var input = input.split(' ').map(n => parseInt(n, 10));
    A = input[0];
    B = input[1];
    C = input[2];
    if(A <= C && C <= B) {
        console.log('Yes');
    } else {
        console.log('No');
    }
    

    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
/************
* 	@Just Another Source code by: ankit.sangwan1999
*	@created on: 23 Apr 2020
*/

#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long

int DP[100005];
int fun(vector<int>&H, int ind){
	if(DP[ind] != -1){
		return DP[ind];
	}
	if(ind==0){
		return 0;
	}
	int pos1=INT_MAX, pos2 = INT_MAX;
	if(ind-1>=0){
		int val1 = abs(H[ind] - H[ind-1]);
		pos1 = val1 + fun(H,ind-1);
	}
	if(ind-2>=0){
		int val2 = abs(H[ind] - H[ind-2]);
		pos2 = val2 + fun(H,ind-2);
	}

	return DP[ind] = min(pos1, pos2);
}

/* MEMO

signed main(){
    fastio;
    int t=1;
    // cin>>t;
    while(--t>=0){
    	int n;
    	cin>>n;
    	vector<int>H(n);
    	memset(DP,-1,sizeof(DP));
    	for(int i=0;i<n;i++) cin>>H[i];
    	cout<<fun(H,n-1);
    }

    return 0;
}

*/

/* BOTTOM-UP */

signed main(){
    fastio;
    int t=1;
    // cin>>t;
    while(--t>=0){
    	int n,k;
    	cin>>n>>k;
    	vector<int>H(n);
    	int dp[n];

    	for(int i=0;i<n;i++) cin>>H[i],dp[i] = INT_MAX;
    		
    	dp[0] = 0;
    	dp[1] = abs(H[1] - H[0]);

    	for(int i=2;i<n;i++){
            int val1;
            for(int j=1;j<=k;j++){
                if(i-j>=0){
                    val1 = abs(H[i] - H[i-j]);
                    dp[i] = min(dp[i], dp[i-j] + val1);
                }
            }
    	}
    	cout<<dp[n-1];
    }

    return 0;
}


Measured memory_bytes: 1024
// C++ program to demonstrate default behaviour of 
// sort() in STL. 
#include <bits/stdc++.h> 
using namespace std;
long long int prime(long long int n)  
{  

long long int t = 0,i;
    if(n%2 == 0) t++;
    while (n % 2 == 0)  
    {  
         
        n = n/2;  
    }  

    for ( i = 3; i <= sqrt(n); i = i + 2)  
    {  
	    if(n%i == 0) t++;
        while (n % i == 0)  
        {  
            //cout << i << " ";  
            n = n/i;  
        }  
    }  
    if (n > 2) t++;
    
    return t;
        
} 
  
int main() 
{ 

   long long int n,m;
   
   cin >> n >> m;
   
   n = __gcd(n,m);
   
   cout << prime(n)+1;
  // cout << s;
    return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
int main(void){
    int a,b,c,d,k;
    cin>>a>>b>>c>>d>>k;
    cout<<(c-a)*60+d-b-k<<endl;
}

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

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

    int m, f, r;
    while (cin >> m >> f >> r, (m != -1 || f != -1 || r != -1)) {
        string res;
        if (m == -1 || f == -1) res = "F";
        else if (m + f >= 80) res = "A";
        else if (m + f >= 65) res = "B";
        else if (m + f >= 50) res = "C";
        else if (m + f >= 30 && r >= 50) res = "C";
        else if (m + f >= 30) res = "D";
        else res = "F";

        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 3140
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    S = input()
    T = input()

    count = 0

    for i, s in enumerate(S):
        t = T[i]

        if s != t:
            count += 1
    return count


def main():
    print(solve())


if __name__ == "__main__":
    main()


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

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

  double r;
  cin >> r;

  double ans = 2 * M_PI * r;
  
  cout << fixed << setprecision(12);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3768
n, k = map(int, input().split())
L = [int(input()) for i in range(n)]

def check(P):
	global n, k, L
	i = 0
	for j in range(k):
		s = 0
		while s + L[i] <= P:
			s += L[i]
			i += 1
			if i == n:
				return n
	return i

def solve():
	left = 0
	right = 100000 * 10000

	while right - left > 1:
		mid = (left + right) // 2
		v = check(mid)
		if v >= n:
			right = mid
		else:
			left = mid

	return right

print(solve())



Measured memory_bytes: 9580
import sys
input = sys.stdin.readline

from operator import itemgetter
N, M = map(int, input().split())
A = [None] * N
B = [None] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
    
l = list(zip(A, B))
l.sort(key=itemgetter(0))
ans = 0
judge = 0
flag = False
for i in range(N):
    for j in range(l[i][1]):
        ans += l[i][0]
        judge += 1
        if judge == M:
            flag = True
            break
    if flag:
        break

print(ans)

Measured memory_bytes: 19692
fun main(args: Array<String>) {
    val a = readLine()!!.toInt()
    val b = readLine()!!.toInt()
    val c = readLine()!!.toInt()
    val x = readLine()!!.toInt()
    var num = 0
    for(i in 0..a) {
        for(j in 0..b) {
            for(k in 0..c) {
                if(x == i * 500 + j * 100 + k * 50) {
                    num = num + 1
                }
            }
        }
    }
    println(num)
}

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

int main(){
    int N; cin >> N;
    double ave = 0;
    vector<double> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        ave += A[i];
    }
    ave /= (double)N;
    vector<pair<double, int>> ans;
    for (int i = 0; i < N; i++) {
        ans.emplace_back(abs(A[i] - ave), i);
    }
    sort(ans.begin(), ans.end());
    cout << ans[0].second << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int K,N,a[200000],dist=0,tmp=0,tmp_maxi,maxi=0;

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

    int tmp = a[0];
    for(int i=0;i<N+1;i++){
        if(i<N){ 
            tmp_maxi = a[i] - tmp;
            tmp = a[i];
        }
        else{
            tmp_maxi = K - tmp + a[0];
        }

        if(tmp_maxi >= maxi) {
            maxi = tmp_maxi;
        }
    }
    cout << K - maxi << endl;
}

Measured memory_bytes: 1024
/*Writer : Md. Shafiur Rahman Dipu  */

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

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define pi 2*acos(0.00)
#define INF 2e18

long long poW(long long base, long long power) {
    long long result = 1;
    while(power > 0) {
        if(power & 1) {
            result = (result*base) ;
        }
        base = (base * base);
        power = power / 2;
    }
    return result;
}


#define ull unsigned long long
#define ll long long
#define ld long double

const int mx = 1005;
const int mod = 1000000007;

char grid[mx][mx];
ll val[mx][mx];

ll func(int h, int w)
{
    bool f = false;
    for(int j=0; j<=w; j++){
        if(grid[0][j]=='#'){f=true;}
        if(!f){val[0][j]=1;}
        else if(f){val[0][j]=0;}
    }
    f = false;
    for(int i=0; i<=h; i++){
        if(grid[i][0]=='#'){f=true;}
        if(!f){val[i][0]=1;}
        else if(f){val[i][0]=0;}
    }

    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            if(grid[i][j]!='#'){
                val[i][j] = (val[i-1][j] + val[i][j-1])%mod;
            }
        }
    }

    return val[h][w];
}



int main()
{
    #ifdef dipu
    //freopen("inp.txt","r",stdin);
    while(1){
    #endif
    int h,w;
    cin >> h >> w;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> grid[i][j];
        }
    }

    memset(val,0,sizeof val);
    ll res = func(h-1,w-1);

    cout << res << endl;

    #ifdef dipu
    }
    #endif // dipu

    return 0;
}


Measured memory_bytes: 9088
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


	public class Main {
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
	        
			int n = sc.nextInt();
			int m = sc.nextInt();
			int[] a = new int[m];
			int[] b = new int[m];
			int na = 0;
			int nb = 0;
			Set<Integer> c = new HashSet<Integer>();
			
			for(int i=0;i<m;i++) {
				a[i]=sc.nextInt();
				b[i]=sc.nextInt();
				if(a[i]==1) {
					c.add(b[i]);
					na++;
				}
				if(b[i]==n) {
					c.add(a[i]);
					nb++;
				}
			}
			
			if(na+nb==c.size()) {
				System.out.println("IMPOSSIBLE");
			}else {
				System.out.println("POSSIBLE");
			}
		}
		
	}


Measured memory_bytes: 111348
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

const int MOD = (int) 1e9 + 7;
const int NMAX = 3005;

int dp[2][NMAX][2];

int32_t main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    for (int i = 0; i <= n; ++i) {
        dp[0][i][i == 0] = 1;
    }
    for (int i = 0, u = 0; i < m; ++i, u ^= 1) {
        memset(dp[u ^ 1], 0, sizeof dp[u ^ 1]);
        for (int l = 0; l < 2; ++l) {
            for (int j = 1; j <= n; ++j) {
                dp[u ^ 1][j - 1][(l == 1) || (j - 1 == 0)] += dp[u][j][l];
                dp[u ^ 1][j - 1][(l == 1) || (j - 1 == 0)] %= MOD;
                dp[u ^ 1][j][(l == 1) || (j - 1 == 0)] += dp[u][j][l];
                dp[u ^ 1][j][(l == 1) || (j - 1 == 0)] %= MOD;
            }
            for (int j = 0; j < n; ++j) {
                dp[u ^ 1][j + 1][l] += dp[u][j][l];
                dp[u ^ 1][j + 1][l] %= MOD;
                dp[u ^ 1][j][l] += dp[u][j][l];
                dp[u ^ 1][j][l] %= MOD;
            }
        }
    }

    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans += dp[m & 1][i][1];
        ans %= MOD;
    }
    if (ans < 0) {
        ans += MOD;
    }
    cout << ans << '\n';
}


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

int calc(int n, const std::vector<int>& array) {
    int size = 1 << n;
    std::vector<int> table(size, INT_MAX);
    table[0] = 0;
    for (int status = 0; status < size - 1; status++) {
        for (int i = 0; i < n; i++) {
            int bit = 1 << i;
            if (status & (1 << i)) {
                continue;
            }
            int target = status | (1 << i);

            int min = array[i * (n + 1)];
            for (int j = 0; j < n; j++) {
                if (status & (1 << j)) {
                    int index = i * (n + 1) + j + 1;
                    min = std::min(min, array[index]);
                }
            }

            table[target] = std::min(table[target], table[status] + min);
        }
    }
    return table[size - 1];
}

int main() {
    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) {
            break;
        }
        std::vector<int> array(n * (n + 1));
        for (int i = 0; i < n * (n + 1); i++) {
            std::cin >> array[i];
        }
        std::cout << calc(n, array) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3260
#include<iostream>
using namespace std;
int main()
{
    long long a,b,x,temp;
    cin>>x;
    a=-64,b=-64;
    temp=a*a*a*a*a-b*b*b*b*b;
    while(temp!=x)
    {
        if(temp>x) b++;
        else a++;
        temp=a*a*a*a*a-b*b*b*b*b;
    }
    cout<<a<<" "<<b;
    return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

void* realloc_check(void* buffer, size_t size) {
	void* ret = realloc(buffer, size + (size == 0));
	if (ret == NULL) exit(1);
	return ret;
}

int cmp(const void* x, const void* y) {
	uint64_t a = *(const uint64_t*)x, b = *(const uint64_t*)y;
	if (a > b) return -1;
	return a < b;
}

uint64_t f(uint64_t b, uint64_t n) {
	uint64_t n2 = n, fv = 0;
	while (n2 > 0) {
		fv += n2 % b;
		n2 /= b;
	}
	return fv;
}

int main(void) {
	uint64_t n, s;
	uint64_t b;
	if (scanf("%" SCNu64 "%" SCNu64, &n, &s) != 2) return 1;
#if 0
	for (b = 2; b <= n + 1; b++) {
		uint64_t n2 = n, fv = 0;
		printf("%" PRIu64 " :", b);
		while (n2 > 0) {
			printf(" %" PRIu64, n2 % b);
			fv += n2 % b;
			n2 /= b;
		}
		printf(" -> %" PRIu64 "\n", fv);
	}
#else
	/* 3桁以上 */
	for (b = 2; b * b <= n; b++) {
		if (f(b, n) == s) {
			printf("%" PRIu64 "\n", b);
			return 0;
		}
	}
	/* 2桁 */
	if (n > s) {
		uint64_t nyan = n - s;
		uint64_t X;
		uint64_t* yakusu = NULL;
		int yakusuCount = 0;
		int i;
		for (X = 1; X * X <= nyan; X++) {
			if (nyan % X == 0) {
				uint64_t X2 = nyan / X;
				yakusu = realloc_check(yakusu, sizeof(*yakusu) * (yakusuCount + 1));
				yakusu[yakusuCount++] = X;
				if (X2 != X) {
					yakusu = realloc_check(yakusu, sizeof(*yakusu) * (yakusuCount + 1));
					yakusu[yakusuCount++] = X2;
				}
			}
		}
		qsort(yakusu, yakusuCount, sizeof(*yakusu), cmp); /* 約数を降順にソート */
		for (i = 0; i < yakusuCount; i++) {
			b = nyan / yakusu[i] + 1;
			if (f(b, n) == s) {
				printf("%" PRIu64 "\n", b);
				return 0;
			}
		}
	}
	/* 1桁 */
	if (n == s) {
		printf("%" PRIu64 "\n", n + 1);
		return 0;
	}
	/* なし */
	puts("-1");
#endif
	return 0;
}

/*
2桁のとき

n = X * b + Y
s = X + Y
0 <= X < b
0 <= Y < b

Y = s - X

n = X * b + s - X
(b - 1) * X = n - s

b = (n - s) / X + 1

bの最小値を求める -> Xをなるべく大きくする

Xは(n - s)の約数でなければならない -> 絞られる

*/


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

int main(){
  int N, A[22], B[22], C[21];
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  
  for(int i=0;i<N;i++){
    cin >> B[i];
  }
  
  for(int i=0;i<N-1;i++){
    cin >> C[i];
  }
  int sat = 0;
  for(int i=0;i<N;i++){
    int dish = A[i];
    sat += B[dish-1];
    if(i<N-1 && A[i+1] - A[i] == 1) sat += C[dish-1];
  }
  
  cout << sat << endl;
  
  return 0;
}

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

template<class T> inline bool chmin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

const long INF = 1L << 60;

int weight[110];
int value[110];
long dp[110000];

int main(){
	int n, w, sum = 0;
	scanf("%d%d", &n, &w);
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &weight[i], &value[i]);
		sum += value[i];
	}
	for(int i = 0; i <= sum; i++) dp[i] = INF;
	dp[0] = 0;
	for(int i = 0; i < n; i++)
		for(int j = sum-value[i]; j >= 0; j--)
			chmin(dp[j+value[i]], dp[j] + weight[i]);
	long ret = 0;
	for(int i=0; i <= sum; i++)
		if(dp[i] <= w) ret = max(ret, (long)i);
	printf("%ld", ret);
}


Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    while(q--) {
        ll x;
        cin >> x;
        ll ans = 0;
        int j = 0;
        ll sum = 0;
        rep(i, n) {
            while(sum <= x and j != n) {
                sum += a[j++];
            }
            ans += j-i-1;
            if(sum <= x) ans++;
            sum -= a[i];
            //cout << x << ' ' << i << ' ' << j << endl;
        }
        cout << ans << '\n';
    }
}


Measured memory_bytes: 3516
# include <bits/stdc++.h>
using namespace std;
# define F(i, s, t) for (int i = (s), _ = (t); i <= _; i ++)
# define LL long long
const int N = 2e5 + 5;
int n, a[N]; LL re, ans;
char nchar() {
	const int S = 1e7;
	static char s[S], *h = s+S, *t = h;
	if (h == t) fread(s, 1, S, stdin), h = s;
	return *h ++;
}
int rd() {
	int x = 0; char c;
	do { c = nchar(); } while (! isdigit(c));
	do { x = x*10+c-'0', c = nchar(); } while (isdigit(c));
	return x;
}
int main() {
	// freopen("C.in", "r", stdin);
	n = rd();
	F(i, 1, n)
		a[i] = rd();
	re = 1;
	for (int i = 1, j; i <= n; i = j+1) {
		for	(
			j = i;
			j < n && a[j] + 1 == a[j+1];
			j ++
		);
		if	(
			i == 1 && a[1]
			||
			i > 1 && a[i] > re
		)
			return puts("-1"), 0;
		ans += re-1;
		re = a[j] + 1;
	}
	ans += re-1;
	printf("%lld\n", ans);
	return 0;
}

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

int main()
{
    int r, c, **a;

    cin >> r >> c;

    a = new int*[r + 1];
    for (int i = 0; i < r + 1; i++) {
        a[i] = new int[c + 1];
        for (int j = 0; j < c + 1; j++) {
            if (i == r || j == c)
                a[i][j] = 0;
            else
                cin >> a[i][j];
        }
    }

    for (int i = 0; i < r + 1; i++) {
        for (int j = 0; j < c + 1; j++) {
            if (i != r)
                a[r][j] += a[i][j];
            if (j != c && i != r)
                a[i][c] += a[i][j];

            if (j == c)
                cout << a[i][j] << endl;
            else
                cout << a[i][j] << ' ';
        }
    }

    for (int i = 0; i < r + 1; i++)
        delete[] a[i];
    delete a;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
const ll mod = 1000000007;
vector<ll> inv, FactorialInv, Factorial;
ll beki(ll a, ll b){
    ll ret = 1 % mod;
    a %= mod;
    while(b) {
        if(b & 1LL) ret = ret * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ret;
}
void init_combination(ll MAX){
    Factorial.resize(MAX + 1);
    FactorialInv.resize(MAX + 1);
    inv.resize(MAX + 1);
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    if(b < 0) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    init_combination(3000000);
    ll K;
    string S;
    cin >> K >> S;
    K += S.size();
    ll ans = 0;
    for(int i = S.size(); i <= K; i++) {
        ll tmp = combination(i - 1, S.size() - 1);
        tmp *= beki(25, i - S.size());
        tmp %= mod;
        tmp *= beki(26, K - i);
        tmp %= mod;
        ans += tmp;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


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

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

    if (n == 2) {
        cout << 0 << endl;
        return 0;
    }

    long long t = 0;
    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            if (n / (i - 1) == n % (i - 1)) {
                t += i;
            }
            if (i * i != n) {
                if (n / (n / i - 1) == n % (n / i - 1)) {
                    t += n / i - 1;
                }
            }
        }
    }
    cout << t + n - 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    vector<int> a1_sum(n+1, 0);
    vector<int> a2_sum(n+1, 0);
    rep(i, n) {
        int a;
        cin >> a;
        a1_sum[i+1] = a1_sum[i] + a; 
    }
    rep(i, n) {
        int a;
        cin >> a;
        a2_sum[i+1] = a2_sum[i] + a;
    }
    int ans = 0;
    for ( int i = 1; i <= n; ++i ) {
        ans = max(ans, a1_sum[i] - a1_sum[0] + a2_sum[n] - a2_sum[i-1]); 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.text.*;

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        for(;;) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if(h == 0 && w == 0) break;
            String s = "";
            String t = "";
            for(int i = 0; i < w; i++) {
                s += "#";
                t += (i == 0 || i == (w-1)) ? "#" : ".";
            }
            for(int i = 0; i < h; i++) {
                System.out.println((i == 0 || i == (h-1)) ? s : t);
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 21252
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;
int main() {
  int n, k; cin >> n >> k;
  int l = 1, r = 0;
  vec a(n); rep(i,n) {
    cin >> a[i];
    r = max(r, a[i]);
  }
  while (l != r) {
    int mid = (l+r)/2;
    ll c = 0;
    rep(i,n) {
      c += (a[i]-1)/mid;
    }
    if (c <= k) r = mid;
    else l = mid+1;
  }
  cout << l << endl;
}

Measured memory_bytes: 3968
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A[] = new long[N+1];
		long B[] = new long[N];
		for (int i=0;i<N+1;i++) {
			A[i] = sc.nextLong();
		}
		for (int i=0;i<N;i++) {
			B[i] = sc.nextLong();
		}
		long sum = 0;
		for (int i=0;i<N;i++) {
			if (A[i]<B[i]) {
				B[i]-=A[i];
				sum +=A[i];
				if (A[i+1]>B[i]) {
					sum +=B[i];
					A[i+1]-=B[i];
				} else {
					sum +=A[i+1];
					A[i+1]=0;
				}
			} else {
				sum +=B[i];
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 67724
#include <iostream>

using namespace std;

int main()
{
    int w,a,b;
    cin>>w>>a>>b;
    if(b<a)
    {
         b=b+a;
         a=b-a;
         b=b-a;
    }
    if(a+w>=b)
        cout<<0<<endl;
    else
        cout<<b-a-w<<endl;


}


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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  for (int i = 0; i < N - 2; i += 2) {
    string T = S.substr(0, N - 2 - i);
    int M = N - 2 - i;
    bool X = true;
    for (int j = 0; j < M / 2; j++) {
      if (T.at(j) != T.at(M / 2 + j)) X = false;
    }
    if (X) {
      cout << M << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
  int main(){
    int n,i;
    double xa,ya,ra,xb,yb,rb;
    scanf("%d",&n);
     for(i=0;i<n;i++){
       scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&ra,&xb,&yb,&rb);
	   double q=xa-xb;
	   double r=ya-yb;
	   double s=ra-rb;
       double dis=q*q+r*r;   
       dis = sqrt(dis);
       if(dis>ra+rb){
printf("%d\n",0);
continue;
}else if(dis<ra+rb && dis*dis>s*s){
printf("%d\n",1);
continue;
}else if(dis*dis<s*s){
	if(ra>rb){
printf("%d\n",2);
continue;
	}else{
		printf("%d\n",-2);
		continue;
	}
}
else{
	printf("%d\n",1);
	continue;
}
}
return 0;
}

Measured memory_bytes: 640
N, M, V, P = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)


ans = P
S = A[P-1]
for i in range(P, N):
    if A[i]+M < A[P-1]:
        continue
    if V <= P-1+N-i:
        if A[i]+M >= A[P-1]:
            ans += 1
    else:
        if S+M*(V-P+1-N+i) <= (A[i]+M)*(i-(P-1)):
            ans += 1
    S += A[i]
print(ans)


Measured memory_bytes: 62576
function block(c,d,x,y){
   var dx,dy;
   if(d==0){dy=[0,0,0,0,1,1,1,1];dx=[0,1,2,3,0,1,2,3];}
   if(d==1){dy=[0,1,2,3,0,1,2,3];dx=[0,0,0,0,1,1,1,1];}
   for(var i=0;i<8;i++){
      yx[(y-1)+dy[i]][(x-1)+dx[i]]=c;
   }
}

function bomb(y,x){
   var dy=[-1,0,0,1];
   var dx=[0,-1,1,0];
   for(var i=0;i<4;i++){
      var yy=y+dy[i];
      var xx=x+dx[i];
      if(yy<0 || yy>=H || xx<0 || xx>=W)continue;
      if(yx[yy][xx]==color){yx[yy][xx]="a";bomb(yy,xx);}
   }
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var WH=(Arr.shift()).split(" ").map(Number);
   var W=WH[0];
   var H=WH[1];
   if(W==0 && H==0)break;
   var xyS=(Arr.shift()).split(" ").map(Number);
   var xS=xyS[0]-1;
   var yS=xyS[1]-1;
   var xyE=(Arr.shift()).split(" ").map(Number);
   var xE=xyE[0]-1;
   var yE=xyE[1]-1;
   var n=(Arr.shift())-0;
   var yx=[];
   for(var i=0;i<H;i++){
      yx[i]=[];
      for(var j=0;j<W;j++){
          yx[i][j]=0;
      }
   }
   for(var i=0;i<n;i++){
      var cdxy=(Arr.shift()).split(" ").map(Number);
      block.apply(null,cdxy);
   }
   var color=yx[yS][xS];
   if(color==0){console.log("NG");continue;}
   if(yx[yS][xS]==color){yx[yS][xS]="a";bomb(yS,xS);}
   var result=(yx[yE][xE]=="a")?"OK":"NG";
   console.log(result);
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int ans = 1;
    rep(i, n) ans = min(ans * 2, ans + k);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	char bf;
	set<string> st;
	rep(i, n){
		string w;
		cin >> w;
		if(i != 0 && bf != w.front() || st.count(w) == 1){
			cout << "No" << endl;
			return 0;
		}
		bf = w.back();
		st.insert(w);
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize
    }
    let mut s = 0;
    for i in 1..n {
        s += i;
    }
    println!("{}", s);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352
//#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>

using namespace std;

#define SIZE 1000010

typedef long double ld;
typedef long long ll;

ll sum[SIZE] = {};
int a[SIZE], x[SIZE], p;

bool check(int n, const ll sum[], int p, ll x){
  ll l = 0, r = n; // [l,r)
  
  for(int i=0;i<n;i++){
    if(x - sum[i] > p) return false;
    if(sum[i] >= x) continue;
    
    ll d = x - sum[i];

    ll tl = 0, tr = 1e9;

    while(tl < tr){
      ll mid = (tr+tl+1)/2;
      if(p - mid*mid >= d) tl = mid;
      else tr = mid-1;
    }

    l = max(l, i - tl);
    r = min(r, i + tl + 1);
  }
  
  return l < r;
}

bool solve(){
  int n, m;
  
  scanf("%d%d", &n, &m);
  if(n == 0) return false;
  
  memset(sum, 0, sizeof(sum));
  
  for(int i=0;i<m-1;i++){
    scanf("%d%d", a+i, x+i);
    x[i]--;
  }
  scanf("%d", &p);

  for(int i=0;i<m-1;i++){
    for(int j=0;j*j<a[i];j++){
      if(x[i]-j >= 0) sum[x[i]-j] += a[i] - j*j;
      if(x[i]+j < n && j > 0) sum[x[i]+j] += a[i] - j*j;
    }
  }
  
  ll l=0, r=1e18;

  while(l<r){
    ll mid = (l+r+1)/2;
    
    if(check(n, sum, p, mid)){
      l = mid;
    }else{
      r = mid-1;
    }
  }

  printf("%lld\n", l);
  
  return true;
}



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




Measured memory_bytes: 11772
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  for(int i=0;i<3;i++){
    if(s.at(i)=='9'){
      s.at(i)='1';
    }else{
      s.at(i)='9';
    }
  }
  cout << s << endl;
}



Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define mo 1000000007
using namespace std;
long long n,m,i,j,k,cf[200005],now,a[200005],ans=1,sum,p1,p2;
char s[200005];
long long read(){
	char ch=getchar();
	long long xx=0;
	while(ch<'0'||ch>'9')
		ch=getchar();
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return xx;
}
void pus(long long xx,int flagg){
	if(xx>=10)
		pus(xx/10,0);
	putchar(xx%10+'0');
	if(flagg==1)
		putchar(' ');
	if(flagg==2)
		putchar('\n');
	return;
}
int main(){
	n=read();
	scanf("%s",s+1);
	for(i=1;i<=2*n;i++)
		if(s[i]=='W'&&(now&1)==0||s[i]=='B'&&(now&1)==1){
			a[i]=2;
			now^=1;
			p1++;
		}
		else{
			a[i]=1;
			now^=1;
			p2++;
		}
	for(i=1;i<=2*n;i++){
		if(a[i]==1)
			sum++;
		else{
			ans=ans*sum%mo;
			sum--;
		}
	}
	if(p1!=p2){
		cout<<0<<endl;
		return 0;
	}
	for(i=1;i<=n;i++)
		ans=ans*i%mo;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  int s=1,b=0,c;
  while(s!=2){
    if(a.at(s-1)==-1){
      cout << -1 << endl;
      return 0;
    }
    c=s-1;
    s=a.at(s-1);
    a.at(c)=-1;
    b++;
  }
  cout << b << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b;
  cin>>n>>a>>b;
  vector<int> mon(3,0);
  REP(i,n){
    int p;cin>>p;
    if(p<=a) mon[0]++;
    else if(p<=b) mon[1]++;
    else mon[2]++;
  }

  cout << min(mon[0],min(mon[1],mon[2])) << endl;
}

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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const ll INF = 1e18+3;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;


int main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    cout << H2 * 60 + M2 - H1 * 60 - M1 - K;
  
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

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

	int N; cin >> N;

	set<string> doll;
	for (int i = 0; i < N; i++) {
		string s; cin >> s;
		doll.insert(s);
	}
	cout << doll.size() << endl;


	return 0;
}


Measured memory_bytes: 19248
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

class BIT{//1-indexed
public:

  vector<ll> bit;
  BIT(){}
  BIT(int size){
    bit.resize(size,0);
  }

  ll sum(int i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&(-i);
    }
    return s;
  }

  void add(int i,ll x){//i!=0
    while(i<bit.size()){
      bit[i]+=x;
      i+=i&(-i);
    }
  }
};

int N;
vector<char> C;
vector<int> A;

ll dp[4040][2020];
const ll INF=1e15;

void chmin(ll &a,ll b){
    if(a>b) a=b;
}

int main(){
  cin>>N;
  C.resize(2*N);
  A.resize(2*N);
  for(int i=0;i<2*N;i++) cin>>C[i]>>A[i];

  vector<ll> black(N+1,0),white(N+1,0);
  for(int i=0;i<2*N;i++){
      if(C[i]=='W') white[A[i]]=i;
      else black[A[i]]=i;
  }

  BIT blt(2*N+1),wht(2*N+1);
  vector<ll> blef(2*N+1,0),wlef(2*N+1,0);
  for(int i=1;i<=N;i++){
      int p=blt.sum(black[i]+1);
      blef[i]=p;
      blt.add(black[i]+1,1);
  }
  for(int i=1;i<=N;i++){
      int p=wht.sum(white[i]+1);
      wlef[i]=p;
      wht.add(white[i]+1,1);
  }

  for(int i=0;i<=2*N;i++) for(int j=0;j<=N;j++) dp[i][j]=INF;
  dp[0][0]=0;
  for(int i=0;i<2*N;i++){
      BIT w(2*N+1);
      for(int j=1;j<=i-N+1;j++) w.add(white[j]+1,1);

      for(int j=min(N-1,i);j>=0;j--){
          int p=black[j+1];
          int lb=blef[j+1];
          int lw=w.sum(p+1);
          chmin(dp[i+1][j+1],dp[i][j]+p-(lb+lw));
          if(i-j+1>=1) w.add(white[i-j+1]+1,1);
      }

      BIT b(2*N+1);
      for(int j=1;j<=i-N+1;j++) b.add(black[j]+1,1);

      for(int j=max(0,i-N+1);j<=min(N,i);j++){
          int p=white[i-j+1];
          int lw=wlef[i-j+1];
          int lb=b.sum(p+1);
          chmin(dp[i+1][j],dp[i][j]+p-(lb+lw));
          if(j+1<=N) b.add(black[j+1]+1,1);
      }
  }

  cout<<dp[2*N][N]<<endl;


  return 0;
}


Measured memory_bytes: 64000
#include <iostream>

int main(){
  int N,T,ans=0;
  std::cin >> N >> T;
  for(int i = 0;i < N;i++){
   int tmp,tmp2;
    std::cin >> tmp >> tmp2;
    if(tmp2 <= T){
     if(ans > tmp || ans == 0){
      ans = tmp; 
     }
    }
  }
  if(!ans){
   std::cout << "TLE" ; 
  }else{
    std::cout << ans ;
  }
  
 return 0; 
}

Measured memory_bytes: 256