akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include<map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef unsigned int ui;
typedef unsigned short us;
typedef unsigned long long ull;

using namespace std;


int inputValue() {
  int a;
  scanf("%d", &a);
  return a;
};
void inputVector(vector<int>* v) {
  //cin.tie(0);
  //ios::sync_with_stdio(false);
  int a;
  while (cin >> a) {
    if (a == -1)break;
    v->push_back(a);
  }
};

void inputVector(vector<int> * p, int a) {
  p->clear();
  p->shrink_to_fit();
  rep(i, a) {
    int input;
    cin >> input;
    p->push_back(input);
  }
}

void inputVector2(vector<vector<int>>& v, ui r, ui c) {
  int temp;
  for (size_t i = 0; i < r; i++)
  {
    for (size_t j = 0; j < c; j++)
    {
      scanf("%d", &temp);
      v[i][j] = temp;
    }
  }
}
void inputVector3(vector<int>* v0, vector<int>* v1) {
  int a;
  unsigned short count = 0b0;
  while (cin >> a) {
    if (a == -1)break;
    if (count)v0->push_back(a); else v1->push_back(a);
    count = count ^ 1;
  }
};

template <typename T>
void output(T a, int precision) {
  if (precision > 0) {
    cout << setprecision(precision) << a << "\n";
  }
  else {
    cout << a << "\n";
  }
}

template<template <class...> class Map, typename T_0, typename T_1, typename... Args>
void inputMap(Map<T_0, T_1, Args...>& mp) {
  T_0 a;
  T_1 b;
  while (cin >> a && a != -1) {
    cin >> b;
    mp.insert(make_pair(a, b));
  }
}

template<template <class...> class Vec, typename T, typename U, typename... Args>
void numberToBoolenVector(Vec<T, Args...>& vec, U a) {
  ui i = 0;
  T amari;
  do {
    if (a % (ull)pow(2, i + 1)) {
      amari = 1;
      vec.push_back(amari);
      a -= (ull)pow(2, i);
    }
    else {
      amari = 0;
      vec.push_back(amari);
    }
    i++;
  } while (a);
}

template<template <class...> class Vec, typename T, typename... Args>
ull boolenVectorToNumber(Vec<T, Args...>& vec) {
  ull r = 0;
  for (size_t i = 0; i < vec.size(); i++)
  {
    r += vec[i] * (ull)pow(2, i);
  }
  return r;
}

int main(int argc, const char * argv[]) {
  string s;
  cin >> s;

  //ui r = 0;
  //while (1) {
  //  ui mozisu = s.size();
  //  for (size_t i = 0; i < mozisu-1; i++)
  //  {
  //    if (s[i] != s[0]) {

  //    }
  //  }
  //}

  ui c0 = 0;
  ui c1 = 0;
  for (size_t i = 0; i < s.size(); i++)
  {
    s[i]=='1' ? c1++ : c0++;
  }

  printf("%d", min(c0, c1)*2);

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=2005,INF=1<<30;

ll dp[MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    
    for(int i=0;i<MAX;i++) for(int j=0;j<MAX;j++) dp[i][j]=-INF;
    
    dp[0][1000]=0;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<=1000;j++){
            if(dp[i][j]<0) continue;
            
            chmax(dp[i+1][1005],dp[i][j]*A[i]+j);
            chmax(dp[i+1][j%A[i]],dp[i][j]+j/A[i]);
            chmax(dp[i+1][j],dp[i][j]);
        }
        
        chmax(dp[i+1][1005],dp[i][1005]);
        chmax(dp[i+1][dp[i][1005]%A[i]],dp[i][1005]/A[i]);
    }
    
    ll ans=0;
    
    for(int j=0;j<=1000;j++) if(dp[N][j]>=0) chmax(ans,ll(j));
    chmax(ans,dp[N][1005]);
    
    cout<<ans<<endl;
}





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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    vector<int> a(5);
    int ans = 0, tmp = 10;
    for (int i = 0; i < 5; ++i) {
        cin >> a[i];
        if (a[i] % 10 == 0) {
            ans += a[i];
        } else {
            ans += ((a[i] + 9) / 10) * 10;
            tmp = min(tmp, a[i] % 10);
        }
    }
    ans -= 10 - tmp;
    cout << ans;
    return 0;
}



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

#define fr(i,b,e) for(int i=(b); i!=(e); ++i)
#define rep(i,e) for(int i=0; i!=(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long int ll;
using graph = vector<vector<int>>;
using edgedp = vector<vector<pair<int,ll>>>;
constexpr int INF=1000000;
//constexpr int MOD=998244353;
constexpr int MOD=1e9+7;




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

    string s,t;
    cin >> s >> t;
    int n=s.length();
    if(n+1==t.length() && s==t.substr(0,n)){
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }
}   




Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
#define BUFSIZE 1000000007
typedef long long ll;
int N,K;

ll rem=0;
ll Sum(ll num){
	ll sum=0;
	ll sum2=0;
	if(num == N+2){
		return 0;
	}

	sum=((num-1)%BUFSIZE)*(num%BUFSIZE)/2;

	sum2=(N*2+1-num)*num/2;
	rem=rem + sum2 - sum + 1;
	rem=rem%BUFSIZE;
	Sum(num+1);
	return 0;
}

int main(void){
	scanf("%d",&N);
	scanf("%d",&K);
	if(N < K){
		printf("1");
		exit(0);
	}
	
	Sum(K);
	
		printf("%d",rem%BUFSIZE);
	
}

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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //int TL = 1.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    int a[n * 2];
    rep(i, 0, n * 2)
        cin >> a[i];
    sort(a, a + n * 2);
    int ans = 0;
    rep(i, 0, n)
        ans += a[i * 2];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

void Print(int pw) {
	long long x = (1LL<<pw);
	cout << x << "\n";
}

void Solve() {
	int n, p;
	cin >> n >> p;

	int even = 0, uneven = 0;

	for (int i = 1; i <= n; ++i) {
		int x;
		cin >> x;

		if (x&1) {
			++uneven;
		} else {
			++even;
		}
	}

	if (uneven == 0) {
		if (p == 1)
			cout << 0 << "\n";
		else Print(even + uneven);
	} else {
		Print(even + uneven - 1);
	}
}

int main() {
	int tests = 1;
	for (;tests; --tests) {
		Solve();
	}
}

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

using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
vector<ll> pw2(51,1);
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
map<ll,ll> prime_factor(ll x){map<ll,ll> ret;ll tmp=x;for(ll i=2;i*i<=x;i++){while(tmp%i==0){ret[i]++;tmp/=i;}}if(tmp!=1) ret[tmp]++;return ret;}
ll high_order_bit(ll n){ll tmp=1,i=-1;while(tmp<=n){tmp*=2;i++;}if(n==0) return 0;else return i;}
vector<ll> binary_expansion(ll n){vector<ll> B(high_order_bit(n)+1);ll tmp=n;for(ll i=high_order_bit(n);i>=0;i--){B[i]=tmp/pw2[i];tmp%=pw2[i];}return B;}
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;}

ll N;
vector<ll> S(13);
vector<ll> V(4500,INF);
ll ans=INF;

void rec(ll now,ll maxx){
    if(now==N+1){
        ll tmp2=0;
        rep(i,maxx+1){
            ll tmp=0;
            rep1(j,N){
                if(S[j]==i) tmp+=pw2[j-1];
            }
            tmp2+=V[tmp];
        }

        chmin(ans,tmp2);
        //rep1(i,N) cout<<S[i]<<" ";
        //cout<<"maxx:"<<maxx<<" ans:"<<ans<<endl;
         
        return; 
    }
    else{
        rep(i,maxx+2){
            S[now]=i;
            if(i==maxx+1) rec(now+1,i);
            else rec(now+1,maxx);
        }
        return;
    }
}

void rec2(ll now,ll x,ll A,ll sum){
    if(now==-1){
        if(A<V[sum]) V[sum]=A;
    }
    else{
        if((pw2[now]^x)<x){
            rec2(now-1,x,A,sum+pw2[now]);
            rec2(now-1,x,A,sum);
        }
        else rec2(now-1,x,A,sum);
    }
}

int main(){
    rep1(i,50) pw2[i]=2*pw2[i-1];
    ll M; cin>>N>>M;

    //V[鍵の種類]:最小値
    rep1(i,M){
        ll A,B; cin>>A>>B;
        ll tmp=0;
        rep(j,B){
            ll x; cin>>x;
            tmp+=pw2[x-1];
        }
        
        rec2(high_order_bit(tmp),tmp,A,0ll);

        //if(A<V[tmp]) V[tmp]=A;
    }
    rec(1,-1);

    if(ans==INF) cout<<-1;
    else cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c=0;
    scanf("%d",&a);
    int f[a];
    for(b=0;b<a;b++)
        scanf("%d",&f[b]);
    for(b=0;b<a;b++)
    {
        if(f[b]%2==0)
        if(f[b]%3!=0&&f[b]%5!=0) {printf("DENIED"); c=1; break;}
    }
    if(c==0) printf("APPROVED");
    return 0;
}

Measured memory_bytes: 128
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <cstdio>
using namespace std;

int main() {
	char chr;
	while(1){
		chr=cin.get();
		if(chr =='\n')break;
		if (isalpha(chr)){
				if (islower(chr))chr=toupper(chr);
				else chr=tolower(chr);
		}
		cout<<chr;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3080
fn main() {
    let (n, a) = input();
    let ans = solve(n, a);
    for v in ans.iter() { println!("{}", v); }
}

fn input() -> (usize, Vec<usize>) {
    let mut buf1 = String::new();
    let mut buf2 = String::new();
    std::io::stdin().read_line(&mut buf1).unwrap();
    std::io::stdin().read_line(&mut buf2).unwrap();
    buf1.pop();
    buf2.pop();
    let n: usize = buf1.parse().unwrap();
    let iter = buf2.split_whitespace();
    let a: Vec<usize> = iter.map(|s| s.parse().unwrap()).collect();
    (n, a)
}

fn solve(n: usize, a: Vec<usize>) -> Vec<usize> {
    let mut counter = vec![0usize; n+1];
    let mut pairs = vec![0usize; n+1];
    for v in a.iter() {
        counter[v-1] += 1;
    }
    for (i, c) in counter.iter().enumerate() {
        pairs[i] = get_pair(*c);
    }
    let sum: usize = pairs.iter().sum();
    let mut ans: Vec<usize> = Vec::new();
    for k in a.iter() {
        ans.push(sum - (counter[k-1] - 1));
    }
    ans
}

fn get_pair(n: usize) -> usize {
    if n == 0 { return 0; }
    (n * (n-1)) / 2
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

bool dp[90][90][14000];
lli leftt[90][90];
lli rightt[90][90];

signed main(){

	lli h,w;
	cin>>h>>w;

	REP(i,0,h)REP(j,0,w)cin>>leftt[i][j];
	REP(i,0,h)REP(j,0,w)cin>>rightt[i][j];
	
	dp[0][0][7000-leftt[0][0]+rightt[0][0]] = true;
	dp[0][0][7000-rightt[0][0]+leftt[0][0]] = true;

	REP(i,0,h)REP(j,0,w){
		lli ll = leftt[i][j]-rightt[i][j];
		lli rr = rightt[i][j]-leftt[i][j];
		if(i!=0)
		{
			REP(k,0,14000){
				lli llk = k+ll;
				lli rrk = k+rr;
				if(0<=llk && llk<14000)dp[i][j][llk] |= dp[i-1][j][k];
				if(0<=rrk && rrk<14000)dp[i][j][rrk] |= dp[i-1][j][k];
			}
		}
		if(j!=0)
		{
			REP(k,0,14000){
				lli llk = k+ll;
				lli rrk = k+rr;
				if(0<=llk && llk<14000)dp[i][j][llk] |= dp[i][j-1][k];
				if(0<=rrk && rrk<14000)dp[i][j][rrk] |= dp[i][j-1][k];
			}
		}
	}
	lli ans = INF;
	REP(i,0,14000){
		if(dp[h-1][w-1][i]){
			if(DEBUG)cout<<i<<endl;
			ans = min(ans,abs(7000-i));
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 100480
#include<stdio.h>

int main(){

  double speed, t, y, n;


  while(scanf("%lf",&speed) != EOF){

    t = speed / 9.8;
    y = 4.9 * t * t;

    n = y / 5 + 1;

    n += 0.5;

    printf("%.0f\n",n);


  }

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
using namespace std;
int main(){
	int h,w;
	while(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+j)%2==0)
					cout<<"#";
				else
					cout<<".";
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, m; cin >> n >> m;

    vector<pair<int, bool>> t(n);

    for (int i = 0; i < n; ++i) {
        t[i] = make_pair(0, false);
    }

    for (int i = 0; i < m; ++i) {
        int p; cin >> p; --p;
        string s; cin >> s;

        if (t[p].second == false) {
            if (s == "AC") {
                t[p].second = true;
            } else {
                t[p].first++;
            }
        }
    }

    int ac = 0;
    int wa = 0;

    for (int i = 0; i < n; ++i) {
        if (t[i].second == true) {
            ac++;
            wa += t[i].first;
        }
    }

    cout << ac << ' ' << wa << endl;
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int M = in.nextInt();
            int C[] = {-1, -1, -1};
            int[] digits = {0, 0, 0};

            while (M-- > 0)
            {
                int pos = in.nextInt() - 1;
                int digit = in.nextInt();
                if (C[pos] != -1 && C[pos] != digit)
                {
                    out.print(-1);
                    return;
                }
                C[pos] = digit;
                digits[pos] = digit;
            }

            if (N == 3 && C[0] == 0 && digits[0] == 0)
            {
                out.print(-1);
                return;
            }
            if (N == 2 && C[0] == 0 && digits[1] == 0)
            {
                out.print(-1);
                return;
            }

            String s = "";
            for (int i = 0; i < N; i++)
            {
                if (i == 0 && digits[0] == 0 && N != 1) digits[0] = 1;
                s += digits[i];
            }
            out.print(Integer.parseInt(s));
        }

    }
}



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

int main(void){
    char o[100],e[100],ans[200];
    int ol,el,i;

    scanf("%s%s",o,e);


    ol = strlen(o);
    el = strlen(e);

    for(i = 0;i < el;i++){
        ans[i * 2] = o[i];
        ans[i * 2 + 1] = e[i];
    }
    if(ol > el){
        ans[i * 2] = o[i];
        ans[i * 2 + 1] = '\0';
    }
    else
        ans[i * 2] = '\0';

    printf("%s\n",ans);
    return 0;
}

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

/*............................*/

#define uint uint64_t
#define mx 100001
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define mp make_pair
#define pb push_back
#define inf INT_MAX
#define pi acos(-1)
#define eps 1e-8
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / __gcd(a, b)
#define input(ara, n)          \
   for (int i = 0; i < n; i++) \
   scanf("%d", &ara[i])
#define inputl(ara, n)                   \
   for (long long int i = 0; i < n; i++) \
   scanf("%lld", &ara[i])
#define pf(a) printf("%d\n", a);
#define pfl(a) printf("%lld\n", a);
#define pfi(a) printf("%d ", a);
#define pfll(a) printf("%lld ", a);
#define sc(a) scanf("%d", &a)
#define scc(a, b) scanf("%d %d", &a, &b)
#define sccdbl(a, b) scanf("%lf %lf", &a, &b)
#define sccc(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scccdbl(a, b, c) scanf("%lf %lf %lf", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define sccl(a, b) scanf("%lld %lld", &a, &b)
#define scccl(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
using namespace std;
int main()
{
   ll n;
   scl(n);
   ll a,b;
   scl(a);
   for(ll i=1;i<n;i++){
      scl(b);
      a=gcd(a,b);
   }
   pfl(a);
   return 0;
}

Measured memory_bytes: 3772
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < (long)n; i++)
#define ll long long
#define pb push_back
long N;

ll make_num(long n, long i){
  return n * pow(10, N - i - 1);
}

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

  // 入力
  rep(i, N){
    cin >> tmp;
    a += make_num(tmp, i);
  }
  tmp = 0;
  rep(i, N){
    cin >> tmp;
    b += make_num(tmp, i);
  }
  // cout << a << " " << b << endl;

  // Nの順列を生成する
  vector<long> v(N);
  rep(i, N) {
    v[i] = i+1;
  }
  vector<ll> sum;
  tmp = 0;
  // １個目だけは特別な処理をする
  rep(i, N) {
    tmp += make_num(v[i], i);
  }
  // cout << tmp << endl;
  sum.push_back(tmp);
  while( next_permutation(v.begin(), v.end()) ){ // 次の順列を生成
    tmp = 0;
    rep(i, N) {
      tmp += make_num(v[i], i);
    }
    // cout << tmp << endl;
    sum.push_back(tmp);
  };

  // aの番号を求める
  long a_num = 1;
  for(ll x: sum) {
    if(x < a) a_num++;
  }

  // bの番号を求める
  long b_num = 1;
  for(ll x: sum) {
    if(x < b) b_num++;
  }

  // cout << a_num << " " << b_num << endl;
  cout << abs(a_num - b_num) << endl;

  return 0;

}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    vec<ll> s(n);
    REP(i, n) { cin >> s[i]; }
    sort(all(s));
    ll q;
    cin >> q;
    ll con = 0;
    while(q--) {
        ll t;
        cin >> t;
        if(binary_search(all(s), t))
            con++;
    }
    cout << con << en;
}

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

    solve();

    /*
    ll t;
    cin >> t;
    REP(i, t) { solve();}
    */

    return 0;
}



Measured memory_bytes: 3516
#include<vector>
template<typename T>
class LazyPropagationSegmentTree {
public:
  LazyPropagationSegmentTree(int n) : size_(1) {
    while(size_ < n) size_ <<= 1;
    node_.assign(size_ << 1, 0);
    lazy_.assign(size_ << 1, 0);
  }
  T find(int left, int right) {return find(left, right + 1, 1, 0, size_);}
  void add(int left, int right, T value) {add(left, right + 1, value, 1, 0, size_);}
private:
  int left_child(int node) const {return node << 1;}
  int right_child(int node) const {return (node << 1) + 1;}
  T find(int a, int b, int k, int l, int r) {
    if(b <= l || r <= a) return 0;
    if(a <= l && r <= b) return node_.at(k) + (r - l) * lazy_.at(k);
    lazy_.at(left_child(k)) += lazy_.at(k);
    lazy_.at(right_child(k)) += lazy_.at(k);
    lazy_.at(k) = 0;
    auto vl = find(a, b, left_child(k), l, (l + r) / 2);
    auto vr = find(a, b, right_child(k), (l + r) / 2, r);
    return vl + vr;
  }
  T add(int a, int b, T value, int k, int l, int r) {
    if(b <= l || r <= a) return node_.at(k) + (r - l) * lazy_.at(k);
    if(a <= l && r <= b) return node_.at(k) + (r - l) * (lazy_.at(k) += value);
    lazy_.at(left_child(k)) += lazy_.at(k);
    lazy_.at(right_child(k)) += lazy_.at(k);
    lazy_.at(k) = 0;
    auto vl = add(a, b, value, left_child(k), l, (l + r) / 2);
    auto vr = add(a, b, value, right_child(k), (l + r) / 2, r);
    return node_.at(k) = vl + vr;
  }
  int size_;
  std::vector<T> node_;
  std::vector<T> lazy_;
};

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

struct Node {int f; long long h;};
bool operator<(const Node& lhs, const Node& rhs) {
  if(lhs.h != rhs.h) return lhs.h < rhs.h;
  return lhs.f < rhs.f;
}

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

  LazyPropagationSegmentTree<long long> hp(N + 1);
  hp.add(0, N, H);

  long long answer = 0;
  int last = 0;
  priority_queue<Node> q;

  for(int i = 1; i < N; ++i) {
    long long d, h;
    cin >> d >> h;

    q.push({i, h});
    hp.add(i, N, -d);

    while(hp.find(i, i) <= 0) {
      auto node = q.top();

      if(node.f < last) {
        q.pop();
        continue;
      }

      if(H < node.h + hp.find(node.f-1, node.f-1)) {
        q.pop();
        q.push({node.f, H - hp.find(node.f-1, node.f-1)});
        continue;
      }

      last = node.f;
      int use = min((-hp.find(i, i) / node.h) + 1, (H - hp.find(node.f-1, node.f-1)) / node.h);
      answer += use;
      hp.add(node.f-1, N, use * node.h);
    }
  }

  cout << answer <<endl;
}

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

int main() {
 long int W,H,x,y;
  int a;
  cin >> W >> H >> x >> y;
  long double w,h,s;
  w=W;
  h=H;
  s=w*h/2.0000000;
  if(x==w/2 && y==h/2){
   a=1; 
  }
  else{
   a=0; 
  }
  cout << s << ' ' << a << endl;
}


Measured memory_bytes: 256
n = m = gets.to_s.to_i

a = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049, 531441, 1000000000]
ans = 0
while m > 0
  
  k = a.bsearch_index { |x| x > m }
  m -= a[k-1]
  ans += 1
  
end

(n+1).times do |i|
  
  c = 0
  t = i
  while t > 0
    c += t%6
    break if ans <= c
    t /= 6
  end
  
  next if ans <= c
  
  t = n-i
  while t > 0
    c += t%9
    break if ans <= c
    t /= 9
  end
  
  ans = c if ans > c
end

puts ans

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

const int INT_INF = 1e9;
const long long LONG_INF = 1e18;
const long long MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

using namespace std;

int main()
{
    int n;
    cin >> n;
    int temp = n % 10;

    if (temp == 2 || temp == 4 || temp == 5 || temp == 7 || temp == 9)
    {
        cout << "hon" << endl;
    }
    else if (temp == 0 || temp == 1 || temp == 6 || temp == 8)
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "bon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
int main() {
	int n, m, a[100], cou = 0, sum = 0;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		sum += a[i];
	}
	for (int i = 0; i < n; i++) {
		if (a[i] >= (double)sum / (4 * m)) {
			cou++;
		}
	}
	printf("%s\n", m <= cou ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;

int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	vector < pair < string, pair < int, int >> > vec;
	int n;

	cin >> n;

	for (int i = 1; i <= n; i++) {
		string s;
		int a;
		cin >> s >> a;
		vec.push_back(make_pair(s, make_pair(-a, i)));
	}

	sort(vec.begin(), vec.end()); // 第1キー、第２キー 、、、の順にソートされる

	for (int i = 0; i < n; i++)
		cout << vec[i].second.second << endl;

	return 0;

}

Measured memory_bytes: 896
MOD = 10**9+7

h,w = gets.split.map(&:to_i)
a = Array.new(h){ gets.chomp }

dp = Array.new(h){ Array.new(w, 0) }
dp[0][0] = 1

h.times do |i|
  w.times do |j|
    next if a[i][j] == "#"
    if i + 1 < h
      dp[i+1][j] += dp[i][j]
      dp[i+1][j] %= MOD
    end

    if j + 1 < w
      dp[i][j+1] += dp[i][j]
      dp[i][j+1] %= MOD
    end
  end
end

p dp[-1][-1]

Measured memory_bytes: 24240
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

bool check(int n, bool d[]) {
	while (n > 0) {
		if (d[n % 10]) {
			return false;
		}
		n /= 10;
	}
	return true;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	bool d[10] = {};
	rep(i, k) {
		int num;
		cin >> num;
		d[num] = true;
	}
	int ans = n;
	while (!check(ans, d)) {
		ans++;
	}
	cout << ans << "\n";
	return 0;
}

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

int main() {
  string s,t;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
    bool TF=1;
    for(int j=0;j<s.size();j++){
      if(s.at((i+j)%s.size())!=t.at(j))
        TF*=0;
    }
    if(TF==1){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll count = 0;
    vector<ll> P;
    cin >> N;
    P.resize(N);
    rep(i, N) cin >> P[i];
    rep2(i, 1, N) {
        if(P[i - 1] == i) {
            count++;
            swap(P[i], P[i - 1]);
        }
    }
    if(P.back() == P.size()) count++;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 1024
package main

import (
  "fmt"
  "sort"
)

func main() {
  var a,b,c int
  fmt.Scan(&a, &b, &c)
  slice := []int{a, b, c}

  sort.Sort(sort.IntSlice(slice))
  fmt.Println(slice[0], slice [1], slice[2])
}


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

int main() {
	
	//vector<int> a(n);  sort(a.begin(),a.end());
	//cout << "test" << "\n";

	cin.tie(0);
	ios::sync_with_stdio(false);
	
	//string ans="YES";
	
	ll ans=0;


	ll n;
	cin >> n;
	
	vector<string> a(n);
	
	rep(i,n){
		cin >> a[i];
		sort(a[i].begin(),a[i].end());
	}
	
	sort(a.begin(),a.end());
	
	ll m=1; //memo
	
	rep(i,n-1) {
		if(a[i]==a[i+1]) m++;
		else{
			ll c=m*(m-1)/2;
			ans+=c;
			//cout << c << " " << i << endl;
			m=1;
		}
	}
	ll c=m*(m-1)/2;
	ans+=c;

	

	cout << ans << "\n";
	
	
	return 0;

    }

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

using namespace std;

typedef long long ll;

const int N = 1e5;
const int INF = 1e9;

int al[8];

int main() {
    int x;
    for (int i = 0; i < 3; i++) {
        cin >> x;
        al[x]++;
    }
    if (al[5] > 1 && al[7])
        cout << "YES";
    else
        cout << "NO";
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

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

    int n, m;
    cin >> n >> m;
    
    multiset<int> mu;

    for(int i = 0; i < n; ++i)
    {
        int a;
        cin >> a;
        mu.insert(a);
    }

    ll ans = 0LL;
    for(int i = m; i > 0; --i)
    {
        if(mu.empty())
            break;
        //cout << sz(mu) << '\n';
        int naj = *mu.rbegin();
        //cout << naj << '\n';
        mu.erase(prev(mu.end()));
        naj >>= 1;
        //cout << naj << '\n';
        if(naj)
            mu.insert(naj);
    }
    //cout << mu.size() << '\n';

    for(auto z : mu)
    {
        //cout << z << '\n';
        ans += 1LL * z;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 8280
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  long long int n,sum=0,h=1;
  cin >> n;
  string s=to_string(n);
  string t;
  for(int i=0;i<s.size();i++){
    sum+=(h*9);
    h*=10;
  }
  if(sum==n) cout <<9*s.size()<<endl;
  else{
    if(n<10){
      cout<< n<<endl;
      return 0;
    }
    for(int i=1;i<s.size();i++){
      if(s[i]!='9') break;
      if(i==s.size()-1){
        sum=0;
        for(int i=0;i<s.size()-1;i++) sum+=9;
        char l=s[0];
        int a=l-'0';
        cout<< a+sum<<endl;
        return  0;
      }
    }
    sum=0;
    for(int i=0;i<s.size()-1;i++) sum+=9;
    char l=s[0];
    int a=l-'0';
    cout<< a-1+sum<<endl;
  }
}


Measured memory_bytes: 256
n,a,b=map(int,input().split())
x=int(n/(a+b))
y=n%(a+b)
if a==0:
    print(0)
elif y==0:
    print(a*x)
elif 0<y<a+1:
    print(a*x+y)
else:
    print(a*(x+1))

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        long l = sc.nextLong();
        long r = sc.nextLong();
        long min = 2018;

        if (l - r >= 2018) {
            System.out.println(0);
        } else {
            for (long i = l; i <= r ; i++) {
                for (long j = i + 1; j <= r ; j++) {
                    long val = (i % 2019 * j % 2019) % 2019;
                    if (val == 0) {
                        System.out.println(0);
                        return;
                    }
                    min = Math.min(val , min);
                }
            }
            System.out.println(min);
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  VI p(21);
  REP(i,n) {
    int x;
    cin >> x;
    p[x]++;
  }
  REP1(i,1,20) {
    p[i]+=p[i-1];
  }
  cout << min({p[a],p[b]-p[a],p[20]-p[b]});
  return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define SORT(v,n) sort(v,v+n)
#define rep(i,n) FOR(i,0,n)
#define EPS (1e-7)
#define INF (1e9)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef priority_queue<int> PQI;
typedef priority_queue<int,vector<int>,greater<int> > PQSI;
typedef priority_queue<ll> PQL;
typedef priority_queue<ll,vector<ll>,greater<ll> > PQSL;

const int MOD = 1000000007;
struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};
void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

template<typename T>
T gcd(T x, T y){
    if (y == 0) return x;
    else return gcd(y, x % y);
}

template<typename T>
T lcm(T x, T y){
    return (x / gcd(x, y)) * y;
}

template<typename T>
T ceil(T x, T y){
    return (x + (y - 1)) / y;
}

int N, X;
int L[100];
int main(void){
    cin >> N >> X;
    rep(i,N) scanf("%d",&L[i]);
    int count = 0, sum = 0;
    while(true){
        sum += L[count];
        count++;
        if (X < sum or count == N+1) break;
    }
    cout << count << endl;

    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int v[1000][1000];
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<ll>sum(n + 1);
  rep(i,n){
    if(s[i] == 'W')sum[i + 1] = sum[i] + 1;
    else sum[i + 1] = sum[i];
  }
  ll ans = INF;
  REP(i,1,n + 1){
    ll l = sum[i - 1];
    ll r = (n - i) - (sum[n] - sum[i]);
    ans = min(ans,l + r); 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/lexical_cast.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define mp make_pair
#define endl '\n'
#define PI acos(-1)
#define bitcount(a) __builtin_popcountll(a)
#define P pair<int,int>
typedef tree<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

long mod=1e9+7;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s,t;
	cin>>s>>t;
	int ans=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]==t[i])
			++ans;
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

int cmp(int* a, int* b)
{
	return (*a < *b) ? 1 : ((*a > *b) ? -1 : 0);
}

int main()
{
	int dat[10];

	for (int i = 0; i < 10; i++)
	{
		cin >> dat[i];
	}

	qsort(dat, 10, sizeof(int), reinterpret_cast<int(*) (const void*, const void*)>(cmp));

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

	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
using namespace std;
bool check(string x, string y) {
  int a = x.size()-1;
  return x[a] == y[0];
}

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if(check(a, b) && check(b, c)) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3628
'use strict';
(function(input){
  input=input.trim().split(' ').map(x=>x-0);
  let A=input[0],B=input[1],K=input[2];
  let L=Math.max(0,K-A);
  console.log([Math.max(A-K,0),Math.max(B-L,0)].join(' '));
})(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 11468
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int n,a[N];
#define no return puts("No"),0
bool check (int l,int r)
{
	int mi=oo,ma=0,ma1=0;
	for (int i=l; i<=r; i++)
		chkmin (mi,a[i]),chkmax (ma,a[i]);
	if (mi!=l||ma!=r) return 0;
	ma=0;
	for (int i=l; i<=r; i+=2)
	{
		if (ma< a[i]) ma=a[i];
		else if (ma1< a[i]) ma1=a[i];
		else return 0;
	}
	return 1;
}
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n);
	for (int i=1; i<=n; i++)
		sc(a[i]);
	for (int i=1,j; i<=n; i++) if (a[i]!=i)
	{
		j=i;
		while (j<=n-2)
			if (a[j+1]!=j+1||a[j+2]==j+2) break;
			else j+=2;
		if (!check (i,j)) no;
		i=j;
	}
	puts("Yes");

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 1e5 + 10;
int n;
int a[MAXN];
bool cmp(int x , int y){
	return x > y;
}
int main(){
	ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 1 ; i <= n ; ++ i)
		cin >> a[i];
	sort(a + 1 , a + n + 1 , cmp);
	int cur = n;
	for(int i = 1 ; i <= n ; ++ i)
		if(i > a[i]){
			cur = i - 1;
			break;
		}
	if(cur != n && a[cur + 1] == cur){
		int tmp = cur + 1;
		while(tmp < n && a[tmp + 1] == cur)
			tmp ++;
		if(((tmp - cur) & 1)){
			cout << "First" << endl;
			return 0;
		}
	}
	cout << (((a[cur] - cur) & 1) ? "First" : "Second") << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int a[5];
int d[15];
int main(){
	for(int i=1;i<=3;i++){
		scanf("%d",&a[i]);
		d[a[i]]++;
	}
	if(d[5]==2&&d[7]==1){
		printf("YES\n");
	}
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
Stones = list(input())

count_red = 0
count_white = 0

for i in range(N):
  if Stones[i] == "R":
    count_red += 1
    
for i in range(count_red):
  if Stones[i] == "W":
    count_white += 1
    
print(count_white)

Measured memory_bytes: 82892
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<llint,vector<llint>,greater<llint>> que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

llint x,y,z,k;

void solve(){
	cin >> x >> y >> z >> k;
	llint a[x],b[y],c[z];
	for(int i=0;i<x;i++)cin >> a[i];
	for(int i=0;i<y;i++)cin >> b[i];
	for(int i=0;i<z;i++)cin >> c[i];
	sort(a,a+x);
	reverse(a,a+x);
	sort(b,b+y);
	reverse(b,b+y);
	sort(c,c+z);
	reverse(c,c+z);
	for(int i=0;i<x;i++){
		for(int j=0;j<y;j++){
			for(int l=0;l<z;l++){
				if((i+1)*(j+1)*(l+1)<=k) q.push(a[i]+b[j]+c[l]);
				else break;
			}
		}
	}
	for(int i=0;i<k;i++){
		cout << q.top() << endl;
		q.pop();
	}

}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 1400
// ハッシュ
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch)
{
    if( ch == 'A' ) return 1;
    else if( ch == 'C' ) return 2;
    else if( ch == 'G' ) return 3;
    else if( ch == 'T' ) return 4;
    else return 0;
}

// 文字列から数値へ変換して　key を生成する
long long getKey(char str[])
{
    long long sum = 0, p = 1, i;

    for( i = 0; i < strlen(str); i++ )
    {
        sum += p * ( getChar(str[i]) );
        p *= 5;
    }

    return sum;
}

int h1(int key)
{
    return key % M;
}

int h2(int key)
{
    return 1 + ( key % ( M - 1 ) );
}

int find(char str[])
{
    long long key, i, h;

    // 文字列を数値に変換
    key = getKey(str);

    for( i = 0; ; i++ )
    {
        // ハッシュ値を生成
        h = ( h1(key) + i * h2(key) ) % M;

        if( strcmp(H[h], str) == 0 )
        {
            // 検索文字列が見つかった
            return 1;
        }
        else if( strlen(H[h]) == 0 )
        {
            // 検索文字列が見つからなかった
            return 0;
        }
    }

    return 0;
}

int insert(char str[])
{
    long long key, i, h;

    // 文字列を数値に変換
    key = getKey(str);

    for( i = 0; ; i++ )
    {
        // ハッシュ値を生成
        h = ( h1(key) + i * h2(key) ) % M;

        if( strcmp(H[h], str) == 0 )
        {
            // 文字列は既に登録済み
            return 1;
        }
        else if( strlen(H[h]) == 0 )
        {
            // 文字列を入れる所が見つかった
            strcpy(H[h], str);
            return 0;
        }
    }

    return 0;
}

int main(void)
{
    int i, n, h;
    char str[L], com[9];

    for( i = 0; i < M; i++ )
    {
        // 配列の初期化
        H[i][0] = '\0';
    }

    scanf("%d", &n);

    for( i = 0; i < n; i++ )
    {
        scanf("%s %s", com, str);

        if( com[0] == 'i' )
        {
            insert(str);
        }
        else
        {
            if( find(str) )
            {
                printf("yes\n");
            }
            else
            {
                printf("no\n");
            }
        }
    }

    return 0;
}



Measured memory_bytes: 16048
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, W: "List[str]"):
    already = []
    for n in range(N-1):
        if W[n] in already:
            print(NO)
            exit()
        already.append(W[n])
        if W[n][-1] != W[n+1][0]:
            print(NO)
            exit()
    if W[-1] in already:
        print(NO)
        exit()
    print(YES)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064