akhauriyash/Code-Regression huggingface dataset:
n,k= list(map(int, input().split()))
INF=998244353
s=[]
for i in range(k):
    j,jj=map(int,input().split())
    s.append([l for l in range(j,jj+1)])
pattern=[0 for i in range(n)]
pattern[0]=1
ls=len(s)
memo=[0 for i in range(k)]
s.sort()
for i in range(1,n):
    tmp=0
    for index,j in enumerate(s):
        if i-j[0]<0:
            break
        elif i-j[-1]>0:
            memo[index]+=pattern[i-j[0]]
            memo[index]-=pattern[i-j[-1]-1]
            if memo[index]<0:
                memo[index]+=INF
        else:
            memo[index]+=pattern[i-j[0]]

        #tmp+=sum(pattern[max(i-j[-1],0):i-j[0]+1])
        memo[index]%=INF
    pattern[i]=(sum(memo)%INF)
print(pattern[-1])

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

int main(){
  int n,p;
  int prime[101000];

  for(int i=0;i<101000;i+=2)prime[i] = 0;
  for(int i=1;i<101000;i+=2)prime[i] = 1;
  prime[1] = 0;
  prime[2] = 1;

  int c = 3;
  while(c*c<101000){
    for(int i=3*c;i<101000;i+=2*c)prime[i] = 0;
    while(!prime[++c]);
  }

  while(1){
    cin >> n >> p;
    if(n<0 && p<0)break;

    vector<int> e;
    for(int i=0;i<p;i++){
      while(!prime[++n]);
      e.push_back(n);
    }

    vector<int> c;
    for(int i=0;i<(int)e.size();i++){
      for(int j=i;j<(int)e.size();j++){
	c.push_back(e[i] + e[j]);
      }
    }

    sort(c.begin(),c.end());
    cout << c[p-1] << endl;
  }
}

Measured memory_bytes: 1360
num = int(input())
lis = list(map(int, input().split()))
print(' '.join([str(h) for h in lis]))
for i in range(1, num):
    v = lis[i]
    j = i - 1
    while lis[j] > v and j >= 0:
        lis[j + 1] = lis[j]
        j -= 1
    lis[j+1] = v
    print(' '.join([str(h) for h in lis]))


Measured memory_bytes: 5608
#include <stdio.h>

int main(void){
    int N,X,T;
    scanf("%d",&N);
    scanf("%d",&X);
    scanf("%d",&T);
    int answer=0;
    //あまりがある
    if(N%X != 0){
        answer  = ((N/X)+1) * T;
    }else{
        answer = (N/X) * T;
    }
    printf("%d",answer);
    return 0;
}

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


int main()
{
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;

    char tmp = s[0];
    int change = 0;
    for (int i = 1; i < s.size(); i++)
    {
        if (s[i] != s[i - 1]){
            change++;
        }
    }
    change -= k*2;
    if(change < 0) change = 0;
    cout << (n - change - 1) << endl;
}



Measured memory_bytes: 512
import numpy as np

MOD = 10**9+7

N = int(input())
DP = [{} for i in range(N+1)]

out = []
AGCT = []
for i in "AGCT":
    for j in "AGCT":
        for k in "AGCT":
            for l in "AGCT":
                str = [i,j,k,l]
                AGCT.append(''.join(str))
                if ''.join(str).count("AGC") >= 1:
                    out.append(''.join(str))
                    continue
                for x  in range(3):
                    hoge = str.copy()
                    hoge[x], hoge[x+1] = hoge[x+1], hoge[x]
                    if ''.join(hoge).count("AGC") >= 1:
                        out.append(''.join(str))
                        break
DP[0]["TTTT"] = 1
for i in range(N):
    for key in AGCT:
        DP[i+1][key] = 0
    for key in DP[i]:
        for c in "AGCT":
            DP[i+1][(key+c)[-4:]] += DP[i][key]
            DP[i+1][(key+c)[-4:]] %= MOD
    for key in out:
        DP[i+1][key] = 0
ans = 0
for i in DP[-1]:
    ans += DP[-1][i]
    ans %= MOD
print(ans)


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

int main()
{
    double a, b;
    cin >> a >> b;
    double ans = a * b;
    string s = to_string(ans), t = "";
    int i = 0;
    while(s[i] != '.'){
        t += s[i++];
    }
    cout << t;
    return 0;
}


Measured memory_bytes: 3256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a%2==0 || b%2==0 || c%2==0){
    printf("0\n");
  } else {
    int x=MIN(a,MIN(b,c));
    int y=MIN(a,b)+MIN(b,c)+MIN(c,a)-2*x;
    printf("%lld\n",(int64)x*y);
  }
}

int main(void){
  run();
  return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
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); }

ll n;
ll ans = 0;

void dfs(ll x, ll a, ll b, ll c){
    if(x > n) return;
    if(a && b && c) ans++;
    dfs(x * 10 + 3, 1, b, c);
    dfs(x * 10 + 5, a, 1, c);
    dfs(x * 10 + 7, a, b, 1);
}

int main(){
    cin >> n;
    dfs(0, 0, 0, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
void main()
{
    long a, b, c, d;
    rdVals(a, b, c, d);

    foreach (i; 0 .. 1000)
    {
        if (i & 1)
        {
            a -= d;
            if (a <= 0)
            {
                "No".writeln;
                return;
            }
        }
        else
        {
            c -= b;
            if (c <= 0)
            {
                "Yes".writeln;
                return;
            }
        }
    }
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

using namespace std;

int main()
{
    long long int a,b,x,c;
    scanf("%lld%lld%lld",&a,&b,&x);
    c=a%x;
    if(c!=0) a-=c;
    else a-=x;
    printf("%lld",(b-a)/x);
    return 0;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,X,Y=MI()
    X-=1
    Y-=1
    
    ans=[0]*N
    
    for i in range(N):
        for j in range(i+1,N):
            if j<=X:
                d=j-i
            elif i>=Y:
                d=j-i
            elif i<=X and j>=Y:
                d=X-i + j-Y +1
            elif i<=X and j<=Y:
                d=min(j-i,X-i +1 +Y-j)
            elif i>=X and j>=Y:
                d=min(j-i, i-X +1 +j-Y)
            else:#どっちも内側
                d=min(j-i, i-X +1 +Y-j)
                
            ans[d-1]+=1
            
    for i in range(N-1):
        print(ans[i])
                

                
   

main()


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

int main()
{
    long long int n,tmp;
    vector<long long int> x;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> tmp;
        x.push_back(tmp);
    }
    long long int minv,maxv;
    minv = x[0];
    maxv = x[1] - minv;
    if(n > 2){
        for(int i = 1; i < n; i++){
            minv = min(x[i], minv);
            maxv = max(x[i+1]-minv, maxv);
        }
    }   
    cout << maxv << endl;
}





Measured memory_bytes: 4952
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

a = n // k
b = n % k

ans = 0

for i in range(k):
    dp = [[0, 0, 0] for i in range(a+2)]
    tj = 0
    for j in range(a+1):
        l = i + k * j
        if l >= n:
            break
        tj = j
        c = t[l]
        if c == 'r':
            dp[j+1][0] = max(dp[j][1], dp[j][2])
            dp[j+1][1] = max(dp[j][0], dp[j][2])
            dp[j+1][2] = max(dp[j][0]+p, dp[j][1]+p)
        if c == 'p':
            dp[j+1][0] = max(dp[j][1], dp[j][2])
            dp[j+1][1] = max(dp[j][0]+s, dp[j][2]+s)
            dp[j+1][2] = max(dp[j][0], dp[j][1])
        if c == 's':
            dp[j+1][0] = max(dp[j][1]+r, dp[j][2]+r)
            dp[j+1][1] = max(dp[j][0], dp[j][2])
            dp[j+1][2] = max(dp[j][0], dp[j][1])
    ans += max(dp[tj+1])
print(ans)


Measured memory_bytes: 69104
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    m = 1000
    up = []
    for i in range(N - 1):
        if A[i] < A[i+1]:
            up.append((A[i], A[i+1]))

    for i in range(len(up)):
        l, h = up[i]
        m = m // l * h + m % l

    print(m)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10028
//01
#include<iostream>
#include<set>
#include<string>
#include<cctype>

using namespace std;

int main(){
  for(string r;getline(cin,r);){
    string s;
    for(int i=0;i<r.size();i++){
      if(isalpha(r[i])){
	s+=toupper(r[i]);
	s+=' ';
      }
    }
    set<string> st;
    for(int i=0;i<s.size();i++){
      int w;
      for(w=0;0<=i-w&&i+w<s.size()&&s[i-w]==s[i+w];w++);
      w--;
      string ps=s.substr(i-w,w*2+1);
      string p;
      for(int i=0;i<ps.size();i++){
	if(ps[i]!=' '){
	  p+=ps[i];
	}
      }
      if(p.size()>2){
	st.insert(p);
      }
    }
    typedef set<string>::iterator SI;
    bool ns=false;
    for(SI i=st.begin();i!=st.end();i++){
      bool f=false;
      for(SI j=st.begin();j!=st.end();j++){
	if(i!=j
	   &&i->size()%2==j->size()%2
	   &&i->size()<j->size()
	   &&*i==j->substr((j->size()-i->size())/2,i->size())){
	  f=true;
	}
      }
      if(!f){
	if(ns){
	  cout<<' ';
	}
	ns=true;
	cout<<*i;
      }
    }
    cout<<endl;
  }
  return 0;
}
    

Measured memory_bytes: 1196
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	fmt.Println((nextInt() + nextInt()) % 24)
}


Measured memory_bytes: 640
x,y=map(int,input().split())
mod=10**9+7
if (x+y)%3!=0:print(0);exit()
if x*2<y or y*2<x:print(0);exit()
t=(x+y)//3
f=[1]
for i in range(1,10**6+7):f.append(f[-1]*i%mod)
def comb(a,b,m):return f[a]*pow(f[b],m-2,m)*pow(f[a-b],m-2,m)%m
print(comb(t,x-t,mod))

Measured memory_bytes: 42668
#include <iostream>
#include<algorithm>
#include<vector>
#include <numeric>
#include<cmath>
using namespace std;

int main(void){
    long n;
    cin >> n;
    std::vector<std::vector<long>> pd(n,vector<long>(3,0));
    std::vector<std::vector<long>> happy(n,vector<long>(3,0));
    for(int i=0;i<n;i++){
        cin >> happy[i][0]>>happy[i][1]>>happy[i][2];
        // cout << happy[i][0]<<" "<< happy[i][1]<< " "<<happy[i][2]<<endl;
    }
    pd[0]=happy[0];
    for(int i=1;i<n;i++){
        pd[i][0] = max(pd[i-1][1],pd[i-1][2])+happy[i][0];
        pd[i][1] = max(pd[i-1][0],pd[i-1][2])+happy[i][1];
        pd[i][2] = max(pd[i-1][0],pd[i-1][1])+happy[i][2];
        // cout << pd[i][0]<<' '<<pd[i][1]<<' '<<pd[i][2]<<endl;
    }
    cout << *max_element(pd[n-1].begin(),pd[n-1].end())<<endl;
}


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

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

    vector<bool> a(26,false);
    for(int i=0;S[i]!='\0';i++) a[S[i]-'a']=true;
    for(int i=0;i<26;i++){
        if(!a[i]){
            cout<<(char)(i+'a')<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
using namespace std;
typedef unsigned long long ll;
int n, p; ll dp[3];
int main(){
	cin>>n>>p;
	dp[0]=1;
	int a;
	for(int i=1;i<=n;i++){
		cin>>a;
		if(a&1){
			dp[2]=dp[0];
			dp[0]+=dp[1]; dp[1]+=dp[2];
		}
		else{
			dp[0]<<=1, dp[1]<<=1;
		}
	}
	printf("%llu\n", dp[p]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, a[11000][11000], t = 0;
bool flag[11000], fl = 0;
bool judge() {
  for (int i = 1; i <= n; ++i)
    if (a[i][0] != n)
      return 0;
  return 1;
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < n; ++j)
      cin >> a[i][j];
    a[i][0] = 1;
  }
  while (1) {
    if (judge()) {
      printf("%d\n", t);
      return 0;
    }
    fl = 0;
    memset(flag, 0, sizeof(flag));
    ++t;
    for (int i = 1; i <= n; ++i) {
      if (flag[i] || a[i][0] == n)
        continue;
      int x = a[i][a[i][0]], y = a[x][a[x][0]];
      if (!flag[x] && !flag[i] && i == y) {
        fl = 1;
        flag[x] = 1;
        flag[i] = 1;
        ++a[i][0];
        ++a[x][0];
      }
    }
    if (!fl) {
      printf("-1\n");
      return 0;
    }
  }

}


Measured memory_bytes: 41600
#include<iostream>
#include<cstdio>
#include<cmath>
# define PI acos(-1)
using namespace std;
int main()
{
    int a,b;
    while (cin>>a>>b && (a&&b))
    {
        for(int i=0;i<a;i++){
            for(int j=0;j<b;j++)
                cout<<'#';
            cout<<'\n';
        }
        cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3072
#include <iostream>



using namespace std;
typedef long long int ll;

int main()
{
	ll h, w; cin >> h >> w;
	ll first = w/2;
	if(w%2) ++first;
	ll second = w/2;

	if(h > 1 and w > 1)
	{
		ll total = first + second;
		
		ll remain = h % 2;
		ll repeat = h / 2;
		
		ll ans = total * repeat;
		if(remain)
			ans += first;

		cout << ans;

	}
	else
		cout << 1;
	return 0;
}

Measured memory_bytes: 256
W, H ,x, y = map(int, input().split())
if W == H:
  if x == W/2 and y == H/2:
    can = 1
  else:
    can = 0
else:
  if x == W/2 or y == H/2:
    if x == W/2 and y == H/2:
      can = 1
    else:
      can = 0
  else:
    if y == (H/W)*x or y == (-H/W)*x:
      can = 0
    else:
      can = 1
 
print('{:.9f}'.format(W*H/2), can)

Measured memory_bytes: 3188
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

int main(void) {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    cout << a + b + c - max({a, b, c}) + max({a, b, c}) * (1 << k) << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using int64 = int64_t;
#define int int64

signed main(){
  string s;cin>>s;
  int ans = 0,cnt=0;
  for(int i=0;i<s.size();++i){
    if(s[i]=='B') ans += s.size()-1-i,++cnt;
  }
  ans -= cnt*(cnt-1)/2;
  cout<<ans<<endl;
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] a = new int[N-1];
        int[] b = new int[N-1];
        for (int i=0; i<N-1; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        System.out.println(solve(N, K, a, b));
    }

    private static long solve(int N, int K, int[] a, int[] b) {
        List<Integer>[] graph = new ArrayList[N];
        for (int i=0; i<N; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int i=0; i<N-1; i++) {
            graph[a[i]-1].add(b[i]-1);
            graph[b[i]-1].add(a[i]-1);
        }

        return K * dfs(K, graph, 0, -1) % MOD;
    }

    private static long dfs(int K, List<Integer>[] graph, int now, int from) {
        int canUseColorNum = K-2;
        if (from == -1) {
            canUseColorNum = K-1;
        }

        if (K < graph[now].size()) {
            // 頂点now に接続するノード数がKより多い場合は彩色不可
            return 0;
        }

        long caseNum = 1;
        // 頂点nowに接続するノードの彩色パターン
        for (Integer e : graph[now]) {
            if (e == from) continue;

            caseNum *= canUseColorNum;
            caseNum %= MOD;
            canUseColorNum--;
        }
        // 頂点nowに接続する子ノードの彩色パターン
        for (Integer e : graph[now]) {
            if (e == from) continue;

            caseNum *= dfs(K, graph, e, now);
            caseNum %= MOD;
        }

        return caseNum;
    }
}


Measured memory_bytes: 99680
#include <stdio.h>

int main(void) {
  int a[10][7] = {{1,1,1,1,1,1,0},
		  {0,1,1,0,0,0,0},
		  {1,1,0,1,1,0,1},
		  {1,1,1,1,0,0,1},
		  {0,1,1,0,0,1,1},
		  {1,0,1,1,0,1,1},
		  {1,0,1,1,1,1,1},
		  {1,1,1,0,0,1,0},
		  {1,1,1,1,1,1,1},
		  {1,1,1,1,0,1,1},};
  int n, m, current[7], bit[7], i, j;

  while (1) {
    scanf("%d", &n);
    if (n == -1) break;

    for (i = 0; i < 7; i++)
      current[i] = 0;

    for (i = 0; i < n; i++) {
      scanf("%d", &m);
      for (j = 0; j < 7; j++) {
	if (a[m][j] == current[j])
	  bit[j] = 0;
	else
	  bit[j] = 1;
      }
      for (j = 0; j < 7; j++)
	current[j] = a[m][j];
      for (j = 6; j >= 0; j--)
	printf("%d", bit[j]);
      putchar('\n');
    }
  }
  return 0;
}

Measured memory_bytes: 604
#include<iostream>
using namespace std;
int main(void){
	int N,maxs=0;
		cin >> N;
	int res=0;
	for(int i=0;i<N;i++){
		int a;
			cin >> a;
		res+=a;
		maxs=max(maxs,a);
	}
	cout << res-maxs/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long

int max(int a, int b){
	return a >= b ? a : b;
}

signed main(){
	int N, K, b, ans = 0;
	scanf("%lld%lld", &N, &K);
	if(K == 0){
		printf("%lld\n", N * N);
		return 0;
	}
	for(b = 1; b <= N; b++){
		if(b > K){
			ans += (N / b) * (b - K) + max((N % b) - K + 1, 0);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
  string s;
  int q;
  cin >> s >> q;
  int cnt = 0;
  deque<char> que;
  for(auto t : s) que.push_back(t);
  rep(i,q){
    int a;
    cin >> a;
    if(a == 1) cnt ++;
    else{
      int f;
      cin >> f;
      char t;
      cin >> t;
      if(f == 1){
        if(cnt%2 == 0) que.push_front(t);
        else que.push_back(t);
      }
      else{
        if(cnt%2 == 0) que.push_back(t);
        else que.push_front(t);
      }
    }
  }
  if(cnt%2 != 0) reverse(que.begin(),que.end());
  for(auto t : que){
    cout << t;
  }
}


Measured memory_bytes: 3928
#include <iostream>
using namespace std;
 
//#include <stdio.h>
//#include <algorithm>
//#include <string>
#include <vector>

/********
*   ?????¢??¢?´¢ Linear Search
*********/ 

/*
int linearSearch(int strS int strT, int n )
{
	int key;
	
	for(int i =0 ; i < n; i++){
		if(strS[i] == key){
			return i;
		}
	}
	return NOT_FOUND;
}
*/

int main(void)
{
	int n;
	cin >> n;	
	vector<int> strS;
	strS.resize(n);
	
	for(int i = 0; i<n; i++){
		cin >> strS[i];
	}
	
	int q;
	cin >> q;
	vector<int> strT;
	strT.resize(q);
	
	for(int i = 0; i<n; i++){
		cin >> strT[i];
	}
	
	int count = 0 ;
	for(int j = 0; j<q ; j++){
		for(int i =0; i < n; i++){
			if(strT[j] == strS[i]){
				count++;
				break;
			}
		}
	}
	cout << count << endl;
	
    return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <tuple>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(v) (v).begin(),(v).end()
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;


int gcd(int a,int b){
    if(a<b){
        int t=a;
        a=b;
        b=t;
    }
    int k=a%b;
    while(k!=0){
        a=b;
        b=k;
        k=a%b;
    }
    return b;
}

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int p=gcd(a,b);
    cout<<(a/p)*(b/p)*c<<endl;
    
    
    
    return 0;
}



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

#define MaxN 1005
#define INF 2140000000
#define eps 1e-9
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795

using namespace std;

long long N,P,Z=1,O=0,X,o,z;

int main()
{
    cin>>N>>P;
    for(int i=1;i<=N;i++)
    {
        cin>>X;
        if(X%2==1)
        {
            z=Z,o=O;
            Z+=o;
            O+=z;
        }
        else
        {
            z=Z,o=O;
            Z+=z;
            O+=O;
        }
    }
    if(P==0)
        cout<<Z;
    else cout<<O;
    return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N = d_in()
H = d_in()
W = d_in()
print((N - H + 1) * (N - W + 1))


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

int main() {
    int N, D;
    cin >> N >> D;
    int ans = (N + 2 * D) / (2 * D + 1);
    cout << ans << endl;

  return 0;
}


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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;

int N, M, L;
vector<int> K, S;
vector<int> sum;

int dp[2010][2010];

int solve(int l, int r)
{
  if(max(l, r) == N-1) {
    int mn, mx;
    tie(mn, mx) = minmax(l, r);
    return (sum[K[mx]+1] - sum[K[mn]]) / L;
  }
  
  int& ret = dp[l][r];
  if(~ret) return ret;

  int s = max(l, r) + 1;
  ret = min(solve(s, r) + (sum[K[s]+1] - sum[K[l]]) / L,
	    solve(l, s) + (sum[K[s]+1] - sum[K[r]]) / L);
  
  return ret;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> M >> L;
  K.resize(N); S.resize(M); sum.resize(M + 1, 0);
  rep(i, N) cin >> K[i], K[i]--; sort(all(K));
  rep(i, M) cin >> S[i], sum[i+1] = sum[i] + S[i];
  
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 1) + (sum[K[1]+1] - sum[K[0]]) / L << endl;
  
  return 0;
}

Measured memory_bytes: 36068
//
// Created by chuan on 2020-04-10.
//

#include <iostream>
#include <numeric>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using ll = long long;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int N; cin>>N;
    vector<int> S(N, 0);
    for (int i = 0; i < N-1; ++ i) {
        int idx = i+1, boss;
        cin>>boss;
        S[boss-1]+=1;
    }
    for (int i = 0; i < N; i++) cout<<S[i]<<endl;




    return 0;
}


Measured memory_bytes: 4056
N = gets.to_i

array = Array.new(4)
array[0] = N / 1000
array[1] = N / 100 % 10
array[2] = N / 10 % 10
array[3] = N % 10

flg = false
3.times do |i|
  flg = true if(array[i] == array[i+1])
end

if flg
  puts "Bad"
else
  puts "Good"
end



Measured memory_bytes: 1788
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>
#include <tuple>
#include <queue>
//#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
 

vector<int> m,M,br; 

int MOD = 1e9 + 7;
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); 
	int n, m;
	string s;
	cin >> s;
	int c = 0, sol = 0;
	for (int i = 0; i < s.length(); i++){
		if (s[i] == 'R'){
			c++;
		} else{
			sol = max(sol, c);
			c = 0;
		}
	}

	sol = max(sol, c);
	cout << sol<<endl;
    return 0;
}

Measured memory_bytes: 3192
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
n = int( input() )
fact = factorization( n )
cnt = 0
for f in fact:
  if f[0] == 1:
    continue
  i = 1
  while True:
    f[1] -= i
    i += 1
    if f[1] < 0:
      break
    cnt += 1
print( cnt )

Measured memory_bytes: 9488
# from sys import stdout
from bisect import bisect_left as bs
from math import log as lg

log = lambda *x: print(*x)

def cin(*fn, def_fn=str):
	i,r = 0,[]
	if fn: def_fn=fn[0]
	for c in input().split(' '):
		r+=[(fn[i] if len(fn)>i else def_fn) (c)]
		i+=1
	return r

INF = 6<<20



n,w,h = cin(int)
a = []

c = 0
for i in range(n):
	a,b = cin(int)
	if a>=w and b>=h:
		c += 1

print(c)







Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int ns[31];
  int id=0;
  vector<ll> dp(31);
  dp[0]=1;
  dp[1]=1;
  dp[2]=2;
  for (int i=3;i <= 30;i++){
      dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
  }
  while(1){
    int x;
    cin >> x;
    if (x==0) break;
    else {
      ns[id]=x;
      id++;
    }
  }
  int id2=0;
  rep(i,id){
    int tmp;
    tmp=ns[id2];
    id2++;
    //cout << dp[tmp] << endl;
    ll ans;
    ans=(dp[tmp]+10-1)/10;
    cout << (ans+365-1)/365 << endl;
  }
  return 0; 
}



Measured memory_bytes: 3096
n = gets.to_i

a,b = gets.chomp.split.map(&:to_i)

(n-1).times {
    c,d = gets.chomp.split.map(&:to_i)
    e,f = 0,0

    for r in [10000000000000000, 10000000000000, 100000000, 100000, 1000]
    while e + r * c < a or f + r * d < b
        e += c * r
        f += d * r
    end
    end

    while e < a or f < b
        e += c
        f += d
    end
    a,b = e,f
    # p [a,b]
}

p (a + b)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

int main()
{
  string s, t = "";
  while(cin >> s)
  {
    int i = 0;
    while(i < s.size())
    {
      if(s[i]=='@'){REP(j,s[i+1]-'0')t+=s[i+2];i+=3;}
      else{t+=s[i];i++;}
    }
    cout << t << endl;
    t = "";
  }
  return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <map>

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	map<long, int> numbers;

	cin >> N;
	for (int i = 0; i < N; i++) {
		int n;
		cin >> n;
		numbers[n]++;
	}

	int ans = 0;
	for (pair<long, int> p : numbers) {
		if (p.second - p.first < 0)
			ans += p.second;
		else
			ans += p.second - p.first;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6272
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  #include <map>
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)

    int main(){
      ll n,k;
      vector<ll> cnt(100010,0);
      cin >> n >> k;
      rep(i,n){
        ll x,y;
        cin >> x >> y;
        cnt[x]+=y;
      }
      ll now=cnt[1];
      if (now >= k) {
        cout << 1 << endl;
        return 0;
      }
      for (int i = 2;i <= 100000;i++){
        now+=cnt[i];
        if (now >= k){
          cout << i << endl;
          return 0;
        }
      }
      return 0;
    }


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define PI 3.141592653589


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    double ans=0,A;
    for(int i=0;i<n;i++)
    {
        cin>>A;
        ans+=1/A;
    }
    ans=1/ans;
    cout<<setprecision(16)<<ans<<endl;


    return 0;
}




Measured memory_bytes: 256
import scala.io.StdIn.{readInt,readLine}

object Main {
  def isStable(l:Array[(String, Int)],a:Array[(String, Int)]) = {
    val s = l.groupBy(_._2).filter(_._2.length > 1)
    var stable = true

    for { i <- s if stable }
      if(a.filter(_._2 == i._1).toSeq != i._2.toSeq)
        stable = false
    stable
  }

  def exchange(a:Array[(String,Int)],i:Int,j:Int) = {
    val temp = a(i)
    a(i) = a(j)
    a(j) = temp
  }

  def partition(a:Array[(String,Int)],p:Int,r:Int) = {
    val x = a(r)._2
    var i = (p-1)
    for(j<-p until r) {
      if(a(j)._2 <= x) {
        i+=1
        exchange(a,i,j)
      }
    }
    exchange(a,i+1,r)
    i+1
  }

  def quicksort(a:Array[(String,Int)],p:Int,r:Int):Unit = {
    if(p<r) {
      val q = partition(a,p,r)
      quicksort(a,p,q-1)
      quicksort(a,q+1,r)
    }
  }

  def main(args:Array[String]) = {
    val n = readInt
    val a = { for(i <- 1 to n) yield {
      val s = readLine.split(" ")
      (s(0),s(1).toInt)
    } }.toArray
    val org = a.clone
    quicksort(a,0,n-1)
    if(isStable(org,a))  println("Stable") else println("Not stable")
    println(a.map(e=>e._1+" "+e._2).mkString("\n"))
  }
}

Measured memory_bytes: 147496
// C - Good Sequence
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
using vi = vector<int>;

int main(){
	int N; cin>>N;
	vi C(N+1);//count, 1 origin
	int ans = 0;
	rp(i, 0, N){
		int a; cin>>a;
		if(a<=N) C[a]++;
		else ans++;
	}
	rp(a, 1, N+1){
		if(C[a]<a) ans += C[a];
		else ans += C[a] - a;
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 640
#include<cstdio>

char s[111],t[111];

int main()
{
	int N;
	while(~scanf("%d",&N)) {
		scanf("%s%s",s,t); 
		int ans=2*N;
		for(int i=0;i<N;++i) {
			int j=0;
			for( j=0;j+i<N;++j) {
				if(s[i+j]!=t[j]) break; 
			}
			if(j+i>=N) {
				ans-=(N-i); break;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128
// 第6回 ドワンゴからの挑戦状 予選 A - Falling Asleep
// 2020.1.12 bal4u

#include <stdio.h>
#include <string.h>

char s[55][105];
char X[105];
int T[55];

int main()
{
	int i, t, tt, N;
	
	scanf("%d", &N);
	t = 0;
	for (i = 0; i < N; ++i) {
		scanf("%s%d", s[i], &tt);
		t += tt;
		T[i] = t;
	}
	scanf("%s", X);
	for (i = 0; i < N; ++i) if (strcmp(s[i], X) == 0) break;
	printf("%d\n", T[N-1] - T[i]);
	return 0;
}


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

int main(int, char**) {
  string s;
  cin >> s;
  int len = s.size();
  bool f = s[0] == '0' ? false : true;
  int ans = 0;
  for (int i = 0; i < len; ++i) {
    bool v = s[i] == '0' ? false : true;
    bool mask = (i % 2 == 0) ? (f) : (!f);
    if (v != mask) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end
 
def gcd(a,b)
	if(a>b)
		return gcd(b,a)
	end
	if(b%a == 0)
		return a
	else
		return gcd(a,b%a)
	end
end
def lcm(a,b)
	a/gcd(a,b)*b
end
 
MAX_INT = 9999999999999999
 
N,M=gets.chomp.split(' ').map{|n| n.to_i}
S=gets.chomp.split('').map{|n| n}
T=gets.chomp.split('').map{|n| n}
g = gcd(N,M)
nd = N/g
md = M/g
for i in 0..(g-1)
	if(S[i*nd] != T[i*md])
		puts -1
		exit(0)
	end
end
puts lcm(N,M)

Measured memory_bytes: 12156
#include <iostream>
#include <numeric>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	int K,T;
	cin >> K>>T;
	vector<int> vec(T);
	int mm = 0;
	for (int i = 0; i < T; i++) {
		cin >> vec.at(i);
		mm = max(mm, vec.at(i));
	}
	if (mm < (K+1)/2) {
		cout << 0 << endl;
	}
	else if (K % 2 == 0) {
		cout << (2*mm - K -1) << endl;
	}
	else {
		cout << (2 * mm - K - 1) << endl;
	}
}

Measured memory_bytes: 256
h, w, kk = map(int, input().split())
c = [[i == "#" for i in input()] for _ in range(h)]
ans = 0
for i in range(2**h):
    for j in range(2**w):
        d =[x[:] for x in c]

        for k in range(h):
            if (i>>k)&1==1:
                for l in range(w):
                    d[k][l] = 0
        
        for k in range(w):
            if (j >> k) & 1 == 1:
                for l in range(h):
                    d[l][k] = 0
        
        if kk == sum(map(sum,d)):
            ans += 1
print(ans)

Measured memory_bytes: 9216
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  const cnt = content
    .trim()
    .split('\n')
    .map(n => +n)
    .reduce((prev, cur) => isPrime(cur) ? prev + 1 : prev, 0);
  console.log(cnt);
});


const isPrime = x => {
  if (x === 2) {
    return true;
  }

  if (x < 2 || x % 2 === 0) {
    return false;
  }
  
  const sqrtX = Math.floor(Math.sqrt(x));
  let i = 3;
  while (i <= sqrtX) {
    if (x % i === 0) {
      return false;
    }

    i += 2;
  }
  
  return true;
}


Measured memory_bytes: 18788
N,M,Q=map(int,input().split())
Query=[list(map(int,input().split())) for i in range(Q)]
import itertools
ans=0
for x in itertools.combinations_with_replacement(range(1, M+1), N):
  l=0
  for i in range(Q):
    a,b,c,d=map(int,Query[i])
    if x[b-1]-x[a-1]==c:
      l+=d
  ans=max(ans,l)
print(ans)

Measured memory_bytes: 73564
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define  st first
#define  nd second
#define int long long

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef cc_hash_table<int, int, hash<int > > ht;
#define TIMES_PER_SEC (CLOCKS_PER_SEC)



double get_absolute_time()
{
	return (double)clock()/TIMES_PER_SEC;
}
double starttime_acrush;
void starttime()
{
	starttime_acrush=get_absolute_time();
}
double gettime()
{
	return get_absolute_time()-starttime_acrush;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define MOD   1000000007
#define maxn 100002
#define inf 1e18

int32_t main(){

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

  int  n  ,d,aa;
  cin >> n >> d >> aa ;
  int ra = 2*d ;
  vector<pair<int,int> > v ;
   int a[n+1]={0};
   int r[n+1]={0};
   v.push_back({0,0});
  for(int i = 1 ; i <= n ; i++ ){
    int x , y ;
    cin >> x >> y;
    v.push_back({x,y});
  }

  sort(v.begin()+1,v.end());

  for(int i = 1 ; i <= n; i++)
    a[i]=v[i].nd;
  int c = 0 ;
  for(int i = 1 ; i<= n ; i++ ){
    auto s = upper_bound(v.begin()+1,v.end(),make_pair(v[i].st+ra+1,0ll));
    int pos = s-v.begin();
    pos-=1;
    //dbg(pos);
    r[i]+=r[i-1];
    a[i]+=r[i];
    if(a[i]<0)
        continue;
    int val = a[i];
    int cnt = (val%aa)==0?(val/aa):(val/aa) + 1 ;
    r[i]-=(aa*cnt);
    if(pos+1<=n)
        r[pos+1]+=(aa*cnt);
    c+=cnt;

  }
  cout << c;



  //cout <
}



Measured memory_bytes: 9200
N=int(input())
abc=[list(map(int,input().split())) for _ in range(N)]
dp = [[0, 0, 0] for _ in range(N+1)]
for i in range(N):
  for j in range(3):
    for k in range(3):
      if j == k:
        continue
      dp[i+1][k] = max(dp[i+1][k], dp[i][j]+abc[i][k])
print(max(dp[N]))

Measured memory_bytes: 76668
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int m = sc.nextInt();
	boolean[] cards = new boolean[n];
	int l,r;
	for (int i=0; i<m; i++) {
	    l = sc.nextInt()-1;
	    r = sc.nextInt()-1;
	    for (int j=0; j<l; j++) cards[j] = true;
	    for (int j=r+1; j<n; j++) cards[j] = true;
	}
	int count = 0;
	for (int i=0; i<n; i++)
	    if (cards[i] == false) count++;
	System.out.print(count);
    }
}


Measured memory_bytes: 60420
def solve(A,N):
    A.sort()
    if N == 1:
        return 1
    elif N == 2:
        if A[1] == A[0]:
            return 0
        elif A[1] % A[0] == 0:
            return 1
        else:
            return 2
    elif A[0] == 1:
        if A[1] >= 2:
            return 1
        else:
            return 0
    else:
        Col = set()
        if A[0] == A[1]:
            Col.add(A[0])
        for i in range(1,N-1):
            if A[i-1] == A[i] or A[i] == A[i+1]:
                Col.add(A[i])
        if A[N-1] == A[N-2]:
            Col.add(A[N-1])

        Mul = set()
        cand = set()
        for i in range(N):
            if A[i] not in Mul:
                if A[i] not in Col:
                    cand.add(A[i])
                for d in range(1,(A[N-1]//A[i])+1):
                    Mul.add(A[i] * d)

        return len(cand)

def main():
    N = int(input())
    A = list(map(int,input().split()))

    print(solve(A,N))

if __name__ == "__main__":
    main()


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;
const ll MOD = 1e+9 + 7;

ll fact[200010];
ll inv[200010];
ll factInv[200010];

void init() {
    fact[0] = 1;
    REP (i, 1, 200010) fact[i] = fact[i - 1] * i % MOD;

    inv[1] = 1;
    REP (i, 2, 200010) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;

    factInv[0] = 1;
    REP (i, 1, 200010) factInv[i] = factInv[i - 1] * inv[i] % MOD;
}

ll modComb(int n, int r) {
    if (n == r) return 1;
    return fact[n] * factInv[n - r] % MOD * factInv[r] % MOD;
}

int main() {
    init();

    int H, W, A, B;
    cin >> H >> W >> A >> B;
    ll ans = 0;
    rep (i, H - A) {
        int h1 = i + 1;
        int w1 = B;
        int h2 = H - i;
        int w2 = W - B;
        ans = (ans + modComb(h1 + w1 - 2, w1 - 1) * modComb(h2 + w2 - 2, w2 - 1)) % MOD;
    }
    cout << ans << endl;
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;

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

    V<Vi> cnt(10,Vi(10,0));
    REP2(i,1,n+1){
        string num_str = to_string(i);
        if(num_str[num_str.size()-1] == '0') continue;
        int first = num_str[0]-'0';
        int last = num_str[num_str.size()-1]-'0';
        cnt[first][last]++;
    }

    int total = 0;
    REP2(i,1,10){
        REP2(j,1,10){
            total += cnt[i][j]*cnt[j][i];
        }
    }

    cout<<total<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mx=2007;

int dp[mx][mx];
char s[mx][mx];

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int H,W; cin>>H>>W;
	for(int i=0; i<H; i++)
		cin>>s[i];

	for(int i=0; i<H; i++) {
		int n=0, m=0;
		for(int j=0; j<W; j++) {
			dp[i][j]+=(s[i][j]=='.')?++n:n=0;
			dp[i][W-j-1]+=(s[i][W-j-1]=='.')?++m:m=0;
		}
	}
	for(int i=0; i<W; i++) {
		int n=0, m=0;
		for(int j=0; j<H; j++) {
			dp[j][i]+=(s[j][i]=='.')?++n:n=0;
			dp[H-j-1][i]+=(s[H-j-1][i]=='.')?++m:m=0;
		}
	}

	int ret=0;
	for(auto &r:dp)
		for(int c:r)
			ret=max(ret,c-3);
	cout<<ret<<"\n";
	return 0;
}

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

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

  sort(a,a+n);
  if(a[n-1]==a[0]){
    cout<<0<<endl;
  }
  else{
    cout<<a[n-1]-a[0]<<endl; 
  }
}

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

int main(){
  int a, b;
  cin >>a >>b;
  for(int i=1;i<1010;i++){
    if(floor(i*0.08)==a && floor(i*0.1)==b){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int 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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    int n,k;
    cin>>n>>k;
    vi v(n);
    rep(i,n)cin>>v[i];
    Rort(v);
    int ans=0;
    rep(i,k)ans+=v[i];
    fin(ans);
}



Measured memory_bytes: 256
/**************************************************
 * Atcoder problems
 * Contest No :088
 * Problem No :B
 * File Name  :program.cs
 * Create date:2020/06/27
 *
 * Copyright 2020 Shunichi Sato,All Rights Reserved.
**************************************************/
//memo terinal command
//compile:mcs program.cs
//excute :mono program.exe
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        // 個数の入力
        int N = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        var list = new List<int>();
        for(int i = 1; i <= N;i++){
            list.Add(int.Parse(input[i-1]));
        }
        list.Sort((a, b) => b - a);

        int Alice = 0;
        int Bob = 0;
        // 計算
        for (int i = 1; i <= N; i++){
            if ( i % 2 ==  0)
            {
                Alice += list[i - 1];
            }
            else
            {
                Bob += list[i - 1];
            }
        }
        //出力
        Console.WriteLine(Bob - Alice);
    }
}


Measured memory_bytes: 17768