akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,q,b,c;
    cin >> n;
    long long int sum=0;
    long long int a[n];
    map<int,int> mp;
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum += a[i];
        mp[a[i]]++;
    }
    cin >> q;
    for(int i=0;i<q;i++){
        cin >> b >> c;
        sum += (c-b)*mp[b];
        mp[c]+=mp[b];
        mp[b]=0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 8596
s = input().rstrip().split(' ')
W = int(s[0])
H = int(s[1])
x = int(s[2])
y = int(s[3])
r = int(s[4])

if 0 <= x - r and x + r <= W and 0 <= y - r and y + r <= H:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 7656
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int total = 0;
		int[] t = new int[n];
		for(int i=0;i<n;i++) {
			t[i] = sc.nextInt();
			total += t[i];
		}
		int m = sc.nextInt();
		for(int i=0;i<m;i++) {
			int p = sc.nextInt();
			int x = sc.nextInt();
			System.out.println(total-(t[p-1]-x));
		}
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
using namespace std;
int b,s,a=0;
int main()
{
	cin>>b;
	while(b!=0)
	{
		s=b%10;
		if(s==9)
		{
			printf("Yes");
			a++;
			break;
		}
		b/=10;
	}
	if(a==0)
	printf("No");
	return 0;
}

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

using namespace std;

const ll MOD=1000000007;
ll p2[100],cnt[100];

int main()
{
    p2[0]=1;
    for (int i=1;i<=60;i++) p2[i]=p2[i-1]<<1;
    int n;
    scanf("%d",&n);
    ll ans=0;
    memset(cnt,0,sizeof(cnt));
    for (int i=0;i<n;i++)
    {
        ll x;
        scanf("%lld",&x);
        for (int j=0;j<=60;j++)
        {
            if ((x&p2[j])==0) ans=(ans+p2[j]%MOD*cnt[j])%MOD;
            else 
            {
                ans=(ans+p2[j]%MOD*(i-cnt[j]))%MOD;
                cnt[j]++;
            }
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 256
import java.util.*;

import javax.naming.spi.DirStateFactory.Result;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0593().doIt();
	}
	
	class AOJ0593{
		void doIt(){
			int n = in.nextInt();//競技
			int b = in.nextInt();//審査員
			Kyougi[] kyougi = new Kyougi[n];
			for(int i=0;i<n;i++)kyougi[i] = new Kyougi(i+1, in.nextInt());
			for(int s=0;s<b;s++){
				int a = in.nextInt();
				for(int i=0;i<n;i++)if(a>=kyougi[i].num){
					kyougi[i].cnt++;
					break;
				}
			}
			int max,result;
			max = result = Integer.MIN_VALUE;
			
			for(int i=0;i<n;i++)if(max<kyougi[i].cnt){
				max = kyougi[i].cnt;
				result = kyougi[i].ban;
			}
			System.out.println(result);
		}
		class Kyougi{
			int ban,cnt,num;
			public Kyougi(int ban,int num){
				this.ban = ban;
				this.num = num;
				cnt = 0;
			}
			public String toString(){
				return this.ban+" "+this.cnt+" "+this.num;
			}
		}
	}
	
}

Measured memory_bytes: 25652
use List::Util qw/reduce/;
sub any (&@) {my $p = shift; return reduce { $a || $p->(local $_ = $b) } 0, @_}

my ($N, $M) = split(' ', <>);
my ($to1, $toN) = ({}, {});
for (1..$M) {
    my ($a, $b) = split(' ', <>);
    $to1->{$b} = 1 if $a == 1;
    $to1->{$a} = 1 if $b == 1;
    $toN->{$b} = 1 if $a == $N;
    $toN->{$a} = 1 if $b == $N;
}

print ((any {$toN->{$_}} keys %$to1) ? 'POSSIBLE' : 'IMPOSSIBLE');

Measured memory_bytes: 36352
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
1 2 3 5

output:
30
"""

import sys
from functools import reduce
from operator import mod


def gcd(x, y):
    if x < y:
        x, y = y, x

    while y > 0:
        r = mod(x, y)
        x = y
        y = r

    return x


def lcm(a, b):
    return a * b // gcd(a, b)


def solve(_n_list):
    return reduce(lcm, _n_list)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    cnt = int(_input[0])
    n_list = tuple(map(int, _input[1].split()))
    print(solve(n_list))

Measured memory_bytes: 8304
#include <stdio.h>

static const int N=1000;

void trace(int *A, int n) {
    int i;

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

void sort(int *A, int n) {
    int i, j, tmp;

    for (i=0;i<n;i++) {
        for (j=i;j<n;j++) {
            if (A[j]<A[i]) {
                tmp=A[i];
                A[i]=A[j];
                A[j]=tmp;
            }
        }
    }
}

int main(void) {
    int n, i;
    int A[N+1];
    
    scanf("%d", &n);
    for (i=0; i<n; i++) scanf("%d", &A[i]);

    //trace(A, n);
    for (i=1; i<=n; i++) sort(A, i), trace(A, n);

    return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>

int Days(int year, int month, int day);

int main(){
	int data;
	int year, month, day;
	int i;
	int millennium_days = Days(1000, 1, 1);
	int birthday;

	scanf("%d", &data);
	for(i=0; i<data; i++){
		scanf("%d %d %d", &year, &month, &day);
		birthday = Days(year, month, day);
		printf("%d\n", millennium_days - birthday);
	}

	return 0;
}

int Days(int year, int month, int day){
	int num;
	int leap_year_num;

	leap_year_num = (year-1)/3;
	num = leap_year_num*200+(year-1-leap_year_num)*195;
	if(year%3==0){
		num += (month-1)*20 + day;
	}else{
		num += (month-1)*20 - (month-1)/2 + day;
	}
	return num;
}

Measured memory_bytes: 596
N, L = map(int, input().split())

r1 = L          # リンゴ1
rN = L + N - 1  # リンゴN
s  = sum(range(r1, rN + 1))

if not (r1 <= 0 <= rN):
    s -= r1 if abs(r1) < abs(rN) else rN
print(s)


Measured memory_bytes: 2940
#include <stdio.h>
#define rep(i,j,k) for(i = j;i <= k;i++)


void Ink(int x,int y,int size, int paper[][14]){
  if(size == 1){
    paper[x+1][y]++;paper[x-1][y]++;paper[x][y+1]++;paper[x][y-1]++;paper[x][y]++;
  }

  if(size == 2){
    paper[x+1][y]++;paper[x-1][y]++;paper[x][y+1]++;paper[x][y-1]++;
    paper[x+1][y+1]++;paper[x-1][y-1]++;paper[x-1][y+1]++;paper[x+1][y-1]++;paper[x][y]++;
  }

  if(size == 3){
        paper[x+1][y]++;paper[x-1][y]++;paper[x][y+1]++;paper[x][y-1]++;
    paper[x+1][y+1]++;paper[x-1][y-1]++;paper[x-1][y+1]++;paper[x+1][y-1]++;
    paper[x][y+2]++;paper[x][y-2]++;paper[x+2][y]++;paper[x-2][y]++;paper[x][y]++;
  }

}



int main(){
  int x,y,size,i,j,count,depth,paper[14][14];
for(i = 0;i <= 13;i++){
  for(j = 0;j <= 13;j++){
      paper[i][j] = 0;
  }
}

  while(scanf("%d,%d,%d",&x,&y,&size) != EOF){
    Ink(x+2,y+2,size,paper);
  }
  count = 0;
  depth = 0;
  rep(i,2,11){
    rep(j,2,11){
      if(paper[i][j] == 0) count++;
      if(depth < paper[i][j]) depth = paper[i][j];
    }
  }

  printf("%d\n%d\n",count,depth);

  return 0;
}

Measured memory_bytes: 0
a, b, c, x, y = map(int, input().split())
if a+b <= c*2:
    print(a*x+b*y)
else:
    ans = 10**9
    for i in range(min(x,y)*2, 1+max(x,y)*2, 2):
        xx = x-i/2 if x-i/2 >= 0 else 0
        yy = y-i/2 if y-i/2 >= 0 else 0
        ans = min(ans, int(a*xx+b*yy+c*i))
    print(ans)

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

int main(){
    int A, B, ans;
    bool C = false;
    cin >> A >> B;
    for(int i = 0; i < 1001; i++){
        if(floor(i * 0.08) == A && floor(i * 0.10) == B){
            ans = i;
            C = true;
            goto ABC;
        }
    }
    ABC:
    if(C == true){
        cout << ans << endl;
    }
    else{
        cout << -1 << endl;
    }
    return 0;
}

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

using namespace std;

int main(void){
    
    while(1){
        int N,ba = 0,cnt = 0;
        char c[101];
        vector<int> mem;
        cin >> N;
        if(N == 0)  return false;
        cin >> c;
        mem.resize(N);
        for(int i = 0; i < 100; i++){
            if(c[i] == 'S'){
                ba = mem[cnt] + ba + 1;
                mem[cnt] = 0;
            }else if(c[i] == 'M'){
                mem[cnt] = mem[cnt] + 1;
            }else if(c[i] == 'L'){
                mem[cnt] = mem[cnt] + ba + 1;
                ba = 0;
            }
            cnt++;
            if(cnt == N)    cnt = 0;
        }
        sort(mem.begin(),mem.end());
        for(int i = 0; i < N; i++){
            cout << mem[i] << " ";
        }
        cout << ba << endl;
    }
    
}

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

int n;
string s, ans;

stack <char> st;

int main()
{
	scanf ("%d", &n);
	cin >> s;
	
	for (int i=0; i<n; i++){
		if (s[i] == '(')
			st.push (s[i]);
		else if (s[i] == ')'){
			if (st.empty())
				ans = '(' + ans;
			else
				st.pop ();
		}
		
		ans += s[i];
	}
	
	while (!st.empty ()){
		ans += ')';
		st.pop ();
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VI D(N);
  rep(i,N) cin>>D[i];
  if(D[0]){
    cout<<0<<endl;
    return 0;
  }
  sort(all(D));
  ll ans=1;
  ll mod=998244353;
  rep(i,N-1){
    int X=D[N-1-i];
    int num=ub(all(D),X-1)-lb(all(D),X-1);
    ans=ans*num%mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Vector;
 
class Main {
 
    /**
     * Returns list of all indices where pattern is found in text.
     */
    public static int[] calculateZ(char input[]) {
        int Z[] = new int[input.length];
        int left = 0;
        int right = 0;
        for (int k = 1; k < input.length; k++) {
            if (k > right) {
                left = right = k;
                while (right < input.length && input[right] == input[right - left]) {
                    right++;
                }
                Z[k] = right - left;
                right--;
            } else {
                // we are operating inside box
                int k1 = k - left;
                // if value does not stretches till right bound then just copy it.
                if (Z[k1] < right - k + 1) {
                    Z[k] = Z[k1];
                } else { // otherwise try to see if there are more matches.
                    left = k;
                    while (right < input.length && input[right] == input[right - left]) {
                        right++;
                    }
                    Z[k] = right - left;
                    right--;
                }
            }
        }
        return Z;
    }
 
    /**
     * Returns list of all indices where pattern is found in text.
     */
 
    public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
 
    public static int[] radixSort(int[] f) {
        return radixSort(f, f.length);
    }
 
    public static int[] radixSort(int[] f, int n) {
        int[] to = new int[n];
        {
            int[] b = new int[65537];
            for (int i = 0; i < n; i++)
                b[1 + (f[i] & 0xffff)]++;
            for (int i = 1; i <= 65536; i++)
                b[i] += b[i - 1];
            for (int i = 0; i < n; i++)
                to[b[f[i] & 0xffff]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        {
            int[] b = new int[65537];
            for (int i = 0; i < n; i++)
                b[1 + (f[i] >>> 16)]++;
            for (int i = 1; i <= 65536; i++)
                b[i] += b[i - 1];
            for (int i = 0; i < n; i++)
                to[b[f[i] >>> 16]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        return f;
    }
 
    public static void main(String[] args) throws java.lang.Exception {
        // your code goes here
        Scanner ob = new Scanner(System.in);
        int T = ob.nextInt();
        int b = ob.nextInt();
        out.println(T * b);
        out.close();
    }
}

Measured memory_bytes: 35732
#include<stdio.h>

int main(void){
    int n, b, f, r, v;
    int x[4][3][10] = {0};
    int j, q, k;
    
    scanf("%d", &n);
    for(j = 0; j < n; j++){
        scanf(" %d %d %d %d", &b, &f, &r, &v);
        x[b -1][f -1][r -1] += v;
    }
    
    for(j = 0; j < 4; j++){
        for(q = 0; q < 3; q++){
            for(k = 0; k < 10; k++){
                printf(" %d", x[j][q][k]);
                if(k == 9)
                    printf("\n");
                if(q == 2 && k == 9 && j != 3)
                    printf("####################\n");
            }
        }
    }
    
    return 0;
}



Measured memory_bytes: 2080
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.parse().unwrap()
    };

    let s: String = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s
    };
    let v: Vec<char> = s.chars().collect();

    let mut count: isize = 0;
    let mut left_num = 0;
    for &c in &v {
        if c == '(' {
            count += 1;
        } else {
            count -= 1;
        }

        if count < 0 {
            left_num += 1;
            count = 0;
        }
    }

    let mut ans = String::new();
    for _ in 0..left_num {
        ans.push('(');
    }
    ans.push_str(&s);

    let mut right_num: isize = 0;
    for c in ans.chars() {
        if c == '(' {
            right_num += 1;
        } else {
            right_num -= 1;
        }
    }

    for _ in 0..right_num {
        ans.push(')');
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
const int N=100005;
vector<int> edges[N];
int dis[N]{};
int vis[N]={};
int inDeg[N]{};
void dfs(int n)
{
    vis[n]=1;
    for(int b: edges[n])
    {
        dis[b]=max(dis[b],dis[n]+1);
        inDeg[b]--;
        if(inDeg[b]==0)
            dfs(b);
    }
}
void solve()
{
    int n,k=1,m=0,i=1,j,x,y,l,r,z;
    int ans=0,sum=0,value=0,weight;
    cin>>n>>m;
    while(m--)
    {
        cin>>x>>y;
        edges[x].pb(y);
        inDeg[y]++;
    }
    for(i=1;i<=n;i++)
    {
        edges[0].pb(i);
        inDeg[i]++;
    }
    for(i=0;i<=n;i++)
    {
        if(!vis[i])
            dfs(i);
    }
    ans=*max_element(dis,dis+n+1);
    cout<<ans-1;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif 
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

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

int main(void){
    long long n=0;
    scanf("%ld",&n);
    //printf("%ld",n);
    
    long long a,b=0;
    long long s = floor(sqrt(n));
    int i = 0;
    for(i=s;i>=1;i--){
        if(n%i==0){
            a=i;
            b=n/i;
            printf("%ld\n",a+b-2);
            return 0;
        }
    }

}

Measured memory_bytes: 128
num_str = input()
if len(num_str) == 1:
  odd_num = int(num_str)
elif len(num_str) == 2:
  odd_num = 9
elif len(num_str) == 3:
  odd_num = 9 + (int(num_str) - 99)
elif len(num_str) == 4:
  odd_num = 909
elif len(num_str) == 5:
  odd_num = 909 + (int(num_str) - 9999)
else:
  odd_num = 90909
  
print(odd_num)


Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<iomanip>

#define PII pair<int,int>
#define LLI long long int

using namespace std;

int N,M;
vector<vector<int> >G;
vector<bool>done;
vector<int>mem;
int dfs(int now){
	if(mem[now]>0)return mem[now];
	int ret=-1;
	for(int j=0;j<G[now].size();j++){
		ret=max(ret,dfs(G[now][j]));
	}
	mem[now]=ret+1;
	return ret+1;
}
int main(){
	cin>>N>>M;
	G=vector<vector<int> >(N+1);
	mem=vector<int>(N+1,0);
	for(int i=0;i<M;i++){
		int x,y;cin>>x>>y;
		G[x].push_back(y);
	}
	int ans;
	for(int i=1;i<=N;i++)if(!mem[i]){
		ans=max(ans,dfs(i));
	}
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 8192
#include <stdio.h>

int i, H, A[2000000];

int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

void maxHeapify(int *A, int i){
  int largest, tmp;
  int l = left(i), r = right(i);
  if(l <= H && A[l] > A[i]){
    largest = l;
  }
  else{
    largest = i;
  }
  if(r <= H && A[r] > A[largest]){
    largest = r;
  }
  if (largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A, largest);
  }
}

int extract(){
  int maxv;
  if(H<1)return -100000;
  maxv=A[1];
  A[1]=A[H--];
  maxHeapify(A,1);
  return maxv;
}

void increaseKey(int i, int key){
  int tmp;
  if(key<A[i])return;
  A[i]=key;
  while(1){
    if(i<=1 || A[i/2]>=A[i])break;
    tmp=A[i];
    A[i]=A[i/2];
    A[i/2]=tmp;
    i=i/2;
  }
}

void insert(int key){
  A[++H]=-100000;
  increaseKey(H, key);
}



int main(){
  int key;
  char C[8];
  
  while(1){
    scanf("%s",C);
    if(C[0]=='e'&&C[1]=='n')break;
    if(C[0]=='i'){
      scanf("%d", &key);
      insert(key);
    }
    else{
      printf("%d\n",extract());
    }
  }
  return 0;
}
 

Measured memory_bytes: 4696
import java.io.IOException;
import java.util.Scanner;

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

        int[] dims = new int[n + 1];
        for (int i = 0; i < n; i++) {
            dims[i] = sc.nextInt();
            if (i == n - 1) {
                dims[i + 1] = sc.nextInt();
            } else {
                sc.nextInt();
            }
        }

        int[][] costs = new int[n][n];

        for (int i = 0; i < n; i++) {
            costs[i][i] = 0;
        }

        for (int len = 2; len <= n; len++) {
            for (int i = 0; i <= n - len; i++) {
                int j = i + len - 1;
                costs[i][j] = Integer.MAX_VALUE;
                for (int k = i; k < j; k++) {
                    int cost = costs[i][k] + costs[k + 1][j] + dims[i] * dims[k + 1] * dims[j + 1];

                    if (cost < costs[i][j]) {
                        costs[i][j] = cost;
                    }
                }
            }
        }

        System.out.println(costs[0][n - 1]);
    }
}

Measured memory_bytes: 26452
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
struct P{int x[33];string name;int rp;};
int main(){
int mp[33]={};
struct P Q[25];


int n;
while(1){
scanf("%d",&n);if(n==0)break;
int Y[25][33]={};
for(int iii=1;iii<24;iii++)
{Q[iii].rp=0;}

for(int iii=1;iii<=n;iii++)
{
cin>>Q[iii].name;
int nj;
cin>>nj;
for(int j=0;j<nj;j++)
{int r;
cin>>r;Y[iii][r]=1;Y[0][r]++;
}
}
for(int i=1;i<=n;i++)
{
for(int j=0;j<31;j++)
{
if(Y[i][j]==1)Q[i].rp+=n-Y[0][j]+1;
}
}



int min=Q[1].rp;string T=Q[1].name;
for(int i=1;i<=n;i++){
	

if(min==Q[i].rp&&T>Q[i].name){min=Q[i].rp;T=Q[i].name;}
else if(min>Q[i].rp){min=Q[i].rp;T=Q[i].name;}
}

cout<<min<<" "<<T<<endl;

}
return 0;
}

Measured memory_bytes: 1272
//Created by Aminul on 9/19/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt();
        long res = 0;
        for (int a = 1; a < n; a++) {
            int b = (n - 1) / a;
            res += b;
        }
        pw.println(res);

        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

Measured memory_bytes: 35876
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val S = sc.nextLine()
    val stack = scala.collection.mutable.Stack[Char]()
    var count = 0
    S.foreach { next =>
      if (stack.nonEmpty) {
        val head = stack.head
        if (head == next)
          stack.push(next)
        else {
          stack.pop()
          count += 2
        }
      } else stack.push(next)
    }

    println(count)
  }

}


Measured memory_bytes: 31532
#include<cstdio>
#include<iostream>
#define LL long long
using namespace std;
const int maxn=1<<30;
LL gcd(LL a,LL b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
int main()
{
	LL n,m;
	while(~scanf("%lld%lld",&n,&m))
	{
		if(n%m==0) printf("-1\n");
		else if(m==1) printf("-1\n");
            else
            printf("%lld\n",m*n/gcd(m,n)+n);
	}
 }


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int K;
	scanf("%d",&K);
	int a[32]= {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

	printf("%d\n",a[K-1]);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  
    cout<< fixed <<setprecision(20);
  
    long long int N;
    cin >> N;
    vector<double> x(N);
    vector<double> y(N);
    
    for(int i=0;i<N;i++)
   { cin >> x[i]; cin >> y[i]; }
   
        vector<int> v(N);
    
    for(int i=0;i<N;i++)
    v[i] = i;
    
        double su = 0;
    long long int c = 0;
    do {
        c++;
        for(int i=0;i<N - 1;i++)
        {
            double dx = x[v[i + 1]] - x[v[i]];
            double dy = y[v[i + 1]] - y[v[i]];
            su += sqrt(dx * dx + dy * dy);
        }
    } while (next_permutation(v.begin() , v.end()));
    cout << su / c << endl;
    return 0;
}

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

int main(){
 long long n,k,a,b;
 cin>>n>>k;

 a=n%k;
 if (a-k>=0){b=a-k;}
 else{b=k-a;}

 if(a>=b){cout<<b<<endl;}
 else{cout<<a<<endl;}
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
    string s;

    cin >> s;

    for(int i = 0; i < s.size() - 8; i++)
    {
        cout << s[i];
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n){
        cin>>a[i];
    }
    int ans=0;
    rep(i,n-1){
        if(a[i]==a[i+1]){
            for(int j=1; j<=10000; ++j){
                if(a[i]!=j&&a[i+1]!=j){
                    a[i+1]=j;
                }
            }
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int N,d,t,q,i,j;
	for(;cin>>N,N;){
		int Q[25][25] = {{0}}; // Q[d][i] d 周期の i 時間目の量 (0<=i<d)
		for(i=0;i<N;++i){
			cin>>d>>t;
			for(j=0;j<d;++j){
				cin>>q;
				Q[d][(j+d-t)%d]+=q;
			}
		}
		const int L = 16*9*5*7*11;
		int sum = 0, T[L] = {0};
		for(d=1;d<=24;++d){
			if(d==13||d==17||d==19||d==23||d==1)
				sum+=*max_element(Q[d],Q[d]+d);
			else
				for(i=0;i<L;++i)T[i]+=Q[d][i%d];
		}
		cout << sum + *max_element(T,T+L) << endl;
	}
}

Measured memory_bytes: 1384
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		if(Math.abs(a-b) <= d && Math.abs(c-b) <= d ) {
			 System.out.println("Yes");
		}else if(Math.abs(a-c) <= d) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 21716
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(r: int):
    print(r*r*3)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    r = int(next(tokens))  # type: int
    solve(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
struct edge { int to, cost; };
bool operator<(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
int n, m, a1, a2, a3, a4, q;
int main() {
	while(cin >> m >> n, n | m) {
		vector<vector<edge> > G1(n), G2(n);
		for(int i = 0; i < m; i++) {
			cin >> a1 >> a2 >> a3 >> a4; a1--, a2--;
			G1[a1].push_back(edge{a2, a3});
			G1[a2].push_back(edge{a1, a3});
			G2[a1].push_back(edge{a2, a4});
			G2[a2].push_back(edge{a1, a4});
		}
		cin >> q;
		while(q--) {
			cin >> a1 >> a2 >> a3; a1--, a2--;
			if(a3 == 0) {
				priority_queue<edge> que; que.push(edge{a1, 0});
				vector<int> d(n, 999999999); d[a1] = 0;
				while(!que.empty()) {
					int u = que.top().to; que.pop();
					for(edge e: G1[u]) {
						if(d[e.to] > d[u] + e.cost) {
							d[e.to] = d[u] + e.cost;
							que.push(edge{e.to, -d[e.to]});
						}
					}
				}
				cout << d[a2] << endl;
			}
			else {
				priority_queue<edge> que; que.push(edge{a1, 0});
				vector<int> d(n, 999999999); d[a1] = 0;
				while(!que.empty()) {
					int u = que.top().to; que.pop();
					for(edge e: G2[u]) {
						if(d[e.to] > d[u] + e.cost) {
							d[e.to] = d[u] + e.cost;
							que.push(edge{e.to, -d[e.to]});
						}
					}
				}
				cout << d[a2] << endl;
			}
		}
	}
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <stdlib.h>
//UG02-50-10-011
int main()
{
    int i,a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    i=a+b+c;
    if(i>=22)
    {
        printf("bust");
    }
    else
    printf("win");
    return 0;
}


Measured memory_bytes: 128
//author-micheal corleone
//the godfather
#include <bits/stdc++.h>
#include <set> 
#include<algorithm>
#include <set> 
#include<algorithm>
#define ll long long int
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define out(n) printf("%lld\n",n)
#define inf 100000000000000
#define endl "\n"
#define precise(x) fixed << setprecision(x) 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
const int MOD =998244353;
#define f(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
 
using namespace std;

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[1] < v2[1]; 
}
 ll mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}
 //ll power(ll x, ll y) 
//{ 
  //  ll temp; 
    //if( y == 0) 
     //   return 1; 
    //temp = power(x, y/2); 
    //temp=temp%MOD;
    //if (y%2 == 0) 
     //   return (temp%MOD)*(temp%MOD); 
    //else
      //  return (x%MOD)*(temp%MOD)*(temp%MOD); 
//} 
 
 
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
    if(n==1 || r==0)return 1;
  //  ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=((((ans * n)%MOD )*modinv(i,MOD))%mod);n--;sum+=ans;sum%=mod;}return sum;
}
 //diamond[2000005],ans[1000006];
 const int maxn=2e5+100;
 

int main()
{
	ios_base::sync_with_stdio(0);
   cin.tie(0);
    cout.tie(0);
     ll t;
   //cin>>t;
   
   t=1;	
   while(t--)
    {
        ll i1,i2,k,j,j1,a1,i31,i3,j2,i5,i4,i6,i7,i,n,m;
        ll x,y,z;
        ll total=0,cnt=0;
        ll flag=0;
        y=0;
        ll res,res1,ans,res2,q;
        ans=0;
        res1=0,res=0;
        ll s1,s2,s3;
        s2=0;
        ll sum=0,flag1=0;
        s1=0;
        ll k1,k2,k3;
        k1=0,k2=0;
        ll d,required,days;
        //cin>>h>>c>>required;
        cin>>n;
        ll a[n+2][4];
        ll dp[n+2][4];
        
        for(i=1;i<=n;i++)
        {
        	cin>>a[i][1]>>a[i][2]>>a[i][3];
		}
		memset(dp,0,sizeof(dp));
		dp[1][1]=a[1][1];
		dp[1][2]=a[1][2];
		dp[1][3]=a[1][3];
		
	//	if(n==1) cout<<max(a[1][1],max(a[1][2],a[1][3]));
		for(i=2;i<=n;i++)
		{
			dp[i][1]=max(dp[i-1][2]+a[i][1],dp[i-1][3]+a[i][1]);
			dp[i][2]=max(dp[i-1][1]+a[i][2],dp[i-1][3]+a[i][2]);
			dp[i][3]=max(dp[i-1][1]+a[i][3],dp[i-1][2]+a[i][3]);
			
		}
		cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));
     }
    
}
	

Measured memory_bytes: 6528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        String s = in.next();
        char[] answer = new char[s.length()];
        Arrays.fill(answer, 'x');
        out.println(String.valueOf(answer));
    }
}


Measured memory_bytes: 20564
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF (1LL<<60)
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
#define MSB(x) (63-__builtin_clzll(x))
#define pcnt(x) (__builtin_popcountll(x))
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  cin >> n;

  FOR(i,1,n){
    if(i*100 >  n) break;
    int k = n - i*100;
    if(range(k,0,5*i+1)){
      cout << 1 << endl;
      return 0;;
    }
  }

  cout << 0 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N; i++) cin >> A[i];
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (i + 1 < A[i] && A[A[i] - 1] == i + 1) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3716
#include <iostream>
#include <string>

using namespace std;

string str;
string res;

int main()
{
	cin >> str;

	for (int i = -1; i <= 1; i += 2)
		for (int j = -1; j <= 1; j+= 2)
			for (int k = -1; k <= 1; k += 2)
			{
				int kq = (str[0] - '0') + i * (str[1] - '0') + j * (str[2] - '0') + k * (str[3] - '0');
				if (kq == 7)
				{
					res = str[0];
					
					if (i == -1)
						res = res + '-' + str[1];
					else
						res = res + '+' + str[1];

					if (j == -1)
						res = res + '-' + str[2];
					else
						res = res + '+' + str[2];

					if (k == -1)
						res = res + '-' + str[3];
					else
						res = res + '+' + str[3];

					res += "=7";

					break;
				}
			}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

void main() {
    int n, c;
    scan(n, c);
    auto d = new int[][](c, c);
    foreach (i ; 0 .. c) {
        d[i] = readln.split.to!(int[]);
    }
    auto cnt = new int[][](3, c);
    foreach (i ; 0 .. n) {
        auto line = readln.split.map!(x => x.to!int - 1).array;
        foreach (j, cij; line) {
            cnt[(i + j) % 3][cij]++;
        }
    }

    debug {
        writeln(cnt);
    }



    int ans = 10^^9 + 3;

    int check(int x, int y, int z) {
        int res;

        foreach (i ; 0 .. 3) {
            foreach (j ; 0 .. c) {
                if (i == 0) {
                    res += d[j][x] * cnt[i][j];
                }
                else if (i == 1) {
                    res += d[j][y] * cnt[i][j];
                }
                else {
                    res += d[j][z] * cnt[i][j];
                }
            }
        }

        debug {
            writefln("(x,y,z) = (%d, %d, %d)", x, y, z);
            writefln("iwa %d", res);
        }

        return res;
    }

    foreach (x ; 0 .. c) {
        foreach (y ; 0 .. c) {
            foreach (z ; 0 .. c) {
                if (x == y || y == z || x == z) {
                    continue;
                }
                ans = min(ans, check(x, y, z));
            }
        }
    }

    writeln(ans);
}










































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 3964
import sys

N = int(input())
S = input()
num = len(S)
ans, count = 0, 0
for i in range(1, num):
    a = set(S[:i])
    b = set(S[i:])
    for j in a:
        if j in b: count += 1
    ans = max(ans, count)
    count = 0
    
print(ans)


Measured memory_bytes: 9180
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;

const int maxn = 402;
const int mo = 1e9 + 7;

int n, a[maxn];
long long f[maxn][maxn], sum[maxn];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		sum[i] = sum[i-1] + a[i];

		if (i > 1)
			f[i-1][i] = sum[i] - sum[i-2];
	}

	for (int len = 3; len <= n; ++len) {
		for (int i = 1; i <= n+1-len; ++i) {
			int j = i + len - 1;

			f[i][j] = min(f[i+1][j], f[i][j-1]);

			for (int k = i+1; k < j-1; ++k)
				f[i][j] = min(f[i][j], f[i][k] + f[k+1][j]);

			f[i][j] += sum[j] - sum[i-1];
		}
	}

	cout << f[1][n] << endl;

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  bool ans=true;
  rep(i,s.size()){
    if(i%2==1&&s[i]=='R') ans=false;
    else if(i%2==0&&s[i]=='L') ans=false;
    if(!ans)break;
  }
  ans ? cout << "Yes" : cout << "No" ;
  cout << endl;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a1 = new int[n];
		for (int i = 0; i < n; ++i)
			a1[i] = scan.nextInt();
		//System.out.println(Arrays.toString(a1));
		//System.out.println(Arrays.binarySearch(a1, 1));
		int q = scan.nextInt();
		int t;
		int sum = 0;
		for (int i = 0; i < q; ++i) {
			t = scan.nextInt();
			if (Arrays.binarySearch(a1, t) >= 0) {//如果找不到则返回应该插入位置的负数值（逻辑索引，实际-1）
				//System.out.println("t:" + t);
				//System.out.println(Arrays.binarySearch(a1, t));
				sum++;
			}
		}
		System.out.println(sum);
		
//		int[] a2 = new int[10];
//		for (int i = 0; i < a2.length; i++) {
//			a2[a2.length - 1 - i] = i;
//		}
//		System.out.println(Arrays.binarySearch(a2, 4));
	}
}



Measured memory_bytes: 81676
#include <bits/stdc++.h>
using namespace std;
int main() {
    
	int n;
	cin>>n;
	int ac=0,wa=0,tle=0,re=0;
	for(int i=1;i<=n;i++)
	{
	  string s;
	     cin>>s;
	     if(s=="AC")
	      ac++;
	     else if(s=="WA")
	     wa++;
	      else if(s=="TLE")
	      tle++;
	      else 
	      re++;
	}
	
	cout<<"AC x"<<" "<<ac<<endl;
	cout<<"WA x"<<" "<<wa<<endl;
	cout<<"TLE x"<<" "<<tle<<endl;
	cout<<"RE x"<<" "<<re<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

ll A, B, Q;

int main(){
    cin >> A >> B >> Q;
    vector<ll> s(A), t(B);
    for (int i = 0; i < A; i++) cin >> s[i];
    for (int i = 0; i < B; i++) cin >> t[i];
    for (int i = 0; i < Q; i++){
        ll x;
        cin >> x;
        auto s_ind = distance(s.begin(), lower_bound(s.begin(), s.end(), x));
        auto t_ind = distance(t.begin(), lower_bound(t.begin(), t.end(), x));
        vector<ll> a;
        if (s_ind != A && t_ind != B) a.push_back(max(s[s_ind], t[t_ind]) - x);
        if (s_ind != A && t_ind != 0){
            a.push_back(abs(s[s_ind] - x) + 2 * abs(t[t_ind - 1] - x));
            a.push_back(2 * abs(s[s_ind] - x) + abs(t[t_ind - 1] - x));
        }
        if (s_ind != 0 && t_ind != B){
            a.push_back(abs(s[s_ind - 1] - x) + 2 * abs(t[t_ind] - x));
            a.push_back(2 * abs(s[s_ind - 1] - x) + abs(t[t_ind] - x));
        }
        if (s_ind != 0 && t_ind != 0) a.push_back(x - min(s[s_ind - 1], t[t_ind - 1]));
        sort(a.begin(), a.end());
        cout << a[0] << endl;
    }
}

Measured memory_bytes: 2944
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

bool check(string s, int l, int r) {
    while(l < r) {
        if(s[l] != s[r]) {
            return false;
        }
        l++;
        r--;
    }

    return true;
}

int main() {
    string s;
    cin >> s;
    int N = s.size();

    bool b0 = check(s, 0, N - 1);
    bool b1 = check(s, 0, (N - 1) / 2 - 1);
    bool b2 = check(s, (N + 3) / 2 - 1, N - 1);

    if(b0 && b1 && b2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    string S, T; cin >> S >> T;
    i64 N = S.length();
    i64 M = T.length();

    sort(S.begin(), S.end());
    sort(T.rbegin(), T.rend());
    if (S < T) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3568
N = int(input())
W = list(map(int, input().split()))

x = sum(W) // 2
s = 0
for w in W:
    s += w
    if x <= s:
        a = abs(sum(W) - 2 * s)
        s -= w
        b = abs(sum(W) - 2 * s)
        print(a if a < b else b)
        break


Measured memory_bytes: 3060
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stdio.h>

using namespace std;
int main()
{
    int n,k,s;
    cin>>n>>k>>s;
    for(int i=1; i<=k; i++)
    {
        if(i!=n)
            cout<<s<<" ";
        else
            cout<<s;
    }
    for(int i=k+1; i<=n; i++)
    {
        if(i!=n&&s!=1000000000)
            cout<<s+1<<" ";
        else if(i!=n&&s==1000000000)
            cout<<1<<" ";
        else if(i==n&&s!=1000000000)
            cout<<s+1;
        else if(i==n&&s==1000000000)
            cout<<1;
        }

}




Measured memory_bytes: 1280
#include<cstdio>
#include<algorithm>
main(){
int n;
while(scanf("%d",&n),n){
int m=0,v[4][2]={{0,1},{1,0},{-1,1},{1,1}},a[257][257]={{0}};
for(int y=n;y;y--)for(int x=n;x;x--)scanf("%1d",&a[x][y]);
for(int i=0;i<4;i++){
int d[257][257]={{0}};
for(int k=n;k;k--)for(int j=n;j;j--)m=std::max(m,d[j][k]=a[j][k]?a[j][k]+d[j+v[i][0]][k+v[i][1]]:0);}
printf("%d\n",m);
}
}

Measured memory_bytes: 1288
fun main(args : Array<String>) {
  print(readLine()!!.split("").let {
    if (it[1] == "A"
      && it.subList(3, it.size - 2).count { it == "C" } == 1
      && it.count { it == it.toUpperCase() } == 4)
      "AC" else "WA"
  })
}

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

int main() {
  int A, B, R;
  cin >> A >> B;
  R=(B-1)%(A-1);
  if (R==0) {
    cout << (B-1)/(A-1) << endl;
  }
  else {
    cout << (B-1-R)/(A-1)+1 << endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=1000000007;
ll MOD=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    int v,E;
    cin >> v >> E;
    vector<vector<pp>> e(v+1,vector<pp>(0));
    rep(i,E){
        int f,g,h;
        cin >> f >> g >> h;
        e[f].push_back(mk(g,h));
        e[g].push_back(mk(f,h));
    } 
    rep(i,v) {
        int f;
        cin >> f;
    }
    int t;
    cin >> t;
    rep(i,120){
        cout << -1 << endl;
        t--;
        if (t==0) return 0;
    }
    queue<int> q;
    q.push(1);
    while(true){
        int f=q.front();
        int u=rand()%e[f].size();
        q.pop();
        q.push(e[f][u].first);
        rep(i,e[f][u].second){
            cout << e[f][u].first << endl;
            t--;
            if (t==0) return 0;
        }
    }
}


Measured memory_bytes: 1240
#include<stdio.h>
 
int judge(int num)
{
  int i;
  
  if(num == 2) return 1;
  if(num % 2 == 0 || num == 1) return 0;
  for(i=3; i * i <= num; i = i+2)
  {
    if(num % i == 0) return 0;
  }
  return 1;
}
 
int main(void)
{
  int a, i,n,count=0;

  scanf("%d",&n);
  for (i=0; i<n; i++)
  {
    scanf("%d",&a);
    if(judge(a) == 1) count++;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
     cin>>n;

       long long int num=0;

        for(int i=1;i<=n;i++)
        {
           if(i % 3!=0 && i % 5!=0)
             num+=i;
        }
       cout<<num;
}


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

using namespace std;

#define REP(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";

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

typedef long double ld;


int main() {

	string S, XS;
	cin >> S;

	V<int> XSi;

	REP(i, S.size()) if (S[i] != 'x') {
		XS.push_back(S[i]);
		XSi.push_back(i);
	}

	string rev = XS;
	reverse(rev.begin(), rev.end());
	if (rev != XS) {
		cout << -1 << endl;
		return 0;
	}

	int l, r;

	if (XS.size() == 0) {
		cout << 0 << endl;
		return 0;
	} else if (XS.size()%2) {
		l = r = XSi[XS.size()/2];
	} else {
		l = XSi[XS.size()/2-1];
		r = XSi[XS.size()/2];
	}


	int ans = 0;

	while (l >= 0 || r < S.size()) {
		char lc = l < 0 ? '@' : S[l];
		char rc = r >= S.size() ? '@' : S[r];
		if (lc == rc) {
			--l;
			++r;
		} else {
			++ans;
			if (lc == 'x') {
				--l;
			} else {
				++r;
			}
		}
	}

	cout << ans << endl;
	
}

Measured memory_bytes: 1148