akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;
int f(){
    LL n;
    LL a, b;
    LL ans=0;
    LL dif=0;
    cin >> n;
    cin >> a;
    forn(i,n-1){
        cin >> b;
        dif = a - b;
        if(dif > 0)
            {
                ans += dif;
                a = b + dif;
            }
        else
            a = b;
    }
    cout << ans << endl;
    return 0;
}

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

Measured memory_bytes: 3656
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int n, k;
	cin >> n >> k;
	int one = 0;
	int ans = 0;
	rep(i, n) {
		cin >> one;
		if (one == 1) {
			one = i;
			break;
		}
	}
	if ((n - k) % (k - 1) != 0)ans = (n - k) / (k - 1) + 2;
	else ans = (n - k) / (k - 1) + 1;
	print(ans);
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>
#include <cstdio>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define RFOR(i,b,n) for(int i=b;i>=n;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))

using namespace std;

int f[10][1000][1000] = {	{ {0} },
						
							{ {1} },
							
							{ 
								{1, 2},
								{3, 4}
							},
							
							{	
								{1, 2, 6},
								{3, 5, 7},
								{4, 8, 9}
							},
							
							{	
								{1, 2, 6, 7},
								{3, 5, 8, 13},
								{4, 9, 12, 14},
								{10, 11, 15, 16}
							},
							
							{
								{1, 2, 6, 7, 15},
								{3, 5, 8, 14, 16},
								{4, 9, 13, 17, 22},
								{10, 12, 18, 21, 23},
								{11, 19, 20, 24, 25}
							},
							
							{
								{1, 2, 6, 7, 15, 16},
								{3, 5, 8, 14, 17, 26},
								{4, 9, 13, 18, 25, 27},
								{10, 12, 19, 24, 28, 33},
								{11, 20, 23, 29, 32, 34},
								{21, 22, 30, 31, 35, 36}
							},
						
							{
								{1, 2, 6, 7, 15, 16, 28},
								{3, 5, 8, 14, 17, 27, 29},
								{4, 9, 13, 18, 26, 30, 39},
								{10, 12, 19, 25, 31, 38, 40},
								{11, 20, 24, 32, 37, 41, 46},
								{21, 23, 33, 36, 42, 45, 47},
								{22, 34, 35, 43, 44, 48, 49}
							},
							
							{
								{1, 2, 6, 7, 15, 16, 28, 29},
								{3, 5, 8, 14, 17, 27, 30, 43},
								{4, 9, 13, 18, 26, 31, 42, 44},
								{10, 12, 19, 25, 32, 41, 45, 54},
								{11, 20, 24, 33, 40, 46, 53, 55},
								{21, 23, 34, 39, 47, 52, 56, 61},
								{22, 35, 38, 48, 51, 57, 60, 62},
								{36, 37, 49, 50, 58, 59, 63, 64}
							},
							
							{
								{1, 2, 6, 7, 15, 16, 28, 29, 45},
								{3, 5, 8, 14, 17, 27, 30, 44, 46},
								{4, 9, 13, 18, 26, 31, 43, 47, 60},
								{10, 12, 19, 25, 32, 42, 48, 59,61},
								{11, 20, 24, 33, 41, 49, 58, 62, 71},
								{21, 23, 34, 40, 50, 57, 63, 70, 72},
								{22, 35, 39, 51, 56, 64, 69, 73, 78},
								{36, 38, 52, 55, 65, 68, 74, 77,79},
								{37, 53, 54, 66, 67, 75, 76, 80, 81}
							},
							
						};

void solve(int n)
{
	FOR(j, 0, n)
		{
			FOR(i, 0, n)
			{
				printf("%3d", f[n][j][i]); 	
			}
			
			putchar('\n');
		}
		
	return;
}

int main()
{
	int n, c = 1;
	
	while(cin >> n, n)
	{
		cout << "Case " << c << ":" << endl;
		solve(n);
		c++;
	}
		
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

typedef double ld;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

int main(){ _

	int K,S;
	cin >> K >> S;

	ll ans = 0;

	for(int i = 0; i <= K; i++){
		for(int j = 0; j <= K; j++){
			int k = S - i - j;
			if(k >= 0 && k <= K) ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
int main(){
  int p,q,r,abc,acb,bac,m;
  scanf("%d",&p);
  scanf("%d",&q);
  scanf("%d",&r);
  abc = p+q;
  acb = r+q;
  bac = p+r;
  if(abc < acb) m = abc;
  else m = acb;
  if(bac < m) m = bac;
  printf("%d",m); 
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**9)

def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x, y = find(x), find(y)
    if x == y:
        return False
    
    if par[x] > par[y]:
        x,y = y,x
    par[x] += par[y]
    par[y] = x
    return True

def size(x):
    return -par[find(x)]

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

par = [-1]*n

for a, b in ab:
    unite(a, b)

nset=set()
for i in range(n):
    if not find(i) in nset:
        nset.add(find(i))
else:
    print(len(nset)-1)
    

Measured memory_bytes: 89884
#include <stdio.h>

int main()
{
    int input[3];
    int cnt = 0;

    scanf("%d %d %d",&input[0], &input[1], &input[2]);

    for (int i = input[0]; i <= input[1]; i++) {
        if ((input[2] % i) == 0) {
            cnt++;
        }
        else {
            /* NOP */
        }
    }

    printf("%d\n", cnt);

}


Measured memory_bytes: 2148
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	map<string, int>n;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		n[s]++;
	}
	cin >> M;
	for (int i = 0; i < M; i++) {
		string s;
		cin >> s;
		n[s]--;
	}
	int ans = 0;
	for (auto i : n) {
		ans = max(ans, i.second);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
S = list(input())
N = len(S)
s1 = S[:int((N-1)/2):]
s2 = S[int(((N+3)/2)-1):int(N):]
if S == S[::-1] :
    if s1 == s1[::-1] and s2 == s2[::-1] :
        print("Yes")
    else:
        print("No")
else:
    print("No")


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long N, std::vector<long long> A){
    vector<i64> cnt(N + 1);
    rep(i, N) cnt[A[i]]++;
    i64 sum = 0;
    rep(i, N + 1) sum += cnt[i] * (cnt[i] - 1) / 2;
    rep(i, N) cout << sum - cnt[A[i]] * (cnt[A[i]] - 1) / 2 + (cnt[A[i]] - 1) * (cnt[A[i]] - 2) / 2 << endl;
}

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

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 5760
import numpy as np

def add1(s, i = -1):
    if s[i] == 0:
        s[i] = 1
        return s
    else:
        s[i] = 0
        return add1(s, i-1)
    
n, m = map(int, input().split())

k = []
s = []

for i in range(0, m):
    ki, *si = map(int, input().split())
    k.append(ki)
    s.append(si)

p = list(map(int, input().split()))

sw = np.zeros(n)

ons = 0
ans = 0
sums = 0

for i in range(0, 2**n):
    for j in range(0, m):
        for l in s[j]:
            ons += sw[l-1]
        if ons % 2 == p[j]:
            sums += 1
        ons = 0
    if sums == m:
        ans += 1
    sums = 0
    if i != 2**n - 1:
        sw = add1(sw)


print(ans)


Measured memory_bytes: 21136
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long LL;

class LowerEnvelope{ typedef long long LL; int s, t; vector<LL> deq_a; vector<LL> deq_b; inline bool check(LL a1, LL b1, LL a2, LL b2, LL a3, LL b3) const { return (a2 - a1) * (b3 - b2) >= (b2 - b1) * (a3 - a2); } public: LowerEnvelope(int n) : s(0), t(0), deq_a(n), deq_b(n) {} void push(LL a, LL b){ while(s + 1 < t && check(deq_a[t - 2], deq_b[t - 2], deq_a[t - 1], deq_b[t - 1], a, b)) t--; deq_a[t] = a; deq_b[t++] = b; } LL minimum(LL x){ assert(s < t); while(s + 1 < t && deq_a[s] * x + deq_b[s] >= deq_a[s + 1] * x + deq_b[s + 1]) s++; return deq_a[s] * x + deq_b[s]; } }; 
LL INF = 10000000000000000LL;

int main(){
    LL N, M, D, X;
    cin >> N >> M >> D >> X;
    vector<LL> p(N);
    REP(i, N) cin >> p[i];
    vector<vector<LL>> right(D);
    for(int i = 0; i < M; i++){
        LL a, b;
        cin >> a >> b;
        LL x = a;
        LL y = abs(b);
        for(int d = 0; d < D; d++){
            right[d].push_back(x - y);
            x += X;
        }
    }
    REP(d, D) sort(right[d].begin(), right[d].end());
    auto w = [&](LL d, LL x) -> LL {
        auto itr = lower_bound(right[d].begin(), right[d].end(), x);
        return M - (itr - right[d].begin());
    };
    vector<LL> cur(N, INF);
    cur[0] = 0;
    for(LL d = 0; d < D; d++){
        vector<LL> next(N, INF);
        LowerEnvelope lowenv(N);
        for(LL i = 0; i < N; i++){
            if(cur[i] < INF){
                lowenv.push(w(d, p[i]), cur[i] - w(d, p[i]) * p[i]);
            }
            next[i] = lowenv.minimum(p[i]);
        }
        cur.swap(next);
    }
    cout << cur[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 12040
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

#N = int(input())
X, K, D = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]
#S = input()
#S = [input() for _ in range(N)]

X = abs(X)
n = X // D + 1

if n >= K:
    answer = abs(abs(X) - D * K)
else:
    answer = abs(abs(X) - D * n)
    K -= n
    
    if K % 2:
        answer = abs(answer - D)
        
print(answer)


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, P> PP;

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

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

int n;
ll a[100001],t;
ll ma[100001],dif;
int cnt;

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

	cin>>n>>t;
	REP(i,n) cin>>a[i];

	for(int i=n-1;i>=0;i--) ma[i]=max(ma[i+1],a[i]);

	REP(i,n-1) {
		if(a[i]+dif==ma[i+1]) cnt++;
		else if(a[i]+dif<ma[i+1]) {
			dif=ma[i+1]-a[i];
			cnt=1;
		}
	}

	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
const int maxn = 303, mod = 1e9 + 7;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	vector<ll> a(n), cur;
	for(auto &i : a) cin >> i;
	for(int i = 0; i < n; i++)
		for(ll c = 0, j = i; j < n; j++) {
			c += a[j];
			cur.pb(c);
		}
	ll ans = 0;
	for(int z = 60; z--;) {
		vector<ll> f[2];
		for(auto i : cur) f[(i>>z)&1].pb(i);
		if(f[1].size() >= k) cur = f[1], ans += 1ll<<z;
		//cout << f[0].size() << " " << f[1].size() << '\n';
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 15052
#include <iostream>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int cnt[1001][1001];

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

  int N, K;
  cin >> N >> K;
  rep(i, N) {
    int x, y, b;
    char c;
    cin >> x >> y >> c;
    if(c=='W')y += K;
    b = x / K % 2 == y / K % 2 ? 1 : -1;
    if(b > 0) cnt[0][0]++;
    int nx = x % K + 1, ny = y % K + 1;
    cnt[nx][0] -= b;
    cnt[0][ny] -= b;
    cnt[nx][ny] += b * 2;
  }
  rep(i, K + 1)rep(j, K)cnt[i][j + 1] += cnt[i][j];
  rep(j, K + 1)rep(i, K)cnt[i + 1][j] += cnt[i][j];
  int ans = 0;
  rep(i, K)rep(j, K)ans = max({ans, cnt[i][j], N - cnt[i][j]});
  cout << ans << endl;
}


Measured memory_bytes: 7520
#include <iostream>

#define MAXN 100000
typedef struct Values {
    int val;
    int comp;
} Values;

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    Values a[MAXN];
    int n;
    int q;
    std::cin >> n;
    std::cin >> q;

    for(int i = 0; i < n; ++i){
        a[i].val = 0;
        a[i].comp = i;
    }
    for(int i = 0; i < q; ++i){
        int op;
        std::cin >> op;
        if(op == 0){
            //relate                                                                                                                                                                                                                
            int id1;
            int id2;
            int v;
            std::cin >> id1 >> id2 >> v;
            int v1 = 0;
            int v2 = 0;
            int i = id1;
            int j = id2;
            while(a[i].comp != i){
                v1 += a[i].val;
                i = a[i].comp;
            }
            while(a[j].comp != j){
                v2 += a[j].val;
                j = a[j].comp;
            }
            a[j].comp = i;
            a[j].val = v1 - v2 - v;
            a[id1].comp = i;
            a[id1].val = v1;
            a[id2].comp = i;
            a[id2].val = v1 - v;

       } else {
            int id1;
            int id2;
            std::cin >> id1 >> id2;
            int v1 = 0;
            int v2 = 0;
            while(a[id1].comp != id1){
                v1 -= a[id1].val;
                id1 = a[id1].comp;
            }
            while(a[id2].comp != id2){
                v2 -= a[id2].val;
                id2 = a[id2].comp;
            }

            if(id1 != id2) std::cout << "?\n";
            else std::cout << v2 - v1 << "\n";
        }
    }
    return 0;
}



Measured memory_bytes: 3924
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll N,K,num=0;
    int h[100000];
    cin >> N >> K;

    REP(i,N){
        cin >> h[i];
        if(h[i]>=K){
            num++;
        }
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pl=pair<ll,ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vvi=vector<vi>;
using vvl=vector<vl>;
using vs=vector<string>;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

void solve() {
    // int N;
    string N;
    cin >> N;
    ll len = N.size();
    cout << N;
    if(N[len-1]=='s') {
        cout << "es" << '\n';
    }else{
        cout << "s" << '\n';
    }
}   

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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; }

int main() {
  ll N; cin>>N;
  ll a=0,b=0,ab=0,ba=0;
  for(int i=0;i<N;i++){
      string s;
      cin>>s;
      if(s[0]=='B'&&s[s.size()-1]=='A') ba++;
      else if(s[0]=='B') b++;
      else if(s[s.size()-1]=='A') a++;
      
      for(int j=0;j<s.size()-1;j++){
          if(s[j]=='A'&&s[j+1]=='B') ab++;
      }
  }
  if(ba==0) cout<<ab+min(a,b)<<endl;
  else if(a==0 && b==0) cout<<ab+ba-1<<endl;
  else if(a==0) cout<<ab+ba<<endl;
  else if(b==0) cout<<ab+ba<<endl;
  else cout<<ab+ba+1+min(a-1,b-1)<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <utility>

using namespace std;

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

#define INF 		2000000007
#define MOD			998244353
#define MAX 		100005

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

struct S{
	// メンバ
	string b;
	int c;
	int num;

	// コンストラクタ
	// 引数無し　宣言時に必要
	S(){
		b="",c=0;
	}
	// ソートに必要
	bool operator<(const S &another) const
	{
		if(b == another.b) return c > another.c;
		return b < another.b;
	};
	bool operator>(const S &another) const
	{
		if(b == another.b) return c < another.c;
		return b > another.b;
	};
};


int main(){
	int N;cin>>N;
	vector<S> vec(N);
	REP(i,N){
		cin>>vec[i].b>>vec[i].c;
		vec[i].num = i+1;
	}
	// 昇順
	sort(vec.begin(),vec.end());

	REP(i,N)cout << vec[i].num << endl;

	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define cpresent(c,x) ((c).find(x) != (c).end()) 
#define vpresent(c,x) (find(all(c),x) != (c).end())
#define endl '\n'
#ifdef LOCAL
#include "/home/iggaboi/Desktop/CP/debug.h"
#else
#define debug(Args...)
#endif
using ll = long long;
using namespace __gnu_pbds;
using namespace std;
template<class T>
using indexed_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

void shit() {
	ll n; cin >> n;
    cout << ((n - 1)*n)/2 << endl;
}

int32_t main() {
	ios_base::sync_with_stdio(false),cin.tie(nullptr);
	// int t; cin >> t;
	// while(t--)
		shit();
	return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
	int n, y;
	cin >> n >> y;

	int a = y/1000, b = 0, c = 0;
	while(a >= 5 and a+b > n and a+b-4 >= n){
		a -= 5;
		b += 1;
	}

	while(b >= 2 and a+b+c > n and a+b+c-1 >= n){
		b -= 2;	
		c += 1;
	}

	if(a+b+c == n){
		cout << c << " " << b << " " << a << endl;
	}else{
		cout << "-1 -1 -1" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;

    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine();
            var ans = 0m;

            // bit列で全探索を行う
            for (int x = 0; x < Math.Pow(2, input.Length - 1); x++)
            {
                var array = new bool[input.Length - 1];

                // 右からk桁目を取り出す
                for (int k = 0; k < input.Length - 1; k++)
                {
                    var y = (x >> k) & 1;
                    array[k] = y == 1;
                }
                var str = string.Empty;
                for (int i = 0; i < input.Length; i++)
                {
                    if (i == input.Length - 1)
                    {
                        str += input[i];
                    }
                    else
                    {
                        str += input[i] + "," + (array[i] == true ? "-" : "");
                    }
                }
                ans = str.Split(',').Select(p => long.Parse(p)).Sum();
                if (ans == 7)
                {
                    Output(str.Replace(",-", "-").Replace(",", "+") + "=7");
                    return;
                }
            }
        }
        private static void Output(string str)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            Console.WriteLine(str);

            Console.Out.Flush();
        }

    }

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

using namespace std;

typedef long long LL;
bool debug = false;

int N, v[101];
int poss[10000];

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	int tot = accumulate(v, v+N, 0);
	memset(poss, 0, sizeof(poss));
	poss[0] = 1;
	for (int i = 0; i < N; i++) {
		for (int s = tot; s >= 0; s--) {
			if (s-v[i] >= 0 && poss[s-v[i]]) {
				poss[s] = 1;
			}
		}
	}
	int m = 0;
	for (int s = 0; s <= tot; s++) {
		if (poss[s] && s%10 > 0) {
			m = max(m, s);
		}
	}
	cout << m << endl;
	exit(0);
}



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

int main(){
	int l_min;
	int p_max = 1-1000000000;
	int p_max_temp;
	int n;
	cin >> n;
	int temp;

	cin >> l_min;
	for(int i=2; i<=n; i++){
		cin >> temp;
		p_max_temp = temp - l_min;
		if(temp < l_min){
			l_min = temp;
		}
		if(p_max_temp > p_max){
			p_max = p_max_temp;
		}
	}

	cout << p_max << endl;

	return 0;
}

Measured memory_bytes: 1164
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int a;
    cin>>a;
    int x=a+(a*a)+(a*a*a);
    cout<<x<<endl;

    return 0;

}





































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

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

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

typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        
        int dp[10000];
        rep(i,10000)dp[i]=INF;
        dp[0]=0;
        
        for(int i=1;i<=n;i++){
            if(i-200>=0)
                dp[i] = min(dp[i],dp[i-200]+380);
            if(i-300>=0)
                dp[i] = min(dp[i],dp[i-300]+550);
            if(i-500>=0)
                dp[i] = min(dp[i],dp[i-500]+850);
            if(i-1000>=0)
                dp[i] = min(dp[i],dp[i-1000]+1520);
            if(i-1200>=0)
                dp[i] = min(dp[i],dp[i-1200]+1870);
            if(i-1500>=0)
                dp[i] = min(dp[i],dp[i-1500]+2244);
        }
        cout<<dp[n]<<endl;
    }
}

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

typedef long long ll;

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

int main() { 
    int N, L;
    string s;
    cin >> N >> L;
    vector<string> S(N);
    rep(i, N) {
        cin >> s;
        S.push_back(s);
    }
    stable_sort(S.begin(), S.end());
    for(string i: S) {
        cout << i ;
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3652
n = gets.chomp.to_i
x = gets.chomp.split(" ").map{|z| z.to_i}
y = gets.chomp.split(" ").map{|z| z.to_i}

d = []
for i in 1..n do
  d[i-1] = (x[i-1] - y[i-1]).abs
end

for p in 1..3 do
  printf("%f\n",(d.map{|z| z**p}.inject(:+))**(1.0/p))
end

printf("%f\n",d.max)


Measured memory_bytes: 6944
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	std::set<int> st; int n; cin >> n;
	for(int i = 0; i < n; i++){
		int a; cin >> a;
		
		if(st.count(a)) st.erase(a);
		else st.insert(a);
	}
	
	cout << st.size() << endl;
	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define inf 10000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

vint pos(5);
int k;
bool check=true;

int main(){
    int x;
    cin>>x;
    if(x==7 || x==5 || x==3)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll H, W;
  IN(H,W);
  ll N;
  IN(N);
  vll a(N);
  REP(i,N) IN(a[i]);
  ll pos = 0;
  vvll c(H, vll(W, 0));
  REP(i,H){
    if(i%2==0){
      REP(j,W){
        if(a[pos]>0){
          c[i][j]=pos+1;
          a[pos]--;
        }else{
          pos++;
          c[i][j] = pos+1;
          a[pos]--;
        }
      }
    }else{
      RREP(j,W-1){
        if(a[pos]<=0){
          pos++;
        }
        c[i][j]=pos+1;
        a[pos]--;
      }
    }
  }

  REP(i,H){
    REP(j,W){
      printf("%d ", c[i][j]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 512
<?php
	fscanf(STDIN, "%d %d %d", $N, $A, $B);

	if (($B - $A) % 2 === 0) {
      $ans = ($B - $A) / 2;
    } else {
      $x = min($A - 1, $N - $B);
      $ans = $x + 1 + ($B - $A - 1) / 2;
    }
	printf("%d", $ans);


Measured memory_bytes: 4604
N = int(input())
ans = [0] * 100000
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            ans[x*x+y*y+z*z+x*y+y*z+z*x-1] += 1
for i in range(N):
    print(ans[i])

Measured memory_bytes: 9772
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr ll mod = 1e9+7;
constexpr ll md = mod;
constexpr ll inf = 1e15;

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(auto & a : v) cin>>a;
    int count  = 0;
    for(int i=0;i<n-2;++i){
        if((v[i] < v[i+1] and v[i+1] < v[i+2]) or (v[i+2] < v[i+1] and v[i+1] < v[i]))count++;
    }
    cout << count << endl;
    return 0;
}



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

const int INF = 1e9;

bool compare(pair<int, int> p1, pair<int, int> p2) {
  return p1.second > p2.second;
}
int main() {
  int n, k;
  cin>>n>>k;
  vector<pair<int, int> > a(n);
  for (int i=0; i<n; i++) {
    int ti, di;
    cin>>ti>>di;
    a.push_back(make_pair(ti, di));
  }
  sort(a.begin(), a.end(), compare);

  long long ans = 0;
  set<int> types;
  priority_queue<int, vector<int>, greater<int> > p;
  for (int i=0; i<k; i++) {
    ans += a[i].second;
    if (types.find(a[i].first) != types.end()) {
      p.push(a[i].second);
    } else {
      types.insert(a[i].first);
    }
  }
  int size = types.size();

  int idx = k;
  long long ans_arr[k+1];
  for (int i=0; i<k+1; i++) {
    ans_arr[i] = 0;
  }
  ans_arr[size] = ans;
  while (size < k && idx < n && !p.empty()) {
    long long tmp_ans = ans_arr[size];
    int v = p.top();
    p.pop();
    while (idx < n) {
      if (types.find(a[idx].first) == types.end()) {
        types.insert(a[idx].first);
        ans_arr[size+1] = ans_arr[size] + a[idx].second -v;
        ++idx;
        ++size;
        break;
      }
      ++idx;
    }
  }

  long long max_ans =0;
  for (int i=0; i<k+1; i++) {
    if (ans_arr[i] != 0) {
      max_ans = max(max_ans, ans_arr[i] + (long long)i*i);
    }
  }
  cout<<max_ans<<endl;
}

Measured memory_bytes: 5616
def main():
    N = int(input())
    p = input().strip().replace(" ", "")
    q = input().strip().replace(" ", "")

    import itertools
    l = ["".join(map(str, s)) for s in itertools.permutations(range(1, N+1))]
    i = l.index(p)
    j = l.index(q)
    print(abs(i-j))


if __name__ == '__main__':
    main()

Measured memory_bytes: 6040
s = "keyence"
s1 = raw_input()
ans = "NO"
for i in range(len(s)):
	fhalf = s[:i]
	shalf = s[i:]
	if s1[0:len(fhalf)] == fhalf and s1[len(s1) - len(shalf):] == shalf:
		ans = "YES"
print ans

Measured memory_bytes: 2568
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		
		int a = s.nextInt();
		int min = a;
		int max = a;
		long sum = a;
		
		for(int i=2; i<=n; i++){
			a = s.nextInt();
			if(a < min){
				min = a;
			}
			if(a > max){
				max = a;
			}
			sum += a;
		}
		
		System.out.println(min + " " + max + " " + sum);
		
	}

}

Measured memory_bytes: 41168
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<pair<int, int> >v1, v2, v3, v4;
    for(int i = 1; i <= n; i++){
        string s;
        cin >> s;
        int x = 0, y = 0, mnbal = 0;
        for(int i = 0; i < s.size(); i++){
            if(s[i] == '('){
                x++;
            }
            else{
                y++;
            }
            mnbal = min(mnbal, x - y);
        }
        int bal = x - y;
        if(bal >= 0 && mnbal == 0){
            v1.push_back(make_pair(mnbal, bal));
        }
        else if(bal >= 0 && mnbal < 0){
            v2.push_back(make_pair(mnbal, bal));
        }
        else if(bal == mnbal){
            v4.push_back(make_pair(mnbal, bal));
        }
        else{
            v3.push_back(make_pair(mnbal, bal));
        }
    }
    int cnt = 0, k = 1;
    for(int i = 0; i < v1.size(); i++){
        cnt = cnt + v1[i].second;
    }
    sort(v2.rbegin(), v2.rend());
    for(int i = 0; i < v2.size(); i++){
        if(cnt + v2[i].first < 0){
            cout << "No";
            return 0;
        }
        cnt = cnt + v2[i].second;
    }
    sort(v3.begin(), v3.end());
    for(int i = 0; i < v3.size(); i++){
        if(cnt + v3[i].first < 0){
            cout << "No";
            return 0;
        }
        cnt = cnt + v3[i].second;
    }
    for(int i = 0; i < v4.size(); i++){
        cnt = cnt + v4[i].second;
    }
    if(cnt == 0){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    return 0;
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){ //aとbの最大公約数を求める
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b){ //aとbの最小公倍数を求める(gcd要)
    return (a/gcd(a,b)*b);
}

/*nCk (mod MOD)の計算 BEGIN*/
//faccal -> n!, k!^(MOD-2)の計算(初期化)
//comb -> nCk (mod MOD)の計算
ll mlpow(ll x, ll p) { //x^p(long long)%MOD
    ll tmp = 1;
    if(p == 0) return 1;
    while(p != 0) {
        if(p & 1) tmp = tmp*x % MOD;
        x = x*x % MOD;
        p = p >> 1;
    }
    return tmp;
}

int facnum = 2005;
vl fac(facnum);   //n!
vl facM2(facnum);  //k!^(MOD-2)

void faccal(void) {
    fac[0] = 1;
    facM2[0] = 1;
    for(ll i = 0; i<2000; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        facM2[i+1] = facM2[i]*mlpow(i+1, MOD-2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
}

ll comb(ll n, ll k) {
    if(n == 0 && k == 0) return 1;
    if(n < k || n < 0) return 0;
    ll tmp = facM2[n-k]*facM2[k] % MOD;
    return tmp*fac[n] % MOD;  //nCk = n!*(k!)^(M-2)*((n-k)!)^(M-2)
}
/*nCk (mod MOD)の計算 END*/

int main() {
    int N, K;
    cin >> N >> K;

    faccal();


    rep1(i,K){
        ll ans = comb(K-1,i-1)*comb(N-K+1,i);
        ans %= MOD;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A = sorted([(a, i) for i, a in enumerate(A)], reverse=True)

dp = [0] * (N + 1)
for i in range(N):
    dp2 = dp[:]
    for l in range(i + 1):
        a, pos = A[i]
        # add left side
        dp2[l + 1] = max(dp2[l + 1], dp[l] + abs(pos - l) * a)
        # add right side
        r = i - l + 1
        dp2[l] = max(dp2[l], dp[l] + abs(N - r - pos) * a)
    dp = dp2
print(max(dp))

Measured memory_bytes: 74720
N = int(input())
A = list(map(int, input().split()))
ans = 0
A.insert(0, A[0])

for i in range(len(A)):
    if i == 0:
        continue
    if A[i] < A[i-1]:
        ans += A[i-1] - A[i]
        A[i] = A[i-1]
print(ans)

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

using namespace std;

typedef long long ll;
typedef double db;

#define dbg(x) cout<<#x<<" is "<<x<<endl

int main() {
    int n;
    ll d;
    scanf("%d%lld", &n, &d);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        ll x, y;
        scanf("%lld%lld", &x, &y);
        if (d * d >= x * x + y * y) {
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

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

using ll = long long;
using P = pair<ll,ll>;

vector<P> factrize(ll n){
    vector<P> res;
    for(ll i = 2; i <= sqrt(n); i++){
        ll ex = 0;
        while(n % i == 0)
        {
            ex++;
            n /= i;
        }
    res.push_back({i,ex});
    }
    if (n != 1)res.push_back({n,1});
    return res;
}

int main(){
    ll n,p;
    cin >> n >> p;
    const auto &pf = factrize(p);
    ll ans = 1;
    for(auto v :pf){
        for(int i = 0; i < v.second / n; i++)
            ans *= v.first;
    }
cout << ans << endl;
}

Measured memory_bytes: 10476
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdlib>  // abs() for integer
#include <math.h>     // math.h をインクルードする！
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

bool find_prime(int n) {
    for(int i = 2; i < n + 1; i++) {
        if(i == n) return false;  
        if (n % i == 0) return true;
    }

}

int main() {
    int x;
    cin >> x;
    while(find_prime(x)) x++;
    cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define double long double
int gcd(int a,int b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
int32_t main()
{
    IOS;

    string s;
    cin>>s;
    int n=s.length();
    if(s[0]=='0' || s[n-1]=='1')
    {
    	cout<<-1;
    	return 0;
    }
    else
    {
    	int root=1;
    	vii g(n+1);
    	int c=2;
    	int cnt=0;
    	//trace1(n);
    	int fc=0;
    	for(int i=0;i<n-1;i++)
    	{
    		if(s[i]=='0')
    		{
    			g[root].pb(c);
    			c++;
    			fc++;
    			
    		}
    		else
    		{
    			//trace2(i,n-1-i);
    			if(s[n-2-i]=='0')
    			{
    				cout<<-1;
    				return 0;
    			}
    			g[c].pb(root);
    			root=c;
    			c++;
    			cnt++;
    			
    			fc=1;
    		}
    	}
    	if(s[fc-1]=='0')
    			{
    				cout<<-1;
    				return 0;
    			}
    	if(cnt<2)
    	{
    		cout<<-1;
    		return 0;
    	}
    	for(int i=1;i<=n;i++)
    	{
    		for(auto it:g[i])
    		{
    			cout<<i<<" "<<it<<endl;
    		}
    	}

    }
    return 0;

}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> map(h, vector<int>(w));
    rep(i, h) {
        rep(j, w) {
            cin >> map[i][j];
        }
    }

    // 添字を覚えておくための配列
    vector<string> index_map(h * w);
    int index = 0;

    vector<int> map2 = {};
    rep(i, h) {
        if (i % 2 == 0) {
            for (int j = 0; j < w; j++) {
                map2.push_back(map[i][j]);

                // index_map[index] = to_string(i + 1) + " " + to_string(j + 1);
                index_map[index] += to_string(i + 1);
                index_map[index] += " ";
                index_map[index] += to_string(j + 1);
                index++;
            }
        } else {
            for (int j = w - 1; j >= 0; j--) {
                map2.push_back(map[i][j]);
                // index_map[index] = to_string(i + 1) + " " + to_string(j + 1);
                
                index_map[index] += to_string(i + 1);
                index_map[index] += " ";
                index_map[index] += to_string(j + 1);
                index++;
            }
        }
    }

    vector<string> res = {};
    int res_cnt = 0;
    rep(i, h * w - 1) {
        if (map2[i] % 2 == 1) {
            res_cnt++;
            map2[i]--;
            map2[i + 1]++;

            res.push_back(index_map[i] + " " + index_map[i + 1]);
        }
    }

    cout << res_cnt << endl;
    rep(i, res.size()) {
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 17248
n,a,b = map(int,input().split())
if a > b or (n == 1 and a != b):
    ans = 0
elif n == 2:
    ans = 1
else:
    min = a * (n - 1) + b
    max = a + b * (n - 1)
    ans = max - min + 1
print(ans)

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


def lcm(x: int, y: int):
    '''
    See:
    https://note.nkmk.me/python-gcd-lcm/
    '''
    from fractions import gcd
    return (x * y) // gcd(x, y)


def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    size = lcm(n, m)
    dn = size // n
    dm = size // m
    part_s = list()
    part_t = list()

    for i in range(0, n, dm):
        part_s.append(s[i])

    for i in range(0, m, dn):
        part_t.append(t[i])

    for si, ti in zip(part_s, part_t):
        if si != ti:
            print(-1)
            exit()

    print(size)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5716
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
 
using P = pair<ll,ll>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////
void solve(){
  ins(S);
  reverse(all(S));

  string T[4] ={"maerd","remaerd","esare","resare"};
  int N = sz(S);
  int idx = 0;
  while(1){
    if(idx == N) die("YES");
    int cur = idx;
    rep(i,4){
      if(T[i] == S.substr(idx , sz(T[i]))){
        cur = idx + sz(T[i]); break;
      }
    }
    if(cur == idx) die("NO");
    idx = cur;
  }
}



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

using namespace std;

int a[200001];

int main() {
    ios_base::sync_with_stdio(false);
    int n, t;
    cin >> n >> t;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int sum = 0, ans = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i+1]-a[i] < t && i != n-1) {
            ans+=a[i+1]-a[i];
        } else {
            ans+=t;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024