akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using i64 = long long;

std::string s;
i64 dp[101][10][2];

i64 rec(int d, int r, int f) {
    if (d < 0) return r == 0;
    if (r == 0) return 1;
    if (dp[d][r][f] >= 0) return dp[d][r][f];

    int digit = s[d] - '0';
    i64 ret = rec(d - 1, r, f || digit > 0);
    if (f) ret += rec(d - 1, r - 1, f) * 9;
    else if (digit) ret += rec(d - 1, r - 1, 1) * (digit - 1) + rec(d - 1, r - 1, 0);

    return dp[d][r][f] = ret;
}

int main() {
    int k;
    std::cin >> s >> k;

    std::reverse(s.begin(), s.end());

    for (int i = 0; i <= 100; i++) for (int j = 0; j < 10; j++) dp[i][j][0] = dp[i][j][1] = -1;

    i64 ret = rec(s.size() - 1, k, 0);
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 2944.cc: 
 */

#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 = 10000;

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  for (int n, m; scanf("%d%d", &n, &m) == 2 && n > 0;) {
    int av = m / n, sum = 0;
    for (int i = 0; i < n; i++) {
      int ai;
      scanf("%d", &ai);
      sum += min(ai, av);
    }
    printf("%d\n", sum);
  }
  return 0;
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
char s[500][500];

struct Dsu {
  struct node_struct {
    int par, size;
    node_struct(int p, int s) : par(p), size(s) {}
    void merge(node_struct &b) {
      b.par = par;
      size += b.size;
    }
  };
  vector<node_struct> nodes;
  stack<tuple<int, int, node_struct, node_struct>> stk;
  Dsu(int n) {
    nodes.reserve(n);
    for (int i = 0; i < n; ++i) nodes.emplace_back(i, 1);
  }
  int anc(int x) {
    while (x != nodes[x].par) x = nodes[x].par;
    return x;
  }
  bool unite(int x, int y) {
    int a = anc(x);
    int b = anc(y);
    stk.emplace(a, b, nodes[a], nodes[b]);
    if (a == b) return false;
    if (nodes[a].size < nodes[b].size) swap(a, b);
    nodes[a].merge(nodes[b]);
    return true;
  }
  void revert(int version = -1) {  // 0 index
    if (version == -1) version = stk.size() - 1;
    for (; stk.size() != version; stk.pop()) {
      nodes[get<0>(stk.top())] = get<2>(stk.top());
      nodes[get<1>(stk.top())] = get<3>(stk.top());
    }
  }
};
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; ++i) cin >> s[i];
  Dsu tool(h * w);
  int dx[4] = {-1, 0, 1, 0};
  int dy[4] = {0, 1, 0, -1};
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      for (int d = 0; d < 4; ++d) {
        int ni = i + dx[d], nj = j + dy[d];
        if (ni < h and ni >= 0 and nj < w and nj >= 0 and s[i][j] != s[ni][nj]) {
          tool.unite(i * w + j, ni * w + nj);
        }
      }
    }
  }
  vector<bool> used(h * w);
  long long ans = 0;
  vector<vector<char>> compo;
  compo.resize(h * w);
  for (int i = 0; i < h * w; ++i) {
    compo[tool.anc(i)].emplace_back(s[i / w][i % w]);
  }
  for (int i = 0; i < h * w; ++i) {
    long long w = count(compo[i].begin(), compo[i].end(), '.'), b = count(compo[i].begin(), compo[i].end(), '#');
    ans += w * b;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 21300
using System;

public class hello
{
    public static void Main()
    {
        var soroban = new string[]{ "* = ****","* =* ***","* =** **","* =*** *","* =**** ",
                                             " *= ****"," *=* ***"," *=** **"," *=*** *"," *=**** " };
        var flag = "first";
        string line;
        for (; (line = Console.ReadLine()) != null;)
        {
            var s = line.Trim();
            var ary = new int[5];
            for (int i = 0; i < s.Length; i++)
                ary[5 - s.Length + i] = int.Parse(s[i].ToString());
            if (flag != "first") Console.WriteLine();
            else flag = "se";
            for (int j = 0; j < 8; j++)
                for (int i = 0; i < 5; i++)
                {
                    var disp = soroban[ary[i]].Substring(j, 1);
                    Console.Write(disp);
                    if (i == 4) Console.WriteLine();
                }
        }

    }
}

Measured memory_bytes: 8944
#include <cstdio>
#include <iostream>
#define MOD 1000000007
long long fac(int v){
    long long ret = 1;
    for(int i = 1; i <= v; i++) ret = (ret * i)%MOD;
    return ret;
}
int main(){
    int N, M;
    scanf("%d%d",&N,&M);
    if(N > M) std::swap(N,M);
    if(N+1==M){
        printf("%lld",fac(N)*fac(M)%MOD);
    }
    else if(N==M){
        printf("%lld",fac(N) * fac(M)%MOD*2%MOD);
    }else printf("0");

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
//using atcorder.DataStructure;
namespace atcorder
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            atcorder.Test.Run();
        }
    }


    public class Test
    {
        public static void Run()
        {
            List<int> times = new List<int>();
            for (int i = 0; i < 5; i++)
            {
                times.Add(int.Parse(Console.ReadLine()));
            }
            List<Tuple<int, int>> tuples = new List<Tuple<int, int>>();
            for (int i = 0; i < 5; i++)
            {
                if (times[i] % 10 == 0) tuples.Add(new Tuple<int, int>(10, times[i]));
                else tuples.Add(new Tuple<int, int>(times[i]%10, times[i]));
            }
            tuples.Sort();
            tuples.Reverse();
            int ret = 0;
            for (int i = 0; i < 4;i++){
                ret += tuples[i].Item2 + (10 - tuples[i].Item1);
            }
            ret += tuples[4].Item2;
            Console.WriteLine(ret);
        }
    }




    public class Input
    {
        int arg;
        int length;
        string s;
        string[] ss;
        char sep;
        public Input(char _sep = '\0')
        {
            sep = _sep;
        }
        public void ReadLine()
        {
            s = Console.ReadLine();
            if (sep != '\0') ss = s.Split(sep);
            else
            {
                ss = new string[1];
                ss[0] = s;
            }
            arg = 0;
            length = ss.Length;
        }
        public T Next<T>()
        {
            if (arg == length) throw new IndexOutOfRangeException();
            return (T)Convert.ChangeType(ss[arg++], typeof(T));
        }
        public void SetSeparater(char _sep)
        {
            sep = _sep;
        }
    }
}


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

int main() {
  int n, k, a;
  int b[200000];
  cin >> n >> k;
  fill(b, b+n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a;
    b[a-1]++;
  }
  sort(b, b+n, greater<int>());
  int ans = n;
  for (int i = 0; i < k; ++i) {
    ans -= b[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
def main():
#     num = [int(input()) for i in range(4)]
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    counter = 0
#     if (10*A+2*B+C < X):
#         print(counter)
#         return
#     if (X%2==1 && C == 0):
#         print(counter)
#         return
    for i in range(A+1):
        for j in range(B+1):
            for k in range(C+1):
                if (500*i+100*j+50*k==X):
                    counter += 1
    print(counter)
main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
main(){
  long N,s=0,i,j;
  cin>>N;
  int a[3*N],b=3*N;
  for(i=0;i<b;i++) cin>>a[i];
  sort(a,a+b);
  for(j=N;j<b;j+=2) s+=a[j];
  cout<<s;
}

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

int main() {
  int s;
  cin>>s;
  vector<bool>check(100000000);
  check[s]=true;
  int i=1;
  while(1){
    i++;
    if(s%2==0) s/=2;
    else s=3*s+1;
    if(check[s]){
      cout<<i<<endl;
      break;
    }
    else{
      check[s]=true;
    }
  }
}


Measured memory_bytes: 12416
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

int match(int a) {
	switch (a) {
	case 1: return 2;
	case 2: return 5;
	case 3: return 5;
	case 4: return 4;
	case 5: return 5;
	case 6: return 6;
	case 7: return 3;
	case 8: return 7;
	case 9: return 6;
	default: return 0;
	}
}

int main() {
	int N, M;
	int A[9];
	int minmatch = 10;
	int minmatchmax = 0;

	cin >> N >> M;

	int m;
	for (int i = 0; i < M; i++) {
		cin >> A[i];
		m = match(A[i]);
		if (m < minmatch) {
			minmatch = m;
			minmatchmax = A[i];
		}
		else if (m == minmatch) {
			if (minmatchmax < A[i]) {
				minmatchmax = A[i];
			}
		}
	}

	sort(A, A + M);

	int *dp = new int[N+1];
	dp[0] = 0;
	int max = 0;
	int l;

	for (int i = 1; i <= N; i++) {
		max = -100;
		for (int m = 0; m < M; m++) {
			l = i - match(A[m]);
			if (l < 0)continue;

			if (max < (dp[l] + 1)) max = dp[l] + 1;
		}

		dp[i] = max;
	}

	int Digit = dp[N];

	while (N != 0){
		for (int m = M - 1; m >= 0; m--) {
			if (N - match(A[m]) < 0)continue;
			if (dp[N - match(A[m])] == dp[N] - 1) {
				cout << A[m];
				N -= match(A[m]);
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
using System;

class Class01
{
    public static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            string s = Console.ReadLine();
            string[] a = new string[n];
            a = s.Split(' ');

            int[] b = new int[3];
            for (int j = 0; j < 3; j++)
            {
                b[j] = int.Parse(a[j]);

            }
            Array.Sort(b);

            if (Math.Pow(b[2], 2) == Math.Pow(b[0], 2) + Math.Pow(b[1], 2))
            {
                Console.WriteLine("YES");
            }
            else Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 9428
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <int> > vv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define mod 1000000007
#define inf 9999999999999999ll
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    fast
    char c;
    cin>>c;
    c++;
    cout<<c<<endl;
}

Measured memory_bytes: 256
N = int(input())
A_list = tuple(map(int, input().split(' ')))

# print(N)
# print(A_list)

ret = 0
now_sum = sum(A_list)
# print("スタート{}".format(now_sum))

for i in range(len(A_list)):
  now_sum -= A_list[i]
  multiple_base = A_list[i]
  # print('now_sumから{0}を引いて{1}'.format(A_list[i], now_sum))
  before_total = 0
  # print("before_totalは{0}, multiple_baseは{1}, 掛け算で{2}".format(multiple_base, before_total, multiple_base * before_total))
  ret += multiple_base * now_sum
  
print(ret % 1000000007)


Measured memory_bytes: 31388
#include<iostream>
#include<string>
#include<map>

int main(void){

  std::string s;
  std::cin>>s;
  
  std::map<char,int> m;
  m['1']=9;
    m['9']=1;
  
  for(auto c:s){
  	std::cout << m[c] ;
  }
  std::cout << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdio>

using T = std::vector<int>;

int inf = std::pow(10, 9);
int n, A, B, C;
int dfs(int now, int a, int b, int c, T& vec) {
    //printf("n=%d;\ndfs: now=%d, a=%d, b=%d, c=%d\n", n, now, a, b, c); printf version
    //std::cout << "n=" << n << ";" << std::endl; print n
    //std::cout << "dfs: now=" << now << ", a=" << a <<", b=" << b << ",c=" << c << std::endl; print now, a, b, c;
    if (now == n) {
        if (std::min({a, b, c}) > 0) {
            return std::abs(a-A) + std::abs(b-B) + std::abs(c-C) - 30;
        }
        else {
            return inf;
        }
    }
    int ret0 = dfs(now+1, a, b, c, vec);
    int ret1 = dfs(now+1, a+vec[now], b, c, vec) + 10;
    int ret2 = dfs(now+1, a, b+vec[now], c, vec) + 10;
    int ret3 = dfs(now+1, a, b, c+vec[now], vec) + 10;
    return std::min({ret0, ret1, ret2, ret3});
}



int main() {
    std::cin >> n >> A >> B >> C;
    std::vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        std::cin >> vec[i];
    }
    std::cout << dfs(0, 0, 0, 0, vec) << std::endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    while(1){
        int n; cin >> n;
        if(n == 0) break;

        int res = 0;
        for(int i = 1; i < n; i++){
            int sum = i;

            for(int j = i + 1; j < n; j++){
                sum += j;
                if(sum == n){
                    res++;
                }
            }
        }

        cout << res << endl;
    }

    return 0;
}

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

using namespace std;
const double pi=acos(-1.0);
int main()
{
    int n;
    cin>>n;
    int m;
    cin>>m;
    while(m--){
        int tmp;
        cin>>tmp;
        n-=tmp;
    }
    if(n<0) cout<<-1<<endl;
    else cout<<n<<endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  int n, m; cin >> n >> m;
  int sum = 0;
  rep(i, m){
    int a; cin >> a;
    sum += a;
  }
  if(sum <= n)
  cout << n - sum << endl;
  else
  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 3624
import sys
n, ans = map(int, input().split())

for x in range(n + 1):
    for y in range(n + 1 - x):
        if n - x - y >= 0:
            if (10000 * x + 5000 * y + 1000 * (n - x - y)) == ans:
                print(x, y, n - x - y)
                sys.exit()

print('-1 -1 -1')

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int x;
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>x;
	cout<<48-x<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)
 
ans = 0
 
for i in range(N-2):
  j = i + 1
  k = N - 1
  while j < k:
    if l[i] < l[j] + l[k]:
      ans += k - j
      j += 1
    else:
      k -= 1
print(ans)

Measured memory_bytes: 3188
#include <queue>
#include <limits>
#include <vector>
#include <iostream>
using namespace std;
struct edge {
	int to, cost;
	edge(int to_, int cost_) : to(to_), cost(cost_) {};
};
bool operator<(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}
template<class Type>
std::vector<Type> shortest_path(std::vector<std::vector<edge> > &G, int s) {
	std::priority_queue<edge> que; que.push(edge(s, 0));
	std::vector<Type> ret(G.size(), std::numeric_limits<Type>::max()); ret[s] = 0;
	while (!que.empty()) {
		edge u = que.top(); que.pop();
		for (edge e : G[u.to]) {
			if (ret[e.to] > ret[u.to] + e.cost) {
				ret[e.to] = ret[u.to] + e.cost;
				que.push(edge(e.to, -ret[e.to]));
			}
		}
	}
	return ret;
}
std::vector<vector<int> > shortest_path_tree_all(std::vector<std::vector<edge> > &G, int s) {
	std::priority_queue<edge> que; que.push(edge(s, 0));
	std::vector<long long> ret(G.size(), std::numeric_limits<long long>::max()); ret[s] = 0;
	vector<vector<int> > res(G.size());
	while (!que.empty()) {
		edge u = que.top(); que.pop();
		for (edge e : G[u.to]) {
			if (ret[e.to] > ret[u.to] + e.cost) {
				ret[e.to] = ret[u.to] + e.cost;
				res[e.to].clear();
				que.push(edge(e.to, -ret[e.to]));
			}
			if (ret[e.to] == ret[u.to] + e.cost) {
				res[e.to].push_back(u.to);
			}
		}
	}
	return res;
}
int n, m, a, b, c;
int main() {
	cin >> n >> m;
	vector<vector<edge> > G(n);
	for (int i = 0; i < m; i++) {
		cin >> a >> b >> c; a--, b--;
		G[a].push_back(edge(b, c));
		G[b].push_back(edge(a, c));
	}
	vector<vector<int> > d(n);
	for (int i = 0; i < n; i++) d[i] = shortest_path<int>(G, i);
	int x = -1;
	vector<vector<int> > p;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (d[i][j] > x) x = d[i][j], p.clear();
			if (d[i][j] == x) p.push_back({ i, j });
		}
	}
	vector<vector<int> > gp(n);
	for (vector<int> i : p) {
		gp[i[0]].push_back(i[1]);
		gp[i[1]].push_back(i[0]);
	}
	vector<bool> ret(n, false);
	for (int t = 0; t < n; t++) {
		vector<vector<int> > f = shortest_path_tree_all(G, t);
		queue<int> que; vector<bool> vis(n, false);
		for (int t2 : gp[t]) {
			que.push(t2);
			vis[t2] = true;
			ret[t2] = true;
		}
		while (!que.empty()) {
			int u = que.front(); que.pop();
			for (int i : f[u]) {
				if (!vis[i]) {
					vis[i] = true;
					ret[i] = true;
					que.push(i);
				}
			}
		}
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (!ret[i]) cnt++;
	}
	cout << cnt << endl;
	for (int i = 0; i < n; i++) {
		if (!ret[i]) cout << i + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 93644
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int q;
    cin >> q;
    long long a,b;
    long long ans[q];
    long long tmp,tmp2;
    for(int i = 0;i<q;i++){
        cin >> a >> b;
        tmp = long(sqrt(a*b)); 
        ans[i] = 2*tmp-1;
        if(tmp*(tmp+1)>=a*b) ans[i]--;
        if(tmp*tmp==a*b) ans[i]--;
        if(a==b) ans[i]++;
    }
    for(int i = 0;i<q;i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
import collections
def main():

    N, A, B, C = map(int, input().split())

    ans = ""
    s = []
    for _ in range(N):
        s.append(input())

    d = dict()
    d['A'] = A
    d['B'] = B
    d['C'] = C
    ans = ""
    for i in range(N):
        if d[s[i][0]] == 0 and d[s[i][1]] == 0:
            break
        elif d[s[i][0]] == 0:
            d[s[i][0]] += 1
            d[s[i][1]] -= 1
            ans += s[i][0]
        elif d[s[i][1]] == 0:
            d[s[i][1]] += 1
            d[s[i][0]] -= 1
            ans += s[i][1]
        else:
            if d[s[i][0]] == 1 and d[s[i][1]] == 1 and d['A'] + d['B'] + d['C'] == 2:
                if i < N-1 and s[i] != s[i+1] and s[i][0] in s[i+1]:
                    d[s[i][0]] += 1
                    d[s[i][1]] -= 1
                    ans += s[i][0]
                else:
                    d[s[i][1]] += 1
                    d[s[i][0]] -= 1
                    ans += s[i][1]
            elif d[s[i][0]] < d[s[i][1]]:
                d[s[i][0]] += 1
                d[s[i][1]] -= 1
                ans += s[i][0]
            else:
                d[s[i][1]] += 1
                d[s[i][0]] -= 1
                ans += s[i][1]

    if len(ans) == N:
        print("Yes")
        for c in ans:
            print(c)
    else:
        print("No")

if __name__ == '__main__':
    main()

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    string S;
    cin >> N;
    cin >> S;
    iter(c, S) c = 'A' + (c - 'A' + N) % 26;
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 3640
import Control.Monad
import Data.IntMap (IntMap, (!))
import qualified Data.IntMap as IM
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Bool
import Data.Maybe

solve :: Int -> IntMap [(Int,Int)] -> Bool
solve n nbr = isJust $ foldM f IM.empty [1..n] where
  f pos i
    | i `IM.member` pos = Just pos
    | otherwise = g i 0 pos
    where
      g i pi pos = foldM h (IM.insert i pi pos) (nbr!i) where
        h pos (j, d)
          | j `IM.member` pos =
              bool Nothing (Just pos) (pos!j == pj)
          | otherwise = g j pj pos
          where pj = pi + d

main :: IO ()
main = do
  [n,m] <- map read.words <$> getLine
  edge <- replicateM m readIntsLn
  let
    nbr = foldr f emps edge
    f [l,r,d] nbr
      = IM.adjust ((r,d):) l $ IM.adjust ((l,-d):) r nbr
    emps = IM.fromDistinctAscList $ zip [1..n] $ repeat [] 
  putStrLn $ bool "No" "Yes" $ solve n nbr

readIntsLn
  = unfoldr (B.readInt . B.dropWhile(==' ')) <$> B.getLine

Measured memory_bytes: 119676
#include <stdio.h>
#include<math.h>
#include<bitset>
#include<string>
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;


int main()
{
    bool flag=true;
    string s;
    cin>>s;
    
    for(int i=0;i<s.length();i+=2){
        if(s[i]=='L'){
            flag=false;
            break;
        }
    }
    
    for(int i=1;i<s.length();i+=2){
        if(s[i]=='R'){
            flag=false;
            break;
        }
    }
    
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n; cin >> n;
  rep(i, 3){
    int t = n%10;
    n /= 10;
    if(t == 7){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  system("pause");
}


Measured memory_bytes: 3708
using System;

// i should implement by Generic Type
public class Stack {
  private int[] stack = new int[1000000];
  private int pos = 0;
  
  public void Push(int x) {
    stack[pos++] = x;
  }

  public int Pop() {
    return stack[--pos];
  }

  public int Top() {
    return stack[pos-1];
  }

  public int Count {
    get {
      return pos;
    }
  }

  public void Print(string sep = " ") {
    if (Count <= 0) return;
    for (int i = pos-1; i > 0; i--) {
      Console.Write(stack[i] + sep);
    }
    Console.WriteLine(stack[0]);
  }

  public void PrintReverse(string sep = " ") {
    if (Count <= 0) return;
    for (int i = 0; i < pos-1; i++) {
      Console.Write(stack[i] + sep);
    }
    Console.WriteLine(stack[pos-1]);
  }
}

public class Solve {
  public static void Main() {
    // define section
    Stack bsPos = new Stack(); // store positions of back slash  
    Stack fldArea = new Stack(); // store areas of each flood
    Stack fldPos = new Stack(); // store positions of each flood's top left
    // note:  fldArea[i] and fldPos[i] have very strong relations.
    //        the order is important, don't sort.
    string line = Console.ReadLine();
    char c;
    int area, pos;
    int ans = 0;
   
    // calculate section 
    for (int i = 0; i < line.Length; i++) {
      c = line[i];
      if (c == '\\') {
        bsPos.Push(i);
      } else if (c == '/') {
        if (bsPos.Count > 0) {
          pos = bsPos.Pop();
          area = i - pos;
          ans += area;
          while (fldPos.Count > 0 && fldPos.Top() >= pos) {
            area += fldArea.Pop();
            fldPos.Pop();  
          }
          fldArea.Push(area);
          fldPos.Push(pos);
        }
      }
      //fldArea.Print();
    }

    // print section
    Console.WriteLine(ans);
    Console.Write(fldArea.Count);
    //fldArea.Print();
    if (fldArea.Count > 0) {
      Console.Write(" ");
      fldArea.PrintReverse();
    } else {
      Console.WriteLine();
    }
  }
}




Measured memory_bytes: 17836
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<string>
#include<cmath>
#include<tuple>
#include<algorithm>
#define INF 1111111111
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> tup;
typedef long long ll;
vector<int> vec(100100);
vector<int> passed(100100);
vector<int> dx = {-1,1};

int main() {
    int n;
    cin >> n;
  int max = 1;
  int tmp = 0;
  bool ans = true;
  for(int i=0;i<n;i++){
    cin >> tmp;
    if(tmp > max)
      max = tmp;
    else if(max-tmp>=2){
      ans = false;
      break;
    }
  }
  cout << (ans?"Yes":"No")<< endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<int> a(N);
    for (auto& x : a) cin >> x;
    int p = 0;
    int res = 0;
    for (int k = 1;; k++) {
      while (p < N && a[p] != k) ++p;
      if (p < N && a[p] == k) {
        ++res;
      } else {
        break;
      }
    }
    if (res == 0) {
      cout << -1 << endl;
    } else {
      cout << N - res << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
package main

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

func main() {
	N := getStdinInt()
	AC := 0
	WA := 0
	TLE := 0
	RE := 0
	for i := 0; i < N; i++ {
		s := getStdin()
		if s == "AC" {
			AC++
		} else if s == "WA" {
			WA++
		} else if s == "TLE" {
			TLE++
		} else if s == "RE" {
			RE++
		}
	}
	fmt.Printf("AC x %d\n", AC)
	fmt.Printf("WA x %d\n", WA)
	fmt.Printf("TLE x %d\n", TLE)
	fmt.Printf("RE x %d\n", RE)
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 4172
n=STDIN.gets.chomp.to_i
t,a=STDIN.gets.chomp.split(/ +/).map(&:to_i)
h = STDIN.gets.chomp.split(/ +/).map(&:to_i).slice(0, n)
pointT = h.map{|h| (t - h*0.006 -a ) .abs}
puts pointT.index( pointT.min ) + 1

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

int gcd(int x, int y){
    int z = min(x, y);
    int w = max(x, y);
    while(z > 0){
        int res = w % z;
        w = z;
        z = res;
    }
    return w;
}

int main(){
    int a, b, c, g, sum=0;
    int k;
    cin >> k;
    for(a=1; a<=k; a++){
        for(b=1; b<=k; b++){
            for(c=1; c<=k; c++){
                sum += gcd(gcd(a, b), c);
            }
        }
    }
    cout << sum << endl;
}

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int xa = min(a,k);
  k -= xa;
  int xb = min(b,k);
  k -= xb;
  int xc = k;
  int ans = xa - xc;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return x*f;
}
const int N=200010;
int f[N];
int main(){
	int n=read(),mx=0;
	for (int i=1;i<=n;++i){
		int t=read();
		f[t]=f[t-1]+1;
		mx=max(mx,f[t]);
	}
	printf("%d\n",n-mx);
	return 0;
}

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

void Main(){
    
}

int main () {
    int a, b, z, total = 0;
	cin >> a >> b >> z;
	for (int i=a ; i<=b ; i++){
		if(z%i == 0){
		
		total++;
		}	
	}
	cout << total << endl;
}


Measured memory_bytes: 3084
#include<stdio.h>

int main(void){
	
	int n,h,m,s;
	
	scanf("%d", &n);
	
		h = n/3600;
		m = (n%3600)/60;
		s = (n%3600)%60;
	
	printf("%d:%d:%d\n", h,m,s);
	

return 0;
}

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

int main(){
  int n; cin>>n;
  bool ans=true;
  string w[110];
  for(int i=0;i<n;i++){
    cin>>w[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<i;j++){
      if(w[i]==w[j]){
        ans=false;
      }
    }
    if(w[i+1][0]!=w[i][w[i].length()-1]){
        if(i==n-1){break;}
        ans=false;
    }
  }
  if(ans){
   cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;

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[] arr = {a, b, c};
        Arrays.sort(arr);
        if (arr[0] == 5 && arr[1] == 5 && arr[2] == 7) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }
}


Measured memory_bytes: 35708
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}

int mm1[300005];
int mm2[300005];
map<pair<int,int>,int>mm;

signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int n,m,k;
    cin>>n>>m>>k;
    int x,y;
    vector<pair<int,int> >pp;
    for(int i=0;i<k;i++)
    {
        cin>>x>>y;
        pp.push_back({x,y});
        mm1[x]++;
        mm2[y]++;
        mm[{x,y}]++;
    }
    int mx1=0,mx2=0;
    multiset<pair<int,int>,greater<>>s;
    for(int i=1;i<=300000;i++)
        mx1=max(mx1,mm1[i]);

    for(int i=1;i<=300000;i++)
    {
        s.insert({mm2[i],i});
    }
    int fi=0;

    for(auto i:pp)
    {
        int ans=mm1[i.first];
        auto j=s.begin();
        if(mm[{i.first,j->second}])
            fi=max(fi,ans-1+j->first);
        else
            fi=max(fi,ans+j->first);
        if(s.size()>0)
        {
            j++;
            if(mm[{i.first,j->second}])
                fi=max(fi,ans-1+j->first);
            else
                fi=max(fi,ans+j->first);
        }
    }

    s.clear();
    for(int i=1;i<=300000;i++)
    {
        s.insert({mm1[i],i});
    }

    for(auto i:pp)
    {
        int ans=mm2[i.second];
        auto j=s.begin();
        if(mm[{j->second,i.second}])
            fi=max(fi,ans-1+j->first);
        else
            fi=max(fi,ans+j->first);
        if(s.size()>0)
        {
            j++;
            if(mm[{j->second,i.second}])
                fi=max(fi,ans-1+j->first);
            else
                fi=max(fi,ans+j->first);
        }
    }

    cout<<fi;

}           


Measured memory_bytes: 125172
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using namespace std;
/*
struct vert {
	int a = 0;
	int b = 0;
	int id;
	vert() {};
};

bool cmp(vert A, vert B) {
	return min(A.a, A.b) < min(B.a, B.b);
}
*/
set<pair<pair<int, int>, pair<int, int> > > vert; // {{minim, id}, {a, b}}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	vector<int> arr(n);
	for (int i = 0; i < n; i++) arr[i] = s[i] - 'A';
	vector<vector<int> > graph(n);
	int a, b;
	vector<pair<int, int> > current(n); //{a, b}
	for (int i = 0; i < n; i++) current[i] = { 0, 0 };
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
		if (arr[a] == 0) current[b].first++;
		else current[b].second++;
		if (arr[b] == 0) current[a].first++;
		else current[a].second++;
	}
	pair<pair<int, int>, pair<int, int> > help, help1;
	for (int i = 0; i < n; i++) {
		help.first.first = min(current[i].first, current[i].second);
		help.first.second = i;
		help.second = current[i];
		vert.insert(help);
	}
	int id = 0;
	while (vert.size() > 0) {
		help = *vert.begin();
		if (help.first.first > 0) {
			cout << "Yes" << endl;
			return 0;
		}
		id = help.first.second;
		for (auto elem : graph[id]) {
			if (elem == id) continue;
			help1.first.first = min(current[elem].first, current[elem].second);
			help1.first.second = elem;
			help1.second = current[elem];
			if (vert.find(help1) == vert.end()) continue;
			vert.erase(help1);
 			if (arr[id] == 0) current[elem].first--;
			else current[elem].second--;
			help1.first.first = min(current[elem].first, current[elem].second);
			help1.first.second = elem;
			help1.second = current[elem];
			vert.insert(help1);
		}
		vert.erase(help);
	}
	cout << "No" << endl;
}

Measured memory_bytes: 24400
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	string s;

	cin>>s;

	if(s.size()==2){
		cout<<s[0]<<s[1]<<endl;
	}else{
		cout<<s[2]<<s[1]<<s[0]<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
from collections import deque

s = input()
s2 = s.replace('x', '')
if s2 != s2[::-1]:
    print(-1)
else:
    d = deque(s)
    a, b = [], []
    cnt = 0
    x = y = ''
    x_skip = y_skip = 0
    while d:
        if not x_skip:
            x = d.popleft()
        if 0 < len(d)and not y_skip:
            y = d.pop()

        if y == '':
            break

        if x == y != 'x':
            cnt += abs(len(a)-len(b))
            x = y = ''
            a, b = [], []
            x_skip = y_skip = 0
            continue

        if x == 'x':
            a.append(x)
        else:
            x_skip = 1

        if y == 'x':
            b.append('x')
        else:
            y_skip = 1
    else:
        cnt += abs(len(a)-len(b))

    print(cnt)

Measured memory_bytes: 5148
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n;
        cin >> n;
        vector<P> ab(n);
        rep(i, n) {
            ll a, b;
            cin >> a >> b;
            ab[i] = P(a, b);
        }

        // solve
        ll ans = 0;
        sort(ab.begin(), ab.end(), greater<>());
        ans += ab[0].second + 1;
        for (int i = 1; i < ab.size(); ++i) {
            ans += min(ab[i - 1].first - ab[i].first, ab[i].second - ab[i - 1].second);
        }
        ans += ab.back().first - 1;
        cout << ans << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

using namespace std;

int main()
{

   int n;

   cin >> n;

   int *arr = (int*) malloc(n + 5 * sizeof(int*));

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

   int check = 0;

    for (int i = 0; i < n; i++)
    {
        if (arr[i] % 2 == 0 && arr[i] % 3 != 0 && arr[i] % 5 != 0)
        {
            puts("DENIED");
            return 0;
        }
    }

 puts("APPROVED");



    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
void input(vector<int>&a,int n)
{
   rep(i,0,n-1)
   cin>>a[i];
}
int a[1000005];
bool factorise(int n)
{   if(a[n]>1) return false;
   rep(i,1,sqrt(n))
  {
     if(n%i==0)
     {
       if(a[i]!=0 and i!=n) {
	    return false;}
       if(i!=n/i and a[n/i]!=0 and n/i!=n)
       {  int m=n/i;  return false;}
     } 
  }
  return true;
}
void solve()
{ 
 int n; cin>>n; memset(a,0,sizeof(a));
 int x; vector<int>v(n);
 rep(i,0,n-1)
 {
  cin>>x; a[x]++;  v[i]=x;
 } int res=0;
 for(auto i:v)
 { 
   if(factorise(i)) res++;
 }
 cout<<res<<"\n";
 return;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  while(t--)
  {
   solve();
  }
  return 0;
}

Measured memory_bytes: 7952
import itertools
import os
import sys
from collections import defaultdict

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353


class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self._bit = [0] * (size + 1)
        self._size = size

    def add(self, i, w):
        """
        i 番目に w を加える
        :param int i:
        :param int w:
        :return:
        """
        x = i
        while x <= self._size:
            self._bit[x] += w
            x += x & -x

    def sum(self, i):
        """
        0 番目から i 番目までの合計
        :param int i:
        :return:
        """
        ret = 0
        x = i
        while x > 0:
            ret += self._bit[x]
            x -= x & -x
        return ret

    def __len__(self):
        return self._size


def compress(li):
    """
    大小関係を保ったまま 1 以上の数値に圧縮する。
    scipy.stats.rankdata に近い感じ
    :param list li:
    :rtype: list of int
    """
    ret = [0] * len(li)
    rank = 0
    prev = None
    for a, i in sorted([(a, i) for i, a in enumerate(li)]):
        if a != prev:
            rank += 1
        ret[i] = rank
    return ret


# 解説AC
N = int(sys.stdin.readline())
XY = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]


def test():
    ret = 0
    counts = defaultdict(int)
    for selection in itertools.product([0, 1], repeat=N):
        if not any(selection):
            continue
        xs = set([XY[i][0] for i, s in enumerate(selection) if s])
        ys = set([XY[i][1] for i, s in enumerate(selection) if s])
        xl = min(xs)
        xr = max(xs)
        yl = min(ys)
        yr = max(ys)
        r = 0
        for x, y in XY:
            r += xl <= x <= xr and yl <= y <= yr
        ret += r
        counts[r] += 1
    return ret


XY.sort()
Y = [y for _, y in XY]
Y = compress(Y)

# LL[i]: x が X[i] より小さくて、y が Y[i] より小さい数
# LG[i]: x が X[i] より小さくて、y が Y[i] より大きい数
LL = []
LG = []
GL = []
GG = []

bit = BinaryIndexedTree(size=N)
for i, y in enumerate(Y):
    ll = bit.sum(y)
    lg = i - ll
    gl = y - ll - 1
    gg = N - y - lg
    LL.append(ll)
    LG.append(lg)
    GL.append(gl)
    GG.append(gg)
    bit.add(y, 1)

pow2 = [1] * N
p = 1
for i in range(N - 1):
    p = p * 2 % MOD
    pow2[i + 1] = p

# 点 p = (X[i], Y[i]) が何回カウントされるか
ans = 0
for ll, lg, gl, gg in zip(LL, LG, GL, GG):
    # -- p を選ぶ --
    ans += pow2[N - 1]
    # -- p を選ばない --
    # ll, gg をそれぞれ1つ以上選ぶ
    a = (pow2[ll] - 1) * (pow2[gg] - 1) % MOD * pow2[N - ll - gg - 1]
    # lg, gl をそれぞれ1つ以上選ぶ
    b = (pow2[lg] - 1) * (pow2[gl] - 1) % MOD * pow2[N - lg - gl - 1]
    # ll, gg, gl, lg をそれぞれ1つ以上選ぶ
    c = (pow2[ll] - 1) * (pow2[gg] - 1) % MOD * (pow2[lg] - 1) * (pow2[gl] - 1) % MOD
    ans += a + b - c
    ans %= MOD
print(ans)


Measured memory_bytes: 120820
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (auto &x: s) cin >> x;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') continue;
      if (i > 0) {
        if (s[i-1][j] == '#') continue;
      }
      if (i < h-1) {
        if (s[i+1][j] == '#') continue;
      }
      if (j > 0) {
        if (s[i][j-1] == '#') continue;
      }
      if (j < h-1) {
        if (s[i][j+1] == '#') continue;
      }
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll n;
  cin >> n;
  vl v(n);
  rep(i, n) cin >> v[i];
  
  map<ll, ll> odd, even;

  for(int i = 0; i < n; i += 2){
    odd[v[i]]++;
    even[v[i + 1]]++;
  }

  priority_queue<pll> odd2, even2;

  for(auto it = odd.begin(); it != odd.end(); it++)
    odd2.push({it->second, it->first});
  for(auto it = even.begin(); it != even.end(); it++)
    even2.push({it->second, it->first});

  if(odd2.size() == 1)
    odd2.push({0, 100001});
  if(even2.size() == 1)
    even2.push({0, 100002});

  if(odd2.top().second == even2.top().second){
    if(odd2.top().first > even2.top().first)
      even2.pop();
    else if(odd2.top().first < even2.top().first)
      odd2.pop();
    else{
      pll odd_top = odd2.top();
      pll evet_top = even2.top();

      odd2.pop();
      even2.pop();

      if(odd2.top().first >= even2.top().first)
		even2.push(odd_top);
      else
		odd2.push(evet_top);
    }
  }
  
  cout << n - odd2.top().first - even2.top().first << "\n";
    
  return 0;
}


Measured memory_bytes: 12588