akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/perl

use strict;
use warnings;

my ($x, $y);
{
    my $in = <STDIN>;
    ($x, $y) = split(" ", $in);
}
my $ans = 0;
$ans += 100000 * (4 - $x) if $x<4;
$ans += 100000 * (4 - $y) if $y<4;
$ans += 400000 if $x==1 && $y==1;

print "$ans\n";

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define DIVCEIL(A,B) ((A+(B-1))/B)
using namespace std;


void solve(long long sx, long long sy, long long tx, long long ty){
    auto w=tx-sx;
    auto h=ty-sy;
    for(int i=0; i<h; i++)cout << "U";
    for(int i=0; i<w; i++)cout << "R";
    for(int i=0; i<h; i++)cout << "D";
    for(int i=0; i<w; i++)cout << "L";
    cout << "L";
    for(int i=0; i<h+1; i++)cout << "U";
    for(int i=0; i<w+1; i++)cout << "R";
    cout << "D";
    cout << "R";
    for(int i=0; i<h+1; i++)cout << "D";
    for(int i=0; i<w+1; i++)cout << "L";
    cout << "U" << endl;
}

int main(){
    long long sx;
    scanf("%lld",&sx);
    long long sy;
    scanf("%lld",&sy);
    long long tx;
    scanf("%lld",&tx);
    long long ty;
    scanf("%lld",&ty);
    solve(sx, sy, tx, ty);
    return 0;
}


Measured memory_bytes: 256
// ?
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

int main(){
    string s;
    cin >> s;
    int n = s.length();
    vector<int> v(3000, 0);
    v[0]++;
    ll ans = 0, ten = 1;
    int tmp = 0;
    for(int i = n-1; i >= 0; i--){
        tmp += ten*(s[i]-'0')%2019;
        tmp %= 2019;
        ans += v[tmp]++;
        ten = ten*10%2019;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3724
#include<iostream>
#include<ios>
// std::left;          // 左揃えで出力
// std::right;         // 右揃えで出力
// std::internal;      // 符号左揃え、数字右揃え
// std::showpos;       // 正の符号も出力
#include<iomanip>
// std::setw(int);     // 文字幅を指定
// std::setfill(char); // 詰めたい文字を指定
using namespace std;

void makeMagicSquare( int n )
{
    int m[n][n];
    for( int i = 0; i < n; i++ )
        for( int j = 0; j < n; j++ )
            m[i][j] = -1;

    m[n/2+1][n/2] = 1;

    int i = n / 2 + 2, j = n / 2 + 1, k = 2;
    while( true )
    {
        bool judge = true;
        for( int s = 0; s < n; s++ )
            for( int t = 0; t < n; t++ )
                if( m[s][t] == -1 )
                    judge = false;
        if( judge == true )
            break;
        if( 0 <= i && i < n && 0 <= j && j < n && m[i][j] == -1 )
        {
            m[i][j] = k;
            k++;
            i++;
            j++;
        }
        else if( i >= n && j >= n )
        {
            i = 0;
            j = 0;
        }
        else if( i >= n )
            i = 0;
        else if( j >= n )
            j = 0;
        else if( j < 0 )
            j = n - 1;
        else if( m[i][j] != -1 )
        {
            i++;
            j--;
        }
        else;
    }

    for( int i = 0; i < n; i++ )
    {
        for( int j = 0; j < n; j++)
            cout << setfill(' ') << right << setw(4) << m[i][j];
        cout << endl;
    }
}

int main()
{
    int n;

    while( cin >> n )
    {
        if( n == 0 )
            break;
        
        makeMagicSquare(n);
    }
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int H,W;cin>>H>>W;
  vector<vector<int>> corr(10,vector<int>(10));
  REP(i,0,10)REP(j,0,10)cin>>corr[i][j];
  vector<int> dist(10,0),visited(10,0);
  REP(i,0,10){
    dist[i]=corr[i][1];
  }
  while(true){
    int min_dist=INF,idx,flg=0;
    REP(i,0,10){
      if(visited[i])continue;
      flg=1;
      REP(j,0,10){
        if(visited[j]){
          dist[i]=min(dist[i],corr[i][j]+dist[j]);
        }
      }
      if(dist[i]<=min_dist){
        min_dist=dist[i];
        idx=i;
      }
    }
    if(!flg)br;
    visited[idx]=1;
  }
  // debug(dist);
  int a,ans=0;
  REP(i,0,H)REP(j,0,W){
    cin>>a;
    if(a==-1)continue;
    ans+=dist[a];
  }
  print(ans);




}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= m; j++) {
				if (i * j + (n - i) * (m - j) == k) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 23764
#include<iostream>

using namespace std;

int main() {
	int a, b;
	int work;
	int ans = 0;
	while (cin >> a >> b) {
		ans = 0;
		work = a + b;
		while (work > 0) {
			work = work / 10;
			ans++;
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
#include<math.h>
#include<pthread.h>
#include<omp.h>
#define mall (node*)malloc(sizeof(node))
using namespace std;
typedef long long ll;
ll mod=998244353;
ll sum[200005]={0};
ll n,q;
ll tree[800005]={0},laz[800005]={0};
void chan(ll k,ll l,ll r,ll l1,ll r1,ll x)
{
	if(l1<=l&&r<=r1)
	{
		tree[k]=(sum[r+1]-sum[l])*x%mod;
		tree[k]=(tree[k]+mod)%mod;
		laz[k]=x;
	}
	else if(l1<=r&&l<=r1)
	{
		ll m=(l+r)/2;
		if(laz[k])
		{
			laz[k*2+1]=laz[k];
			laz[k*2+2]=laz[k];
			tree[k*2+1]=(sum[m+1]-sum[l])*laz[k]%mod+mod;
			tree[k*2+2]=(sum[r+1]-sum[m+1])*laz[k]%mod+mod;
			tree[k*2+1]%=mod,tree[k*2+2]%=mod;
			laz[k]=0;
		}
		chan(k*2+1,l,m,l1,r1,x);
		chan(k*2+2,m+1,r,l1,r1,x);
		tree[k]=(tree[k*2+1]+tree[k*2+2])%mod;
	}
}
int main(void)
{
	scanf("%lld%lld",&n,&q);
	sum[1]=1;
	for(ll i=2;i<=n;i++) sum[i]=(sum[i-1]*10)%mod;
	for(ll i=2;i<=n;i++) sum[i]=(sum[i]+sum[i-1])%mod;
	tree[0]=sum[n],laz[0]=1;
	while(q--)
	{
		ll l,r,d;
		scanf("%lld%lld%lld",&l,&r,&d);
		chan(0,0,n-1,n-r,n-l,d);
		printf("%lld\n",tree[0]);
	}
}


Measured memory_bytes: 13584
def resolve():
    N = int(input())
    a = list(map(int, input().split()))
    cnt = 1
    ans = 0
    for i in range(N):
        if a[i] == cnt:
            cnt += 1
        else:
            ans += 1
    if ans == N:
        print(-1)
        return
    print(ans)

    return
resolve()

Measured memory_bytes: 24744
loop do
  m, f, r = gets.split.map(&:to_i)
  break if m == -1 and f == -1 and r == -1
  sum = m + f
  st = if m == -1 or f == -1
    "F"
  elsif sum >= 80
    "A"
  elsif sum >= 65
    "B"
  elsif sum >= 50
    "C"
  elsif sum >= 30
    (r >= 50) ? "C" : "D"
  else
    "F"
  end
  puts st
end


Measured memory_bytes: 6876
#include<iostream>
#include<cstdio>
#define MN 4000
#define mod 1000000007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,K,f[MN+5][MN+5];
inline void R(int&x,int y){x+=y;x>=mod?x-=mod:0;} 
int main()
{
	n=read();m=read();K=read();
	f[0][0]=1;int maxtower=(n+m-1)/(K-1);
	for(int i=1;i<=maxtower;++i)
		for(int j=0;j<=m;++j) if(f[i-1][j])
			for(int k=0;k<K&&j+k<=m;++k)
				R(f[i][j+k],f[i-1][j]);
	int ans=0;
	for(int i=1;i<=maxtower;++i) for(int j=1;j<=m;++j) 
		if(j%(K-1)==m%(K-1)&&(K-1)*i-j<=n-1) R(ans,(f[i][j]-f[i-1][j]+mod)%mod);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 61056
N=int(input())
lis = [[0 for i in range(10)] for i in range(10)]
for i in range(1,N+1):
    fir = i//(10**(len(str(i))-1))
    las = i%10
    lis[fir][las]+=1
sum=0
for i in range(0,10):
    for j in range(i,10):
        if i==j:
            sum+=lis[i][j]*(lis[i][j]-1)+lis[i][j]
        else:
            sum+=lis[i][j]*lis[j][i]*2

#print(*lis, sep="\n")
print(sum)


Measured memory_bytes: 40300
import copy

S = list(input())
T = list(input())
candidate = []
if len(T) > len(S):
    print("UNRESTORABLE")
    exit()
for i in range(len(S) - len(T) + 1):
    c = 0
    A = copy.copy(S)
    check = False
    for j in range(len(T)):
        if A[i + j] == T[j]:
            c += 1
        elif A[i + j] == "?":
            A[i + j] = T[j]
            c += 1
        else:
            break
        if c == len(T):
            candidate = A
print("".join(candidate).replace("?", "a") if candidate else "UNRESTORABLE")


Measured memory_bytes: 38384
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        n:usize,
    }
    let mut g = G::new(n);
    g.dfs(vec![], 'a');
    for s in g.ans {
        for &c in s.iter() {
            print!("{}", c);
        }
        println!();
    }
}
struct G {
    n: usize,
    ans: Vec<Vec<char>>,
}
impl G {
    fn new(n: usize) -> G {
        G {
            n: n,
            ans: Vec::<Vec<char>>::new(),
        }
    }
    fn dfs(&mut self, st: Vec<char>, mx: char) {
        if st.len() == self.n {
            self.ans.push(st);
        } else {
            let cc = charconv(mx, 'a');
            for ch in 0..=cc {
                let mut nx = st.clone();
                nx.push(('a' as u8 + ch as u8) as char);
                self.dfs(nx, if ch == cc { (mx as u8 + 1) as char } else { mx });
            }
        }
    }
}

pub fn charconv(c: char, base: char) -> usize {
    return (c as u8 - base as u8) as usize;
}


Measured memory_bytes: 13700
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		int a1 = Integer.parseInt(s.substring(0, 2));
		int a2 = Integer.parseInt(s.substring(2, 4));

		boolean m1 = false;
		if(1<=a1 && a1 <= 12) {
			m1=true;
		}
		boolean m2 = false;
		if(1<=a2 && a2 <= 12) {
			m2=true;
		}

		String ans = "";
		if(m1 && m2) {
			ans = "AMBIGUOUS";
		}else if(m1 && ! m2) {
			ans = "MMYY";
		}else if(! m1 && m2) {
			ans = "YYMM";
		}else {
			ans = "NA";
		}
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 21972
import itertools

N = int(input())
L = list(map(int, input().split()))

L.sort()

candidates = itertools.combinations(L, 3)

count = 0

for t in candidates:
    if t[0] == t[1] or t[1] == t[2]:
        continue
    if t[0] + t[1] > t[2]:
        count += 1

print(count)


Measured memory_bytes: 9176
n,q = list(map(int, input().split()))
P = [[p,int(t)] for p,t in [input().split() for _ in range(n)]]
time = 0
while len(P) > 0:
    pi = P.pop(0)
    if pi[1] > q:
        P.append([pi[0],pi[1]-q])
        time += q
    else:
        time += pi[1]
        print(pi[0],time)

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int a, p;
	cin >> a >> p;

	int num = a * 3 + p;

	out(num / 2);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

const int MAX_V = 1010;
const int MAX_E = 2020;
bool negative = false;

struct edge {
  int from, to, cost;
};

edge es[MAX_E];
int d[MAX_V];
int V, E; // 頂点数、辺数

void bellman_ford(int s) {
  for(int i = 0; i < V; i++) d[i] = INF;
  d[s] = 0;
  int counter = 0;

  for(int i = 0; i < V; i++) {
    bool update = false;
    for(int j = 0; j < E; j++) {
      edge e = es[j];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if(!update) break;
    if(i == V - 1) negative = true;
  }
}

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

    int start;
    cin >> V >> E >> start;
    rep(i, E) {
        cin >> es[i].from >> es[i].to >> es[i].cost;
    }

    bellman_ford(start);

    if(negative) {
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }

    rep(i, V) {
        if(d[i] != INF) cout << d[i] << endl;
        else cout << "INF" << endl;
    }
    return 0;
}


Measured memory_bytes: 3236
//
//  Competitive Programming
//  Don't Copy Be Original - Ehsaan Rahman
//  Copyright © 2020 Ehsaan Rahman. All rights reserved.
//
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<bitset>
#include<cstring>
#include<stack>
#include<queue>
#include<set>
#include<chrono>
#include<list>
#include<climits>
#include<iomanip>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #define PBDS tree<long long int,null_type,less<long long int>, rb_tree_tag,tree_order_statistics_node_update>
// using namespace __gnu_pbds;
#define arrsize 300001
#define dpsize 1001
#define vpp vector<PP>
#define vll vector<ll>
#define vcc vector<char>
#define vbb vector<bool>
#define w(t) while(t--)
#define PP pair<ll,ll>
#define szs(x) x.length()
#define szv(x) x.size()
#define INF 1999999996000000010
#define ll long long int
#define takeINP(arr,n) for(long long int i=0;i<n;i++) cin>>arr[i];
#define f(i,s,e) for(long long int i=s;i<e;i++)
#define cf(i,s,e) for(long long int i=s;i<=e;i++)
#define rf(i,e,s) for(long long int i=e-1;i>=s;i--)
#define mem(arr) memset(arr,0,sizeof(arr));
#define MOD 1000000007
#define pp(a,b) make_pair(a,b)
#define pb push_back
#define print(arr,s,e) f(i,s,e) cout<<arr[i]<<" "; cout<<endl;
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define vll vector<ll>
#define triplet pair<ll,pair<ll,ll> >
#define MITR(a,b) map<a,b>::reverse_iterator 
using namespace std;
using namespace chrono;

///Author - Ehsaan Rahman - Don't Copy Be Original
///---------------Functions---------------------///
ll advceil(ll num,ll den){return (num%den==0?num/den:num/den+1);}
ll lstbt(ll val){ ll msk = val&(val-1); return log2(val^msk);}
ll expo(ll a,ll b){	ll res=1;	while(b>0){		if(b&1) res = (res%MOD*a%MOD)%MOD;		a = (a%MOD*a%MOD);		b/=2;	}	return res;}
ll gcd(ll a,ll b){ return a==0?b:gcd(b%a,a); }

///---------x------------x----------x-----------///

void solve(){
	ll n; cin>>n;
	ll arr[arrsize];
	takeINP(arr,n);
	ll ans = 0;
	ll prev = arr[0];

	f(i,1,n){
		if(arr[i]<prev) ans+=prev-arr[i];
		prev=max(prev,arr[i]);
	}
	cout<<ans<<endl;
}

int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r" ,stdin);
		freopen("output.txt", "w" ,stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    auto start1 = high_resolution_clock::now();
    solve();
    auto stop1 = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stop1 - start1);
    #ifndef ONLINE_JUDGE
		cerr << "Time: " << duration.count() / 1000.0 << endl;
	    cout<<duration.count()/1000.0<<endl;
    #endif
}

Measured memory_bytes: 5136
import math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        d = 0
        for k in range(D):
            d += (X[i][k]-X[j][k])**2
        d = math.sqrt(d)

        if d.is_integer():
            ans += 1

print(ans)


Measured memory_bytes: 9148
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
const int MAXN=2e5+10;
const int Mod=1e9+7;
int n,Col[MAXN],Last[MAXN],F[MAXN];
int main()
{   scanf("%d",&n),F[1]=1;
	for(rg int i=1;i<=n;i++) scanf("%d",&Col[i]);
	Last[Col[1]]=1;
	for(rg int i=2;i<=n;i++)
		F[i]=(F[i-1]+F[Last[Col[i]]]*(Last[Col[i]]!=i-1))%Mod,Last[Col[i]]=i;
	printf("%d\n",F[n]);
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	cin >> N >> A >> B >> C;
	ll a = 0, b = 0, c = 0;
	vector<ll>l(N);
	for (int i = 0; i < N; i++)cin >> l[i];
	ll mp = 100000;
	for (int bita = 1; bita < (1 << N); bita++) {
		bool flag = 0;
		ans = 0;
		a = 0;
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			if (bita&(1 << i)) {
				a += l[i];
				cnt++;
			}
		}
		ans += 10 * (cnt - 1) + abs(A - a);
		for (int bitb = 1; bitb < (1 << N); bitb++) {
			cnt = 0;
			b = 0;
			flag = 0;
			int tmp = ans;
			for (int i = 0; i < N; i++) {
				if (bitb&(1 << i)) {
					if (bita&(1 << i)) {
						flag = 1;
						break;
					}
					b += l[i];
					cnt++;
				}
			}
			if (flag)continue;
			tmp += 10 * (cnt - 1) + abs(B - b);
			for (int bitc = 1; bitc < (1 << N); bitc++) {
				cnt = 0;
				flag = 0;
				c = 0;
				ll tmp2 = tmp;
				for (int i = 0; i < N; i++) {
					if (bitc&(1 << i)) {
						if (bita&(1 << i) || bitb & (1 << i)) {
							flag = 1;
							break;
						}
						c += l[i];
						cnt++;
					}
				}
				if (flag)continue;
				tmp2 += 10 * (cnt - 1) + abs(C - c);
				mp = min(mp, tmp2);
			}
		}
	}
	cout << mp << endl;
}

Measured memory_bytes: 256
//競技プログラミング　テンプレ
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

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

const int max_v = 300;
const int INF = 1000000;



int main() {
	int n,s,m, ans=0;
    map<int, int> mp;
	cin >> n;
	vector <int> A(n);
	//string str;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
    REP(i,n){
        s=A[i];
        mp[s]++;
    }
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        s= itr ->first;
        m= itr ->second;
        //cout << itr -> first <<endl << itr -> second << endl;
        if(s<m) ans+=m-s;
        else if(s>m) ans+=m;
    }
	//sort(A.begin(), A.end());
    
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5120
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <numeric>

using namespace std;

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

    int result = 0;
    int pos[n][d] = {};
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            cin >> pos[i][j];
        }

        if(i == 0){
            continue;
        }

        for(int k = 0 ; k < i ; k++){
            int distance_sq = 0;
            for(int l = 0; l < d ; l++){
                int d = pos[i][l] - pos[k][l];
                distance_sq += d * d;
            }

            double distance = sqrt((double)distance_sq);
            if(distance == (int)distance){
                result++;
            } 
        }

    }

    cout << result << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N, L;
    cin >> N >> L;
    int sum = 0;
    int diff = 1e+9;
    for(int i = 1; i <= N; i++){
        sum += (L+i-1);
        if(abs(diff) > abs(L+i-1)) diff = (L+i-1);
    }
    cout << sum-diff << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int n, k, ans = 0, roop, save3[10], roop2, card[10], res, save2;
bool save[100000000];
void solve(){
	roop--;
	for (int i = 0; i<n; i++){
		if(save3[i]==1) continue;
			if (roop == 0){
				save2 = res;
				if(card[i]/10>=1){
					res = res*100;
				}
				else{
					res = res*10;
				}
				res += card[i];
				if (save[res] == 0){
					ans++;
					save[res]=1;
				}
				res = save2;
			}
			else{
				if(card[i]/10>=1){
					res = res*100;
				}
				else{
					res = res*10;
				}
				res += card[i];
				save3[i]=1;
				solve();
				save3[i]=0;
				roop++;
				res -= card[i];
				if(card[i]/10>=1){
					res = res/100;
				}
				else{
					res = res/10;
				}
		}
	}
}
int main() {
	while (true){
		cin >> n >> k;
		roop2 = 0;
		if (n == 0 && k == 0){
			return 0;
		}
		for (int i = 0; i < n; i++){
			cin >> card[i];
		}
		for (int i = 0; i < n; i++){
			roop = k - 1;
			res = card[i];
			save3[i] = 1;
			solve();
			save3[i]=0;
		}
		cout << ans << endl;
		ans=0;
		for (int i = 0; i < 10000000; i++){
			save[i] = 0;
		}
	}
}

Measured memory_bytes: 40096
function bomb(str){
   min=Math.min(min,str.length);
   for(var i=0;i<str.length;i++){
      if(str[i]==str[i+4]){
         var arr=str.split("");
         arr[i]="";
         arr[i+4]="";
         bomb(arr.join(""));
      }
      if(i!=3 && i!=7 && i!=11 && i!=15){
         if(str[i]==str[i+1]){
            var arr=str.split("");
            arr[i]="";
            arr[i+1]="";
            bomb(arr.join(""));
         }
         if(str[i]==str[i+5]){
            var arr=str.split("");
            arr[i]="";
            arr[i+5]="";
            bomb(arr.join(""));
         }
      }
      if(i!=0 && i!=4 && i!=8 && i!=12){
         if(str[i]==str[i+3]){
            var arr=str.split("");
            arr[i]="";
            arr[i+3]="";
           bomb(arr.join(""));
         }
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var n=arr.shift()-0;
while(n--){
   var str="";
   for(var i=0;i<5;i++)str+=arr.shift();
   str=str.replace(/ /g,"");
   var min=20;
   bomb(str);
   console.log(min);
}

Measured memory_bytes: 18204
# 2020/06/13
# 東京海上日動　プログラミングコンテスト2020 - B

# Input
a, v = map(int,input().split())
b, w = map(int,input().split())
t = int(input())

dist = max(a, b) - min(a, b)
chase = v * t - w * t   # tで縮む距離

# Calc
if w >= v:
    ans = 'NO'
else:
    if dist <= chase:
        ans = 'YES'
    else:
        ans = 'NO'

# Output
print(ans)


Measured memory_bytes: 9180
/* 
* ID: juryc
* PROG: 500 Yen Coins
* LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int k,x; cin>>k>>x;
int v=k*500;
if(v>=x) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 3628
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

vector<string> split(const string &s, const char &delim) {
  istringstream ss(s);
  string got;
  vector<string> v;
  while (getline(ss, got, delim)) v.pb(got);
  return v;
}

void solve() {
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    if (regex_match(s, regex(">'=+#=+~"))) {
      vs v = split(s, '#');
      if (v[0].size() - 2 == v[1].size() - 1) {
        cout << "A" << endl;
        continue;
      }
    }
    if (regex_match(s, regex(">\\^(Q\\=)+~~"))) {
      cout << "B" << endl;
      continue;
    }
    cout << "NA" << endl;
  }
}

Measured memory_bytes: 3228
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdbool.h>


int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	if (a >= 13)printf("%d", b);
	else if (a <= 5)printf("%d", 0);
	else printf("%d", b / 2);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 200001
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REV(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
const ll INF = 9e18;
ll n, h[MAX_N];

signed main(){
    cin >> n;
    REP(i, n) cin >> h[i];
    ll cnt = 0, ret = 0;
    REP(i, n-1){
        if(h[i] - h[i+1] >= 0) cnt++;
        else cnt = 0;
        ret = max(ret, cnt);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<tuple>
#include<utility>
using namespace std;

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

typedef long long ll;


int abc107_b(){
    //入力
    int h,w;
    cin >> h >> w;
    vector<string> v(h);
    REP(i,h){
        cin >> v[i];
    }

    //処理
    vector<bool> row(h,false);
    vector<bool> column(w,false);
    REP(i,h){
        REP(j,w){
            if(v[i][j] == '#'){
                row[i] = true;
                column[j] = true;
            }
        }
    }
    
    //出力
    REP(i,h){
        if(row[i]){
            REP(j,w){
                if(column[j]){
                    cout << v[i][j];
                }
            }
            cout << enter;
        }
    }
    
    return 0;
}

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


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

int main() {
  int N;
  cin >> N;
  vector <int> item(N);
  
  for (int i = 0; i < N; i++) {
    cin >> item.at(i);
 }
  
  sort(item.begin(), item.end());
  cout << item[N-1] - item[0] << endl;
}

Measured memory_bytes: 3520
a,b = map(int,input().split())

def ExtGCD(a,b): #ax+by=GCD(a,b)の解(x,y)
    flag = True
    if a < b:
        a,b = b,a
        flag = False
    r0, r1, s0, s1, t0, t1 = a, b, 1, 0, 0, 1
    while r1 != 0:
        q, r2 = r0//r1, r0%r1
        r0, s0, t0, r1, s1, t1 = r1, s1, t1, r2, s0-s1*q,t0-t1*q
    d = r0
    if flag :
        return (d,s0,t0)
    else:
        return (d,t0,s0)

print(str(ExtGCD(a,b)[1])+" "+str(ExtGCD(a,b)[2]))



Measured memory_bytes: 5600
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
void BubbleSort(char **A,int n)
{
  int i,j;
  int buf[3];
  for(i=0;i<n;i++)
    {
      for(j=n-1;j>i;j--)
        {
          if(A[j-1][1]>A[j][1])
            {
              strcpy(buf,A[j-1]);
              strcpy(A[j-1],A[j]);
              strcpy(A[j],buf);
            }
        }
    }
  printf("%s",A[0]);
  for(i=1;i<n;i++)
    {
      printf(" %s",A[i]);
    }
  printf("\n");
}
void SelectionSort(char **A,int n)
{
  int i,j;
  int min;
  char buf[3];
  for(i=0;i<n;i++)
    {
      min=i;
      for(j=i;j<n;j++)
        {
          if(A[j][1]<A[min][1])
            {
              min=j;
            }
        }
      if(i!=min)
        {
          strcpy(buf,A[i]);
          strcpy(A[i],A[min]);
          strcpy(A[min],buf);
        }
    }
  printf("%s",A[0]);
  for(i=1;i<n;i++)
    {
      printf(" %s",A[i]);
    }
  printf("\n");
}
void Gudge(int n,char **card,char **A)
{
  int i,j,f;
  int c=0;
  for(i=1;i<n;i++)
    {
      if(A[i-1][1]==A[i][1])
        {
          for(j=c;j<n;j++)
            {
              if(A[i-1][1]==card[j][1])
                {
                  if(A[i-1][0]==card[j][0])
                    {
                      for(f=j+1;f<n;f++)
                        {
                          if(A[i][1]==card[f][1])
                            {
                              if(A[i][0]==card[f][0])
                                {
                                  c=j+1;
                                  j=n;
                                  break;
                                }
                              else
                                {
                                  i=n;
                                  j=n;
                                  break;
                                }
                            }
                        }
                    }
                  else
                    {
                      i=n;
                      break;
                    }
                }
            }
        }
      else
        {
          c=0;
        }
    }
  if(i==n+1)
    {
      printf("Not stable\n");
    }
  else
    {
      printf("Stable\n");
    }
}
int main()
{
  int n;
  char **card;
  char **card1;
  char **card2;
  int i,j;
  int f;
  scanf("%d",&n);
  card =(char**)malloc(sizeof(char*)*n);
  card1=(char**)malloc(sizeof(char*)*n);
  card2=(char**)malloc(sizeof(char*)*n);
  for(i=0;i<n;i++)
    {
      card[i] =(char*)malloc(sizeof(char)*3);
      card1[i]=(char*)malloc(sizeof(char)*3);
      card2[i]=(char*)malloc(sizeof(char)*3);
      scanf("%s",card[i]);
      strcpy(card1[i],card[i]);
      strcpy(card2[i],card1[i]);
    }
  BubbleSort(card1,n);
  Gudge(n,card,card1);
  SelectionSort(card2,n);
  Gudge(n,card,card2);
  return 0;
}


Measured memory_bytes: 2088
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;


int main(void){
  int a;
  cin >> a;

  cout << a+a*a+a*a*a << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)
        return true;
    while(d!=n-1)
    {
        x=(x*x)%n;
        d*=2;
        if(x==1)
            return false;
        if(x==n-1)
            return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)
        return false;
    if(n<=3)
        return true;
    ll d=n-1;
    while(d%2==0)
        d/=2;
    for(int i=0; i<k; i++)
    {
        if(!miller_rabin(d,n))
            return false;
    }
    return true;
}
int n;
string s;
ll ans = 0;

void solve(ll x,ll y)
{
    if(x==n+1)
    {
        ans += y;
        return;
    }
    ll cur = 0;
    for(ll i=x; i<=n; i++)
    {
        cur = (10*cur) + (s[i]-'0');
        solve(i+1,y+cur);
    }
}
bool cmp(const pair<int,int>& x,const pair<int,int>& y){return x.second>y.second;}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int cnt[n+2]={0};
    int a[n+2];
    set<int>s;
    for(int i=0;i<n;i++){
        cin>>a[i];
        s.insert(a[i]);
        cnt[a[i]]++;
    }
    vector<pair<int,int> >v;
    for(auto x: s){
        v.push_back({x,cnt[x]});
    }
    sort(v.begin(),v.end(),cmp);
    ll sum=0;
    for(int i=k;i<v.size();i++)sum+=v[i].second;
    cout<<sum<<endl;
}


Measured memory_bytes: 16280
/*zxj*/
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
using namespace std;
#define csh(a,n) memset(a,n,sizeof(a));
int main(){
	int a,b;
	cin>>a>>b;
	int min=b-a+1;
	int max=b+a-1;
	if(min<-1000000){
		min=-1000000;
	}
	if(max>1000000){
		max=1000000;
	}
	for(int i=min;i<=max;i++){
		if(i!=min){
			cout<<' ';
		}
		cout<<i;
	}
}

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

int main() {
    int n, m, t; cin >> n >> m;
    for (int i=0; i<m; i++) {
        cin >> t;
        n -= t;
    }
    if (n < 0) cout << -1 << endl;
    else cout << n << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i;
	double r, ans;
	cin >> r;
	ans = 2.0 * r * PI;
	printf("%.10lf\n", ans);
	return 0;
}

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

using namespace std;

int main(void)
{
	int res=700;
	string s;

	cin >> s;

	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='o')
		{
			res+=100;
		}
	}

	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 764
#include<stdio.h>

int main(){
  int i,j,k,q,n,x,p=1,r;

  scanf("%d",&n);
  int A[n+1];
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  r=n;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      k=A[i];
      A[i]=A[j];
      A[j]=k;
    }
  }
  k=A[i+1];
  A[i+1]=A[r];
  A[r]=k;
  q=i+1;
  for(i=1;i<q;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[q]);
  for(i=q+1;i<n+1;i++){
    if(i<n){
      printf("%d ",A[i]);
    }
    else{
      printf("%d\n",A[i]);
    }
  }
}



Measured memory_bytes: 2088
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char[] s = sc.next().toCharArray();
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		ArrayList<Integer> xList = new ArrayList<>();
		ArrayList<Integer> yList = new ArrayList<>();
		
		boolean isX = true;
		int cnt=0;
		for(int i=0; i<=s.length; i++) {
			if(i==s.length || s[i]=='T') {
				if(isX)
					xList.add(cnt);
				else
					yList.add(cnt);
				cnt=0;
				isX ^= true;
			} else {
				cnt++;
			}
		}

		x -= xList.get(0);
		xList.remove(0);
		System.out.println(reachable(xList, x) && reachable(yList, y) ? "Yes" : "No");
		
		sc.close();
	}
	
	static boolean reachable(ArrayList<Integer> list, int goal) {
		HashSet<Integer> set = new HashSet<Integer>();
		set.add(0);
		
		for(int v : list) {
			HashSet<Integer> next = new HashSet<>();
			for(int base : set) {
				next.add(base + v);
				next.add(base - v);
			}
			set = next;
		}
		
		return set.contains(goal);
	}
}


Measured memory_bytes: 93220
N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
grid = [list(map(int, input().split())) for _ in range(N)]
D0 = {i: 0 for i in range(C)}
D1 = {i: 0 for i in range(C)}
D2 = {i: 0 for i in range(C)}
for i in range(N):
  for j in range(N):
    if (i+j) % 3 == 0:
      D0[grid[i][j]-1] += 1
    elif (i+j) % 3 == 1:
      D1[grid[i][j]-1] += 1
    elif (i+j) % 3 == 2:
      D2[grid[i][j]-1] += 1
m = int(1e11) + 23
for i in range(C):
  for j in range(C):
    for k in range(C):
      if i != j and j != k and k != i:
        differ = 0
        for l in range(C):
          differ += D0[l] * D[l][i]
          differ += D1[l] * D[l][j]
          differ += D2[l] * D[l][k]
        if m > differ:
          m = differ
print(m)

Measured memory_bytes: 6900
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_N 40
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll,double> P;

int n, m;
int a[100000], b[100000];
set<ll> s;

int main(){
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) s.insert(a[i]);
    cin >> m;
    rep(i,m) cin >> b[i];
    int ans = 0;
    rep(i,m) if(s.count(b[i])) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 5672
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#define Abs                           \
	ios_base::sync_with_stdio(false); \
	cout.tie(NULL);                   \
	cin.tie(NULL);
#define FOR(i, b, a) for (ll i = b; i < a; i++)
#define FOR1(i, b, a) for (ll i = b; i <= a; i++)
#define FORd(i, b, a) for (int i = (a)-1; i >= b; i--)
const double PI = acos(-1);
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define iq(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define endl "\n"
#define sz(v) ((ll)((v).size()))
#define fx(n) fixed << setprecision(n)
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
const ll mod = 1e9 + 7;
int main()
{
	Abs;
	ll n;
	cin >> n;
	ll l = 0, r = 1e6 + 1, ans = 0;
	while (true)
	{
		l++;
		ans = ans * 10 + 7;
		ans %= n;
		
		if (!ans)
		{
			cout << l << endl;
			break;
		}
		if (l >= r)
		{
			cout << "-1" << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3652
n = int(input())
ab = []
for _ in range(n): ab.append([int(x) for x in input().split()])
c = 0
for a, b in ab[::-1]:
    if b == 1 or (a + c) % b == 0: continue
    else: c += b - (a + c) % b
print(c)

Measured memory_bytes: 21924
INT_MAX=10**18+7
x=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
###############################################################################
s=input()
prev=0
sum=0
i=0
while(i<len(s)):
    if s[i]=="<":
        count1=0
        while(i<len(s) and s[i]=="<" ):
            count1+=1
            i+=1
        sum=sum+(count1*(2*prev+1+count1))//2
        prev=prev+count1
    else:
        count=0
        while(i<len(s) and s[i]==">"):
            count+=1
            i+=1
        if count>prev:
            sum-=prev
            prev=count
            sum+=((count)*(count+1))//2
            prev=0
        else:
            sum+=(count*(count-1))//2
            prev=0
print(sum)


Measured memory_bytes: 43936
#include<bits/stdc++.h>
using namespace std;
const int mo=1e9+7;
int main(){
	long long a=1,b=0,c=0,d=0;int n;scanf("%d",&n);
	for(int i=0;i<n;i++){
		d=(b+c+d*10)%mo;
		b=(b*9+a)%mo;
		c=(c*9+a)%mo;
		a=a*8%mo;
	}
	printf("%d",d);
	return 0;
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main()
{int x;
 cin >> x;
 
 bool  k = false;
 if (x == 3 || x == 5 || x == 7) k = true;
 
 cout << (k ? "YES" : "NO" ) << endl;
 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n,a,b,c;
  cin>>n;
  a=n/3;
  b=n/5;
  c=n/15;
  if(n%2==0){
    n=n/2*(n+1);
  }else{
    n=(n+1)/2*n;
  }
  cout<<n-3*a*(a+1)/2-b*5*(b+1)/2+15*c*(c+1)/2<<endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)


typedef long long ll;

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


/*************************************************************************/
//多次元配列の確保及び初期化用マクロ
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
/*************************************************************************/


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int dp[ARRAY_MAX];

int main() {

	int n;
	cin >> n;
	dp[0] = 0;

	for (int i = 1; i < ARRAY_MAX; i++)
	{
		dp[i] = dp[i - 1] + 1;
	}

	

	for (int i = 6; i <= n; i *= 6)
	{
		for (int j = 0; j <= n; j++)
		{
			if (j + i <= n)
			{
				dp[j + i] = min(dp[j + i], dp[j] + 1);
			}
		}
	}

	
	for (int i = 9; i <= n; i *= 9)
	{
		for (int j = 0; j <= n; j++)
		{
			if (j + i <= n)
			{
				dp[j + i] = min(dp[j + i], dp[j] + 1);
			}
		}
	}

	/*for (int i = 0; i <= n; i++)
	{
		dp[i + 1] = min(dp[i + 1], dp[i] + 1);
	}*/


	cout << dp[n] << endl;

	return 0;
}


Measured memory_bytes: 640
H, N= map(int,input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
ma = max(A)
dp = [0] * (H + ma)
dp[0] = 0
for i in range(N):
    a = A[i]
    b = B[i]
    for j in range(1, H + ma):
        if dp[j] == 0:
            dp[j] = dp[j - a] + b
        else:
            dp[j] = min(dp[j - a] + b, dp[j])
print(min(dp[H:]))


Measured memory_bytes: 43228
/*  -*- coding: utf-8 -*-
 *
 * 2870.cc: The Diversity of Prime Factorization
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_P = 1000000;
const int MOD = 1000000007;

/* typedef */

/* global variables */

bool primes[MAX_P + 1];
int qs[MAX_N], dp[MAX_N][2];

/* subroutines */

void gen_primes(int maxp) {
  memset(primes, true, sizeof(primes));
  primes[0] = primes[1] = false;

  for (int p = 2; p * p <= maxp; p++)
    if (primes[p])
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
}

inline void addmod(int &a, int b) { a = (a + b) % MOD; }

/* main */

int main() {
  gen_primes(MAX_P);

  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", qs + i);

  if (! primes[qs[0]]) {
    puts("0");
    return 0;
  }

  dp[0][0] = 1;
  for (int i = 1; i < n; i++) {
    if (primes[qs[i]]) {
      if (primes[qs[i - 1]] && qs[i - 1] < qs[i])
	addmod(dp[i][0], dp[i - 1][0]);
      if (i >= 2 && primes[qs[i - 2]] && qs[i - 2] < qs[i])
	addmod(dp[i][0], dp[i - 1][1]);
    }

    dp[i][1] = dp[i - 1][0];
  }
  //for (int i = 0; i < n; i++) printf("%d,%d ", dp[i][0], dp[i][1]);

  printf("%d\n", (dp[n - 1][0] + dp[n - 1][1]) % MOD);
  return 0;
}



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

int arr[10],N,largest=-1,sum=0;
int main(){
  cin >> N;
  for (int i=0;i<N;i++){
    cin >> arr[i];
    sum += arr[i];
    if (arr[i] > largest){
      largest = arr[i];
    }
  }
  sum -= largest/2;
  cout << sum;
  return 0;
}



Measured memory_bytes: 256