akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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; }
const int64_t INF = 1LL << 60;

int main() {
    int N;
    cin>>N;
    vector<int>a(N);
    for(int i=0;i<N;i++){
      cin>>a[i];
    }
    int s=0;
    for(int i=0;i<N;i++){
      s^=a[i];
    }
    for(int i=0;i<N;i++){
      a[i]^=s;
    }
    for(int i=0;i<N;i++){
      cout<<a[i]<<endl;
    }
  return 0;
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
	int n; cin>>n;
	int m=n%10;
	if(m==3) cout<<"bon"<<endl;
	else if(m==0||m==1||m==6||m==8) cout<<"pon"<<endl;
	else cout<<"hon"<<endl;

	return 0;
}


Measured memory_bytes: 3652
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    string l;
    cin >> l;
    cout << l << endl << l << endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<long long> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  long long ans = 0;
  for (int i = n - 1; - 1 < i; i--)
    ans += ((a[i] + ans) % b[i] == 0 ? 0 : b[i]) - (a[i] + ans) % b[i];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Chara{
  string name;
  int vote;
  bool operator < (const Chara& c) const {
    if(vote != c.vote) return vote > c.vote;
    return name < c.name;
  }
};

int main(){
  int N, M, K, L;
  while(cin >> N >> M >> K >> L && N){
    Chara cs[100000];
    REP(i, N){
      char s[11];
      scanf("%s %d", s, &cs[i].vote);
      cs[i].name = string(s);
    }
    sort(cs, cs + N);
    set<string> favs;
    REP(i, M){
      char s[11];
      scanf("%s", s);
      favs.insert(string(s));
    }
    int lb = 0, ub = min(M + 1, K + 1); // 
    while(lb + 1 < ub){
      int X = (ub + lb) / 2; // X 人
      ll S = 0;
      int idx = K - X;
      int Rest = X;
      for(int i = 0; i < N; i++) if(Rest > 0 && favs.count(cs[i].name)){
        if(i > idx){
          S += cs[idx].vote - cs[i].vote;
          if(cs[idx].name < cs[i].name) S++;
        }else{
          idx++;
        }
        if(S > L) break;
        Rest--;
      }
      if(S <= L) {
        lb = X;
      }else{
        ub = X;
      }
    }
    cout << lb << endl;
  }
  return 0;
}

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

typedef long long ll;
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    for(int i = a; i <= b; i++){
        if(i % c == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::greater<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  cin >> n;
  vector<pair<int, int>> a(n);
  for (auto& pr : a) {
    cin >> pr.first >> pr.second;
  }
  sort(begin(a), end(a), [&] (const auto& l, const auto& r) {
    return l.first - l.second < r.first - r.second;
  });
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
  int ans = 0;
  for (const auto& pr : a) {
    while (!q.empty() && q.top().first <= pr.first - pr.second) {
      ans = max(ans, q.top().second);
      q.pop();
    }
    q.emplace(pr.first + pr.second, ans + 1);
  }
    while (!q.empty()) {
      ans = max(ans, q.top().second);
      q.pop();
    }
  cout << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 2168
#                         author:  kagemeka 
#                         created: 2019-11-08 14:51:29(JST)
## internal modules
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version) 

def main():
    n, *a = (int(x) for x in sys.stdin.read().split())
    a.sort()
    print(a[-1] - a[0])


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 0;
	int e = 0;
	int d = 0;
	for (int i = 0; ; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		int tmp = 0;
		if (a > b) {
			tmp = a;
			a = b; b = tmp;
		}
		if (b > c) {
			tmp = b;
			b = c; c = tmp;
		}
		if (a > b) {
			tmp = a;
			a = b; b = tmp;
		}
		if (a + b <= c) {
			cout << i << " " << t << " " << e << " " << d << endl;
			break;
		}
		if (a * a + b * b > c * c) e++;
		if (a * a + b * b == c * c) t++;
		if (a * a + b * b < c * c) d++;
	}
	return 0;
}


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

int main() {
	int n,sum=0; cin>>n;
	int a[n],b[n],c[n-1];
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n-1;i++) cin>>c[i];
	for(int i=0;i<n;i++) {
		sum+=b[a[i]-1];
		if(i!=n-1 && a[i+1]==a[i]+1) sum+=c[a[i]-1];
	}
	cout<<sum<<endl;
	return 0;
}


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

#define N	25000
#define K	400
#define MD	1000000007

int max(int a, int b) { return a > b ? a : b; }

int vv[K + 1], ff[K + 1], gg[K + 1];

void init() {
	int i;

	ff[0] = gg[0] = 1;
	for (i = 1; i <= K; i++) {
		vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
		ff[i] = (long long) ff[i - 1] * i % MD;
		gg[i] = (long long) gg[i - 1] * vv[i] % MD;
	}
}

int main() {
	static int aa[N], pp[K], dp[N + 1][K], dq[N + 1][K];
	int n, k, m, i, j, ans;

	init();
	scanf("%d%d%d", &n, &k, &m);
	for (i = 0; i < m; i++)
		scanf("%d", &aa[i]), aa[i]--;
	memset(pp, -1, k * sizeof *pp);
	for (i = -1, j = 0; j < m; j++) {
		i = max(i, pp[aa[j]]), pp[aa[j]] = j;
		if (j - i == k)
			break;
	}
	ans = n - m + 1;
	for (i = 0; i < n - m; i++)
		ans = (long long) ans * k % MD;
	if (j < m) {
		printf("%d\n", ans);
		return 0;
	}
	memset(pp, -1, k * sizeof *pp);
	j = 0;
	while (j < m && pp[aa[j]] == -1)
		pp[aa[j]] = j, j++;
	if (j < m) {
		dp[0][j] = 1;
		for (i = 1; i <= n - m; i++) {
			for (j = k - 1; j > 0; j--)
				dp[i][j] = ((j + 1 == k ? 0 : dp[i][j + 1]) + dp[i - 1][j]) % MD;
			for (j = 1; j < k; j++)
				dp[i][j] = (dp[i][j] + (long long) dp[i - 1][j - 1] * (k - j + 1)) % MD;
		}
		memset(pp, -1, k * sizeof *pp);
		j = m - 1;
		while (j >= 0 && pp[aa[j]] == -1)
			pp[aa[j]] = j, j--;
		dq[0][m - 1 - j] = 1;
		for (i = 1; i <= n - m; i++) {
			for (j = k - 1; j > 0; j--)
				dq[i][j] = ((j + 1 == k ? 0 : dq[i][j + 1]) + dq[i - 1][j]) % MD;
			for (j = 1; j < k; j++)
				dq[i][j] = (dq[i][j] + (long long) dq[i - 1][j - 1] * (k - j + 1)) % MD;
		}
		for (i = 0; i <= n - m; i++) {
			int x, y;

			x = 0, y = 0;
			for (j = 1; j < k; j++) {
				x = (x + dp[i][j]) % MD;
				y = (y + dq[n - m - i][j]) % MD;
			}
			ans = (ans - (long long) x * y) % MD;
		}
	} else {
		dp[0][0] = 1, dq[0][0] = 0;
		for (i = 1; i <= n; i++) {
			for (j = k - 1; j > 0; j--) {
				dp[i][j] = ((j + 1 == k ? 0 : dp[i][j + 1]) + dp[i - 1][j]) % MD;
				dq[i][j] = ((j + 1 == k ? 0 : dq[i][j + 1]) + dq[i - 1][j]) % MD;
			}
			for (j = 1; j < k; j++) {
				dp[i][j] = (dp[i][j] + (long long) dp[i - 1][j - 1] * (k - j + 1)) % MD;
				dq[i][j] = (dq[i][j] + (long long) dq[i - 1][j - 1] * (k - j + 1)) % MD;
			}
			for (j = m; j < k; j++)
				dq[i][j] = (dq[i][j] + (long long) dp[i][j] * gg[k] % MD * ff[k - m]) % MD;
		}
		for (j = 1; j < k; j++)
			ans = (ans - dq[n][j]) % MD;
	}
	if (ans < 0)
		ans += MD;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 79824
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a<=c&&c<=b){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  int d, n;
  cin >> d >> n;
  int x = 0;
  if(d == 0) {
    if(n == 100) n++;
    cout << n << endl;
    return 0;
  }
  if(d == 1) {
    if(n == 100) x = 100;
    cout << n*100+x << endl;
    return 0;
  }
  if(d == 2) {
    if(n == 100) x = 10000;
    cout << n*10000+x << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    string a[3] = {}, s;
    cin >> s;
    a[0] = "Sunny", a[1] = "Cloudy", a[2] = "Rainy";
    for (int i = 0; i < 3; i++) {
        if (s == a[i]) cout << a[(i + 1) % 3] << endl;
    }
}


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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  map<int, int> A;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    A[a]++;
  }
  int ans = 0;
  vector<int> list;
  for (pair<int, int> p : A) list.push_back(p.second);
  sort(list.begin(), list.end());
  ans =
      accumulate(list.begin(), list.begin() + max(0, (int)list.size() - K), 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10748
S = int(input())
p = S%(10**9)
k = (S-p)//10**9
L = [0,0,10**9,1,10**9-p,(k+1)]
if S != 10**18:
  print(" ".join(map(str,L)))
else:
  L = [0,0,10**9,0,0,10**9]
  print(" ".join(map(str,L)))

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

int main()
{
  int i = 1;
  while (1)
  {
    int x;
    std::cin >> x;
    if(x == 0) break;
    std::cout << "Case " << i << ": " << x <<'\n';
    ++i;
  }
  return 0;
}



Measured memory_bytes: 3096
import java.util.*;

public class Main{

    ArrayList<String[]> color,list;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt();
            if(n==0) break;

            color = new ArrayList<String[]>();
            int cnt = 0;
            for(int i=0; i<n; i++){
                String[] s = new String[6];
                for(int j=0; j<6; j++) s[j] = sc.next();
                if(same(s)) cnt++;
                else color.add(s);
            }

            System.out.println(cnt);
        }
    }

    int[][] rotate = {{1,2,4,3},{0,4,5,1},{0,2,5,3}};

    boolean same(String[] dice){
        list = new ArrayList<String[]>();
        for(int i=0; i<4; i++){
            dice = rotate(dice,0);
            for(int j=0; j<4; j++){
                dice = rotate(dice,1);
                for(int l=0; l<4; l++){
                    dice = rotate(dice,2);
                    list.add(dice);
                }
            }
        }

        for(int i=0; i<list.size(); i++){
            String[] s1 = list.get(i);
            for(int j=0; j<color.size(); j++){
                boolean boo = false;
                String[] s2 = color.get(j);
                for(int k=0; k<6; k++){
                    if(!s1[k].equals(s2[k])){
                        boo = false;
                        break;
                    }
                    boo = true;
                }
                if(boo) return true;
            }
        }
        return false;
    }

    String[] rotate(String[] dice, int idx){
        String[] res = new String[6];
        for(int i=0; i<6; i++) res[i] = dice[i];
        String tmp = res[rotate[idx][3]];
        for(int i=3; i>0; i--) res[rotate[idx][i]] = res[rotate[idx][i-1]];
        res[rotate[idx][0]] = tmp;
        return res;
    }

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

Measured memory_bytes: 12000
a=[int(input()) for _ in range(5)]
t=[x%10 if x%10!=0 else 10 for x in a]
idx=t.index(min(t))
m=a[idx]
a.remove(m)
a=[(x//10+int(bool(x%10)))*10 for x in a]
print(sum(a)+m)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define ll int
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e9;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  long long tmp=1e9;
  bool judge = true;
  long long h,w,n;cin>>h>>w>>n;
  vector<ll> a(n),b(n);
  for(i=0;i<n;i++){cin>>a[i]>>b[i];a[i]--;b[i]--;}
  unordered_set<long long>c;
  for(i=0;i<n;i++){
    c.insert({a[i]+tmp*(b[i]+1)});
  }
  unordered_map<long long,ll> x;
  for(i=0;i<n;i++){
    for(j=-1;j<=1;j++){
      for(o=-1;o<=1;o++){
        if(a[i]+j<1||a[i]+j>=h-1||b[i]+o<1||b[i]+o>=w-1)continue;
        buf=0;
        for(ll p=-1;p<=1;p++){
          for(ll q=-1;q<=1;q++){
            buf+=c.find(a[i]+j+p+(b[i]+o+q+1)*tmp)!=c.end();
          }
        }
        //cout<<a[i]+j spa b[i]+o spa buf<<endl;
        x.insert({a[i]+j+(b[i]+o+1)*tmp,buf});
      }
    }
  }
  vector<ll>m(10);
  for(auto y:x){
    m[y.second]++;
  }
  cout<<(h-2)*(w-2)-x.size()<<endl;
  for(i=1;i<=9;i++)cout<<m[i]<<endl;

  return 0;
}

Measured memory_bytes: 43536
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
X = INT()

# #nを素因数分解したリストを返す
# def prime_decomposition(n):
#   i = 2
#   table = []
#   while i * i <= n:
#     while n % i == 0:
#       n /= i
#       table.append(i)
#     i += 1
#   if n > 1:
#     table.append(n)
#   return table
def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

for a in range(-200, 200):
    for b in range(-200, 200):
        if a ** 5 - b ** 5 == X:
            print(a, b)
            exit()
        








# for d in D:
#     ab = d
#     Z = ab // d
#     print(ab, Z)
#     # print((X ** (1/5)))
#     for b in range(int(sqrt(X)) + 1):
#         a = ab - b
#         if a**5-b**5 == X:
#             print("a, b:", a, b)



# for d in divisor(X):
#     ab = d
#     z = X // d
#     for a in range(10 ** 9):
#         b = a - d
#         dot = 
    # for b in range():
    

Measured memory_bytes: 10052
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MAX 100000
typedef long long ll;
typedef pair<ll,int> P;



int main(){
  int n,p[20],ans=0;
  cin>>n;
  for(int i=0;i<n;i++) cin>>p[i];

  for(int i=1;i<n-1;i++){
    if(p[i]>p[i-1] && p[i+1]>p[i]) ans++;
    else if(p[i]<p[i-1] && p[i+1]<p[i]) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 888
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

template <typename QvQ> inline QvQ Min(QvQ a,QvQ b){if(a<b) return a;return b;}
template <typename QvQ> inline QvQ Max(QvQ a,QvQ b){if(a>b) return a;return b;}

#define inf 0x7f7f7f7f
#define dinf 0x3f3f3f3f

#define ll long long
#define rei register int
#define inv inline void

#define bl putchar(' ')
#define ed putchar('\n')

#define read2(a,b) read(a),read(b)
#define write2(a,b) write(a),bl,write(b)
#define read3(a,b,c) read(a),read(b),read(c)
#define write3(a,b,c) write(a),bl,write(b),bl,write(c)

template <typename QvQ>inv read(QvQ &x)
{
	x=0;int f=1;
	char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x=x*f;
}
template <typename QvQ>inv write(QvQ x)
{
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10+48);
}
using namespace std;
#define MAXN 200050
int n,m;
int head[MAXN],tot;
struct node
{
	int to;
	int nex;
}e[MAXN<<1];
void add_edge(int u,int v)
{
	e[tot].to=v;
	e[tot].nex=head[u];
	head[u]=tot++;
}
int T,l[MAXN],r[MAXN];
void dfs(int u,int fa)
{
	l[u]=++T;
	for(rei i=head[u];i!=-1;i=e[i].nex)
	{
		int t=e[i].to;
		if(t!=fa) dfs(t,u);
	}
	r[u]=T;
}
int tree[MAXN];
void add(int x,int val)
{
	for(;x<=n;x+=x&-x) tree[x]+=val;
}
int query(int x)
{
	int ret=0;
	for(;x;x-=x&-x) ret+=tree[x];
	return ret;
}
int main()
{
	memset(head,-1,sizeof(head));
	read2(n,m);
	int x,y;
	for(rei i=1;i<n;++i)
	{
		read2(x,y);
		add_edge(x,y);
		add_edge(y,x);
	}
	dfs(1,0); int po,val;
	for(rei i=1;i<=m;++i)
	{
		read2(po,val);
		add(l[po],val);
		add(r[po]+1,-val);
	}
	for(rei i=1;i<=n;++i) write(query(l[i])),bl;
	return 0;
}

Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, x, count=0;
  cin >> N >> x;
  vector<int> a(N);
  REP(i,N) cin >> a[i];
  sort ALL(a);
  REP(i,N) {
    if(a[i]<=x) {
      x-=a[i];
      count++;
    }
    else break;

    if(i == N-1 && 0 < x) count--;
  }
  cout << count << endl;
}

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

using namespace std;

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

const int MAX = 2e5+10;

int N;
int A[MAX];

bool check(int n) {
    map<int, int> m; // m[i]: i文字目のアルファベット、iが存在しないときはm[i] = 0

    REP (i, N-1) {
        if (A[i+1] > A[i]) continue;
        int a = A[i+1];
        while (m[a] == n-1) {
            a--;
            if (a <= 0) return false;
        }
        
        m[a]++;
        // インクリメントした文字以降は全て0にリセット
        auto it = m.upper_bound(a);
        while (it != m.end()) it = m.erase(it);
    }
    return true;
}

bool isIncreasing() {
    REP (i, N-1) {
        if (A[i+1] <= A[i]) return false;
    }
    return true;
}

int main() {
    cin >> N;
    REP (i, N) cin >> A[i];
    if (isIncreasing()) {
        cout << 1 << endl;
        return 0;
    }
    int lo = 1, hi = N+1;
    while (hi - lo > 1) {
        int mid = (hi+lo)/2;
        if (check(mid)) hi = mid;
        else lo = mid;
    }

    cout << hi << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
#define mst(a) memset(a,0,sizeof a)
int main(){
	int n,m;
	while(cin>>n>>m){
	int a[n],sum=0,cnt=0;
	for(int i=0;i<n;i++) cin>>a[i],sum+=a[i];
	for(int i=0;i<n;i++) if(a[i]*4*m>=sum) cnt++;
	if(cnt>=m) puts("Yes");
	else puts("No");
	}
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
ll GCD(ll a, ll b) {
  if(a < b) {
    swap(a, b);
  }
  ll r;
  r = a % b;
  while(r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll A, B;
  cin >> A >> B;
  cout << (A * B) / GCD(A, B) << endl;
}

Measured memory_bytes: 256
import sys
import math
import itertools
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

n, m = I2()
a = [Intl() for i in range(n)]
a.sort()
i = 0#index
c = 0#コスト
s = 0#本数累積和
while s < m:
    s += a[i][1]
    c += a[i][0]*a[i][1]
    i += 1
i -= 1

print(c-a[i][0]*(s-m))

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

bool threeOrfour(vector<char>);

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

  vector<char> color(N);
  for(int i=0; i<N; i++)
    cin>>color[i];

  if(threeOrfour(color))
    cout<<"Three"<<endl;
  else
    cout<<"Four"<<endl;

  return 0;
}

bool threeOrfour(vector<char> color)
{
  for(char s: color){
    if(s=='Y')
      return false;
  }
  return true;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY puts("Yes")
#define NN puts("No")
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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 gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int Rand() { return (rand() % 32768) * 32768 + (rand() % 32768); }
int solve(){
  int w,a,b;
  cin >> w >> a >> b;
  if(abs(a - b) <= w)cout << 0 << endl;
  else if(a + w <= b)cout << abs(b - (a + w)) << endl;
  else cout << abs(a - (b + w)) << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL x,y;cin>>x>>y;


    if(x==y){
        cout<<0<<endl;
        return;
    }

    LL result = max(abs(x)-abs(y), abs(y)-abs(x));
    if(x==0){
        if(y<0){
            result ++;
        }
        else if(y>0){
            //none
        }
    }
    else if(x<0){
        if(y==0){
            //none
        }
        else if(y>0){
            if(abs(x)>abs(y)){
                result++;
            }
            else{
                result++;
                
            }

        }
        else if(y<0){
            if(abs(x)>abs(y)){
                //none
            }
            else{
                result += 2;
            }
        }
    }
    else if(x>0){
        if(y==0){
            result++;
        }
        else if(y>0){
            if(x>y){
                result+=2;
            }
            else{
                //none
            }
        }
        else if(y<0){
            if(abs(x)>abs(y)){
                result++;
            }
            else{
                result++;
            }

        }
    }
    cout<<result<<endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int A[N];
    for (auto& a : A) cin >> a;
    int cnt = 0;
    for (int i = N - 1; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            if (A[j] > A[j+1]) {
                swap(A[j], A[j+1]);
                cnt++;
            }
        }
    }
    for (int i = 0; i < N; i++) {
        cout << A[i] << (i < N - 1 ? " " : "\n");
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3104
data class Task (
  val cost: Int,
  val deadline: Int
)

fun main(args: Array<String>) {
  val n = nextInt()
  val tasks = (0 until n).map {
    val (a, b) = readLine()!!.split(" ")
    Task(a.toInt(), b.toInt())
  }
  val sortedTasks = tasks.sortedBy { it.deadline }
  var now = 0L
  sortedTasks.forEach {
    now += it.cost
    if (now > it.deadline) {
      println("No")
      return
    }
  }
  println("Yes")
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

Measured memory_bytes: 118872
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Ordinary Number
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 20;

/* typedef */

/* global variables */

int ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", ps + i);

  int cnt = 0;
  for (int i = 2; i < n; i++) {
    int &p0 = ps[i - 2], &p1 = ps[i - 1], &p2 = ps[i];
    if ((p0 < p1 && p1 < p2) || (p0 > p1 && p1 > p2)) cnt++;
  }

  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc073/tasks/abc073_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> v;
    REP(i, r) {
        int t;
        cin >> t;
        v.push_back(t - 1);
    }
    sort(ALL(v));
    vector<vector<int>> g(n, vector<int>(n, INT_MAX));
    REP(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        g[a][b] = g[b][a] = c;
    }
    // ダイクストラ法
    REP(k, n) REP(i, n) REP(j, n) { g[i][j] = min(g[i][j], g[i][k] + g[k][j]); }

    int M = INT_MAX;
    do {
        int tmp = 0;
        REP(i, r - 1) tmp += g[v[i]][v[i + 1]];
        M = min(M, tmp);
    } while (next_permutation(ALL(v))); // 次の順列を生成

    cout << M << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) \
  SORT(var);       \
  REVERSE(var)
#define OPTIMIZE_STDIO         \
  ios::sync_with_stdio(false); \
  cin.tie(0);                  \
  cout.precision(10);          \
  cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
  ll x;
  mint() : x(0) {
  }
  mint(ll x) : x((x % MOD + MOD) % MOD) {
  }
  mint& operator+=(const mint& r) {
    if ((x += r.x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint& operator-=(const mint& r) {
    if ((x -= r.x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint& operator*=(const mint& r) {
    if ((x *= r.x) > MOD) {
      x %= MOD;
    }
    return *this;
  }
  mint& operator++() {
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint operator++(int) {
    mint ret = x;
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return ret;
  }
  mint& operator--() {
    if ((--x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint operator--(int) {
    mint ret = x;
    if ((--x) < 0) {
      x += MOD;
    }
    return ret;
  }
  mint operator+(const mint& r) {
    mint ret;
    return ret = x + r.x;
  }
  mint operator-(const mint& r) {
    mint ret;
    return ret = x - r.x;
  }
  mint operator*(const mint& r) {
    mint ret;
    return ret = x * r.x;
  }
  mint operator-() {
    return mint() - *this;
  }
  bool operator<(const mint& a) {
    return x < a.x;
  }
  bool operator>(const mint& a) {
    return x > a.x;
  }
  bool operator<=(const mint& a) {
    return x <= a.x;
  }
  bool operator>=(const mint& a) {
    return x >= a.x;
  }
  bool operator==(const mint& a) {
    return x == a.x;
  }
  bool operator!=(const mint& a) {
    return x != a.x;
  }
};
ostream& operator<<(ostream& os, const mint& r) {
  os << r.x;
  return os;
}
ostream& operator>>(ostream& os, const mint& r) {
  os >> r.x;
  return os;
}

void solve(istream& cin, ostream& cout) {
  int n, m;
  cin >> n >> m;
  map<int, bool> good;
  REP(i, n) {
    good[i] = true;
  }
  vector<int> h(n);
  REP(i, n) cin >> h[i];
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h[a] > h[b]) {
      good[b] = false;
    } else if (h[a] < h[b]) {
      good[a] = false;
    } else {
      good[a] = false;
      good[b] = false;
    }
  }
  int ans = 0;
  REP(i, n) {
    if (good[i]) ans++;
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 8336
import re,sys
for e in sys.stdin:
 s=any([len(x)>1 and x[0]=='X' for x in re.split('[+=]',e.strip())])
 for i in '0123456789'[s:]:
  if eval(e.replace('X',i).replace('=','==')):print(i);break
 else:print('NA')


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

inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}
//const int INF = 0x3f3f3f3f;
//const int mod=1e9+7;
//const double pi=3.14159265359;
//###################################################################
int main() {
        int n=D();
        int a[n];
        for(int i=0;i<n;i++)a[i]=D();
        sort(a,a+n);
        reverse(a,a+n);
        ll ans=a[0];
        int ind=1;
        for(int i=2;i<n;i++){
            if(i%2==1){
                ans+=1ll*a[ind];
                ind++;
            }else{
                ans+=1ll*a[ind];
            }
        }
        cout<<ans<<"\n";

}

Measured memory_bytes: 4496
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,Q;
int L[20],R[20];
ll dp[10][1<<16];
const ll mo=1000000007;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}


template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<40> uf;

vector<pair<int,int>> C[40];
int ID[40];
ll mul[1<<20];
ll param(int len) {
	ll a=(modpow(10,len)+8);
	ll b=(modpow(10,len)-1);
	return a*modpow(b)%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	vector<int> V;
	FOR(i,Q) {
		cin>>L[i]>>R[i];
		L[i]--;
		V.push_back(L[i]);
		V.push_back(R[i]);
	}
	V.push_back(0);
	sort(ALL(V));
	V.erase(unique(ALL(V)),V.end());
	FOR(i,Q) {
		L[i]=lower_bound(ALL(V),L[i])-V.begin();
		R[i]=lower_bound(ALL(V),R[i])-V.begin();
		uf(L[i],R[i]);
	}
	
	Q=0;
	FOR(i,V.size()) {
		C[uf[i]].push_back({V[i],i});
		if(uf[i]==i) Q++;
	}
	sort(C,C+40);
	reverse(C,C+40);
	int lef=0;
	FOR(i,Q) {
		FORR(c,C[i]) {
			ID[c.second]=i;
			if(c.second==0) lef=1<<i;
		}
	}
	
	int mask;
	FOR(mask,1<<Q) {
		mul[mask]=1;
		FOR(j,V.size()-1) if((mask&(1<<ID[j]))&&(mask&(1<<ID[j+1]))) (mul[mask]*=param(V[j+1]-V[j]))%=mo;
	}
	
	
	dp[0][0]=1;
	FOR(i,9) {
		
		FOR(mask,1<<Q) {
			int cand=mask^((1<<Q)-1);
			for(int sm=cand; sm>=0; sm--) {
				sm&=cand;
				
				if(i==0 && ((sm&lef)==0)) continue;
				if(i && (sm&lef)) continue;
				
				(dp[i+1][mask^sm]+=dp[i][mask]*mul[sm])%=mo;
			}
		}
	}
	
	ll base=modpow(10,N-V.back());
	FOR(i,V.size()-1) base=base*(modpow(10,V[i+1]-V[i])-1)%mo*modpow(9)%mo;
	
	cout<<base*dp[9][(1<<Q)-1]%mo<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 5888
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
         int n = Integer.parseInt(input.readLine());
        StringTokenizer tokenizer;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            tokenizer = new StringTokenizer(input.readLine());
            sum += Math.abs(Integer.parseInt(tokenizer.nextToken()) - Integer.parseInt(tokenizer.nextToken())) + 1;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 22868
object Main extends App {
  import scala.io.StdIn._
  val Array(k,n) = readLine().split(" ").map(_.toInt)
  val a = readLine().split(" ").map(_.toInt)
  var long = k - a(n-1) + a(0)
  for (i <- (0 until(n-1))){
    long = Math.max(long,a(i + 1) - a(i))
  }
  println(k - long)
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}


using namespace std;

lint s[1005][1005];
lint val[1005][1005];

void dodaj(int x1, int y1, int x2, int y2, int val) {
	s[x2][y2] += val;
	if (y1 > 0) s[x2][y1-1] -= val;
	if (x1 > 0) s[x1-1][y2] -= val;
	if (x1 > 0 && y1 > 0) s[x1-1][y1-1] += val;
}

void compute(int k) {
	FORD(i,k,0) FORD(j,k,0) {
		val[i][j] = s[i][j];
		if (i < k) val[i][j] += val[i+1][j];
		if (j < k) val[i][j] += val[i][j+1];
		if (i<k && j<k) val[i][j] -= val[i+1][j+1];
	}
}

void wypisz(int k) {
	FOR(i,0,k+1) {
		FOR(j,0,k+1) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
		cout << endl;
}

int main() {
	make2(n, k);
	FOR(i,0,n) {
		make2(x, y);
		char C = ' ';
		while (C!='W' && C!='B') C = getchar();
		int exp = (C == 'B') ? 1 : 0;
		int a = x/k;
		int b = y/k;
		int col = (a+b)%2;
		int d1 = x - k*a;
		int d2 = y - k*b;
		
		if (exp == col) {
			dodaj(0,0,d1,d2,1);
			dodaj(d1+1,d2+1,k,k,1);
		} else {
			dodaj(0,0,k,k,1);
			dodaj(0,0,d1,d2,-1);
			dodaj(d1+1,d2+1,k,k,-1);
		}
	}
	compute(k);
	lint best = 0;
	FOR(i,0,k+1) FOR(j,0,k+1) {
		best = max(best, max(val[i][j], n - val[i][j]));
	}
	printf("%lld\n", best);
}


Measured memory_bytes: 16000
N,X = map(int,input().split())
A = list(map(int,input().split()))

ans = 0
if A[0]>X:
    ans = A[0]-X
    A[0] -= ans

for i in range(1,N):
    r = max(0, A[i]+A[i-1]-X)
    ans += r
    A[i] -= r

print(ans)

Measured memory_bytes: 14132
fn solve(a: i32, b: i32, c: i32) -> i32 {
    if a - b > c {
        return 0;
    }

    c - (a - b)
}

fn solve_test() {
    assert_eq!(solve(6, 4, 3), 1);
    assert_eq!(solve(8, 3, 9), 4);
    assert_eq!(solve(12, 3, 7), 0);
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let (a, b, c) = parse_line!(i32, i32, i32);
    println!("{}", solve(a, b, c));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

struct Edge {
    ll from, to, weight;
    Edge() : from(0), to(0), weight(0) {}
    Edge(ll f, ll t, ll w) : from(f), to(t), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &g, ll a, ll b, ll w = 1){
    g[a].emplace_back(a, b, w);
    g[b].emplace_back(b, a, w);
}

vector<ll> dijkstra(Graph &g, ll s){
    vector<ll> dist(g.size(), INF);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    
    while(!que.empty()){
        ll cost, idx;
        tie(cost, idx) = que.top();
        que.pop();
        if(dist[idx] < cost) continue;
        for(auto &e : g[idx]){
            auto next_cost = cost + e.weight;
            if(dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    Graph G(N);
    rep(i, N - 1){
        ll a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        add_edge(G, a, b, c);
    }

    ll Q, K;
    cin >> Q >> K;
    --K;

    vector<ll> dist = dijkstra(G, K);

    rep(i, Q){
        ll x, y;
        cin >> x >> y;
        --x, --y;
        print(dist[x] + dist[y]);
    }

    return 0;
}

Measured memory_bytes: 13104
#include<iostream>
#include<algorithm>
#include<set>
#include<cmath>
using namespace std;
static const int MAX_N = 3000;
static const double EPS = 1e-9;
class Point{
    public:
        double x, y;
 
        Point(double x = 0, double y = 0): x(x), y(y) {}
 
        Point operator + (Point p){ return Point(x + p.x, y + p.y);}
        Point operator - (Point p){ return Point(x - p.x, y - p.y);}
        Point operator * (double a){ return Point(a * x, a * y);}
        Point operator / (double a){ return Point(x / a, y / a);}
 
        double abs(){ return sqrt(norm());}
        double norm(){ return x * x + y * y;}
 
        bool operator < (const Point &p) const{
            return x != p.x ? x < p.x : y < p.y;
        }
 
        bool operator == (const Point &p) const{
            return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
        }
};

typedef Point Vector;

int main(){
	for(;;){
		int n;
		Point p[MAX_N];
		set<Point> sa;
		cin >> n;
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			cin >> p[i].x >> p[i].y;
			sa.insert(p[i]);
		}
		int ans = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				Vector v1 = (Vector){p[j].y - p[i].y, p[i].x - p[j].x};
				if((sa.count(p[i] + v1) && sa.count(p[j] + v1)) || (sa.count(p[i] - v1) && sa.count(p[j] - v1))){
					int S = (v1.x + v1.y) * (v1.x + v1.y) - 2 * v1.x * v1.y;
					ans = max(ans, S);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3416