akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int w,n,x,y;
    scanf("%d ", &w);
    int *ar = new int[w];
    for (int i = 0; i < w; i++) {
        ar[i] = i + 1;
    }

    scanf("%d ", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d,%d ", &x, &y);
        swap(ar[x - 1], ar[y - 1]);
    }
    for (int i = 0; i < w; i++) {
        printf("%d\n", ar[i]);
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

int n;
vector<int> h, dp;

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

    cin >> n;

    h.resize(n);
    for (int i = 0; i < n; i++)
        cin >> h[i];

    dp.resize(n);
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
        dp[i] = min(
                dp[i - 1] + abs(h[i] - h[i - 1]),
                dp[i - 2] + abs(h[i] - h[i - 2]));

    cout << dp[n - 1] << endl;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int n;
  //cin >> n;
  scanf("%d",&n);
  vector<int> v(n);
  //rep(i,n)cin >> v[i];
  rep(i,n)scanf("%d",&v[i]);
  int L,Q;
  //cin >> L >> Q;
  scanf("%d %d",&L,&Q);
  vector<vector<int>> next(n,vector<int>(20,n-1));
  rep(i,n){
    auto iter = lower_bound(ALL(v),v[i]+L);
    if(iter == v.end())continue;
    if(*iter <= v[i]+L)next[i][0] = iter-v.begin();
    else next[i][0] = iter-v.begin()-1;
  }
  rep(j,19)rep(i,n)next[i][j+1] = next[next[i][j]][j];
  while(Q--){
    int a,b;//cin >> a >> b;
    scanf("%d %d",&a,&b);
    a--,b--;
    if(a > b)swap(a,b);
    int l = 0,r = 100100;
    while(r-l > 1){
      int mid = (r+l)/2;
      int pos = a;
      for(int i = 19;i >= 0;i--)if(mid >> i & 1)pos = next[pos][i];
      if(pos >= b)r = mid;
      else l = mid;
    }
    //cout << r << endl;
    printf("%d\n",r);
  }







  return 0;
}

Measured memory_bytes: 15392
#include <bits/stdc++.h>
using namespace std;
int N;
int V[21], C[21];
int ans = 0;
int main() {
	cin >> N;
	for (int n = 0; n < N; n ++) cin >> V[n];
	for (int n = 0; n < N; n ++) cin >> C[n];
	for (int n = 0; n < N; n ++) {
		if (V[n] > C[n]) {
			ans += V[n] - C[n];
		}
	}
	cout << ans << endl;
}

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

using namespace std;

typedef pair<int, int> P;

P data[200005];
int s[200005];

int main()
{
  int n;
  int mpos;
  int a, b;


  cin >> n;
  for ( int i = 0; i < n; i++) {
    cin >> data[i].first;
    data[i].second = i;

    s[i] = data[i].first;
  }

  mpos = n / 2;
  sort(s, s + n);

  a = s[mpos];
  b = s[mpos - 1];
  
  for ( int i = 0; i < n; i++) {
    if ( data[i].first < a ) {
      cout << a << endl;
    } else {
      cout << b << endl;
    }
  }
  
    return (0);
}

Measured memory_bytes: 4480
#include <iostream>
 
using namespace std;
 
int main()
{
    int  n, a, b, c, d, a1, a2;
    cin >> n >> a >> b >> c >> d;
    a1 = b * ((n / a) + 1);
    if (n%a == 0)
    {
        a1 -= b;
    }
    a2 = d * ((n / c) + 1);
    if (n%c == 0)
    {
        a2 -= d;
    }
    if (a1 < a2)
    {
        cout << a1 << endl;
    }
    else
        cout << a2 << endl;
         
    return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>

using namespace std;
int main(void){
  int N,M;
  cin >> N >> M;
  vector<int> number(N,-1);
  
  bool isCollision = false;
  for(int i=0;i<M;i++){
    int s,c;
    cin >> s >> c;
    if(N>1 && s==1 && c==0){
      isCollision = true;
      break;
    }
    if(number[s-1]>=0 && number[s-1] != c){
      isCollision = true;
      break;
    }
    number[s-1] = c;
  }
  
  int answer = -1;
  if(!isCollision){
    answer = 0;
    for(int i=0;i<N;i++){
      if(number[i]==-1){
        if(i==0 && N >1){
          number[i] = 1;
        } else {
          number[i] = 0;
        }
      }
      answer += number[i] * pow(10,N-(i+1));
    }
  }
  
  cout << answer << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

int n, d;

bool getdist(int* y, int* z) {
	int square = 0;
	for (int i = 0; i < d; i++) {
		square += (y[i] - z[i]) * (y[i] - z[i]);
	}
	int tmp = sqrt(square);
	return tmp * tmp == square;
}

int main()
{
	int ans = 0;
	int x[11][11];
	cin >> n >> d;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin>>x[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			ans += getdist(x[i], x[j]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();

        if (a >= 13) {
            System.out.println(b);
        } else if (a >= 6) {
            System.out.println(b / 2);
        } else {
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
typedef pair<int, int> P;
typedef int64_t ll;
const int MAX_N = 10000;
const int INF = 1000000000;

int N;

int main() {
	vector<int> fac = { 2,4,8,16,32,64 };
	cin >> N;
	for ( int i = fac.size()-1; i >=0; i--)
	{
		if (fac.at(i) <= N) {
			cout << fac.at(i) << endl;
			return 0;
		}
	}
	cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 3596
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()] for _ in range(n)]
cd = [[int(i) for i in input().split()] for _ in range(m)]

for stu in ab:
    mind = float("inf")
    for i,cp in enumerate(cd,1):
        d = sum(map(abs,(stu[0]-cp[0],stu[1]-cp[1])))
        if mind > d:
            ans = i
            mind = d
    else:
        print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 998244353
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

int main()
{
	boost;
	ll n, k, i;
	cin >> n >> k;
	
	vector <pii> v(k);
	fo(i, 0, k)
	cin >> v[i].f >> v[i].s;
	
	ll dp[n + 1], val[n + 1];
	memset(dp, 0, sizeof dp);
	memset(val, 0, sizeof val);
	val[1] = 1;
	
	for(i = 2; i <= n; i++) {
		for(int j = 0; j < k; j++)
		dp[i] = (dp[i] + (i - v[j].f > 0 ? val[i - v[j].f] : 0) - (i - v[j].s - 1 > 0 ? val[i - v[j].s - 1] : 0) + MOD) % MOD;
		val[i] = (val[i - 1] + dp[i]) % MOD; 
	}
	cout << dp[n];
}


Measured memory_bytes: 6724
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	string O, E;
	cin >> O >> E;
	int o = O.size();
	int e = E.size();
	for (int i = 0; i < e; i++) {
		cout << O[i] << E[i];
	}
	if (o - e == 1) {
		cout << O[o - 1];
	}
	cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int numOfInput = stdIn.nextInt();
        
        long sum = 0L;
        int max = -1000000;
        int min = 1000000;
        for(int i = 0; i < numOfInput; i++) {
            int n = stdIn.nextInt();
            sum += n;
            if(n > max) {
                max = n;
            }
            if(n < min) {
                min = n;
            }
        }
        System.out.println(min + " " + max + " " + sum);
    }
}

Measured memory_bytes: 41928
#include <stdio.h>
#include <stdlib.h>

#define parent(i) ((i) / 2)
#define left(i) (2 * (i))
#define right(i) (2 * (i) + 1)

int
main (void)
{
	int i, n, p;
	int *a;

	scanf("%d", &n);
	n += 1; /* 1 origin */

	a = (int *)malloc(sizeof(int) * n);
	if (a == NULL)
		return 1;

	for (i = 1; i < n; i++)
		scanf("%d", a + i);

	for (i = 1; i < n; i++) {
		printf("node %d: key = %d, ", i, a[i]);
		if (i > 1)
			printf("parent key = %d, ", a[parent(i)]);
		if (left(i) < n)
			printf("left key = %d, ", a[left(i)]);
		if (right(i) < n)
			printf("right key = %d, ", a[right(i)]);
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 2036
line = readline
k = line.chomp.split(" ")[0].to_i
x = line.chomp.split(" ")[1].to_i

min = x - k + 1
max = x + k - 1

putarr = [*min..max]
putarrsub = []
putarr.each do |a|
  if a >= -1000000 && a <= 1000000
    putarrsub << a
  end
end

putarrsub.each_with_index do |b,i|
  if i == putarrsub.length - 1
    print "#{b}"
  else
    print "#{b} "
  end
end

Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            //var line = consoleReader.SplitInt32();
            var S = consoleReader.String();
            var T = consoleReader.String();
            var dic1 = new Dictionary<char, char>();
            var dic2 = new Dictionary<char, char>();
            foreach (var c in Enumerable.Zip(S, T, (s, t) => new { s, t }))
            {
                if (dic1.ContainsKey(c.t))
                {
                    if (dic1[c.t] != c.s)
                        return "No";
                }
                else
                {
                    dic1[c.t] = c.s;
                }
                if (dic2.ContainsKey(c.s))
                {
                    if (dic2[c.s] != c.t)
                        return "No";
                }
                else
                {
                    dic2[c.s] = c.t;
                }
            }
            return "Yes";
        }

        public const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int32() => int.Parse(String()); public long Int64() => long.Parse(String()); public ulong UInt64() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray(); public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt32(int count) { for (int i = 0; i < count; i++) yield return Int32(); } public IEnumerable<long> RepeatInt64(int count) { for (int i = 0; i < count; i++) yield return Int64(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt32(int count) { for (int i = 0; i < count; i++) yield return SplitInt32(); } }
}

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

using namespace std;

struct Arm{
  int left;
  int right;
  bool operator<(const Arm& arm) const{
    return right < arm.right;
  }
};

int main(){
  int N;
  cin >> N;
  
  vector<Arm> arms(N);
  for(int i = 0; i < N; i++){
    int X, L;
    cin >> X >> L;
    arms[i].left = X - L;
    arms[i].right = X + L;
  }
  sort(arms.begin(), arms.end());
  
  int robots = 1;
  int r = arms[0].right;
  for(int i = 1; i < N; i++){
    if(arms[i].left >= r){
      robots++;
      r = arms[i].right;
    }
  }
  
  cout << robots << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(void){
	
	int a,b,c;
	
	cin>>a;
	cin>>b;
	cin>>c;
	
	if(a<=c &&  c<=b)
			puts("Yes");
	else
				puts("No");
				
				
	return 0;
}

				
	

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

int main() {
    string S;
    cin >> S;
    vector<string> str{"dream", "dreamer", "erase", "eraser"};
    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; i++) {
        reverse(str[i].begin(), str[i].end());
    }

    for (int i = 0; i < S.size();) {
        bool flag = false;
        for (int j = 0; j < 4; j++) {
            string t = str[j];
            if (S.substr(i, t.size()) == t) {
                flag = true;
                i += t.size();
                break;
            }
        }
        if (!flag) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
use proconio::input;

fn main() {
  input! {
    N: usize,
    S: String,
  }
  let mut result = 0;
  for i in 0..N - 2 {
    if S[i..i + 3] == String::from("ABC") {
      result += 1;
    }
  }
  println!("{}", result);
}

Measured memory_bytes: 2144
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

void swap(int *a, int *b){
    int t;
    t = *a;
    *a = *b;
    *b = t;
}

int partition(int p, int r){
    int x, i, j, t;
    x = A[r];
    i = p - 1;
    for(j=0; j<r; j++){
        if(A[j] <= x){
            i++;
            swap(&A[i], &A[j]);
        }
    }
    swap(&A[i+1], &A[r]);
    return i + 1;
}

int main(){
    int i, q;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d", &A[i]);
    }
    q = partition(0, n-1);

    for(i=0;i<n;i++){
        if (i>0) printf(" ");
        if (i==q) printf("[") ;
        printf("%d", A[i]);
        if (i==q) printf("]");
    }
    printf("\n");
    return 0;
}

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

using namespace std;

int main(){
  unsigned long long x;
  cin >> x;
  cin.ignore();

  unsigned long long a = 100;
  if(a == x){
    cout << 0 << endl;
    return 0;
  }
  unsigned long long cnt = 0;
  while (true) {
    a += a / 100;
    ++cnt;
    if(a >= x){
      cout << cnt << endl;
      return 0;
    }
    //cout << a << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
from collections import Counter
N = int(input())

# 因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = prime_factorize(N)
c = Counter(a)
ans = 0
for i in c.values():
    j = 1
    while i >= j:
        i -= j
        j += 1
        ans += 1
print(ans)



Measured memory_bytes: 65916
class Dice():
    def __init__(self):
        self.nums = list(range(6))
        self.work = list(range(6))

    def set_nums(self, n0, n1, n2, n3, n4, n5):
        self.nums[0] = n0
        self.nums[1] = n1
        self.nums[2] = n2
        self.nums[3] = n3
        self.nums[4] = n4
        self.nums[5] = n5

    def rotate(self, cmd):
        for i in range(6):
            # deepcopy
            self.work[i] = self.nums[i]

        if cmd == 'N':
            self.set_nums(self.work[1], self.work[5], self.work[2], self.work[3], self.work[0], self.work[4])
        elif cmd == 'S':
            self.set_nums(self.work[4], self.work[0], self.work[2], self.work[3], self.work[5], self.work[1]),
        elif cmd == 'E':
            self.set_nums(self.work[3], self.work[1], self.work[0], self.work[5], self.work[4], self.work[2])
        else:
            self.set_nums(self.work[2], self.work[1], self.work[5], self.work[0], self.work[4], self.work[3])

    def top(self):
        return self.nums[0]

    def right(self, top, front):
        # サイコロの面IDを返す
        if top == 1:
            return [3,5,2,4][front-2]
        elif top == 6:
            return [4,2,5,3][front-2]
        elif top == 2:
            # 0が返る場合は不正なサイコロ
            return [4,0,1,6,0,3][front-1]
        elif top == 5:
            # 0が返る場合は不正なサイコロ
            return [3,0,6,1,0,4][front-1]
        elif top == 3:
            # 0が返る場合は不正なサイコロ
            return [2,6,0,0,1,5][front-1]
        elif top == 4:
            # 0が返る場合は不正なサイコロ
            return [5,1,0,0,6,2][front-1]
        else:
            pass

    def rolls(self):
        # 上面、前面、右面、左面、奥面、下面の値を返す
        return [self.nums[i] for i in range(6)]

import random
nums_1 = [int(arg) for arg in input().split()]
nums_2 = [int(arg) for arg in input().split()]
d1 = Dice()
d1.set_nums(*nums_1)
d2 = Dice()
d2.set_nums(*nums_2)
d1_roll = d1.rolls()


for i in range(10000):
    cmd = ['N', 'S', 'E', 'W'][random.randint(0,3)]
    d2.rotate(cmd)
    d2_roll = d2.rolls()
    if all([d1_roll[i] == d2_roll[i] for i in range(6)]):
        print('Yes')
        exit()
print('No')



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

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

  ll T = 1;
  ll A = 1;
  rep(i, N) {
    ll t, a;
    cin >> t >> a;
    // T <= x * t && A <= x * a;
    ll x = max((T + t - 1) / t, (A + a - 1) / a);
    T = x * t;
    A = x * a;
  }
  ll Ans = T + A;
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <bitset>


#define max(a,b)  a > b ? a : b
#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pib = pair<int,bool>;

int main(){
    int n;
    cin >> n;
    int a;
    
    vector<bool> vec(n);
    vector<pib> info[15];

    bool skip_flag;
    int x,y;

    rep(i,n){
        cin >> a;
        rep(j,a){
            cin >> x >> y;
            x--;
            if(y == 1)
                info[i].push_back(make_pair(x,true)); 
            else 
                info[i].push_back(make_pair(x,false)); 
            
        }
    }
int ans = 0;

    rep(i,1 << n){
        skip_flag = false;
        bitset<15> bs(i);
    
        rep(j,n){
            if(bs[j] == true){
                rep(k,info[j].size()){
                    if(bs[info[j][k].first] != info[j][k].second ){
                        skip_flag =true;
                        break;
                    }
                }
            }
            if(skip_flag) break;
        }

        if(skip_flag) {
            continue;
        }else{ 
            ans = max(ans,bs.count());
        }
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int 
#define mk make_pair


int main(){
    ll n,d;
    cin>>n>>d;
    ll x[n],y[n];
    int ans=0;
    d=d*d;
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        ll val=x[i]*x[i]+y[i]*y[i];
        if(d>=val)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6708
using System;

namespace ConsoleApp37
{
    class Program
    {
        static void Main(string[] args)
        {
            var x =int.Parse( Console.ReadLine());
            if (x % 1000 == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(1000 - (x % 1000));
            }
        }
    }
}


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


int main()
{
	int i;
	unsigned long long int N;
	int keta = 0;
	unsigned long long int tasikame = 0;
	unsigned long long int ketaketa = 1;
	int kotae = 0;

	scanf("%llu", &N);
	unsigned long long int m = N;
	while (m != 0) {
			m /= 10;
			keta++;
			tasikame += 9 * ketaketa;
			ketaketa *= 10;
	}
	ketaketa /= 10;

	while (tasikame > N) {
		tasikame -= 1 * ketaketa;
	}
	while (tasikame != 0) {
		kotae += tasikame % 10;
		tasikame /= 10;
	}

	printf("%u", kotae);
	return 0;
}


Measured memory_bytes: 128
import itertools

N, M = map(int, input().split())

d = dict()
for i in range(1, N+1):
    d[i] = list()
for m in range(M):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

ans = 0
for p in itertools.permutations(range(2, N+1)):
    nodes = {1}
    prev_node = 1
    for i, n in enumerate(p):
        if n not in d[prev_node]:
            break

        else:
            prev_node = n
            nodes.add(n)

        if len(nodes) == N:
            ans += 1
            break

print(ans)

Measured memory_bytes: 3188
import collections

n=int(input())
l=[]
for _ in range(n):
    l.append(input())

c=collections.Counter(l)
cc=c.most_common()
ccc=[]
for j in cc:
    if j[1]==cc[0][1]:
        ccc.append(j[0])

for k in sorted(ccc):
    print(k)

Measured memory_bytes: 120016
#include <iostream>
#include <vector>
#include <algorithm> 
#include <queue>
#include <functional>
#include <map>
#include <string>
using namespace std;
typedef long long ll;

int main(void){
    string s[50];
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++){
        cin >> s[i];
    }

    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if(s[i][j]=='#'){
                cout<<'#';
                continue;
            }
            int count = 0;
            for (int dx = -1; dx <= 1; dx++){
                for (int dy = -1; dy <= 1; dy++){
                    if (0<=j+dx&&j+dx<w&&0<=i+dy&&i+dy<h&&s[i + dy][j + dx] == '#'){
                        count++;
                    }
                }
              
            }
             cout << count;
        }
        cout << endl;
    }

    
}

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

/*  using namespace  */
using namespace std;

/*  local var  */

/*  define  */
#define loop(i,j) for(int i = 0; i < j; i++)

/*  typedef  */
typedef long long ll;

/*  function  */
//None

/*  main program  */
int main()
{
	ll A,B;	
	cin>>A>>B;
	cout<<max(A+B,max(A-B,A*B))<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 998244353;
constexpr int inf = 3e18;

int mod_pow(int x,int y,int m=mod){
	int res=1;
	while(y>0){
		if(y&1)(res*=x)%=m;
		(x*=x)%=m;
		y>>=1;
	}
	return res;
}
vector<int>perm,inv;
void init_perm(){
	int x=1e6+1;perm.resize(x);inv.resize(x);
	perm[0]=1;
	REP(i,x+1)perm[i]=perm[i-1]*i%mod;
	inv[x]=mod_pow(perm[x],mod-2);
	for(int i=x-1;i>=0;i--){
		inv[i]=inv[i+1]*(i+1)%mod;
	}
}
int nCk(int x,int y){
	if(x<y)return 0;
	return perm[x]*inv[x-y]%mod*inv[y]%mod;
}
template<typename Monoid,typename OperatorMonoid>
struct Segtree{
	using F=function<Monoid(Monoid,Monoid)>;
	using G=function<Monoid(Monoid,OperatorMonoid,int)>;
	using H=function<OperatorMonoid(OperatorMonoid,OperatorMonoid)>;
	int size=1;
	vector<Monoid>dat;
	vector<OperatorMonoid>lazy;
	const F f;
	const G g;
	const H h;
	Monoid M,M1;
	OperatorMonoid OM;
	void set(int a,Monoid x){
		dat[a+size-1]=x;
	}
	void init(){
		for(int i=size-2;i>=0;i--){
			dat[i]=f(dat[i*2+1],dat[i*2+2]);
		}
	}
	void eval(int k,int l,int r){
		if(lazy[k]!=OM){
			dat[k]=g(dat[k],lazy[k],(r-l));
			if(r-l>1){
				lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
				lazy[2*k+2]=h(lazy[2*k+2],lazy[k]);
			}
			lazy[k]=OM;
		}
	}
	void update(int a,int b,OperatorMonoid M,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l)return;
		if(a<=l&&r<=b){
			lazy[k]=h(lazy[k],M);
			eval(k,l,r);
			return;
		}
		update(a,b,M,k*2+1,l,(l+r)/2);
		update(a,b,M,k*2+2,(l+r)/2,r);
		dat[k]=f(dat[k*2+1],dat[k*2+2]);
	}
	Monoid query(int a,int b,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l)return M1;
		if(a<=l&&r<=b)return dat[k];
		Monoid lv=query(a,b,k*2+1,l,(l+r)/2);
		Monoid rv=query(a,b,k*2+2,(l+r)/2,r);
		return f(lv,rv);
	}
	Segtree(int x,F f,G g,H h,Monoid M,OperatorMonoid OM,Monoid M1)
	:f(f),g(g),h(h),M(M),OM(OM),M1(M1){
		while(size<x)size*=2;
		dat.resize(size*2-1,M);
		lazy.resize(size*2-1,OM);
	}
};
signed main() {
	cin.tie(0);ios::sync_with_stdio(false);
	int N;cin>>N;
	int all=0;
	vector<P>v1,v2;
	rep(i,N){
		string s;cin>>s;
		int cnt=0,mn=inf;
		for(char c:s){
			if(c=='(')cnt++;
			else cnt--;
			chmin(mn,cnt);
		}
		all+=cnt;
		int mx=cnt-mn;
		if(cnt>=0){
			v1.pb({-mn,mx});
		}else {
			v2.pb({-mn,mx});
		}
	}
	if(all!=0){
		cout<<"No"<<endl;
		return 0;
	}
	auto f=[](P a,P b){
		return a.first<b.first;
	};
	auto g=[](P a,P b){
		return a.second>b.second;
	};
	sort(all(v1),f);sort(all(v2),g);
	int now=0;
	for(auto i:v1){
		if(now<i.first){
			cout<<"No"<<endl;return 0;
		}
		now+=i.second-i.first;
	}
	for(auto i:v2){
		if(now<i.first){
			cout<<"No"<<endl;return 0;
		}
		now+=i.second-i.first;
	}
	cout<<"Yes"<<endl;
}


Measured memory_bytes: 19008
#include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(i=a;i<b;i++)
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define vi vector < ll  int >
    #define CLR(a) memset((a),0,sizeof(a))
    #define mp make_pair
    #define hell 1000000007
    using namespace std;

    #define MAXN 1000005
    int spf[MAXN];
    void sieve()
    {
        spf[1] = 1;
        for (int i=2; i<MAXN; i++)
            spf[i] = i;
        for (int i=4; i<MAXN; i+=2)
            spf[i] = 2;

        for (int i=3; i*i<MAXN; i++)
        {
            if (spf[i] == i)
            {
                for (int j=i*i; j<MAXN; j+=i)

                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }


    vector<int> gf(int x)
    {
        vector<int> ret;
        while (x != 1)
        {
            ret.push_back(spf[x]);
            x = x / spf[x];
        }
        return ret;
    }
    int BIT[100050];
    void upd(int x) { ++x;  while(x<=MAXN)  {  BIT[x]++;  x+=(x&-x);  } }
    int cal(int x) {  ++x;  int res=0;  while(x>0)  {  res+=BIT[x];  x-=(x&-x);  } return res; }

    ll mod=hell;
    ll pr( ll x , ll y)
    {
        ll ans=1;
        if(y==0) return ans;
        while(y>1)
        {
            if(y&1) ans*=x;
            x*=x;
            y/=2;
            x%=mod;
            ans%=mod;
        }
        ans*=x;
        ans%=mod;
        return ans;
    }
    ll inv(ll n)
    {
        return pr(n,mod-2);
    }
    ll stoi(string s)
    {
        int n=s.size();
        ll k=0; int i;
        rep(i,0,n)
        {
            k+=s[i]-'0';
            k*=10;
        }
        return k/10;
    }
    string to_string(ll n)
    {  if(!n) return "0";
        string s=""; int a,b;
        while(n>0)
        {
            b=n%10;
            s+=(b+'0');
            n/=10;
        }
        reverse(all(s));
        return s;
    }
  ll invvf[1000500],fact[1000500];
  void pre()
  {
      ll i,j,n=1000050;
      fact[0]=1; fact[1]=1;
      rep(i,2,n) {fact[i]=fact[i-1]*i; fact[i]%=hell;}
      invvf[1]=1; invvf[0]=1;
      rep(i,2,n)
      {
          invvf[i]=inv(fact[i]);
      }

  }
 ll ncr(ll n , ll r)
 {
     ll y=fact[n];
     y*=invvf[r];
     y%=hell;
     y*=invvf[n-r];
     y%=hell;
     return y;
 }


int phi(int n) {
    int result = n;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if (n > 1)
        result -= result / n;
    return result;
}
    void solve()
    {
    long long  i,j=0,r=200,p,q,k=0,d,y=0,n,h=100000000000000,flag=0,m=0,a=hell,b=hell,id,h1,h2,a1,b1,a2,w,x,u,f,l,c=0,e,ans=0;
      string s;
      cin>>n;
      cin>>s;
      rep(i,0,n-2)
      {
          string ss=s.substr(i,3);
          if(ss=="ABC") y++;
      }
      cout<<y;


    }
    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t=1;
        //sieve();
        //pre();
        //cin>>t;
        while(t--)
        solve();
    }


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

int main(void) {
	long long K, N; cin >> K >> N;
	vector<long long> A(N);

	for (int i = 0; i < N; i++) cin >> A[i];

	long long max_distance = 0;
	for (int i = 0; i < N-1; i++) {
		max_distance = max(max_distance, A[i + 1] - A[i]);
	}
	max_distance = max(max_distance, K - A[N - 1] + A[0]);

	cout << K - max_distance << endl;

	return 0;
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N, K;
  cin >> N >> K;
  long long n = N/K;
  long long m = (N+K/2)/K;
  if(K%2 == 1){
    cout << n*n*n << endl;
  }else{
    cout << n*n*n + m*m*m << endl;
  }
}

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

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

double sol(int i, int j, int k, vector<vector<vector<double>>>& dp){
    if(dp[i][j][k] or i+j+k == 0) return dp[i][j][k];

    int N = dp.size()-1;
    dp[i][j][k] += (double) N/(i+j+k);
    if(i > 0) dp[i][j][k] += sol(i-1, j, k, dp) * i/(i+j+k);
    if(j > 0) dp[i][j][k] += sol(i+1, j-1, k, dp) * j/(i+j+k);
    if(k > 0) dp[i][j][k] += sol(i, j+1, k-1, dp) * k/(i+j+k);

    return dp[i][j][k];
}


int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    vector<vector<vector<double>>> dp(N+1, vector<vector<double>>(N+1, vector<double>(N+1, 0)));

    cout << fixed << setprecision(10) << sol(count(a.begin(), a.end(), 1),
                                             count(a.begin(), a.end(), 2),
                                             count(a.begin(), a.end(), 3), dp) << endl;

    return 0;
}

Measured memory_bytes: 216960
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;

    cout << n / 3 << endl;


    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.141592653589793
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int A,B,H,M;

int main() {
  INCANT;
  cin >> A >> B >> H >> M;
  double jishin = (double)360*(60*H+M)/(60*12);
  double hunshin = (double)360*M/60;
  double w = max(360-abs(hunshin-jishin), abs(hunshin-jishin));
  double ans = pow(A,2)+pow(B,2)-2*A*B*cos(PI*(w/180.0));
  cout << sqrt(ans) << "\n";
  return 0;
}

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

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> p(n);
        for (auto& i : p) cin >> i;
        sort(p.begin(), p.end());

        int ans = 1<<28;
        for (int i = 0; i < n-1; i++) {
            ans = min(ans, p[i+1]-p[i]);
        }

        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3152
#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 <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
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;
#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) << endl
#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)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -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;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
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;

void modAdd(int &a,int b){
    a += b;
    if(a >= MOD) a-= MOD;
}
int main(void) {
    int H,W;
    vs a;
    int dp[1100][1100] = {0};

    cin >> H >> W;
    a.resize(H);
    rep(i,H) cin >> a[i];

    dp[0][0] = 1;

    rep(i,H){
        rep(j,W){
            if(i+1 < H && a[i+1][j] == '.') modAdd(dp[i+1][j],dp[i][j]);
            if(j+1 < W && a[i][j+1] == '.') modAdd(dp[i][j+1],dp[i][j]);
        }
    }
    fin(dp[H-1][W-1]);//0indexなので

}

Measured memory_bytes: 6016
from collections import Counter
n = int(input())
xy = [tuple([int(_) for _ in input().split()]) for i in range(n)]
if n == 1:
    result = 1
else:
    xy.sort()
    dxy = [(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
           for i in range(n)
           for j in range(i+1, n)]
    cdxy = Counter(dxy)
    result = n - max(cdxy.values())
print(result)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
int main() 
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if (N % 2 == 0) {
    int a = A[N / 2 - 1] + A[N / 2];
    int b = B[N / 2 - 1] + B[N / 2];
    cout << b - a + 1 << '\n';
  } else {
    int a = A[N / 2];
    int b = B[N / 2];
    cout << b - a + 1 << '\n';
  }
  return 0;
}

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

int main()
{
  int N, M, C;
  cin >> N >> M >> C;
  
  int s=0;
  
  int B[M];
  for(int k=0; k<M; k++){
        cin >> B[k];
  }
  
  int A[M];
  for(int i=0;i<N;i++){
    int S=C;
    for(int j=0; j<M; j++){
      cin >> A[j];
      S += A[j]*B[j];
    }
    if(S>0)
      s=s+1;
  }
  cout << s;
  
  return 0;
}


Measured memory_bytes: 256
using System;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int m = sc.NextInt();
        int k = sc.NextInt();

        int[] a = sc.IntArray();
        int[] b = sc.IntArray();

        long[] sumB = new long[m + 1];
        for (int i = 0; i < m; i++)
        {
            sumB[i + 1] += sumB[i] + b[i];
        }

        long ans = long.MinValue;
        long s = 0;
        for (int i = 0; i < n && s <= k; i++)
        {
            int ok = 0;
            int ng = m + 1;
            while (ng - ok > 1)
            {
                int mid = (ok + ng) / 2;
                if (sumB[mid] + s <= k)
                {
                    ok = mid;
                }
                else
                {
                    ng = mid;
                }
            }

            ans = Math.Max(ans, i + ok);

            s += a[i];
        }

        if (s <= k)
        {
            int ok = 0;
            int ng = m + 1;
            while (ng - ok > 1)
            {
                int mid = (ok + ng) / 2;
                if (sumB[mid] + s <= k)
                {
                    ok = mid;
                }
                else
                {
                    ng = mid;
                }
            }

            ans = Math.Max(ans, n + ok);
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

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

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

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

            return _line[_index++];
        }

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

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

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

Measured memory_bytes: 70048
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int A, B;
    cin >> A >> B;
    int num = A * 3 + B;
    cout << num / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] L = new int[n];
		for(int i = 0;i < n;i ++) {
			L[i] = sc.nextInt();	
		}
		Arrays.sort(L);
		int sum = 0;
		for(int i = 0;i < n - 1;i ++) {
			sum += L[i];
		}
		if(L[L.length - 1] < sum) System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 22868
n=int(input())
h = list(map(int,input().split()))
 
ans=1
cnt=0
for i in range(n-1):
  for j in range(i+1):
    if h[j]<=h[i+1]:
      cnt+=1
    else:
      cnt=0
      break
    if cnt==i+1:
      ans+=1
      cnt=0
      break
 
print(ans)

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

int main(){
    int n,m;
    cin >> n >> m;
    
    int A[n][m];
    int b[m];
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> A[i][j];
        }
    }
    for(int k = 0; k < m; k++){
        cin >> b[k];
    }
    
    for(int i = 0; i < n; i++){
        int sum = 0;
        for(int j = 0; j < m; j++){
            sum += A[i][j]*b[j];
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
#include <stdio.h>
#define N 10000

int linearSearch(int*,int,int);

int main(){
  int n,q,i,S[N+1],t,count=0;

  scanf("%d",&n);
  for(i = 0;i < n;i++) scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&t);
    if(linearSearch(S,n,t)) count++;
  }
  
  printf("%d\n",count);

  return 0;
}

int linearSearch(int U[],int m,int key){
  int j = 0;
  U[m] = key;
  while(U[j] != key) j++;
  return j != m;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
const int LIM = 6200;

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

    long long int a[LIM];
    for(long long int i = 0; i < LIM; i++){
        a[i] = pow(i, 5);
    }

    long long int ans1 = 0;
    long long int ans2 = 0;
    for(int i = 0; i < LIM; i++){
        long long int b = x - a[i];
        if(b == 0){
            ans1 = i;
            ans2 = 0;
            break;
        }else if(b > 0){
            long long int left = -1;
            long long int right = LIM;
            while(right - left > 1){
                long long int mid = left + (right - left)/2;
                if(a[mid] >= b){
                    right = mid;
                }else{
                    left = mid;
                }
            }
            if(right < LIM && a[right] == b){
                ans1 = i;
                ans2 = right*(-1);
                break;
            }
        }else{
            long long int left = -1;
            long long int right = LIM;
            while(right - left > 1){
                long long int mid = left + (right - left)/2;
                if(a[mid] >= b*(-1)){
                    right = mid;
                }else{
                    left = mid;
                }
            }
            if(right < LIM && a[right]*(-1) == b){
                ans1 = i;
                ans2 = right;
                break;
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}

Measured memory_bytes: 4240
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    
    double ans=0.0;
    for(int i=0; i<N; i++){
        double a;
        cin >> a;
        ans+=1.0/a;
    }
    ans=1.0/ans;
    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

ll dp[101][100001];

int main(void){
    cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,W;
	cin>>n>>W;
	vl w(n),v(n);
	rep(i,n) cin>>w[i]>>v[i];
	rep(i,n) rep(j,100001) dp[i][j] = inf;
	dp[0][0] = 0;
	rep(i,n){
	    rep(j,100001){
	        if(i>0){
	            dp[i][j] = min(dp[i][j],dp[i-1][j]);
	            if(j-v[i]>=0) dp[i][j] = min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
	        }
	        else{
	            if(j==v[i]){
	                dp[i][j] = w[i];
	                //cout<<i<<" "<<j<<endl;
	            }
	        }
	        //dp[i][j] = min(dp[i][j],dp[i][max(0LL,j-v[i])]+w[i]);
	    }
	}//cout<<dp[0][30]<<endl;
	ll ans = 0;
	for(ll i=100000;i>=0;i--){
	    if(dp[n-1][i] <= W){
	        ans = i;
	        break;
	    }
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 78336
#include <iostream>
#include <vector>
#include <cmath>

int main() {
    int N;
    std::cin >> N;
    std::vector<int> hs(N);
    std::vector<int> dp_table(N);
    for (auto& h: hs)
        std::cin >> h;
    dp_table[0] = 0;
    dp_table[1] = std::abs(hs[0] - hs[1]);
    for (int i=2; i<N; ++i) {
        dp_table[i] = std::min(
                dp_table[i-1] + std::abs(hs[i] - hs[i-1]),
                dp_table[i-2] + std::abs(hs[i] - hs[i-2]));
    }
    std::cout << dp_table[N-1] << std::endl;
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  multiset<int> S;
  Solver(LL n) : n(n){};

  void solve() {
    for (int i = 0; i < (1 << n); ++i) {
      int tmp;
      cin >> tmp;
      S.insert(tmp);
    }
    vector<int> t;
    t.push_back(*prev(S.end()));
    S.erase(prev(S.end()));
    for (int i = 0; i < n; ++i) {
      int l = t.size();
      for (int j = 0; j < l; ++j) {
        auto it = S.lower_bound(t[j]);
        if (it == S.begin()) {
          cout << "No" << endl;
          return;
        }
        it--;
        t.push_back(*it);
        S.erase(it);
      }
    }
    cout << "Yes" << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 13688
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int N,W;
    scanf("%d%d",&N,&W);
    vector<ll> dp(W+1);
    for(int i=1;i<=N;++i){
        int weight,value;
        scanf("%d%d",&weight,&value);
        for(int w=W;w>=weight;--w){
            dp[w]=max(dp[w],dp[w-weight]+value);
        }
    }
    ll ans=0;
    for(int i=1;i<=W;++i){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<'\n';
    // while(1);
    return 0;
}

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

int main() {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	int ans = A * X + B * Y;
	for (int i = 0; i <= max(X, Y); i++) {
		int tmp = i * 2 * C + max(0, X - i) * A + max(0, Y - i) * B;
		if (ans > tmp) {
			ans = tmp;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256