akhauriyash/Code-Regression huggingface dataset:
# AOJ 2832 All Japan Association of Return home
# Python3 2018.7.12 bal4u

n, d = map(int, input().split())
ans = t0 = f0 = num = 0
for i in range(n):
	t, f = map(int, input().split())
	f -= 1
	df = f-f0
	if df < 0: df = -df
	dt = t - t0
	if dt < df:	ans = -1; break
	if dt >= f0+f:
		ans += num*f0
		num = 0
	else:
		if num+1 > d: ans = -1; break
		ans += num*dt
	f0, t0 = f, t
	num += 1
print(-1 if ans < 0 else ans+num*f0)


Measured memory_bytes: 5620
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 30);
const double PI = acos(-1);

//解説AC

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	ll T = 1, A = 1;
	REP(i, N) {
		int t, a;
		cin >> t >> a;
		ll n = max(T / t + (T%t == 0 ? 0 : 1), A / a + (A%a == 0 ? 0 : 1));
		T = t * n;
		A = a * n;
	}
	cout << T + A << endl;
	PAU;
	return 0;
}


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

n, m, l = list(map(int, input().split()))
a = []
b = []

for i in range(n):
    a.append(list(map(int, input().split())))

for i in range(m):
    b.append(list(map(int, input().split())))

for i in range(n):
    for j in range(l):
        mat_sum = 0
        for k in range(m):
            mat_sum += a[i][k] * b[k][j]
        if j == l - 1:
            print('{0}'.format(mat_sum), end='')
        else:
            print('{0} '.format(mat_sum), end='')
    print()


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

#define ll long long

#define pll pair<ll, ll>
#define pi pair<int,int>

map<pll,int> black;

struct mat
{
	int r, c;
	bool operator<(const mat& b) const
	{
		return (pi(this->r,this->c) < pi(b.r,b.c));
	}
	bool operator=(const mat& b) const
	{
		return (pi(this->r,this->c) == pi(b.r,b.c));
	}
};

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

map<mat,int> found;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	ll R[n], C[n];
	for(int i = 0; i < n; i++)
	{
		cin >> R[i] >> C[i];
		black[pll(R[i],C[i])] = 1;
	}
	ll ans[10];
	memset(&ans,0,sizeof(ans));
	ll tt = 0;
		int total = 0;
		for(int i = 0; i < n; i++)
		{
			//cout << "original: " << R[i] << " " << C[i] << endl;
			for(int px = 0; px < 3; px++)
			{
				if(R[i]+dx[px] > h-2 || R[i]+dx[px] <= 0) continue;
				int cnt = 0;
				int st = 0;
				for(int py = 0; py < 3; py++)
				{
					//cout << "new: " << R[i]+dx[px] << " " << C[i]+dy[py] << endl;
					if(C[i]+dy[py] > w-2 || C[i] + dy[py] <= 0) continue;
					mat rect;
					rect.r = R[i]+dx[px], rect.c = C[i]+dy[py];
					if(found.count(rect))
					{
						continue;
					}
					if(st == 0)
					{
						cnt = 0;
						for(int r = 0; r < 3; r++)
						{
							for(int c = 0; c < 3; c++)
							{
								int blck_cnt = black.count(pll((R[i]+dx[px])+r,(C[i]+dy[py])+c));
								//cout << blck_cnt << " ";
								if(blck_cnt)
								{
									cnt ++;
								}
							}
						//	cout << endl;
						}
					}
					else
					{
					/*	for(int r = 0; r < 3; r++)
						{
							for(int c = 0; c < 3; c++)
							{
								int blck_cnt = black.count(pll((R[i]+dx[px])+r,(C[i]+dy[py])+c));
								cout << blck_cnt << " ";
							}
							cout << endl;
						}*/
						for(int r = 0; r < 3; r++)
						{
							int blck_cnt = black.count(pll((R[i]+dx[px])+r,(C[i]+dy[py-1]+2)));
							int blck_cnt2 = black.count(pll((R[i]+dx[px])+r,(C[i]+dy[py])));
							cnt -= blck_cnt;
							cnt += blck_cnt2;
						}
					}
						found[rect]=cnt;
						ans[cnt]++;
						tt++;
					//cout << endl;
					st++;
				}
			}
		}
	ans[0] = ((h-2)*(w-2))-tt;
	for(int j = 0; j <= 9; j++)
	{
		cout << ans[j] << endl;
	}
	return 0;
}


Measured memory_bytes: 64384
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
from bisect import bisect,bisect_right,bisect_left

def get_int():
    return int(stdin.readline().strip())


def get_tuple():
    return map(int, stdin.readline().split())


def get_list():
    return list(map(int, stdin.readline().split()))

s = input()
t =input()
c = 0
for i in range(len(s)):
    if s[i]!=t[i]:
        c += 1
print(c)

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

vector<vector<char>>grid;

int h, w;

bool find(int x, int y, int c){
  if(grid[x][y]=='.' || c<0)return false;
  if(c==0 && x==h && y==w)return true;
  return (find(x+1, y, c-1) || find(x, y+1, c-1));
}

int main(){
  cin >> h >> w;
  int c=0;
  grid.resize(h+2, vector<char>(w+2, '.'));
  for(int i=1; i<=h; i++){
    for(int j=1; j<=w; j++){
      cin >> grid[i][j];
      if(grid[i][j]=='#')c++;
    }
  }
  if(find(1, 1, c-1))cout << "Possible";
  else cout << "Impossible";
  return 0;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <deque>
using namespace std;

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

int P[100005]={};
int trank[100005]={};

int findP(int x){
  if(P[x]!=x)return findP(P[x]);
  return x;
}

void setP(int n){
  for(int i=0;i<n;i++){
    P[i]=i;
  }
}

bool isUnit(int x, int y){
  return (findP(x)==findP(y));
}
void Link(int x, int y){
  if(isUnit(x,y))return;
  int px,py;
  px=findP(x);py=findP(y);
  if(trank[px]>=trank[py]){
    if(trank[px]==trank[py])trank[px]++;
    P[py]=px;
  }else{
    P[px]=py;
  }
}
class EDGE{
public:
  int p1,p2;
  ll d;
  EDGE(){}
  EDGE(int p1,int p2,ll d):p1(p1),p2(p2),d(d){}
  bool operator <(EDGE e){return d<e.d;}
};

class Point{
public:
  ll x,y;
  int id;
  void set(ll x,ll y, int id){
    this->x=x;this->y=y;this->id=id;}
};

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

Point poi[100005];

int main(){
  int n;
  ll ans=0;
  vector<EDGE> f;
  cin>>n;
  setP(n);
  for(int i=0;i<n;i++){
    ll x,y;
    cin>>x>>y;
    poi[i].set(x,y,i);
  }
  sort(poi,poi+n,lessX);
  for(int i=0;i<n-1;i++){
    ll x1,x2;
    int p1,p2;
    p1=poi[i].id;p2=poi[i+1].id;
    x1=poi[i].x;x2=poi[i+1].x;
    EDGE e(p1,p2,abs(x1-x2));
    f.push_back(e);
  }
  sort(poi,poi+n,lessY);
  for(int i=0;i<n-1;i++){
    ll y1,y2;
    int p1,p2;
    p1=poi[i].id;p2=poi[i+1].id;
    y1=poi[i].y;y2=poi[i+1].y;
    EDGE e(p1,p2,abs(y1-y2));
    f.push_back(e);
  }
  sort(f.begin(),f.end());
  for(auto&& e:f){
    int p1,p2;
    ll d;
    p1=e.p1;p2=e.p2;d=e.d;
    if(isUnit(p1,p2))continue;
    Link(p1,p2);
    ans+=d;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 9200
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define N 100010
using namespace std;
int num[N],n;
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
bool work()
{
	
	return !work();
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&num[i]);
	bool ans=0;
	while(true)
	{
		int cnt=0;
		bool one=false;
		for(int i=1;i<=n;i++)
		{
			if(num[i]==1) one=true;
			if(num[i]&1) cnt++;
		}
	
		if((n-cnt)&1){ans^=1;break;}
		if(one || cnt>1)break;
	
		for(int i=1;i<=n;i++)
		if(num[i]&1) {num[i]--;break;}
	
		int g=num[1];
		for(int i=2;i<=n;i++) g=gcd(g,num[i]);
		for(int i=1;i<=n;i++) num[i]/=g;
		ans^=1;
	}
	puts(ans?"First":"Second");
	return 0;
}


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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 100100;
int bal[N];

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	string s;
	getline(cin, s);
	int n = sz(s);
	pii ans = mp(-2, -2);
	forn(i, 26) {
		bal[0] = 0;
		int tek = 0;
		int bst = 0, pos = 0;
		forn(j, sz(s)) {
			if (s[j] == char('a' + i)) {
				tek++;
			} else {
				tek--;
			}
			bal[j + 1] = tek;
			if (j) {
				if (tek > bst) {
					ans = mp(pos, j);			
				}
				if (umn(bst, bal[j])) {
					pos = j;
				}
			}	
		}		
	}
	cout << ans.fs + 1 << ' ' << ans.sc + 1 << endl;
	return 0;
}


Measured memory_bytes: 896
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var in = newIo(bufio.NewScanner(os.Stdin))
var mod = int64(1000000007)

func main() {
	in.setSplit(bufio.ScanLines)
	var buf = strings.Split(in.next(), " ")
	var n, m = parseLong(buf[0]), parseLong(buf[1])
	print(solve(n, m))
}

func print(result int64) {
	fmt.Println(result)
}

func solve(n int64, m int64) int64 {
	var primes = []int64{}
	for i := int64(2); i <= m; i++ {
		count := int64(0)
		for m%i == 0 {
			m /= i
			count++
		}
		if count != 0 {
			primes = append(primes, count)
		}
	}
	var result = int64(1)

	for i := 0; i < len(primes); i++ {
		result *= combination(primes[i]+n-1, primes[i]) % mod
		result %= mod
	}
	return result % mod
}

func combination(n int64, k int64) int64 {
	factN := int64(1)
	for i := int64(2); i <= n; i++ {
		factN *= i % mod
		factN %= mod
	}
	invNr := inverse(n - k)
	invK := inverse(k)
	return ((factN * invK) % mod) * invNr % mod
}

func inverse(n int64) int64 {
	fact := int64(1)
	for i := int64(2); i <= n; i++ {
		fact *= i % mod
		fact %= mod
	}
	return modPow(fact, mod-2, mod)
}
func modPow(b int64, e int64, m int64) int64 {
	result := int64(1)
	for e > 0 {
		if e&1 == 1 {
			result = (result * b) % m
		}
		e >>= 1
		b = (b * b) % m
	}
	return result
}

type io struct {
	sc *bufio.Scanner
}

func newIo(sc *bufio.Scanner) *io {
	i := new(io)
	i.sc = sc
	i.sc.Buffer([]byte{}, math.MaxInt64)
	i.sc.Split(bufio.ScanWords)
	return i
}

func (i *io) setSplit(f bufio.SplitFunc) {
	i.sc.Split(f)
}

func (i *io) nextIntSlice(y int, delim string) [][]int {
	result := make([][]int, y)
	for j := 0; j < y; j++ {
		line := i.next()
		result[j] = parseIntSlice(strings.Split(line, delim))
	}
	return result
}

func (i *io) next() string {
	i.sc.Scan()
	return i.sc.Text()
}

func (i *io) nextInt() int {
	return parseInt(i.next())
}

func (i *io) nextLong() int64 {
	return parseLong(i.next())
}

func parseInt(s string) int {
	in, _ := strconv.Atoi(s)
	return in
}

func parseLong(s string) int64 {
	in, _ := strconv.ParseInt(s, 10, 64)
	return in
}

func parseIntSlice(s []string) []int {
	var r = make([]int, len(s))
	for i := 0; i < len(s); i++ {
		r[i] = parseInt(s[i])
	}
	return r
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int n,k,b,a[200001],s;
int main()
{
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>b,a[b]++;
sort(a,a+n);
for(int i=n-1;i>=n-k;i--)
s+=a[i];
cout<<n-s<<endl;
return 0;
}


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

int main() {
  int N;
  string S;
  cin>>N>>S;
  int count=0;
  for(int i=0;i<1000;i++){
    int a,b,c;
    a=i/100;
    b=(i-100*a)/10;
    c=i-100*a-10*b;
    char x,y,z;
    x='0'+a;
    y='0'+b;
    z='0'+c;
    
    int fi,se,th;
    bool judge=false;
    rep(j,N){
      if(S.at(j)==x){
        judge=true;
        fi=j;
        break;
      }
    }
    if(judge==false){continue;}
    judge=false;
    for(int j=fi+1;j<N;j++){
      if(S.at(j)==y){
        judge=true;
        se=j;
        break;
      }
    }
    if(judge==false){continue;}
    judge=false;
    for(int j=se+1;j<N;j++){
      if(S.at(j)==z){
        judge=true;
        th=j;
        break;
      }
    }
    if(judge){count++;}
  }
  cout<<count<<endl;
}





Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=2005;
const int mod=1000000007;

int n,k,ans;
int dp[N][N];

int main(){
	int i,j;
	scanf("%d%d",&n,&k);
	for (i=1;i<=n;i++) dp[0][i]=1;
	for (i=1;i<k;i++){
		for (j=i+1;j<=n;j++) dp[i][j]=(dp[i][j-1]+dp[i-1][j])%mod;
	}
	ans=dp[k-1][n];
	for (i=1;i<=n-k-1;i++) ans=ans*2%mod;
	ans=(ans%mod+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 15360
n=int(input())
h=list(map(int,input().split())) 
dp=[0]*(n)
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1])) 
print(dp[-1])

Measured memory_bytes: 20316
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;
 
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
 
#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif
 
#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
 
inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}
 
inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}
 
inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}
 
inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}
 
inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}
 
inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

int n;
int l[100000], r[100000], diff[100000];
int ans;

void solve() {
  for ( int i = 0; i < n; i++){
    diff[i] = r[i] - l[i] + 1;
    ans += diff[i];
  }
  cout << ans << endl;
}

int main() {
  cin >> n ;
  for ( int i = 0; i < n; i++){
    cin >> l[i] >> r[i] ;
  }

  solve();

  return 0;
}

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

int n, l, s, m;

int main(){
	cin >> n;
	s = m = 0;
	for (int i = 0; i < n; ++i){
		cin >> l;
		s += l;
		if (m < l) m = l;
	}
	cout << (s - m > m ? "Yes" : "No");
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
  typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second
#define all v.begin(),v.end()
#define fio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
typedef unsigned long long ulll;
 
using namespace std ;
int main () {

  string s;
  cin>>s;
  
  int ct=0;
  if(s[0]==s[1]&&s[1]==s[2])
    ct++;
    
    if(s[1]==s[2]&&s[2]==s[3])
       ct++;
    
    if(ct>0)
       cout<<"Yes";
       else
       cout<<"No";
   
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	int n; cin >> n;
	string st; cin >> st;
	long long int base = 0;
	long long int fstj = 0;
	long long int lsti = 0;
	long long int mido = 0;
	{
		long long int jnum = 0;
		long long int inum = count(st.begin(), st.end(), 'I');
		for (int i = 0; i < st.size(); ++i) {

			mido = max(jnum*inum, mido);
			if (st[i] == 'I') {
				inum--;
			}
			else if (st[i] == 'O') {
				base += jnum*inum;
				fstj += inum;
				lsti += jnum;
			}
			else {
				jnum++;
			}
			mido = max(jnum*inum, mido);
		}
	}
	cout << base + max(max(fstj, lsti), mido) << endl;
	
	return 0;
}

Measured memory_bytes: 3276
#include<iostream>
#include<map>
#include<string>
#include<stdio.h>
using namespace std;

int main (void){

	string str,maxByLength("");
	//map<int,string> X; //¶Ì·³
	map<string,int> Y; //¶Ì
	//int mm;

	while (cin>>str){
		if (str.size()>maxByLength.size())	maxByLength=str;
		Y[str]++;
	}

	string maxByCount("");
	int cnt = 0;
	for(map<string, int>::iterator it = Y.begin(); it != Y.end(); ++it) {
		if(it->second > cnt) {
			maxByCount = it->first;
			cnt = it->second;
		}
	}

	cout << maxByCount << " " << maxByLength << endl;

	// cout << (*Y.rbegin()).first << " " << maxByLength << endl;
	return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#define Union(x,y) fa[Find(x)]=Find(y)
using namespace std;
int n,m,fa[200003],ans=-(1<<30),s=1,a[200003];
int Find(int x)
{
    return x==fa[x]?x:fa[x]=Find(fa[x]);
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++) fa[i]=i;
    while(m--){
        int a,b;
		cin>>a>>b;
        int roota=Find(a),rootb=Find(b);
        if(roota!=rootb) Union(a,b);
    }
    for(int i=1;i<=n;i++)
		a[i]=Find(fa[i]);
    sort(a+1,a+1+n);
    for(int i=2;i<=n;i++)
	{
        if(a[i]==a[i-1]) s++;
        else ans=max(ans,s),s=1;
    }
    ans=max(ans,s);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 11396
n,s=map(int,input().split()) 
a=list(map(int,input().split()))
d=[[0]*(s+1) for _ in range(n+1)]
d[0][0]=1
for j in range(0,s+1):
    for i in range(1,n+1):
        d[i][j]=2*d[i-1][j]
        if a[i-1]<=j:
            d[i][j]+=d[i-1][j-a[i-1]]
        d[i][j]=d[i][j]%998244353
print(d[n][s])

Measured memory_bytes: 132540
N, x = map(int, input().split())

if N == 2:
    if x == 2:
        print("Yes")
        print(1)
        print(2)
        print(3)
    else:
        print("No")

else:
    from collections import deque
    used = [True] + [False] * (2 * N)
    if x == 1 or x == 2*N-1:
        print("No")
        exit()
    elif x == 2:
        ans = deque([3, 1, 2, 4, 5])
        for i in range(1, 6):
            used[i] = True
    elif x == 3:
        ans = deque([4, 1, 3, 5, 2])
        for i in range(1, 6):
            used[i] = True
    else:
        ans = deque([x-3, x-1, x, x+1, x-2])
        for i in range(-3, 2):
            used[x+i] = True

    p = 0
    for i in range(2*N):
        if not used[i]:
            p^=1
            if p:
                ans.append(i)
            else:
                ans.appendleft(i)

    print("Yes")
    for e in list(ans):
        print(e)

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, n) for (auto i : (n))
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int N, M;
int s[5], c[5];

bool ok(int i) {
  REP(m, M) {
    int j = i;
    REP(si, N - s[m]) j /= 10;
    if (i == 702) DBG(N, m, s[m], c[m], j);
    if (j % 10 != c[m])  return false;
  }
  return true;
}

int main() {
  cin >> N >> M;
  REP(i, M) cin >> s[i] >> c[i];

  int minimum = 1;
  REP(n, N - 1) minimum *= 10;
  if (N == 1) minimum = 0;
  int maximum = 1;
  REP(n, N) maximum *= 10;

  int ans = -1;
  for (int i = minimum; i < maximum; ++i) {
    if (ok(i)) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

void printVector(vector<int> A) {
    for (int i = 0; i < A.size(); ++i) {
        if (i == 0) cout << A[i];
        else cout << " " << A[i];
    }
    cout << endl;
}

// 挿入ソート
vector<int> insertionSort(vector<int> A) {
    int N = A.size();
    // 整列済みでない要素を順に見ていく
    for (int i = 1; i < N; ++i) {
        // 対象の要素を変数vに退避
        int v = A[i];
        int j = i - 1;
        // vより大きい要素を後ろにずらしていく
        while(A[j] > v && j >= 0) {
            A[j+1] = A[j];
            --j;
        }
        // ずらして空いたスペースにvを挿入
        A[j+1] = v;
        printVector(A);
    }
    return A;
}

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    printVector(A);
    insertionSort(A);
}


Measured memory_bytes: 3148
#include <stdio.h>
int main(){
  
 int H, W, i, j;
 while(1) {
 scanf("%d%d", &H, &W);
 if(H == 0 && W == 0) break;
 for(i = 1; i <= H; i++) {
  for(j = 1; j <= W; j++) {
   printf("#");
  }
 printf("\n");
 }
 printf("\n");
 }
  
 return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> h(n), diffs(n);
  for (auto&& e : h) {
    cin >> e;
  }
  adjacent_difference(cbegin(h), cend(h), begin(diffs));
  replace_if(begin(diffs), end(diffs), [](auto&& n){return n < 0;}, 0);
  cout << accumulate(begin(diffs), end(diffs), 0) << endl;
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	var A = make([]int, n)
	for i := range A {
		sc.Scan()
		A[i], _ = strconv.Atoi(sc.Text())
	}

	sc.Scan()
	for sc.Scan() {
		m, _ := strconv.Atoi(sc.Text())
		if solve(0, m, A) {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

func solve(i int, m int, A []int) bool {
	if m == 0 {
		return true
	}
	if i >= len(A) {
		return false
	}
	return solve(i+1, m, A) || solve(i+1, m-A[i], A)
}



Measured memory_bytes: 1084
N = int(input())
H = list(map(int, input().split()))
points = [0]*N
points[1] = abs(H[1]-H[0])
for i in range(2,N):
    points[i] = min(points[i-2]+abs(H[i-2]-H[i]), points[i-1]+abs(H[i-1]-H[i]))
print(points[-1])

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

using namespace std;
using ll = long long;

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


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

    int d, g; cin >> d >> g;
    vector<int> p(d);
    vector<int> c(d);
    REP(i, d) {
        cin >> p.at(i) >> c.at(i);
    }

    int min_solved = 1000000000;

    for (int i = 0; i < 1 << d; i++) {
        bitset<10> bit(i);

        int current_g = 0;
        int solved = 0;

        for (int x = 0; x < d; x++) {
            if (bit.test(x)) {
                current_g += (100 * (x + 1) * p.at(x) + c.at(x));
                solved += p.at(x); 
            }
        }

        if (current_g >= g) {
            min_solved = min(min_solved, solved);
            continue;
        }

        bool flag = false;

        for (int x = d - 1; x >= 0; x--) {
            if (!bit.test(x)) {
                for (int y = 0; y < p.at(x); y++) {
                    current_g += 100 * (x + 1);
                    solved++;

                    if (current_g >= g) {
                        min_solved = min(min_solved, solved);
                        flag = true;
                        break;
                    }
                }
            }
            if (flag) break;
        }
    }

    cout << min_solved << endl;
    
    return 0;
}

Measured memory_bytes: 256
"use strict";

function Main(input) {
  let nums = input.split(' ').map(x => x*1);
  let Tnum = nums[0] - nums[2];
  let Anum = nums[1];
    if(Tnum < 0){
      Anum = nums[1]  + nums[0]  - nums[2];
      Tnum = 0;
    }
    if(Anum < 0){
      Anum = 0;
    }

  console.log(Tnum + " " +Anum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 21064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by S64 on 15/07/26.
 */
class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] inputs = br.readLine().split(" ");
        int arg1 = Integer.parseInt(inputs[0]);
        int arg2 = Integer.parseInt(inputs[1]);
        int rectangle, length;
        {
            rectangle = arg1 * arg2;
            length = (arg1 + arg2) * 2;
        }
        {
            System.out.println( String.format("%d %d", rectangle, length) );
        }
    }

}

Measured memory_bytes: 16904
#include <iostream>

int main(){
   std::string A, B;
   std::cin >> A >> B;

   if(A.size()>B.size()) std::cout << "GREATER" << std::endl;
   else if(A.size()<B.size()) std::cout << "LESS" << std::endl;
   else {
      for(int i=0; i<A.size(); ++i){
	 if(A[i]>B[i]) {
	    std::cout << "GREATER" << std::endl;
	    return 0;
	 }else if(A[i]<B[i]) {
	    std::cout << "LESS" << std::endl;
	    return 0;
	 }
      }
      std::cout << "EQUAL" << std::endl;
   }

   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define INF                          1e9+5
#define int                          long long
#define mod                          1000000007  // 1e9 + 7 >>>  ans%mod
#define greator_sort(arr,n)          sort(arr, arr+n, greater<int>())  //descending order sorting of array
#define mk(arr,n,type)               type*arr = new type[n];    //to make array dynamically // n = size_of_array  |  type = int or long long etc;                      
#define w(x)                         int x;cin>>x; while(x--)   //x = test cases
#define pb                           push_back

/*void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
//}
//WINES PROBLEMS TUTORIAL EXPLANATION-----------------------------------------------------------------------
/*int profit(int wines[], int i, int j, int y, int dp[][100]) {
	//base case
	if (i > j) {
		return 0;
	}

	//return if dp[i][j]
	if (dp[i][j] != 0) {
		return dp[i][j];
	}

	//recursive case
	int op1 = wines[i] * y + profit(wines, i + 1, j, y + 1, dp);
	int op2 = wines[i] * y + profit(wines, i, j - 1, y + 1, dp);

	return dp[i][j] =  max(op1, op2);

}



int32_t main()
{
	c_p_c();
	int wines[] = {2, 3, 5, 1, 4};
	int dp[100][100] = {0};
	int y = 1;
	int n = sizeof(wines) / sizeof(int);
	cout << profit(wines, 0, n - 1, y, dp);

	return 0;

}
*/
//-------------------------------------------------------------------------------------------------------------------------//
//
//
//SOLUTION OF   FROG 1---------------------------------------------------->

/*int ans(int a[], int n, int dp[]) {
	//base case
	dp[1] = 0;

	//recursive case
	for (int i = 2; i <= n ; ++i)
	{
		int op2;
		int op1 = abs(a[i] - a[i - 1]) + dp[i - 1];
		if (i != 2)
			op2 = abs(a[i] - a[i - 2]) + dp[i - 2];
		if (i == 2)
			dp[i] = op1;
		else
			dp[i] = min(op1, op2);
	}
	return dp[n];
}



int32_t main()
{
	c_p_c();
	int n; cin >> n; //size of the array
	int a[n];//height array
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	int dp[n + 1] = {0};
	cout << ans(a, n, dp) << endl;
}
*/
/*--------------------------------------------------------------------------
/...................FROG 2 PROBLEM SOLUTION--------------------------------

int32_t main()
{
	c_p_c();
	int n , k;
	cin >> n >> k;

	int a[n + 1];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	vector<int> dp(n, INF);
	//base case
	dp[0] = 0;
	//recursive case
	for (int i = 0; i < n; ++i)
	{
		for (int j = i + 1; j <= i + k; ++j)
		{
			if (j < n)
				dp[j] = min(dp[j], abs(a[i] - a[j]) + dp[i]);
		}
	}
	cout << dp[n - 1] << endl;
}
*/
int32_t main()
{
	//c_p_c();
	int n; cin >> n;
	vector<int> dp(3);
	for (int day = 0; day < n; day++)
	{
		vector<int> newdp(3, 0);
		vector<int> c(3);
		for (int i = 0; i < 3; ++i)
			cin >> c[i];

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (i != j) {
					newdp[j] = max(newdp[j], dp[i] + c[j]);
				}
			}
		}
		dp = newdp;
	}
	cout << max({dp[0], dp[1], dp[2]}) << endl;
}




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

using namespace std; 

int main() {
  
  int a,b,c; cin >> a >> b >> c;
  
  int max_num = max(a,max(b,c));
  int min_num = min(a,min(b,c));  
  int mid_num = a + b + c - max_num - min_num;
  
  int ans = max_num - mid_num;
  
  int diff_c = mid_num - min_num;
    
  if (diff_c % 2 == 1) {
    ans++;
    diff_c++;
  }
  
  while(diff_c > 0){
    diff_c -= 2;
    ans++;
  }
  
  cout << ans << endl;
}

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

#define ll long long
#define MP make_pair
#define PB push_back
#define P push
#define f first
#define se second
#define S size()
#define B begin()
#define E end()
#define fscan1(n)  scanf("%d",&(n));
#define fscan2(n,m)  scanf("%d %d",&(n),&(m));
#define fscan3(n,m,k)  scanf("%d %d %d",&(n),&(m),&(k));

using namespace std;

const ll oo=1e18+1;
const int N=2e5+1001;
const int M=2010;



int main() {
    
    int n;
    cin>>n;
    
    int u=n/2;
    int x=n-u;
    cout<<u*x<<endl;
    
    
    return 0;
}





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

#define PI acos(-1)
#define pb push_back
#define lli long long int
#define mp make_pair
#define pi pair<int, int>
#define pii pair<pi, int>
#define fir first
#define sec second
#define MAXN 100001
#define MAXL 20
#define mod 1000000007

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  unordered_map<string, int> m;
  for (int i = 0; i < n; i++)
  {
    string s;
    cin >> s;
    m[s]++;
  }
  cout << "AC x " << m["AC"] << endl;
  cout << "WA x " << m["WA"] << endl;
  cout << "TLE x " << m["TLE"] << endl;
  cout << "RE x " << m["RE"] << endl;
  return 0;
}

Measured memory_bytes: 3664
<?php
$cnt = 0;
fscanf(STDIN,"%d %d %d",$a ,$b, $c);
for($i = 1; $i <= 100; $i++){
    if($i % $c === 0){
        if($i >= $a && $i <= $b){
            $cnt++;
        }
    }
}
echo $cnt;

Measured memory_bytes: 15548
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>

#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair

typedef long long  ll;
using namespace std;
int inf = 1e9;
const int N = 100005;
int n, m;
vector<int> g[N];
bool was[N];

void dfs(int v){
    was[v] = true;
    for(int to : g[v]){
        if(!was[to]){
            dfs(to);
        }
    }
}

int main(){
    faster
    cin >> n >> m;
    int cnt = 0;
    for(int i = 0;i < m;i++){
        int x, y; cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int i = 1;i <= n;i++){
        if(!was[i]){
            dfs(i);
            cnt++;
        }
    }
    cout << cnt - 1 << endl;
    return 0;
}


Measured memory_bytes: 9184
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b;
  cin >> a >> b;
  cout << 6 - a - b << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

using namespace std;

int main(int argc, char **argv) {
	int n, t, a;
	cin >> n >> t >> a;
	double h = (t - a) / 0.006;
	int pos = 0;
	double diff = -1.0;
	for (int i = 0; i < n; i++) {
		int newh;
		cin >> newh;
		double newdiff = abs(h - (double)newh);
		if (diff < 0 || newdiff < diff) {
			pos = i;
			diff = newdiff;
		}
	}
	cout << pos + 1 << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i=0; i<(n); i++)//第一引数の変数をカウンタ変数としてn回回す
//repはカウンタ変数が1ずつ増える場合にしか使えない
int INF = 10101010;
using veci = vector<int>;
using vecd = vector<double>;
int main(){//まず全種類のドーナツを作り、次に使用する粉が最も少ないものを調べ、それの
  //使用する粉の量で残った粉の量を割る
  int n, x;
  cin >> n >> x;
  int min_p = INF;
  int ans;
  rep(i, n){
    int a;
    cin >> a;
    min_p = min(a, min_p);
    x -= a;
    ans++;
  }
  int y = x/min_p;
  ans += y;
  cout << ans << endl;
}

Measured memory_bytes: 256
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

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


long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

int a[MAXN];

set <int> v[2];

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt();
    for (int i = 1; i <= n; i++) {
    	a[i] = readInt();
    	v[(i - 1) % 2].insert(a[i]);
    }
    sort(a + 1, a + 1 + n);
    int res1 = 0;
    int res2 = 0;
    for (int i = 1; i <= n; i++) {
    	if ((i - 1) % 2 == 0) {
    		if (v[(i - 1) % 2].find(a[i]) == v[(i - 1) % 2].end()) {
    			res1++;
    		}
    	} else {
    		if (v[(i - 1) % 2].find(a[i]) == v[(i - 1) % 2].end()) {
    			res2++;
    		}
    	}
    }
    cout << max(res1, res2);
    return 0;
}

Measured memory_bytes: 5376
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		System.out.println((int)Math.pow(Integer.parseInt(br.readLine()), 3));
	}
}

Measured memory_bytes: 24144
#include<stdio.h>
void call(int n);

int main(void){
   int n;
   scanf("%d",&n);
   call(n);
   return 0;
}


void call(int n){
  int i = 1;

  do{
  int x = i;
  if ( x % 3 == 0 ){printf(" %d",i);  }
  else {
     do{
        if ( x % 10 == 3 ){printf(" %d",i);break;}
        x =x/10;
        }while( x );
     }
  }while( ++i <= n );
  printf("\n");
}

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

int main(void) {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    string str;
    while(cin >> str) {
        int len = str.length();
        int cnt = 0;
        bool flag = true;
        int l = 0, r = len - 1;
        while(l < r) {
            if(str[l] == str[r]) ++l, --r;
            else if(str[l] == 'x') ++l, ++cnt;
            else if(str[r] == 'x') --r, ++cnt;
            else {
                flag = false;
                break;
            }
        }
        cout << (flag ? cnt : -1) << endl;
    }
}


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

using namespace std;

int main()
{
  int N, A[100000];
  cin >> N;
  int nim = 0;
  bool sz[30] = {};
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    nim ^= A[i];
    sz[__builtin_popcount(A[i] ^ (A[i] - 1)) - 1] = true;
  }
  int ret = 0;
  for(int i = 30; i >= 0; i--) {
    if((nim >> i) & 1) {
      if(!sz[i]) {
        cout << -1 << endl;
        return (0);
      }
      ++ret;
      nim ^= (1 << 31) - 1;
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 640
#include<iostream> 
#include<stdio.h>
#include<string>
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (int i = 0; i < (n); ++i)	
//setprecision(16)

void outi(int x) { cout << x << endl; }
void outl(ll x) { cout << x << endl; }
void outs(string x) { cout << x << endl; }
ll max(ll a, ll b) {
	ll max;
	if (a > b) max = a;
	else max = b;
	return max;
}
ll min(ll a, ll b) {
	ll min;
	if (a < b) min = a;
	else min = b;
	return min;
}
int gcd(int x, int y) {
	/*最大公約数 O(log MAX_X)*/
	if (y == 0) return x;
	return gcd(y, x % y);
}
//---------------------------------------------------------------

int main() {

	int n;
	cin >> n;
	if (n % 1000 == 0)
		cout << 0 << endl;
	else
	cout << 1000 - (n % 1000) << endl;
}

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

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

    for (char si :S)
    {
       int t = (int)si + N;
       if (t>90) t -= 26;
       cout << (char)t;
    }
    cout << endl;

}

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

using namespace std;

vector<long long> getDiv(long long x)
{
    vector<long long> Res;
    Res.clear();
    Res.push_back(1);
    int Lim = sqrt(x) + 1;
    for (int i = 2; i <= Lim; i++)
    {
        if (x % i == 0)
        {
            int SZ = Res.size();
            long long t = 1;
            while (x % i == 0)
            {
                t = t * i;
                x /= i;
                for (int j = 0; j < SZ; j++)
                {
                    Res.push_back(Res[j] * t);
                }
            }
        }
    }
    if (x > 1)
    {
        int SZ = Res.size();
        for (int i = 0; i < SZ; i++)
        {
            Res.push_back(Res[i] * x);
        }
    }
    return Res;
}

long long n;
set<long long> Ans;

bool Check(long long N, long long K)
{
    if (N % K == 0)
    {
        return Check(N / K, K);
    }
    if (N % K == 1)
    {
        return true;
    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    Ans.clear();
    vector<long long> v = getDiv(n - 1);
    for (long long x : v)
    {
        if (x > 1 && Check(n, x))
        {
            Ans.insert(x);
        }
    }
    v = getDiv(n);
    for (long long x : v)
    {
        if (x > 1 && Check(n, x))
        {
            Ans.insert(x);
        }
    }
    cout << Ans.size();
    return 0;
}


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

const ll mod = 1e9 + 7;
int main()
{
    int N;
    cin >> N;
    char S1[60], S2[60];
    cin >> S1;
    cin >> S2;

    vector<bool> Q;
    for(int i = 0; i < N; ){
        if(i+1 < N && S1[i] == S1[i+1]) {
            Q.push_back(false);
            i += 2;
        }
        else {
            Q.push_back(true);
            i += 1;
        }
    }

    ll res = 0;
    for(int i = 0; i < Q.size(); ++i) {
        if(i == 0) {
            if(Q[i]) res += 3;
            else res += 6;
            continue;
        }

        bool prev = Q[i-1], cur = Q[i];
        if(prev && cur) { res *= 2; res %= mod; }
        else if(!prev && cur) { res *= 1; }
        else if(prev && !cur) { res *= 2; res %= mod;}
        else { res *= 3; res %= mod; }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b; cin >> a >> b;
    if((a+b)%2 == 1){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    cout << (a+b)/2 << endl;

}


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cerr<<#x<<" = "<<x<<endl

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    li s;

    cin>>s;

    const li M=1e9+7;

    vector<vi> dp(2050,vi(2050,0));

    f(j,3,s)
    {
        dp[1][j]=1;
    }

    f(j,1,s)
    {
        dp[1][j]+=dp[1][j-1];
        dp[1][j]%=M;
    }

    li ans;

    if(s>=3)
        ans=1;
    else
        ans=0;

    f(i,2,s/3)
    {
        f(j,3,s)
        {
            dp[i][j]=dp[i-1][j-3];
        }

        ans+=dp[i][s];
        ans%=M;

        f(j,1,s)
        {
            dp[i][j]+=dp[i][j-1];
            dp[i][j]%=M;
        }
    }

    cout<<ans;
}

int main()
{    
    //remove this in kickstart

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

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

    li t=1;

    // cin>>t;

    f(i,1,t)
    {
        // cout<<"Case #"<<i<<": ";

        solve();
    }

    return 0;
}

Measured memory_bytes: 36192