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

int dx[6] = {1, 1, 0, -1, -1, 0};
int dy[6] = {1, 0, -1, -1, 0, 1};
typedef tuple<int, int, int> T;

void solve(int t, int n){
	int a[500][500];
	for(int i=0; i<500; ++i)
		for(int j=0; j<500; ++j)
			a[i][j] = 0;
	for(int i=0; i<n; ++i){
		int x, y;
		cin >> x >> y;
		a[x+200][y+200] = -1;
	}
	int x, y;
	cin >> x >> y;
	a[x+200][y+200] = t+1;
	queue<T> q;
	q.push(T(x+200, y+200, t+1));
	while(!q.empty()){
		T tp = q.front();
		q.pop();
		for(int i=0; i<6; ++i){
			int nx = get<0>(tp)+dx[i];
			int ny = get<1>(tp)+dy[i];
			if(0 <= nx && nx < 500 && 0 <= ny && ny < 500 && a[nx][ny] != -1 && get<2>(tp) - 1 > a[nx][ny]){
				a[nx][ny] = get<2>(tp) - 1;
				if(a[nx][ny] > 1)
					q.push(T(nx, ny, a[nx][ny]));
			}
		}
	}
	int ans = 0;
	for(int i=0; i<500; ++i)
		for(int j=0; j<500; ++j){
			if(a[i][j] > 0)
				++ans;
//			cout << a[i][j] << (j == 60 ? "\n" : " ");
		}
	cout << ans << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int t, n;
		cin >> t >> n;
		if(t == 0 && n == 0) return 0;
		solve(t, n);
	}
}


Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int K_MAX = 1e5+5;
bool reached[K_MAX];

int solve(){
  int K;cin >> K;
  deque<PII> dq(1,PIL(1,1));
  reached[1] = true;
  while(!dq.empty()){
    //cout << dq.front().first SP dq.front().second << endl;
    int n = dq.front().first;
    int count = dq.front().second;
    if(n == 0) return count;
    reached[n] = true;
    int val1 = (n+1)%K;
    int val2 = (n*10)%K;
    dq.pop_front();
    if(val2==0) return count;
    if(!reached[val2]) dq.push_front(PII(val2,count));
    if(!reached[val1]) dq.push_back(PII(val1,count+1));
  }
  return 0;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cout << solve() << endl;
  return 0;
}




Measured memory_bytes: 896
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  int n,tmp=0,x=0;
  cin>>n;
  string s;
  cin>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='I') tmp=tmp+1;
    if(s[i]=='D') tmp=tmp-1;
    if(tmp>x) x=tmp;
  }
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	long long n;
	long long k,ex,sum=0;
	cin>>n;
	for(long long i=1;i<=n;i++){
		sum+=i;
		if(sum==n){
			k=i;
			ex=0;
			break;
		}
		if(sum>n){
			k=i;
			ex=sum-n;
			break;
		}
	}
	for(long long i=1;i<=k;i++){
		if(i!=ex){
			cout<<i<<endl;
		}
	}
}


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

int main()
{
  int a,b;
  int h,m,s;

  cin >> a >> b;

  if(a < b){
    cout << "a < b" << endl;
  }else if(a > b){
    cout << "a > b" << endl;
  }else{
    cout << "a == b" << endl;
  }
  
  return 0;
} 

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

using namespace std;


void dfs(vector<vector<int>> &Graph, vector<bool> &visited, vector<int>&dp, int node) {
    visited[node] = 1;
    for(int i : Graph[node]) {
        if(!visited[i]) {
            dfs(Graph, visited, dp, i);
        }
        dp[node] = max(dp[node], 1 + dp[i]);
    }
}

int path(vector<vector<int>> &Graph, int n) {
    vector<bool> visited(n+1, 0);
    vector<int> dp(n+1, 0);
    for(int i=1;i<=n;i++) {
        if(!visited[i]) {
            dfs(Graph, visited, dp, i);
        }
    }
    int ans = 0;
    for(auto i : dp) ans = max(ans, i);
    return ans;

}


int main() {

    int m, n;
    cin>>n>>m;
    vector<vector<int>> Graph(n + 1, vector<int>());
    int a, b;
    
    for(int i = 0; i<m;i++) {
        cin>>a>>b;
        Graph[a].push_back(b);
    }
    // for(auto V : Graph) {
    //     for(auto i: V) {
    //         cout<<i<<" ";
    //     }
    //     cout<<'\n';
    // }
    cout<<path(Graph, n)<<'\n';
    
    return 0;
}

Measured memory_bytes: 9472
// AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define FORREV(i,N,_cnt) for(auto i=N-1,cnt=_cnt; cnt > 0; --i, --cnt)
#define ALL(x) x.begin(), x.end()

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
/* clang-format on */

constexpr ll MOD = ll(1e9 + 7);
int main() {
#ifdef DEBUG
	ifstream ifs("in.txt");
	cin.rdbuf(ifs.rdbuf());
#endif
	string S; cin >> S;
	reverse(ALL(S));
	const int N = S.size();
	//vector < vector<ll> > dp(N + 1, );
	auto dp = make_v(N + 1, 2, 0LL);
	dp[0][1] = 1;
	FOR(_i, N) {
		auto i = N - 1 - _i;
		auto c = S[i];
		if (c == '1') {
			// 1を守って 1 -> 1, Aが1, Bが2で2パターン
			// 0 にして 1 -> 0
			// 0->0 これは(0,0), (1,0), (0,1) の3パターン
			(dp[_i + 1][1] += dp[_i][1] * 2) %= MOD;
			(dp[_i + 1][0] += dp[_i][1]) %= MOD;
			(dp[_i + 1][0] += dp[_i][0] * 3) %= MOD;
		}
		else {
			// 0 をとって、 1 -> 1, 0 -> 0
			(dp[_i + 1][1] += dp[_i][1]) %= MOD;
			(dp[_i + 1][0] += dp[_i][0] * 3) %= MOD;
		}
	}
	cout << (dp[N][1] + dp[N][0]) % MOD << endl;
	

	return 0;
}


Measured memory_bytes: 5760
package main

import (
	"fmt"
	"math"
)

var A, B int

func main() {
	fmt.Scan(&A, &B)
	fmt.Println((A + B) % 24)
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }
func ceil(x int) int      { return int(math.Ceil(float64(x))) }

type si struct {
	s int
	i int
}

type SortBy []si

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i].s < a[j].s }


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

N,M=map(int,input().split())
B=[list(map(int,input().split())) for i in range(N)]

B.sort()
j=0

import heapq
H=[]
ANS=0


for day in range(1,M+1):
    while j<N and B[j][0]<=day:
        heapq.heappush(H,-B[j][1])
        j+=1

    if H:
        ANS+=-heapq.heappop(H)


print(ANS)
        

    


Measured memory_bytes: 68060
n,m = map(int,input().split())

binary = 2**(n)

lamps={i:[] for i in range(m)}


for i in range(m):
    temp=list(map(int,input().split()))
    lamps[i]=[temp[1:]]
ps=list(map(int,input().split()))

for i,p in enumerate(ps):
    lamps[i].append(p)


pattern=0
for i in range(binary,binary*2):
    check_flg=True
    i_binary = bin(i)
    switch = list(map(int, list(i_binary[2:])))
    for sws, on_flg in lamps.values():
        sums=0
        for s_index in sws:
            if switch[s_index] == 1:
                sums+=1
        if sums%2!=on_flg:
            check_flg=False
            break
    if check_flg:
        pattern+=1
print(pattern)

Measured memory_bytes: 3064
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  int min = 1145141919;

  REP(i,n){
    int a;
    cin >> a;
    int num = 0;
    while (a % 2 == 0)
    {
      a /= 2;
      num++;
    }
    min = min > num ? num : min;
  }

  cout << min << endl;
}


Measured memory_bytes: 256
N = int(input())
ans = 0
plus = []
minus = []
A =[]
zero =0
for i in  [int(n) for n in input().split()]:
    A.append(abs(i))
    if i > 0:
        plus.append(i)
    elif i<0:
        minus.append(i)
    else:
        zero += 1
if len(minus)%2 == 0:
    print(sum(plus)-sum(minus))
else:
    if zero > 0:
        print(sum(plus)-sum(minus))
    else:
        odd = min(A)
        print(sum(A)-2*odd)

Measured memory_bytes: 14480
@==1..<>;@$_[@=]=map[glob<>],@=for 1,2;$\=-5e9;for$i(1..1023){$c=0;$c+=$2[$j=$_][grep$1[$j][$_]&$i>>$_,0..9]for@=;$\+=$-=$c-$\}print

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ll n;
    cin >> n;
    double q = sqrt(n);
    ll ans = 0;

    vi aa;

    for(int i=0; ++i<q;) {
        if(n%i == 0) {
            aa.push_back(i);
            aa.push_back(n/i);
        } 
    }

    for(ll i:aa) {
        if(i-1 && n%(i-1) == n/(i-1)) {
            ans += i-1;
        }
    }

    cout << ans << endl;
}

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

int main(){
  int n,s,a,b;
  while(cin>>a>>b>>n){
    s=0;
    a%=b;
    for(int i=1;i<=n;i++){
      a*=10;
      s+=a/b;
      a%=b;
    }
    cout<<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<endl
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define endl "\n"
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
bool compare(pair<ll,ll> p1,pair<ll,ll> p2){
return p1.se>p2.se;
}
void solve(){
    ll n;
    cin>>n;
    set<string> s;
    fr(i,0,n){
    string a;
    cin>>a;
    s.insert(a);
    }
    cout<<s.size()<<endl;
}

int main()
{   fast;
    ll t=1;
    //cin>>t;
    fr(zz,1,t+1){
    solve();
    }
}


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

int main() {
  
  int N, a, b; cin >> N; vector<int> vecN(N, 0);
  
  for (int i = 0; i < N; i++) vecN.at(i) = i + 1;
  
  vector<int> vecA(N); vector<int> vecB(N);
  
  for (int i = 0; i < N; i++) cin >> vecA.at(i);
  
  for (int i = 0; i < N; i++) cin >> vecB.at(i);
  
  int count = 1;
  
  do {
    
    if (vecN == vecA) a = count; if (vecN == vecB) b = count;
    
    count++;
    
  } while (next_permutation(vecN.begin(), vecN.end()));
  
  cout << abs(a - b) << endl;
  
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var x int
	fmt.Scan(&x)
	ans := 1
	for i := 2; i <= x; i++ {
		n := i * i
		for n <= x {
			if n > ans {
				ans = n
			}
			n *= i
		}
	}
	fmt.Println(ans)
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<int> l, r;
    auto getPositions = [&]() {
        vector<int> res;
        for (int i = 0; i < n && res.size() < k; i++) {
            if (s[i] == 'o') {
                res.pb(i);
                i += c;
            }
        }
        return res;
    };
    l = getPositions();
    reverse(all(s));
    r = getPositions();
    rep(i, k) {
        r[i] = n - 1 - r[i];
    }
    reverse(all(s));

    vector<int> lastL(n+1, -1);
    rep(i, k) {
        lastL[l[i]+1] = i;
    }
    rep(i, n) {
        if (lastL[i+1] == -1) lastL[i+1] = lastL[i];
    }
    vector<int> lastR(n+1, -1);
    rep(i, k) {
        lastR[r[i]] = i;
    }
    for (int i = n - 1; i >= 0; i--) {
        if (lastR[i] == -1) lastR[i] = lastR[i+1];
    }

    rep(i, n) {
        if (s[i] == 'x') continue;
        int li = lastL[i];
        int ri = lastR[i+1];
        int cnt = 0;
        if (li != -1) cnt += li + 1;
        if (ri != -1) cnt += ri + 1;
        if (li != -1 && ri != -1 && r[ri] - l[li] <= c) --cnt;
        if (cnt >= k) continue;
        cout << i + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 5004
def main():
	n,m = map(int,input().split())
	a = list(map(int,input().split()))
	wa = [0,(1/2 * a[0] * (a[0] +1))/a[0]]
	for i in range(1,n):
		wa.append(wa[i] + (1/2 * a[i] * (a[i]+1))/a[i])
	ans = wa[m-1]
	for i in range(m,len(wa)):
		ans = max(wa[i]-wa[i-m],ans)
	print(ans)
	
 
if __name__ == '__main__':
	main()

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

int main(void)
{
	char cards[3][101];
	scanf("%s", cards[0]);
	scanf("%s", cards[1]);
	scanf("%s", cards[2]);

	char *p[3] = {cards[0], cards[1], cards[2]};
	int n = 0;
	char c;
	while(1) {
		c = *p[n];
		if (!c) break;

		p[n]++;
		switch (c) {
			case 'a':
				n = 0;
				break;
			case 'b':
				n = 1;
				break;
			case 'c':
				n = 2;
				break;
			default:
				return 1;
		}
	}
	switch (n) {
		case 0:
			printf("A\n");
			break;
		case 1:
			printf("B\n");
			break;
		case 2:
			printf("C\n");
			break;
		default:
			return 1;
	}

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N;
    string s;
    cin >> N;
    int AC, WA, TLE, RE;
    AC = WA = TLE = RE = 0;
    while(N--){
        cin >> s;
        if(s == "AC"){
            ++AC;
        } else if(s == "WA"){
            ++WA;
        } else if(s == "TLE"){
            ++TLE;
        } else if(s ==  "RE"){
            ++RE;
        }

    }
    cout <<"AC x "<<AC<<endl<<"WA x "<<WA<<endl<<"TLE x "<<TLE<<endl<<"RE x "<<RE<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(){
#ifdef CIN
	ifstream cin("input.txt");
	// ofstream cout("output.txt");
	freopen("output.txt", "w", stdout);
#endif

	double x;
	cin >> x;

	double a, b;

	a = x * x * 3.1415926535897932384626433832795;
	b = 2 * x * 3.1415926535897932384626433832795;

	printf("%lf %lf\n", a, b);

	return 0;
}

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

int main(){
  int num[5];
  cin>>num[0]>>num[1]>>num[2]>>num[3]>>num[4];
  sort(num,num+5,greater<int>());
  for(int i=0;i<4;i++)
    cout<<num[i]<<" ";
  cout<<num[4]<<endl;
  return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound 

int main()
{
  ll a;
  string b;
  cin>>a>>b;
  int bb;
  bb=(b[0]-'0')*100+(b[2]-'0')*10+(b[3]-'0');
  ll c = a*bb;
  c /=100;
  cout<<c<<endl;
}

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

typedef long long ll;
typedef long double ld;
#define blue ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007;
/*
int globalN;
int dp[100009][3];

int dping(int happiness[][3], int selected, int tillNow, int day) {
  if(day>=globalN) return tillNow;
  int a[3];
  for(int i=0;i<3;i++) {
    if(i==selected) a[i]=0;
    else {
      if(dp[day+1][i] == -1) a[i] = dping(happiness,i, tillNow+happiness[day][i],day+1);
    }
  }
  return max(a[0], max(a[1],a[2]));
}
*/


int main() {
  blue;
  int n;
  cin>>n;
  // globalN=n;
  int dp[n][3];
  int happiness[n][3];
  // memset(dp,-1,sizeof(dp));
  for(int i=0;i<n;i++)
    for(int j=0;j<3;j++)
      cin>>happiness[i][j];

  dp[0][0]=happiness[0][0];
  dp[0][1]=happiness[0][1];
  dp[0][2]=happiness[0][2];
  
  for(int i=1;i<n;i++) {
    for(int j=0;j<3;j++) {
      dp[i][j]=happiness[i][j] + max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3] );
    }
  }
  int one=dp[n-1][0];
  int two=dp[n-1][1];
  int three=dp[n-1][2];
  // int one=dping(happiness,0,happiness[0][0],1);
  // int two=dping(happiness,1,happiness[0][1],1);
  // int three=dping(happiness,2,happiness[0][2],1);

  cout<<max(one,max(two,three));


}

/*
  
*/

Measured memory_bytes: 2560
package main
 
import (
	"fmt"
)
 
func main() {
	var n, c, m int
	var s string
	fmt.Scan(&n, &s)
	t := []rune(s)
	for i := 1; i < n; i++ {
		c = 0
		l := map[string]int{}
		r := map[string]int{}
		for j := 0; j < i; j++ {
			l[string(t[j])]++
		}
		for v := i; v < n; v++ {
			r[string(t[v])]++
		}
		for k, _ := range l {
			if r[k] > 0 {
				c++
			}
		}
		if c >= m {
			m = c
		}
	}
	fmt.Println(m)
}

Measured memory_bytes: 896
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
	string s;
	cin >> s;
	char a, b, c;
	a = s.at(0), b = s.at(1), c = s.at(2);
	int sum = 0;
	if (a == '1') sum += 1;
	if (b == '1') sum += 1;
	if (c == '1') sum += 1;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const long long MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const ll INF = (1 << 28);
const ll dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const ll Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a / gcd(a, b)*b;
}
struct edge {
    ll to, cost;
};
ll n;
vector<ll> a;
map<ll, ll> res;
void prime_factor(ll n){
    map<ll, ll> res1;
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            ++res1[i];
            if(res1[i]>res[i]){
                res[i]=res1[i];
            }
            n/=i;
        }
    }
    if(n!=1&&res[n]==0) res[n]=1;
    //for(ll i=2;i<=n;i++)cout<<res[i]<<"\n";
    //return res;
}
void prime_factorm(ll n){
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            --res[i];
            n/=i;
        }
    }
    if(n!=1) res[n]=1;
    //for(ll i=2;i<=n;i++)cout<<res[i]<<"\n";
    //return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll power(ll x, ll n){
    x %= MOD;
    ll res = 1;
    while(n > 0){
        if(n&1){
            res = res*x % MOD;
        }
        x = x*x %MOD;
        n >>= 1;
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (ll i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        a.push_back(temp);

    }
    for(ll i=0;i<n;i++){
        prime_factor(a[i]);
    }
    ll koubai=1;
    for(int i=1;i<=1000000;i++){
        koubai*=power(i,res[i]);
        koubai%=MOD;
    }
    ll ans = 0;
    for(ll i=0;i<n;i++){
        ll temp=koubai*modinv(a[i],MOD);
        ans+=temp;
        ans%=MOD;
    }
    cout << ans << "\n";
}



Measured memory_bytes: 62848
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <tuple>
#include <vector>
using namespace std;

int N;
double dp[303][303][303];

double calc(int i, int j, int k){
    if(dp[i][j][k] >= 0.0) return dp[i][j][k];
    double p1 = 1.0*i/N;
    double p2 = 1.0*j/N;
    double p3 = 1.0*k/N;
    double q = p1+p2+p3;

    double tmp = 0.0;
    if(i > 0){
        dp[i-1][j][k] = calc(i-1, j, k);
        tmp += p1*dp[i-1][j][k];
    }
    if(j > 0){
        dp[i+1][j-1][k] = calc(i+1, j-1, k);
        tmp += p2*dp[i+1][j-1][k];
    }
    if(k > 0){
        dp[i][j+1][k-1] = calc(i, j+1, k-1);
        tmp += p3*dp[i][j+1][k-1];
    }
    dp[i][j][k] = (tmp+1)/q;
    return dp[i][j][k];
}

int main(){
    cin >> N;
    int one = 0;
    int two = 0;
    int thr = 0;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        if(a == 1) one++;
        else if(a == 2) two++;
        else thr++;
    }
    for(int i=0; i<=300; i++)
        for(int j=0; j<=300; j++)
            for(int k=0; k<=300; k++)
                dp[i][j][k] = -1.0;
    dp[0][0][0] = 0.0;
    cout << fixed << setprecision(32) << calc(one, two, thr) << endl;
    return 0;
}


Measured memory_bytes: 217472
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
const double pie  =3.141592653589793238463;
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n" 
#define t4(x,y,z,a) cout<<"x is "<<x<<"    y is "<<y<<"    z is "<<z<<"    a is "<<a<<endl;
#define t3(x,y,z) cout<<"x is "<<x<<"    y is "<<y<<"    z is "<<z<<endl;
#define t2(x,y) cout<<"x is "<<x<<"    y is "<<y<<endl;
#define t1(x) cout<<"x is "<<x<<endl;
using namespace std;
int main()
{
    // fastio
    ll t,i,j,k,l,m,n,a,b,x,y,z,c,d,e,p,nl,np,q,r;
    string str2,str3;
    ll mx=INT_MIN;
    ll mn=INT_MAX;
    ll ans=0,s1=0,s2=0;
    cin>>a>>b>>c>>k;
    if(a+b>=k)
    {
        cout<<min(a,k)<<endl;
    }
    else
    {
        cout<<a-(k-(a+b))*(1)<<endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int dp[100005][20];

inline void solve(){

    string str;

    cin >> str;
    
    dp[0][0] = 1;
    for(int i = 0; i < str.length(); i++) {
        int x = (str[i] == '?' ? -1 : str[i]-'0');
        for(int j = 0; j < 10; j++) {
            if(x != -1 && x != j) continue;
            for(int k = 0; k < 13; k++) {
                dp[i+1][(k*10+j)%13] += dp[i][k];
            }
        }
        for(int j = 0; j < 13; j++) dp[i+1][j] %= SMOD;
    }
    cout << dp[str.length()][5] << endl;
    
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 16080
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	int x=0;
	cin>>a>>b>>c;
	for(int i=0;;i++)
	{
		if(b>a)
			break;
		b*=2;
		x++;
	}
	for(int i=0;;i++)
	{
		if(c>b)
			break;
		c*=2;
		x++;		
	}
	int k;
	cin>>k;
	if(k>=x)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>
#define maxn 200010
int a[maxn],head[maxn],tot,n,d[maxn],ans,mx[maxn];
struct node{
	int to,next;
}e[maxn<<1];
void add_edge(int u,int v){
	tot++,e[tot].to=v,e[tot].next=head[u],head[u]=tot;
}
void dfs(int u,int fa){
	int b,v,save,flag,l,r,mid;;
	for(b=head[u];b;b=e[b].next){
		v=e[b].to;
		if(v==fa)continue;
		save=ans,flag=0;
		if(d[ans]<a[v])d[++ans]=a[v];
		else{
			l=0,r=ans;
			while(l+1<r){
				mid=(l+r)/2;
				if(d[mid]<a[v])l=mid;
				else r=mid;
			}
			flag=d[r],d[r]=a[v];
		}
		mx[v]=ans;
		dfs(v,u);
		ans=save;
		if(flag)d[r]=flag;
	}
}
void init(){
	int i,u,v;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v),add_edge(v,u);
	}
}
int main(){
	init();
	ans=1,d[1]=a[1],mx[1]=1;
	dfs(1,0);
	for(int i=1;i<=n;i++)printf("%d\n",mx[i]);
	return 0;
}

Measured memory_bytes: 20188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)

int main() {
	int n;
	string o[52],s[52],much;
	cin >> n;
	rep(i, 0, n) {
		cin >> o[i];
		s[i] = o[i];
		//cout << s[i] << " " << o[i] << endl;
	}
	rep(i, 0, s[0].size()) {
		char m = s[0][i];
		//cout << m <<" "<<"start"<< endl;
		bool flag = true;
		rep(j, 1, n) {
			if (s[j].find(m) == -1) {
				flag = false;
				break;
			}
		}
		if (flag == true) {
			rep(j, 0, n) {
				//cout << s[j].find(m) << endl;
				//s[j].erase(s[j].begin() + s[j].find(m),s[j].end());
				s[j].replace(s[j].find(m), 1, "*");
				//cout << s[j]<< endl;
			}
			much += m;
		}
	}
	sort(much.begin(), much.end());
	cout << much << endl;
}

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

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	vector<int> cnt1(s.length() + 1, 0), cnt2(t.length() + 1, 0);
	for (int i = 1; i <= s.length(); i++) {
		cnt1[i] = (s[i - 1] - 'A' + 1);
		cnt1[i] += cnt1[i - 1];
	}
	for (int i = 1; i <= t.length(); i++) {
		cnt2[i] = (t[i - 1] - 'A' + 1);
		cnt2[i] += cnt2[i - 1];
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--;
		c--;
		bool flag = ((cnt1[b] - cnt1[a]) % 3 == (cnt2[d] - cnt2[c]) % 3);
		cout << (flag ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 1744
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  	int A,B;
    cin >> A >> B;
  	int sum = 0;  
  
  	for(int i=A;i<B+1;i++){
		int e = A%10;
        int d = A%100/10;
        int c = A%1000/100;
        int b = A%10000/1000;
        int a = A/10000;
        if(a==e && b==d)
          	sum += 1;
      	A += 1;
    }
  cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <map>
#include <set>

using namespace std;

int main() {
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    set<int> water;
    set<int>::iterator itr,it;
    double dens = 0;
    int sugar;
    int liquid = 100*a,maxsugar = 0;
    for(int i = 0; i < f; i++) {
        for(int j = 0; j < f; j++) {
            if(f >= 100*a*i + 100*b*j) {
                water.insert(100*a*i + 100*b*j);
            }
        }
    }
    for(int t:water) {
        for(int i = 0; i < f; i++) {
            for(int j = 0; j < f; j++) {
                sugar = c*i + d*j;
                if(t+sugar > f || 100*sugar > t*e) {
                    break;
                }
                if(100*sugar > dens*(t+sugar)) {
                    dens = 100.0*sugar/(t+sugar);
                    liquid = t+sugar;
                    maxsugar = sugar;
                }
            }
        }
    }
    cout << liquid << " " << maxsugar;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;

signed main(){
  int n,m;
  cin>>n>>m;
  int p[100000];
  int y[100000];
  vector<int> yd[100001];
  for(int i=0;i<m;i++){
    cin>>p[i]>>y[i];
    yd[p[i]].push_back(y[i]);
  }
  for(int i=0;i<n;i++)sort(yd[i+1].begin(),yd[i+1].end());
  for(int i=0;i<m;i++)printf("%012lld\n",(int)p[i]*1000000+(int)(lower_bound(yd[p[i]].begin(),yd[p[i]].end(),y[i])-yd[p[i]].begin())+1LL);
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  int K;
  cin >> K;
  int cnt = 0;
  while (B <= A) {
    B *= 2;
    cnt++;
  }
  while (C <= B) {
    C *= 2;
    cnt++;
  }
  if (cnt <= K) {
    cout << "Yes" << endl; 
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>

#define n 5

int main() {
    int includeNumber[10000] = { 0 };
	int searchNumber[500] = { 0 };
	int needIN, needSN;
	int count;
	int i, j;
	count = 0;
	
	scanf("%d", &needIN);
	for (i = 0; i < needIN; i++) {
		scanf("%d", &includeNumber[i]);
	}
	scanf("%d", &needSN);
	for (i = 0; i < needSN; i++) {
		scanf("%d", &searchNumber[i]);
	}

	for (i = 0; i < needIN; i++) {
		for (j = 0; j < needSN; j++) {
			if (includeNumber[i] == searchNumber[j]) {
				searchNumber[j] = -1;
				count++;
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 648
#include<iostream>
using namespace std;
int main()
{
	int A1, A2, A3;
	cin >> A1 >> A2 >> A3;
	
	
		if ((A1 + A2 + A3) >= 22)
			cout << "bust\n";
		else
			cout << "win\n";
	


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll x = a[0], y = a[1], z = 0;
    for (int i = 2; i < n; i++) {
        z ^= a[i];
    }
    if ((x + y - z) % 2 != 0) {
        cout << -1 << '\n';
        return 0;
    }
    ll t = (x + y - z) / 2;
    for (int i = 0; i < 60; i++) {
        if ((t & (1LL << i)) && (z & (1LL << i))) {
            cout << -1 << '\n';
            return 0;
        }
    }
    if (t > x) {
        cout << -1 << '\n';
        return 0;
    }
    debug(t, x);
    for (int i = 60; i >= 0; i--) {
        if (z & (1LL << i)) {
            if ((t | (1LL << i)) <= x) {
                t |= 1LL << i;
            }
        }
    }
    if (t == 0) {
        cout << -1 << '\n';
        return 0;
    }
    cout << x - t << '\n';
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
using namespace std;
using ll = long long;

int main(){
	int n, cnt, max_cnt;
	ll a;
	cin >> n;
	cnt = 0;
	for(int i=0; i<n; i++){
		cin >> a;
		for(;;){
			if(a%2 == 0){
				a /= 2;
				cnt++;
				continue;
			}else{
				break;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())

man = -1
gosen = -1
sen = -1

for i in range(N+1):
  for j in range(N+1):
    k = N-i-j
    if Y == i*10000+j*5000+k*1000 and k >= 0:
      print(i, j, k)
      exit()
      
print(-1, -1, -1)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int[] a = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
		Scanner sc = new Scanner(System.in);
		int b = sc.nextInt() - 1;
		System.out.println(a[b]);

	}
}

Measured memory_bytes: 21716
A = str(input())
B = str(input())

a = len(A)
b = len(B)

if a > b:
    print ('GREATER')
    exit()
elif a < b:
    print ('LESS')
    exit()

for i in range(a):
    c = int(A[i])
    d = int(B[i])
    if c > d:
        print ('GREATER')
        exit()
    elif c < d:
        print ('LESS')
        exit()

print ('EQUAL')

Measured memory_bytes: 3064
from collections import deque
 
h, w = map(int, input().split())
s = [input() for i in range(h)]
 
d = [[h+w for j in range(w)] for i in range(h)]
que = deque()
 
#黒だったらスタートキューに入れる
for i in range(h):
  for j in range(w):
    if s[i][j]=='#':
        que.append((i, j))
        d[i][j] = 0
 
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
 
 
while que:
    p = que.popleft()
    # 黒にする4方向をループ
    for i in range(4):
        nx = p[1] + dx[i]
        ny = p[0] + dy[i]
 
        if (0<=nx<w) and (0<=ny<h) and (d[ny][nx]==h+w):
            que.append((ny, nx))
            d[ny][nx] = d[p[0]][p[1]] + 1
 
res = max(map(max, d))
print(res)


Measured memory_bytes: 88028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n) {
        int l, r;
        cin >> l >> r;
        ans += (r-l+1);
    }
    
    cout << ans << endl;
    return 0;
}


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

ll L,R;

int main(){
  cin >> L >> R;

  if((R-L) >= 2019){
    cout << 0 << endl;
    return 0;
  }

  ll N = R-L+1;
  ll ans = 2019;

  for(int l=L;l<=R-1;l++){
    for(int r=L+1;r<=R;r++){
      ll result = ((l % 2019) * (r % 2019)) % 2019;
      ans = min(ans,result);
    }
  }

  cout << ans << endl;
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int A[110000], B[110000];
pint Ai[110000], Bi[110000];
int G[110000];
bool visited[110000];
int cnt = 0;
void dfs(int x) {
    if (visited[x]) { return; }
    cnt++;
    visited[x] = true;
    dfs(G[x]);
}
signed main() {
    cin >> N;
    rep(i, N) { cin >> A[i], Ai[i] = {A[i], i}; }
    rep(i, N) { cin >> B[i], Bi[i] = {B[i], i}; }
    sort(Ai, Ai + N);
    sort(Bi, Bi + N);
    rep(i, N) {
        if (Ai[i].first > Bi[i].first) { fin("No"); }
    }
    rep(i, N) {
        G[Ai[i].second] = Bi[i].second;
    }
    dfs(0);
    if (cnt != N) { fin("Yes"); }
    for (int i = 1; i < N; i++) {
        if (Ai[i].first <= Bi[i - 1].first) { fin("Yes"); }
    }
    fin("No");
}

Measured memory_bytes: 6016
using System;

namespace ABC090_B_Palindromic_Numbers
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			int a = int.Parse(input[0]);
			int b = int.Parse(input[1]);

			int count = 0;
			for (int i = a; i <= b; i++)
			{
				string firstword = i.ToString().Substring(0, 1);
				string secondWord = i.ToString().Substring(1, 1);
				string beforeLastWord = i.ToString().Substring(3, 1);
				string lastWord = i.ToString().Substring(4, 1);

				if (firstword == lastWord && secondWord == beforeLastWord)
				{
					count++;
				}
			}
			
			Console.WriteLine(count);
		}
	}
}

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

#define NDEBUG
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


class UnionFind {
  vector<int> data;
 public:
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

#define IJ(i,j) (i)*W+(j)


void solve(int H,int W,vs& m){
    vvi a(H,vi(W,0)), b(H,vi(W,0));

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

    rep(i,H) rep(j,W) if (m[i][j] == '#') a[i][j] = b[i][j] = 1;


    rep(i,H){
        rep(j,W) putchar(".#"[a[i][j]]);
        putchar('\n');
    }
    putchar('\n');
    rep(i,H){
        rep(j,W) putchar(".#"[b[i][j]]);
        putchar('\n');
    }
}

int main() {
    int H, W; cin >> H >> W;
    vs a(H);
    rep(i,H) cin >> a[i];
    solve(H,W,a);
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
using namespace std;
int main()
{
	string s;
	while(cin>>s,s!="0"){
		int sum=0;
		for(int i=0;i<s.size();i++) sum+=(int)s[i]-(int)'0';
	cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 1188
N,Q  = map(int, input().split())

# 木
G = [[] for i in range(N)]
for i in range(N-1):
    u,v = map(int,input().split())
    G[u-1].append((v-1))
    G[v-1].append((u-1))

## クエリを覚えておく
scores = [0]*N
for i in range(Q):
    p,x = map(int, input().split())
    scores[p-1] += x 

# 和をとっていく
ans = [0]*N
ans[0] = scores[0]
used = [False] * N

"""
dfs TLEする。なんで
"""
# import sys
# sys.setrecursionlimit(100000)
# def dfs(G, v):
#    # vを訪問済みにする
#    used[v] = True
#    #グラフ中の次のVについて
#    for next_v in G[v]:
#        if used[next_v]: continue
#        ans[next_v] = ans[v] + scores[next_v]
#        dfs(G, next_v)
# dfs(G,0)
# print(*ans)

# 木をBFSをする
from collections import deque
used = [False] * N
used[0] = True # 始めどこから行くか
q = deque([0])
while len(q) > 0:
    v = q.popleft()
    Vs = G[v]
    for next_v in Vs: 
        if not used[next_v]:
            q.append(next_v)
            ans[next_v] = ans[v] + scores[next_v]
            used[next_v] = True
print(*ans)

Measured memory_bytes: 108080
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
  int P, Q, R;
  cin >> P >> Q >> R;
  int ans = min(P+Q, min(Q+R, R+P));

  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
//set<pair<ll,ll>> spll;
//map<string,ll> mp;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<ll> deq;
//vector<ll> vll;
ll num[ten5],pp[ten52],mm[ten52];
//priority_queue<ll> pq;          //decreasing

int main(void)
{
    ll m,n,i,j,k,l,r;
    cin>>n;
    cout<<n+n*n+n*n*n;
    return 0;
}





Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n, a;
	cin >> n;
	long long ans = 0;
	int mini = 0;

	for (int i = 0; i < n; i++) {
		cin >> a;

// printf("i %d, a %d, mini %d, ans %lld\n", i, a, mini, ans);
		if (i == 0) {
			ans += a - 1;
			mini = 1;
			continue;
		}

		if (a == mini + 1) {
			mini++;
			continue;
		}

		if (a > mini) {
			ans += a / (mini + 1);
			if (a % (mini + 1) == 0) {
				ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split(' ')))
min_a = a.pop(a.index(min(a)))
while len(a) != 0:
    a = [x%min_a for x in a if x%min_a != 0]
    a.append(min_a)
    min_a = a.pop(a.index(min(a)))
print(min_a)

Measured memory_bytes: 14252