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

    int n, m, x;
    cin >> n >> m >> x;
    int ans = 10000000;
    int v[n][m+1];
    for(int i=0;i<n;i++) {
        for(int j=0;j<m+1;j++){
            cin >> v[i][j];
        }
    }

    for(int i=0;i<(1<<n);i++) {
        int p = 0;
        int tmp[m];
        for(int i=0;i<m;i++) tmp[i]=0;

        for(int j=0;j<n;j++){
            if((i>>j)&1) {
                p += v[j][0];
                for(int k=0;k<m;k++){
                    tmp[k] += v[j][k+1]; 
                    //cout << i<<" "<<v[j][k+1] << endl;
                }

            }
        }
        for(int k=0;k<m;k++) {
            if(tmp[k]<x) break;
            if(k==m-1) ans = min(ans, p);
        }
        
    }
    if(ans==10000000) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3632
n, k = [int(x) for x in input().split()]
stands = [int(x) for x in input()]

wl = wr = 0
a = 1 - stands[0]
maxhand = 1

while wr < n-1:
    # extend to right
    if stands[wr + 1] == 1:
        wr += 1
    else: # right extends to 0
        if stands[wr] == 0:
            wr += 1
        else: # current rightmost is 1
            if (a+1 <= k): # use a flip anyway
                a += 1
                wr += 1
            else: # retract from the left
                # update counter
                if (wr - wl + 1) > maxhand:
                    maxhand = wr - wl + 1
                while stands[wl] == 1:
                    wl += 1
                while stands[wl] == 0:
                    wl += 1
                a -= 1

if (wr - wl + 1) > maxhand:
    maxhand = wr - wl + 1

print(maxhand)



Measured memory_bytes: 4084
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
//#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
//#define EXIST(s, e) ((s).find(e)!=(s).end())
//#define SORT(c) sort(begin(c),end(c))
//#define pb emplace_back
//#define MP make_pair
//#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int N,M,X;
    cin >> N >> M >> X;

    vector<int> A(M);
    rep(i,0,M){
        cin >> A[i];
    }

    int costA = lower_bound(all(A),X) - A.begin();
    int costB = A.end() - lower_bound(all(A),X);

    cout << min(costA,costB) << endl;

    return 0;
}


Measured memory_bytes: 256
//package atcoder.dpContest;

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

public class Main {
    public static void main(String[] args) {
//        try {
//            FastScanner in = new FastScanner(new FileInputStream("src/input.in"));
//            PrintWriter out = new PrintWriter(new FileOutputStream("src/output.out"));

        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

            solve(1, in, out);

//        } catch (IOException e) {
//            e.printStackTrace();
//        }
    }

    private static void solve(int q, FastScanner in, PrintWriter out) {
        for (int qq = 0; qq < q; qq++) {
            int N = in.nextInt();
            int[] a = new int[N];
            for(int i = 0; i < N; i++) {
                a[i] = in.nextInt();
            }
            long[] prefixSum = new long[N];
            prefixSum[0] = a[0];
            for(int i = 1; i < N; i++) {
                prefixSum[i] = prefixSum[i - 1] + a[i];
            }
            long[][] dp = new long[N][N];   //dp[i][j]: the min cost to merge piles [i, j]
            for(int l = 2; l <= N; l++) {
                for(int left = 0; left <= N - l; left++) {
                    int right = left + l - 1;
                    dp[left][right] = Long.MAX_VALUE;
                    for(int split = left; split < right; split++)
                    dp[left][right] = Math.min(dp[left][right], dp[left][split] + dp[split + 1][right] + prefixSum[right] - (left > 0 ? prefixSum[left - 1] : 0));
                }
            }
            out.println(dp[0][N - 1]);
        }
        out.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream stream) {
            try {
                br = new BufferedReader(new InputStreamReader(stream));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

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

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

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

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

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




Measured memory_bytes: 24572
#include <stdio.h>
#include <string.h>

#define MAX 36

int main(){
  char a[MAX][4],b[MAX][4],str[4];
  int n,i,j,c[MAX],d[MAX],tmp,mini,ok = 1;

  scanf("%d" ,&n);
  for(i = 0 ; i < n ; i++){
    scanf("%s" ,a[i]);
    strcpy(b[i],a[i]);
    c[i] = d[i] = a[i][1]-'0';
  }

  for(i = 0 ; i < n ; i++){
    for(j = n-1 ; j > i ; j--){
      if(c[j] < c[j-1]){
	tmp = c[j];
	c[j] = c[j-1];
	c[j-1] = tmp;

	strcpy(str,a[j]);
	strcpy(a[j],a[j-1]);
	strcpy(a[j-1],str);
      }
    }
  }  

  for(i = 0 ; i < n ; i++){
    if(i != n-1){
      printf("%s " ,a[i]);
    }else{
      printf("%s\n" ,a[i]);
      puts("Stable");
    }
  }

  for(i = 0 ; i < n-1 ; i++){
    mini = i;
    for(j = i+1 ; j < n ; j++){
      if(d[j] < d[mini]){
	mini = j;
      }
    }
    
    if(mini != i){
      tmp = d[i];
      d[i] = d[mini];
      d[mini] = tmp;

      strcpy(str,b[i]);
      strcpy(b[i],b[mini]);
      strcpy(b[mini],str);
    }
  }

  for(i = 0 ; i < n ; i++){
    if(strcmp(a[i],b[i])){
      ok = 0;
    }
    if(i != n-1){
      printf("%s " ,b[i]);
    }else{
      printf("%s\n" ,b[i]);
    }
  }

  if(ok){
    puts("Stable");
  }else{
    puts("Not stable");
  }

  return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

int main() {
    string s, t;
    cin >> s >> t;
    auto dp = make_v(s.size()+1, t.size()+1, 0);
    auto keiro = dp;
    auto n = s.size(), m = t.size();
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if(s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
                keiro[i+1][j+1] = 1;
            }
            else {
                if(dp[i][j+1] <= dp[i+1][j]){
                    dp[i+1][j+1] = dp[i+1][j];
                    keiro[i+1][j+1] = 2;
                }else {
                    dp[i+1][j+1] = dp[i][j+1];
                    keiro[i+1][j+1] = 3;
                }
            }
        }
    }
    string ans;
    int a = static_cast<int>(n), b = static_cast<int>(m);
    while(keiro[a][b]){
        if(keiro[a][b] == 1) ans += s[--a], b--;
        else if(keiro[a][b] == 2) b--;
        else if(keiro[a][b] == 3) a--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << "\n";
    return 0;
}


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

static const int MAX = 2e+5 + 1;

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    int a[MAX], b[MAX];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];

    ll sum_a[MAX], sum_b[MAX];
    sum_a[0] = sum_b[0] = 0;
    for(int i = 0; i < n; i++){
        sum_a[i+1] = a[i] + sum_a[i];
    }
    for(int i = 0; i < m; i++){
        sum_b[i+1] = b[i] + sum_b[i];
    }

    int ans = 0;
    int j = m;
    for(int i = 0; i <= n; i++){
        if(sum_a[i] > k)
            break;
        while(k - sum_a[i] < sum_b[j])
            j--;
        ans = max(ans, i+j);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8364
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;
int main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	ini(n);
	int a[10000010];
	int tmp1 = 0;
	int tmp_ = 0;
	FOR(i,0,n){in(a[i]);}
	auto x_ = max_element(a,a+n);
	int pos = x_ - a;
	int tmp = a[pos];
	a[pos] = 0;
	auto x = max_element(a, a + n);
	a[pos] = tmp;
	FOR(i, 0, n) {
		if (a[i] == *x_) {
			out(*x);
		}
		else {
			out(*x_);
		}
	}
	return 0;
}

Measured memory_bytes: 3840
import scala.collection.mutable.Stack
import scala.util.control.Breaks
object Main extends App {
  val stack = Stack.empty[Int]

  val b = Breaks

  b.breakable {
    for (line <- io.Source.stdin.getLines()) {
      if (line.isEmpty) b.break()

      val n = line.toInt

      if (n == 0) {
        println(stack.pop)
      } else {
        stack.push(n)
      }
    }
  }
}


Measured memory_bytes: 43972
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m, x = map(int, readline().split())
c = [list(map(int, readline().split())) for _ in range(n)]

ans = float('inf')
# bit全探索
for i in range(2 ** n):
    bag = np.empty(m+1)
    total = 0
    for j in range(n):
        if ((i >> j) & 1):
            bag += np.array(c[j])
        if np.amin(bag[1::]) >= x:
            ans = min(ans, bag[0])
            
print('-1'if ans == float('inf') else int(ans))

Measured memory_bytes: 27108
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,p,po[13];
char a[200020];
bool tag[800000];
int ch[800000][3],ans[600000],cnt;
void build(int k,int dep)
{
	if(!dep)return;
	ch[k][0]=k*3-1,ch[k][1]=k*3,ch[k][2]=k*3+1;
	build(k*3-1,dep-1),build(k*3,dep-1),build(k*3+1,dep-1);
}
void pushtag(int k)
{
	swap(ch[k][1],ch[k][2]);
	tag[k]^=1;
}
void work(int k,int dep)
{
	if(!dep)return;
	if(tag[k])
	{
		pushtag(ch[k][0]);
		pushtag(ch[k][1]);
		pushtag(ch[k][2]);
		tag[k]=0;
	}
	int a=ch[k][0],b=ch[k][1],c=ch[k][2];
	ch[k][0]=c,ch[k][1]=a,ch[k][2]=b;
	work(ch[k][0],dep-1);
}
void dfs(int k,int dep,int cur)
{
	if(!dep)
	{
		int s=0;k-=p+1;
		for(int i=1;i<=n;++i)s=s*3+k%3,k/=3;
		ans[s]=cur;
		return;
	}
	if(tag[k])
	{
		pushtag(ch[k][0]);
		pushtag(ch[k][1]);
		pushtag(ch[k][2]);
		tag[k]=0;
	}
	dfs(ch[k][0],dep-1,cur);
	dfs(ch[k][1],dep-1,cur+po[n-dep]);
	dfs(ch[k][2],dep-1,cur+2*po[n-dep]);
}
int main()
{
	po[0]=1;
	for(int i=1;i<=12;++i)po[i]=3*po[i-1];
	scanf("%d",&n);
	build(1,n);
	scanf("%s",a+1);
	m=strlen(a+1);
	for(int i=1;i<=m;++i)
	{
		if(a[i]=='S')pushtag(1);
		else work(1,n);
	}
	p=(po[n]-1)/2;
	dfs(1,n,0);
	for(int i=0;i<po[n];++i)printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 16248
#include <iostream>
#include <vector>
#include <string>

using namespace std;


struct Dice
{
    vector<int> faces;

    Dice(vector<int>& f)
        : faces(f) {}

    int top() {
        return faces.front();
    }

    void roll(char direction) {
        int tmp;
        switch (direction) {
        case 'E': // 1,4,6,3 -> 4,6,3,1
            tmp = faces[0];
            faces[0] = faces[3];
            faces[3] = faces[5];
            faces[5] = faces[2];
            faces[2] = tmp;
            break;
        case 'N': // 1,2,6,5 -> 2,6,5,1
            tmp = faces[0];
            faces[0] = faces[1];
            faces[1] = faces[5];
            faces[5] = faces[4];
            faces[4] = tmp;
            break;
        case 'S': // 1,5,6,2 -> 5,6,2,1
            tmp = faces[0];
            faces[0] = faces[4];
            faces[4] = faces[5];
            faces[5] = faces[1];
            faces[1] = tmp;
            break;
        case 'W': // 1,3,6,4 -> 3,6,4,1
            tmp = faces[0];
            faces[0] = faces[2];
            faces[2] = faces[5];
            faces[5] = faces[3];
            faces[3] = tmp;
            break;
        }
    }
};

int main()
{
    vector<int> faces;
    for (int i = 0; i < 6; ++i) {
        int x;
        cin >> x;
        faces.push_back(x);
    }

    Dice dice(faces);
    string s;
    cin >> s;

    // cerr << s << endl;
    for (string::iterator it = s.begin(); it != s.end(); ++it) {
        dice.roll(*it);
        // cerr << *it << "->" << dice.top() << endl;
    }
    cout << dice.top() << endl;

    return 0;
}

Measured memory_bytes: 3204
from collections import deque

def reverse(p):
    q = p[::-1]
    if p == q:
        return True
    else:
        return False


S = input()

N = len(S)

pt1 = (N - 1) // 2 - 1
pt2 = (N + 3) // 2 - 1

ptS1 = S[:pt1 + 1]
ptS2 = S[pt2:]

#print(ptS1, ptS2)

#print(reverse(ptS1), reverse(ptS2))

if reverse(S) and reverse(ptS1) and reverse(ptS2):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include <cstdio>
#include <vector>

long long int n;
std::vector<long long int> v;
int ans;

int main(){
	scanf("%lld", &n);
	for(long long int i=1; i*i<=n; ++i){
		if(n % i == 0){
			v.push_back(i);
			v.push_back(n/i);
		}
	}
	while(*(v.end()-1) > 0){
		*(v.end()-1) /= 10;
		++ans;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
s=input()
S=[0]
d=0
for i in s:
  if i=='A':
    d+=1
  else:
    d+=2
  S.append(d)
t=input()
T=[0]
d=0
for i in t:
  if i=='A':
    d+=1
  else:
    d+=2
  T.append(d)
q=int(input())
for i in range(q):
  a,b,c,d=map(int, input().split())
  x=S[b]-S[a-1]
  y=T[d]-T[c-1]
  if (x-y)%3==0:
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 17112
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int a,b,c;

int main()
{
	scanf("%d%d%d",&a,&b,&c);
	if(b-a==c-b)puts("YES");
	else puts("NO");
	return 0;
}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, m;
	cin >> n >> m;

	int ans = 0;
	vector<int> was(n);
	for (int i = 0; i < m; ++i)
	{
		int p; string s;
		cin >> p >> s;
		--p;

		if (s == "WA")
		{
			if (was[p] >= 0)
				++was[p];
		}
		else
		{
			if (was[p] >= 0)
				ans += was[p];
			was[p] = -1;
		}
	}
	cout << count(was.begin(), was.end(), -1) << " " << ans << "\n";

	return 0;
}


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

#define int long long
//#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define mod 1000000007


int fact[100005];
int inv[100005];
int power(int x,int y)
{
    int res=1;
    x =x%mod;
    while (y > 0)
    {
        if(y&1)
         res=(res*x)%mod;
         y=y>>1;
         x=(x*x)%mod;
    }
    return res % mod;
}  
int ncr(int n, int r)
{
	return ((fact[n] * inv[r]) % mod * inv[n-r]) % mod;
}
signed main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	/*****************************************/
	
	
	int n; cin>>n;
	pair<int, int> p[n];
	
	for(int i=0; i<n; i++)
		cin>>p[i].second>>p[i].first;
	
	sort(p, p+n);
	bool ok = true;
	ok &= p[0].second <= p[0].first;
	for(int i=1; i<n; i++)
	{
		p[i].second += p[i-1].second;
		ok &= p[i].second <= p[i].first;
	}
	if(ok) cout<<"Yes\n";
	else cout<<"No\n";
	
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;

long long N, K;

int main() {
	cin >> N >> K;
	long long P1 = N % K;
	long long P2 = K - P1;
	cout << min(P1, P2) << endl;
	return 0;
}

Measured memory_bytes: 3660
// inputに入力データ全体が入る
function Main(input) {
	input = input.split(" ");
	const map1 = input.map(n => parseInt(n, 10));
  	map1.sort(function(a,b){
        if( a < b ) return -1;
        if( a > b ) return 1;
        return 0;
	});
  	if (map1[0] + map1[1] === map1[2] ) {
      console.log("Yes");
    } else {
      console.log("No");
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define ll long long

using namespace std;

int main(){
	ll i,j,n,y,b,f,r,v;
	char x;
	
	cin>>n;
	
	ll b1[4][11]={0},b2[4][11]={0},b3[4][11]={0},b4[4][11]={0};
	
	for(i=1;i<=n;i++){
		cin>>b>>f>>r>>v;
		if(b==1) b1[f][r]+=v;
			else if(b==2) b2[f][r]+=v;
				else if(b==3) b3[f][r]+=v;
					else if(b==4) b4[f][r]+=v;
	}
	
	for(i=1;i<=3;i++){
		for(j=1;j<=10;j++){
			cout<<" "<<b1[i][j];
		}
		cout<<"\n";
	}
	for(i=1;i<=20;i++){
		cout<<"#";
	}
	cout<<"\n";
	for(i=1;i<=3;i++){
		for(j=1;j<=10;j++){
			cout<<" "<<b2[i][j];
		}
		cout<<"\n";
	}
	for(i=1;i<=20;i++){
		cout<<"#";
	}
	cout<<"\n";
	for(i=1;i<=3;i++){
		for(j=1;j<=10;j++){
			cout<<" "<<b3[i][j];
		}
		cout<<"\n";
	}
	for(i=1;i<=20;i++){
		cout<<"#";
	}
	cout<<"\n";
	for(i=1;i<=3;i++){
		for(j=1;j<=10;j++){
			cout<<" "<<b4[i][j];
		}
		cout<<"\n";
	}
}


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

int N, K;
vector<int> Nums;
string S;

int main() {
    cin >> N >> K;
    cin >> S;
    int now = 1;
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i] == (char)('0' + now)) cnt++;
        else {
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if (cnt != 0) Nums.push_back(cnt);

    if (Nums.size() % 2 == 0) Nums.push_back(0);

    int Add = 2 * K + 1;

    int ans = 0;

    for (int i = 0; i < Nums.size() ; i += 2) {
        int tmp = 0;
        int left = i;
        int right = min(i + Add, (int)Nums.size());
        for (int j = left; j < right; ++j) {
            tmp += Nums[j];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1020
//B問題

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>

int main() {
	std::string str;
	std::cin >> str;

	std::string stryy = str.substr(0, 2);
	std::string strmm = str.substr(2, 2);

	int yy = std::atoi(stryy.c_str());
	int mm = std::atoi(strmm.c_str());

	bool flagyy = (yy > 0 && yy < 13);
	bool flagmm = (mm > 0 && mm < 13);

	if (flagyy == false && flagmm == true) {
		std::cout<<"YYMM"<<std::endl;
		return 0;
	}

	if (flagyy == true && flagmm == false ) {
		std::cout<<"MMYY"<<std::endl;
		return 0;
	}

	if (flagyy == true && flagmm == true) {
		std::cout<< "AMBIGUOUS"<<std::endl;
		return 0;
	}

	if (flagyy == false && flagmm == false) {
		std::cout<<"NA"<<std::endl;
		return 0;
	}
	//std::cout << flag << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
typedef long long int ll;
using namespace std;

int main(){
	ll n,k; cin >>n>>k;
	ll ans=0;
	for(int i=0;i<n-1;i++){
		ans=ans%(k-1)+1+ans/(k-1)*k;
	}
	cout << ans << endl;
}


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

int main() {
  string S; cin >> S;
  string T = "CODEFESTIVAL2016";
  int cnt = 0;
  for (int i = 0; i < 16; i++) {
    if (S.at(i) != T.at(i)) cnt++;
  }
  cout << cnt << endl;
}

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

struct data {
  int p, c;
};

int n, m, s, t;
vector<int> edge[100005];
int d[100005][3] = {0};
queue<data> qu;

long long solve();

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    long long x, y;
    cin >> x >> y;
    edge[--x].push_back(--y);
  }
  cin >> s >> t;
  --s, --t;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < 3; ++j) d[i][j] = inf;
  qu.push({s, 0});
  while(qu.size() > 0) {
    data now = qu.front();
    qu.pop();
    for(int i = 0; i < edge[now.p].size(); ++i) {
      data nextp = now;
      nextp.p = edge[now.p][i];
      ++nextp.c;
      if(d[nextp.p][nextp.c % 3] > nextp.c) {
        d[nextp.p][nextp.c % 3] = nextp.c;
        qu.push(nextp);
      }
    }
  }
  if(d[t][0] == inf) return -1;
  return d[t][0] / 3;
}

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

int main() {
  int N,K,Q;
  cin >> N >> K >> Q;
  int s = Q - K ;
  int a[100100];
  for(int i=0;i<N;i++){
    a[i]=0;
  }
  for(int i=0;i<Q;i++){
    int x;
    cin >> x;
    a[x-1] +=1;
  }       
  for(int i=0;i<N;i++){
    if(a[i]>s) cout << "Yes" <<endl;
    else  cout << "No" <<endl;
  }
}


Measured memory_bytes: 1024
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (X, Y, A, B, C) = nextIntList()
    val P = nextLongList().sortedDescending().take(X)
    val Q = nextLongList().sortedDescending().take(Y)
    val R = nextLongList()
    val ans = (P + Q + R).sortedDescending().take(X + Y).sum()
    println(ans)
}


Measured memory_bytes: 70776
//Created Time:2019年12月19日 星期四 11时42分55秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 505

using namespace std;

char s[N], a[N][N], b[N][N];

int main(){
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; ++i){
		scanf("%s", s + 1);
		for(int j = 1; j <= m; ++j)
			if(s[j] == '#') a[i][j] = b[i][j] = '#';
			else a[i][j] = b[i][j] = '.';
	}
	for(int i = 1; i <= n; i += 2){
		for(int j = 2; j <= m; ++j)
			a[i][j] = '#';
		if(i != 1) a[i - 1][m] = '#';
	}
	for(int i = 2; i <= n; i += 2){
		for(int j = 1; j < m; ++j)
			b[i][j] = '#';
		if(i != 2) b[i - 1][1] = '#';
	}
	for(int i = 1; i <= n; ++i)
		printf("%s\n", a[i] + 1);
	puts("");
	for(int i = 1; i <= n; ++i)
		printf("%s\n", b[i] + 1);
	return 0;
}


Measured memory_bytes: 1280
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = ["a", "i", "u", "e", "o"]
    c = S()
    if c[0] in a:
        print("vowel")
    else:
        print("consonant")
    return

#B
def B():
    _ = II()
    t = LI()
    tsum = sum(t)
    for _ in range(II()):
        p, x = LI()
        print(tsum - t[p - 1] + x)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 38740
#include<stdio.h>
int main()
{
	int a[200];
	int x,n;
	scanf("%d %d",&n,&x);
	int i;
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	int sum=0;
	int d=0;
	for(i=0;i<n;i++)
	{
	d+=a[i];
	if(d<=x)
	{
		sum++;
	}
	}
	printf("%d",sum+1);
	
}

Measured memory_bytes: 256
n=int(input())
count=0 #個数
for i in range(1,n+1):
    count_yakusu=0 #約数の個数
    for j in range(1,i+1):
        if i%j==0:
            count_yakusu+=1
    if count_yakusu == 8 and i%2==1:
        count+=1
print(count)

Measured memory_bytes: 3060
N,K = map(int,input().split())
A = list(map(int,input().split()))

def check(m):
    n = 0
    for a in A:
        if a%m == 0:
            n += a//m - 1
        else:
            n += a//m
    return n <= K
        

l = 0
r = 10**9+10

while r-l > 1:
    m = (r+l) // 2
    if check(m):
        r = m
    else:
        l = m

print(r)




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

int main()
{
	int N, A[200000], B[200000];

	cin >> N;

	int a = N / 2, b = N / 2 + 1;

	if (N % 2 == 0) {
		a--;
		b--;
	}

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

	for (int i = 0; i < N; i++) {
		if ((i+1) %2 == N%2) {
			B[a] = A[i];
			a--;
		}
		else {
			B[b] = A[i];
			b++;
		}
	}

	for (int i = 0; i < N; i++) {
		cout << B[i];
		if (i < N - 1)cout << " ";
	}

	return 0;
}

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

const int mxN=200005,M=1000000007;
int n,a,b,tot;
int fat[mxN],inv[mxN];

int mod(int x,int M){int ret=x%M;if(ret<0)ret+=M;return ret;}

int exp(int a,int b,int M){
    if(b==0LL)return 1LL;
    if(b==1LL)return mod(a,M);

    int t=mod(exp(a,b/2,M),M);
    if(b%2==1)return mod(a*mod(t*t,M),M);
    return mod(t*t,M);
}

int C(int n,int k){
    int ans=1LL;
    for(int i=n;i>=n-k+1;i--){
        ans=mod(ans*i,M);
    }
    return mod(ans*inv[k],M);
}

int32_t main(){
    cin>>n>>a>>b;
    fat[0]=inv[0]=1;
    tot=exp(2LL,n,M);
    for(int i=1;i<mxN;i++){
        fat[i]=(i*fat[i-1])%M;
        inv[i]=exp(fat[i],M-2,M);
    }

    tot=(tot-1-C(n,a)-C(n,b))%M;
    if(tot<0)tot+=M;

    cout<<tot;




}

Measured memory_bytes: 3328
/**
 *      ABC 99 C
 *      author  : kyomukyomupurin
 *      created : 2018-10-05 14:55:45
**/

#include <bits/stdc++.h>
#define int32 int_fast32_t
#define int64 int_fast64_t
using namespace std;


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

    int32 ans = 1e5 + 1;

    for (auto i = 0; i <= N; ++i) {
        int32 cnt = 0;
        int32 t = i; int32 tt = N - i;
        while (t > 0){
            cnt += (t % 6); t /= 6;
        }
        while (tt > 0){
            cnt += (tt % 9); tt /= 9;
        }
        if (cnt < ans) ans = cnt;
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  int i,n,cnt=0;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  i=0;
  while(1){
    if(a[i]%2==1)
      break;
    else
      a[i]/=2;
    i++;
    if(i==n){
      i=0;
      cnt++;
    }
  }
  printf("%d\n",cnt);
}

Measured memory_bytes: 128
#include <stdio.h>

#define MAX 2000000

void maxHeapify(int*,int);
int left(int);
int right(int);

int H;

int main()
{
  int A[MAX+1],i;

  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
    }
  for(i=H/2;i>=1;i--){
    maxHeapify(A,i);
  }
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
    }
  printf("\n");
  return 0;
}

void maxHeapify(int A[],int i){
  int l,r,largest,t;

  l = left(i);
  r = right(i);

// 左の子、自分、右の子で値が最大のノードを選ぶ
  if (l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if (r <= H && A[r] > A[largest]) largest = r;
// i の子の方が値が大きい場合if
  if(largest != i){
    t = A[i];
    A[i] = A[largest];
    A[largest] = t;
    maxHeapify(A, largest); // 再帰的に呼び出し
  }
}

int left(int i){
  return 2*i;
}

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



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

int solve() {
  int N;
  cin >> N;
  string s, t;
  cin >> s >> t;
  rep(i, N) {
    bool ok = true;
    rep(j, N - i) {
      if (s[i + j] != t[j])
        ok = false;
    }
    if (ok)
      return N + i;
  }
  return 2 * N;
}

int main() {
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define int long long
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
/* 	1) order_of_key (k) : Number of items strictly smaller than k .
	2) find_by_order(k) : K-th element in a set (counting from zero).
*/
using namespace __gnu_pbds;
using namespace std;
using LD = long double;

const int maxs = 1e6+1;
const int mod = 1e9+7;
const int INF = 1e18;
int row[8] = {1,1,0,-1,-1,-1,0,1};
int col[8] = {0,-1,-1,-1,0,1,1,1};

void solve() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int mx = a * c;
	mx = max(mx, a * d);
	mx = max(mx, b * c);
	mx = max(mx, b * d);
	cout << mx << endl;
}
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t = 1,i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A,B;
  A = 0,B=0;
  cin >> N;
  vector<int> ns(N);
  for(int i=0;i<N;i++){
    cin >> ns.at(i);
  }
  bool b = true;
  while(ns.size()>0){
    int max = 0;
    int index;
    for(int i = 0;i < ns.size();i++){
      if(ns.at(i)>max){
        max = ns.at(i);
        index = i;
      }
    }
    if(b==true){
      b=false;
      A+= max;
    }else{
      b =true;
      B+=max;
    }
    ns.erase(ns.begin()+index);
  }
  cout << A - B << endl;
}

Measured memory_bytes: 256
def main():
    MOD = 998244353
    N, K = list(map(int, input().split()))
    section_list = [list(map(int, input().split())) for _ in range(K)]
    dp = [0] * N
    dp[0] = 1
    dp[1] = -1
    for n in range(N):
        cnt = dp[n]
        for k in range(K):
            L, R = section_list[k]
            if n + L < N:
                dp[n + L] += cnt
                dp[n + L] %= MOD
            if n + R + 1 < N:
                dp[n + R + 1] -= cnt
                dp[n + R + 1] %= MOD
        if n < N - 1:
            dp[n + 1] += dp[n]
            dp[n + 1] %= MOD
    print(dp[N - 1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 69924
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;
        if(a > b) {
            ans += a;
            a--;
        } else {
            ans += b;
            b--;
        }
        
        ans += Math.max(a,b);
        System.out.println(ans);
    } 
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <string>

using namespace std;

bool kaibun(const string& str) {
	string rev = str;
	reverse(rev.begin(), rev.end());
	return rev == str;
	
}

int main()
{
	string str;

	cin >> str;

	int size = str.length()/2;

	if (!kaibun(str)) {
		cout << "No" << endl;
		return 0;
	}

	if (!kaibun(str.substr(0, size))) {
		cout << "No" << endl;
		return 0;
	}

	if (!kaibun(str.substr(size+1, size))) {
		cout << "No" << endl;
		return 0;
	}



	cout << "Yes" << endl;

}

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

void print_sheet(vector<vector<int>> &sheet)
{
  for (int r = 0; r < sheet.size(); r++)
  {
    for (int c = 0; c < sheet.at(0).size(); c++)
    {
      cout << sheet.at(r).at(c);
      if (c != sheet.at(0).size() - 1)
      {
        cout << ' ';
      }
    }
    cout << endl;
  }
}

int main()
{
  int row, column;
  cin >> row >> column;

  vector<vector<int>> sheet(row + 1, vector<int>(column + 1));
  for (int r = 0; r < row; r++)
  {
    int sum = 0;
    for (int c = 0; c < column; c++)
    {
      cin >> sheet.at(r).at(c);
      sum += sheet.at(r).at(c);
    }
    sheet.at(r).at(column) = sum;
  }
  for (int c = 0; c < column + 1; c++)
  {
    int sum = 0;
    for (int r = 0; r < row; r++)
    {
      sum += sheet.at(r).at(c);
    }
    sheet.at(row).at(c) = sum;
  }

  print_sheet(sheet);
}



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

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    rep(i,N){
        cin >> S[i];
    }
    vector<int> C(4,0);
    rep(i,N){
        if(S[i]=="AC"){
            C[0]++;
        }
        if(S[i]=="WA"){
            C[1]++;
        }
        if(S[i]=="TLE"){
            C[2]++;
        }
        if(S[i]=="RE"){
            C[3]++;
        }
    }
    
    cout << "AC x " << C[0] << endl;
    cout << "WA x " << C[1] << endl;
    cout << "TLE x " << C[2] << endl;
    cout << "RE x " << C[3] << endl;

}

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

long long gcd(long long x, long long y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

long long lcm(long long x, long long y)
{
    if (x == 0 || y == 0)
        return 0;
    return x / gcd(x, y) * y;
}

int cnt = 0;
vector<vector<int>> ab;

int main()
{
    int N, M;
    cin >> N >> M;
    ab.resize(N);
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        ab[a].push_back(b);
        ab[b].push_back(a);
    }

    int check = -1;
    while (check != cnt)
    {
        check = cnt;
        for (int i = 0; i < N; i++)
        {
            if (ab[i].size() == 1 && ab[i][0] != -1)
            {
                cnt++;
                int e = ab[i][0];
                ab[i][0] = -1;
                ab[e].erase(remove(ab[e].begin(), ab[e].end(), i));
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 変数
        int[][] bingo  = new int[3][3]; // ビンゴシート
        int n = 0; // 表示される数字の数
        int x[] = null; // 数字リスト
        int count;
        boolean judge = false; // ビンゴ有無

        // 変数準備
        Scanner sc = new Scanner(System.in);

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                bingo[i][j] = sc.nextInt();
            }
        }

        n = sc.nextInt();
        x = new int[n];

        for (int k = 0; k < n; k++) {
            x[k] = sc.nextInt();
        }

        // 判定準備
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < n; k++) {
                    if (x[k] == bingo[i][j]) {
                        bingo[i][j] = -1;
                    }
                }
            }
        }

        // 判定
        // 縦
        count = 0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (bingo[i][j] == -1) {
                    count++;
                }
            }
            if (count == 3) {
                judge = true;
            }
            count= 0;
        }

        // 横
        if (!judge) {
            count = 0;
            for (int j = 0; j < 3; j++) {
                for (int i = 0; i < 3; i++) {
                    if (bingo[i][j] == -1) {
                        count++;
                    }
                }
                if (count == 3) {
                    judge = true;
                }
                count= 0;
            }
        }

        // 斜め
        if (!judge) {
            count = 0;
            if (bingo[0][0] == -1) {
                count++;
            }
            if (bingo[1][1] == -1) {
                count++;
            }
            if (bingo[2][2] == -1) {
                count++;
            }
            if (count == 3) {
                judge = true;
            }
        }

        if (!judge) {
            count = 0;
            if (bingo[0][2] == -1) {
                count++;
            }
            if (bingo[1][1] == -1) {
                count++;
            }
            if (bingo[2][0] == -1) {
                count++;
            }
            if (count == 3) {
                judge = true;
            }
        }

        if(judge) {
            System.out.print("Yes");
        } else {
            System.out.print("No");
        }

    }
}


Measured memory_bytes: 22608
def hex(s):
    if s=="A" :
        return 10
    elif s=="B" :
        return 11
    elif s=="C" :
        return 12
    elif s=="D" :
        return 13
    elif s=="E" :
        return 14
    elif s=="F" :
        return 15

x,y = map(hex, input().split())
if x > y :
    print(">")
elif x == y :
    print("=")
elif x < y :
    print("<")

Measured memory_bytes: 38256
from heapq import heappush, heappop, heapify


def dijkstra(s, t, links):
    heap = list(links[s])
    heapify(heap)
    visited = set()
    while heap:
        fare, node = heappop(heap)
        if node == t:
            return fare
        if node in visited:
            continue
        visited.add(node)
        for fare2, node2 in links[node]:
            if node2 not in visited:
                heappush(heap, (fare + fare2, node2))
    return -1


while True:
    n, k = map(int, input().split())
    if not n:
        break
    links = [set() for _ in range(n)]
    for _ in range(k):
        o = map(int, input().split())
        if next(o):
            c, d, e = o
            c, d = c - 1, d - 1
            links[c].add((e, d))
            links[d].add((e, c))
        else:
            a, b = o
            print(dijkstra(a - 1, b - 1, links))

Measured memory_bytes: 8092
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int i ,j=0 ,n ,m ,L ,tmp ,savings=0;
  while( 1 ){  // 目標金額
    cin >> L;
    if( L == 0 ){
      break;
    }

    if( L == 0 ){
      break;
    }
    
    for( i=1 ; i<=12 ; i++ ){
      cin >> m >> n;       // 小遣い　使用金額
      savings = savings + ( m - n );
      if( savings >= L && j == 0 ){
	tmp = i;
	j++;
      }
    }
    
    if( j != 0 ){
      cout << tmp << endl;
    }

    else{
      cout << "NA" << endl;
    }
    savings = 0;
    j=0;
  }

  return 0;
}
    

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var k = int.Parse(Console.ReadLine());
    var zen = new double[k,2];
   
    for(var i = 0;i<k;i++){
       var aho = Console.ReadLine().Split();
       zen[i,0] = double.Parse(aho[0]);
       zen[i,1] = double.Parse(aho[1]);
    }
    double go  = 0;
    for(var i = 0;i<k;i++){
    	for(var j = 0;j<k;j++){
          if(i == j) continue;
           double x = (zen[i,0]-zen[j,0]);
           double y = (zen[i,1]-zen[j,1]);
           double kyori = Math.Sqrt(x*x+y*y);
           go += kyori;
        }
    }
    Console.WriteLine(go/k);
  }
}

Measured memory_bytes: 13140
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/14/20 20:53:44
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  vector<int> A(n); for (auto& a:A) cin>>a;
  map<int,int> as;
  for (auto a:A) {
    as[a]++;
  }
  set<int> ans;
  while (not as.empty()) {
    auto [af,afc] = *as.begin();
    if (afc == 1)
      ans.insert(af);
    for (int k = af; k <= 1e6; k += af) {
      as.erase(k);
    }
  }
  cout << ans.size() << endl;

  return 0;
}


Measured memory_bytes: 13440
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n, a[100010];
int ta;
int sum;
vector<int> mu;

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		if (a[i] < 0) {
			ta++;
			mu.push_back(a[i] * -1);
			sum += a[i] * -1;
		}
		else {
			sum += a[i];
			mu.push_back(a[i]);
		}
	}
	if (ta % 2 == 0) {
		cout << sum << endl;
		return 0;
	}
	sort(all(mu));
	cout << sum - mu[0] * 2 << endl;
}

Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define R cin>>
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;
#define SEGTREE_MAX_N (1<<21)

int c[100010],d[100010];
class SegmentTree {
private:
  int size;
  vector<P> dat;
  P query(int a, int b, int k, int l, int r) {
    if(r<=a || b<=l) return P(1,0);   
    if(a<=l && r<=b) return dat[k];
    P vl=query(a,b,k*2+1,l,(l+r)/2);
    P vr=query(a,b,k*2+2,(l+r)/2,r);
    P p;
    p.F=vl.F/__gcd(vl.F,vr.F)*vr.F;
    p.S=p.F/vl.F%MAX*vl.S+p.F/vr.F%MAX*vr.S;
    p.S%=MAX;
    return p;
  }
public:
  SegmentTree(int n_) {
    size = 1;
    while(size<n_) size*=2;
    dat.resize(2*size-1, P(INT_MAX,INT_MAX));
  }
  P find(int s, int t) {
    return query(s, t, 0, 0, size);
  }
  void update(int idx, int x, int y) {
    idx += size-1;
    dat[idx]=P(x,y);
    
    while(idx>0) {
      idx = (idx-1)/2;
      dat[idx].F=dat[idx*2+1].F/__gcd(dat[idx*2+1].F,dat[idx*2+2].F)*dat[idx*2+2].F;
      dat[idx].S=dat[idx].F/dat[idx*2+1].F%MAX*dat[idx*2+1].S+dat[idx].F/dat[idx*2+2].F%MAX*dat[idx*2+2].S;
      dat[idx].S%=MAX;
    }
    
  }
};
 
int main() {
  int n,q;
  cin >> n >> q;
  SegmentTree s(n+1);
  int p[n+1];
  REP(i,1,n+1) cin >> p[i];
  bool u[n+1];
  memset(u,0,sizeof(u));
  memset(c,0,sizeof(c));
  memset(d,0,sizeof(d));
  REP(i,1,n+1) {
    if(!u[i]) {
      c[i]=u[i]=1;
      d[i]=i;
      int x=p[i];
      while(!u[x]) {
	c[i]++;
	u[x]=1;
	d[i]+=x;
	x=p[x];
      }
      x=p[i];
      while(x!=i) {
	c[x]=c[i];
	d[x]=d[i];
	x=p[x];
      }
    }
    s.update(i,c[i],d[i]);
  }
  while(q--) {
    int l,r;
    cin >> l >> r;
    P p=s.find(l,r+1);
    cout << p.S << endl;
  }
  return 0;
}


Measured memory_bytes: 6480
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;
void print(long double a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}


//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];
//ll dp[1001][1001];
//char a[1001][1001];
long double dp[3000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
	cout <<setprecision(10) << fixed ;

	ll n;
	cin>>n;
	long double a[n];
	for(ll i = 1;i<=n;i++){
		cin>>a[i];
	}
	ll op = n/2+1;
	
 	dp[0]=1;
	for(int i=1;i<=n;i++){
		for(int j=i;j>=0;j--){
			if(j==0)
				dp[j] = dp[j]*(1-a[i]);
			else
				dp[j] = dp[j-1]*a[i] + dp[j]*(1-a[i]);
		}
	}
	long double ans=0;
	for(int i=op;i<=n;i++){
		ans+=dp[i];
	}
	//print(dp, n+1);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
signed main() {
	int n; cin >> n;
	int p = 0;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		if (a % 2 == 0)p++;
	}
	cout << p << endl;
}


Measured memory_bytes: 3124
#include<iostream>
#include<cmath>
#include<map>
#include<vector>
using namespace std;


int main(){
    //宣言
    long long N, K, n;
    long long min, max;
    long long ans = 0;
    

    //インプット
    std::cin >> N >> K;

    for(long long i = 0; i < N+2-K ; i ++){
        //選ぶ個数のループ
        n = K + i; //選ぶ個数
        min = (0 + n-1) * n /2;
        max = (N- n + 1 + N) * n /2;
        ans = ans + max - min + 1;
    }

    std::cout << ans%1000000007;
}

Measured memory_bytes: 3632