akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll l, r, minN = INF;
	cin >> l >> r;
	r = min(r,l+2019*2);
	for (ll i = l; i <= r; i++) {
		for (ll k = i + 1; k <= r; k++) {
			ll tmp = (i * k) % 2019;
			minN = min(minN,tmp);
		}
	}
	cout << minN << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN 2*int(1e5)+5
#define fim '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << fim
#define debug2(x, y) cout << "DEBUG " << x << " " << y << fim
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< fim
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << fim
#define max3(x, y, z) max(x, max(y, z))
#define ull unsigned long long
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll MOD = 1e9+7;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	string aux = "", aux2 = "";
	for(int i = 0; i < n/2; i++)
		aux.pb(s[i]);
	for(int i = n/2; i < n; i++)
		aux2.pb(s[i]);
	cout << (aux == aux2 ? "Yes":"No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int oo = 1e9;
const int MOD = 1000000007;
const int BASE = 26;
const int N = 200010;
#define x first
#define y second
#define pb push_back
#define mp make_pair

int n , p[1001] , x[1001], sum[1001];
vector<int> g[1001];

pii dfs(int u) {
	sum[u] = 0;
	bitset<5002> bt;
	bt[0] = 1;
	for (int i = 0; i < g[u].size(); ++i) {
		int v = g[u][i];
		pii f = dfs(v);
		sum[u] += f.x + f.y;
		bt = ((bt << f.x) | (bt << f.y));
	}
	if (!g[u].size()) {
		sum[u] = x[u];
		return mp(x[u], 0);
	}
	int add = 0 , last = -1;
	for (int k = x[u]; k >= 0 ; --k) {
		if (bt[k]) {
			last = k;
			break;
		}
	}
	if (last == -1) {
		puts("IMPOSSIBLE");
		exit(0);
	}
	add = x[u] - last;
	sum[u] += add;
	return mp(x[u], sum[u] - x[u]);
}
int main() {
	scanf("%d", &n);
	for (int i = 2; i <= n; ++i) {
		scanf("%d", &p[i]);
		g[p[i]].pb(i);
	}
	for (int i = 1 ; i <= n ; ++i)
		scanf("%d", &x[i]);
	dfs(1);
	puts("POSSIBLE");
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int main() {
	fastio;
	ll N, K;
	cin >> N >> K;

	int sp[63][200000];
	for (int i = 0; i < N; ++i) {
		cin >> sp[0][i];
		sp[0][i]--;
	}

	for (int i = 1; i < 63; ++i) for (int j = 0; j < N; ++j)
		sp[i][j] = sp[i - 1][sp[i - 1][j]];

	int ans = 0;
	for (int i = 63; i--; ) {
		if (K >= 1ll << i) {
			ans = sp[i][ans];
			K -= 1ll << i;
		}
	}

	cout << ans + 1;

	return 0;
}

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

N,M = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(N)]

p = [0]*8
for i in range(2 ** 3):
    tmp = [0]*N
    for k in range(N):
        q = 0
        for j in range(3):
            if ((i >> j) & 1):
                q -= l[k][j]
            else:
                q += l[k][j]
        tmp[k] = q
    tmp.sort(reverse=True)
    p[i] = sum(tmp[:M])

print(max(p))


Measured memory_bytes: 3296
#include "bits/stdc++.h"
using namespace std;
int main()
{
    char a[5];
    scanf("%s", a);
    for (int i = 0; i < 4; i++)
    {
        if (a[i] == 'A' && a[i + 1] == 'C')
        {
            printf("Yes\n");
            break;
        }
        if (i == 3)
        {
            printf("No\n");
        }
    }
}


Measured memory_bytes: 256
///////////////////////////////////////////// Template /////////////////////////////////////////////
#![allow(non_snake_case, unused)]
use std::collections::*;

//////////////////// missing functions in 1.15.1 ////////////////////
macro_rules! eprint {
	($($t:tt)*) => { {
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	} };
}
macro_rules! eprintln {
	($($t:tt)*) => { {
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	} };
}

//////////////////// useful functions ////////////////////
pub trait SetMin {
	fn setmin(&mut self, v: Self) -> bool;
}
impl<T> SetMin for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
}
pub trait SetMax {
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMax for T where T: PartialOrd {
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

macro_rules! debug {
	($($v: expr),*) => {
		$(eprint!("{} = {:?} ", stringify!($v), $v);)*
		eprintln!("@ {}:{}", file!(), line!());
	}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:ty),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

fn run() {
	let (n, k) = read!(usize, usize);
	let a = read!([usize]);
	println!("{}", (n - 1 + k - 2) / (k - 1));
}


Measured memory_bytes: 10620
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    ll n;
    cin >> n;
    cout << n*(n-1)/2;

    return 0;
}

Measured memory_bytes: 3632
def main():
    H,W,D = map(int,input().split())
    N = H*W
    A = []
    for i in range(H):
        A.append(list(map(int, input().split())))
    places = [0] * (H * W + 1)
    for i in range(H):
        for j in range(W):
            places[A[i][j]] = (i,j)
    dp = [0] * (N+1)
    for i in range(D+1,N+1):
        y1,x1 = places[i-D]
        y2,x2 = places[i]
        dp[i] = dp[i-D]+abs(x1-x2)+abs(y1-y2)
    

    Q = int(input())
    queries = []
    ans = []
    for i in range(Q):
        l,r = map(int,input().split())
        ans.append(dp[r] - dp[l])
    print('\n'.join(map(str,ans)))
main()


Measured memory_bytes: 91204
#include <bits/stdc++.h>
#define LL long long
	int n,k;
	int a[100];
	int ans[100001];
using namespace std;
void Solve()
{
	if(k<a[0]) {cout<<2;return;}
	for(int i=a[0];i<=k;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i-a[j]<0) break;
			if(ans[i-a[j]]==0) {ans[i]=1;break;}	
		}
	}
	cout<<(((2-ans[k])==1)?"First":"Second");
}
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<=k;i++) ans[i]=0;
	Solve();
}


Measured memory_bytes: 640
import std.stdio, std.conv, std.string, std.array, std.algorithm, std.regex;

void main(){
	auto ip = readln.split.to!(int[]), a = ip[0], b = ip[1], c = ip[2];
	if(a == b + c || b == a + c || c == a + b){
		writeln("Yes");
	} else {
		writeln("No");
	}
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main (String[] args) {
		Main values = new Main(); 
		long a,b;
		while (sc.hasNext()){
			a = sc.nextLong();
			b = sc.nextLong();
			System.out.println(values.GCF(a, b)+" "+values.LCM(a, b));}
	}
	public long GCF(long a, long b) {
	    if (b == 0) return a;
	    else return (GCF (b, a % b));
	}
	public long LCM(long a, long b){
		return (a*b)/GCF(a,b);
	}
}

Measured memory_bytes: 26276
import math

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

lst = []
for p in range(10, 1010):
  if (math.floor(0.08*p) == A) and (math.floor(0.10*p) == B):
    lst.append(p)

if lst:
  print(min(lst))
else:
  print(-1)

Measured memory_bytes: 3060
#pragma region noncode
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SORT(v) sort(all(v))
#define TROS(v) sort(all(v), std::greater<Type>());
#pragma endregion

int main() {
    // template
    int x,a,b;cin>>x>>a>>b;
    x-=a;
    x%=b;
    cout<<x<<endl;
    
}


Measured memory_bytes: 3624
import java.util.*;
class Main{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int m=s.nextInt();
int M=m;
for(int i=1;i<n;i++){
int a=s.nextInt();
if(a<m)m=a;
else if(a>M)M=a;
}
System.out.println(M-m);
}}

Measured memory_bytes: 21332
def factorials(M):#M!までのリストｘと其の逆元のリストyを返すmod INF
    INF=int(1e9+7)
    fac=[0]*(M+1)
    finv=[0]*(M+1)
    inv=[0]*(M+1)
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,M+1):
        fac[i]=(fac[i-1]*i)%INF
        inv[i]=INF-(inv[INF%i]*(INF//i))%INF
        finv[i]=finv[i-1]*inv[i]%INF
    return fac,finv
def nCr(n,r):
    INF=int(1e9+7)
    if n<r or r<0 or n<0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%INF)%INF

N=int(input())
fac,finv=factorials(N+1)
A=list(map(int,input().split()))
INF=int(1e9+7)
d=[0]*(N+1)
for i in A:
    d[i]+=1
key=-1
for i in range(1,N+1):
    if d[i]==2:
        key=i
a,b,c=0,0,0
t=0
for i in range(N+1):
    if key==A[i]:
        t+=1
    elif t==0:
        a+=1
    elif t==1:
        b+=1
    elif t==2:
        c+=1
for i in range(1,N+2):
    if i==1:
        print(N)
        continue

    print((nCr(N+1,i)-nCr(a+c,i-1))%INF)


Measured memory_bytes: 59316
module module_sort
    use iso_fortran_env
    implicit none

    interface quicksort
        module procedure :: int32_qsort
        module procedure :: int64_qsort
    end interface quicksort
contains

    recursive function int32_qsort(m) result(res)
        integer(int32), intent(in) :: m(:)
        integer(int32) :: res(size(m))

        if (size(m) <= 1) then; res = m
        else; res = [int32_qsort( pack(m(2:), m(2:) >= m(1)) ), m(1), int32_qsort( pack(m(2:), m(2:) < m(1)) )]
        end if

    end function int32_qsort

    recursive function int64_qsort(m) result(res)
        integer(int64), intent(in) :: m(:)
        integer(int64) :: n, pm, pn, pv, res(size(m))

        n = size( m, 1 )

        if (n <= 1) then
          res = m
        else
          pv = m( n/2 )
          pm = max( m(1), m(n) )
          pn = min( m(1), m(n) )
          if ( pv > pm ) pv = pm
          if ( pv < pn ) pv = pn
          res = [ int64_qsort( pack(m(:), m(:) > pv) ), &
                               pack(m(:), m(:) == pv), &
                  int64_qsort( pack(m(:), m(:) < pv) ) ]
        endif

    end function int64_qsort

end module module_sort

program main
    use module_sort
    use iso_fortran_env
    implicit none
    integer(int64) :: n
    integer(int64), allocatable :: ai(:)
    integer(int64) :: i, ie
    integer(int64) :: ans

    read *, n
    allocate( ai(n) )
    read *, ai( 1:n )
    ai = quicksort( ai )
!    print *, int32, int64, int128
!    call qsort( ai )
!    ai(n:1:-1) = ai(1:n)
!    ai = intQsort( ai )
!    ai(n:1:-1) = ai(1:n)

    if ( mod((n-1), 2) == 0 ) then
        ie = (n-1) / 2
        ans = ai(1) + ai(ie + 1)
    else
        ie = n / 2
        ans = ai(1)
    endif

    do i = 2, ie
        ans = ans + ai(i) * 2
    enddo

    print *, ans

contains

recursive subroutine qsort(a)
  implicit none
  integer(8),intent(inout) :: a(:)
  integer(8)::i,j,toobig,toosmall,pv,n

  n = size(a)
i = 1
j = n
pv = a((i+j)/2)
do
   do
     if (a(i) < pv) then
       i = i+1
     else
       exit
     end if
   end do
   do
     if(a(j) > pv) then
       j = j-1
     else
       exit
     end if
   end do
   if (i>=j) then
     exit
   else
     toobig = a(j)
     toosmall = a(i)
     a(i) = toobig
     a(j) = toosmall
     i = i+1
     j = j-1
   end if
 end do
 if (i > 2) then
   call qsort(a(1:i-1))
 end if
 if (j < n-1) then
   call qsort(a(j+1:n))
 end if
end subroutine qsort

pure recursive function intQsort( a ) result( r )
implicit none
integer(int64), intent(in) :: a(:)
integer(int64) :: r( size(a) )
integer(int64) :: sample(3), len, i,j

len = size( a(:) )
if( len<=1 )then
  r = a
else
  !select pivot
  sample(1:3) = [a(1), a(len/2), a(len)]
  do i = 1,2
    do j = 2,3
      if( sample(i)>sample(j) )then
        len = sample(i) !len is buffer
        sample(i) = sample(j)
        sample(j) = len
      end if
    end do
  end do
  
  r = [ intQsort( pack(a(:), a(:)< sample(2)) ), &
                  pack(a(:), a(:)==sample(2))  , &
        intQsort( pack(a(:), a(:)> sample(2)) ) ]
end if
end function intQsort

end program main

Measured memory_bytes: 11008
#13:27
N = int(input())
A = list(map(int,input().split()))
ex_red = [0]*8
red_cnt = 0

for i in range(8):#0-7
    for j in range(N):
        if 400*i<=A[j] and A[j]<400*(i+1):
            ex_red[i]+=1
n = 0
for i in range(N):
    if 3200 <= A[i]:
        n += 1
not_red_color = 0
c = 0
for i in range(8):
    if ex_red[i] > 0:
        c += 1
#print(c)#soreigai_count
#print(n)#red_count

max_ans = n + c

#min_ans
if c >= 1:
    min_ans = c
elif c == 0:
    min_ans = 1
print(min_ans, max_ans)






    


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int>a(n);
	int cnt = 0;
	bool flag = false;
	rep(i, n) {
		cin >> a[i];
		a[i]--;
		if (a[i] == i) {
			cnt++;
			if (!flag)flag = true;
			else {
				cnt--;
				flag = false;
			}
		}
		else flag = false;
	}
	if (cnt >= n - 1)cnt = n - 1;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {  
    int n; cin >> n;
    vector<ll> A(n); ll b = 0;
    rep(i, n) {cin >> A[i]; b += A[i];}
    ll a = A[0]; b -= A[0]; ll res = abs(b - a);
    for(int i=1; i<n-1; i++){
        a += A[i]; b -= A[i];
        chmin(res, abs(b - a));
    }
    cout << res << ln;
}




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

void query(vector<int>V) {
	cout << "?";
	for (int e : V) {
		cout << ' ' << e;
	}cout << endl;
}

signed main() {
	int n; cin >> n;
	vector<int>q;
	rep(i, n)q.push_back(i + 1);
	query(q);
	string start; cin >> start;
	int l = -1, u = n;
	while (u - l > 1) {
		int mi = (u + l) / 2;
		q.clear();
		rep(i, mi)q.push_back(i + 1);
		rep(i, n - mi)q.push_back(n+n - i);
		 query(q);string r;
		cin >> r;
		if (r == start)u = mi;
		else l = mi;
	}
	q.clear();
	rep(i, l)q.push_back(i + 1);
	rep(i, n - u)q.push_back(n + n - i);
	vector<int>q2;
	for (int i = u + 1; i <= n + l; i++) {
		q2.push_back(i);
	}
	vector<int>used(n + n);
	for (int e : q)used[e-1]++;
	string ans(n+n,'0');

	rep(i, n + n) {
		if (!used[i]) {
			q.push_back(i + 1);
			query(q);
			string s; cin >> s;
			ans[i] = s[0];
			q.pop_back();
		}
	}
	for (int e : q) {
		q2.push_back(e);
		query(q2);
		string s; cin >> s;
		ans[e-1] = s[0];
		q2.pop_back();
	}
	cout << "! " << ans << endl;
}

Measured memory_bytes: 724
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  std::cin >> N;

  for (int i = 1; i <= N; i ++) {
    int n = i * 1.08;

    if (n == N) {
      std::cout << i << std::endl;

      return 0;
    }
  }

  std::cout << ":(" << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool binarySearch(int temp, int arr[], int n){
    int left = 0;
    int right = n;
    int mid;
    while(left < right){
        mid = (left+right)/2;
        if(temp == arr[mid]){
            return true;
        } else if(temp > arr[mid]){
            left = mid + 1;
        } else {
            right = mid;
        }
    }
    return false;
}

int main()
{

    int n,m;
    int count = 0;
    cin>>n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    cin>>m;
    int temp;
    for(int i = 0;i<m;i++){
        cin>>temp;
        if(binarySearch(temp, a, n)){
            count++;
        }
    }
    cout<<count<<endl;

    return 0;





}

Measured memory_bytes: 3424
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = getInt(sc);
		if (x == 3 || x == 5 || x == 7) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


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

int main(){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(10) << sqrt(pow((x2-x1), 2) + pow((y2-y1), 2)) << endl;
    return 0;
}


Measured memory_bytes: 3280
//065A
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x, a, b;
    cin >> x >>a >> b;
    if (-a+b <=0){
        cout << "delicious";
    }else if(-a+b <=x){
        cout << "safe";
    }else{
        cout << "dangerous";
    }
}

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

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

int N;
int P[5050];
const ll mo=1000000007;

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

int fix[5050],dyn[5050];
ll p[5050][5050];
ll num[5050];
ll fact[5050];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	fact[0]=1;
	FOR(i,5010) {
		fact[i+1]=fact[i]*(i+1)%mo;
		p[i][0]=1;
		FOR(j,5010) p[i][j+1]=p[i][j]*i%mo;
	}
	
	
	cin>>N;
	ll pat=N-1;
	FOR(i,N) {
		cin>>P[i];
		if(P[i]>0) {
			P[i]--;
			uf(i,P[i]);
		}
	}
	int nd=0;
	FOR(i,N) {
		if(P[i]==-1) dyn[uf[i]]++, nd++;
		else fix[uf[i]]++;
	}
	
	int e=0;
	FOR(i,N) if(dyn[i]+fix[i]) {
		if(dyn[i]) e+=dyn[i]+fix[i];
		else e+=fix[i]-1;
	}
	pat=p[N-1][nd]*e%mo;
	
	num[0]=1;
	FOR(i,N) if(dyn[i]) {
		pat-=fix[i]*p[N-1][nd-1]%mo;
		for(j=N;j>=0;j--) {
			(num[j+1]+=num[j]*(dyn[i]+fix[i]))%=mo;
		}
	}
	
	for(i=2;i<=N;i++) if(num[i]) {
		pat-=num[i]*fact[i-1]%mo*p[N-1][nd-i]%mo;
	}
	
	pat=(pat%mo+mo)%mo;
	
	cout<<pat<<endl;
}


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


Measured memory_bytes: 201524
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    string s;
    cin >> s;


    bool A = s[0] == 'A', C = false;
    int big = 0;

    for (int i = 2; i < s.size() - 1; ++i) {
        if (s[i] == 'C') C = true;
    }

    rep(i, 0, s.size())if (s[i] >= 'A' && s[i] <= 'Z') big++;

    if(A && C && big == 2){
        cout << "AC" << endl;
    }else{
        cout << "WA" << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long LL;

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    LL a, b, x, ans=0;
    cin>>a>>b>>x;
    ans = (b/x) - (a/x);
    if(a%x==0) ans++;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

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

	int n;
	cin >> n;
	vector<int> a(n);
	int s = 0;
	for (auto &t : a) {
		cin >> t;
		s += t;
	}
	int ans = 0;
	for (auto t : a) {
		ans += t * (s - t);
	}
	cout << ans / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
    int H;
    std::cin >> H;

    int heap[H];
    for (auto i = 0; i < H; i++) {
        std::cin >> heap[i];
    }
    for (auto i = 0; i < H ; i++) {
        int parent = (i + 1) / 2 - 1;
        int left = (i + 1) * 2 - 1;
        int right = left + 1;
        std::cout << "node " << i + 1 << ": key = " << heap[i] << ", ";
        if (parent >= 0) {
            std::cout << "parent key = " << heap[parent] << ", ";
        }
        if (left < H) {
            std::cout << "left key = " << heap[left] << ", ";
            if (right < H) {
                std::cout << "right key = " << heap[right] << ", ";
            }
        }
        std::cout << std::endl;
    }
}



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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    char ch = 'R';
    int c = 0;
    REP(i, N) {
        if(ch == 'R' && S[i] == 'L') {
            c += 2;
        }
        ch = S[i];
    }
    int indices[c];
    int rl[c];
    fill(rl, rl + c, 0);
    fill(indices, indices + c, 0);
    int index = 0;
    int nya = 0;
    ch = 'R';
    REP(i, N) {
        if(ch == S[i]) {
            rl[index] += 1;
        }else{
            if(ch == 'R' && S[i] == 'L') {
                indices[nya] = i - 1;
                indices[nya + 1] = i;
                nya += 2;
            }
            index += 1;
            rl[index] = 1;
        }
        ch = S[i];
    }

    int res[N];
    fill(res, res + N, 0);

    REP(i, c/2) {
        int r = indices[2*i];
        int l = indices[2*i + 1];

        int mr = rl[2*i];
        int ml = rl[2*i + 1];

        res[r] = (mr - mr/2) + ml/2;
        res[l] = mr/2 + (ml - ml/2);
    }
    REP(i, N) {
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}



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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, m;
    cin >> n >> m;
    REP(i, m){
        int a;
        cin >> a;
        n -= a;
    }
    cout << max(-1, n) << endl;
    return 0;
}


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

int bubbleSort(int A[], int n){
	int sw=0;
	int i=0;
	bool flag = 1;
	for(int i=0;flag;i++){
		flag=0;
		for(int j=n-1;j>i;j--){
			if(A[j-1]>A[j]){
				swap(A[j],A[j-1]);
				flag=1;
				sw++;
			}
		}
	}
	return sw;
}

int main(){
	int A[100],N,sw;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i]; 
	}
	
	sw = bubbleSort(A,N);
	
	for(int i=0;i<N;i++){
		if(i) cout<<" ";
		cout<<A[i];
	}
	cout<<endl;
	cout<<sw<<endl;
	return 0;
}

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

cnt = 0
clist = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
for i in range(len(S)):
    if S[i].islower():
        S = S.replace(S[i], clist[cnt])
        cnt += 1

cnt = 0
for i in range(len(T)):
    if T[i].islower():
        T = T.replace(T[i], clist[cnt])
        cnt += 1

if S == T:
    print('Yes')
else:
    print('No')


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MAX=100005;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,q;

    cin>>n>>q;
    vector<P> ev; //time id
    ll s,t;
    Vec rw(200020);
    REP(i,1,n+1){
        cin>>s>>t>>rw[i];
        ev.pb(mp(s-rw[i],i));
        ev.pb(mp(t-rw[i],-i));
    }
    sort(ALL(ev));
    //dbg(ev);
    set<P> active;
    ll k = 0;
    ll d;
    rep(i,q){
        cin>>d;
        while(k<ev.size()&& ev[k].fi<=d){
            ll id = ev[k].se;
            if(id>0){
                //activeイベント追加
                active.insert({rw[id],id});
            }else{
                //activeイベント削除
                active.erase({rw[-id],-id});
            }
            k++;
            //dbgmap(active);
        }
        if(active.empty()){
            cout<<-1<<endl;
        }else{
            cout<< active.begin()->first<<endl;
        }
    }

    return  0;
}


Measured memory_bytes: 21864
// 2011/03/23 Tazoe

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
	string str;
	getline(cin, str);

	vector<string::size_type> apple_pos;
	for(string::size_type pos=str.find("apple"); pos!=string::npos; pos=str.find("apple", 5+pos))
		apple_pos.push_back(pos);

	vector<string::size_type> peach_pos;
	for(string::size_type pos=str.find("peach"); pos!=string::npos; pos=str.find("peach", 5+pos))
		peach_pos.push_back(pos);

	for(int i=0; i<apple_pos.size(); i++)
		str.replace(apple_pos[i], 5, "peach");

	for(int i=0; i<peach_pos.size(); i++)
		str.replace(peach_pos[i], 5, "apple");

	cout << str << endl;

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
  /*行と列を設定する*/
  int H,W;
  cin>>H>>W;
  /*マスを設定し、入力*/
  vector<vector<char>> board(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>board.at(i).at(j);
    }
  }
  /*少なくとも一個黒いマスがあれば、その行と列は消去しない*/
  vector<bool> row(H,false);
  vector<bool> column(W,false);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(board.at(i).at(j)=='#'){
        row.at(i)=true;
        column.at(j)=true;
      }
    }
  }
  /*見ているのが消去しない(少なくとも一個黒いマスがある)行と列であれば順番に出力*/
  for(int i=0;i<H;i++){
    if(row.at(i)){
      for(int j=0;j<W;j++){
        if(column.at(j)){
          cout<<board.at(i).at(j);
        }
      }
      cout<<endl;/*全ての列が終わったら改行*/
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
#define MOD 1000000007
typedef long long int ll;
typedef unsigned long long int ull;
ll gcd(ll x,ll y){if(!y)return x;return gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void swap(ll *x,ll *y){ll tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}

ll modpow(ll a,ll n){
    ll res=1;
    while(n>0){
        if(n&1){res*=a;res%=MOD;}
        a*=a;a%=MOD;
        n>>=1;
    }
    return res;
}   
ll nCr(ll n,ll r){
    ll res,x,y;
    res=x=y=1;
    for(int i=0;i<r;i++){
        x*=(n-i);x%=MOD;
        y*=(r-i);y%=MOD;
    }
    res=modpow(y,MOD-2)%MOD;
    res=(res*x)%MOD;
    return res;
}


int main(){
    ll n,a,b;scanf("%lld %lld %lld",&n,&a,&b);

    ll x=modpow(2,n)-1;
    ll y=nCr(n,a)+nCr(n,b);
    y%=MOD;
    printf("%lld\n",(x-y+MOD)%MOD);
    
      
}


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

int main() {
  int N;
  cin >> N;
  int a,b;
  int counter = 0;

  //N回目まで繰り返す
  for(int i = 0; i < N ; ++i){
      //終端から最初をひいて座席数を数える
      cin >> a >> b;
      counter += b - (a - 1);
  }

  cout << counter << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<functional>
#include<cmath>
#include<vector>
#include<map>
//using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
using std::map;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
int rd(){int s=0,c,b=0;while(((c=getchar())<'0'||c>'9')&&c!='-');if(c=='-'){c=getchar();b=1;}do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9');return b?-s:s;}
void put(int x){if(!x){putchar('0');return;}static int c[20];int t=0;while(x){c[++t]=x%10;x/=10;}while(t)putchar(c[t--]+'0');}
int upmin(int &a,int b){if(b<a){a=b;return 1;}return 0;}
int upmax(int &a,int b){if(b>a){a=b;return 1;}return 0;}
map<int,int> s;
const int N=100010;
int a1[N],a2[N],s1[N],s2[N];
int n;
int main()
{
	open2("c");
	scanf("%d",&n);
	n/=2;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a1[i],&a2[i]);
		s1[a1[i]]++;
		s2[a2[i]]++;
	}
	for(int i=1;i<=100000;i++)
		s[n-s1[i]]++;
	int ans=2*n;
	for(int i=1;i<=100000;i++)
	{
		s[n-s1[i]]--;
		while(!(s.begin()->second))
			s.erase(s.begin());
		ans=min(ans,n-s2[i]+s.begin()->first);
		s[n-s1[i]]++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed_=(b);i<=_ed_;++i)
#define DREP(i,a,b) for(int i=(a),_ed_=(b);i>=_ed_;--i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)((x).size())
typedef long long ll;
typedef pair<int,int> pii;
inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x;
}

int n,p[200005];
vector<int> S[200005];
ll ans;

int tot=1,ch[1000005][26],siz[1000005];
void insert(vector<int>& S){
    static int pre[1000005][26];
    REP(i,1,sz(S))memset(pre[i],0,sizeof pre[i]);
    REP(i,0,sz(S)-1){
	memcpy(pre[i+1],pre[i],sizeof pre[i]);
	++pre[i+1][S[i]];
    }
    reverse(S.begin(),S.end());
    int p=1,t=sz(S);
    for(int c:S){
	REP(i,0,25)if(pre[t][i])ans+=siz[ch[p][i]];
	if(!ch[p][c])ch[p][c]=++tot;
	p=ch[p][c],--t;
    }
    ++siz[p];
}

int main(){
    //freopen("in.in","r",stdin);
    n=read();
    REP(t,1,n){
	static char s[1000005];
	scanf("%s",s+1);
	int l=strlen(s+1);
	REP(i,1,l)S[t].pb(s[i]-'a');
	p[t]=t;
    }
    sort(p+1,p+n+1,[&](int a,int b){return sz(S[a])<sz(S[b]);});
    REP(t,1,n){
	insert(S[p[t]]);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 212076
#include <iostream>

using namespace std;
 
int main(void) {
  int n;
  cin >> n;
  int w[n];
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  int m;
  m = 99999;
  for (int i = 1; i <= n-1; i++) {
    int w1 = 0;
    int w2 = 0;
    for (int j = 0; j <= i-1; j++) {
      w1 += w[j];
    }
    for (int j = i; j <= n-1; j++) {
      w2 += w[j];
    }
    m = min(m, abs(w1-w2));
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 504
//UG02-48-18-011

#include <stdio.h>
int main(){
int A_1,A_2,A_3;
scanf("%d%d%d",&A_1,&A_2,&A_3);
if(A_1+A_2+A_3==22 || A_1+A_2+A_3>22){
    printf("bust");
}
else
    printf("win");

}

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

#define HAS_TEST_CASE 0

namespace rG{

typedef long long ll;

const int N=5e5;
const int P=1e9+7;

int n,m,k,a[N+10];
char s[N+10];

int qpow(int a,int b,int p=P){
	int res=1;
	while(b){
		if(b&1)res=1LL*res*a%p;
		a=1LL*a*a%p;
		b>>=1;
	}
	return res;
}

inline void main(){
	scanf("%d",&n);
	int ans=((2LL*qpow(9,n)%P-qpow(8,n)%P)%P+P)%P;
	printf("%d\n",((qpow(10,n)-ans)%P+P)%P);
}

} // namespace rG

int main(){
#if defined(LOCAL)&&HAS_TEST_CASE
	freopen("tmp.out","w",stdout);
#endif
#if HAS_TEST_CASE
	int T;
	scanf("%d",&T);
	while(T--)rG::main();
#else
	rG::main();
#endif
	return 0;
}


Measured memory_bytes: 3852
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<string>
#include<cstdio>
#include<cctype>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<set>
#include<map>

using namespace std;

int main() {
	int n,a;
	cin>>n>>a;
	cout<<(n%500<=a?"Yes":"No");
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        double a,b,c,rad,s,l,h;
        a=scan.nextDouble();
        b=scan.nextDouble();
        c=scan.nextDouble();
        
        rad=Math.toRadians(c);
        
        s=(a*b*Math.sin(rad))/2;
        l=a+b+Math.sqrt(a*a+b*b-2*a*b*Math.cos(rad));
        h=b*Math.sin(rad);
        
        System.out.println(s);
        System.out.println(l);
        System.out.println(h);
    }
}


Measured memory_bytes: 27944
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	int A[N];
	int sum = 0;
	rep(i,N){
		cin >> A[i];
	}
	rep(i,N){
		sum ^= A[i];
	}
	rep(i,N){
		cout << (sum^A[i]) << " ";
	}
	cout << endl;
}

Measured memory_bytes: 5184
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

/* 先行順巡回 */
void preParse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

/* 中間順巡回 */
void inParse(int u) {
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

/* 後方順巡回 */
void postParse(int u) {
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

/*
9
0 1 4
1 2 3
2 -1 -1
3 -1 -1
4 5 8
5 6 7
6 -1 -1
7 -1 -1
8 -1 -1
*/



Measured memory_bytes: 2756
#include <stdio.h>

int main()
{
  int i,a[4] = {0},A = 0;

  for(i = 0;i < 4;i++){
    scanf("%d",&a[i]);
  }

  for(i = 0;i < 4;i++){
    A += a[i];
  }

  printf("%d\n%d\n",A/60,A%60);

  return 0;
}

Measured memory_bytes: 1764
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())
d1, d2, d3 = sorted(((x2 - x3) ** 2 + (y2 - y3) ** 2,
                     (x1 - x3) ** 2 + (y1 - y3) ** 2,
                     (x1 - x2) ** 2 + (y1 - y2) ** 2), reverse=True)
d1 = d1 ** .5
d2 = d2 ** .5
d3 = d3 ** .5
s = abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2
r = 2 * s / (d1 + d2 + d3)
print(d1 / (2 + d1 / r))

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

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n){
    cin>>v.at(i);
  }
  sort(v.begin(),v.end());
  if(v.at(n/2-1)==v.at(n/2)){
    cout<<0<<endl;
    return 0;
  }else{
    cout<<v.at(n/2)-v.at(n/2-1)<<endl;
      return 0;
    }
    return 0;
  }



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

vector<pair<int, int> > to[100005];
vector<int> color(100005, 0);

void dfs(int n, int b, int c){
    rep(i, to[n].size()){
        int a = to[n][i].first;
        if(a == b)continue;
        int x = to[n][i].second;
        int cc;
        if(x % 2 == 1){
            cc = (c+1)%2;
        } else {
            cc = c;
        }
        color[a] = cc;
        dfs(a, n, cc);
    }
    return;
}

int main() {
    int N; cin >> N;
    //to.resize(N);
    //color.resize(N);

    rep(i, N-1){
        int u, v, w; cin >> u >> v >> w;
        u--;
        v--;
        to[u].push_back(make_pair(v, w));
        to[v].push_back(make_pair(u, w));
    }

    dfs(0, -1, 0);

    rep(i, N){
        cout << color[i] << endl;
    }


    return 0;
}

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

int main()
{
  int N;scanf("%d",&N);
  int A[N+1],B[N];
  for(int i=0;i<N+1;i++)scanf("%d",&A[i]);
  for(int i=0;i<N;i++)scanf("%d",&B[i]);
  long long ans=0;
  for(int i=0;i<N;i++)
  {
    ans+=min(A[i]+A[i+1],B[i]);
    A[i+1]=min(A[i+1],max(A[i+1]+A[i]-B[i],0));
  }
  printf("%lld",ans);
}

Measured memory_bytes: 4624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();

        int answer = a * b;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27500
abcde = list(map(int, open(0).read().split()))

minimum = abcde[0] % 10
num = 0
for i in range(len(abcde)):
    if abcde[i] % 10 < minimum and abcde[i] % 10 != 0:
        minimum = abcde[i] % 10
        num = i

ans = 0
for i in range(len(abcde)):
    if i == num:
        ans += abcde[i]
        continue
    
    if abcde[i] % 10 != 0:
        ans += (abcde[i] // 10 + 1) * 10
    else:
        ans += abcde[i]
        
print(ans)

Measured memory_bytes: 3064