akhauriyash/Code-Regression huggingface dataset:
//
// Created by Pulak on 29-11-2019.
//
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
vector <int> a;
int dp[3005][3005][2];
int play(int left, int right, int player){
    if(left > right) return 0;
    if(left == right){
        if(player == 0) return a[left];
        else return 0;
    }
    if(dp[left][right][player] != -1) return dp[left][right][player];
    
    if(player == 0)
        return dp[left][right][player] = max(a[left] + play(left + 1, right, 1 - player), a[right] + play(left, right - 1, 1 - player));
    return dp[left][right][player] = min(play(left + 1, right, 1 - player), play(left, right - 1, 1 - player));
}



signed main(){
    
    cin >> n;
    a.resize(n);
    int sum = 0;
    memset(dp, - 1, sizeof(dp));
    for(int i = 0; i <  n ; i++) {cin >> a[i];
        sum += a[i];
    }
    cout << 2 * play(0 , n - 1, 0) - sum<< endl;
    
}

Measured memory_bytes: 141568
/*
 * 2345.cc: Network Reliability
 */

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

/* constant */

const int MAX_N = 14;
const int NBITS = 1 << MAX_N;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii es[MAX_N];
double dp[NBITS];

/* subroutines */

/* main */

int main() {
  int n, m;
  double p;
  cin >> n >> m >> p;

  int nbits = 1 << n;
  p /= 100;
  memset(es, false, sizeof(es));

  for (int i = 0; i < m; i++) {
    cin >> es[i].first >> es[i].second;
    es[i].first--, es[i].second--;
  }

  for (int bits = 0; bits < nbits; bits++) dp[bits] = 0.0;
  
  for (int bits = 1; bits < nbits; bits++) {
    int b0 = 1;
    for (; ! (bits & b0); b0 <<= 1);
    dp[bits] = 1.0;
    
    for (int s0 = (bits - 1) & bits; s0 != 0; s0 = (s0 - 1) & bits)
      if (s0 & b0) {
	int s1 = bits & ~s0;
	double pp = dp[s0];
	for (int j = 0; j < m; j++) {
	  int &u = es[j].first, &v = es[j].second;
	  int bu = 1 << u, bv = 1 << v;
	  if ((bits & bu) && (bits & bv) &&
	      (((s0 & bu) && ! (s0 & bv)) || ((! (s0 & bu) && (s0 & bv)))))
	    pp *= p;
	}
	dp[bits] -= pp;
      }
  }

  printf("%.12lf\n", dp[nbits - 1]);
  return 0;
}

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

int main(){
	string o,e;
	string ans="";
	cin>> o>> e;
	
	for(int i=0; i<o.size();i++){
		ans+= o.at(i);	
		if(i<e.size()) ans+= e.at(i);
	}
	
	cout<< ans<<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 in=new Scanner(System.in);
		for(;;)
		{
			int w=in.nextInt(),d=in.nextInt();
			if((w|d)==0)
				return;
			int front[]=new int[w];
			int side[]=new int[d];
			int cnt=0;
			for(int i=0;i<w;i++)
				front[i]=in.nextInt();
			for(int i=0;i<d;i++)
				side[i]=in.nextInt();

			for(int i=0;i<w;i++)
				for(int j=0;j<d;j++)
				{
					if(front[i]==side[j])
					{
						side[j]=0;
						break;
					}
				}
			for(int i=0;i<w;i++)
				cnt+=front[i];
			for(int i=0;i<d;i++)
				cnt+=side[i];
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 23260
#include <stdio.h> 

int main(void)
{
	int a;
	int b;
	int c;
	int x;
	int y=0;
	int z;

	scanf("%d %d %d", &a, &b, &c);

	for(x=a ;x<=b ;x++)
	{

		z=c%x;

		if (z==0)
		{
			y=y+1;
		}

	}

	printf("%d\n", y);

	return 0;


}

Measured memory_bytes: 596
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        for(int i = 0; i < 300; i++) {
          String line = sc.nextLine();
          String[] l = line.split(" ");
          int H = Integer.parseInt(l[0]);
          int W = Integer.parseInt(l[1]);
          if(H == 0 && W == 0) {
            break;
          }

          for(int h = 0; h < H; h++) {
            for(int w = 0; w < W; w++) {
              System.out.print("#");
            }
            System.out.println();
          }
          System.out.println();
        }
    }
}

Measured memory_bytes: 34892
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin>>a>>b;
    if(a<b)
    cout<<"a < b"<<endl;
    else if(a>b)
    cout<<"a > b"<<endl;
    else
    cout<<"a == b"<<endl;
   }



Measured memory_bytes: 3092
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;

char a[10];
int main()
{
	scanf("%s",a);
	if((a[0] == a[1] && a[1] == a[2]) || (a[1] == a[2] && a[2] == a[3]))
		puts("Yes\n");
		else	puts("No\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
      ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
      string s, t;
      cin >> s >> t;
      if (t.size()<s.size())
      {
            cout << "No" << endl;
            return 0;
      }
      int flag=1;
      for (int i=0; i<s.size(); i++)
      {
            if (s[i]!=t[i])
            {
                  flag=0;
                  break;
            }
      }
      if (flag==1)
      {
            cout << "Yes" << endl;
      }
      else cout<< "No" << endl;
      return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
#include <cstdio>
#include <iomanip>
#include <list>
#include <set>

#define ULL unsigned long long
using namespace std;


ULL getMaxP(ULL s, ULL t) { // s >= t
	if (s%t == 0) {
		return t;
	}
	else {
		return getMaxP(t, s%t);
	}
}

bool check(ULL a, ULL b, ULL c, ULL  d) {
	long long first_a;
	if (a > c) {
		long long buf = (a - c) % b;
		first_a = c - (b - buf)%b;
	}
	else {
		first_a = a;
	}

	if (first_a < 0) {
		return false;
	}
	
	auto f = d % b;
	if (f == 0) {
		return true;
	}

	auto g = getMaxP(b, f);
	return (first_a + ((c - first_a) / g + 1)*g) >= b;
}

int main(void) {
	int T;
	ULL a, b, c, d;
	a = 100000;
	scanf("%d", &T);
	for (int i = 0; i < T; i++) {
		scanf("%lld %lld %lld %lld", &a, &b, &c, &d);

		if (a >= b && d >= b) {
			if (c >= b-1) {
				printf("Yes\n");
			}
			else {
				if (check(a, b, c, d)) {
					printf("Yes\n");
				}
				else {
					printf("No\n");
				}
			}
		}
		else {
			printf("No\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

void dijkstra(){
int minv;
int d[MAX],color[MAX];

for(int i=0;i<n;i++){
d[i] = INFTY;
color[i] = WHITE;
}

color[0] = GRAY;
d[0] = 0;

while(1){
minv = INFTY;
int u = -1;
for(int i=0;i<n;i++){
if(minv>d[i]&&color[i]!=BLACK){
u = i;
minv = d[i];
}
}
if(u==-1)break;
color[u] = BLACK;

for(int v=0;v<n;v++){
if(color[v]!=BLACK&&M[u][v]!=INFTY){
if(d[v]>d[u]+M[u][v]){
d[v] = d[u] + M[u][v];
color[v] = GRAY;
}
}
}
}
for(int i=0;i<n;i++){
cout<<i<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
}
}

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



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k];
    }
}; //comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

int main() {
    // 包除原理？、sort
    // 0000の１通りを調べて、最後に2^N倍
    // 1の個数
    int N;
    cin >> N;
    vector<int> C(N);
    rep(i, N) cin >> C[i];
    sort(C.begin(), C.end());

    mint ans = 0;
    mint own = mint(2).pow(N-1); // 自分自身の個数
    rep(i, N) {
        mint remain = (mint)(N - i - 1);
        ans += (own + (own / 2) * remain) * C[i];
    }
    ans *= mint(2).pow(N);
    cout << ans << '\n';
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}

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

int main(){
    int N, MA, MB;
    cin >> N >> MA >> MB;
    int inf = 9999999;
    vector<vector<int>> dp(401, vector<int>(401, inf));
    dp[0][0] = 0;
    for (int i = 0; i < N; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        for (int j = 400; j >= a; j--) {
            for (int k = 400; k >= b; k--) {
                dp[j][k] = min(dp[j][k], dp[j-a][k-b]+c);
            }
        }
    }
    int ans = inf;
    for (int i = 1; max(i*MA, i*MB) <= 400; i++) {
        ans = min(ans, dp[i*MA][i*MB]);
    }
    if (ans < inf) cout << ans << endl;
    else cout << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 896
#include <cstdio>
using namespace std;
 
int main(){
	long int a, b, n;
  
  	scanf("%ld%ld", &a, &b);
  	if(a == 1 || b == 1){
  	    n = 1;
  	}
  	else if(a%2 != 0 && b%2!=0){
    	n = (a*b)/2 +1;
    }
  	else{
    	n = (a*b)/2;
    }
  	printf("%ld", n);
 	
 
}

Measured memory_bytes: 128
# 9
# 英小文字からなる文字列が与えられ、空文字にdream dreamer erase eraser のいずれかを追加することでその文字列が生成できるかを判定する。
a = str(input())
tmp = ''
for i in range(len(a)):
    tmp = a[len(a)-1] + tmp
    a = a[:-1]
    if tmp == 'dream' or tmp == 'dreamer' or tmp == 'erase' or tmp == 'eraser':
        tmp = ''

if tmp == '':
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

void FFT(vector<complex<double>> &A,int sign){
	int n = A.size();

	double PI = 3.14159265358979323;
	

	vector<complex<double>> tmp(n);
	int mask = n-1;
	
	for(int i=n>>1;i>=1;i>>=1){
		double dir = 2.0*PI*i*sign/n;

		complex<double> w(cos(dir),sin(dir));
		
		complex<double> now = 1.0;
	
		for(int j=0;j<n;j+=i){
			for(int k=0;k<i;k++){
				tmp[j+k] = A[((j<<1)&mask)|k] + now*A[(((j << 1)|i)&mask)|k];
			}
			now *= w;
		}
		swap(A,tmp);
	}

	int num;
	for(int i=0;true;i++){
		if((n>>i)&1){
			num = i;
			break;
		}
	}

	if(num&1){
		swap(A,tmp);
		for(int i=0;i<n;i++)A[i] = tmp[i];
	}
	
	return;
}

vector<long long> do_FFT(vector<long long> &A,vector<long long> &B){
	
	int n = A.size()+B.size()-1;
	
	if(min(A.size(),B.size())<=150){
		vector<long long> ret(n,0);
		for(int i=0;i<A.size();i++){
			for(int j=0;j<B.size();j++){
				ret[i+j] = mod(ret[i+j] + mod(A[i]*B[j]));
			}
		}
		return ret;
	}
	
	for(int i=0;true;i++){
		if((1<<i)>=n){
			n = (1<<i);
			break;
		}
	}
	
	vector<complex<double>> a(n,complex<double>(0.0,0.0)),b(n,complex<double>(0.0,0.0));
	
	for(int i=0;i<A.size();i++)a[i].real(A[i]);
	for(int i=0;i<B.size();i++)b[i].real(B[i]);
	
	FFT(a,1);
	if(A==B)b=a;
	else FFT(b,1);
	
	vector<complex<double>> c(n);
	for(int i=0;i<n;i++)c[i] = a[i]*b[i];
	
	FFT(c,-1);
	
	vector<long long> C(n);
	for(int i=0;i<n;i++){
		C[i] = round(c[i].real()/n);
	}
	
	return C;
	
}

int main(){
	
	long long N,M;
	cin>>N>>M;
	
	vector<long long> A(100005,0);
	
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A[a] ++;
	}
	
	vector<long long> B = A;
	
	vector<long long> C = do_FFT(A,B);
	
	long long ans = 0;
	
	for(int i=C.size()-1;i>=0;i--){
		ans += (long long)i*min(M,C[i]);
		M -= C[i];
		if(M<0)break;
	}
	
	cout<<ans<<endl;
	
    return 0;
}


Measured memory_bytes: 18556
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
int main(){
    double PI = M_PI;
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double rada, radb, shita;
    rada = ((h/12) + (m/(12*60))) * 2* PI;
    radb = (m/60) * 2 * PI;
    if(rada >= radb){
        shita = rada - radb;
        if(shita >= PI){
            shita = 2*PI - shita;
        }
        //if(shita<= PI - 0.001){
        //    cout << max(a, b) * cos(shita);
        //}else{
            cout << setprecision(16) <<  sqrt(a*a + b*b - 2 * a*b*cos(shita));
        //}

    }else{
        shita = radb - rada;
        if(shita >= PI){
            shita = 2*PI - shita;
        }
        //if(shita != PI){
      //      cout << max(a, b) * cos(shita);
    //    }else{
            cout << setprecision(16)<<sqrt(a*a + b*b - 2*a*b*cos(shita));
      ///  }
    }
    cout << endl;
    //cout << shita;
}

Measured memory_bytes: 4216
# Cosmic rays
import math
import heapq

xs, ys, xt, yt = map(int, input().split())
N = int(input())

d = [((xs, ys), 0, 0)]
# node,radius

for _ in range(N):
    x, y, r = map(int, input().split())
    d.append(((x, y), _+1, r))

graph = {i: [] for i in range(N+2)}

d.append(((xt, yt), N+1, 0))
for i in range(N+2):
    for j in range(i+1, N+2):
        p, point, rad = d[i]
        q, point2, rad2 = d[j]
        D = math.hypot(p[0]-q[0], p[1]-q[1])
        if D > (rad+rad2):
            graph[i].append((D-rad-rad2, j))
            graph[j].append((D-rad-rad2, i))
        else:
            graph[i].append((0, j))
            graph[j].append((0, i))


def dijkstra(s, graph):
    n = len(graph)
    dist = [float("inf") for i in range(n+1)]
    dist[s] = 0
    pq = []
    heapq.heapify(pq)
    heapq.heappush(pq, (0, s))
    while pq:
        mini_dis, node = heapq.heappop(pq)
        if dist[node] < mini_dis:
            continue
        for w, point in graph[node]:
            if dist[point] < w:
                continue
            newlen = dist[node]+w
            if newlen < dist[point]:
                heapq.heappush(pq, (newlen, point))
                dist[point] = newlen
    return dist

K=dijkstra(0,graph)[N+1]
print(K)


Measured memory_bytes: 174332
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pr(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
#define BLACK 0
#define WHITE 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


int main(void) {
    string s;
    cin >> s;
    ll ans=0;
    
    string t=s;
    
    while(s.size()) {
        if(s[0]==s[s.size()-1])
            s=s.substr(1, s.size()-2);
        else {
            if(s[0]=='x') {
                ans++;
                s=s.substr(1, s.size()-1);
            }else if(s[s.size()-1]=='x') {
                ans++;
                s=s.substr(0, s.size()-1);
            }else {
                puts("-1");
                return 0;
            }
        }
    }
    
    pr(ans);
    
    
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		int n = sc.nextInt();
		int result = 0;

		if (n % 2 == 0) {
			result = n / 2 - 1;
		} else {
			result = (n - 1) / 2;
		}

		System.out.println(result);
	}

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using Graph = vector<vector<int>>;


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

    cout << T << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define repr(i,a,n) for (int i=a;i<n;i++)
#define rrep(i,a,n) for (int i=n-1;i>=a;i--)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define fi first
#define se second
#define mod 1000000007
const int N = 2e5 + 5;
#define PI acos(-1.0)
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
#define pqll_max priority_queue<ll> // max heap. push(),pop(),top(),size(),empty()
#define pqll_min priority_queue<ll,vector<ll>,greater<ll> >
#define lb(v,val)   lower_bound(v.begin(),v.end(),val) //first equal to or lower than [------------
#define ub(v,val)   upper_bound(v.begin(),v.end(),val) //first greater than ------------)
#define bs(v,x) binary_search(v.begin(),v.end(),x)
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(ll a, ll b) { if (a < b)swap(a, b); return (((a%mod) - (b%mod) + mod) % mod); }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;

void solve() {

	int n;
	cin >> n;
	string s;
	cin >> s;
	map<char, vector<int>> m;
	rep(i, n) {
		m[s[i]].PB(i);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (s[i] != s[j]) {
				if (s[i] != 'R' && s[j] != 'R') {
					ans += m['R'].size() - (lb(m['R'], j) - m['R'].begin());
					if (bs(m['R'], j + j - i)) {
						ans--;
					}
				}
				else if (s[i] != 'G' && s[j] != 'G') {
					ans += m['G'].size() - (lb(m['G'], j) - m['G'].begin());
					if (bs(m['G'], j + j - i)) {
						ans--;
					}
				}
				else if (s[i] != 'B' && s[j] != 'B') {
					ans += m['B'].size() - (lb(m['B'], j) - m['B'].begin());
					if (bs(m['B'], j + j - i)) {
						ans--;
					}
				}
			}
		}
}
	cout << ans << endl;

}

signed main()
{
	int tc;
	tc = 1;
	//	cin >> tc;
	while (tc--) {
		solve();
	}


}

Measured memory_bytes: 3696
N = int(input())
d = {}
for i in range(N):
    s = input()
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1

maxw = max(d.values())

ans = [k for k, v in d.items() if v == maxw]
ans.sort()
for i in ans:
    print(i)


Measured memory_bytes: 32092
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;

int main()
{
  int n = 0, i;
  double p[4], squaring, gap, sum3;

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

  cin >> n;

  //in

  int x[n], y[n];
  for(i = 0; i < n; i++)
  {
    cin >> x[i];
  }
  for(i = 0; i < n; i++)
  {
    cin >> y[i];
  }

  //calculate_1

  for(i = 0; i < n; i++)
  {
    squaring = (x[i] - y[i]) * (x[i] - y[i]);
    gap = sqrt( squaring );
      
    p[0] += gap;

  //calculate_2

    p[1] += squaring;

  //calculate_3
    
    sum3 += sqrt( squaring * squaring * squaring );

  //calculate_4

    if(p[3] < gap)
    {
      p[3] = gap;
    }
  }
    
  p[1] = sqrt( p[1] );
  p[2] = pow(sum3, 1.0 / 3.0);

  //out

  for(i = 0; i < 4; i++)
  {
    printf("%f\n", p[i]);
  }

  return 0;
}


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

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple

#define N 311111
#define A 1111111
#define BLOCK 555 // ~sqrt(N)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int INF = 1e9 +5;
const int nax = 1e5 +5;
const long M = 1000000007;
double p[305][305][305];
double ev[305][305][305];
int arr[4];
// int visited[nax];
// int in_degree[nax];
// vector<int> edges[nax];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout<<fixed;
	cout<<setprecision(10);
	int t;
	// cin>>t;
	t = 1;
	while(t--){
		int n;
		cin>>n;
		for(int i=0;i<n;i++){
			int x;
			cin>>x;
			arr[x]++;
		}
		// cout<<arr[1]<<arr[2]<<arr[3]<<endl;
		p[arr[1]][arr[2]][arr[3]] = 1;

		for(int c = n;c>=0;--c){
			for (int b = n; b >= 0; --b){			
				for (int a = n; a >= 0; --a){				
					if((a ==0 && b==0 && c==0) || (a+b+c > n)){
						continue;
					}
					double p_waste = (double) (n - (a+b+c))/n ;
					ev[a][b][c] += (1/(1-p_waste))*p[a][b][c];
					if(a!=0){
						double l = (double) a/(a+b+c);
						p[a-1][b][c] += p[a][b][c] * l;
						ev[a-1][b][c] += ev[a][b][c]*l;
					}
					if(b!=0){
						double l = (double) b/(a+b+c);
						p[a+1][b-1][c] += p[a][b][c] * l;
						ev[a+1][b-1][c] += ev[a][b][c]*l;
					}
					if(c!=0){
						double l = (double) c/(a+b+c);
						p[a][b+1][c-1] += p[a][b][c] * l;
						ev[a][b+1][c-1] += ev[a][b][c]*l;
					}
				}
			}
		}

		cout<<ev[0][0][0]<<endl;
	}
}

Measured memory_bytes: 438528
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

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

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

func main() {
	n := nextInt()
	s := map[string]int{}

	c := 0
	for i := 0; i < n; i++ {
		ss := next()
		s[ss]++

		if c < s[ss] {
			c = s[ss]
		}
	}

	var res []string
	for k, v := range s {
		if v == c {
			res = append(res, k)
		}
	}

	sort.Strings(res)
	for i := 0; i < len(res); i++ {
		fmt.Println(res[i])
	}
}


Measured memory_bytes: 31488
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College

'''
from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')



def solve():
    
    # for _ in range(ii()):

        


        
        x,k,d= mi()
        x = abs(x)
        c = x//d
        if c>=k:
            print(x-k*d)
            exit(0)
        k -= c
        c1 = x%d
        c2 = c1-d
        if k&1:
            print(abs(c2))
        else:
            print(abs(c1))
    # print(c1,c2,k) 



















        
if __name__ =="__main__":

    if path.exists('input.txt'):
        sys.stdin=open('input.txt', 'r')
        sys.stdout=open('output.txt','w')
    else:
        input=sys.stdin.readline
    solve()


Measured memory_bytes: 68352
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    long long mod=1e9+7;
    //cout<<mod<<endl;
    cin>>n>>m;
    vector<bool> forbidden(n+1,false);
    for(int i=0;i<m;i++){
        int a;
        cin>>a;
        forbidden[a]=true;
    }
    vector<long long int> sum(n+1,0);
    sum[0]=1;
    for(int now=0;now<n;now++){
        for(int next=now+1;next<=min(n,now+2);next++){
            if(forbidden[next])continue;
            sum[next]+=sum[now];
            sum[next]%=mod;
        }
    }
    cout<<sum[n]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

bool func(pair<ll,ll> a, pair<ll,ll> b){
    return a.second < b.second;
}

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

    ll N ;
    vector<pair<ll,ll> > ab;
    cin >> N ;
    rep(i ,N){
        ll A, B ;
        cin >> A >> B ;
        ab.pb(mp(A,B));
    }
    sort(all(ab), func);

    ll now = 0;
    rep(i, N){
        ll span = ab[i].first;
        ll till = ab[i].second;

        now += span;
        if(now > till){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 6384
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    string text;
    int q;

    cin >> text;
    cin >> q;

    string order;
    int a, b;
    string p;
    
    for (int i = 0; i < q;i++) {
        string sub, sub1, sub4;

        cin >> order >> a >> b;

        if (order == "print"){
            sub=text.substr(a,b-a+1);
            cout << sub << endl;
        }
        if (order=="reverse") {

            sub1 = text.substr(a, b - a+1);
                reverse(sub1.begin(), sub1.end());
                
                text = text.replace(a, sub1.size(), sub1);
                
        }
        if (order == "replace") {
            cin >> p;
            sub4 = text.replace(a, p.size(), p);
            text = sub4;
            
        }


    }


    return 0;
}


Measured memory_bytes: 3168
import sys
from collections import Counter
from itertools import combinations


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()

S = []
ans = 0

for i in range(n):
    s = input()[0]
    if s in ["M","A","R","C","H"]:
        S.append(s)

C = Counter(S)

for w in combinations(["M","A","R","C","H"],3):
    ans += C[w[0]]*C[w[1]]*C[w[2]]

print(ans)

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

const long long MOD = 1e9 + 7;


#define INPUT(x)                freopen(x,"r",stdin)
#define OUTPUT(x)               freopen (x,"w",stdout)


#define pb                      push_back
#define endl                    '\n'
#define LCM(a,b)                (a/__gcd(a,b))*b
#define GCD(a,b)                __gcd(a,b)
#define SP(x,y)                 fixed<<setprecision((y))<<(x)
#define PI                      acos(-1.0)
#define distance(x1,y1,x2,y2)   sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define MAX                     1e9 + 9

#define taratari                ios_base::sync_with_stdio(0);cin.tie(NULL);


int main()
{
    taratari

    int n;
    cin>>n;

    vector <int> a;
    vector <int> b;

    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;

        a.pb(x);
        b.pb(x);
    }

    sort(a.begin(),a.end());

    int c=0;

    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
        {
            c++;
        }
    }

    if(c==2 || c==0)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }



    return 0;

}



Measured memory_bytes: 3608
#include <stdio.h>

char s[11];
typedef long long ll;
ll res = 0;
int p[11], sz=0;

void solve(int a, ll b, ll c) {
  //printf("%d %lld %lld\n", a, b, c);
  if (!s[a]) {
    res += b+c;
    return;
  }

  solve(a+1, b+c, s[a]-'0');
  solve(a+1, b, (s[a]-'0')+c*10);
}

int main(void) {
  scanf("%s", s);

  solve(0, 0, 0);

  printf("%lld\n", res/2);

  return 0;
}


Measured memory_bytes: 128
using System.Numerics;
using System;

public class Hello
{
    public static int MOD = 1000000007;
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, long.Parse);
        var asum = 0L;
        var a2sum = 0L;
        for (int i = 0; i < n; i++)
        {
            asum += a[i];
            asum %= MOD;
            a2sum += a[i] * a[i];
            a2sum %= MOD;
        }
        var ans = asum * asum;
        ans %= MOD;
        ans -= a2sum;
        if (ans < 0) ans += MOD;
        ans %= MOD;
        var tt = ModInverse(2, MOD);
        ans *= (long)tt;
        ans %= MOD;
        Console.WriteLine(ans);
    }
    public static BigInteger ModInverse(BigInteger a, BigInteger m)
    {
        return BigInteger.ModPow(a, m - 2, m);
    }
}


Measured memory_bytes: 46872
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()
A = i_l()

h = {}

for i in range(len(A)):
    h[i] = 0


for x in A:
    h[x-1] += 1

for x in h.values():
    print(x)

print(0)

Measured memory_bytes: 40176
#include<iostream>
#include <vector>

using namespace std;

int main()
{
	int N;
	int ans = 0;
	int ansss = 1;

  cin >> N;

  for(int n = 2; n <= N; n++){  
  	vector<int> x(n + 1);
	  int num = n; // 素因数分解する変数num 

  	for (int i = 2; i <= n; i++) {
	  	while (num%i == 0) { // 素数で割り切れなくなるまで割っていく
		  	x.at(i)++; //割った個数を配列に足す
			  num /= i;
  		}
	  }
	  for (int i = 2; i <= n; i++){ 	
	  	ansss *= x.at(i) + 1; //それぞれを+1して掛けていく
	  }
    if(n % 2 == 1 && ansss == 8){
      ans++;
    }
    ansss = 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
void output(int* list,int listnum,int num,int max);
 
int main(void) {
    int list[30];
    int n;
    while(1) {
        scanf("%d",&n);
        if(n==0)break;
        output(list,0,n,n);
    }
    return 0;
}

void output(int* list,int listnum,int num,int max) {
    int i;
    if(num<=0) {
        printf("%d",list[0]);
        for(i=1;i<listnum;i++) {
            printf(" %d",list[i]);
        }
        puts("");
    } else {
        for(i=(max>num?num:max);i>0;i--) {
            list[listnum]=i;
            output(list,listnum+1,num-i,i);
        }
    }
}

Measured memory_bytes: 1040
# ビット全探索
from itertools import product

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

result = -float('inf')
for i in product([True, False], repeat=10):
    if i.count(False) == 10:
        continue
    t = 0
    for j in range(N):
        t += P[j][sum(1 & F[j][k] for k in range(10) if i[k])]
    result = max(result, t)
print(result)


Measured memory_bytes: 9224
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using namespace std;

long rui[200010]={0};
bool visited[200010]={0};
vector<int> G[200010];

void dfs(int i=0, long val=0) {
    cerr << i << endl;
    visited[i] = true;
    rui[i] += val;
    for (auto g:G[i]) {
        if (visited[g]) continue;
        dfs(g, rui[i]);
    }
    return;
}

int main() {
    int n, q;
    cin >> n >> q;
    for (int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i=0; i<q; i++) {
        long p, x;
        cin >> p >> x;
        rui[p-1] += x;
    }
    dfs();
    for (int i=0; i<n; i++)
        cout << rui[i] << (i < n-1 ? ' ' : '\n');
    return 0;
}


Measured memory_bytes: 24448
n, eat = map(int, input().split())

pattiesCount = lambda level: (1 << (level + 1)) - 1
bunsCount = lambda level: (1 << (level + 1)) - 2
bothCount = lambda level: (1 << (level + 2)) - 3

# for i in range(51):
#     if pattiesCount(i) != p[i]:
#         raise Exception()
#     print(i, '->', pattiesCount(i), bunsCount(i), bothCount(i))

def doit(level, eat):
    if level == 0:
        return int(eat >= 1)
    both = bothCount(level - 1)
    patties = pattiesCount(level - 1)
    if eat == both + 2:
        return 1 + patties
    if eat > both + 1:
        return 1 + patties + doit(level - 1, eat - 2 - both)
    return doit(level - 1, eat - 1)

print(doit(n, eat))


Measured memory_bytes: 3188
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    f, *shape, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    dp = arr(31)
    dp[0], dp[1], dp[2] = 1, 1, 2
    for i in range(3, 31):
        dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3]
    while True:
        n = read(int)
        if n == 0:
            break
        print(dp[n] // 10 // 365 + 1)


if __name__ == "__main__":
    main()



Measured memory_bytes: 6740
import sys

X, N = map(int, sys.stdin.readline().split())
P = [int(x) for x in sys.stdin.readline().split()]

Y = [x for x in range(102)]
setY = set(Y)
setP = set(P)
R = list(setY-setP)
RX = [abs(r - X) for r in R]
i = RX.index(min(RX))
print(R[i])


Measured memory_bytes: 9200
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define INF 10e16

int main() {
  int n, i;
  ll x = 0, y = 0, ans = INF;
  cin >> n;
  vector<int> a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    y += a[i];
  }
  for (i = 0; i < n - 1; i++) {
    x += a[i];
    y -= a[i];
    ans = min(ans, abs(x - y));
  }
  cout << ans << "\n";
  return 0;
}

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

typedef long long ll;
using namespace std;

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

	int a[2] = {0,0};

	for (int i = 0;i < 2;i++){
		for (int j = 0;j < 4;j++){
			int tmp; cin >> tmp;
			a[i] += tmp;
		}
	}

	cout << max(a[0],a[1]) << endl;

	return 0;

}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,cnt=0;
  cin>>a;
  int b[a],e[a];
  for(int i=0;i<a;i++){
    cin>>b[i];
  }
  int c[a];
  for(int i=0;i<a;i++){
    cin>>c[i];
  }
  for(int i=0;i<a;i++){
    e[i]=b[i]-c[i];
    if(e[i]>0)
      cnt+=e[i];
  }
  cout<<cnt;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

int main(){
  int X;
  cin >> X;
  int ans = 0;

  ans += 1000 * floor(X / 500);
  X %= 500;
  ans += 5 * floor(X / 5);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include<list>
#include<map>
#include<utility>
#include<tuple>
#include<numeric>
#include<set>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),a.end()
using namespace std;

int main()
{
	int n;
	int k;
	cin >> n >> k;
	if (n%k == 0)cout << '0' << endl;
	else cout << '1' << endl;
}



Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n;
int a[101];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	double ans=0;
	for (int i=1;i<=n;i++)
	{
		double t=a[i];
		ans+=1.0/t;
	}
	printf("%.6lf",1.0/ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static Long getLong(){return Long.parseLong(getStr());}
        static boolean isNext(){return sc.hasNext();}
        static char[] splitSingle(String str){return str.toCharArray();}
        public static void main(String[] args){
          int N = getInt();
          int T = getInt();
          int[] list = new int[N];
          for(int i = 0; i < N; i++){
            list[i] = getInt();
          }
          long output = 0;
          for(int i = 1; i < N; i++){
            if(list[i] - list[i-1] > T){
              output += T;
            }else{
              output += list[i] - list[i-1];
            }
          }
          output += T;
          myout(output);
        }
        //便利メソッド追加枠ここから

        //便利メソッド追加枠ここまで
}


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

int main(){
  int N; int64_t K; cin >> N >> K;

  vector<pair<int, int>> ab;
  int a, b;
  rep(i,N){
    cin >> a >> b;
    ab.push_back(make_pair(a,b));
  } 
  sort(ab.begin(),ab.end());
  //for (auto p:ab) cout << p.first << p.second << endl;
  
  int64_t sum=0;

  rep(i,N){
    sum += ab.at(i).second;
    if (sum>=K){
      cout << ab.at(i).first << endl;
      break;
    } 
  }

  
}

 

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

int sss(int);
int main(){
  int n,*aaa,i,count=0;

  scanf("%d",&n);
  aaa=malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    scanf("%d",&aaa[i]);
  }
  for(i=0;i<n;i++){
    if(sss(aaa[i])==1){
      count++;
    }
  }
  printf("%d\n",count);

  return 0;
}

int sss(int x){
  int i,j,y;

  y=sqrt(x);
  for(i=3;i<=y;i+=2){
    if(x%i==0){
      return 0;
    }
  }
  if(x==2){
    return 1;
  }
  else if(x%2==0){
    return 0;
  }
  return 1;
}



Measured memory_bytes: 2060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;

int main() {
	
	int n;
	cin>>n;
	
	ll arr[n+1];
	for(int i=0;i<n;i++)
	cin>>arr[i];
	
	int sum[n+5];
	sum[n]=0;
	for(int i=n-1;i>=0;i--)
	{
	    sum[i]=(sum[i+1]+arr[i])%mod;
	}
	
	ll ans=0;
	for(int i=0;i<n;i++)
	{
	    ll val=(arr[i]*sum[i+1])%mod;
	    ans=(ans+val)%mod;
	}
	cout<<ans;
}


Measured memory_bytes: 5956
n = gets.chomp.to_i
a = gets.chomp.split(" ")
a.map! { |item| item.to_i }

### n = 3
### a = [500, 300, 200]

a.sort!

for i in 1..(n-1)
  t = (a.shift + a.shift) / 2.0
  a.insert(0, t)
end
p a[0]

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

int main()
{
    int a, b, n;
    int plan1 = 0, plan2 = 0;
    cin >> n >> a >> b;
    
    plan1 = a * n;
    plan2 = b;
    if(plan1 <= plan2)
        cout << plan1 << endl;
    else if(plan1 > plan2)
        cout << plan2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main ()
{
	int n,temp;
	bool lucky=false;
	cin>>n;
	while(n)
	{
		
		temp=n%10;
		//cout<<temp<<endl;
		if(temp==7)lucky=true;
		n/=10;
		
	}
	if(lucky)cout<<"Yes";
	else cout<<"No";
}

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

int main() {
	ll n,ans;
	cin>>n;
	ans=n;
	string s;
	cin>>s;
	for(ll i=1;i<n;i++)
	{
		if(s[i]==s[i-1])
		--ans;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

    while (true) {
      int h = sc.nextInt();
      int w = sc.nextInt();
      
      if (h == 0 && w == 0) break;

      IntStream.range(0, h).forEach(i ->  {
        IntStream.range(0, w).forEach(j -> pw.print("#"));
        pw.println();
      });
      pw.println();
    }

    pw.flush();
    sc.close();
  }
}


Measured memory_bytes: 32476
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,k;
    cin>>n>>k;
    vi f(n+1);
    rep(i,k){
        int d;
        cin>>d;
        rep(j,d){
            int a;
            cin>>a;
            f[a]=1;
        }
    }
    cout<<n-accumulate(all(f),0ll)<<endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;
int L;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	L=S.size();
	
	if((S[0]==S[L-1]) ^ (L%2)) _P("First\n");
	else _P("Second\n");
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ab = sc.nextInt();
        int bc = sc.nextInt();
        int ac = sc.nextInt();

        int result = 1000;
        result = Math.min(ab + bc, result);
        result = Math.min(ac + bc, result);
        result = Math.min(ab + ac, result);
        System.out.println(result);
    }
}

Measured memory_bytes: 21844
/*
         ██╗ ██████╗ ██╗███╗   ██╗    ██╗   ██╗███████╗
         ██║██╔═══██╗██║████╗  ██║    ██║   ██║██╔════╝
         ██║██║   ██║██║██╔██╗ ██║    ██║   ██║███████╗
    ██   ██║██║   ██║██║██║╚██╗██║    ██║   ██║╚════██║
    ╚█████╔╝╚██████╔╝██║██║ ╚████║    ╚██████╔╝███████║
     ╚════╝  ╚═════╝ ╚═╝╚═╝  ╚═══╝     ╚═════╝ ╚══════╝
*/
//password:+BdCHpO8dQvpo5fnV3/u
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
priority_queue<ll>pq;

int main() {
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        ll x;
        cin>>x;
        pq.push(x);
    }
    while(m--)
    {
        ll r=pq.top();
        pq.pop();
        r/=2;
        pq.push(r);
    }
    ll ans=0;
    while(pq.size()) ans+=pq.top(),pq.pop();
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1400