akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int n, a[3][112345], b[112345], c[112345];

    cin >> n;
    REP(i, n)
    cin >> a[0][i + 1] >> a[1][i + 1] >> a[2][i + 1];

    int dp[112345][3];

    dp[1][0] = a[0][1];
    dp[1][1] = a[1][1];
    dp[1][2] = a[2][1];

    for (int i = 2; i <= n; i++)
    {
        REP(j, 3)
        {
            int tmp = 0;
            REP(k, 3)
            {
                if (k == j)
                    continue;

                tmp = max(tmp, dp[i - 1][k] + a[j][i]);
            }

            dp[i][j] = tmp;
        }
    }

    int res = max(dp[n][0], dp[n][1]);
    res = max(res, dp[n][2]);

    cout << res << endl;

    return 0;
}

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

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

  if (X == 7 || X == 5 || X == 3)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}


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

int main() {
  long long q,h,s,d,n;
  cin >>q>>h>>s>>d>>n;
  long long yasui1=min({q*4,h*2,s});
  long long yasui2=min(n/2*d,yasui1*n);
  long long kotae=LLONG_MAX;
  if(n%2==0)kotae=min(yasui1*n,yasui2);
  else kotae=min(yasui1*n,n/2*d+yasui1);
  cout<<kotae<<endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <unordered_map>

#define MIN(a,b) (a)>(b)?(b):(a)

using namespace std;

int main() {
	int N;
	cin >> N;
	long ans = 0;
	unordered_map<string, int> S;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		if (S.find(s) == S.end()) {
			S[s] = 0;
		}
		else {
			S[s] ++;
		}
	}
	for (auto& i : S) {
		long f = i.second;
		ans += f * (f + 1) / 2;
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 10660
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC073A
{
    class Program
    {
        static void Main(string[] args)
        {
            String n;

            n = Console.ReadLine();

            if (n[0] == '9' || n[1] == '9')
                Console.WriteLine("Yes");

            else
                Console.WriteLine("No");

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
s=input()

l=0
r=len(s)-1
ans=0
while l<r:
    if s[l]=='x' and s[r]=='x':
        l+=1
        r-=1
    elif s[l]=='x' and s[r]!='x':
        l+=1
        ans+=1
    elif s[l]!='x' and s[r]=='x':
        r-=1
        ans+=1
    elif s[l] == s[r]:
        l+=1
        r-=1
    else:
        ans=-1
        break
print(ans)

Measured memory_bytes: 3316
#include <iostream>
using namespace std;
string leftkey="qwertasdfgzxcvb";
string s;
bool r,l;
int cnt;
int main(){
	while(1){
		cin >>s;
		if(s=="#")break;
		cnt=0;
		r=l=false;
		for(int i=0;i<s.size();i++){
			for(int j=0;j<leftkey.size();j++){
				if(s[i]==leftkey[j]){
					if(r&&!l)cnt++;
					l=true;
					r=false;
					break;
				}else if(j==leftkey.size()-1){
					if(!r&&l)cnt++;
					l=false;
					r=true;
				}
			}
		}
		cout << cnt<<endl;
	}
	return 0;
}

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

using namespace std;
using llint = long long;
using pint = pair<int,int>;

#define LOG(x) cout << "# " << #x <<" => "<< (x) <<endl

const int INF = 1<<28;
const llint LLINF = 1LL<<60;

int n, x, ans=0;
vector<int> l;

vector<int> cumulativeSum(vector<int> &a){
    int n = a.size();
    vector<int> res(n+1);

    res.at(0) = 0;

    for (int i = 1; i <= n; ++i) {
        res.at(i) = a.at(i-1) + res.at(i-1);
    }
    
    return res;
}

int main() {
    // Input
    cin >> n >> x;
    l.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> l.at(i);
    }

    // Solve
    vector<int> ls = cumulativeSum(l);
    for (int i = 0; i <= n; ++i) {
        if (ls.at(i)<=x)
        {
            ++ans;
        }
    }

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

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

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

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

  cin >> q;
  for (int i = 0; i < q; ++i) {
    int com, b, e;
    cin >> com >> b >> e;

    if (com == 0) {
      int mn = 1e9;
      for (int j = b; j < e; ++j)
        mn = min(mn, a[j]);
      cout << mn << endl;
    } else {
      int mx = -1e9;
      for (int j = b; j < e; ++j)
        mx = max(mx, a[j]);
      cout << mx << endl;
    }
  }
}


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

int main() {
	int n;
	while (scanf("%d", &n), ~n) {
		double x = 1, y = 0;
		rep(i, n - 1) {
			double X = ((x - y) - (x + y)) / 2, Y = ((x - y) + (x + y)) / 2;
			double d = sqrt(x*x + y*y);
			x += X / d; y += Y / d;
		}
		printf("%.7lf\n%.7lf\n", x, y);
	}
}

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

int main() {
    int N=0,K=0;
    cin >> N >> K;
    string S;
    cin >> S;
    if(S.at(K-1)=='A'){
        S.at(K-1)='a';
    }
    if(S.at(K-1)=='B'){
        S.at(K-1)='b';
    }
    if(S.at(K-1)=='C'){
        S.at(K-1)='c';
    }
    cout << S << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int H, W; cin >> H >> W;
    vector<string> ans(H + 2);
    for(int h = 0; h < H + 2; h++) {
        if(h == 0 || h == H + 1) {
            for(int w = 0; w < W + 2; w++) ans[h].push_back('#');
        }
        else {
            ans[h].push_back('#');
            for(int w = 1; w < W + 1; w++) {
                char s; cin >> s;
                ans[h].push_back(s);
            }
            ans[h].push_back('#');
        }
    }
    for(int h = 0; h < H + 2; h++) {
        for(int w = 0; w < W + 2; w++) {
            if(w != W + 1) cout << ans[h][w];
            else cout << ans[h][w] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3612
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type edge struct {
	a, b int
}

type graph [][]bool

func deleteEdge(G *graph, e edge) {
	(*G)[e.a][e.b], (*G)[e.b][e.a] = false, false
}

func addEdge(G *graph, e edge) {
	(*G)[e.a][e.b], (*G)[e.b][e.a] = true, true
}

func DFS(G *graph, n int, d *[]bool) {
	(*d)[n] = true
	for i, isLinked := range (*G)[n] {
		if isLinked && !(*d)[i] {
			DFS(G, i, d)
		}
	}
}

func isBridge(G *graph, e edge) bool {
	deleteEdge(G, e)

	N := len((*G)[0])
	dist := make([]bool, N)

	DFS(G, 0, &dist)

	addEdge(G, e)

	for _, b := range dist {
		if !b {
			return true
		}
	}
	return false
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := scanInt(), scanInt()
	G := make(graph, N)
	for i := 0; i < N; i++ {
		G[i] = make([]bool, N)
	}

	L := make([]edge, M)
	for i := 0; i < M; i++ {
		a, b := scanInt()-1, scanInt()-1
		L[i].a, L[i].b = a, b
		G[a][b], G[b][a] = true, true
	}

	ans := 0
	for _, l := range L {
		if isBridge(&G, l) {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1804
import time
import random

def check(j,r):
    global point
    last=[0]*26
    sum_=0
    t=ans.copy()
    t[j]=r
    for i in range(D):
        d=i+1
        sum_+=s[i][t[i]]
        for k in range(26):
            if t[i]==k:
                continue
            sum_-=c[k]*(d-last[k])
        last[t[i]]=d
    if sum_>point:
        point=sum_
        return True
    else:
        return False

start=time.time()
INF=10**30
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
last=[0]*26
ans=[]
point=0
for i in range(D):
    d=i+1
    res=-INF
    z=-1
    for j in range(26):
        p=s[i][j]
        for k in range(26):
            if k==j:
                continue
            p-=c[k]*(d-last[k])
        res=max(res,p)
        if res==p:
            z=j
    ans.append(z)
    last[z]=i+1
    point+=res
while True:
    if time.time()-start>1.80:
        break
    for i in range(D):
        if time.time()-start>1.80:
            break
        r=random.randrange(26)
        if check(i,r):
            ans[i]=r
for i in range(D):
    print(ans[i]+1)

Measured memory_bytes: 80148
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int L, N;
	cin >> N >> L;
	string S[100];
	for (int i = 0; i < N; ++i) {
		cin >> S[i];
	}
	sort(S, S + N);
	for (int i = 0; i < N; ++i) {
		cout << S[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
#define INF 2e9
const int maxn=200000+10;
int n;
int a[maxn];
int L[maxn/2+2],R[maxn/2+2];
LL merge(int left,int mid,int right)
{
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++) L[i]=a[left+i];
    for(int i=0;i<n2;i++) R[i]=a[mid+i];
    L[n1]=INF,R[n2]=INF;
    int i=0,j=0;
    LL cnt=0;
    for(int k=left;k<right;k++)
    {
        if(L[i]<=R[j])
        {
            a[k]=L[i++];

        }
        else
        {
            a[k]=R[j++];
            cnt+=n1-i;
        }
    }
    return cnt;



}
LL merge_sort(int left,int right)
{
    if(right-left>1)
    {
        int mid=(left+right)/2;
        LL n1=merge_sort(left,mid);
        LL n2=merge_sort(mid,right);
        LL n3=merge(left,mid,right);
        return n1+n2+n3;
    }
    return 0;
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    printf("%lld\n",merge_sort(0,n));


    return 0;
}

Measured memory_bytes: 4748
#include<stdio.h>
int main(){int a,b,c=0;
  scanf("%d%d%d",&a,&b,&c);
  if(a <= b && a <= c) { printf("%d",a);
    if(b <= c) printf(" %d %d\n",b,c);
    else printf(" %d %d\n",c,b);}
     
  else if(b <= a && b <= c) { printf("%d",b);
    if(a <= c) printf(" %d %d\n",a,c);
    else printf(" %d %d\n",c,a);}
  else if(c <= a && c <= b) { printf("%d",c);
    if(a <= b) printf(" %d %d\n",a,b);
    else printf(" %d %d\n",b,a);}
  
 
  
  return 0;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(10);
    /*start*/
    int n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    bool flg = true;
    rep(i, n - 1)
    {
        if (h[i + 1] < h[i])
        {
            h[i + 1]++;
            if (h[i + 1] < h[i])
            {
                flg = false;
                break;
            }
        }
    }
    if (flg)
    {
        c("Yes");
    }
    else
        c("No");

    return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict
n=int(input())
A=sorted((map(int,input().split())))
maxA=max(A)
L=[0]*(maxA+1)
AD=defaultdict(int)
for a in A:
	L[a]=1
	AD[a]+=1
for a in A:
	if AD[a]>=2:
		L[a]=0
	for i in range(2*a,maxA+1,a):
		L[i]=0
print(sum(L))


Measured memory_bytes: 43516
N = int(raw_input())
A = (map(int, raw_input().split()))
A.sort(reverse=True)
j = 0
c = 1
ans = 0
for i in range(N-1):
  ans += A[j]
  c += 1
  if c == 2:
    c = 0
    j += 1
print ans


Measured memory_bytes: 95180
#include <stdio.h>
#include <math.h>

#define NUM 123456*2  // NUM??\???????´???°????±???????

int main(void)
{
  unsigned i, j;
  unsigned sq_num = (int)sqrt((double)NUM);
  unsigned prime[NUM];
  int count,n;
  // 1????????£???????????????????´???°
  // 0????????£??????????????????????????°????´???°??§????????????
  
  for (i = 1; i < NUM; i++)
    prime[i] = 1;  // ??¨????????°???1????????????
  // 1????´???°??§?????????
  for (i = 1; i < sq_num; i++) {
    if (prime[i] == 1)          // prime[i]????´???°??????
      for (j = (i+1); (i+1) * j <= NUM; j++)
	prime[(i+1) * j - 1] = 0;  // ?´???°????????°????´???°??§?????????
  }
  while(1){
    scanf("%d",&n);
    count=0;
    if(n==0){
      break;
    }

    for (i = n; i <n*2; i++){
//    	printf("%d prime[i]%d\n",i+1,prime[i]);
      if (prime[i] == 1)  // 1????????£???????????????????´???°
	count++;
    }
    printf("%d\n",count);
  }
  return (0);
}

Measured memory_bytes: 1560
#include<stdio.h>
int main(){
    int N,i,j;
    int d[100];
    int value = 0;
    
    scanf("%d",&N);
    for(i = 0 ; i < N ; i++){
        scanf("%d",&d[i]);
    }
    
    for(i = 0 ; i < N-1 ; i++){
        for(j = i+1 ; j < N ; j++){
            value += d[i] * d[j];
        }
    }
    printf("%d\n",value);
    return 0;
}


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

static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,m[MAX][MAX];

void dijkstra(){
    int min,d[MAX],color[MAX];
    
    for(int i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }
    d[0]=0;
    color[0]=GRAY;
    while(1){
        min=INFTY;
        int u=-1;
        for(int i=0;i<n;i++){
            if(min>d[i] && color[i]!=BLACK){
                u=i;
                min=d[i];
            }
        }
        if(u==-1) break;
        color[u]=BLACK;
        for(int j=0;j<n;j++){
            if(color[j]!=BLACK && m[u][j]!=INFTY){
                if(d[j]>d[u]+m[u][j]){
                    d[j]=d[u]+m[u][j];
                    color[j]=GRAY;
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        cout << i << " " << (d[i]==INFTY ? -1 : d[i]) << endl;
    }
}
int main(){
  cin >>n;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
        m[i][j]=INFTY;
    }
  }
  int k,c,u,v;
  for(int i=0;i<n;i++){
      cin >> u >> k;
      for(int j=0;j<k;j++){
          cin >> v >> c;
          m[u][v]=c;
      }
  }
  dijkstra();

  return 0;
}


Measured memory_bytes: 3124
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = a + b;
		
		if (ans >= 24) {
			ans = ans - 24;
		}
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////
#define MAX_V 30000//調節！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
//辺を表す構造体{行き先、容量、逆辺}
struct edge{ll to,cap,rev;};
vector<edge> G[MAX_V];
bool used[MAX_V];//dfsですでに調べたかのフラグ
//fromからtoへの流量capの辺をグラフに追加
void add_edge(ll from,ll to,ll cap){
    //cout<<from<<" "<<to<<" "<<cap<<endl;
    G[from].push_back((edge){to,cap,static_cast<ll>(G[to].size())});
    G[to].push_back((edge){from,0,static_cast<ll>(G[from].size()-1)});
}
//増加パスをdfsで探す
ll dfs(ll v,ll t,ll f){
    if(v==t)return f;
    used[v]=true;
    for(ll i=0;i<G[v].size();i++){
        edge &e=G[v][i];
        if(!used[e.to]&&e.cap>0){
            ll d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
ll max_flow(ll s,ll t){
    ll flow=0;
    while(1){
        memset(used,0,sizeof(used));
        ll f=dfs(s,t,inf);
        if(f==0)return flow;
        flow+=f;
    }
}
///////////////////////////////////////



int main(){
    int n;cin>>n;
    i_i a[2*n];
    rep(i,0,2*n-1){
        cin>>a[i].first>>a[i].second;
    }
    rep(i,0,n-1){
        rep(j,n,2*n-1){
            if(a[i].first<a[j].first&&a[i].second<a[j].second){
                add_edge(i,j,1);
            }
        }
    }
    int sta=2*n,end=2*n+1;
    rep(i,0,n-1){
        add_edge(sta,i,1);
    }
    rep(i,n,2*n-1){
        add_edge(i,end,1);
    }
    cout<<max_flow(sta,end)<<endl;
    
    return 0;
}




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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    string a, b;
    cin >> a >> b;
    string sa="", sb="";
    for (int i=0; i<b[0]-'0'; ++i) sa += a;
    for (int i=0; i<a[0]-'0'; ++i) sb += b;
    cout << min(sa, sb) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int count =0;
    int n;
    cin>>n;
    int a[n];
    
    for(int i=0;i<n;i++)
    {cin>>a[i];
    if(a[i]!=i+1)
    count++;
    }
    if(count<=2)
    cout<<"YES";
    else
    cout<<"NO";
    
    
    
    
    return 0;
    
}

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

using namespace std;

int w, h;
vector<string> c;
string dp[100][100];

string cmax(string& a, string& b){
	if(a.size() < b.size()) return b;
	else if(a.size() == b.size()) return max(a, b);
	else return a;
}

int main(){
	while(1){
		cin >> w >> h;
		if(!w && !h) break;
		c.resize(h);
		fill(dp[0], dp[100], "");
		for(int i=0; i<h; i++){
			cin >> c[i];
		}

		string ans = "";
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				if(isdigit(c[i][j])) dp[i][j] += c[i][j];
				else dp[i][j] = "";
				if(dp[i][j] == "0") dp[i][j] = "";
				ans = cmax(ans, dp[i][j]);
				dp[i+1][j] = cmax(dp[i+1][j], dp[i][j]);
				dp[i][j+1] = cmax(dp[i][j+1], dp[i][j]);
				//dp[i+1][j+1] = cmax(dp[i+1][j+1], dp[i][j]);
			}
		}
		cout << ans << endl;
	}
}


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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.length()-1]!=b[0]){
        cout<<"NO"<<endl;
        return 0;
    }
    if(b[b.length()-1]!=c[0]){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll T1,T2,A1,A2,B1,B2;
  cin>>T1>>T2>>A1>>A2>>B1>>B2;
  if(T1*A1+T2*A2==T1*B1+T2*B2){cout<<"infinity"<<endl; return 0;}
  if(T1*A1+T2*A2>T1*B1+T2*B2){
    swap(A1,B1);
    swap(A2,B2);
  }
  if(B1>A1){cout<<0<<endl; return 0;}
  B1-=A1; B2-=A2;
  A2=0; A1=0;
  B1=abs(B1);
  B1*=T1;
  B2*=T2;
  B2-=B1;
  cout<<(B1+B2)/B2+(B1+B2-1)/B2-1<<endl;
  
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

char t,l;
string c[5][14];

int p(string a){
	int x=0;
	if(a[1]==t)x+=50;
	if(a[1]==l)x+=20;
	if(isdigit(a[0]))return x+a[0]-'0';
	if(a[0]=='T')return x+10;
	if(a[0]=='J')return x+11;
	if(a[0]=='Q')return x+12;
	if(a[0]=='K')return x+13;
	return x+14;
}

int main(){
	while(cin>>t&&t!='#'){
		rep(i,4)rep(j,13)cin>>c[i][j];
		int w=0,ns=0,ew=0;
		rep(i,13){
			l=c[w][i][1];
			int M=0,m;
			rep(j,4)if(p(c[j][i])>M)M=p(c[j][i]),m=j;
			m%2?ew++:ns++;
			w=m;
		}
		if(ns>ew)cout<<"NS "<<ns-6<<endl;
		else cout<<"EW "<<ew-6<<endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = 1 << 29;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const int MAX_V = 500;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
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; }







void solve() {
    ll n;
    cin>>n;
    ll ans=0;
    rep(i,n+1){
        if(i%3==0||i%5==0) continue;
        ans += i;
    }
    cout<<ans<<endl;

    
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);


    ll t=1;
    
    // cin>>t;

    rep(i,t){
        solve(); 
    }

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    ve<int> p(n),q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    int ans = 0;
    if(p>q)swap(p,q);
    do{
        if(p==q)break;
        ans++;
    }while(next_permutation(p.begin(), p.end()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
ABCDpre = input()
ABCD = [i for i in ABCDpre]
op = ["-","-","-"]
for i in range(1 << 3):
    for j in range(3):
        if ((i >> j) & 1) == 1:
            op[j] = "+"
    if eval(ABCD[0]+op[0]+ABCD[1]+op[1]+ABCD[2]+op[2]+ABCD[3]) == 7.0:
        print(ABCD[0]+op[0]+ABCD[1]+op[1]+ABCD[2]+op[2]+ABCD[3]+"=7")
        exit()
    op = ["-","-","-"]

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> row;
typedef vector<row> matrix;
typedef pair<double, double> point;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
	//file();
	fast();
	ll n, a, b; cin >> n >> a >> b;
	ll ans = n / (a + b) * a;
	ans += min(n % (a + b), a);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/* #region template */
#![allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, Bytes, Read, Stdin, StdinLock, Stdout, StdoutLock, Write};
use std::iter::{repeat, repeat_with};
use std::mem::swap;
use std::str::FromStr;
#[allow(dead_code)]
struct Io<'a> {
    reader: Bytes<StdinLock<'a>>,
    writer: StdoutLock<'a>,
    in_buf: [u8; BUF_SIZE],
}
#[allow(dead_code)]
impl<'a> Io<'a> {
    fn new(stdin: &'a Stdin, stdout: &'a Stdout) -> Io<'a> {
        Io {
            reader: stdin.lock().bytes(),
            writer: stdout.lock(),
            in_buf: [0; BUF_SIZE],
        }
    }
    fn r<T: FromStr>(&mut self) -> T {
        let mut count = 0;
        loop {
            match self.reader.next() {
                Some(Ok(b' ')) | Some(Ok(b'\n')) => break,
                Some(Ok(c)) => self.in_buf[count] = c,
                _ => panic!(),
            }
            count += 1;
        }

        let s = unsafe { std::str::from_utf8_unchecked(&self.in_buf[0..count]) };
        s.parse().unwrap_or_else(|_| panic!())
    }
    fn ru(&mut self) -> usize {
        self.r()
    }
    fn iter<'b, T>(&'b mut self) -> IoIter<'a, 'b, T> {
        IoIter::new(self)
    }
    fn c<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        self.iter().take(n).collect()
    }
    fn cu(&mut self, n: usize) -> Vec<usize> {
        self.c(n)
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.writer, "{}", v).unwrap();
    }
    fn wn<T: std::fmt::Display>(&mut self, v: T) {
        write!(self.writer, "{}", v).unwrap();
    }
}
#[allow(dead_code)]
struct IoIter<'a: 'b, 'b, T> {
    io: &'b mut Io<'a>,
    m: std::marker::PhantomData<T>,
}
#[allow(dead_code)]
impl<'a: 'b, 'b, T> IoIter<'a, 'b, T> {
    fn new(io: &'b mut Io<'a>) -> IoIter<'a, 'b, T> {
        IoIter {
            io,
            m: std::marker::PhantomData,
        }
    }
}
impl<'a, 'b, T: FromStr> Iterator for IoIter<'a, 'b, T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let mut io = Io::new(&stdin, &stdout);
    unsafe {
        solve(&mut io);
    }
}
/* #endregion */

const BUF_SIZE: usize = 1024;

unsafe fn solve(io: &mut Io) {
    let n: String = io.r();
    if n.chars().find(|s| *s == '7').is_some() {
        io.w("Yes");
    } else {
        io.w("No");
    }
}


Measured memory_bytes: 2076
IDENTIFICATION DIVISION.
        PROGRAM-ID. AtCoder.
      
        ENVIRONMENT DIVISION.
      
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 INP PIC X(100).
      	01 INP1 PIC X(100).
        01 A PIC 9(15).
        01 B PIC 9(15).
        01 C PIC 9(15).
      	01 D PIC 9(15).
      	01 E PIC 9(15).
        01 F PIC 9(15).
      	01 ans PIC ZZZZZZZZZZZ9.
	    01 temp1 PIC 9(15).
        01 temp2 PIC 9(15).
        01 N PIC 9(15).
      
        PROCEDURE DIVISION.
      	MAIN.
			ACCEPT INP.
      		ACCEPT INP1.
      		MOVE 0 to A.
      		IF INP(1:1) = INP1(1:1) THEN
      			COMPUTE A = A + 1
      		END-IF.
      		IF INP(2:1) = INP1(2:1) THEN
      			COMPUTE A = A + 1
      		END-IF.
      		IF INP(3:1) = INP1(3:1) THEN
      			COMPUTE A = A + 1
      		END-IF.
      		MOVE A TO ans.
      		DISPLAY ans.
		STOP RUN.

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			// nがあり、nの数だけの整数の入力
			long n = sc.nextLong();
			List<Long> an = new ArrayList<>();
			for (long i = 0; i < n - 1; i++) {
				an.add(sc.nextLong());
			}
			LinkedHashMap<Long, Long> map = new LinkedHashMap<>();
			for (long i = 1; i <= n; i++) {
				map.put(i, 0L);
			}
			for (int i = 0; i < n - 1; i++) {
				map.put(an.get(i), map.get(an.get(i)) + 1);
			}
			for (Long val : map.values()) {
				System.out.println(val);
			}
		}
	}

	/**
	 * 最小公倍数
	 */
	static long lcm(long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return c / b;
	}

	/**
	 * 最大公約数
	 */
	static long gcd(long a, long b) {
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return b;
	}
}

Measured memory_bytes: 83512
from collections import deque
H,W=map(int,input().split())

q=deque()
dist=[[-1]*(W+1) for a in range(H+1)]
G=[['#']*(W+1) for _ in range(H+1)]
for i in range(1,H+1):
    G_comp=list(str(input()))
    for j in range(1,W+1):
        if G_comp[j-1]=='#':
            q.append((i,j))
            dist[i][j]=0
        G[i][j]=G_comp[j-1]

def sur(v):  #v is tuple
    vx=v[0]
    vy=v[1]
    preE=[(vx-1,vy),(vx+1,vy),(vx,vy-1),(vx,vy+1)]
    E=[]
    for nv in preE:
        if 1<=nv[0]<=H and 1<=nv[1]<=W:
            if G[nv[0]][nv[1]]=='.':
                E.append(nv)
    return E

while q:
    now=q.popleft()
    for next in sur(now):
        if dist[next[0]][next[1]]!=-1:
            continue
        q.append(next)
        dist[next[0]][next[1]]=dist[now[0]][now[1]]+1

M=[]
for k in range(1,H+1):
    M.append(max(dist[k]))

print(max(M))






Measured memory_bytes: 123100
/*<----------------------------------------------------------------------->

<-------------------------------------------------------------------------->
            _           __                _      _____ _____ _____ 
  ___ _   _| |__   ___ / _|_ __ ___  __ _| | __ |___  |___  |___  |
 / __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ /    / /   / /   / / 
| (__| |_| | |_) |  __/  _| | |  __/ (_| |   <    / /   / /   / /  
 \___|\__,_|_.__/ \___|_| |_|  \___|\__,_|_|\_\  /_/   /_/   /_/   

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vi;
typedef vector<pll> vpll;
typedef unordered_map <ll,ll> umap ; 
//#pragma GCC optimize "trapv"
#define loop(i,a,b) for(ll i=a ;i<b;i++)
#define For(i,n) for(int i=0;i<(ll)n;i++)
#define Rev(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(),(v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a,b) make_pair(a,b)
#define pf(n) cout<<n<<"\n"
#define pff(n) cout << n << " " ; 
long const M=1e9+7;
const long mxN =1e5+2 ;
const long mxNN =1e6+2 ;
set<ll>store ;
void pre_comp(ll x){
    store.insert(x) ;
    if(x>323456666+3)return ;
    if(x%10>0)pre_comp(x%10-1+x*10) ;
    if(x%10<9)pre_comp(x%10+1+x*10) ;
    pre_comp(10*x+x%10) ;
}
void solve(){
    for(int i=1;i<10;i++)pre_comp(i) ;
    ll k; cin >> k ;k--;
    while(k--)store.erase(store.begin()) ;
    cout << *store.begin() << endl ;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout << setprecision(20) << fixed ;
    solve() ;
    //ll t ; cin >> t ; while(t--)solve();
	return 0;
}


Measured memory_bytes: 4992
/*
    author: Salam_35
    Created at :

*/

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

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));


const ll MOD = 1e9+7;

typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;
vec primes;


int main()
{
    string a,b;
  int aa,bb;
  string s;
  cin >> a>> b>>aa>>bb>>s;
  if(s==a)cout<<aa-1<<' '<<bb<<endl;
  else cout<<aa<<' '<<bb-1<<endl;
  return 0;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  string t;
  cin>>s>>t;
  int count=0;
  int w=s.size();
  
  for(int i=0;i<w;i++){
    if(s[i]==t[i]){
    }
    if(s[i]!=t[i]){
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3816
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,ans;
map<ll,ll> mp;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        mp[a]++;
    }
    for(auto x:mp){
        if(x.second>=x.first)ans+=x.second-x.first;
        else ans+=x.second;
    }
    cout<<ans<<endl;
}


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

int main() {
    int a;
    map <int, int> b;
    rep (i, 28) cin >> a, b[a]++;

    rep (i, 30) if (b.count(i + 1) == 0) cout << i + 1 << endl;
    return 0;
}


Measured memory_bytes: 3104
<?php 
	$ans = "";
  	$s = explode(' ', trim(fgets(STDIN)));
	$start = $s[1]-$s[0]+1;
	$end = $s[1]+$s[0]-1;
	for($i = $start ; $i<=$end ; $i++){
    	echo $i;
        echo " ";
    }
	echo $ans;

?>

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

int main(int argc, const char * argv[]) {
    // insert code here...
    int R;
    cin >> R;
    
    if (R < 1200) cout << "ABC" << endl;
    else if (R < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N, M = map(int, input().split())
    keys = []

    for _ in range(M):
        a, _ = map(int ,input().split())
        C = list(map(int, input().split()))
        cMask = 0
        for c in C:
            cMask |= (1 << (c - 1))
        keys.append((a, cMask))

    dp = [[INF] * (1 << N) for _ in range(M + 1)]  # dp[i][mask] = i番目の鍵までで，状態mask
    dp[0][0] = 0

    for i, (cost, cMask) in enumerate(keys, start=1):
        for mask in range(1 << N):
            dp[i][mask] = min(dp[i][mask], dp[i - 1][mask])
            dp[i][mask | cMask] = min(dp[i][mask | cMask], dp[i - 1][mask] + cost)

    ans = dp[M][(1 << N) - 1]
    if ans == INF:
        print(-1)
    else:
        print(ans)

sol()

Measured memory_bytes: 140892
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
ll inf=100000000000000000,mod=1000000007;
int main(){
    
	ios::sync_with_stdio(false);
	cin.tie(0);
    ll n,m;
    cin>>n>>m;
    if(n==m)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
// LNU_Algotesters
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 2000 + 47;
const double EPS = 1e-9;




int main()
{
    
   // freopen("in.txt", "r", stdin);
    //ios::sync_with_stdio(false); cin.tie(0);
    
    int n, d, x;
    cin >> n >> d >> x;
    double D = (2 * d + (2 * n - 1) * 1LL * x) * .5;
    double ans = .0;
    RFOR(i, n+1, 1)
    {
        ans += D;
        D += D / i;
    }
    cout << fixed << setprecision(11) << ans << endl;
    return 0;
}





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

using namespace std;

bool aki[50][31];
bool get[50];
int n;

bool solve(int p){
  for(;;p--){
    bool f = true;
    for(int i=0;i<n;i++){
      if(!get[i]){
        f = false;
        break;
      }
    }
    if(f) return true;
    if(p == 0) break;
    f = false;
    for(int i=0;i<n;i++){
      if(get[i] && aki[i][p]) f = true;
    }
    if(f){
      for(int i=0;i<n;i++){
        if(aki[i][p]) get[i] = true;
      }
    }
  }
  return false;
}

main(){
  while(cin >> n && n){
    fill(aki[0], aki[50], false);
    for(int i=0;i<n;i++){
      int f;
      cin >> f;
      for(int j=0;j<f;j++){
        int in;
        cin >> in;
        aki[i][in] = true;
      }
    }
    int ans = -1;
    for(int j=30;j>0;j--){
      for(int i=0;i<n;i++){
        fill(get, get+n, false);
        get[i] = true;
        if(solve(j)) ans = j;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] S = new int[n];
		for (int i = 0; i < S.length; i++) {
			S[i] = scan.nextInt();
		}
		int q = scan.nextInt();
		int[] T = new int[q];
		for (int i = 0; i < T.length; i++) {
			T[i] = scan.nextInt();
		}
		
		System.out.println(linearSearch(S, T));
		scan.close();
	}

	public static int linearSearch(int[] S, int[] T) {
		int ans = 0;
		for(int t: T){
			for(int s: S){
				if (t== s) {
					ans++;
					break;
				}
			}
		}
		
		return ans;
	}
}

Measured memory_bytes: 40672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

const int MAX = 2000010;
ll fac[MAX], finv[MAX], inv[MAX];
bool Pre = true;
void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    FOR(i, 2, MAX) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
ll com(int n, int k) {
    if (Pre) {
        cominit();
        Pre = false;
    }
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll hom(int n, int k) { return com(n + k - 1, k); }

int main() {
    init();

    int n, k; cin >> n >> k;
    chmin(k, n - 1);
    ll ans = 0;
    eFOR(i, 0, k)(ans += com(n, i) * hom(n - i, i) % mod) %= mod;
    cout << ans << "\n";
}

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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 510, M = 1010;

int a, b, n = 100;
char g[N][N];

int main()
{
	cin >> a >> b;
	a -- , b -- ;
	
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= n; j ++ )
			g[i][j] = i <= 50 ? '#' : '.';
	
	for (int i = 1; a && i <= n / 2 - 1; i += 2)
		for (int j = 1; a && j <= n; j += 2, a -- )
			g[i][j] = '.';
	
	for (int i = n / 2 + 2; b && i <= n; i += 2)
		for (int j = 1; b && j <= n; j += 2, b -- )
			g[i][j] = '#';
	
	puts("100 100");
	for (int i = 1; i <= n; i ++ ) puts(g[i] + 1);
    return 0;
}

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

#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
#define CLR(arr,val) memset(arr,val,sizeof(arr))

typedef long long LL;

int main(){
    FAST_IO;
    int tx=0,ty=0,pret=0;
    int n,T,x,y,t;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>T>>x>>y;
        t=T-pret;
        pret=T;
        int rx=abs(x-tx);
        int ry=abs(y-ty);
        if(rx+ry>t) {cout<<"No"<<endl;return 0;}
        else if(rx+ry==t) {tx=x;ty=y;}
        else{
            int tmp=t-rx-ry;
            if(tmp%2==1) {cout<<"No"<<endl;return 0;}
            else {tx=x;ty=y;}
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

using namespace std;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
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);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}


class UnionFind {
public:
	vector<ll> parent;

	UnionFind(int n) {
		parent = vector<ll>(n, -1);
	}

	int root(int a) {
		if (parent[a] < 0) return a;
		return parent[a] = root(parent[a]);
	}

	int size(int a) {
		return -parent[root(a)];
	}

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

	bool unite(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) {
			return false;
		}

		if (size(a) < size(b)) swap(a, b);

		parent[a] += parent[b];
		parent[b] = a;

		return true;
	}

};

int main(){

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


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

    ll inconv = 1;
    for(int i = n-1; i >= 2; --i){
        inconv += i;
    }

    vector<ll> ans;
    ans.push_back(inconv);

    UnionFind uf(n);

    vector<int> a(m), b(m);
    for(int i = m-1; i >= 0; --i){
        int A, B;
        cin >> A >> B;
        a[i] = A-1; b[i] = B-1;
    }

    for(int i = 0; i < m-1; ++i){
        if(!uf.same(a[i], b[i])){
            inconv -= uf.size(a[i])*uf.size(b[i]);
            uf.unite(a[i], b[i]);
        }
        ans.push_back(inconv);
    }

    reverse(ans.begin(), ans.end());

    for(int i = 0; i < m; ++i){
        ppp(ans[i]);
    }



    return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    string S;
    cin >> S;

    ll mx = 0, cnt = 0;
    REP(i,0,SZ(S)) {
        if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') ++cnt;
        else {
            mx = MAX(mx,cnt);
            cnt = 0;
        }
    }
    mx = MAX(mx,cnt);
    PR(mx);

    return 0;
}

/*



*/

Measured memory_bytes: 3596
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println(gcd(sc.nextInt(), sc.nextInt()));
    }
    private static int gcd(int x, int y) {
        if (y == 0)
            return x;
        return gcd(y, x%y);
    }
}



Measured memory_bytes: 26336