akhauriyash/Code-Regression huggingface dataset:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(deftype int32 () '(signed-byte 32))
(deftype int64 () '(signed-byte 64))


;;macros
(defmacro println (n)
  `(format t "~a~%" ,n))
(defmacro vint-out (vec)
  `(progn
     (rep i (length ,vec)
          (princ (vref ,vec i))
          (princ " "))
     (fresh-line)))


(defmacro rep (i n &body body)
  `(dotimes (,i ,n) ,@body))

(defmacro rep1 (i s g &body body)
  `(loop for ,i from ,s below ,g
      do ,@body))

;;vector
(defmacro vec (type &optional (num 100) (val 0))
  (let* ((g (gensym)))
    `(let* ((,g ,num))
       (make-array ,g :element-type ',type :initial-element ,val
                   :adjustable nil :fill-pointer ,g))))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vint (&optional (num 0) (val 0))
  `(vec int32 ,num ,val))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vref (vector pos &optional value)
  (let ((g (gensym)))
    `(let ((,g ,value))
       (if ,g
           (setf (aref ,vector ,pos) ,g)
           (aref ,vector ,pos)))))

(defmacro chvar (sym comp predicate)
  (let ((g (gensym)))
    `(let ((,g ,comp))
       (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))
           (setf ,sym ,g)))))

(defmacro chmax (sym comp &optional (predicate #'>))
  `(chvar ,sym ,comp ,predicate))

(defmacro chmin (sym comp &optional (predicate #'<))
  `(chvar ,sym ,comp ,predicate))

;;本体

(defun ctoi (c)
  (- (char-int c) (char-int #\0)))

(defun main()
  (let ((n-str (read-line)) (n 0) sn)
    (setf sn (reduce #'+ (map 'vector #'ctoi n-str)))
    (dotimes (i (length n-str))
         (setf n (+ n (* (ctoi (aref (reverse n-str) i)) (expt 10 i)))))
    (if (zerop (mod n sn))
        (println "Yes")
        (println "No"))))



#-swank(main)



Measured memory_bytes: 21092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner vd = new Scanner(System.in);
		String[] s = vd.next().split("");
		int[] n = new int[4];
		for(int i=0; i<s.length; i++) n[i]=Integer.parseInt(s[i]);
		if( (n[0]==n[1] && n[1]==n[2]) || (n[1]==n[2]&&n[2]==n[3]) ) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21716
fun main(args: Array<String>){
    val N = nextInt()
    val A = listOfLong().toLongArray()

    fun dfs(A: LongArray, left: Int, right: Int, c_l: Int, c_r: Int): Long {
        var ans = 0L
        if (left + 1 != right) {
            ans = Long.MAX_VALUE
            for (i in left + 1 until right) {
                ans = Math.min(ans, dfs(A, left, i, c_l, c_l + c_r) + dfs(A, i, right, c_l + c_r, c_r) + (c_l + c_r) * A[i])
            }
        }
        return ans
    }

    val ans = dfs(A, 0, N - 1, 1, 1) + A[0] + A[N - 1]
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { it.toLong() }


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

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

int main(){
  int n;
  cin >> n;
  vector<int> d(n);

  REP(i,n){
    cin >> d[i];
  }

  sort(all(d));
  cout << d[(n-1)/2+1]-d[(n-1)/2] << endl;
}


Measured memory_bytes: 640
S = input()
T = input()

search_str = ["?" for x in range(len(T))]

last_occ = -1

for i in range(len(S)) :    
    if i < len(S) - len(T) + 1:
        ok_cnt = 0
        for j in range(len(T)) :
            if S[i + j] == T[j] or S[i + j] == "?" :
                ok_cnt += 1

        if ok_cnt == len(T) :
            last_occ = i
            
if last_occ != -1 :
    str_tmp = S[0:last_occ] + T + S[last_occ + len(T):]
    print(str_tmp.replace("?", "a"))
else :
    print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
#include <string.h>
#include <bitset>
#include <queue>
using namespace std;

typedef pair<int, int> P;
#define INF (1LL<<60)
#define int long long
#define ll long long
#define mod 1000000007

struct UnionFind {
	vector< int > data;

	UnionFind(int sz) {
		data.assign(sz, -1);
	}

	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return (false);
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return (true);
	}

	int find(int k) {
		if (data[k] < 0) return (k);
		return (data[k] = find(data[k]));
	}

	int size(int k) {
		return (-data[find(k)]);
	}
};


signed main(){

	int N, M;
	cin >> N >> M;
	vector<int> a(M), b(M);
	for (int i = 0; i < M; i++){
		cin >> a[i] >> b[i];
	}

	int ans = 0;
	// nが橋か
	for (int n = 0; n < M; n++){
		UnionFind u(N);
		for (int i = 0; i < M; i++){
			if (i == n) continue;
			u.unite(a[i]-1, b[i]-1);
		}
		int count = 0;
		for (int i = 0; i < N; i++){
			if (u.unite(0, i)) count++;
		}
		if (count > 0) ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using V = vector<int>;
using VV = vector<vector<int>>;
int Inf = (1<<30);
ll inf = (1LL<<60);
int main() {
	string s;
	cin >> s;
	if (s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1;
		return 0;
	}
	vector<bool> flag(26, false);
	int i;
	for (i = 0; i < s.size(); i++) {
		int tmp = s[i] - 'a';
		flag[tmp] = true;
	}
	if (s.size() != 26) {
		cout << s;
		for (i = 0; i <= 25; i++) {
			if (flag[i]) continue;
			char ans = i + 'a';
			cout << ans;
			return 0;
		}
	}
	string t = s;
	next_permutation(s.begin(), s.end()); // next_permutationは文字列に対しても使える
	 // cout << s;
	for (i = 0; i < s.size(); i++) {
		cout << s[i];
		if (s[i] != t[i]) break;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000000000000
#define test int t; cin>>t;
#define MOD 1000000007LL
#define all(x) (x).begin(),(x).end()

using namespace std;

ll nxt(){
    ll x;
    cin>>x;
    return x;
}

void dfs(int i, vector<bool>& visited, vector<ll>& par, vector<vector<ll>>& edge, ll p){
    visited[i] = true;
    par[i] = p;
    for(int j = 0; j<edge[i].size(); j++){
        if(!visited[edge[i][j]]){
            dfs(edge[i][j],visited,par,edge,p);
        }
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS
    
    ll n = nxt();
    ll m = nxt();
    vector<vector<ll>>edge(n);
    for(int i = 0; i<m; i++){
        ll x,y;
        cin>>x>>y;
        x--; y--;
        edge[x].pb(y);
        edge[y].pb(x);
    }

    vector<bool> visited(n,0);
    vector<ll>par(n);
    for(int i = 0; i<n; i++) par[i] = i;

    for(int i = 0; i<n; i++){
        if(!visited[i]){
            dfs(i,visited,par,edge, i);
        }
    }

    map<ll,ll> cnt;
    for(int i = 0; i<n; i++){
        cnt[par[i]]++;
    }
    ll ans = 0;
    for(auto it = cnt.begin(); it!=cnt.end(); it++){
        ans = max(ans,(*it).second);
    }
    cout<<ans<<endl;

    return 0;
}

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

int main() {
 int X;
 cin>>X;
 
 int apple,butter,happy;
 
 apple = X/500;
 butter = (X-500*apple)/5;
 
 happy = 1000*apple + 5*butter;
  
  cout << happy << endl;
}

Measured memory_bytes: 3640
#!/usr/bin/env python3

N, A, B = map(int, input().split())

# 各桁の和を計算する関数
def kansu(n):
    sum = 0
    while(n > 0):
        sum += n % 10
        n //= 10
    return sum

total = 0
for i in range(N+1):
    # iについて各桁の和を計算
    i_sum = kansu(i)
    if(i_sum >= A and i_sum <= B):
        total += i

print(total)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long int

signed main(){
    int n,r;
    cin >> n >> r;
    if(n >= 10){
        cout << r << endl;
    }else{
        cout << r + (100*(10-n)) << endl;
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<list>
#include<stack>
using namespace std;

int main() {
  int N; cin >> N;
  list<pair<int, int>> E[N];
  for (int i = 0; i < N-1; i++) {
    int u, v, w;
    cin >> u >> v >> w; u--; v--;
    E[u].push_back(make_pair(v, w));
    E[v].push_back(make_pair(u, w));
  }
  int color[N]; for (int i = 0; i < N; i++) color[i] = 0;
  bool visited[N]; for (int i = 0; i < N; i++) visited[i] = 0;
  stack<int> s; s.push(0);
  while (!s.empty()) {
    int u = s.top(); s.pop();
    visited[u] = true;
    for (auto it = E[u].begin(); it != E[u].end(); it++) {
      int v = it->first, w = it->second;
      if (!visited[v]) {
        color[v] = (color[u] + w) % 2; s.push(v);
      }
    }
  }
  for (int i = 0; i < N; i++) cout << color[i] << endl;
}

Measured memory_bytes: 8704
n = int(input())
s = list(input())
ans = 0
for i in range(1,n):
    cnt = 0
    flag = []
    for j in range(0,i):
        for k in range(i,n):
            if s[j]==s[k] and s[j] not in flag:
                cnt += 1
                flag.append(s[j])
                break

    ans = max(ans,cnt)

print(ans)


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    int n;cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];

    int a_size = a.size();
    sort(ALL(a));
    a.erase(unique(ALL(a)), a.end());
    if(a_size == a.size())cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

ll n, m;
vector<ll> a;
vector<ll> b, c;
vector<pair<ll,ll>> waza;

int main() {
    cin >> n >> m;
    a.resize(n); b.resize(m); c.resize(m); waza.resize(m);
    for (int i = 0; i < n; i++) scanf("%Ld",  &a[i]);
    for (int i = 0; i < m; i++) scanf("%Ld %Ld", &b[i], &c[i]);
    for (int i = 0; i < m; i++) waza[i] = make_pair(c[i],b[i]);
    sort(waza.begin(), waza.end(), greater<pair<int,int>>());
    sort(a.begin(), a.end());

    ll point = 0;
    for (int i = 0; i < m; i++) {
        if (point >= n) break;
        while(1) {
            if (point >= n) break;
            if (a[point] < waza[i].first) {
                for (int j = 0; j < waza[i].second; j++) {
                    if (point >= n || a[point] >= waza[i].first) break;
                    a[point] = waza[i].first;
                    point++;
                }
                break;
            }
            point++;
        }
    }
    ll sum = 0;
    for (int i = 0; i < n; i++) sum += a[i];
    cout << sum << endl;
    return 0;
}

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

// 1 つの証言を表す構造体
using pint = pair<int,int>; // 「人」と「0 or 1」

// 入力
int N;
vector<vector<pint>> v;

// 整数 bit に対応する「決め打ち」が整合しているかを判定
bool judge(int bit) {
    
    // i 人目の証言を検証する
    for (int i = 0; i < N; ++i) {
        
        // i 人目が「不親切」だったら、証言はすべて無意味
        if ( !(bit & (1 << i)) ) continue;

        // それぞれ確認
        for (pint xy : v[i]) {
            int x = xy.first; // x が
            int y = xy.second; // y = 1: 正直、y = 0: 不親切

            if ( ((bit >> x) & 1) ^ y ) return false;
        }
    }
    return true;
}


int main() {
    cin >> N;
    v.resize(N);
    for (int i = 0; i < N; ++i) {
        int A; cin >> A;
        v[i].resize(A);
        for (int j = 0; j < A; ++j) {
            cin >> v[i][j].first >> v[i][j].second;
            --v[i][j].first; // 0-indexed に
        }
    }

    int res = 0;
    for (int bit = 0; bit < (1 << N); ++bit) {
        
        // 矛盾 check
        if (judge(bit)) {
            
            // bit に含まれる人数を数える
            int count = 0;
            for (int i = 0; i < N; ++i) {
                if (bit & (1 << i)) ++count;
            }
            res = max(res, count);
        }
    }

    cout << res << endl;
}


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

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

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

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

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

ll mypow(ll x,ll n,ll m) {
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

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

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

	int t,x; cin>>t>>x;
	cout<<max(0,t-x)<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    boolean aIsMin = a < b;
    if (aIsMin) {
      long[] minPrimes = primes(a);
      Set<Long> and = primesAnd(b, minPrimes);
      pw.println(and.size() + 1);
    } else {
      long[] minPrimes = primes(b);
      Set<Long> and = primesAnd(a, minPrimes);
      pw.println(and.size() + 1);
    }
  }

  static long[] primes(long n) {
    long[] ans = new long[64];
    int count = 0;
    if (n % 2 == 0) {
      ans[count] = 2;
      count++;
      n = n / 2;
      while (n % 2 == 0) {
        n = n / 2;
      }
    }
    long d = 3;
    while (d <= n) {
      d = tryDivide(n, d);
      n = n / d;
      ans[count] = d;
      count++;
      while (n % d == 0) {
        n = n / d;
      }
    }
    return ans;
  }

  static long tryDivide(long n, long min) {
    long max = (long) Math.sqrt(n);
    for (long i = min; i <= max; i += 2) {
      if (n % i == 0) {
        return i;
      }
    }
    return n;
  }

  static Set<Long> primesAnd(long n, long[] prev) {
    Set<Long> ans = new HashSet<>();
    for (long p : prev) {
      if (p == 0) {
        break;
      }
      if (n % p == 0) {
        ans.add(p);
        n = n / p;
      }
    }
    return ans;
  }
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;

V<V<int> > g;
V<ll> ans;

void dfs(int v, int i = -1) {
    for(auto next_v : g[v]){
        if(next_v == i) continue;
        ans[next_v] += ans[v];
        dfs(next_v, v);
    }
}

int main() {
    int n, q; cin >> n >> q;
    g.resize(n);
    for(int i = 0; i < n - 1; i++){
        int a, b; cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    ans.resize(n);
    for(int i = 0; i < q; i++){
        int p, x; cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(0);

    for(int i = 0; i < n; i++){
        cout << ans[i] << endl;
    }



    return 0;
}


Measured memory_bytes: 25116
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N;
    cin >> N;
    int sum = 0,ans=0,goukei=0;
    double heikin1,heikin2;

    vector<int> A(N);

    for(int i = 0;i < N;i++){
        cin >> A.at(i);
        sum += A.at(i);
    }

    heikin1 = ceil(sum / (double)N);
    heikin2 = floor(sum / (double)N);
    

    for(int i = 0;i < N;i++)
        goukei += (A.at(i) - heikin1) * (A.at(i) - heikin1);

    ans = goukei;

    goukei = 0;

    for(int i = 0;i < N;i++)
        goukei += (A.at(i) - heikin2) * (A.at(i) - heikin2);

    if(ans > goukei)
        ans = goukei;

    cout << ans << endl;





    
}

Measured memory_bytes: 3580
ugrd={'L'}
grd={'R'}
s=str(input())
for i in range(len(s)):
  if i%2==0:
    if s[i] in ugrd:
      print('No')
      break
  if i%2==1:
    if s[i] in grd:
      print('No')
      break
  if i==len(s)-1:
    print('Yes')

Measured memory_bytes: 3060
N=int(input())
set=set()
bool=True
list = (list(input()for i in range(N)))
    # S=input()
    # if S in set or :
    #     bool=False
    #     break
set.add(list[0])
for i in range(1,N):
    if list[i] in set or list[i-1][-1] != list[i][0]:
        bool=False
        break
    set.add(list[i])
print('Yes' if bool else 'No')


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
#include <map>

#define PB push_back
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int N = 2e5 + 500;
const int M = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 20;
const int OFF = (1 << LOG);
const double EPS = 1e-9;

vi h;
int n, x, sol = 0, lst = 0, mx = 0, ans[N];

int main(){
    scanf("%d",&n);
    for(int i = 0;i<n;i++){
        scanf("%d", &x);
        ans[x] = ans[x - 1] + 1;
        mx = max(mx, ans[x]);
    }
    printf("%d\n", n - mx);
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		char[] input=new Scanner(System.in).nextLine().toCharArray();
		String result="Yes";
		for(int i=0;i<input.length;i++) {
			if((input[i]=='R'&&i%2==1)||(input[i]=='L'&&i%2==0)) {
				result="No";
				break;
			}
		}
		System.out.println(result);
	}
}

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

#グラフの問題は行き先を入力の段階でしまっておく
to = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
#grobalで答えを管理
cnt = 0
#i現在いる、visited過去行った
def search(i,visited):
    global cnt
    if len(visited)==n:
        cnt += 1
    #隣に行って、現在を過去に追加
    #forで再帰先が複数になるが、searchの値を求めるわけではなくsearchでループを回すのが目的なのでok
    #if v not in visitedを満たすものがない(行けるとこはもう行った)ならそのループは終了
    for v in to[i]:
        if v not in visited:
            search(v,visited+[v])
search(0,[0])
print(cnt)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

using namespace std;

int main() {
    int n, q;
    cin >> n;
    int *s = new int[n];
    for(int i=0; i<n; i++) {
        cin >> s[i];
    }
    cin >> q;
    int c = 0;
    for(int i=0; i<q; i++) {
        int r;
        cin >> r;
        int f = 0;
        int l = n-1; 
        for (int mid=(f + l) / 2; f <= l; mid = (f + l) / 2){
            if(s[mid] == r) {
                c++;
                break;
            }
            else if(s[mid] < r) {
                f = mid+1;
            }else if(s[mid] > r) {
                l = mid-1;
            }
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 3488
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;
    
    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] A = cin.ArrayInt(N);
        int ans = 0;
        while (true)
        {
            bool flag = true;
            for (int i = 0; i < N; i++)
            {
                if(A[i] % 2 == 0)
                {
                    A[i] /= 2;
                }
                else
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                ans++;
                continue;
            }
            Console.WriteLine(ans);
            return;
        }
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define len(arr) (int)(sizeof(arr)/sizeof((arr)[0]))
#define Sort(arr) sort(arr,arr+len(arr))
#define For(i,s,n) for(int i=s;i<n;i++)	
#define Rep(i,n) for(int i=0;i<n;i++)
#define Per(i,n) for(int i=n;i>=0;i--)
#define All(x) (x).begin(),(x).end()
#define in(arr,n) Rep(i,n) cin >> arr[i];
#define in2(arr1,arr2,n) Rep(i,n) cin >> arr1[i] >> arr2[i];
#define in3(arr1,arr2,arr3,n) Rep(i,n) cin >> arr1[i] >> arr2[i] >> arr3[i];
#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775808
#define MOD 1000000007
#define MOD9 1000000009

//{ ライブラリ

// 標準出力の高速化
#define endl "\n"

// 出力
template<typename Type>
void print(Type a[],int n){
	Rep(i,n) cout << a[i] << endl;
}
template<typename Type1,typename Type2>
void print(Type1 a[],Type2 b[],int n){
	Rep(i,n) cout << a[i] << " " << b[i] << endl;
}
template<typename Type1,typename Type2,typename Type3>
void print(Type1 a[],Type2 b[],Type3 c[],int n){
	Rep(i,n) cout << a[i] << " " << b[i] << " " << c[i] << endl;
}

// 配列の最大値
template<typename Type>
Type max(Type a[],int n){
	Type ret=a[0];
	For(i,1,n) ret=max(ret,a[i]);
	return ret;
}

// 配列の最小値
template<typename Type>
Type min(Type a[],int n){
	Type ret=a[0];
	For(i,1,n) ret=min(ret,a[i]);
	return ret;
}

// 最大公約数
template<typename Type>
Type gcd(Type a,Type b){return(b==0)?a:gcd(b,a%b);}
template<typename Type>
Type gcd(Type a[],int n){
	Type ret=a[0];
	For(i,1,n) ret=gcd(ret,a[i]);
	return ret;
}

// 最小公倍数
template<typename Type>
Type lcm(Type a,Type b){return (a/gcd(a,b))*b;}
template<typename Type>
Type lcm(Type a[],int n){
	Type ret=a[0];
	For(i,1,n) ret=lcm(ret,a[i]);
	return ret;
}

// aを元にしてペアでソート
template<typename Type1,typename Type2>
void PairSort(Type1 a[],Type2 b[],int left,int right){
	int i=left,j=right;
	Type1 p=a[(left+right)/2];
	while(true){
		while(a[i]<p) i++;
		while(p<a[j]) j--;
		if(i>=j) break;
		swap(a[i],a[j]);
		swap(b[i],b[j]);
		i++;j--;
	}
	if(left<i-1) PairSort(a,b,left,i-1);
	if(j+1<right) PairSort(a,b,j+1,right);
}
template<typename Type1,typename Type2,typename Type3>
void PairSort(Type1 a[],Type2 b[],Type3 c[],int left,int right){
	int i=left,j=right;
	Type1 p=a[(left+right)/2];
	while(true){
		while(a[i]<p) i++;
		while(p<a[j]) j--;
		if(i>=j) break;
		swap(a[i],a[j]);
		swap(b[i],b[j]);
		swap(c[i],c[j]);
		i++;j--;
	}
	if(left<i-1) PairSort(a,b,c,left,i-1);
	if(j+1<right) PairSort(a,b,c,j+1,right);
}

// 配列を逆順にする
template<typename Type>
void Reverse(Type a[],int n){Rep(i,n/2) swap(a[i],a[n-i-1]);}

// 文字列を逆順にする
// reverse(All(str));

//}

int main(){
	int n;
	cin >> n;
	int p[n];
	in(p,n);
	int ans=0;
	Rep(i,n-2){
		if((p[i+2]<p[i+1]&&p[i+1]<p[i])||(p[i]<p[i+1]&&p[i+1]<p[i+2]))
			ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll x,cost;
};
int main() {

	string s;
	cin>>s;
	rep(i,s.size()){
		if(i%2==0&&s[i]!='h'){
			cout<<"No"<<endl;
			return 0;
		}
		if(i%2>0&&s[i]!='i'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	if(s.size()%2>0)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}


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

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(x) x.begin(),x.end()


int s[10][10]={};

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


int solve(int y,int x,int d,int base){
    int dx=ddx[d];
    int dy=ddy[d];
    int ret=0;
    
    rep(i,8){
        int dxi=dx*(i+1),dyi=dy*(i+1);
        if( !( y+dyi>=0 && y+dyi<8 && x+dxi>=0 && x+dxi<8 ) || s[y+dyi][x+dxi]==-1 ) return 0;
        else if(s[y+dyi][x+dxi]==base)return ret;
        else if(s[y+dyi][x+dxi]!=base)ret++;
    }
    return -100;
}


void out(){
    rep(i,8){
        rep(j,8){
            int aa=s[i][j];
            if(aa==1)cout<<"o";
            if(aa==0)cout<<"x";
            if(aa==-1)cout<<".";
        }
        cout<<endl;
    }
}


int main(){
    rep(i,8){
        rep(j,8){
            char tmp;
            cin>>tmp;
            if(tmp=='o')s[i][j]=1;
            else if(tmp=='x')s[i][j]=0;
            else s[i][j]=-1;
        }
    }
    
    int flag=false;
    while(true){
//        out();cout<<endl;
        
        
        int d[10]={};
        int y=-1,x=-1;
        int count=0;
        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++){
                if(s[i][j]!=-1)continue;
                int result=0;
                int tmp[10]={};
                rep(k,8){
                    int aaa=solve(i,j,k,1);
                    tmp[k]=aaa;
                    result+=aaa;
                }
                if(result>count){
                    count=result;
                    y=i;
                    x=j;
                    rep(z,8)d[z]=tmp[z];
                }
            }
        }
        if(count!=0){
            flag=false;
            s[y][x]=1;
            rep(i,8){
                rep(j,d[i]){
                    s[y+ddy[i]*(j+1)][x+ddx[i]*(j+1)]=1;        ///////
                }
            }
        }
        else{
            if(flag)break;
            flag=true;
        }
/////////////////////////////////////////////////////////
//        out();cout<<endl;
        y=-1,x=-1;
        count=0;
        for(int i=7;i>=0;i--){
            for(int j=7;j>=0;j--){
                if(s[i][j]!=-1)continue;
                int result=0;
                int tmp[10]={};
                rep(k,8){
                    int aaa=solve(i,j,k,0);
                    tmp[k]=aaa;
                    result+=aaa;
                }
                if(result>count){
                    count=result;
                    y=i;
                    x=j;
                    rep(z,8)d[z]=tmp[z];
                }
            }
        }
        if(count!=0){
            flag=false;
            s[y][x]=0;
            rep(i,8){
                rep(j,d[i]){
                    s[y+ddy[i]*(j+1)][x+ddx[i]*(j+1)]=0;        ///////
                }
            }
        }
        else{
            if(flag)break;
            flag=true;
        }
        
    }
    out();
    
    return 0;
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<map>
#include<iterator>
using namespace std;
#define tt int t;cin>>t;while(t--)
#define ll long long
#define nl endl
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.begin(),v.end(),greater<int>());
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define amax(a,n) *max_element(a,a+n)
#define amin(a,n) *min_element(a,a+n)
#define vmax(a) *max_element(a.begin(),a.end())
#define vmin(a) *min_element(a.begin(),a.end())
#define so ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define a_size 100
ll i,j;

int main()
{
        so

        string s;
        cin>>s;
        if(s[s.size()-1]=='s')cout<<s<<"es";
        else cout<<s<<"s";



        return 0;
}



Measured memory_bytes: 3620
import java.util.*;

public class Main{
    static long[] last = new long[26];
    static long[] c = new long[26];
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        long[][] s = new long[d+1][26];

        for(int i=0; i<26; i++) {
            c[i] = sc.nextLong();
        }

        for(int i=1; i<=d; i++) {
            for(int j=0; j<26; j++) {
                s[i][j] = sc.nextLong();
            }
        }

        for(int i=1; i<=d; i++) {
            int index = select(s[i], i);
            System.out.print(index);
            System.out.print("\n");
        }
    }

    public static int select(long[] s, int day) {
        long[] score = new long[26];
        int index = 0;
        long max = -1000000000;
        for(int i=0; i<26; i++) {
            score[i] = s[i];
            for(int j=0; j<26; j++) {
                if(i!=j) {
                    score[i] -= c[j]*(day-last[i]);
                }
            }

            if(score[i]>max) {
                index = i;
                max = score[i];
            }
        }
        return index+1;
    }
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

void out(){cout << "\n";}
template<class T,class... Args>
void out(const T &x,const Args &... args){
	cout << x << " ";
	out(args...);
}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,now=0;;
	cin >> n;
	vpll v(n);
	rep(i,n){
		ll a,b;
		cin >> a >> b;
		v[i]=m_p(b,a);
	}
	sort(all(v));
	for(auto&& e:v){
		if(now+e.second>e.first){
			cout << "No\n";
			return 0;
		}
		else now+=e.second;
	}
	cout << "Yes\n";
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
long long const mod = 1000000007;
long long mod_fact(int x){
    static vector<long long> fact = {1, 1};
    if(x < 0)return 0; //
    if(x < fact.size())return fact[x];
    for(int i = fact.size(); i <= x; i++){
        fact.push_back((fact[i-1] * i) % mod);
    }
    return fact[x];
}

long long mod_pow(long long a, long long b){
    long long res = 1;
    a %= mod;
    while(b > 0){
        if(b%2 == 1) res = (res * a) % mod;
        a = (a * a) % mod;
        b /= 2;
    }
    return res;
}

long long mod_inv(long long a){
    return mod_pow(a, mod-2);
}

long long mod_comb(int a, int b){
    if(b < 0 || a < b)return 0;
    if(b > a/2)return mod_comb(a, a-b);
    return (((mod_fact(a) * mod_inv(mod_fact(a-b))) % mod) * mod_inv(mod_fact(b))) % mod;
}

int main(void){
    int n;
    vector<int> c;
    long long ans = 0;
    cin >> n;
    c.assign(n, 0);
    for(int i=0;i<n;i++) cin >> c[i];
    sort(c.begin(), c.end());
    for(int i=0;i<n;i++){
        long long s = mod_pow(2, i) * c[i] % mod;
        long long t = (mod_pow(2, n-i-2) * (n-i-1) % mod + mod_pow(2, n-i-1)) % mod;
        ans += s * t % mod;
        ans %= mod;
    }
    ans *= mod_pow(2, n);
    cout << ans%mod << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        String inputArr[] = input.split(" ");
        
        double x0 = Double.parseDouble(inputArr[0]);
        double y0 = Double.parseDouble(inputArr[1]);
        double x1 = Double.parseDouble(inputArr[2]);
        double y1 = Double.parseDouble(inputArr[3]);
        
        double num = Math.sqrt(Math.pow(x1-x0, 2) + Math.pow(y1-y0, 2));
        System.out.print(num);
    }
}


Measured memory_bytes: 26232
#include<stdio.h>
#include<math.h>
int isPrime(int);
int count;
int main(void){
    int i,j,m,a;
    scanf("%d",&m);
    for(i=0;i<m;i++){
    scanf("%d",&a);
    isPrime(a);
    }   
    printf("%d\n",count);
    return 0;
}
int isPrime(int d){
    int i;
    if(d==2){count++;return 0;}
    if(d>2&&d%2==0)return 0;
    for(i=3;i<=sqrt(d);i+=2)
        if(d%i==0)return 0;
    count++;
    return 0;
}


Measured memory_bytes: 1992
// 2014/07/17 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int H, W;
		cin >> H >> W;

		if(H==0 && W==0)
			break;

		for(int i=0; i<H; i++){
			for(int j=0; j<W; j++){
				if(i>=1 && i<H-1 && j>=1 && j<W-1){
					cout << '.';
				}
				else{
					cout << '#';
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
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; }
using Graph = vector<vector<int> >;
using P = pair<int, int>; 
// MOD
const int MOD = 1000000007;
using ll = long long;
long long INF = 1<<30;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
//int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int H, W;
int field[100][100];

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double PI=3.14159265358979323846;
bool seen[100][100];

bool memo[110];
bool flag;
Graph G;

int dist[100][100];

bool compare_f(pair<int, int> &x, pair<int, int> &y) {
  return x.second< y.second;
}

struct Unionfind{
    vector<int> par;

    Unionfind(int n) : par(n, -1){}

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    } 

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x]>par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main() {
    ll n, d, a; cin >> n >> d >> a;
    vector<P> p(n);
    for(int i=0; i<n; i++){
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(), p.end());
    d = d*2;
    queue<pair<ll,ll> > q;
    ll ans = 0;
    ll tot = 0;
    for(int i=0; i<n; i++){
        ll x = p[i].first;
        ll h = p[i].second;
        while(!q.empty() && q.front().first<x){
            tot -= q.front().second;
            q.pop();
        }
        h -= tot;
        if(h>0){
            ll num = (h + a -1)/a;
            ans += num;
            ll damage = num*a;
            tot += damage;
            q.emplace(x+d, damage);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3456
# alds1_5_d
INF = 1e11

def merge(A, left, mid, right):
    n_inv = 0
    L = A[left:mid] + [INF]
    R = A[mid:right] + [INF]
    len_L = len(L) - 1

    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            n_inv += len_L - i
    return n_inv


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        inv_l = merge_sort(A, left, mid)
        inv_r = merge_sort(A, mid, right)
        return merge(A, left, mid, right) + inv_l + inv_r
    return 0

if __name__ == "__main__":
    n = int(input())
    A = [int(i) for i in input().split()]
    print(merge_sort(A, 0, n))


Measured memory_bytes: 27488
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

ll dp[3][111111];
ll a[111111];
ll b[111111];
ll c[111111];

signed main()
{
	int N;
	cin >> N;
	REP(i, N){
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[0][0] = a[0];
	dp[1][0] = b[0];
	dp[2][0] = c[0];
	FOR(i, 1, N-1){
		dp[0][i] = max(dp[1][i-1], dp[2][i-1])+a[i];
		dp[1][i] = max(dp[2][i-1], dp[0][i-1])+b[i];
		dp[2][i] = max(dp[0][i-1], dp[1][i-1])+c[i];
	}
	cout << max(dp[0][N-1], max(dp[1][N-1], dp[2][N-1])) << endl;
}


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

int main(){
  int a,b,c,d;
  cin >> a;
  b = a % 1000;
  a /= 1000;
  c = b % 100;
  b /= 100;
  d = c % 10;
  c /= 10;
  
  if(a == b && b == c){
    cout << "Yes" << endl;
  }
  else if(b == c && c == d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main() {
  char c;
  cin >> c;
  
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;    
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int N;
  cin>>N;
  int A[N];
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  for(int p=0;p<N;p++){
    if(p==N-1){
      cout<<A[p]<<endl;
    }else{
      cout<<A[p]<<" ";
    }
  }
  for(int i=1;i<N;i++){
    int v=A[i],j=i-1;
    while(j>=0&&v<A[j]){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(int p=0;p<N;p++){
      if(p==N-1){
        cout<<A[p]<<endl;
      }else{
        cout<<A[p]<<" ";
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<map>
#define PI 3.141592653589793238
#define INF -1
#define ll long long
using namespace std;

int main()
{
	int n, m, s, c;
	int* ans;
	int call = 0;
	int deg = 1;

	cin >> n >> m;

	ans = new int[n + 1];

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

	for (int i = 0; i < m; i++) {
		cin >> s >> c;
		if (ans[s] == -1 || ans[s] == c) {
			ans[s] = c;
		} else {
			printf("%d", -1);
			return 0;
		}
	}


	if (n > 1) {
		if (ans[1] == 0) {
			printf("%d", -1);
			return 0;
		}

		if (ans[1] == -1) {
			ans[1] = 1;
		}
		for (int i = 0; i < n; i++) {
			if (ans[n - i] == -1) {
				ans[n - i] = 0;
			}
			call += ans[n - i] * deg;
			deg *= 10;
		}
		printf("%d", call);
	} else {
		if (ans[1] <= 0) {
			printf("%d", 0);
		} else {
			printf("%d", ans[1]);
		}
	}





	return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s, t;
    cin >> s >> t;
    int num = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i]!=t[i]){
            num++;
        }
    }
    cout << num << endl;
    
    return 0;
}

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

int main() {
  int A,B,C,D,cnt=0;
  cin >> A >> B >> C >> D;
  if(A>B){
    cnt += B;
  }else{
    cnt += A;
  }
  if(C>D){
    cnt += D;
  }else{
    cnt += C;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
//dominant  tree
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lf double
#define nn 178
#define lg 18
#define mod 998244353
ll a,b,c;
int main()
{
    
    cin>>a>>b>>c;
    if(c-1<=a+b)
    {
    	cout<<c+b;
    	exit(0);
    }
    else 
    {
    	cout<<a+b*2+1;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,n,i,j,k,c,f;
	cin>>n;
	vc a(n+1);ll u,v;
	for(i=1;i<=n;i++)
	{
	    
	    cin>>u>>v;
	    if(u==v)a[i]++;
	}
	f=0;
	for(i=1;i<=n;i++)
	{
	    if(a[i]==1)a[i]+=a[i-1];
	    if(a[i]>=3)f=1;
	}
	if(f)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define M_PI 3.14159265358979323846

using namespace std;

const int ms = 1e5 + 17;
const int mod = 1e9 + 7;

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

    int n;
    cin >> n;

    vector<int> v(n, 0);

    for(int i = 0; i < n; ++i)
        cin >> v[i];

    int answer = 0;
    int temp_len = 1;
    vector<int> ans;

    for(int i = 1; i < n; ++i)
    {
        if(v[i] == v[i - 1])
            ++temp_len;
        else
        {ans.push_back(temp_len);
            temp_len = 1;
        }
    }

    ans.push_back(temp_len);

    for(int i = 0; i < ans.size(); ++i)
        answer += ans[i] / 2;

    cout << answer << '\n';
}


Measured memory_bytes: 256