akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

using namespace std;
typedef long long ll;

#define f first
#define s second

int n, x[10], y[10], p[10], a, b;

int main()
{
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> y[i];
    p[i] = i;
  }
  int nr = 1;
  do {
    bool ok = 1;
    for (int i = 1; i <= n; i++) {
      if (p[i] != x[i])
        ok = 0;
    }
    if (ok)
      a = nr;
    ok = 1;
    for (int i = 1; i <= n; i++) {
      if (p[i] != y[i])
        ok = 0;
    }
    if (ok)
      b = nr;
    nr++;
  }while(next_permutation(p + 1, p + n + 1));
  cout << abs(a - b);
  return 0;
}


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

int gcd(long long a, long long b){
  long long M = max(a, b), m = min(a, b);
  while(m != 0){
  	long long r = M%m;
    M = m; m = r;
  }
  return M;
}

int digit_sum(long long n){
  long long ans;
  while(n != 0){
  	ans += n%10;
  	n /= 10;
  }
  return ans;
}

int main(){
  int n;
  cin >> n;
  vector<pair<int, int>> p(n);
  for(int i = 0; i < n; i++){
  	int a;
  	cin >> a;
  	p.at(i) = make_pair(a, i+1);
  }
  
  sort(p.begin(), p.end());
  
  for(int i = 0; i < n-1; i++){
  	cout << p.at(i).second << ' ';
  }
  cout << p.at(n-1).second;
  cout << endl;
}

Measured memory_bytes: 1664
NN = 2020202
MOD = 10**9+7
INF = float("inf")

A = input()
N = [0]*len(A)
for i in range(len(A)):
    N[i] = int(A[i])
N = N[::-1]
N.append(0)
kyaku = 0
mise = 0

for i in range(len(N)-1):
    # print(N, kyaku, mise)
    if N[i] == 5 and N[i+1] >= 5:
        mise += 10 - N[i]
        N[i+1] += 1
    elif N[i] <= 5:
        kyaku += N[i]
    else:
        mise += 10-N[i]
        N[i + 1] += 1

if N[-1] == 1:
    kyaku += 1

print(kyaku+mise)

Measured memory_bytes: 76636
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = LLONG_MAX, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
    cin >> N;
    cout << (N+1)/2;
}


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

int main(){
  string s;
  cin >> s;
  int f = 0, g = 0;
  for(int i=0; i<3; i++){
    if(s[i] == 'R'){
      if(f == 0) f=1;
      else if(f == 1) f=2;
      else if(f == 2) f=3;
    }
    else{
      f = 0;
    }
    g = max(g, f);
  }
  cout << g;
  return 0;
}

Measured memory_bytes: 3628
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn main() {
    let v: Vec<u64> = read_line().split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (a, b, t) = (v[0], v[1], v[2]);
    println!("{}", t / a * b);
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            var K = int.Parse(Console.ReadLine());

            var c = S.ToCharArray();
            var ck = c[K - 1];

            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] != ck)
                    c[i] = '*';
            }

            Console.WriteLine(c);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(30);
#define ll long long
#define pi 3.14159265359
using namespace std;

int main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    int p[n];
    for(int i=0;i<n;i++) cin>>p[i];
    sort(p,p+n);
    int s=0;
    for(int i=0;i<k;i++) s+=p[i];
    cout<<s;
    return 0;
}

Measured memory_bytes: 3636
// Sasageyo! Sasageyo! Shinzou wo Sasageyo !
// https://goo.gl/IwJzbx

#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

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

#define endl '\n'
int main()
{
	fast_io;
  int n;
  cin >> n;
  deque<int> d;
  for(int i=0;i<n;i++) {
    int a;
    cin >> a;
    if(!(i%2))
      d.push_back(a);
    else
      d.push_front(a);
  }
  if(n%2)
    reverse(ALL(d));
  for(int i=0;i<n;i++) {
    cout << d.front() << " ";
    d.pop_front();
  }
  cout << endl;
	return 0;
}

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

typedef long long ll;

ll f(ll x, ll m) {
    return (x * x) % m;
}

int main() {
    ll N, X, M;
    cin >> N >> X >> M;
    set<ll> s;
    s.insert(X);
    ll t = X;
    set<ll> c;
    vector<ll> v, w;
    v.push_back(X);
    for (int i = 0; i < N; i++) {
        t = f(t, M);
        //cout << t << "\n";
        if (s.count(t) == 1) {
            if (c.count(t) == 1) {
                break;
            }
            w.push_back(t);
            c.insert(t);
        }
        if (c.size() == 0) {
            s.insert(t);
            v.push_back(t);
        }
    }
    // for (ll i : s) {
    //     cout << i << " ";
    // }
    // cout << "\n";
    // for (ll i : c) {
    //     cout << i << " ";
    // }
    // cout << "\n";
    
    
    ll ans = 0;
    if (v.size() >= N) {
        for (int i = 0; i < N; i++) {
            ans += v[i];
        }
        cout << ans << "\n";
        return 0;
    }
    
    for (ll i : v) {
        ans += i;
    }
    
    ll sum = 0;
    for (ll i : w) {
        sum += i;
    }
    
    N -= v.size();
    ll m = N / c.size();
    ans += m * sum;
    ll k = N - m * c.size();
    
    for (int i = 0; i < k; i++) {
        ans += w[i];
    }
    cout << ans << "\n";
    return 0;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    bool a=1, b=1, c=1;
    if(A == 1)a=0;
    if(A == 2)b=0;
    if(A == 3)c=0;
    if(B == 1)a=0;
    if(B == 2)b=0;
    if(B == 3)c=0;
    if(a)cout << 1 << endl;
    if(b)cout << 2 << endl;
    if(c)cout << 3 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
    int N, W;
    std::cin >> N >> W;
    std::vector<int> v, w;
    for (int i = 0; i < N; i++) {
        int v_, w_, m_;
        std::cin >> v_ >> w_ >> m_;
        for (int k = 1; m_ > 0; k *= 2) {
            const int use = std::min(k, m_);
            m_ -= use;
            v.push_back(v_ * use), w.push_back(w_ * use);
        }
    }
    std::vector<int> dp(W + 1, 0);
    for (int i = 0; i < v.size(); i++) {
        for (int j = W - w[i]; j >= 0; j--) { dp[j + w[i]] = std::max(dp[j + w[i]], dp[j] + v[i]); }
    }
    std::cout << *max_element(dp.begin(), dp.end()) << std::endl;
}


Measured memory_bytes: 3212
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
int main(){
 char S[21];
  scanf("%s",S);
  srand((unsigned)time(NULL));
  int sPos;
  if(strlen(S)==3){
   sPos = rand() % (strlen(S) - 2);
  }else{
   sPos = 0;
  }
  S[sPos+3]='\0';
  printf("%s",&S[sPos]);
  return 0;
}

Measured memory_bytes: 1720
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL K;
LL ans[51];

int main()
{
	in >> K;

	if (K == 0) { out << 4 << std::endl << 3 << " " << 3 << " " << 3 << " " << 3 << std::endl; }
	else if (K == 1) { out << 3 << std::endl << 1 << " " << 0 << " " << 3 << std::endl; }
	else if (2LL <= K && K < 50LL)
	{
		out << K << std::endl;
		rep(i, K - 1) { out << K << " "; }
		out << K << std::endl;
	}
	else
	{
		out << 50 << std::endl;
		rep(i, 50) { ans[i] = i + K / 50; }
		rep(i, K % 50) { ++ans[49 - i]; }
		rep(i, 49) { out << ans[i] << " "; }
		out << ans[49] << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		sc.nextLine();
		int count3200 = 0;
		int[] array = {0, 0, 0, 0, 0, 0, 0, 0};
		for (int i = 0; i < count; i++) {
			int temp = sc.nextInt();
			if (temp >= 1 && temp <= 399) {
				array[0] = 1;
			} else if (temp >= 400 && temp <= 799) {
				array[1] = 1;
			} else if (temp >= 800 && temp <= 1199) {
				array[2] = 1;
			} else if (temp >= 1200 && temp <= 1599) {
				array[3] = 1;
			} else if (temp >= 1600 && temp <= 1999) {
				array[4] = 1;
			} else if (temp >= 2000 && temp <= 2399) {
				array[5] = 1;
			} else if (temp >= 2400 && temp <= 2799) {
				array[6] = 1;
			} else if (temp >= 2800 && temp <= 3199) {
				array[7] = 1;
			} else if (temp >= 3200) {
				count3200++;
			}
		}
		sc.close();
		int countColor = 0;
		for (int i = 0; i < 8; i++) {
			if (array[i] == 1) {
				countColor++;
			}
		}
		
		int small = countColor;
		if (small == 0) {
			small = 1;
		}
		int big = countColor + count3200;
		if (big > 100) {
			big = 100;
		}
		String result = small + " " + big;
		
		System.out.println(result);
	}
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;
 
//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!
 
// OT.find_by_order(k-1)
// 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// #define 
 
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(987654319)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long
 
//////////////////////
const int N = 200005;

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

    int tt = 1;
    // cin >> tt;
    while(tt--) {
    	int x,y;
    	cin >> x >> y;

    	int a[] = {0,300000,200000,100000,0};
    	if(x > 3) x = 4;
    	if(y > 3) y = 4;
    	if(x==1 and y==1) {
    		cout << 2*a[1] + 400000;
    	} else {
    		cout << a[x] + a[y];
    	}
    	cout << "\n";
    }
}	

Measured memory_bytes: 256
// D - String Equivalence
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vector<string> s(1,"a");
	while(--N){
		vector<string>t; swap(s,t);
		rp(i, 0, t.size()){
			char mx='a'; rp(j, 1, t[i].size()) mx = max(mx, t[i][j]); mx++;
			rp(c, 'a', mx+1) s.push_back(t[i] + string(1,c));
		}
	}
	rp(i, 0, s.size()) cout<< s[i] <<endl;
}

Measured memory_bytes: 8780
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    long long ans = 0;
    if(n==1&&m==1){
        ans = 1;
    }
    else if(n==1 || m==1){
        ans = (long long)abs(n-m)-1;
    }
    else{
        ans = (long long)(n-2)*(m-2);
    }
    cout <<ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

// python でいうところの s.split(c)
vector<string> split(string s, char c){
    vector<string> res;
    s.push_back(c); // 番兵
    ll n = s.size();
    string cur;
    for(ll i = 0; i < n; i++) {
        if(s[i] == c) {
            res.push_back(cur);
            cur = "";
        } else {
            cur.push_back(s[i]);
        }
    }
    return res;
}

void solve() {
    string s;
    cin >> s;
    auto v = split(s, '/');
    bool f = true;
    if(v[0] > "2019") f = false;
    if(v[0] == "2019" && v[1] > "04") f = false;
    if(f) cout << "Heisei" << endl;
    else cout << "TBD" << endl;
}

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

Measured memory_bytes: 3580
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int N=333;
const int E=1008611;
const int inf=1<<29;
#define LL int
struct edge{
    int u,v;
    LL c,f;
    int next;
};
int eh[N],tot;
edge et[E];
void add(int u,int v,LL c,LL f){
    edge e={u,v,c,f,eh[u]};
    et[tot]=e,eh[u]=tot++;
}
void addedge(int u,int v,LL c){
    add(u,v,c,0),add(v,u,0,0);
}
int cur[N],cnt[N],dis[N],pre[N];
LL low[N];
void rebfs(int s,int t,int n){
    for(int i=0;i<=n;i++){
        cnt[i]=0;
        dis[i]=n;
    }
    queue<int>q;
    dis[t]=0;
    cnt[0]=1;
    q.push(t);
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(int now=eh[u];now!=-1;now=et[now].next){
            if(et[now^1].c==0||dis[et[now].v]<n)continue;
            dis[et[now].v]=dis[u]+1;
            cnt[dis[et[now].v]]++;
            q.push(et[now].v);
        }
    }
}
LL isap(int s,int t,int n) {      //s襍キ轤ケ?荊扈育せ?系荳コ轤ケ謨ー
    rebfs(s,t,n);            //鬚?、?炊譛?洒霍ッ譬?捷
    int u,v,now,i;
    for(i=0;i<=n;i++) low[i]=0;
    for(u=0;u<=n;u++) cur[u]=eh[u];
    LL flow=0;
    u=s;
    low[s]=inf;
    while(dis[s]<n){
        for(now=cur[u];now!=-1;now=et[now].next)
            if(et[now].c-et[now].f>0 && dis[u]==dis[v=et[now].v]+1)
                break;
        if(now!=-1){
            cur[u]=now,pre[v]=now;
            low[v]=et[now].c-et[now].f;
            low[v]=min(low[v],low[u]);
            u=v;
            if(u==t){
                for(;u!=s;u=et[pre[u]].u){
                    et[pre[u]].f+=low[t];
                    et[pre[u]^1].f-=low[t];
                }
                flow+=low[t];low[s]=inf;
            }
        }
        else{
            if(--cnt[dis[u]]==0) break;
            dis[u]=n;
            cur[u]=eh[u];
            for(now=eh[u];now!=-1;now=et[now].next)
                if(et[now].c-et[now].f>0 && dis[u]>dis[et[now].v]+1)
                    dis[u]=dis[et[now].v]+1;
            cnt[dis[u]]++;
            if(u!=s) u=et[pre[u]].u;
        }
    }
    return flow;
}
bool g[N][N];
void init(){
    tot=0;
    memset(eh,-1,sizeof(eh));
    memset(g,0,sizeof(g));
}

int main(){
    int n,m;
    while(cin>>n>>m){
        init();
        while(m--){
            int u,v;
            scanf("%d%d",&u,&v);
            g[u][v]=1;
            addedge(u,v,1);
            addedge(v,u,1);
        }
        int s,t;
        scanf("%d%d",&s,&t);
        printf("%d\n",isap(s,t,n));
        int cnt=0;
        vector<int>r;
        for(int i=0,j=1;i<tot;i+=4,j++){
            int u=et[i].u,v=et[i].v;
            if(et[i].f==0) swap(u,v);
            if(!g[u][v]){
                cnt++;
                r.push_back(j);
            }
        }
        printf("%d\n",cnt);
        for(int i=0;i<cnt;i++) printf("%d\n",r[i]);
    }
    return 0;
}

Measured memory_bytes: 1464
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	int num1=0,num2=0,num3=0,test1[200][3],test2[200][3],test3[200];
	cin>>num1;
	for(int i=0;i<num1;i++){
		for(int q=0;q<3;q++){;
			cin>>test1[i][q];
		}
	}
	for(int r=0;r<num1;r++){
		for(int t=0;t<3;t++){
			test2[r][t]=test1[r][t];
		}
	}
	for(int w=0;w<3;w++){
		for(int e=0;e<num1;e++){
			for(int r=0;r<num1;r++){
				if(test2[e][w]==test2[r][w]){
					if(e!=r){
						test1[e][w]=0;
					}
				}
			}
		}
	}
	for(int a=0;a<num1;a++){
		test3[a]=0;
	}
	for(int y=0;y<num1;y++){
		for(int u=0;u<3;u++){
			test3[y]=test3[y]+test1[y][u];
		}
	}
	for(int p=0;p<num1;p++){
		cout<<test3[p];
		cout<<"\n";
	}
}

Measured memory_bytes: 3084
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int n,m,q,a[55],b[55],c[55],d[55],x[11],ans;
int test(void)
{
	int ret=0;
	for(int i=1;i<=q;i++)
	{
		if(x[b[i]]-x[a[i]]==c[i])
			ret+=d[i];
	}
	return ret;
}
void go(int id,int mn)
{
	if(id==n+1)
	{
		ans=max(ans,test());
		return ;
	}
	for(int i=mn;i<=m;i++)
	{
		x[id]=i;
		go(id+1,i);
	}
	return ;
}
int main(){
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++)
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	go(1,1);
	cout<<ans;
	return 0;
}

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

const long long MOD = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;

    vector<int> b(n + 1, true);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        b[a] = false;
    }

    vector<long long> dp(n + 1);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j <= min(n, i + 2); j++) {
            if (b[j]) {
                (dp[j] += dp[i]) %= MOD;
            }
        }
    }

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1408
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n;
  cin >> n;
  ll x[n+1];
  for(int i=1;i<n+1;i++) cin >> x[i];
  ll p[n];
  p[0] = 0;
  ll inv[n];
  inv[1] = 1;
  for(int i=2;i<n;i++){
    inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
  }
  p[1] = 1;
  for(int i=2;i<n;i++){
    p[i] = inv[i]+p[i-1];
    p[i] %= MOD;
  }
  ll ans = 0;
  for(int i=1;i<n;i++){
    ll w = x[i+1]-x[i];
    w %= MOD;
    ans += p[i]*w;
    ans %= MOD;
  }
  for(int i=1;i<n;i++){
    ans *= i;
    ans %= MOD;
  }
  ans += MOD;
  ans %= MOD;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>

using namespace std;

int table[300005][2] = {};

int cal(string s)
{
	int ans = 0;

	int size = s.size();

	if (s[0] == 'W')
		table[0][0] = 1;
	else
		table[0][0] = 0;

	for (int i = 1; i < size; i++)
	{
		if (s[i] == 'W')
			table[i][0] = table[i - 1][0] + 1;
		else
			table[i][0] = table[i - 1][0];
	}

	if (s[size - 1] == 'E')
		table[size - 1][1] = 1;
	else
		table[size - 1][1] = 0;

	for (int i = size - 2; i >= 0; i--)
	{
		if (s[i] == 'E')
			table[i][1] = table[i + 1][1] + 1;
		else
			table[i][1] = table[i + 1][1];
	}

	return 0;
}

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

	string s;
	cin >> s;

	int size = s.size();

	int best_ans = 400005;

	cal(s);

	best_ans = table[1][1];

	for (int i = 1; i < size; i++)
	{
		int ans = table[i - 1][0] + table[i + 1][1];

		if (ans < best_ans)
			best_ans = ans;
	}

	cout << best_ans << endl;

	return 0;
}


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

#define mp       make_pair
#define mt	  make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF=1<<29;
const double EPS=1e-9;
const ll MOD = 1000000007;

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

int main(){
  cin >> str;
  for (int i = 0; i < 4; i++){
    cout << str[i];
  }
  cout << " ";
  for (int i = 4; i < str.size(); i++){
    cout << str[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int W, a, b;
	cin >> W >> a >> b;
	int res;
	if (a < b) res = max(0, b - a - W);
	else res = max(0, a - b - W);
	cout << res << "\n";

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef long long int lli;
typedef long double float64;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define all(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define tr(container, it) \
    for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 

// #define sz(a) int((a).size())
// #define pb push_back
// #define fill(a,v) memset(a,v,sizeof a)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;

#define trace3(x,y,z) cout<< '>' << #x << ':' << x \
        << " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;

#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x \
    << " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;


inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);

/////////////////////////////////////////////////////////////////////

/*bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}*/

template<class T> inline T gcd(T a,T b)//NOTES:gcd(   __gcd(0,0) gives exception
  {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}

const int MAX_N = 2345;

int main() {
    int N,K;
    scanf("%d%d",&N,&K);
    ll x=1,temp=1;
    for(int i=0;i<N;i++){
        if(x*2<temp+K)
            x=x*2;
        else
            x=x+K;
        temp=x;
    }
    printf("%lld\n",x);
    return 0;
}


Measured memory_bytes: 256
void E(int d[6]){
    int temp;
    temp = d[0];
    d[0] = d[3];
    d[3] = d[5];
    d[5] = d[2];
    d[2] = temp;
}
void S(int d[6]){
    int temp;
    temp = d[0];
    d[0] = d[4];
    d[4] = d[5];
    d[5] = d[1];
    d[1] = temp;
}
void N(int d[6]){
    int temp;
    temp = d[0];
    d[0] = d[1];
    d[1] = d[5];
    d[5] = d[4];
    d[4] = temp;
}
void W(int d[6]){
    int temp;
    temp = d[0];
    d[0] = d[2];
    d[2] = d[5];
    d[5] = d[3];
    d[3] = temp;
}

#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i, j, t, f, l, r, b, c, n=0, count=0, count1=0, count2=0;
    int t2, f2, l2, r2, b2, c2;
    int d[6], d2[6];
    int C=0;
    
    scanf("%d", &n);
    
    for(i=0; i<6; i++) {
        scanf("%d",&d[i]);
    }
    b = d[4];
    t = d[0];
    r = d[2];
    l = d[3];
    c = d[5];
    f = d[1];
    
    for(j=0; j<n-1; j++){
        for(i=0; i<6; i++) {
            scanf("%d",&d2[i]);
        }
        b2 = d2[4];
        t2 = d2[0];
        r2 = d2[2];
        l2 = d2[3];
        c2 = d2[5];
        f2 = d2[1];
        
        while (d2[1] != f) {
            
            if((d2[1] != b) &&
               (d2[1] != t) &&
               (d2[1] != r) &&
               (d2[1] != l) &&
               (d2[1] != c) &&
               (d2[1] != f) ){
                count++;
                break;
            }
            
            if (d2[2] == f || d2[3] == f) {
                E(d2);
            }
            N(d2);
        }
        while(d2[5] != c){
            if((d2[5] != b) &&
               (d2[5] != t) &&
               (d2[5] != r) &&
               (d2[5] != l) &&
               (d2[5] != c) &&
               (d2[5] != f) ){
                count1++;
                break;
            }
            if(0 < count) break;
            E(d2);
            C++;
            if(C >= 4)break;
        }
        C=0;
        while (d2[0] != t) {
            if((d2[0] != b) &&
               (d2[0] != t) &&
               (d2[0] != r) &&
               (d2[0] != l) &&
               (d2[0] != c) &&
               (d2[0] != f) ){
                break;
            }
            if(0 < count) break;
            if(0 < count1) break;
            E(d2);
            C++;
            if(C >= 4)break;
        }
        
        b2 = d2[4];
        t2 = d2[0];
        r2 = d2[2];
        l2 = d2[3];
        c2 = d2[5];
        f2 = d2[1];
        
        if(b == b2 &&
           t == t2 &&
           r == r2 &&
           l == l2 &&
           c == c2 &&
           f == f2){
            count2++;
        }
    }
    if(count2 == 0 ){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 2104
package main

import (
	"fmt"
)

func main(){
	var N, X int
	fmt.Scanf("%d %d", &N, &X)

	L := make([]int, N+1)
	var D []int
	
	for i:=0; i < N; i++ {
		fmt.Scan(&L[i])
	}
	D = append(D, 0)
	qtd := 0

	for i:=0; D[i] <= X; i++ {
		if i == N {
			qtd++
			break
		}
		D = append(D, D[i]+L[i])
		qtd++
		//fmt.Println(D[i], qtd)
	}
	fmt.Println(qtd)
}

// func testaTudoZero(N int, L []int) bool{
// 	tst := true
// 	for i:=0; i < N; i++ {
// 		if L[i] != 0 {
// 			tst = false
// 			break
// 		}
// 	}
// 	return tst
// }

Measured memory_bytes: 512
#include <stdio.h>
int main(void){
    int S,h,m,s;
    scanf("%d",&S);
    s = S % 60;
    m = S / 60;
    h = m / 60;
    m = m % 60;
    printf("%d:%d:%d\n", h , m , s);
    return 0;
}



Measured memory_bytes: 2748
N=int(input())
A=list(map(int,input().split()))
def f(x):
  if x==1:
    return dict()
  y=x
  r=dict()
  for i in range(2,int(x**0.5)+1):
    if y%i==0:
      r[i]=0
      while y%i==0:
        r[i]+=1
        y=y//i
    if y==1:
      break
  if y!=1:
    r[y]=1
  return r

B=[f(A[i]) for i in range(N)]
def g(X):
  if len(X)==1:
    return X[0]
  a,b=g(X[:len(X)//2]),g(X[len(X)//2:])
  c=list(set(a.keys())|set(b.keys()))
  for i in range(len(c)):
    a[c[i]]=max(a.get(c[i],0),b.get(c[i],0))
  return a

G=g(B)
X=1
mod=10**9+7
P=0
Y=list(G.keys())
for i in range(len(Y)):
  X=X*pow(Y[i],G[Y[i]],mod)%mod
for i in range(N):
  P=(P+X*pow(A[i],mod-2,mod))%mod
print(P)

Measured memory_bytes: 82680
N, K = map(int, input().split())
S = input() + '2'

T = []
c = 1
for i in range(1, len(S)) :
    if S[i] == S[i-1] :
        c += 1
    else :
        T.append(c)
        c = 1
        
for i in range(1, len(T)) :
    T[i] += T[i-1]

if S[-2] == '0' :
    T.append(T[-1])

ret = 0
for i in range(0 if S[0] == '1' else 1, len(T), 2) :
    if i - 2*K - 1 < 0 :
        ret = max(ret, T[i])
    else :
        ret = max(ret, T[i] - T[i-2*K-1])
    
print(ret)

Measured memory_bytes: 45424
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, m, x, ans = -1;
  cin >> n >> m >> x;
  int c[n];
  int a[n][m];
  rep(i,n)
  {
    cin >> c[i];
    rep(j,m)
      cin >> a[i][j];
  }
  rep(b,(1 << n))
  {
    bitset<13> bit(b);
    int learn[m] = { }, cost = 0;
    rep(i,n)
    {
      if (bit.test(i)) {
        cost += c[i];
        rep(j,m)
        {
          learn[j] += a[i][j];
        }
      }
    }
    bool f = true;
    rep(j,m)
      if (learn[j] < x)
        f = false;
    if (f) {
      if (ans == -1) {
        ans = cost;
      } else {
        ans = min(ans, cost);
      }
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3636
// Goods things are coming, just keep believing 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define okay cout << "okay" << endl
// #define hey cout << "hey" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mpp make_pair
#define endl '\n'
#define ff first 
#define int long long
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 #define ld long double
#define INF 1000000000;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
 
 
 
const int N = 2e5 + 10;
const int LG = 20;
const int mod = 1e9 + 7;

int arr[N];

void solve()
{
	int n, k;
	cin >> n >> k;
	int cnt = 0;
	while(n)
	{
		cnt++;
		n /= k;
	}
	cout << cnt << endl;
}

int32_t main() 
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    	solve();
    return 0;
}

Measured memory_bytes: 256
// Problem : A - ∴ (Therefore)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    //int T; cin >> T;
    //while(T--) 
 	//{
  //    
  //  }
	int N;
	cin>>N;
	N%=10;
	switch(N)
	{
		case 0:case 1:case 6:case 8:
		cout<<"pon"<<endl;
		break;
		case 2:case 4:case 5:case 7:case 9:
		cout<<"hon"<<endl;
		break;
		case 3:
		cout<<"bon"<<endl;
	}
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343
 



Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(int, A); invar(int, B); invar(int, M);
  vi a(A); vi b(B);
  rep(i, A) {
    cin >> a[i];
  }
  rep(i, B) {
    cin >> b[i];
  }
  
  int mv = INF;
  rep(i, M) {
    invar(int, x); invar(int, y); invar(int, c);
    --x; --y;
    
    int cost = a[x] + b[y] - c;
    chmin(mv, cost);
  }
  
  sort(all(a));
  sort(all(b));
  chmin(mv, a[0] + b[0]);
  
  fin(mv);
}

Measured memory_bytes: 1024
import collections
l,r = map(int, raw_input().split(' '))
cc = collections.Counter([n % 2019 for n in range(l, min(r, l + 2019)+1) ])

m = +float('inf')
for a in cc:
	for b in cc:
		if a!=b or cc[a] > 1:
			m = min(m,(a*b) % 2019)
print m

Measured memory_bytes: 33004
#include<iostream>
#include <stdio.h>
using namespace std;

int pow(int n){

        int ans = 1;
        for(int i=0;i<n;i++){
            ans *= 10;
        }

    return ans;

}

int first_num(int n){
    while(1){
        if(n/10==0){
            return n;
        }else{
            n = n / 10;
        }
    }
}

int last_num(int n){
    return n%10;
}

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

    int ans=0;
    int mat[10][10];

    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            mat[i][j]=0;
        }
    }

    for(int i=1;i<N+1;i++){
        mat[first_num(i)][last_num(i)]++;
    }    

    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            ans += mat[i][j] * mat[j][i];
        }
    }

    cout << ans << endl;

    return 0;

}

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

using namespace std;

typedef long long ll;

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int n,k;
        cin>>n>>k;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        ll ans=0;
        for(int i=0;i<k;i++){
            ans+=arr[i];
        }
        cout<<ans;
    return 0;
}

Measured memory_bytes: 3648
fun main(args: Array<String>) {
    val l = readLine()!!.split(' ').map { it.toInt() }
    var a = l[0]
    val b = l[1]
    var c = l[2]
    val d = l[3]
    var cnt = 0
    while (a > 0 && c > 0) {
        cnt++
        if (cnt % 2 == 1) {
            c -= b
        } else {
            a -= d
        }
    }
    if (a > 0) println("Yes") else println("No")
}


Measured memory_bytes: 36360
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int T=sc.nextInt();
        int count=0;
        for(int i=1;i<T+1;i++){
          if(i%A==0){
            count+=B;
          }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <cmath>

using namespace std;

int main() {

  int n, ans;
  
  while (cin >> n && n) {

    if (n < 3) {
      cout << 2 << endl;
      continue;
    }
  
    for (int i = n; ; i++) {
      bool flag = true;
      for (int j = 2; j <= sqrt(i); j++) {
        //cout << "n: " << n << " i: " << i << " j: " << j << endl;
        if (i % j == 0) {
          //cout << "divided" << endl;
          flag = false;
          break;
        }
      }
      if (flag) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

#define u unsigned
#define s short
#define ll long long
#define REP(i, a, b) for (auto i = (a); i < (b); i++)
#define REPR(i, a, b) for (auto i = (a-1); i >= (b); i--)

using namespace std;

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

    cout << a + pow(a, 2) + pow(a, 3) << "\n";

    return 0;
}

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

 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;

//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const LL INF=LONG_MAX;
const double EPS=0.00001;
const long double PI = acos(-1.0);



int main(){
    int N;
    cin>>N;
    int res=0;
    REP(i,N){
        int l,r;
        cin>>l>>r;
        res+=(r-l+1);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

// namespace
using namespace std;
namespace mp = boost::multiprecision;

// types
using pii = pair<int, int>;
using ll = long long int;
using ld = long double;
using mpi = mp::cpp_int;
using mpf = mp::number<mp::cpp_dec_float<1024>>;

int main() {
    queue<ll> q;
    unordered_set<ll> s;
    for (ll i = 1; i <= 9; ++i) {
        q.push(i);
    }

    ll K;
    cin >> K;
    while(s.size() < 5 * K && !q.empty()) {
        auto e = q.front(); q.pop();
        // cout << e << endl;
        s.insert(e);
        auto d = e % 10;
        if (d - 1 >= 0) q.push(e * 10 + d - 1);
        q.push(e * 10 + d);
        if (d + 1 <= 9) q.push(e * 10 + d + 1);
    }


    vector<ll> v(s.begin(), s.end());
    sort(v.begin(), v.end());
    // for (int i = 0; i < 100; ++i) {
    //     cout << i + 1 << " " << v[i] << endl;
    // }
    cout << v[K-1] << endl;
    return 0;
}


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

int main() {
	int A, B, C, a, b, c, cnt = 0;
	cin >> A >> B >> C;
	while (cnt < 100) {
		if (A & 1)break;
		if (B & 1)break;
		if (C & 1)break;
		a = B / 2 + C / 2;
		b = A / 2 + C / 2;
		c = A / 2 + B / 2;
		A = a; B = b; C = c;
		cnt++;
	}
	cout << (cnt != 100 ? cnt : -1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
#define pi acos(-1);
ll strtoint(string str);
int main(){
	fast;
	ll n; cin>>n;
	vector<ll> arr(n+1),rev(n+1);
	for(auto i=1;i<=n;++i)cin>>arr[i];
	for(auto i=1;i<=n;++i){
		rev[arr[i]]=i;
	}
	for(auto i=1;i<=n;++i)cout<<rev[i]<<' ';
	cout<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 2432
import java.util.*;

public class Main {
	public static void main(String[] args) {

		//input
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			
			//calculation
			int sum = 0;
		    for(int i=0;i<10;i++){
		    	for(int j=0;j<10;j++){
		    		for(int k=0;k<10;k++){
		    			for(int l=0;l<10;l++){
		    				if(i+k+j+l == n){
		    					sum++;
		    				}
		    			}
		    		}
		    	}
		    }
		    //output
		    System.out.println(sum);
		}
	}
}

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

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

	int N, K;
	cin >> N >> K;
	int ans = 1;
	while (ans < K && N>0) {
		ans *= 2;
		N--;
	}
	cout << ans + K * N;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll n, y;
ll count(ll mon){
    ll cnt = y / mon;
    y %= mon;
    return cnt;
}

int main() {
    cin >> n >> y;
    vector<ll> a(3, 0);
    a[2] = count(10000);
    a[1] = count(5000);
    a[0] = count(1000);
    ll d = n - (a[0]+a[1]+a[2]);
    if (d<0){
        cout << -1 << " " << -1 << " " << -1 << endl;
        return 0;
    }
    ll val = min(a[2], d/9);
    a[0] += val*10;
    a[2] -= val;
    d -= val*9;
    val = min(a[1], d/4);
    a[0] += val*5;
    a[1] -= val;
    d -= val*4;
    val = min(a[2], d);
    a[1] += val*2;
    a[2] -= val;
    d -= val;
    if (d!=0){
        cout << -1 << " " << -1 << " " << -1 << endl;
        return 0;
    }
    cout << a[2] << " " << a[1] << " " << a[0] << endl;
    //printf("%.12f", ans);
}


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

//定義
int abc116_a(){
    //入力
    int a,b,c;
    cin >> a >> b >> c;
    
    //処理
    int s = a*b/2;
    
    //出力
    cout << s << endl;
    return 0;
}

int main(){
    abc116_a();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll x, y;
    cin >> x >> y;
    if (abs(x) == abs(y))
        cout << 1 << endl;
    else if (x > y and x > 0 and y > 0)
        cout << x - y + 2 << endl;
    else if (x > y and x > 0 and y < 0 and abs(x) > abs(y))
        cout << x + y + 1 << endl;
    else if (x > y and x > 0 and y < 0 and abs(x)<abs(y))
        cout << -x  -y + 1 << endl;
    else if(x>y and x<0 and y<0)
        cout << x - y + 2 << endl;
    else if(x<y and x>0 and y>0)
        cout << y - x << endl;
    else if(x<y and x<0 and y>0 and abs(x)<abs(y))
        cout << x + y + 1 << endl;
    else if(x<y and x<0 and y>0 and abs(x)>abs(y))
        cout << -x -y + 1 << endl;
    else if(x<y and x<0 and y<0)
        cout << y - x << endl;
    else if(x==0 and y>0)
        cout << y - x << endl;
    else if(x==0 and y<0)
        cout << -y + 1 << endl;
    else if(y==0 and x>0)
        cout << x + 1 << endl;
    else if(y==0 and x<0)
        cout << -x << endl;
}

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

using namespace std;
int main() {
  int a,b; cin>>a>>b;
  int count,B,ans;
  count=b-a;
  B=0;
  for(int i=0;i<=count;i++)
  {
      B=i+B;
  }
  ans=B-b;
  cout<<ans;
    return 0;
}



Measured memory_bytes: 256